diff --git a/src/blackgui/components/hotkeydialog.cpp b/src/blackgui/components/hotkeydialog.cpp index 2e6d865a4..4c221f1d4 100644 --- a/src/blackgui/components/hotkeydialog.cpp +++ b/src/blackgui/components/hotkeydialog.cpp @@ -121,8 +121,7 @@ namespace BlackGui // add local application editDialog.setRegisteredApplications(applications); if (editDialog.exec()) { return editDialog.getSelectedActionHotkey(); } - else { return {}; } - + return {}; } void CHotkeyDialog::ps_advancedModeChanged() @@ -270,7 +269,7 @@ namespace BlackGui for (const auto &token : tokens) { QModelIndex startIndex = m_actionModel.index(0, 0, parentIndex); - auto indexList = m_actionModel.match(startIndex, Qt::DisplayRole, QVariant::fromValue(token)); + const auto indexList = m_actionModel.match(startIndex, Qt::DisplayRole, QVariant::fromValue(token)); if (indexList.isEmpty()) return; parentIndex = indexList.first(); ui->tv_Actions->expand(parentIndex); diff --git a/src/blackgui/models/actionmodel.cpp b/src/blackgui/models/actionmodel.cpp index 65979e978..7a3f82e11 100644 --- a/src/blackgui/models/actionmodel.cpp +++ b/src/blackgui/models/actionmodel.cpp @@ -31,15 +31,16 @@ namespace BlackGui int CActionModel::columnCount(const QModelIndex &parent) const { - if (parent.isValid()) { return static_cast(parent.internalPointer())->getColumnCount(); } - else { return m_rootItem->getColumnCount(); } + return parent.isValid() ? + static_cast(parent.internalPointer())->getColumnCount() : + m_rootItem->getColumnCount(); } QVariant CActionModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } - ActionItem *item = static_cast(index.internalPointer()); + const ActionItem *item = static_cast(index.internalPointer()); if (role == Qt::DisplayRole) { return item->getActionName(); } if (role == ActionRole) { return item->getAction(); } @@ -50,21 +51,24 @@ namespace BlackGui Qt::ItemFlags CActionModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return 0; } - - return QAbstractItemModel::flags(index); + const ActionItem *item = static_cast(index.internalPointer()); + const Qt::ItemFlags flags = QAbstractItemModel::flags(index); + const bool selectable = item && !item->hasChildren(); // only leafs are selectable + return selectable ? flags | Qt::ItemIsSelectable : flags & ~Qt::ItemIsSelectable; } QModelIndex CActionModel::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) { return QModelIndex(); } - ActionItem *parentItem; - if (!parent.isValid()) { parentItem = m_rootItem.data(); } - else { parentItem = static_cast(parent.internalPointer()); } + const ActionItem *parentItem = parent.isValid() ? + static_cast(parent.internalPointer()) : + m_rootItem.data(); ActionItem *childItem = parentItem->getChildByRow(row); - if (childItem) { return createIndex(row, column, childItem); } - else { return {}; } + return childItem ? + createIndex(row, column, childItem) : + QModelIndex(); } QModelIndex CActionModel::parent(const QModelIndex &index) const diff --git a/src/blackgui/models/actionmodel.h b/src/blackgui/models/actionmodel.h index a1d9dec06..b39f47997 100644 --- a/src/blackgui/models/actionmodel.h +++ b/src/blackgui/models/actionmodel.h @@ -28,7 +28,7 @@ namespace BlackGui class ActionItem; /*! - * Action tree model + * Action tree model, used with hotkey actions */ class BLACKGUI_EXPORT CActionModel : public QAbstractItemModel {