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
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
80void KActionCategory::addAction(QAction *action)
81{
82 // Only add the action if wasn't added earlier.
83 if (!d->actions.contains(action)) {
84 d->actions.append(action);
85 }
86}
87
92
93QString KActionCategory::text() const
94{
95 return d->text;
96}
97
99{
100 d->text = text;
101}
102
103void KActionCategory::unlistAction(QAction *action)
104{
105 // ATTENTION:
106 // This method is called from KActionCollection with an QObject formerly
107 // known as a QAction during _k_actionDestroyed(). So don't do fancy stuff
108 // here that needs a real QAction!
109 d->actions.erase(std::remove(d->actions.begin(), d->actions.end(), action), d->actions.end());
110}
111
112KActionCategoryPrivate::KActionCategoryPrivate(KActionCategory *host)
113 : q(host)
114{
115}
116
117#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.
QObject * parent() const const
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.