KirigamiActionCollection Class

A container for a set of QAction objects. More...

Header: #include <KirigamiActionCollection>
Inherits: QObject

Public Functions

KirigamiActionCollection(QObject *parent, const QString &cName = QString())
virtual ~KirigamiActionCollection() override
QAction *action(const QString &name) const
QAction *action(int index) const
const QList<QActionGroup *> actionGroups() const
QList<QAction *> actions() const
const QList<QAction *> actionsWithoutGroup() const
typename std::enable_if<!std::is_convertible<Func, const char *>::value, ActionType>::type *add(const QString &name, const Receiver *receiver, Func slot)
QAction *addAction(const QString &name, QAction *action)
typename std::enable_if<!std::is_convertible<Func, const char *>::value, QAction>::type *addAction(const QString &name, const Receiver *receiver, Func slot)
typename std::enable_if<!std::is_convertible<Func, const char *>::value, QAction>::type *addAction(KStandardActions::StandardAction actionType, const QString &name, const Receiver *receiver, Func slot)
void addActions(const QList<QAction *> &actions)
void clear()
QString componentDisplayName() const
QString componentName() const
QString configGroup() const
bool configIsGlobal() const
int count() const
bool isEmpty() const
void readSettings(KConfigGroup *config = nullptr)
void removeAction(QAction *action)
void setComponentDisplayName(const QString &displayName)
void setComponentName(const QString &componentName)
void setConfigGlobal(bool global)
void setConfigGroup(const QString &group)
QAction *takeAction(QAction *action)
void writeSettings(KConfigGroup *config = nullptr, bool writeDefaults = false, QAction *oneAction = nullptr) const

Signals

void actionHovered(QAction *action)
void actionTriggered(QAction *action)
void changed()
void inserted(QAction *action)

Static Public Members

const QList<KirigamiActionCollection *> &allCollections()
QKeySequence defaultShortcut(QAction *action)
QList<QKeySequence> defaultShortcuts(QAction *action)
bool isShortcutsConfigurable(QAction *action)
void setDefaultShortcut(QAction *action, const QKeySequence &shortcut)
void setDefaultShortcuts(QAction *action, const QList<QKeySequence> &shortcuts)
void setShortcutsConfigurable(QAction *action, bool configurable)

Detailed Description

KirigamiActionCollection manages a set of QAction objects. It allows them to be grouped for organized presentation of configuration to the user, saving + loading of configuration, and optionally for automatic plugging into specified widget(s).

Additionally, KirigamiActionCollection provides several convenience functions for locating named actions, and actions grouped by QActionGroup.

Member Function Documentation

[explicit] KirigamiActionCollection::KirigamiActionCollection(QObject *parent, const QString &cName = QString())

Constructor.

Allows specification of a component name other than the default application name, where needed (remember to call setComponentDisplayName() too).

[override virtual noexcept] KirigamiActionCollection::~KirigamiActionCollection()

Destructor.

[invokable] QAction *KirigamiActionCollection::action(const QString &name) const

Get the action with the given name from the action collection.

This won't return the action for the menus defined using a "<Menu>" tag in XMLGUI files (e.g. "<Menu name="menuId">" in "applicationNameui.rc"). To access menu actions defined like this, use e.g.

qobject_cast<QMenu *>(guiFactory()->container("menuId", this));

after having called setupGUI() or createGUI().

name Name of the QAction

Returns A pointer to the QAction in the collection which matches the parameters or null if nothing matches.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

QAction *KirigamiActionCollection::action(int index) const

Return the QAction* at position index in the action collection.

This is equivalent to actions().value(index);

const QList<QActionGroup *> KirigamiActionCollection::actionGroups() const

Returns the list of all QActionGroups associated with actions in this action collection.

[signal] void KirigamiActionCollection::actionHovered(QAction *action)

Indicates that action was hovered.

[signal] void KirigamiActionCollection::actionTriggered(QAction *action)

Indicates that action was triggered

QList<QAction *> KirigamiActionCollection::actions() const

Returns the list of QActions which belong to this action collection.

