Skip to content

Commit

Permalink
Merge pull request TrenchBroom#4217 from TrenchBroom/4211
Browse files Browse the repository at this point in the history
4211: Fix compilation dialog bugs
  • Loading branch information
kduske authored Feb 25, 2023
2 parents 933e719 + 9bc2f5e commit 80d3498
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 90 deletions.
47 changes: 15 additions & 32 deletions common/src/View/CompilationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ namespace TrenchBroom
namespace View
{
CompilationDialog::CompilationDialog(MapFrame* mapFrame)
: QDialog(mapFrame)
, m_mapFrame(mapFrame)
, m_launchButton(nullptr)
, m_compileButton(nullptr)
, m_testCompileButton(nullptr)
, m_stopCompileButton(nullptr)
, m_closeButton(nullptr)
, m_currentRunLabel(nullptr)
, m_output(nullptr)
: QDialog{mapFrame}
, m_mapFrame{mapFrame}
{
ensure(mapFrame != nullptr, "must have a map frame");
createGui();
Expand All @@ -74,42 +67,42 @@ void CompilationDialog::createGui()
auto game = document->game();
auto& compilationConfig = game->compilationConfig();

m_profileManager = new CompilationProfileManager(document, compilationConfig);
m_profileManager = new CompilationProfileManager{document, compilationConfig};

auto* outputPanel = new TitledPanel("Output");
m_output = new QTextEdit();
auto* outputPanel = new TitledPanel{"Output"};
m_output = new QTextEdit{};
m_output->setReadOnly(true);
m_output->setFont(Fonts::fixedWidthFont());

auto* outputLayout = new QVBoxLayout();
auto* outputLayout = new QVBoxLayout{};
outputLayout->setContentsMargins(0, 0, 0, 0);
outputLayout->setSpacing(0);
outputLayout->addWidget(m_output);
outputPanel->getPanel()->setLayout(outputLayout);

auto* splitter = new Splitter(Qt::Vertical);
auto* splitter = new Splitter{Qt::Vertical};
splitter->addWidget(m_profileManager);
splitter->addWidget(m_output);
splitter->setSizes({2, 1});

auto* buttonBox = new QDialogButtonBox();
auto* buttonBox = new QDialogButtonBox{};
m_launchButton = buttonBox->addButton("Launch...", QDialogButtonBox::NoRole);
m_stopCompileButton = buttonBox->addButton("Stop", QDialogButtonBox::NoRole);
m_testCompileButton = buttonBox->addButton("Test", QDialogButtonBox::NoRole);
m_compileButton = buttonBox->addButton("Compile", QDialogButtonBox::NoRole);
m_closeButton = buttonBox->addButton("Close", QDialogButtonBox::RejectRole);

m_currentRunLabel = new QLabel("");
m_currentRunLabel = new QLabel{""};
m_currentRunLabel->setAlignment(Qt::AlignRight);

auto* buttonLayout = new QHBoxLayout();
auto* buttonLayout = new QHBoxLayout{};
buttonLayout->setContentsMargins(0, 0, 0, 0);
buttonLayout->setSpacing(LayoutConstants::WideHMargin);
buttonLayout->addWidget(m_launchButton, 0, Qt::AlignVCenter);
buttonLayout->addWidget(m_currentRunLabel, 1, Qt::AlignVCenter);
buttonLayout->addWidget(buttonBox);

auto* dialogLayout = new QVBoxLayout();
auto* dialogLayout = new QVBoxLayout{};
dialogLayout->setContentsMargins(0, 0, 0, 0);
dialogLayout->setSpacing(0);
dialogLayout->addWidget(splitter, 1);
Expand Down Expand Up @@ -168,21 +161,11 @@ void CompilationDialog::keyPressEvent(QKeyEvent* event)

void CompilationDialog::updateCompileButtons()
{
if (m_run.running())
{
m_compileButton->setEnabled(false);
m_testCompileButton->setEnabled(false);
m_stopCompileButton->setEnabled(true);
}
else
{
const auto* profile = m_profileManager->selectedProfile();
const auto enable = profile && !profile->tasks.empty();
const auto* profile = m_profileManager->selectedProfile();

m_compileButton->setEnabled(enable);
m_testCompileButton->setEnabled(enable);
m_stopCompileButton->setEnabled(false);
}
m_compileButton->setEnabled(!m_run.running() && profile && !profile->tasks.empty());
m_testCompileButton->setEnabled(!m_run.running() && profile && !profile->tasks.empty());
m_stopCompileButton->setEnabled(m_run.running());
}

void CompilationDialog::startCompilation(const bool test)
Expand Down
18 changes: 9 additions & 9 deletions common/src/View/CompilationDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class CompilationDialog : public QDialog
{
Q_OBJECT
private:
MapFrame* m_mapFrame;
CompilationProfileManager* m_profileManager;
QPushButton* m_launchButton;
QPushButton* m_compileButton;
QPushButton* m_testCompileButton;
QPushButton* m_stopCompileButton;
QPushButton* m_closeButton;
QLabel* m_currentRunLabel;
QTextEdit* m_output;
MapFrame* m_mapFrame{nullptr};
CompilationProfileManager* m_profileManager{nullptr};
QPushButton* m_launchButton{nullptr};
QPushButton* m_compileButton{nullptr};
QPushButton* m_testCompileButton{nullptr};
QPushButton* m_stopCompileButton{nullptr};
QPushButton* m_closeButton{nullptr};
QLabel* m_currentRunLabel{nullptr};
QTextEdit* m_output{nullptr};
CompilationRun m_run;

public:
Expand Down
22 changes: 5 additions & 17 deletions common/src/View/CompilationProfileEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,12 @@ void CompilationProfileEditor::removeTask(const int index)
{
assert(index >= 0);

if (m_profile->tasks.size() == 1)
{
m_taskList->setCurrentRow(-1);
m_profile->tasks.clear();
m_taskList->reloadTasks();
}
else if (index > 0)
{
m_taskList->setCurrentRow(index - 1);
kdl::vec_erase_at(m_profile->tasks, size_t(index));
m_taskList->reloadTasks();
}
else
m_profile->tasks = kdl::vec_erase_at(std::move(m_profile->tasks), size_t(index));
m_taskList->reloadTasks();

if (!m_profile->tasks.empty())
{
m_taskList->setCurrentRow(1);
kdl::vec_erase_at(m_profile->tasks, size_t(index));
m_taskList->reloadTasks();
m_taskList->setCurrentRow(0);
m_taskList->setCurrentRow(std::min(index, int(m_profile->tasks.size()) - 1));
}
emit profileChanged();
}
Expand Down
5 changes: 3 additions & 2 deletions common/src/View/CompilationProfileListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ ControlListBoxItemRenderer* CompilationProfileListBox::createItemRenderer(
{
auto& profile = m_config.profiles[index];
auto* renderer = new CompilationProfileItemRenderer{profile, parent};
connect(renderer, &QWidget::customContextMenuRequested, this, [&](const QPoint& pos) {
emit this->profileContextMenuRequested(renderer->mapToGlobal(pos), profile);
connect(renderer, &QWidget::customContextMenuRequested, this, [=](const QPoint& pos) {
emit this->profileContextMenuRequested(
renderer->mapToGlobal(pos), m_config.profiles[index]);
});
return renderer;
}
Expand Down
13 changes: 3 additions & 10 deletions common/src/View/CompilationProfileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,12 @@ void CompilationProfileManager::removeProfile()

void CompilationProfileManager::removeProfile(const size_t index)
{
kdl::vec_erase_at(m_config.profiles, index);
m_config.profiles = kdl::vec_erase_at(m_config.profiles, index);
m_profileList->reloadProfiles();

if (m_profileList->count() > 0)
if (!m_config.profiles.empty())
{
if (static_cast<int>(index) >= m_profileList->count())
{
m_profileList->setCurrentRow(static_cast<int>(index - 1));
}
else
{
m_profileList->setCurrentRow(static_cast<int>(index));
}
m_profileList->setCurrentRow(int(std::min(index, m_config.profiles.size() - 1)));
}
}

Expand Down
54 changes: 36 additions & 18 deletions common/src/View/CompilationRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,31 +424,49 @@ CompilationRunner::~CompilationRunner() = default;
CompilationRunner::TaskRunnerList CompilationRunner::createTaskRunners(
CompilationContext& context, const Model::CompilationProfile& profile)
{
return kdl::vec_transform(profile.tasks, [&](const auto& task) {
return std::visit(
auto result = TaskRunnerList{};
for (const auto& task : profile.tasks)
{
std::visit(
kdl::overload(
[&](const Model::CompilationExportMap& exportMap)
-> std::unique_ptr<CompilationTaskRunner> {
return std::make_unique<CompilationExportMapTaskRunner>(context, exportMap);
[&](const Model::CompilationExportMap& exportMap) {
if (exportMap.enabled)
{
result.push_back(
std::make_unique<CompilationExportMapTaskRunner>(context, exportMap));
}
},
[&](const Model::CompilationCopyFiles& copyFiles)
-> std::unique_ptr<CompilationTaskRunner> {
return std::make_unique<CompilationCopyFilesTaskRunner>(context, copyFiles);
[&](const Model::CompilationCopyFiles& copyFiles) {
if (copyFiles.enabled)
{
result.push_back(
std::make_unique<CompilationCopyFilesTaskRunner>(context, copyFiles));
}
},
[&](const Model::CompilationRenameFile& renameFile)
-> std::unique_ptr<CompilationTaskRunner> {
return std::make_unique<CompilationRenameFileTaskRunner>(context, renameFile);
[&](const Model::CompilationRenameFile& renameFile) {
if (renameFile.enabled)
{
result.push_back(
std::make_unique<CompilationRenameFileTaskRunner>(context, renameFile));
}
},
[&](const Model::CompilationDeleteFiles& deleteFiles)
-> std::unique_ptr<CompilationTaskRunner> {
return std::make_unique<CompilationDeleteFilesTaskRunner>(context, deleteFiles);
[&](const Model::CompilationDeleteFiles& deleteFiles) {
if (deleteFiles.enabled)
{
result.push_back(
std::make_unique<CompilationDeleteFilesTaskRunner>(context, deleteFiles));
}
},
[&](const Model::CompilationRunTool& runTool)
-> std::unique_ptr<CompilationTaskRunner> {
return std::make_unique<CompilationRunToolTaskRunner>(context, runTool);
[&](const Model::CompilationRunTool& runTool) {
if (runTool.enabled)
{
result.push_back(
std::make_unique<CompilationRunToolTaskRunner>(context, runTool));
}
}),
task);
});
}
return result;
}

void CompilationRunner::execute()
Expand Down
5 changes: 3 additions & 2 deletions common/src/View/CompilationTaskListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,9 @@ ControlListBoxItemRenderer* CompilationTaskListBox::createItemRenderer(
}),
task);

connect(renderer, &QWidget::customContextMenuRequested, this, [&](const QPoint& pos) {
emit this->taskContextMenuRequested(renderer->mapToGlobal(pos), task);
connect(renderer, &QWidget::customContextMenuRequested, this, [=](const QPoint& pos) {
emit this->taskContextMenuRequested(
renderer->mapToGlobal(pos), m_profile->tasks[index]);
});

return renderer;
Expand Down

0 comments on commit 80d3498

Please sign in to comment.