KXmlGui

kactioncategory.cpp
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
16
17 //! The text for this category
18 QString text;
19
20 //! List of actions
21 QList<QAction *> actions;
22
23}; // class KActionCategoryPrivate
24
26 : QObject(parent)
27 , d(new KActionCategoryPrivate(this))
28{
29 d->text = text;
30}
31
33
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(action)) {
71 d->actions.append(action);
72 }
73}
74
79
80QString KActionCategory::text() const
81{
82 return d->text;
83}
84
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(action);
99
100 // Action not found.
101 if (index == -1) {
102 return;
103 }
104
105 // Remove the action
106 d->actions.takeAt(index);
107}
108
109KActionCategoryPrivate::KActionCategoryPrivate(KActionCategory *host)
110 : q(host)
111{
112}
113
114#include "moc_kactioncategory.cpp"
Categorize actions for KShortcutsEditor.
const QList< QAction * > actions() const
Returns the actions belonging to this category.
KActionCategory(const QString &text, KActionCollection *parent=nullptr)
Default constructor.
~KActionCategory() override
Destructor.
void setText(const QString &text)
Set the action categorys descriptive text.
KActionCollection * collection() const
The action collection this category is associated with.
A container for a set of QAction objects.
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
Add an action under the given name to the collection.
QList< T > findChildren(Qt::FindChildOptions options) const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.