The list is guaranteed to be in the same order the action were put into the collection.

const QList<QAction *> KirigamiActionCollection::actionsWithoutGroup() const

Returns the list of QActions without an QAction::actionGroup() which belong to this action collection.

template <typename ActionType, typename Receiver, typename Func> typename std::enable_if<!std::is_convertible<Func, const char *>::value, ActionType>::type *KirigamiActionCollection::add(const QString &name, const Receiver *receiver, Func slot)

Creates a new action under the given name, adds it to the collection and connects the action's triggered(bool) signal to the specified receiver/member.

The type of the action is specified by the template parameter ActionType.

The KirigamiActionCollection takes ownership of the action object.

name The internal name of the action (e.g. "file-open").

receiver The QObject to connect the triggered(bool) signal to.

slot The slot or lambda to connect the triggered(bool) signal to.

Returns new action of the given type ActionType.

See also add(const QString &, const QObject *, const char *).

[invokable] QAction *KirigamiActionCollection::addAction(const QString &name, QAction *action)

Add an action under the given name to the collection.

Inserting an action that was previously inserted under a different name will replace the old entry, i.e. the action will not be available under the old name anymore but only under the new one.

Inserting an action under a name that is already used for another action will replace the other action in the collection (but will not delete it).

If KAuthorized::authorizeAction() reports that the action is not authorized, it will be disabled and hidden.

The ownership of the action object is not transferred. If the action is destroyed it will be removed automatically from the KirigamiActionCollection.

name The name by which the action be retrieved again from the collection.

action The action to add.

Returns the same as the action given as parameter. This is just for convenience (chaining calls) and consistency with the other addAction methods, you can also simply ignore the return value.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

template <typename Receiver, typename Func> typename std::enable_if<!std::is_convertible<Func, const char *>::value, QAction>::type *KirigamiActionCollection::addAction(const QString &name, const Receiver *receiver, Func slot)

Creates a new action under the given name to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is returned.

name The internal name of the action (e.g. "file-open").

receiver The QObject to connect the triggered(bool) signal to.

slot The slot or lambda to connect the triggered(bool) signal to.

Returns new action of the given type ActionType.

template <typename Receiver, typename Func> typename std::enable_if<!std::is_convertible<Func, const char *>::value, QAction>::type *KirigamiActionCollection::addAction(KStandardActions::StandardAction actionType, const QString &name, const Receiver *receiver, Func slot)

Creates a new standard action, adds it to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is also returned.

The action can be retrieved later from the collection by its standard name as per KStandardActions::stdName.

The KirigamiActionCollection takes ownership of the action object.

actionType The standard action type of the action to create.

name The name by which the action be retrieved again from the collection.

receiver The QObject to connect the triggered(bool) signal to.

slot The slot or lambda to connect the triggered(bool) signal to.

Returns new action of the given type ActionType.

void KirigamiActionCollection::addActions(const QList<QAction *> &actions)

Adds a list of actions to the collection.

The objectName of the actions is used as their internal name in the collection.

The ownership of the action objects is not transferred. If the action is destroyed it will be removed automatically from the KirigamiActionCollection.

Uses addAction(const QString&, QAction*).

actions the list of the actions to add.

See also addAction().

[static] const QList<KirigamiActionCollection *> &KirigamiActionCollection::allCollections()

Access the list of all action collections in existence for this app

[signal] void KirigamiActionCollection::changed()

Emitted when an action has been inserted into, or removed from, this action collection.

void KirigamiActionCollection::clear()

Clears the entire action collection, deleting all actions.

QString KirigamiActionCollection::componentDisplayName() const

The display name for the associated component.

See also setComponentDisplayName().

QString KirigamiActionCollection::componentName() const

The component name with which this class is associated.

See also setComponentName().

QString KirigamiActionCollection::configGroup() const

Returns the KConfig group with which settings will be loaded and saved.

Note: Getter function for property configGroup.

See also setConfigGroup().

bool KirigamiActionCollection::configIsGlobal() const

Returns whether this action collection's configuration should be global to KDE ( true ), or specific to the application ( false ).

