Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
1.3 KB
Raw Blame
/*
    SPDX-FileCopyrightText: 2021 Waqar Ahmed <[email protected]>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef COMMANDMODEL_H
#define COMMANDMODEL_H

#include <QAbstractTableModel>
#include <QVector>

class QAction;

class CommandModel : public QAbstractTableModel
{
    struct Item {
        QString component;
        QAction *action;
        int score;
    };

    Q_OBJECT
public:
    CommandModel(QObject *parent = nullptr);

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

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

    int rowCount(const QModelIndex &parent = QModelIndex()) const override
    {
        if (parent.isValid()) {
            return 0;
        }
        return m_rows.size();
    }

    int columnCount(const QModelIndex &parent = QModelIndex()) const override
    {
        Q_UNUSED(parent);
        return 2;
    }

    bool setData(const QModelIndex &index, const QVariant &value, int role) override
    {
        if (!index.isValid()) {
            return false;
        }
        if (role == Role::Score) {
            auto row = index.row();
            m_rows[row].score = value.toInt();
        }
        return QAbstractTableModel::setData(index, value, role);
    }

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

private:
    QVector<Item> m_rows;
};

#endif // COMMANDMODEL_H