Core::Command Class
class Core::CommandCommand 类表示一种操作,例如菜单项、工具按钮或快捷方式。更多内容...
| Header: | #include <coreplugin/actionmanager/command.h> |
| Inherits: | QObject |
公共类型
| enum | CommandAttribute { CA_UpdateText, CA_UpdateIcon, CA_Hide, CA_NonConfigurable } |
| flags | CommandAttributes |
公共函数
| QAction * | action() const |
| void | augmentActionWithShortcutToolTip(QAction *a) const |
| Core::Context | context() const |
| QList<QKeySequence> | defaultKeySequences() const |
| QString | description() const |
| bool | hasAttribute(Core::Command::CommandAttribute attribute) const |
| bool | isActive() const |
| bool | isScriptable() const |
| QKeySequence | keySequence() const |
| QList<QKeySequence> | keySequences() const |
| void | removeAttribute(Core::Command::CommandAttribute attribute) |
| void | setAttribute(Core::Command::CommandAttribute attribute) |
| void | setDefaultKeySequence(const QKeySequence &key) |
| void | setDefaultKeySequences(const QList<QKeySequence> &keys) |
| void | setDescription(const QString &text) |
| void | setTouchBarIcon(const QIcon &icon) |
| void | setTouchBarText(const QString &text) |
| QString | stringWithAppendedShortcut(const QString &string) const |
| QIcon | touchBarIcon() const |
| QString | touchBarText() const |
信号
| void | activeStateChanged() |
| void | keySequenceChanged() |
静态公共成员
| QAction * | createActionWithShortcutToolTip(Utils::Id commandId, QObject *parent) |
| QToolButton * | createToolButtonWithShortcutToolTip(Utils::Id commandId, QWidget *parent = nullptr) |
| QToolButton * | toolButtonWithAppendedShortcut(QAction *action, Core::Command *cmd) |
| QToolButton * | toolButtonWithAppendedShortcut(QAction *action, Utils::Id commandId) |
详细说明
您不能直接创建 Command 对象,而是通过调用 `ActionManager::registerAction()` 来注册操作并获取 Command 对象。Command 对象代表用户可见的操作及其属性。如果多个操作使用相同的 ID(但在不同的上下文中)进行注册,则返回的 Command 是这些操作之间共享的。
一个Command对象有两个基本属性:默认快捷键列表和默认文本。默认快捷键是用户可用于触发Command所代表的当前活动的操作的键序列。该列表中的第一个快捷键是主快捷键,例如,它也会显示在工具提示和菜单中。 默认文本用于在键盘快捷键偏好设置面板中显示该命令。如果默认文本为空,则使用可见操作的文本。
用户可见的操作会更新以反映当前活动操作的状态(如有)。出于性能考虑,默认情况下仅考虑“已启用”和“可见”状态。您可以通过设置相应的attribute ,让命令同时更新操作的图标和文本。
如果没有活动操作,可见操作的默认行为是禁用。您可以通过命令的attributes 将该行为更改为隐藏可见操作。
有关 `Core::Command ` 与 `Core::ActionManager ` 之间交互关系的概述,请参阅《操作管理器和命令》。
另请参阅《 Core::ActionManager 》 和《操作管理器与命令》。
成员类型文档
enum Command::CommandAttribute
flags Command::CommandAttributes
此枚举定义了当活动操作发生变化时,用户可见操作的更新方式。默认情况下,系统会更新“已启用”和“可见”状态,并在没有活动操作时禁用用户可见操作。
| 常量 | 值 | 描述 |
|---|---|---|
Core::Command::CA_UpdateText | 2 | 同时更新操作文本。 |
Core::Command::CA_UpdateIcon | 4 | 同时更新操作图标。 |
Core::Command::CA_Hide | 1 | 当没有活动操作时,隐藏用户可见的操作,而不是仅仅将其禁用。 |
Core::Command::CA_NonConfigurable | 8 | 用于指示该命令的键盘快捷键不应由用户配置的标志。 |
CommandAttributes 类型是QFlags<CommandAttribute> 的 typedef。它存储 CommandAttribute 值的按“或”运算组合。
成员函数文档
QAction *Command::action() const
返回该命令的用户可见操作。可将此操作应用于工具按钮等位置。 该操作会自动将triggered() 和toggled() 信号转发给当前针对此命令处于活动状态的操作。它还会在其工具提示中显示当前的主要键盘快捷键(除活动操作的工具提示外),并在当前上下文中没有活动操作时被禁用/隐藏。
[signal] void Command::activeStateChanged()
当命令的状态发生变化时,会发出此信号。
void Command::augmentActionWithShortcutToolTip(QAction *a) const
将操作a 的工具提示设置为该操作的文本,并附加该命令的主键盘快捷键。每当主键盘快捷键或操作的文本发生变化时,工具提示会自动更新。
另请参阅 stringWithAppendedShortcut() 和createActionWithShortcutToolTip()。
Core::Context Command::context() const
返回此命令的上下文。
[static] QAction *Command::createActionWithShortcutToolTip(Utils::Id commandId, QObject *parent)
返回一个新的QAction 对象,其中包含该命令的图标、图标文本以及由commandId 提供的文本。将该按钮的父对象设置为parent 。该操作的工具提示由操作文本加上该命令的主要键盘快捷键组成。该操作的其他属性不会自动更新。
另请参阅 augmentActionWithShortcutToolTip()。
[static] QToolButton *Command::createToolButtonWithShortcutToolTip(Utils::Id commandId, QWidget *parent = nullptr)
返回一个新的QToolButton 对象,其中包含该命令的图标、图标文本以及由commandId 提供的文本。将按钮的父对象设置为parent 。该操作的工具提示由操作的文本以及该命令的主要键盘快捷键组成。按钮的其他属性不会自动更新。
另请参阅 createActionWithShortcutToolTip()。
QList<QKeySequence> Command::defaultKeySequences() const
返回可用于激活此命令的默认键盘快捷键。
另请参阅 setDefaultKeySequences()。
QString Command::description() const
返回用于向用户显示此命令的文本。
另请参阅 setDescription()。
bool Command::hasAttribute(Core::Command::CommandAttribute attribute) const
返回该命令是否已设置attribute 。
另请参阅 CommandAttribute 、removeAttribute() 和setAttribute()。
bool Command::isActive() const
返回该命令在当前上下文中是否具有有效的操作。
bool Command::isScriptable() const
返回该命令是否支持脚本调用。支持脚本调用的命令可从脚本中调用,而无需用户进行交互。
QKeySequence Command::keySequence() const
返回当前分配给此命令的主键盘快捷键。
另请参阅 ` defaultKeySequences()`。
[signal] void Command::keySequenceChanged()
当分配给此命令的键盘快捷键发生变化时触发,例如当用户在键盘快捷键设置对话框中进行设置时。
QList<QKeySequence> Command::keySequences() const
返回当前分配给此命令的键盘快捷键。
另请参阅 defaultKeySequences()。
void Command::removeAttribute(Core::Command::CommandAttribute attribute)
从该命令的属性中移除attribute 。
另请参阅 CommandAttribute 以及setAttribute()。
void Command::setAttribute(Core::Command::CommandAttribute attribute)
将attribute 添加到该命令的属性中。
另请参阅 CommandAttribute 、removeAttribute() 以及hasAttribute()。
void Command::setDefaultKeySequence(const QKeySequence &key)
将用于激活此命令的默认快捷键设置为key 。当用户未自定义快捷键时,或需要将快捷键重置为默认值时,可使用此功能。
void Command::setDefaultKeySequences(const QList<QKeySequence> &keys)
将用于激活此命令的默认键盘快捷键设置为keys 。当用户未自定义快捷键时,或需将快捷键重置为默认设置时,可使用此功能。
另请参阅 defaultKeySequences()。
void Command::setDescription(const QString &text)
设置用于在键盘快捷键设置对话框中表示该命令的text 。如果未设置此项,则采用用户可见操作中的当前文本(在大多数情况下这样即可)。
另请参阅 description()。
void Command::setTouchBarIcon(const QIcon &icon)
将触控条上该操作的图标设置为icon 。
另请参阅 touchBarIcon()。
void Command::setTouchBarText(const QString &text)
将触控条上该操作的文本设置为“text ”。
另请参阅 touchBarText()。
QString Command::stringWithAppendedShortcut(const QString &string) const
返回string ,并在其后附加当前分配给该命令的主键盘快捷键的表示形式。
[static] QToolButton *Command::toolButtonWithAppendedShortcut(QAction *action, Core::Command *cmd)
返回一个用于action 的工具按钮。
将主键盘快捷键cmd 添加到该操作的工具提示中。
[static] QToolButton *Command::toolButtonWithAppendedShortcut(QAction *action, Utils::Id commandId)
返回一个用于action 的工具按钮。
将 ID 为commandId 的命令的主键盘快捷键追加到该按钮的工具提示中。
QIcon Command::touchBarIcon() const
返回触控条上该操作的图标。
另请参阅 setTouchBarIcon()。
QString Command::touchBarText() const
返回触控条上该操作的文本。
另请参阅 setTouchBarText()。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.