このページでは

Core::Command Class

class Core::Command

Command クラスは、メニュー項目、ツールボタン、ショートカットなどのアクションを表します。詳細...

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

シグナル

静的パブリックメンバー

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には、2つの基本的なプロパティがあります。それは、デフォルトのショートカットのリストと、デフォルトのテキストです。デフォルトのショートカットとは、ユーザーがCommandが表すアクティブなアクションを起動するために使用できるキーの組み合わせです。そのリストの最初のショートカットはメインのショートカットであり、たとえばツールチップやメニューにも表示されます。 デフォルトテキストは、キーボードショートカットの設定パネルでコマンドを表すために使用されます。デフォルトテキストが空の場合、表示されているアクションのテキストが使用されます。

ユーザーに表示されるアクションは、アクティブなアクションの状態(存在する場合)を反映するように更新されます。ただし、パフォーマンス上の理由から、デフォルトでは「有効」および「表示中」の状態のみが考慮されます。対応するattribute を設定することで、コマンドにアクションのアイコンやテキストも更新させることができます。

アクティブなアクションがない場合、表示されているアクションのデフォルトの挙動は無効化されることです。コマンドのattributes を設定することで、その挙動を変更し、代わりに表示されているアクションを非表示にするようにすることもできます。

Core::Command とCore::ActionManager の相互作用の概要については、「アクションマネージャーとコマンド」を参照してください。

「 Core::ActionManager 」 および「アクションマネージャーとコマンド」も参照してください 。

メンバ型のドキュメント

enum Command::CommandAttribute
flags Command::CommandAttributes

この列挙型は、アクティブなアクションが変更された際に、ユーザーに表示されるアクションがどのように更新されるかを定義します。デフォルトでは、有効および表示状態が更新され、アクティブなアクションがない場合は、ユーザーに表示されるアクションが無効化されます。

定数値説明
Core::Command::CA_UpdateText2アクションのテキストも更新します。
Core::Command::CA_UpdateIcon4アクションのアイコンも更新します。
Core::Command::CA_Hide1アクティブなアクションがない場合、単に無効化するのではなく、ユーザーに見えるアクションを非表示にする。
Core::Command::CA_NonConfigurable8このコマンドのキーボードショートカットをユーザーが設定できないことを示すフラグ。

CommandAttributes 型は、QFlags<CommandAttribute> の typedef です。CommandAttribute 値の OR 組み合わせを格納します。

メンバ関数のドキュメント

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)

commandId で指定されたコマンドのアイコン、アイコンテキスト、およびテキストを持つ新しい `QAction ` を返します。ボタンの親を `parent` に設定します。アクションのツールチップは、アクションのテキストにコマンドのメインのキーボードショートカットが追加されたものになります。アクションのその他のプロパティは自動的に更新されません。

augmentActionWithShortcutToolTip()も参照してください 。

[static] QToolButton *Command::createToolButtonWithShortcutToolTip(Utils::Id commandId, QWidget *parent = nullptr)

commandId で指定されたコマンドのアイコン、アイコンテキスト、およびテキストを持つ新しいQToolButton を返します。ボタンの親を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.