1/*
2 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "kactioncategory.h"
8
9#include <QAction>
10
11struct KActionCategoryPrivate {
12 KActionCategoryPrivate(KActionCategory *host);
13
14 //! Our host
15 KActionCategory *q;
16
17 //! The text for this category
18 QString text;
19
20 //! List of actions
21 QList<QAction *> actions;
22
23}; // class KActionCategoryPrivate
24
25KActionCategory::KActionCategory(const QString &text, KActionCollection *parent)
26 : QObject(parent)
27 , d(new KActionCategoryPrivate(this))
28{
29 d->text = text;
30}
31
32KActionCategory::~KActionCategory() = default;
33
34const QList<QAction *> KActionCategory::actions() const
35{
36 return d->actions;
37}
38
39QAction *KActionCategory::addAction(const QString &name, QAction *action)
40{
41 collection()->addAction(name, action);
42 addAction(action);
43 return action;
44}
45
46#if KXMLGUI_BUILD_DEPRECATED_SINCE(6, 9)
47QAction *KActionCategory::addAction(KStandardAction::StandardAction actionType, const QObject *receiver, const char *member)
48{
49 QAction *action = collection()->addAction(actionType, receiver, member);
50 addAction(action);
51 return action;
52}
53#endif
54
55#if KXMLGUI_BUILD_DEPRECATED_SINCE(6, 9)
56QAction *KActionCategory::addAction(KStandardAction::StandardAction actionType, const QString &name, const QObject *receiver, const char *member)
57{
58 QAction *action = collection()->addAction(actionType, name, receiver, member);
59 addAction(action);
60 return action;
61}
62#endif
63
64#if KXMLGUI_ENABLE_DEPRECATED_SINCE(6, 9)
65QAction *KActionCategory::addAction(const QString &name, const QObject *receiver, const char *member)
66{
67 QAction *action = collection()->addAction(name, receiver, member);
68 addAction(action);
69 return action;
70}
71#endif
72
73QAction *KActionCategory::addAction(KStandardActions::StandardAction actionType)
74{
75 QAction *action = collection()->addAction(actionType);
76 addAction(action);
77 return action;
78}
79
80QAction *KActionCategory::addAction(KStandardActions::StandardAction actionType, const QString &name)
81{
82 QAction *action = collection()->addAction(actionType, name);
83 addAction(action);
84 return action;
85}
86
87void KActionCategory::addAction(QAction *action)
88{
89 // Only add the action if wasn't added earlier.
90 if (!d->actions.contains(t: action)) {
91 d->actions.append(t: action);
92 }
93}
94
95KActionCollection *KActionCategory::collection() const
96{
97 return qobject_cast<KActionCollection *>(object: parent());
98}
99
100QString KActionCategory::text() const
101{
102 return d->text;
103}
104
105void KActionCategory::setText(const QString &text)
106{
107 d->text = text;
108}
109
110void KActionCategory::unlistAction(QAction *action)
111{
112 // ATTENTION:
113 // This method is called from KActionCollection with an QObject formerly
114 // known as a QAction during _k_actionDestroyed(). So don't do fancy stuff
115 // here that needs a real QAction!
116 d->actions.erase(abegin: std::remove(first: d->actions.begin(), last: d->actions.end(), value: action), aend: d->actions.end());
117}
118
119KActionCategoryPrivate::KActionCategoryPrivate(KActionCategory *host)
120 : q(host)
121{
122}
123
124#include "moc_kactioncategory.cpp"
125

source code of kxmlgui/src/kactioncategory.cpp