7 #include <QStringBuilder>
20 CActionModel::CActionModel(QObject *parent)
21 : QAbstractItemModel(parent), m_rootItem(new
CActionItem(QString(), QString()))
31 m_rootItem->getColumnCount();
36 if (!
index.isValid()) {
return QVariant(); }
39 Q_ASSERT_X(item, Q_FUNC_INFO,
"Missing item");
41 if (role == ActionRole) {
return item->
getAction(); }
42 if (role == Qt::DisplayRole) {
return item->
getActionName(); }
43 if (role == Qt::DecorationRole) {
return item->
getIcon(); }
50 if (!
index.isValid()) {
return Qt::NoItemFlags; }
52 const Qt::ItemFlags
flags = QAbstractItemModel::flags(
index);
53 const bool selectable = item && !item->
hasChildren();
54 return selectable ?
flags | Qt::ItemIsSelectable :
flags & ~Qt::ItemIsSelectable;
59 if (!hasIndex(row, column,
parent)) {
return QModelIndex(); }
65 return childItem ? createIndex(row, column, childItem) : QModelIndex();
70 if (!
index.isValid()) {
return {}; }
75 if (parentItem == m_rootItem.data()) {
return {}; }
77 return createIndex(parentItem->
getRow(), 0, parentItem);
82 if (
parent.column() > 0) {
return 0; }
88 void CActionModel::setupModelData()
90 m_rootItem.reset(
new CActionItem(QString(), QString()));
95 QStringList keys = availableActionsAndIcons.keys();
97 for (
const QString &actionPath : std::as_const(keys))
100 const QStringList tokens = actionPath.split(
"/", Qt::SkipEmptyParts);
102 for (
const auto &token : tokens)
104 currentPath += u
'/' % token;
106 if (child ==
nullptr)
108 const bool isAction = currentPath == actionPath;
110 isAction ? availableActionsAndIcons[actionPath] : CIcons::StandardIconEmpty16;
111 child =
new CActionItem(isAction ? actionPath :
"", token, icon, parentItem);
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
CInputManager * getInputManager() const
The input manager, if available.
One single action item in a tree.
QString getAction() const
Returns the stored action.
int getRow() const
Get row of this item.
bool hasChildren() const
Has children?
int getChildCount() const
Number of children.
void appendChild(CActionItem *child)
Append a new child.
CActionItem * getParentItem() const
Get parent item.
CActionItem * getChildByRow(int row) const
Get child by row.
CActionItem * findChildByName(const QString &name) const
Find child by its name.
QString getActionName() const
Get action name.
const QPixmap & getIcon() const
Icon.
QVariant data(const QModelIndex &index, int role) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Qt::ItemFlags flags(const QModelIndex &index) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual ~CActionModel()
Destructor.
QModelIndex parent(const QModelIndex &index) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Backend services of the swift project, like dealing with the network or the simulators.
Models to be used with views, mainly QTableView.
Free functions in swift::misc.