KXmlGui

kactioncollection.h
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Reginald Stadlbauer <[email protected]>
3  (C) 1999 Simon Hausmann <[email protected]>
4  (C) 2000 Nicolas Hadacek <[email protected]>
5  (C) 2000 Kurt Granroth <[email protected]>
6  (C) 2000 Michael Koch <[email protected]>
7  (C) 2001 Holger Freyther <[email protected]>
8  (C) 2002 Ellis Whitehead <[email protected]>
9  (C) 2005-2006 Hamish Rodda <[email protected]>
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Library General Public
13  License version 2 as published by the Free Software Foundation.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Library General Public License for more details.
19 
20  You should have received a copy of the GNU Library General Public License
21  along with this library; see the file COPYING.LIB. If not, write to
22  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  Boston, MA 02110-1301, USA.
24 */
25 
26 #ifndef KACTIONCOLLECTION_H
27 #define KACTIONCOLLECTION_H
28 
29 #include <kxmlgui_export.h>
30 #include <kstandardaction.h>
31 
32 #include <QObject>
33 #include <QAction>
34 
35 class QAction;
36 class KXMLGUIClient;
37 class KConfigGroup;
38 class QActionGroup;
39 class QString;
40 
58 class KXMLGUI_EXPORT KActionCollection : public QObject
59 {
60  friend class KXMLGUIClient;
61 
62  Q_OBJECT
63 
64  Q_PROPERTY(QString configGroup READ configGroup WRITE setConfigGroup)
65  Q_PROPERTY(bool configIsGlobal READ configIsGlobal WRITE setConfigGlobal)
66 
67 public:
72  explicit KActionCollection(QObject *parent, const QString &cName = QString());
73 
77  ~KActionCollection() override;
78 
82  static const QList<KActionCollection *> &allCollections();
83 
87  void clear();
88 
96  void associateWidget(QWidget *widget) const;
97 
106  void addAssociatedWidget(QWidget *widget);
107 
112  void removeAssociatedWidget(QWidget *widget);
113 
117  QList<QWidget *> associatedWidgets() const;
118 
122  void clearAssociatedWidgets();
123 
127  QString configGroup() const;
128 
133  bool configIsGlobal() const;
134 
138  void setConfigGroup(const QString &group);
139 
144  void setConfigGlobal(bool global);
145 
153  void readSettings(KConfigGroup *config = nullptr);
154 
162  void importGlobalShortcuts(KConfigGroup *config);
163 
172  void exportGlobalShortcuts(KConfigGroup *config, bool writeDefaults = false) const;
173 
189  void writeSettings(KConfigGroup *config = nullptr, bool writeDefaults = false, QAction *oneAction = nullptr) const;
190 
196  int count() const;
197 
201  bool isEmpty() const;
202 
208  QAction *action(int index) const;
209 
217  QAction *action(const QString &name) const;
218 
225  QList<QAction *> actions() const;
226 
230  const QList<QAction *> actionsWithoutGroup() const;
231 
235  const QList<QActionGroup *> actionGroups() const;
236 
248 
250  QString componentName() const;
251 
257  void setComponentDisplayName(const QString &displayName);
258 
260  QString componentDisplayName() const;
261 
265  const KXMLGUIClient *parentGUIClient() const;
266 
267 Q_SIGNALS:
271  void inserted(QAction *action);
272 
273 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
274 
278  KXMLGUI_DEPRECATED_VERSION(5, 0, "removed() is sometimes emitted with partially destroyed objects; use changed() instead (added in 5.66)")
279  QT_MOC_COMPAT void removed(QAction *action);
280 #endif
281 
286  void changed();
287 
288 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
289 
293  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KActionCollection::actionHovered(QAction* action)")
294  QT_MOC_COMPAT void actionHighlighted(QAction *action);
295 #endif
296 
300  void actionHovered(QAction *action);
301 
305  void actionTriggered(QAction *action);
306 
307 protected:
309  void connectNotify(const QMetaMethod &signal) override;
310 
311 protected Q_SLOTS:
312  virtual void slotActionTriggered();
313 
314 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
315 
319  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KActionCollection::slotActionHovered()")
320  QT_MOC_COMPAT virtual void slotActionHighlighted();
321 #endif
322 
323 private Q_SLOTS:
324  void slotActionHovered();
325 
326 public:
349  Q_INVOKABLE QAction *addAction(const QString &name, QAction *action);
350 
366  void addActions(const QList<QAction *> &actions);
367 
372  void removeAction(QAction *action);
373 
381  QAction *takeAction(QAction *action);
382 
403  QAction *addAction(KStandardAction::StandardAction actionType, const QObject *receiver = nullptr, const char *member = nullptr);
404 
425  QAction *addAction(KStandardAction::StandardAction actionType, const QString &name,
426  const QObject *receiver = nullptr, const char *member = nullptr);
427 
452  QAction *addAction(const QString &name, const QObject *receiver = nullptr, const char *member = nullptr);
453 
474  template<class ActionType>
475  ActionType *add(const QString &name, const QObject *receiver = nullptr, const char *member = nullptr)
476  {
477  ActionType *a = new ActionType(this);
478  if (receiver && member) {
479  connect(a, SIGNAL(triggered(bool)), receiver, member);
480  }
481  addAction(name, a);
482  return a;
483  }
484 
497  #ifdef K_DOXYGEN
498  template<class ActionType>
499  inline ActionType *add(const QString &name, const Receiver *receiver, Func slot)
500  #else
501  template<class ActionType, class Receiver, class Func>
502  inline typename std::enable_if<!std::is_convertible<Func, const char*>::value, ActionType>::type *add(
503  const QString &name, const Receiver *receiver, Func slot)
504  #endif
505  {
506  ActionType *a = new ActionType(this);
507  connect(a, &QAction::triggered, receiver, slot);
508  addAction(name, a);
509  return a;
510  }
511 
524  #ifdef K_DOXYGEN
525  inline QAction *addAction(const QString &name, const Receiver *receiver, Func slot)
526  #else
527  template<class Receiver, class Func>
528  inline typename std::enable_if<!std::is_convertible<Func, const char*>::value, QAction>::type *addAction(
529  const QString &name, const Receiver *receiver, Func slot)
530  #endif
531  {
532  return add<QAction>(name, receiver, slot);
533  }
534 
542  QKeySequence defaultShortcut(QAction *action) const;
543 
551  QList<QKeySequence> defaultShortcuts(QAction *action) const;
552 
553  //TODO KF6: Make setDefaultShortcut static
563  void setDefaultShortcut(QAction *action, const QKeySequence &shortcut);
564 
574  Q_INVOKABLE void setDefaultShortcuts(QAction *action, const QList<QKeySequence> &shortcuts);
575 
582  bool isShortcutsConfigurable(QAction *action) const;
583 
591  void setShortcutsConfigurable(QAction *action, bool configurable);
592 
593 private:
594  Q_PRIVATE_SLOT(d, void _k_actionDestroyed(QObject *))
595  Q_PRIVATE_SLOT(d, void _k_associatedWidgetDestroyed(QObject *))
596 
597  KActionCollection(const KXMLGUIClient *parent); // used by KXMLGUIClient
598 
599  friend class KActionCollectionPrivate;
600  class KActionCollectionPrivate *const d;
601 };
602 
603 #endif
QAction * addAction(const QString &name, const Receiver *receiver, Func slot)
This is the same as addAction(const QString &name, const QObject *receiver, const char *member) using...
A container for a set of QAction objects.
void triggered(bool checked)
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
Definition: kxmlguiclient.h:48
virtual QString componentName() const
ActionType * add(const QString &name, const QObject *receiver=nullptr, const char *member=nullptr)
Creates a new action under the given name, adds it to the collection and connects the action&#39;s trigge...
virtual void connectNotify(const QMetaMethod &signal)
Q_PROPERTY(...)
virtual void setComponentName(const QString &componentName, const QString &componentDisplayName)
Sets the component name for this part.
QAction * action(const char *name) const
Retrieves an action of the client by name.
ActionType * add(const QString &name, const Receiver *receiver, Func slot)
This is the same as add(const QString &name, const QObject *receiver, const char *member) using new s...
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jul 7 2020 22:48:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.