Command Class

(Core::Command)

The Command class represents an action, such as a menu item, tool button, or shortcut. More...

Header: #include <Command>

Public Types

enum CommandAttribute { CA_UpdateText, CA_UpdateIcon, CA_Hide, CA_NonConfigurable }
flags CommandAttributes

Public Functions

virtual QAction *action() const = 0
void augmentActionWithShortcutToolTip(QAction *a) const
virtual Core::Context context() const = 0
virtual QKeySequence defaultKeySequence() const = 0
virtual QString description() const = 0
virtual bool hasAttribute(Core::Command::CommandAttribute attr) const = 0
virtual Core::Id id() const = 0
virtual bool isActive() const = 0
virtual bool isScriptable() const = 0
virtual bool isScriptable(const Core::Context &) const = 0
virtual QKeySequence keySequence() const = 0
virtual void removeAttribute(Core::Command::CommandAttribute attr) = 0
virtual void setAttribute(Core::Command::CommandAttribute attr) = 0
virtual void setDefaultKeySequence(const QKeySequence &key) = 0
virtual void setDescription(const QString &text) = 0
virtual void setKeySequence(const QKeySequence &key) = 0
virtual void setTouchBarIcon(const QIcon &icon) = 0
virtual void setTouchBarText(const QString &text) = 0
virtual QString stringWithAppendedShortcut(const QString &str) const = 0
virtual QAction *touchBarAction() const = 0
virtual QIcon touchBarIcon() const = 0
virtual QString touchBarText() const = 0

Signals

Static Public Members

QToolButton *toolButtonWithAppendedShortcut(QAction *action, Core::Command *cmd)

Detailed Description

The Command class represents an action, such as a menu item, tool button, or shortcut.

You do not create Command objects directly, but use ActionManager::registerAction() to register an action and retrieve a Command. The Command object represents the user visible action and its properties. If multiple actions are registered with the same ID (but different contexts) the returned Command is the shared one between these actions.

A Command has two basic properties: a default shortcut and a default text. The default shortcut is a key sequence that the user can use to trigger the active action that the Command represents. The default text is e.g. used for representing the Command in the keyboard shortcut preference pane. If the default text is empty, the text of the visible action is used.

The user visible action is updated to represent the state of the active action (if any). For performance reasons only the enabled and visible state are considered by default though. You can tell a Command to also update the actions icon and text by setting the corresponding attribute.

If there is no active action, the default behavior of the visible action is to be disabled. You can change that behavior to make the visible action hide instead via the Command's attributes.

Member Type Documentation

enum Command::CommandAttribute
flags Command::CommandAttributes

This enum defines how the user visible action is updated when the active action changes. The default is to update the enabled and visible state, and to disable the user visible action when there is no active action.

ConstantValueDescription
Core::Command::CA_UpdateText2Also update the actions text.
Core::Command::CA_UpdateIcon4Also update the actions icon.
Core::Command::CA_Hide1When there is no active action, hide the user-visible action, instead of just disabling it.
Core::Command::CA_NonConfigurable8Flag to indicate that the keyboard shortcut of this Command should not be configurable by the user.

The CommandAttributes type is a typedef for QFlags<CommandAttribute>. It stores an OR combination of CommandAttribute values.

Member Function Documentation

[pure virtual] QAction *Command::action() const

[signal] void Command::activeStateChanged()

void Command::augmentActionWithShortcutToolTip(QAction *a) const

Appends the keyboard shortcut that is currently assigned to the action a to its tool tip.

[pure virtual] Core::Context Command::context() const

[pure virtual] QKeySequence Command::defaultKeySequence() const

See also setDefaultKeySequence().

[pure virtual] QString Command::description() const

See also setDescription().

[pure virtual] bool Command::hasAttribute(Core::Command::CommandAttribute attr) const

[pure virtual] Core::Id Command::id() const

[pure virtual] bool Command::isActive() const

[pure virtual] bool Command::isScriptable() const

[pure virtual] bool Command::isScriptable(const Core::Context &) const

[pure virtual] QKeySequence Command::keySequence() const

See also setKeySequence().

[signal] void Command::keySequenceChanged()

[pure virtual] void Command::removeAttribute(Core::Command::CommandAttribute attr)

[pure virtual] void Command::setAttribute(Core::Command::CommandAttribute attr)

See also hasAttribute().

[pure virtual] void Command::setDefaultKeySequence(const QKeySequence &key)

See also defaultKeySequence().

[pure virtual] void Command::setDescription(const QString &text)

See also description().

[pure virtual] void Command::setKeySequence(const QKeySequence &key)

See also keySequence().

[pure virtual] void Command::setTouchBarIcon(const QIcon &icon)

See also touchBarIcon().

[pure virtual] void Command::setTouchBarText(const QString &text)

See also touchBarText().

[pure virtual] QString Command::stringWithAppendedShortcut(const QString &str) const

[static] QToolButton *Command::toolButtonWithAppendedShortcut(QAction *action, Core::Command *cmd)

Returns a tool button for action.

Appends the keyboard shortcut cmd to the tool tip of the action.

[pure virtual] QAction *Command::touchBarAction() const

[pure virtual] QIcon Command::touchBarIcon() const

See also setTouchBarIcon().

[pure virtual] QString Command::touchBarText() const

See also setTouchBarText().