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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • 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 
26 struct 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 
43 KActionCategory::KActionCategory(const QString &text, KActionCollection *parent)
44  : QObject(parent)
45  ,d( new KActionCategoryPrivate(this) )
46  {
47  d->text = text;
48  }
49 
50 
51 KActionCategory::~KActionCategory()
52  {
53  delete d;
54  }
55 
56 
57 const QList<QAction*> KActionCategory::actions() const
58  {
59  return d->actions;
60  }
61 
62 
63 QAction * KActionCategory::addAction(const QString &name, QAction *action)
64  {
65  collection()->addAction(name, action);
66  addAction(action);
67  return action;
68  }
69 
70 
71 KAction * KActionCategory::addAction(const QString &name, KAction *action)
72  {
73  collection()->addAction(name, action);
74  addAction(action);
75  return action;
76  }
77 
78 
79 KAction * 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 
90 KAction * 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 
102 KAction *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 
113 void 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 
123 KActionCollection * KActionCategory::collection() const
124  {
125  return qobject_cast<KActionCollection*>(parent());
126  }
127 
128 
129 QString KActionCategory::text() const
130  {
131  return d->text;
132  }
133 
134 
135 void KActionCategory::setText(const QString &text)
136  {
137  d->text = text;
138  }
139 
140 
141 void 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 
159 KActionCategoryPrivate::KActionCategoryPrivate( KActionCategory *host )
160  : q(host)
161  {}
162 
163 
164 #include "moc_kactioncategory.cpp"
KActionCategory
Categorize actions for KShortcutsEditor.
Definition: kactioncategory.h:95
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:56
KActionCategory::KActionCategory
KActionCategory(const QString &text, KActionCollection *parent=NULL)
Default constructor.
Definition: kactioncategory.cpp:43
KActionCategory::~KActionCategory
virtual ~KActionCategory()
Destructor.
Definition: kactioncategory.cpp:51
KStandardAction::StandardAction
StandardAction
The standard menubar and toolbar actions.
Definition: kstandardaction.h:125
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
KActionCollection::addAction
QAction * addAction(const QString &name, QAction *action)
Add an action under the given name to the collection.
Definition: kactioncollection.cpp:217
KActionCategory::collection
KActionCollection * collection() const
The action collection this category is associated with.
Definition: kactioncategory.cpp:123
QObject
QString
QList< QAction * >
KActionCategory::text
QString text() const
The action categorys descriptive text.
kaction.h
KActionCategory::setText
void setText(const QString &text)
Set the action categorys descriptive text.
Definition: kactioncategory.cpp:135
KActionCategory::actions
const QList< QAction * > actions() const
Returns the actions belonging to this category.
Definition: kactioncategory.cpp:57
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
KActionCategory::addAction
QAction * addAction(const QString &name, QAction *action)
Definition: kactioncategory.cpp:63
kactioncategory.h
QObject::parent
QObject * parent() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:58 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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