Krita Source Code Documentation
Loading...
Searching...
No Matches
commandmodel.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2021 Waqar Ahmed <waqar.17a@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "commandmodel.h"
7
8#include <KLocalizedString>
9#include <QAction>
10#include <QDebug>
11
13 : QAbstractTableModel(parent)
14{
15}
16
17void CommandModel::refresh(QVector<QPair<QString, QAction *>> actionList)
18{
19 QVector<Item> temp;
20 temp.reserve(actionList.size());
21 for (const auto &action : std::as_const(actionList)) {
22 temp.push_back({action.first, action.second, 0});
23 }
24
25 beginResetModel();
26 m_rows = std::move(temp);
27 endResetModel();
28}
29
30QVariant CommandModel::data(const QModelIndex &index, int role) const
31{
32 if (!index.isValid()) {
33 return {};
34 };
35
36 auto entry = m_rows[index.row()];
37 int col = index.column();
38
39 switch (role) {
40 case Qt::DisplayRole:
41 if (col == 0) {
42 return QString(entry.component + QStringLiteral(": ") + KLocalizedString::removeAcceleratorMarker(entry.action->text()));
43 } else {
44 return entry.action->shortcut().toString();
45 }
46 case Qt::DecorationRole:
47 if (col == 0) {
48 return entry.action->icon();
49 }
50 break;
51 case Qt::TextAlignmentRole:
52 if (col == 0) {
53 return Qt::AlignLeft;
54 } else {
55 return Qt::AlignRight;
56 }
57 case Qt::UserRole: {
58 QVariant v;
59 v.setValue(entry.action);
60 return v;
61 }
62 case Role::Score:
63 return entry.score;
64 }
65
66 return {};
67}
qreal v
CommandModel(QObject *parent=nullptr)
QVector< Item > m_rows
QVariant data(const QModelIndex &index, int role) const override
void refresh(QVector< QPair< QString, QAction * > > actionList)