Krita Source Code Documentation
Loading...
Searching...
No Matches
kactioncategory.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz>
2
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "kactioncategory.h"
7#include "config-xmlgui.h"
8#include <QAction>
9#include "kstandardaction.h"
10
12
14
17
19 QString text;
20
23
24}; // class KisKActionCategoryPrivate
25
27 : QObject(parent)
28 , d(new KisKActionCategoryPrivate(this))
29{
30 d->text = text;
31}
32
37
39{
40 return d->actions;
41}
42
43QAction *KisKActionCategory::addAction(const QString &name, QAction *action)
44{
45 collection()->addAction(name, action);
46 addAction(action);
47 return action;
48}
49
52 const QObject *receiver,
53 const char *member)
54{
55 QAction *action = collection()->addAction(actionType, receiver, member);
56 addAction(action);
57 return action;
58}
59
62 const QString &name,
63 const QObject *receiver,
64 const char *member)
65{
66 QAction *action = collection()->addAction(actionType, name, receiver, member);
67 addAction(action);
68 return action;
69}
70
72 const QString &name,
73 const QObject *receiver,
74 const char *member)
75{
76 QAction *action = collection()->addAction(name, receiver, member);
77 addAction(action);
78 return action;
79}
80
81void KisKActionCategory::addAction(QAction *action)
82{
83 // Only add the action if wasn't added earlier.
84 if (!d->actions.contains(action)) {
85 d->actions.append(action);
86 }
87}
88
90{
91 return qobject_cast<KisKActionCollection *>(parent());
92}
93
95{
96 return d->text;
97}
98
99void KisKActionCategory::setText(const QString &text)
100{
101 d->text = text;
102}
103
105{
106 // ATTENTION:
107 // This method is called from KisKActionCollection with an QObject formerly
108 // known as a QAction during _k_actionDestroyed(). So don't do fancy stuff
109 // here that needs a real QAction!
110
111 // Get the index for the action
112 int index = d->actions.indexOf(action);
113
114 // Action not found.
115 if (index == -1) {
116 return;
117 }
118
119 // Remove the action
120 d->actions.takeAt(index);
121}
122
126
~KisKActionCategory() override
const QList< QAction * > actions() const
KisKActionCollection * collection() const
void unlistAction(QAction *action)
void setText(const QString &text)
KisKActionCategory(const QString &text, KisKActionCollection *parent=0)
QAction * addAction(const QString &name, QAction *action)
KisKActionCategoryPrivate *const d
Implementation details.
A container for a set of QAction objects.
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
QList< QAction * > actions
List of actions.
KisKActionCategory * q
Our host.
KisKActionCategoryPrivate(KisKActionCategory *host)
QString text
The text for this category.