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
12
CommandModel::CommandModel
(QObject *parent)
13
: QAbstractTableModel(parent)
14
{
15
}
16
17
void
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
30
QVariant
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
}
v
qreal v
Definition
KisBezierUtils.cpp:702
CommandModel::CommandModel
CommandModel(QObject *parent=nullptr)
Definition
commandmodel.cpp:12
CommandModel::m_rows
QVector< Item > m_rows
Definition
commandmodel.h:59
CommandModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition
commandmodel.cpp:30
CommandModel::Score
@ Score
Definition
commandmodel.h:26
CommandModel::refresh
void refresh(QVector< QPair< QString, QAction * > > actionList)
Definition
commandmodel.cpp:17
QList
Definition
KisQStringListFwd.h:16
commandmodel.h
libs
widgetutils
commandmodel.cpp
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52