diff --git a/apps/OpenSpace/ext/launcher/include/launcherwindow.h b/apps/OpenSpace/ext/launcher/include/launcherwindow.h index 28ec0395e1..f85248851d 100644 --- a/apps/OpenSpace/ext/launcher/include/launcherwindow.h +++ b/apps/OpenSpace/ext/launcher/include/launcherwindow.h @@ -59,7 +59,7 @@ public: * * \return true if the "start OpenSpace" button was clicked */ - bool wasLaunchSelected(); + bool wasLaunchSelected() const; /** * Returns true if both the profile and sgct window configuration were specified @@ -67,7 +67,7 @@ public: * * \return true if both profile and sgct window config were specified at CLI */ - bool isFullyConfiguredFromCliArgs(); + bool isFullyConfiguredFromCliArgs() const; /** * Returns the selected profile name when launcher window closed @@ -75,7 +75,7 @@ public: * \return name of selected profile (this is only the name without file extension * and without path) */ - std::string selectedProfile(); + std::string selectedProfile() const; /** * Returns the selected sgct window configuration when launcher window closed @@ -83,11 +83,11 @@ public: * \return name of selected profile (this is only the name without file extension * and without path) */ - std::string selectedWindowConfig(); + std::string selectedWindowConfig() const; public slots: - void openWindow_edit(); - void openWindow_new(); + void openWindowEdit(); + void openWindowNew(); void startOpenSpace(); private: diff --git a/apps/OpenSpace/ext/launcher/include/profile/profileedit.h b/apps/OpenSpace/ext/launcher/include/profile/profileedit.h index e2f78d8af9..d595cbd4c8 100644 --- a/apps/OpenSpace/ext/launcher/include/profile/profileedit.h +++ b/apps/OpenSpace/ext/launcher/include/profile/profileedit.h @@ -69,7 +69,7 @@ public: * * \return true if the file was saved (false if cancel) */ - bool wasSaved(); + bool wasSaved() const; /** * Gets the profile name from the top save/edit window. This can be changed by user in @@ -77,14 +77,14 @@ public: * * \return the profile name */ - std::string specifiedFilename(); + std::string specifiedFilename() const; /** * Handles keypress while the Qt dialog window is open * * \param evt #QKeyEvent object for the key press event */ - void keyPressEvent(QKeyEvent *evt); + void keyPressEvent(QKeyEvent* evt); public slots: void duplicateProfile(); @@ -106,14 +106,12 @@ private: std::string summarizeAssets(); std::string summarizeProperties(); std::string summarizeKeybindings(); - void labelText(const openspace::Profile& pData, int size, QString title, - QLabel* pLabel); bool isReadOnly(std::string profileToSave); openspace::Profile& _profile; const std::string _reportedAssets; bool _saveSelected = false; - std::vector _profilesReadOnly; + std::vector _readOnlyProfiles; QLineEdit* _profileEdit = nullptr; QLabel* _modulesLabel = nullptr; diff --git a/apps/OpenSpace/ext/launcher/resources/qss/launcher.qss b/apps/OpenSpace/ext/launcher/resources/qss/launcher.qss index 835875efc8..7d38a599bf 100644 --- a/apps/OpenSpace/ext/launcher/resources/qss/launcher.qss +++ b/apps/OpenSpace/ext/launcher/resources/qss/launcher.qss @@ -89,11 +89,15 @@ ProfileEdit QLabel#profile { font-weight: bold; } -ProfileEdit QLabel#heading { +ProfileEdit QLabel#heading { font-size: 10pt; font-weight: bold; } +ProfileEdit QLabel#error-message { + min-width: 10em; +} + /* * Properties */ diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index f9fec20efd..8de5d6f37e 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -43,7 +43,31 @@ namespace { constexpr const int LeftRuler = 40; constexpr const int TopRuler = 80; constexpr const int ItemWidth = 240; + constexpr const int ItemHeight = ItemWidth / 4; constexpr const int SmallItemWidth = 100; + constexpr const int SmallItemHeight = SmallItemWidth / 4; + + namespace geometry { + constexpr const QRect BackgroundImage(0, 0, ScreenWidth, ScreenHeight); + constexpr const QRect LogoImage(LeftRuler, TopRuler, ItemWidth, ItemHeight); + constexpr const QRect ChooseLabel(LeftRuler, TopRuler + 80, 151, 24); + constexpr const QRect ProfileBox( + LeftRuler, TopRuler + 110, ItemWidth, ItemHeight + ); + constexpr const QRect OptionsLabel(LeftRuler, TopRuler + 180, 151, 24); + constexpr const QRect WindowConfigBox( + LeftRuler, TopRuler + 210, ItemWidth, ItemHeight + ); + constexpr const QRect StartButton( + LeftRuler, TopRuler + 290, ItemWidth, ItemHeight + ); + constexpr const QRect NewButton( + LeftRuler + 140, TopRuler + 380, SmallItemWidth, SmallItemHeight + ); + constexpr const QRect EditButton( + LeftRuler, TopRuler + 380, SmallItemWidth, SmallItemHeight + ); + } // geometry } // namespace using namespace openspace; @@ -78,70 +102,71 @@ LauncherWindow::LauncherWindow(std::string basePath, bool profileEnabled, setFixedSize(ScreenWidth, ScreenHeight); setAutoFillBackground(false); - QFile file(":/qss/launcher.qss"); - file.open(QFile::ReadOnly); - QString styleSheet = QLatin1String(file.readAll()); - setStyleSheet(styleSheet); + { + QFile file(":/qss/launcher.qss"); + file.open(QFile::ReadOnly); + QString styleSheet = QLatin1String(file.readAll()); + setStyleSheet(styleSheet); + } QWidget* centralWidget = new QWidget(this); QLabel* backgroundImage = new QLabel(centralWidget); - backgroundImage->setGeometry(QRect(0, 0, ScreenWidth, ScreenHeight)); + backgroundImage->setGeometry(geometry::BackgroundImage); QLabel* logoImage = new QLabel(centralWidget); logoImage->setObjectName("clear"); - logoImage->setGeometry(QRect(LeftRuler, TopRuler, ItemWidth, ItemWidth / 4)); + logoImage->setGeometry(geometry::LogoImage); logoImage->setPixmap(QPixmap(":/images/openspace-horiz-logo-small.png")); QLabel* labelChoose = new QLabel("Choose Profile", centralWidget); labelChoose->setObjectName("clear"); - labelChoose->setGeometry(QRect(LeftRuler, TopRuler + 80, 151, 24)); + labelChoose->setGeometry(geometry::ChooseLabel); _profileBox = new QComboBox(centralWidget); _profileBox->setObjectName("config"); - _profileBox->setGeometry(QRect(LeftRuler, TopRuler + 110, ItemWidth, ItemWidth / 4)); + _profileBox->setGeometry(geometry::ProfileBox); QLabel* optionsLabel = new QLabel("Window Options", centralWidget); optionsLabel->setObjectName("clear"); - optionsLabel->setGeometry(QRect(LeftRuler, TopRuler + 180, 151, 24)); + optionsLabel->setGeometry(geometry::OptionsLabel); _windowConfigBox = new QComboBox(centralWidget); _windowConfigBox->setObjectName("config"); - _windowConfigBox->setGeometry(QRect(LeftRuler, TopRuler + 210, ItemWidth, ItemWidth / 4)); + _windowConfigBox->setGeometry(geometry::WindowConfigBox); QPushButton* startButton = new QPushButton("START", centralWidget); connect(startButton, &QPushButton::released, this, &LauncherWindow::startOpenSpace); startButton->setObjectName("large"); - startButton->setGeometry(QRect(LeftRuler, TopRuler + 290, ItemWidth, ItemWidth / 4)); + startButton->setGeometry(geometry::StartButton); startButton->setCursor(Qt::PointingHandCursor); QPushButton* newButton = new QPushButton("New", centralWidget); - connect(newButton, &QPushButton::released, this, &LauncherWindow::openWindow_new); + connect(newButton, &QPushButton::released, this, &LauncherWindow::openWindowNew); newButton->setObjectName("small"); - newButton->setGeometry(QRect(LeftRuler + 140, TopRuler + 380, SmallItemWidth, SmallItemWidth / 4)); + newButton->setGeometry(geometry::NewButton); newButton->setCursor(Qt::PointingHandCursor); QPushButton* editButton = new QPushButton("Edit", centralWidget); - connect(editButton, &QPushButton::released, this, &LauncherWindow::openWindow_edit); + connect(editButton, &QPushButton::released, this, &LauncherWindow::openWindowEdit); editButton->setObjectName("small"); - editButton->setGeometry(QRect(LeftRuler, TopRuler + 380, SmallItemWidth, SmallItemWidth / 4)); + editButton->setGeometry(geometry::EditButton); editButton->setCursor(Qt::PointingHandCursor); setCentralWidget(centralWidget); - - _reportAssetsInFilesystem = _filesystemAccess.useQtFileSystemModelToTraverseDir( - QString::fromStdString(basePath) + "/data/assets"); + QString::fromStdString(basePath) + "/data/assets" + ); populateProfilesList(globalConfig.profile); - _profileBox->setDisabled(!_profileChangeAllowed); + _profileBox->setEnabled(_profileChangeAllowed); populateWindowConfigsList(sgctConfigName); - _windowConfigBox->setDisabled(!_sgctConfigChangeAllowed); + _windowConfigBox->setEnabled(_sgctConfigChangeAllowed); _fullyConfiguredViaCliArgs = (!profileEnabled && !sgctConfigEnabled); bool hasSyncFiles = false; @@ -160,7 +185,7 @@ LauncherWindow::LauncherWindow(std::string basePath, bool profileEnabled, std::random_device rd; std::mt19937 rng(rd()); std::uniform_int_distribution uni(0, 4); - auto random_integer = uni(rng); + int random_integer = uni(rng); filename = QString::fromStdString( "/http/launcher_images/1/profile" + std::to_string(random_integer) + ".png" ); @@ -174,9 +199,7 @@ LauncherWindow::LauncherWindow(std::string basePath, bool profileEnabled, } void LauncherWindow::populateProfilesList(std::string preset) { - for (int i = 0; i < _profileBox->count(); ++i) { - _profileBox->removeItem(i); - } + _profileBox->clear(); std::string reportProfiles = _fileAccessProfiles.useQtFileSystemModelToTraverseDir( _basePath + "/data/profiles" ); @@ -219,13 +242,13 @@ void LauncherWindow::populateWindowConfigsList(std::string preset) { } } -void LauncherWindow::openWindow_new() { +void LauncherWindow::openWindowNew() { std::string initialProfileSelection = _profileBox->currentText().toStdString(); Profile profile; ProfileEdit editor( profile, _reportAssetsInFilesystem, - _globalConfig.profilesReadOnly, + _globalConfig.readOnlyProfiles, this ); editor.exec(); @@ -241,7 +264,7 @@ void LauncherWindow::openWindow_new() { } } -void LauncherWindow::openWindow_edit() { +void LauncherWindow::openWindowEdit() { std::string initialProfileSelection = _profileBox->currentText().toStdString(); std::string profilePath = _basePath.toStdString() + "/data/profiles/"; int selectedProfileIdx = _profileBox->currentIndex(); @@ -253,7 +276,7 @@ void LauncherWindow::openWindow_edit() { ProfileEdit editor( *profile, _reportAssetsInFilesystem, - _globalConfig.profilesReadOnly, + _globalConfig.readOnlyProfiles, this ); editor.setProfileName(profileToSet); @@ -273,18 +296,6 @@ void LauncherWindow::saveProfileToFile(const std::string& path, const Profile& p std::ofstream outFile; try { outFile.open(path, std::ofstream::out); - } - catch (const std::ofstream::failure& e) { - QMessageBox::critical( - this, - "Exception", - QString::fromStdString(fmt::format( - "Exception opening profile file {} for write: ({})", path, e.what() - )) - ); - } - - try { outFile << p.serialize(); } catch (const std::ofstream::failure& e) { @@ -292,12 +303,10 @@ void LauncherWindow::saveProfileToFile(const std::string& path, const Profile& p this, "Exception", QString::fromStdString(fmt::format( - "Data write error to file: {} ({})", path, e.what() + "Error writing data to file: {} ({})", path, e.what() )) ); } - - outFile.close(); } std::optional LauncherWindow::loadProfileFromFile(std::string filename) { @@ -346,19 +355,19 @@ std::optional LauncherWindow::loadProfileFromFile(std::string filename) } } -bool LauncherWindow::wasLaunchSelected() { +bool LauncherWindow::wasLaunchSelected() const { return _launch; } -bool LauncherWindow::isFullyConfiguredFromCliArgs() { +bool LauncherWindow::isFullyConfiguredFromCliArgs() const { return _fullyConfiguredViaCliArgs; } -std::string LauncherWindow::selectedProfile() { +std::string LauncherWindow::selectedProfile() const { return _profileBox->currentText().toStdString(); } -std::string LauncherWindow::selectedWindowConfig() { +std::string LauncherWindow::selectedWindowConfig() const { return _windowConfigBox->currentText().toStdString(); } diff --git a/apps/OpenSpace/ext/launcher/src/profile/profileedit.cpp b/apps/OpenSpace/ext/launcher/src/profile/profileedit.cpp index 9beca43491..fe3a78509c 100644 --- a/apps/OpenSpace/ext/launcher/src/profile/profileedit.cpp +++ b/apps/OpenSpace/ext/launcher/src/profile/profileedit.cpp @@ -34,17 +34,30 @@ #include #include +namespace { + template struct overloaded : Ts... { using Ts::operator()...; }; + template overloaded(Ts...)->overloaded; + + QString labelText(int size, QString title) { + QString label; + if (size > 0) { + label = title + " (" + QString::number(size) + ")"; + } + else { + label = title; + } + return label; + } +} // namespace + using namespace openspace; -template struct overloaded : Ts... { using Ts::operator()...; }; -template overloaded(Ts...) -> overloaded; - ProfileEdit::ProfileEdit(Profile& profile, const std::string reportedAssets, - std::vector& profilesReadOnly, QWidget* parent) + std::vector& readOnlyProfiles, QWidget* parent) : QDialog(parent) , _reportedAssets(reportedAssets) , _profile(profile) - , _profilesReadOnly(profilesReadOnly) + , _readOnlyProfiles(readOnlyProfiles) { setWindowTitle("Profile Editor"); @@ -315,14 +328,8 @@ ProfileEdit::ProfileEdit(Profile& profile, const std::string reportedAssets, QDialogButtonBox* buttons = new QDialogButtonBox; buttons->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel); - connect( - buttons, &QDialogButtonBox::accepted, - this, &ProfileEdit::cancel - ); - connect( - buttons, &QDialogButtonBox::rejected, - this, &ProfileEdit::reject - ); + connect(buttons, &QDialogButtonBox::accepted, this, &ProfileEdit::approved); + connect(buttons, &QDialogButtonBox::rejected, this, &ProfileEdit::reject); footer->addWidget(buttons); layout->addLayout(footer); } @@ -331,25 +338,23 @@ ProfileEdit::ProfileEdit(Profile& profile, const std::string reportedAssets, } void ProfileEdit::initSummaryTextForEachCategory() { - labelText(_profile, _profile.modules().size(), "Modules", _modulesLabel); + _modulesLabel->setText(labelText(_profile.modules().size(), "Modules")); - labelText(_profile, _profile.assets().size(), "Assets", _assetsLabel); + _assetsLabel->setText(labelText(_profile.assets().size(), "Assets")); _assetsEdit->setText(QString::fromStdString(summarizeAssets())); - labelText(_profile, _profile.properties().size(), "Properties", _propertiesLabel); + _propertiesLabel->setText(labelText(_profile.properties().size(), "Properties")); _propertiesEdit->setText(QString::fromStdString(summarizeProperties())); - labelText(_profile, _profile.keybindings().size(), "Keybindings", _keybindingsLabel); + _keybindingsLabel->setText(labelText(_profile.keybindings().size(), "Keybindings")); _keybindingsEdit->setText(QString::fromStdString(summarizeKeybindings())); - labelText(_profile, _profile.deltaTimes().size(), "Simulation Time Increments", - _deltaTimesLabel); - labelText(_profile, _profile.markNodes().size(), "Mark Interesting Nodes", - _interestingNodesLabel); - labelText(_profile, 0, "Camera", _cameraLabel); - labelText(_profile, 0, "Time", _timeLabel); - labelText(_profile, 0, "Meta", _metaLabel); - labelText(_profile, 0, "Additional Scripts", _additionalScriptsLabel); + _deltaTimesLabel->setText( + labelText(_profile.deltaTimes().size(), "Simulation Time Increments") + ); + _interestingNodesLabel->setText( + labelText(_profile.markNodes().size(), "Mark Interesting Nodes") + ); } void ProfileEdit::setProfileName(QString profileToSet) { @@ -358,7 +363,7 @@ void ProfileEdit::setProfileName(QString profileToSet) { void ProfileEdit::duplicateProfile() { QString currentProfile = _profileEdit->text(); - if (currentProfile != "") { + if (!currentProfile.isEmpty()) { QString duplicatedName = currentProfile + "_1"; if ((currentProfile.length() > 2) && (currentProfile.midRef(currentProfile.length() - 2, 1) == "_")) @@ -384,22 +389,20 @@ void ProfileEdit::openMeta() { void ProfileEdit::openModules() { _errorMsg->clear(); ModulesDialog(_profile, this).exec(); - labelText(_profile, _profile.modules().size(), "Modules", _modulesLabel); + _modulesLabel->setText(labelText(_profile.modules().size(), "Modules")); } void ProfileEdit::openProperties() { _errorMsg->clear(); PropertiesDialog(_profile, this).exec(); - labelText(_profile, _profile.properties().size(), "Properties", _propertiesLabel); + _propertiesLabel->setText(labelText(_profile.properties().size(), "Properties")); _propertiesEdit->setText(QString::fromStdString(summarizeProperties())); } void ProfileEdit::openKeybindings() { _errorMsg->clear(); KeybindingsDialog(_profile, this).exec(); - labelText(_profile, _profile.keybindings().size(), "Keybindings", - _keybindingsLabel - ); + _keybindingsLabel->setText(labelText(_profile.keybindings().size(), "Keybindings")); _keybindingsEdit->setText(QString::fromStdString(summarizeKeybindings())); } @@ -407,7 +410,7 @@ void ProfileEdit::openAssets() { _errorMsg->clear(); AssetsDialog assets(_profile, _reportedAssets, this); assets.exec(); - labelText(_profile, _profile.assets().size(), "Assets", _assetsLabel); + _assetsLabel->setText(labelText(_profile.assets().size(), "Assets")); _assetsEdit->setText(assets.createTextSummary()); _assetsEdit->setText(QString::fromStdString(summarizeAssets())); } @@ -420,11 +423,8 @@ void ProfileEdit::openTime() { void ProfileEdit::openDeltaTimes() { _errorMsg->clear(); DeltaTimesDialog(_profile, this).exec(); - labelText( - _profile, - _profile.deltaTimes().size(), - "Simulation Time Increments", - _deltaTimesLabel + _deltaTimesLabel->setText( + labelText(_profile.deltaTimes().size(), "Simulation Time Increments") ); } @@ -441,25 +441,11 @@ void ProfileEdit::openCamera() { void ProfileEdit::openMarkNodes() { _errorMsg->clear(); MarkNodesDialog(_profile, this).exec(); - labelText(_profile, _profile.markNodes().size(), "Mark Interesting Nodes", - _interestingNodesLabel + _interestingNodesLabel->setText( + labelText(_profile.markNodes().size(), "Mark Interesting Nodes") ); } -void ProfileEdit::labelText(const Profile& pData, int size, QString title, - QLabel* pLabel) -{ - QString label; - if (size > 0) { - label = title + " (" + QString::number(size) + ")"; - } - else { - label = title; - } - QByteArray qba = label.toLocal8Bit(); - pLabel->setText(label); -} - std::string ProfileEdit::summarizeProperties() { std::string results; for (openspace::Profile::Property p : _profile.properties()) { @@ -485,16 +471,16 @@ std::string ProfileEdit::summarizeKeybindings() { std::string ProfileEdit::summarizeAssets() { std::string results; for (const std::string& a : _profile.assets()) { - results += a + "\n"; + results += a + '\n'; } return results; } -bool ProfileEdit::wasSaved() { +bool ProfileEdit::wasSaved() const { return _saveSelected; } -std::string ProfileEdit::specifiedFilename() { +std::string ProfileEdit::specifiedFilename() const { return _profileEdit->text().toStdString(); } @@ -504,8 +490,8 @@ void ProfileEdit::cancel() { } bool ProfileEdit::isReadOnly(std::string profileSave) { - auto it = std::find(_profilesReadOnly.begin(), _profilesReadOnly.end(), profileSave); - return !(it == _profilesReadOnly.end()); + auto it = std::find(_readOnlyProfiles.begin(), _readOnlyProfiles.end(), profileSave); + return !(it == _readOnlyProfiles.end()); } void ProfileEdit::approved() { diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index 3962967033..65811a23fc 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -46,7 +46,7 @@ struct Configuration { std::string sgctConfigNameInitialized; std::string asset; std::string profile; - std::vector profilesReadOnly; + std::vector readOnlyProfiles; std::vector globalCustomizationScripts; std::map pathTokens = { { "CACHE" , "CACHE = \"${BASE}/cache\"" } diff --git a/openspace.cfg b/openspace.cfg index 98c401d3fe..063dac1ae9 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -62,7 +62,7 @@ Profile = "default" -- Profile = "voyager" -- These are profiles that are set to "read-only" -ProfilesReadOnly = { +ReadOnlyProfiles = { "apollo", "asteroids", "dawn", diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index a3491f54be..e70a905d8f 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -91,7 +91,7 @@ namespace { constexpr const char* KeyModuleConfigurations = "ModuleConfigurations"; constexpr const char* KeySgctConfigNameInitialized = "sgctconfiginitializeString"; - constexpr const char* KeyReadOnlyProfiles = "ProfilesReadOnly"; + constexpr const char* KeyReadOnlyProfiles = "ReadOnlyProfiles"; constexpr const char* KeyBypassLauncher = "BypassLauncher"; template @@ -310,7 +310,7 @@ void parseLuaState(Configuration& configuration) { getValue(s, KeyHttpProxy, c.httpProxy); getValue(s, KeySgctConfigNameInitialized, c.sgctConfigNameInitialized); - getValue(s, KeyReadOnlyProfiles, c.profilesReadOnly); + getValue(s, KeyReadOnlyProfiles, c.readOnlyProfiles); getValue(s, KeyBypassLauncher, c.bypassLauncher); }