From 3a2618fadb5f079a02de518d972ad314870516bb Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sun, 5 Mar 2017 14:08:45 +0100 Subject: [PATCH] Pass application list directly to CHotkeyDialog constructor The list of applications is already known when the CHotkeyDialog object is constructed. So there was no good reason to defer this to a later time with a setter. In contrast, supporting a setter function was much more complex, since internally all GUI signals were already connected and more carefull case handling would be necessary (e.g. the machine combobox would change its index). Therefore the setter is removed in favor of passing the application list directly to the constructor. This fixes also an issue that the machine name was not properly set up in the dialog when editing a hotkey. This also reverts the change from CIdentifier to string based machine handling. refs #881 --- src/blackgui/components/hotkeydialog.cpp | 28 +++++++++++++----------- src/blackgui/components/hotkeydialog.h | 5 +---- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/blackgui/components/hotkeydialog.cpp b/src/blackgui/components/hotkeydialog.cpp index 7fa0767e4..c020a86bd 100644 --- a/src/blackgui/components/hotkeydialog.cpp +++ b/src/blackgui/components/hotkeydialog.cpp @@ -63,7 +63,7 @@ namespace BlackGui m_oldIndex = index; } - CHotkeyDialog::CHotkeyDialog(const CActionHotkey &actionHotkey, QWidget *parent) : + CHotkeyDialog::CHotkeyDialog(const CActionHotkey &actionHotkey, const BlackMisc::CIdentifierList &applications, QWidget *parent) : QDialog(parent), ui(new Ui::CHotkeyDialog), m_actionHotkey(actionHotkey), @@ -80,6 +80,19 @@ namespace BlackGui if (!actionHotkey.getCombination().isEmpty()) { ui->pb_SelectedHotkey->setText(actionHotkey.getCombination().toQString()); } + CIdentifierList machinesUnique = applications.getMachinesUnique(); + int index = -1; + for (const auto &app : machinesUnique) + { + ui->cb_Identifier->addItem(app.getMachineName(), QVariant::fromValue(app)); + if (m_actionHotkey.getApplicableMachine().isFromSameMachine(app)) { index = ui->cb_Identifier->count() - 1; } + } + + if (index != ui->cb_Identifier->currentIndex()) + { + ui->cb_Identifier->setCurrentIndex(index); + } + connect(ui->pb_AdvancedMode, &QPushButton::clicked, this, &CHotkeyDialog::ps_advancedModeChanged); connect(ui->pb_SelectedHotkey, &QPushButton::clicked, this, &CHotkeyDialog::ps_selectHotkey); connect(ui->pb_Accept, &QPushButton::clicked, this, &CHotkeyDialog::ps_accept); @@ -94,15 +107,6 @@ namespace BlackGui CHotkeyDialog::~CHotkeyDialog() { } - void CHotkeyDialog::setRegisteredApplications(const CIdentifierList &applications) - { - const QStringList machines = applications.getMachineNames(); - for (const QString &machine : machines) - { - ui->cb_Identifier->addItem(machine); - } - } - void CHotkeyDialog::initStyleSheet() { const QString s = sGui->getStyleSheetUtility().styles( @@ -116,10 +120,8 @@ namespace BlackGui CActionHotkey CHotkeyDialog::getActionHotkey(const CActionHotkey &initial, const CIdentifierList &applications, QWidget *parent) { - CHotkeyDialog editDialog(initial, parent); + CHotkeyDialog editDialog(initial, applications, parent); editDialog.setWindowModality(Qt::WindowModal); - // add local application - editDialog.setRegisteredApplications(applications); if (editDialog.exec()) { return editDialog.getSelectedActionHotkey(); } return {}; } diff --git a/src/blackgui/components/hotkeydialog.h b/src/blackgui/components/hotkeydialog.h index eeb560556..559f08f40 100644 --- a/src/blackgui/components/hotkeydialog.h +++ b/src/blackgui/components/hotkeydialog.h @@ -67,7 +67,7 @@ namespace BlackGui public: //! Constructor - CHotkeyDialog(const BlackMisc::Input::CActionHotkey &actionHotkey, QWidget *parent = nullptr); + CHotkeyDialog(const BlackMisc::Input::CActionHotkey &actionHotkey, const BlackMisc::CIdentifierList &applications, QWidget *parent = nullptr); //! Destructor virtual ~CHotkeyDialog(); @@ -75,9 +75,6 @@ namespace BlackGui //! Get hotkey selected by user BlackMisc::Input::CActionHotkey getSelectedActionHotkey() const { return m_actionHotkey; } - //! Set registered applications - void setRegisteredApplications(const BlackMisc::CIdentifierList &applications); - //! Init style sheet void initStyleSheet();