KXmlGui

kactioncategory.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Michael Jansen <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "kactioncategory.h"
8 
9 #include <QAction>
10 
11 struct KActionCategoryPrivate {
12 
13  KActionCategoryPrivate(KActionCategory *host);
14 
16  KActionCategory *q;
17 
19  QString text;
20 
22  QList<QAction *> actions;
23 
24 }; // class KActionCategoryPrivate
25 
27  : QObject(parent)
28  , d(new KActionCategoryPrivate(this))
29 {
30  d->text = text;
31 }
32 
34 {
35  delete d;
36 }
37 
39 {
40  return d->actions;
41 }
42 
43 QAction *KActionCategory::addAction(const QString &name, QAction *action)
44 {
45  collection()->addAction(name, action);
46  addAction(action);
47  return action;
48 }
49 
50 QAction *KActionCategory::addAction(
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 
60 QAction *KActionCategory::addAction(
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 
71 QAction *KActionCategory::addAction(
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 
81 void KActionCategory::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 {
92 }
93 
95 {
96  return d->text;
97 }
98 
100 {
101  d->text = text;
102 }
103 
104 void KActionCategory::unlistAction(QAction *action)
105 {
106  // ATTENTION:
107  // This method is called from KActionCollection 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 
123 KActionCategoryPrivate::KActionCategoryPrivate(KActionCategory *host)
124  : q(host)
125 {}
126 
Categorize actions for KShortcutsEditor.
A container for a set of QAction objects.
virtual ~KActionCategory()
Destructor.
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
Add an action under the given name to the collection.
KActionCollection * collection() const
The action collection this category is associated with.
QString text() const
The action categorys descriptive text.
KActionCategory(const QString &text, KActionCollection *parent=nullptr)
Default constructor.
void setText(const QString &text)
Set the action categorys descriptive text.
const QList< QAction * > actions() const
Returns the actions belonging to this category.
T qobject_cast(QObject *object)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Oct 25 2020 22:54:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.