diff --git a/common/src/View/GameEngineDialog.cpp b/common/src/View/GameEngineDialog.cpp index f3b2ee90f9..e7e8265a1e 100644 --- a/common/src/View/GameEngineDialog.cpp +++ b/common/src/View/GameEngineDialog.cpp @@ -33,14 +33,12 @@ #include -namespace TrenchBroom +namespace TrenchBroom::View { -namespace View -{ -GameEngineDialog::GameEngineDialog(const std::string& gameName, QWidget* parent) - : QDialog(parent) - , m_gameName(gameName) - , m_profileManager(nullptr) + +GameEngineDialog::GameEngineDialog(std::string gameName, QWidget* parent) + : QDialog{parent} + , m_gameName{std::move(gameName)} { setWindowTitle("Game Engines"); setWindowIconTB(this); @@ -49,21 +47,21 @@ GameEngineDialog::GameEngineDialog(const std::string& gameName, QWidget* parent) void GameEngineDialog::createGui() { - auto* gameIndicator = new CurrentGameIndicator(m_gameName); + auto* gameIndicator = new CurrentGameIndicator{m_gameName}; auto& gameFactory = Model::GameFactory::instance(); auto& gameConfig = gameFactory.gameConfig(m_gameName); - m_profileManager = new GameEngineProfileManager(gameConfig.gameEngineConfig); + m_profileManager = new GameEngineProfileManager{gameConfig.gameEngineConfig}; - auto* buttons = new QDialogButtonBox(QDialogButtonBox::Close); + auto* buttons = new QDialogButtonBox{QDialogButtonBox::Close}; - auto* layout = new QVBoxLayout(); - layout->setContentsMargins(QMargins()); + auto* layout = new QVBoxLayout{}; + layout->setContentsMargins(QMargins{}); layout->setSpacing(0); setLayout(layout); layout->addWidget(gameIndicator); - layout->addWidget(new BorderLine(BorderLine::Direction::Horizontal)); + layout->addWidget(new BorderLine{BorderLine::Direction::Horizontal}); layout->addWidget(m_profileManager, 1); layout->addLayout(wrapDialogButtonBox(buttons)); @@ -86,5 +84,5 @@ void GameEngineDialog::saveConfig() auto& gameFactory = Model::GameFactory::instance(); gameFactory.saveGameEngineConfig(m_gameName, m_profileManager->config(), logger); } -} // namespace View -} // namespace TrenchBroom + +} // namespace TrenchBroom::View diff --git a/common/src/View/GameEngineDialog.h b/common/src/View/GameEngineDialog.h index 1f33b3f3a3..5898ed36f2 100644 --- a/common/src/View/GameEngineDialog.h +++ b/common/src/View/GameEngineDialog.h @@ -26,10 +26,9 @@ class QKeyEvent; class QCloseEvent; -namespace TrenchBroom -{ -namespace View +namespace TrenchBroom::View { + class GameEngineProfileManager; /** @@ -40,10 +39,10 @@ class GameEngineDialog : public QDialog Q_OBJECT private: const std::string m_gameName; - GameEngineProfileManager* m_profileManager; + GameEngineProfileManager* m_profileManager = nullptr; public: - explicit GameEngineDialog(const std::string& gameName, QWidget* parent = nullptr); + explicit GameEngineDialog(std::string gameName, QWidget* parent = nullptr); public slots: // QDialog overrides void done(int r) override; @@ -51,5 +50,5 @@ public slots: // QDialog overrides void createGui(); void saveConfig(); }; -} // namespace View -} // namespace TrenchBroom + +} // namespace TrenchBroom::View diff --git a/common/src/View/GameEngineProfileEditor.cpp b/common/src/View/GameEngineProfileEditor.cpp index 0acdb36e59..f2e1a3791c 100644 --- a/common/src/View/GameEngineProfileEditor.cpp +++ b/common/src/View/GameEngineProfileEditor.cpp @@ -36,10 +36,9 @@ #include #include -namespace TrenchBroom -{ -namespace View +namespace TrenchBroom::View { + GameEngineProfileEditor::GameEngineProfileEditor(QWidget* parent) : QWidget{parent} { @@ -173,5 +172,5 @@ void GameEngineProfileEditor::changePathClicked() updatePath(pathStr); } } -} // namespace View -} // namespace TrenchBroom + +} // namespace TrenchBroom::View diff --git a/common/src/View/GameEngineProfileEditor.h b/common/src/View/GameEngineProfileEditor.h index 4f65fa4e6e..c3d4322b65 100644 --- a/common/src/View/GameEngineProfileEditor.h +++ b/common/src/View/GameEngineProfileEditor.h @@ -24,14 +24,12 @@ class QLineEdit; class QStackedWidget; -namespace TrenchBroom -{ -namespace Model +namespace TrenchBroom::Model { struct GameEngineProfile; } -namespace View +namespace TrenchBroom::View { /** * Editor widget for a single game engine profile. @@ -40,10 +38,10 @@ class GameEngineProfileEditor : public QWidget { Q_OBJECT private: - Model::GameEngineProfile* m_profile{nullptr}; - QStackedWidget* m_stackedWidget{nullptr}; - QLineEdit* m_nameEdit{nullptr}; - QLineEdit* m_pathEdit{nullptr}; + Model::GameEngineProfile* m_profile = nullptr; + QStackedWidget* m_stackedWidget = nullptr; + QLineEdit* m_nameEdit = nullptr; + QLineEdit* m_pathEdit = nullptr; public: explicit GameEngineProfileEditor(QWidget* parent = nullptr); @@ -69,5 +67,5 @@ private slots: */ void profileChanged(); }; -} // namespace View -} // namespace TrenchBroom + +} // namespace TrenchBroom::View diff --git a/common/src/View/GameEngineProfileListBox.cpp b/common/src/View/GameEngineProfileListBox.cpp index a290566f7c..07b8f49867 100644 --- a/common/src/View/GameEngineProfileListBox.cpp +++ b/common/src/View/GameEngineProfileListBox.cpp @@ -27,9 +27,7 @@ #include "View/ElidedLabel.h" #include "View/QtUtils.h" -namespace TrenchBroom -{ -namespace View +namespace TrenchBroom::View { // GameEngineProfileItemRenderer @@ -136,5 +134,5 @@ void GameEngineProfileListBox::doubleClicked(const size_t index) emit profileSelected(m_config->profiles[index]); } } -} // namespace View -} // namespace TrenchBroom + +} // namespace TrenchBroom::View diff --git a/common/src/View/GameEngineProfileListBox.h b/common/src/View/GameEngineProfileListBox.h index 6e2a411e6f..6db65c022c 100644 --- a/common/src/View/GameEngineProfileListBox.h +++ b/common/src/View/GameEngineProfileListBox.h @@ -21,15 +21,13 @@ #include "View/ControlListBox.h" -namespace TrenchBroom -{ -namespace Model +namespace TrenchBroom::Model { struct GameEngineConfig; struct GameEngineProfile; -} // namespace Model +} // namespace TrenchBroom::Model -namespace View +namespace TrenchBroom::View { class ElidedLabel; @@ -86,5 +84,5 @@ class GameEngineProfileListBox : public ControlListBox */ void profileSelected(Model::GameEngineProfile& profile); }; -} // namespace View -} // namespace TrenchBroom + +} // namespace TrenchBroom::View diff --git a/common/src/View/GameEngineProfileManager.cpp b/common/src/View/GameEngineProfileManager.cpp index eacb351bc8..cfd8438618 100644 --- a/common/src/View/GameEngineProfileManager.cpp +++ b/common/src/View/GameEngineProfileManager.cpp @@ -34,10 +34,9 @@ #include -namespace TrenchBroom -{ -namespace View +namespace TrenchBroom::View { + GameEngineProfileManager::GameEngineProfileManager( Model::GameEngineConfig config, QWidget* parent) : QWidget{parent} @@ -121,7 +120,7 @@ void GameEngineProfileManager::removeProfile() return; } - kdl::vec_erase_at(m_config.profiles, size_t(index)); + m_config.profiles = kdl::vec_erase_at(std::move(m_config.profiles), size_t(index)); m_profileList->reloadProfiles(); m_profileList->setCurrentRow(index >= m_profileList->count() ? index - 1 : index); } @@ -131,5 +130,5 @@ void GameEngineProfileManager::currentProfileChanged(Model::GameEngineProfile* p m_profileEditor->setProfile(profile); m_removeProfileButton->setEnabled(profile != nullptr); } -} // namespace View -} // namespace TrenchBroom + +} // namespace TrenchBroom::View diff --git a/common/src/View/GameEngineProfileManager.h b/common/src/View/GameEngineProfileManager.h index b8ab26dbd6..4ef9924026 100644 --- a/common/src/View/GameEngineProfileManager.h +++ b/common/src/View/GameEngineProfileManager.h @@ -25,15 +25,14 @@ class QAbstractButton; -namespace TrenchBroom -{ -namespace Model +namespace TrenchBroom::Model { struct GameEngineProfile; -} // namespace Model +} // namespace TrenchBroom::Model -namespace View +namespace TrenchBroom::View { + class GameEngineProfileEditor; class GameEngineProfileListBox; @@ -45,9 +44,9 @@ class GameEngineProfileManager : public QWidget Q_OBJECT private: Model::GameEngineConfig m_config; - GameEngineProfileListBox* m_profileList{nullptr}; - GameEngineProfileEditor* m_profileEditor{nullptr}; - QAbstractButton* m_removeProfileButton{nullptr}; + GameEngineProfileListBox* m_profileList = nullptr; + GameEngineProfileEditor* m_profileEditor = nullptr; + QAbstractButton* m_removeProfileButton = nullptr; public: explicit GameEngineProfileManager( @@ -59,5 +58,5 @@ private slots: void currentProfileChanged(Model::GameEngineProfile* profile); }; -} // namespace View -} // namespace TrenchBroom + +} // namespace TrenchBroom::View diff --git a/common/src/View/LaunchGameEngineDialog.cpp b/common/src/View/LaunchGameEngineDialog.cpp index f8bf2dca0e..12ae5443ba 100644 --- a/common/src/View/LaunchGameEngineDialog.cpp +++ b/common/src/View/LaunchGameEngineDialog.cpp @@ -217,17 +217,25 @@ void LaunchGameEngineDialog::editGameEngines() { saveConfig(); - const auto wasEmpty = m_gameEngineList->count() == 0; - auto dialog = GameEngineDialog{kdl::mem_lock(m_document)->game()->gameName(), this}; dialog.exec(); + const auto previousRow = m_gameEngineList->currentRow(); + // reload m_config as it may have been changed by the GameEngineDialog reloadConfig(); - if (wasEmpty && m_gameEngineList->count() > 0) + if (m_gameEngineList->count() > 0) { - m_gameEngineList->setCurrentRow(0); + if (previousRow >= 0) + { + m_gameEngineList->setCurrentRow( + std::min(previousRow, m_gameEngineList->count() - 1)); + } + else + { + m_gameEngineList->setCurrentRow(0); + } } }