• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • actions
kactioncategory.cpp
Go to the documentation of this file.
1/* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "kactioncategory.h"
20
21#include <QtGui/QAction>
22
23#include "kaction.h"
24
25
26struct KActionCategoryPrivate
27 {
28
29 KActionCategoryPrivate( KActionCategory *host );
30
32 KActionCategory *q;
33
35 QString text;
36
38 QList<QAction*> actions;
39
40 }; // class KActionCategoryPrivate
41
42
43KActionCategory::KActionCategory(const QString &text, KActionCollection *parent)
44 : QObject(parent)
45 ,d( new KActionCategoryPrivate(this) )
46 {
47 d->text = text;
48 }
49
50
51KActionCategory::~KActionCategory()
52 {
53 delete d;
54 }
55
56
57const QList<QAction*> KActionCategory::actions() const
58 {
59 return d->actions;
60 }
61
62
63QAction * KActionCategory::addAction(const QString &name, QAction *action)
64 {
65 collection()->addAction(name, action);
66 addAction(action);
67 return action;
68 }
69
70
71KAction * KActionCategory::addAction(const QString &name, KAction *action)
72 {
73 collection()->addAction(name, action);
74 addAction(action);
75 return action;
76 }
77
78
79KAction * KActionCategory::addAction(
80 KStandardAction::StandardAction actionType,
81 const QObject *receiver,
82 const char *member)
83 {
84 KAction *action = collection()->addAction(actionType, receiver, member);
85 addAction(action);
86 return action;
87 }
88
89
90KAction * KActionCategory::addAction(
91 KStandardAction::StandardAction actionType,
92 const QString &name,
93 const QObject *receiver,
94 const char *member)
95 {
96 KAction *action = collection()->addAction(actionType, name, receiver, member);
97 addAction(action);
98 return action;
99 }
100
101
102KAction *KActionCategory::addAction(
103 const QString &name,
104 const QObject *receiver,
105 const char *member)
106 {
107 KAction *action = collection()->addAction(name, receiver, member);
108 addAction(action);
109 return action;
110 }
111
112
113void KActionCategory::addAction(QAction *action)
114 {
115 // Only add the action if wasn't added earlier.
116 if (!d->actions.contains(action))
117 {
118 d->actions.append(action);
119 }
120 }
121
122
123KActionCollection * KActionCategory::collection() const
124 {
125 return qobject_cast<KActionCollection*>(parent());
126 }
127
128
129QString KActionCategory::text() const
130 {
131 return d->text;
132 }
133
134
135void KActionCategory::setText(const QString &text)
136 {
137 d->text = text;
138 }
139
140
141void KActionCategory::unlistAction(QAction *action)
142 {
143 // ATTENTION:
144 // This method is called from KActionCollection with an QObject formerly
145 // known as a QAction during _k_actionDestroyed(). So don't do fancy stuff
146 // here that needs a real QAction!
147
148 // Get the index for the action
149 int index = d->actions.indexOf(action);
150
151 // Action not found.
152 if (index==-1) return;
153
154 // Remove the action
155 d->actions.takeAt(index);
156 }
157
158
159KActionCategoryPrivate::KActionCategoryPrivate( KActionCategory *host )
160 : q(host)
161 {}
162
163
164#include "moc_kactioncategory.cpp"
KActionCategory
Categorize actions for KShortcutsEditor.
Definition: kactioncategory.h:96
KActionCategory::text
QString text
Definition: kactioncategory.h:99
KActionCategory::actions
const QList< QAction * > actions() const
Returns the actions belonging to this category.
Definition: kactioncategory.cpp:57
KActionCategory::addAction
QAction * addAction(const QString &name, QAction *action)
Definition: kactioncategory.cpp:63
KActionCategory::~KActionCategory
virtual ~KActionCategory()
Destructor.
Definition: kactioncategory.cpp:51
KActionCategory::KActionCategory
KActionCategory(const QString &text, KActionCollection *parent=NULL)
Default constructor.
Definition: kactioncategory.cpp:43
KActionCategory::setText
void setText(const QString &text)
Set the action categorys descriptive text.
Definition: kactioncategory.cpp:135
KActionCategory::collection
KActionCollection * collection() const
The action collection this category is associated with.
Definition: kactioncategory.cpp:123
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:57
KActionCollection::addAction
QAction * addAction(const QString &name, QAction *action)
Add an action under the given name to the collection.
Definition: kactioncollection.cpp:217
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
QAction
QList
QObject
kaction.h
kactioncategory.h
KStandardAction::StandardAction
StandardAction
The standard menubar and toolbar actions.
Definition: kstandardaction.h:125
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal