From ef4640e66f18800c3ae16236d853648dcd90a3c6 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 24 Nov 2019 19:32:44 +0100 Subject: [PATCH] [Hotkey] Style --- src/blackcore/inputmanager.cpp | 6 ++- src/blackgui/components/hotkeydialog.cpp | 6 +-- src/blackgui/models/actionhotkeylistmodel.cpp | 25 +++++------- src/blackgui/models/actionhotkeylistmodel.h | 5 ++- src/blackmisc/input/actionhotkey.cpp | 12 +++--- src/blackmisc/input/actionhotkey.h | 4 +- src/blackmisc/input/hotkeycombination.cpp | 2 +- src/blackmisc/input/hotkeycombination.h | 2 +- src/blackmisc/input/joystickbutton.cpp | 39 ++++++++----------- src/blackmisc/input/joystickbutton.h | 13 ++++--- 10 files changed, 54 insertions(+), 60 deletions(-) diff --git a/src/blackcore/inputmanager.cpp b/src/blackcore/inputmanager.cpp index fc6872b23..9e64f0434 100644 --- a/src/blackcore/inputmanager.cpp +++ b/src/blackcore/inputmanager.cpp @@ -76,6 +76,7 @@ namespace BlackCore void CInputManager::processKeyCombinationChanged(const CHotkeyCombination &combination) { // Merge in the joystick part + // mixed on purpose, as any joystick keyboard combination is possible CHotkeyCombination copy(combination); copy.setJoystickButtons(m_lastCombination.getJoystickButtons()); processCombination(copy); @@ -83,7 +84,8 @@ namespace BlackCore void CInputManager::processButtonCombinationChanged(const CHotkeyCombination &combination) { - // Merge in the keyboard dkeys + // Merge in the keyboard keys + // mixed on purpose, as any joystick keyboard combination is possible CHotkeyCombination copy(combination); copy.setKeyboardKeys(m_lastCombination.getKeyboardKeys()); processCombination(copy); @@ -124,7 +126,7 @@ namespace BlackCore { m_keyboard = IKeyboard::create(this); m_joystick = IJoystick::create(this); - connect(m_keyboard.get(), &IKeyboard::keyCombinationChanged, this, &CInputManager::processKeyCombinationChanged, Qt::QueuedConnection); + connect(m_keyboard.get(), &IKeyboard::keyCombinationChanged, this, &CInputManager::processKeyCombinationChanged, Qt::QueuedConnection); connect(m_joystick.get(), &IJoystick::buttonCombinationChanged, this, &CInputManager::processButtonCombinationChanged, Qt::QueuedConnection); } diff --git a/src/blackgui/components/hotkeydialog.cpp b/src/blackgui/components/hotkeydialog.cpp index b016a7605..ac47715c7 100644 --- a/src/blackgui/components/hotkeydialog.cpp +++ b/src/blackgui/components/hotkeydialog.cpp @@ -113,7 +113,7 @@ namespace BlackGui if (sGui && sGui->getInputManager()) { - connect(sGui->getInputManager(), &BlackCore::CInputManager::combinationSelectionChanged, this, &CHotkeyDialog::combinationSelectionChanged); + connect(sGui->getInputManager(), &BlackCore::CInputManager::combinationSelectionChanged, this, &CHotkeyDialog::combinationSelectionChanged); connect(sGui->getInputManager(), &BlackCore::CInputManager::combinationSelectionFinished, this, &CHotkeyDialog::combinationSelectionFinished); } @@ -199,7 +199,7 @@ namespace BlackGui void CHotkeyDialog::changeSelectedAction(const QItemSelection &selected, const QItemSelection &deselected) { - Q_UNUSED(deselected); + Q_UNUSED(deselected) if (selected.indexes().isEmpty()) { return; } const auto index = selected.indexes().first(); m_actionHotkey.setAction(index.data(CActionModel::ActionRole).toString()); @@ -265,7 +265,7 @@ namespace BlackGui void CHotkeyDialog::changeApplicableMachine(int index) { - Q_UNUSED(index); + Q_UNUSED(index) const QVariant userData = ui->cb_Identifier->currentData(); Q_ASSERT(userData.canConvert()); m_actionHotkey.setApplicableMachine(userData.value()); diff --git a/src/blackgui/models/actionhotkeylistmodel.cpp b/src/blackgui/models/actionhotkeylistmodel.cpp index 3d8685c35..8bb5a13e3 100644 --- a/src/blackgui/models/actionhotkeylistmodel.cpp +++ b/src/blackgui/models/actionhotkeylistmodel.cpp @@ -24,8 +24,7 @@ namespace BlackGui { CActionHotkeyListModel::CActionHotkeyListModel(QObject *parent) : QAbstractTableModel(parent) - { - } + { } int CActionHotkeyListModel::rowCount(const QModelIndex & /** parent **/) const { @@ -40,14 +39,13 @@ namespace BlackGui QVariant CActionHotkeyListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } - if (index.row() >= m_actionHotkeys.size() || index.row() < 0) { return QVariant(); } if (role == Qt::DisplayRole) { if (index.column() == 0) { - BlackMisc::CIdentifier identifier = m_actionHotkeys[index.row()].getApplicableMachine(); + const CIdentifier identifier = m_actionHotkeys[index.row()].getApplicableMachine(); return identifier.getMachineName(); } if (index.column() == 1) @@ -62,7 +60,7 @@ namespace BlackGui } else if (role == ActionHotkeyRole) { - auto hotkey = m_actionHotkeys[index.row()]; + const auto hotkey = m_actionHotkeys[index.row()]; return QVariant::fromValue(hotkey); } return {}; @@ -72,15 +70,13 @@ namespace BlackGui { if (role == Qt::DisplayRole) { - if (orientation == Qt::Horizontal) { + if (orientation == Qt::Horizontal) + { switch (section) { - case 0: - return QStringLiteral("Machine"); - case 1: - return QStringLiteral("Combination"); - case 2: - return QStringLiteral("Action"); + case 0: return QStringLiteral("Machine"); + case 1: return QStringLiteral("Combination"); + case 2: return QStringLiteral("Action"); } } } @@ -89,7 +85,7 @@ namespace BlackGui bool CActionHotkeyListModel::insertRows(int position, int rows, const QModelIndex &index) { - Q_UNUSED(index); + Q_UNUSED(index) beginInsertRows(QModelIndex(), position, position + rows - 1); for (int row = 0; row < rows; ++row) @@ -103,7 +99,7 @@ namespace BlackGui bool CActionHotkeyListModel::removeRows(int position, int rows, const QModelIndex &index) { - Q_UNUSED(index); + Q_UNUSED(index) beginRemoveRows(QModelIndex(), position, position + rows - 1); Q_ASSERT(position + rows - 1 < m_actionHotkeys.size()); @@ -136,6 +132,5 @@ namespace BlackGui m_actionHotkeys.clear(); endResetModel(); } - } } // namespace diff --git a/src/blackgui/models/actionhotkeylistmodel.h b/src/blackgui/models/actionhotkeylistmodel.h index 64aeeb515..aecc47a91 100644 --- a/src/blackgui/models/actionhotkeylistmodel.h +++ b/src/blackgui/models/actionhotkeylistmodel.h @@ -71,6 +71,7 @@ namespace BlackGui private: BlackMisc::Input::CActionHotkeyList m_actionHotkeys; }; - } -} + } // ns +} // ns + #endif // guard diff --git a/src/blackmisc/input/actionhotkey.cpp b/src/blackmisc/input/actionhotkey.cpp index 6c765e6b6..d5a3a3131 100644 --- a/src/blackmisc/input/actionhotkey.cpp +++ b/src/blackmisc/input/actionhotkey.cpp @@ -69,13 +69,13 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexIdentifier: return CVariant::from(m_identifier); - case IndexIdentifierAsString: return CVariant::from(m_identifier.getMachineName()); - case IndexAction: return CVariant::from(m_action); - case IndexActionAsString: return CVariant::from(m_action); - case IndexCombination: return CVariant::from(m_combination); + case IndexIdentifier: return CVariant::from(m_identifier); + case IndexIdentifierAsString: return CVariant::from(m_identifier.getMachineName()); + case IndexAction: return CVariant::from(m_action); + case IndexActionAsString: return CVariant::from(m_action); + case IndexCombination: return CVariant::from(m_combination); case IndexCombinationAsString: return CVariant::from(QString(m_combination.toQString())); - default: return CValueObject::propertyByIndex(index); + default: return CValueObject::propertyByIndex(index); } } diff --git a/src/blackmisc/input/actionhotkey.h b/src/blackmisc/input/actionhotkey.h index 294a0227b..0f61f883c 100644 --- a/src/blackmisc/input/actionhotkey.h +++ b/src/blackmisc/input/actionhotkey.h @@ -100,9 +100,9 @@ namespace BlackMisc QString convertToQString(bool i18n = false) const; private: - CIdentifier m_identifier; //!< Identifier to which machine this hotkey belongs to + CIdentifier m_identifier; //!< Identifier to which machine this hotkey belongs to CHotkeyCombination m_combination; //!< hotkey combination - QString m_action; //!< hotkey action + QString m_action; //!< hotkey action BLACK_METACLASS( CActionHotkey, diff --git a/src/blackmisc/input/hotkeycombination.cpp b/src/blackmisc/input/hotkeycombination.cpp index 6383cd0de..0c5a5912a 100644 --- a/src/blackmisc/input/hotkeycombination.cpp +++ b/src/blackmisc/input/hotkeycombination.cpp @@ -102,7 +102,7 @@ namespace BlackMisc QString CHotkeyCombination::convertToQString(bool i18n) const { - Q_UNUSED(i18n); + Q_UNUSED(i18n) QStringList sl; sl.reserve(m_keyboardKeys.size() + m_joystickButtons.size()); for (const auto &key : m_keyboardKeys) diff --git a/src/blackmisc/input/hotkeycombination.h b/src/blackmisc/input/hotkeycombination.h index c18edb5f4..97038959d 100644 --- a/src/blackmisc/input/hotkeycombination.h +++ b/src/blackmisc/input/hotkeycombination.h @@ -98,7 +98,7 @@ namespace BlackMisc QString asStringWithDeviceNames() const; private: - CKeyboardKeyList m_keyboardKeys; + CKeyboardKeyList m_keyboardKeys; CJoystickButtonList m_joystickButtons; BLACK_METACLASS( diff --git a/src/blackmisc/input/joystickbutton.cpp b/src/blackmisc/input/joystickbutton.cpp index b5aa6cfb8..236f63034 100644 --- a/src/blackmisc/input/joystickbutton.cpp +++ b/src/blackmisc/input/joystickbutton.cpp @@ -7,7 +7,6 @@ */ #include "blackmisc/input/joystickbutton.h" - #include "blackmisc/variant.h" namespace BlackMisc @@ -20,7 +19,7 @@ namespace BlackMisc QString CJoystickButton::getButtonAsStringWithDeviceName() const { - return QString("%1 Button%2").arg(m_deviceName).arg(m_buttonIndex); + return QStringLiteral("%1%2 - %3").arg(buttonIndentifier()).arg(m_buttonIndex).arg(m_deviceName); } void CJoystickButton::setButtonIndex(int buttonIndex) @@ -30,20 +29,19 @@ namespace BlackMisc bool CJoystickButton::isValid() const { - if (!m_deviceName.isEmpty() && m_buttonIndex >= 0) { return true; } - else { return false; } + return (!m_deviceName.isEmpty() && m_buttonIndex >= 0); } void CJoystickButton::setButtonObject(CJoystickButton button) { - m_deviceName = button.m_deviceName; + m_deviceName = button.m_deviceName; m_buttonIndex = button.m_buttonIndex; } void CJoystickButton::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { (*this) = variant.to(); return; } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexDeviceName: @@ -65,13 +63,13 @@ namespace BlackMisc CVariant CJoystickButton::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexDeviceName: return CVariant::from(this->getDeviceName()); - case IndexButton: return CVariant::from(this->getButtonIndex()); + case IndexDeviceName: return CVariant::from(this->getDeviceName()); + case IndexButton: return CVariant::from(this->getButtonIndex()); case IndexButtonAsString: return CVariant::from(this->getButtonAsString()); - case IndexButtonObject: return CVariant::from(*this); + case IndexButtonObject: return CVariant::from(*this); } Q_ASSERT_X(false, "CJoystickButton", "index unknown"); @@ -81,25 +79,22 @@ namespace BlackMisc QString CJoystickButton::buttonIndexToString(qint32 buttonIndex) { - QString buttonString("Button"); - return buttonString.append(QStringLiteral("%1").arg(buttonIndex)); + return buttonIndentifier() + QString::number(buttonIndex); } int CJoystickButton::buttonIndexFromString(const QString &buttonName) { - QString name("Button"); - if (!buttonName.startsWith(name)) return getInvalidIndex(); - - name.remove("Button"); - return name.toInt(); + if (!buttonName.startsWith(buttonIndentifier())) { return getInvalidIndex(); } + QString name(buttonName); + name.remove(buttonIndentifier()); + if (name.contains('-')) { name = name.mid(0, name.indexOf('-')); } + return name.trimmed().toInt(); } QString CJoystickButton::convertToQString(bool /* i18n */) const { - QString s = getButtonAsString(); - return s.trimmed(); + return getButtonAsString().trimmed(); } - } // namespace Hardware - -} // BlackMisc + } // namespace +} // namespacexs diff --git a/src/blackmisc/input/joystickbutton.h b/src/blackmisc/input/joystickbutton.h index a3d1bab80..6541fb719 100644 --- a/src/blackmisc/input/joystickbutton.h +++ b/src/blackmisc/input/joystickbutton.h @@ -81,16 +81,17 @@ namespace BlackMisc static int buttonIndexFromString(const QString &button); //! Invalid button index - static int getInvalidIndex() { return m_invalidIndex; } + static int getInvalidIndex() { return InvalidButtonIndex; } //! \copydoc BlackMisc::Mixin::String::toQString QString convertToQString(bool i18n = false) const; private: - QString m_deviceName; - int m_buttonIndex = m_invalidIndex; + static const QString &buttonIndentifier() { static const QString bn("Button"); return bn; } + static constexpr int InvalidButtonIndex = -1; - static constexpr int m_invalidIndex = -1; + QString m_deviceName; + int m_buttonIndex = InvalidButtonIndex; BLACK_METACLASS( CJoystickButton, @@ -98,8 +99,8 @@ namespace BlackMisc BLACK_METAMEMBER(buttonIndex) ); }; - } -} + } // ns +} // ns Q_DECLARE_METATYPE(BlackMisc::Input::CJoystickButton)