Skip to content

Commit

Permalink
Merge pull request TrenchBroom#4333 from TrenchBroom/4268
Browse files Browse the repository at this point in the history
4268: Fix delete button for engine profiles
  • Loading branch information
kduske authored Sep 17, 2023
2 parents fa401da + 34766b7 commit b7de79d
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 69 deletions.
28 changes: 13 additions & 15 deletions common/src/View/GameEngineDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@

#include <string>

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);
Expand All @@ -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));

Expand All @@ -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
13 changes: 6 additions & 7 deletions common/src/View/GameEngineDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
class QKeyEvent;
class QCloseEvent;

namespace TrenchBroom
{
namespace View
namespace TrenchBroom::View
{

class GameEngineProfileManager;

/**
Expand All @@ -40,16 +39,16 @@ 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;

private:
void createGui();
void saveConfig();
};
} // namespace View
} // namespace TrenchBroom

} // namespace TrenchBroom::View
9 changes: 4 additions & 5 deletions common/src/View/GameEngineProfileEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
#include <kdl/set_temp.h>
#include <kdl/string_compare.h>

namespace TrenchBroom
{
namespace View
namespace TrenchBroom::View
{

GameEngineProfileEditor::GameEngineProfileEditor(QWidget* parent)
: QWidget{parent}
{
Expand Down Expand Up @@ -173,5 +172,5 @@ void GameEngineProfileEditor::changePathClicked()
updatePath(pathStr);
}
}
} // namespace View
} // namespace TrenchBroom

} // namespace TrenchBroom::View
18 changes: 8 additions & 10 deletions common/src/View/GameEngineProfileEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -69,5 +67,5 @@ private slots:
*/
void profileChanged();
};
} // namespace View
} // namespace TrenchBroom

} // namespace TrenchBroom::View
8 changes: 3 additions & 5 deletions common/src/View/GameEngineProfileListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#include "View/ElidedLabel.h"
#include "View/QtUtils.h"

namespace TrenchBroom
{
namespace View
namespace TrenchBroom::View
{
// GameEngineProfileItemRenderer

Expand Down Expand Up @@ -136,5 +134,5 @@ void GameEngineProfileListBox::doubleClicked(const size_t index)
emit profileSelected(m_config->profiles[index]);
}
}
} // namespace View
} // namespace TrenchBroom

} // namespace TrenchBroom::View
12 changes: 5 additions & 7 deletions common/src/View/GameEngineProfileListBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -86,5 +84,5 @@ class GameEngineProfileListBox : public ControlListBox
*/
void profileSelected(Model::GameEngineProfile& profile);
};
} // namespace View
} // namespace TrenchBroom

} // namespace TrenchBroom::View
11 changes: 5 additions & 6 deletions common/src/View/GameEngineProfileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@

#include <filesystem>

namespace TrenchBroom
{
namespace View
namespace TrenchBroom::View
{

GameEngineProfileManager::GameEngineProfileManager(
Model::GameEngineConfig config, QWidget* parent)
: QWidget{parent}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
19 changes: 9 additions & 10 deletions common/src/View/GameEngineProfileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(
Expand All @@ -59,5 +58,5 @@ private slots:

void currentProfileChanged(Model::GameEngineProfile* profile);
};
} // namespace View
} // namespace TrenchBroom

} // namespace TrenchBroom::View
16 changes: 12 additions & 4 deletions common/src/View/LaunchGameEngineDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit b7de79d

Please sign in to comment.