File indexing completed on 2024-06-16 04:16:23
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Sven Langkamp <sven.langkamp@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "tasksetmodel.h" 0008 0009 #include <QAction> 0010 #include <klocalizedstring.h> 0011 #include <kis_icon.h> 0012 0013 TasksetModel::TasksetModel(QObject* parent): QAbstractTableModel(parent) 0014 { 0015 } 0016 0017 TasksetModel::~TasksetModel() 0018 { 0019 } 0020 0021 QVariant TasksetModel::data(const QModelIndex& index, int role) const 0022 { 0023 if (index.isValid()) { 0024 0025 switch (role) { 0026 case Qt::DisplayRole: 0027 { 0028 return m_actions.at(index.row())->iconText(); 0029 } 0030 case Qt::DecorationRole: 0031 { 0032 const QIcon icon = m_actions.at(index.row())->icon(); 0033 if (icon.isNull()) { 0034 return KisIconUtils::loadIcon("tools-wizard"); 0035 } 0036 return icon; 0037 } 0038 } 0039 } 0040 return QVariant(); 0041 } 0042 0043 QVariant TasksetModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int /*role*/) const 0044 { 0045 return i18n("Task"); 0046 } 0047 0048 0049 int TasksetModel::rowCount(const QModelIndex& /*parent*/) const 0050 { 0051 return m_actions.count(); 0052 } 0053 0054 int TasksetModel::columnCount(const QModelIndex& /*parent*/) const 0055 { 0056 return 1; 0057 } 0058 0059 Qt::ItemFlags TasksetModel::flags(const QModelIndex& /*index*/) const 0060 { 0061 Qt::ItemFlags flags = /*Qt::ItemIsSelectable |*/ Qt::ItemIsEnabled; 0062 return flags; 0063 } 0064 0065 void TasksetModel::addAction(QAction* action) 0066 { 0067 m_actions.append(action); 0068 beginResetModel(); 0069 endResetModel(); 0070 } 0071 0072 QVector< QAction* > TasksetModel::actions() 0073 { 0074 return m_actions; 0075 } 0076 0077 QAction* TasksetModel::actionFromIndex(const QModelIndex& index) 0078 { 0079 if(index.isValid()) { 0080 return m_actions.at(index.row()); 0081 } 0082 return 0; 0083 } 0084 0085 void TasksetModel::clear() 0086 { 0087 m_actions.clear(); 0088 beginResetModel(); 0089 endResetModel(); 0090 } 0091