KXmlGui

kactioncollection.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <[email protected]>
4  SPDX-FileCopyrightText: 1999 Simon Hausmann <[email protected]>
5  SPDX-FileCopyrightText: 2000 Nicolas Hadacek <[email protected]>
6  SPDX-FileCopyrightText: 2000 Kurt Granroth <[email protected]>
7  SPDX-FileCopyrightText: 2000 Michael Koch <[email protected]>
8  SPDX-FileCopyrightText: 2001 Holger Freyther <[email protected]>
9  SPDX-FileCopyrightText: 2002 Ellis Whitehead <[email protected]>
10  SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <[email protected]>
11 
12  SPDX-License-Identifier: LGPL-2.0-only
13 */
14 
15 #ifndef KACTIONCOLLECTION_H
16 #define KACTIONCOLLECTION_H
17 
18 #include <kxmlgui_export.h>
19 #include <kstandardaction.h>
20 
21 #include <QObject>
22 #include <QAction>
23 
24 class QAction;
25 class KXMLGUIClient;
26 class KConfigGroup;
27 class QActionGroup;
28 class QString;
29 
47 class KXMLGUI_EXPORT KActionCollection : public QObject
48 {
49  friend class KXMLGUIClient;
50 
51  Q_OBJECT
52 
53  Q_PROPERTY(QString configGroup READ configGroup WRITE setConfigGroup)
54  Q_PROPERTY(bool configIsGlobal READ configIsGlobal WRITE setConfigGlobal)
55 
56 public:
61  explicit KActionCollection(QObject *parent, const QString &cName = QString());
62 
66  ~KActionCollection() override;
67 
71  static const QList<KActionCollection *> &allCollections();
72 
76  void clear();
77 
85  void associateWidget(QWidget *widget) const;
86 
95  void addAssociatedWidget(QWidget *widget);
96 
101  void removeAssociatedWidget(QWidget *widget);
102 
106  QList<QWidget *> associatedWidgets() const;
107 
111  void clearAssociatedWidgets();
112 
116  QString configGroup() const;
117 
122  bool configIsGlobal() const;
123 
127  void setConfigGroup(const QString &group);
128 
133  void setConfigGlobal(bool global);
134 
142  void readSettings(KConfigGroup *config = nullptr);
143 
151  void importGlobalShortcuts(KConfigGroup *config);
152 
161  void exportGlobalShortcuts(KConfigGroup *config, bool writeDefaults = false) const;
162 
178  void writeSettings(KConfigGroup *config = nullptr, bool writeDefaults = false, QAction *oneAction = nullptr) const;
179 
185  int count() const;
186 
190  bool isEmpty() const;
191 
197  QAction *action(int index) const;
198 
206  QAction *action(const QString &name) const;
207 
214  QList<QAction *> actions() const;
215 
219  const QList<QAction *> actionsWithoutGroup() const;
220 
224  const QList<QActionGroup *> actionGroups() const;
225 
237 
239  QString componentName() const;
240 
246  void setComponentDisplayName(const QString &displayName);
247 
249  QString componentDisplayName() const;
250 
254  const KXMLGUIClient *parentGUIClient() const;
255 
256 Q_SIGNALS:
260  void inserted(QAction *action);
261 
262 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
263 
267  KXMLGUI_DEPRECATED_VERSION(5, 0, "removed() is sometimes emitted with partially destroyed objects; use changed() instead (added in 5.66)")
268  QT_MOC_COMPAT void removed(QAction *action);
269 #endif
270 
275  void changed();
276 
277 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
278 
282  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KActionCollection::actionHovered(QAction* action)")
283  QT_MOC_COMPAT void actionHighlighted(QAction *action);
284 #endif
285 
289  void actionHovered(QAction *action);
290 
294  void actionTriggered(QAction *action);
295 
296 protected:
298  void connectNotify(const QMetaMethod &signal) override;
299 
300 protected Q_SLOTS:
301  virtual void slotActionTriggered();
302 
303 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
304 
308  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KActionCollection::slotActionHovered()")
309  QT_MOC_COMPAT virtual void slotActionHighlighted();
310 #endif
311 
312 private Q_SLOTS:
313  void slotActionHovered();
314 
315 public:
338  Q_INVOKABLE QAction *addAction(const QString &name, QAction *action);
339 
355  void addActions(const QList<QAction *> &actions);
356 
361  void removeAction(QAction *action);
362 
370  QAction *takeAction(QAction *action);
371 
392  QAction *addAction(KStandardAction::StandardAction actionType, const QObject *receiver = nullptr, const char *member = nullptr);
393 
414  QAction *addAction(KStandardAction::StandardAction actionType, const QString &name,
415  const QObject *receiver = nullptr, const char *member = nullptr);
416 
441  QAction *addAction(const QString &name, const QObject *receiver = nullptr, const char *member = nullptr);
442 
463  template<class ActionType>
464  ActionType *add(const QString &name, const QObject *receiver = nullptr, const char *member = nullptr)
465  {
466  ActionType *a = new ActionType(this);
467  if (receiver && member) {
468  connect(a, SIGNAL(triggered(bool)), receiver, member);
469  }
470  addAction(name, a);
471  return a;
472  }
473 
486  #ifdef K_DOXYGEN
487  template<class ActionType>
488  inline ActionType *add(const QString &name, const Receiver *receiver, Func slot)
489  #else
490  template<class ActionType, class Receiver, class Func>
491  inline typename std::enable_if<!std::is_convertible<Func, const char*>::value, ActionType>::type *add(
492  const QString &name, const Receiver *receiver, Func slot)
493  #endif
494  {
495  ActionType *a = new ActionType(this);
496  connect(a, &QAction::triggered, receiver, slot);
497  addAction(name, a);
498  return a;
499  }
500 
513  #ifdef K_DOXYGEN
514  inline QAction *addAction(const QString &name, const Receiver *receiver, Func slot)
515  #else
516  template<class Receiver, class Func>
517  inline typename std::enable_if<!std::is_convertible<Func, const char*>::value, QAction>::type *addAction(
518  const QString &name, const Receiver *receiver, Func slot)
519  #endif
520  {
521  return add<QAction>(name, receiver, slot);
522  }
523 
531  QKeySequence defaultShortcut(QAction *action) const;
532 
540  QList<QKeySequence> defaultShortcuts(QAction *action) const;
541 
542  //TODO KF6: Make setDefaultShortcut static
552  void setDefaultShortcut(QAction *action, const QKeySequence &shortcut);
553 
563  Q_INVOKABLE void setDefaultShortcuts(QAction *action, const QList<QKeySequence> &shortcuts);
564 
571  bool isShortcutsConfigurable(QAction *action) const;
572 
580  void setShortcutsConfigurable(QAction *action, bool configurable);
581 
582 private:
583  Q_PRIVATE_SLOT(d, void _k_actionDestroyed(QObject *))
584  Q_PRIVATE_SLOT(d, void _k_associatedWidgetDestroyed(QObject *))
585 
586  KActionCollection(const KXMLGUIClient *parent); // used by KXMLGUIClient
587 
588  friend class KActionCollectionPrivate;
589  class KActionCollectionPrivate *const d;
590 };
591 
592 #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:38
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 Thu Dec 3 2020 22:51:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.