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
46QAction *KActionCategory::addAction(KStandardAction::StandardAction actionType, const QObject *receiver, const char *member)
47{
48 QAction *action = collection()->addAction(actionType, receiver, member);
49 addAction(action);
50 return action;
51}
52
53QAction *KActionCategory::addAction(KStandardAction::StandardAction actionType, const QString &name, const QObject *receiver, const char *member)
54{
55 QAction *action = collection()->addAction(actionType, name, receiver, member);
56 addAction(action);
57 return action;
58}
59
60QAction *KActionCategory::addAction(const QString &name, const QObject *receiver, const char *member)
61{
62 QAction *action = collection()->addAction(name, receiver, member);
63 addAction(action);
64 return action;
65}
66
67void KActionCategory::addAction(QAction *action)
68{
69 // Only add the action if wasn't added earlier.
70 if (!d->actions.contains(t: action)) {
71 d->actions.append(t: action);
72 }
73}
74
75KActionCollection *KActionCategory::collection() const
76{
77 return qobject_cast<KActionCollection *>(object: parent());
78}
79
80QString KActionCategory::text() const
81{
82 return d->text;
83}
84
85void KActionCategory::setText(const QString &text)
86{
87 d->text = text;
88}
89
90void KActionCategory::unlistAction(QAction *action)
91{
92 // ATTENTION:
93 // This method is called from KActionCollection with an QObject formerly
94 // known as a QAction during _k_actionDestroyed(). So don't do fancy stuff
95 // here that needs a real QAction!
96
97 // Get the index for the action
98 int index = d->actions.indexOf(t: action);
99
100 // Action not found.
101 if (index == -1) {
102 return;
103 }
104
105 // Remove the action
106 d->actions.takeAt(i: index);
107}
108
109KActionCategoryPrivate::KActionCategoryPrivate(KActionCategory *host)
110 : q(host)
111{
112}
113
114#include "moc_kactioncategory.cpp"
115

source code of kxmlgui/src/kactioncategory.cpp