Note: Getter function for property configIsGlobal.

int KirigamiActionCollection::count() const

Returns the number of actions in the collection.

This is equivalent to actions().count().

[static] QKeySequence KirigamiActionCollection::defaultShortcut(QAction *action)

Get the default primary shortcut for the given action.

action the action for which the default primary shortcut should be returned.

Returns the default primary shortcut of the given action

See also setDefaultShortcut().

[static] QList<QKeySequence> KirigamiActionCollection::defaultShortcuts(QAction *action)

Get the default shortcuts for the given action.

action the action for which the default shortcuts should be returned.

Returns the default shortcuts of the given action

See also setDefaultShortcuts().

[signal] void KirigamiActionCollection::inserted(QAction *action)

Indicates that action was inserted into this action collection.

bool KirigamiActionCollection::isEmpty() const

Returns whether the action collection is empty or not.

[static] bool KirigamiActionCollection::isShortcutsConfigurable(QAction *action)

Returns true if the given action's shortcuts may be configured by the user.

action the action for the hint should be verified.

void KirigamiActionCollection::readSettings(KConfigGroup *config = nullptr)

Read all key associations from config.

If config is zero, read all key associations from the application's configuration file KSharedConfig::openConfig(), in the group set by setConfigGroup().

void KirigamiActionCollection::removeAction(QAction *action)

Removes an action from the collection and deletes it. action The action to remove.

void KirigamiActionCollection::setComponentDisplayName(const QString &displayName)

Set the component displayName associated with this action collection.

(e.g. for the toolbar editor) KXMLGUIClient::setComponentName takes care of calling this.

See also componentDisplayName().

void KirigamiActionCollection::setComponentName(const QString &componentName)

Set the componentName associated with this action collection.

Warning: Don't call this method on a KirigamiActionCollection that contains actions. This is not supported.

componentData the name which is to be associated with this action collection, or QString() to indicate the app name. This is used to load/save settings into XML files.

KXMLGUIClient::setComponentName takes care of calling this.

See also componentName().

void KirigamiActionCollection::setConfigGlobal(bool global)

Set whether this action collection's configuration should be global to KDE ( true ), or specific to the application ( false ).

Note: Setter function for property configIsGlobal.

void KirigamiActionCollection::setConfigGroup(const QString &group)

Sets group as the KConfig group with which settings will be loaded and saved.

Note: Setter function for property configGroup.

See also configGroup().

[static] void KirigamiActionCollection::setDefaultShortcut(QAction *action, const QKeySequence &shortcut)

Set the default shortcut for the given action.

action the action for which the default shortcut should be set.

shortcut the shortcut to use for the given action in its specified shortcutContext()

See also defaultShortcut().

[static invokable] void KirigamiActionCollection::setDefaultShortcuts(QAction *action, const QList<QKeySequence> &shortcuts)

Set the default shortcuts for the given action.

action the action for which the default shortcut should be set.

shortcuts the shortcuts to use for the given action in its specified shortcutContext()

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

See also defaultShortcuts().

[static] void KirigamiActionCollection::setShortcutsConfigurable(QAction *action, bool configurable)

Indicate whether the user may configure the action's shortcuts.

action the action for the hint should be verified.

configurable set to true if the shortcuts of the given action may be configured by the user, otherwise false.

See also isShortcutsConfigurable().

QAction *KirigamiActionCollection::takeAction(QAction *action)

Removes an action from the collection.

The ownership of the action object is not changed.

action the action to remove.

void KirigamiActionCollection::writeSettings(KConfigGroup *config = nullptr, bool writeDefaults = false, QAction *oneAction = nullptr) const

Write the current configurable key associations to config. What the function does if config is zero depends. If this action collection belongs to a KXMLGUIClient the setting are saved to the kxmlgui definition file. If not the settings are written to the applications config file.

Note: oneAction and writeDefaults have no meaning for the kxmlgui configuration file.

config Config object to save to, or null (see above)

writeDefaults set to true to write settings which are already at defaults.

oneAction pass an action here if you just want to save the values for one action, eg. if you know that action is the only one which has changed.