Krita Source Code Documentation
Loading...
Searching...
No Matches
CommandModel Class Reference

#include <commandmodel.h>

+ Inheritance diagram for CommandModel:

Classes

struct  Item
 

Public Types

enum  Role { Score = Qt::UserRole + 1 }
 

Public Member Functions

int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
 CommandModel (QObject *parent=nullptr)
 
QVariant data (const QModelIndex &index, int role) const override
 
void refresh (QVector< QPair< QString, QAction * > > actionList)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 

Private Attributes

QVector< Itemm_rows
 

Detailed Description

Definition at line 14 of file commandmodel.h.

Member Enumeration Documentation

◆ Role

Enumerator
Score 

Definition at line 26 of file commandmodel.h.

26{ Score = Qt::UserRole + 1 };

Constructor & Destructor Documentation

◆ CommandModel()

CommandModel::CommandModel ( QObject * parent = nullptr)

Definition at line 12 of file commandmodel.cpp.

13 : QAbstractTableModel(parent)
14{
15}

Member Function Documentation

◆ columnCount()

int CommandModel::columnCount ( const QModelIndex & parent = QModelIndex()) const
inlineoverride

Definition at line 38 of file commandmodel.h.

39 {
40 Q_UNUSED(parent);
41 return 2;
42 }

◆ data()

QVariant CommandModel::data ( const QModelIndex & index,
int role ) const
override

Definition at line 30 of file commandmodel.cpp.

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
QVector< Item > m_rows

References m_rows, Score, and v.

◆ refresh()

void CommandModel::refresh ( QVector< QPair< QString, QAction * > > actionList)

Definition at line 17 of file commandmodel.cpp.

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}

References m_rows.

◆ rowCount()

int CommandModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
inlineoverride

Definition at line 30 of file commandmodel.h.

31 {
32 if (parent.isValid()) {
33 return 0;
34 }
35 return m_rows.size();
36 }
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References m_rows.

◆ setData()

bool CommandModel::setData ( const QModelIndex & index,
const QVariant & value,
int role )
inlineoverride

Definition at line 44 of file commandmodel.h.

45 {
46 if (!index.isValid()) {
47 return false;
48 }
49 if (role == Role::Score) {
50 auto row = index.row();
51 m_rows[row].score = value.toInt();
52 }
53 return QAbstractTableModel::setData(index, value, role);
54 }
float value(const T *src, size_t ch)

References m_rows, Score, and value().

Member Data Documentation

◆ m_rows

QVector<Item> CommandModel::m_rows
private

Definition at line 59 of file commandmodel.h.


The documentation for this class was generated from the following files: