MCPcopy Create free account
hub / github.com/Geant4/geant4 / AddViewerTabFromFile

Method AddViewerTabFromFile

source/interfaces/implementation/src/G4UIQt.cc:3187–3210  ·  view source on GitHub ↗

Add a new tab in the viewer */

Source from the content-addressed store, hash-verified

3185/** Add a new tab in the viewer
3186 */
3187G4bool G4UIQt::AddViewerTabFromFile(std::string fileName, std::string title)
3188{
3189 if (fViewerTabWidget == nullptr) {
3190 return false;
3191 }
3192
3193 G4UImanager* UI = G4UImanager::GetUIpointer();
3194 if (UI == nullptr) return false;
3195 std::ifstream file(UI->FindMacroPath(fileName.c_str()).data());
3196 if (file) {
3197 std::string content((std::istreambuf_iterator<char>(file)), (std::istreambuf_iterator<char>()));
3198
3199 auto text = new QTextEdit();
3200 text->setAcceptRichText(true);
3201 text->setContentsMargins(5, 5, 5, 5);
3202 text->setText(QString("<pre>") + content.c_str() + "</pre>");
3203 text->setReadOnly(true);
3204 fViewerTabWidget->addTab(text, title.c_str());
3205 }
3206 else {
3207 return false;
3208 }
3209 return true;
3210}
3211
3212/** Add a new tab widget.
3213 Create the tab if it was not done

Callers 3

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 4

FindMacroPathMethod · 0.80
c_strMethod · 0.80
QStringClass · 0.50
dataMethod · 0.45

Tested by

no test coverage detected