本页内容

Core::IMode Class

class Core::IMode

IMode 类表示Qt Creator 中的一个模式。更多内容...

Header: #include <coreplugin/imode.h>
Inherits: QObject
Inherited By:

Core::DesignMode

属性

公共函数

IMode(QObject *parent = nullptr)
void addToMenu(QMenu *menu) const
Core::Context context() const
QString displayName() const
bool hasMenu() const
QIcon icon() const
Utils::Id id() const
bool isEnabled() const
int priority() const
void setContext(const Core::Context &context)
void setDisplayName(const QString &displayName)
void setEnabled(bool enabled)
void setIcon(const QIcon &icon)
void setId(Utils::Id id)
void setMenu(std::function<void (QMenu *)> menuFunction)
void setPriority(int priority)
void setWidget(QWidget *widget)
void setWidgetCreator(const std::function<QWidget *()> &widgetCreator)
QWidget *widget() const

信号

void enabledStateChanged(bool enabled)

详细说明

该类定义了一种模式及其在Qt Creator 主窗口左侧模式选择器中以工具按钮形式呈现的表示。

模式用于根据不同的开发任务显示不同的用户界面。因此,模式控制着Qt Creator 主窗口的大部分布局,但左侧的工具栏和状态栏除外。 例如,编辑模式(编写代码时最常用的模式)会显示代码编辑器以及各种导航和输出窗格。调试模式则通过可配置的调试相关信息布局来增强该视图。设计模式则将主窗口的全部空间留给图形编辑器。

当选定一种模式时,会添加一个上下文并显示一个控件。使用IMode::setContext() 来设置上下文,并使用IMode::setWidget() 直接设置控件,或者使用IMode::setWidgetCreator() 定义一个在需要控件时使用的函子。

添加模式应谨慎使用,仅作为最后手段。请先考虑您的功能是否可以作为INavigationWidgetFactory 、IOutputPane 、Perspective、独立对话框或特化的IEditor 来实现。

如果添加了模式,请考虑在模式布局的左侧添加一个 NavigationWidgetPlaceHolder,并在底部添加一个 OutputPanePlaceHolder。

模式在创建时会自动向Qt Creator 注册,在销毁时自动注销。

属性文档

displayName : QString

该属性存储了该模式的显示名称。

该显示名称显示在模式选择器中的模式图标下方。

访问函数:

QString displayName() const
void setDisplayName(const QString &displayName)

enabled : bool

该属性用于指定该模式是否已启用。

默认情况下,该属性的值为true 。

访问函数:

bool isEnabled() const
void setEnabled(bool enabled)

通知信号:

void enabledStateChanged(bool enabled)

icon : QIcon

该属性存储该模式的图标。

该图标将在模式选择器中显示该模式的图标。模式图标应支持 34x34 像素和 68x68 像素(适用于 HiDPI)两种尺寸。

访问函数:

QIcon icon() const
void setIcon(const QIcon &icon)

id : Utils::Id

该属性存储模式的 ID。

访问函数:

Utils::Id id() const
void setId(Utils::Id id)

priority : int

该属性用于指定模式的优先级。

优先级定义了模式在模式选择器中显示的顺序。优先级越高,该模式在列表中的位置就越靠前。欢迎模式应始终位于最上方,其优先级为 100。默认优先级为 -1。

访问函数:

int priority() const
void setPriority(int priority)

成员函数文档

IMode::IMode(QObject *parent = nullptr)

创建一个 IMode,并可选地指定parent 。

将该模式注册到Qt Creator 中。

void IMode::addToMenu(QMenu *menu) const

如果存在模式特定项,则将其添加到menu 中。

另请参阅 setMenu()。

Core::Context IMode::context() const

返回与该IMode 关联的上下文列表。

另请参阅 setContext()。

bool IMode::hasMenu() const

如果该模式提供了特定于该模式的上下文菜单项,则返回。

另请参阅 setMenu()。

void IMode::setContext(const Core::Context &context)

设置与该IMode 关联的context 。

另请参阅 context()。

void IMode::setMenu(std::function<void (QMenu *)> menuFunction)

设置一个menuFunction ,用于将特定于该模式的项目添加到该模式的上下文菜单中。每当通过新的QMenu 实例请求上下文菜单时,都会调用此方法。菜单在关闭后将被销毁。

另请参阅 hasMenu()。

void IMode::setWidget(QWidget *widget)

设置与该IMode 关联的widget 。

注意: 所传递小部件的所有权 不会发生改变。

另请参阅 widget() 和setWidgetCreator()。

void IMode::setWidgetCreator(const std::function<QWidget *()> &widgetCreator)

将widgetCreator 设置为在需要时创建与该IMode 关联的小部件。

注意:该 模式本身将拥有所创建小部件的所有权。

另请参阅 widget() 和setWidget()。

QWidget *IMode::widget() const

返回与该IMode 关联的小部件。

另请参阅 setWidget()。

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.