X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fshortcutsmodel.cpp;h=fe93e6103dfb8234f951eff516e29cc7f4cfe498;hp=1123137209d5b65f63ec673b596aa0b8922931c1;hb=HEAD;hpb=0a43227b8cd44625f4881cc1545d42c8c8a4876c diff --git a/src/qtui/settingspages/shortcutsmodel.cpp b/src/qtui/settingspages/shortcutsmodel.cpp index 11231372..c9a3b0b5 100644 --- a/src/qtui/settingspages/shortcutsmodel.cpp +++ b/src/qtui/settingspages/shortcutsmodel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -24,20 +24,20 @@ #include "actioncollection.h" #include "util.h" -ShortcutsModel::ShortcutsModel(const QHash &actionCollections, QObject *parent) - : QAbstractItemModel(parent), - _changedCount(0) +ShortcutsModel::ShortcutsModel(const QHash& actionCollections, QObject* parent) + : QAbstractItemModel(parent) + , _changedCount(0) { for (int r = 0; r < actionCollections.values().count(); r++) { - ActionCollection *coll = actionCollections.values().at(r); - Item *item = new Item(); + ActionCollection* coll = actionCollections.values().at(r); + auto* item = new Item(); item->row = r; item->collection = coll; for (int i = 0; i < coll->actions().count(); i++) { - Action *action = qobject_cast(coll->actions().at(i)); + auto* action = qobject_cast(coll->actions().at(i)); if (!action) continue; - Item *actionItem = new Item(); + auto* actionItem = new Item(); actionItem->parentItem = item; actionItem->row = i; actionItem->collection = coll; @@ -49,60 +49,45 @@ ShortcutsModel::ShortcutsModel(const QHash &actionC } } - ShortcutsModel::~ShortcutsModel() { qDeleteAll(_categoryItems); } - -QModelIndex ShortcutsModel::parent(const QModelIndex &child) const +QModelIndex ShortcutsModel::parent(const QModelIndex& child) const { if (!child.isValid()) - return QModelIndex(); + return {}; - Item *item = static_cast(child.internalPointer()); + auto* item = static_cast(child.internalPointer()); Q_ASSERT(item); if (!item->parentItem) - return QModelIndex(); + return {}; return createIndex(item->parentItem->row, 0, item->parentItem); } - -QModelIndex ShortcutsModel::index(int row, int column, const QModelIndex &parent) const +QModelIndex ShortcutsModel::index(int row, int column, const QModelIndex& parent) const { if (parent.isValid()) - return createIndex(row, column, static_cast(parent.internalPointer())->actionItems.at(row)); + return createIndex(row, column, static_cast(parent.internalPointer())->actionItems.at(row)); // top level category item return createIndex(row, column, _categoryItems.at(row)); } - -int ShortcutsModel::columnCount(const QModelIndex &parent) const +int ShortcutsModel::columnCount(const QModelIndex&) const { return 2; - if (!parent.isValid()) - return 2; - - Item *item = static_cast(parent.internalPointer()); - Q_ASSERT(item); - - if (!item->parentItem) - return 2; - - return 2; } - -int ShortcutsModel::rowCount(const QModelIndex &parent) const +int ShortcutsModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) return _categoryItems.count(); - Item *item = static_cast(parent.internalPointer()); + auto* item = static_cast(parent.internalPointer()); Q_ASSERT(item); if (!item->parentItem) @@ -111,7 +96,6 @@ int ShortcutsModel::rowCount(const QModelIndex &parent) const return 0; } - QVariant ShortcutsModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation != Qt::Horizontal || role != Qt::DisplayRole) @@ -126,13 +110,12 @@ QVariant ShortcutsModel::headerData(int section, Qt::Orientation orientation, in } } - -QVariant ShortcutsModel::data(const QModelIndex &index, int role) const +QVariant ShortcutsModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); - Item *item = static_cast(index.internalPointer()); + auto* item = static_cast(index.internalPointer()); Q_ASSERT(item); if (!item->parentItem) { @@ -146,7 +129,7 @@ QVariant ShortcutsModel::data(const QModelIndex &index, int role) const } } - Action *action = qobject_cast(item->action); + auto* action = qobject_cast(item->action); Q_ASSERT(action); switch (role) { @@ -166,7 +149,7 @@ QVariant ShortcutsModel::data(const QModelIndex &index, int role) const return QVariant(); case ActionRole: - return QVariant::fromValue(action); + return QVariant::fromValue(action); case DefaultShortcutRole: return action->shortcut(Action::DefaultShortcut); @@ -181,8 +164,7 @@ QVariant ShortcutsModel::data(const QModelIndex &index, int role) const } } - -bool ShortcutsModel::setData(const QModelIndex &index, const QVariant &value, int role) +bool ShortcutsModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (role != ActiveShortcutRole) return false; @@ -190,7 +172,7 @@ bool ShortcutsModel::setData(const QModelIndex &index, const QVariant &value, in if (!index.parent().isValid()) return false; - Item *item = static_cast(index.internalPointer()); + auto* item = static_cast(index.internalPointer()); Q_ASSERT(item); QKeySequence newSeq = value.value(); @@ -202,46 +184,43 @@ bool ShortcutsModel::setData(const QModelIndex &index, const QVariant &value, in if (oldSeq == storedSeq && newSeq != storedSeq) { if (++_changedCount == 1) - emit hasChanged(true); + emit changed(true); } else if (oldSeq != storedSeq && newSeq == storedSeq) { if (--_changedCount == 0) - emit hasChanged(false); + emit changed(false); } return true; } - void ShortcutsModel::load() { - foreach(Item *catItem, _categoryItems) { - foreach(Item *actItem, catItem->actionItems) { + foreach (Item* catItem, _categoryItems) { + foreach (Item* actItem, catItem->actionItems) { actItem->shortcut = actItem->action->shortcut(Action::ActiveShortcut); } } - emit dataChanged(index(0, 1), index(rowCount()-1, 1)); + emit dataChanged(index(0, 1), index(rowCount() - 1, 1)); if (_changedCount != 0) { _changedCount = 0; - emit hasChanged(false); + emit changed(false); } } - void ShortcutsModel::commit() { - foreach(Item *catItem, _categoryItems) { - foreach(Item *actItem, catItem->actionItems) { + foreach (Item* catItem, _categoryItems) { + foreach (Item* actItem, catItem->actionItems) { actItem->action->setShortcut(actItem->shortcut, Action::ActiveShortcut); } } if (_changedCount != 0) { _changedCount = 0; - emit hasChanged(false); + emit changed(false); } } - void ShortcutsModel::defaults() { for (int cat = 0; cat < rowCount(); cat++) {