Skip to content

Commit

Permalink
Fix bugs in compilation profile editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kduske committed Feb 24, 2023
1 parent 4cf21dd commit 3d948aa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 31 deletions.
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
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 3d948aa

Please sign in to comment.