Krita Source Code Documentation
Loading...
Searching...
No Matches
commandmodel.h
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#ifndef COMMANDMODEL_H
7#define COMMANDMODEL_H
8
9#include <QAbstractTableModel>
10#include <QVector>
11
12class QAction;
13
14class CommandModel : public QAbstractTableModel
15{
16 struct Item {
17 QString component;
18 QAction *action;
19 int score;
20 };
21
22 Q_OBJECT
23public:
24 CommandModel(QObject *parent = nullptr);
25
26 enum Role { Score = Qt::UserRole + 1 };
27
28 void refresh(QVector<QPair<QString, QAction *>> actionList);
29
30 int rowCount(const QModelIndex &parent = QModelIndex()) const override
31 {
32 if (parent.isValid()) {
33 return 0;
34 }
35 return m_rows.size();
36 }
37
38 int columnCount(const QModelIndex &parent = QModelIndex()) const override
39 {
40 Q_UNUSED(parent);
41 return 2;
42 }
43
44 bool setData(const QModelIndex &index, const QVariant &value, int role) override
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 }
55
56 QVariant data(const QModelIndex &index, int role) const override;
57
58private:
60};
61
62#endif // COMMANDMODEL_H
float value(const T *src, size_t ch)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
CommandModel(QObject *parent=nullptr)
QVector< Item > m_rows
QVariant data(const QModelIndex &index, int role) const override
void refresh(QVector< QPair< QString, QAction * > > actionList)