ICore Class

class Core::ICore

The ICore class allows access to the different parts that make up the basic functionality of Qt Creator. More...

Header: #include <coreplugin/icore.h>
Inherits: QObject

Public Types

enum class ContextPriority { High, Low }

Signals

void contextAboutToChange(const QList<Core::IContext *> &context)
void contextChanged(const Core::Context &context)
void coreAboutToClose()
void coreAboutToOpen()
void coreOpened()
void saveSettingsRequested(Core::ICore::SaveSettingsReason reason)

Static Public Members

void addAdditionalContext(const Core::Context &context, Core::ICore::ContextPriority priority = ContextPriority::Low)
void addContextObject(Core::IContext *context)
void addPreCloseListener(const std::function<bool ()> &listener)
bool askForRestart(const QString &text, const QString &altButtonText = {})
Utils::FilePath cacheResourcePath(const QString &rel = {})
QList<Core::IContext *> contextObjects(QWidget *widget)
QList<Core::IContext *> currentContextObjects()
QWidget *currentContextWidget()
QWidget *dialogParent()
bool enablePlugins(const QSet<ExtensionSystem::PluginSpec *> &plugins)
Utils::InfoBar *infoBar()
Utils::FilePath installerResourcePath(const QString &rel = {})
Core::ICore *instance()
bool isNewItemDialogRunning()
Utils::FilePath libexecPath(const QString &rel = {})
QMainWindow *mainWindow()
QString msgShowOptionsDialog()
QString msgShowOptionsDialogToolTip()
QWidget *newItemDialog()
QPrinter *printer()
void raiseWindow(QWidget *widget)
void registerWindow(QWidget *window, const Core::Context &context, const Core::Context &actionContext = {})
void removeAdditionalContext(const Core::Context &context)
void removeContextObject(Core::IContext *context)
Utils::FilePath resourcePath(const QString &rel = {})
void restart()
Utils::QtcSettings *settings(QSettings::Scope scope = QSettings::UserScope)
void showNewItemDialog(const QString &title, const QList<Core::IWizardFactory *> &factories, const Utils::FilePath &defaultLocation = {}, const QVariantMap &extraVariables = {})
bool showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr)
bool showOptionsDialog(const Utils::Id page, Utils::Id item, QWidget *parent = nullptr)
bool showWarningWithOptions(const QString &title, const QString &text, const QString &details = QString(), Utils::Id settingsId = {}, QWidget *parent = nullptr)
void updateAdditionalContexts(const Core::Context &remove, const Core::Context &add, Core::ICore::ContextPriority priority = ContextPriority::Low)
QString userInterfaceLanguage()
Utils::FilePath userResourcePath(const QString &rel = {})
QString versionString()

Detailed Description

You should never create a subclass of this interface. The one and only instance is created by the Core plugin. You can access this instance from your plugin through instance().

Member Type Documentation

enum class ICore::ContextPriority

This enum defines the priority of additional contexts.

ConstantValueDescription
Core::ICore::ContextPriority::High0Additional contexts that have higher priority than contexts from Core::IContext instances.
Core::ICore::ContextPriority::Low1Additional contexts that have lower priority than contexts from Core::IContext instances.

See also Core::ICore::updateAdditionalContexts().

Member Function Documentation

[static] void ICore::addAdditionalContext(const Core::Context &context, Core::ICore::ContextPriority priority = ContextPriority::Low)

Adds context with priority to the list of active additional contexts.

See also updateAdditionalContexts().

[static] void ICore::addContextObject(Core::IContext *context)

Adds context to the list of registered IContext instances. Whenever the IContext's widget is in the application focus widget's parent hierarchy, its context is added to the list of active contexts.

See also removeContextObject(), updateAdditionalContexts(), currentContextObjects(), and The Action Manager and Commands.

[static] void ICore::addPreCloseListener(const std::function<bool ()> &listener)

Provides a hook for plugins to veto on closing the application.

When the application window requests a close, all listeners are called. If one of the listener calls returns false, the process is aborted and the event is ignored. If all calls return true, coreAboutToClose() is emitted and the event is accepted or performed.

[static] bool ICore::askForRestart(const QString &text, const QString &altButtonText = {})

Shows a modal dialog that asks the user if they want to restart Qt Creator. Uses text as the main text in the dialog, and triggers a restart of Qt Creator if the user chooses that option.

[static] Utils::FilePath ICore::cacheResourcePath(const QString &rel = {})

Returns a writable path for the relative path rel that can be used for persistent cache files.

[signal] void ICore::contextAboutToChange(const QList<Core::IContext *> &context)

Indicates that a new context will shortly become the current context (meaning that its widget got focus).

[signal] void ICore::contextChanged(const Core::Context &context)

Indicates that a new context just became the current context. This includes the context from the focus object as well as the additional context.

[static] QList<Core::IContext *> ICore::contextObjects(QWidget *widget)

Returns all registered IContext instance for the specified widget, if any.

[signal] void ICore::coreAboutToClose()

Enables plugins to perform some pre-end-of-life actions.

The application is guaranteed to shut down after this signal is emitted. It is there as an addition to the usual plugin lifecycle functions, namely IPlugin::aboutToShutdown(), just for convenience.

[signal] void ICore::coreAboutToOpen()

Indicates that all plugins have been loaded and the main window is about to be shown.

[signal] void ICore::coreOpened()

Indicates that all plugins have been loaded and the main window is shown.

[static] QList<Core::IContext *> ICore::currentContextObjects()

Returns a list IContexts for the current top level context widget, or an empty list if there is none.

See also updateAdditionalContexts(), addContextObject(), and The Action Manager and Commands.

[static] QWidget *ICore::currentContextWidget()

Returns the widget of the top level IContext of the current context, or nullptr if there is none.

See also currentContextObjects().

[static] QWidget *ICore::dialogParent()

Returns a widget pointer suitable to use as parent for QDialogs.

Especially for modal dialogs it is important to use the current modal dialog as a parent (if there is one) for the new dialog, because otherwise the new dialog can open behind the old one, while also blocking interaction with that. Using dialogParent() ensures this.

Also use dialogParent() for non-modal dialogs that do not need any specific lifetime management. If you need to control the lifetime of a non-modal dialog (for example because another part of the application depends on it), use a more specific parent instead.

[static] bool ICore::enablePlugins(const QSet<ExtensionSystem::PluginSpec *> &plugins)

Asks the user if they want to enable the plugins and their dependencies. If the user agrees, the plugins are enabled. If all plugins are soft loadable without restart, they get loaded directly. Otherwise the "Restart Required" dialog is shown.

Returns whether the user agreed to enabling the plugins.

[static] Utils::InfoBar *ICore::infoBar()

Returns a central InfoBar that is shown in Qt Creator's main window. Use for notifying the user of something without interrupting with dialog. Use sparingly.

[static] Utils::FilePath ICore::installerResourcePath(const QString &rel = {})

Returns the path, based on the relative path rel, to resources written by the installer, for example pre-defined kits and toolchains.

[static] Core::ICore *ICore::instance()

Returns the pointer to the instance. Only use for connecting to signals.

[static] bool ICore::isNewItemDialogRunning()

Returns whether the new item dialog is currently open.

[static] Utils::FilePath ICore::libexecPath(const QString &rel = {})

Returns the path, based on the relative path rel, to the command line tools that are included in the Qt Creator installation.

[static] QMainWindow *ICore::mainWindow()

Returns the main window of the application.

For dialog parents use dialogParent().

See also dialogParent().

[static] QString ICore::msgShowOptionsDialog()

Returns the text to use on buttons that open the options dialog.

See also showOptionsDialog() and msgShowOptionsDialogToolTip().

[static] QString ICore::msgShowOptionsDialogToolTip()

Returns the tool tip to use on buttons that open the options dialog.

See also showOptionsDialog() and msgShowOptionsDialog().

[static] QWidget *ICore::newItemDialog()

Returns the currently open new item dialog widget, or nullptr if there is none.

See also isNewItemDialogRunning() and showNewItemDialog().

[static] QPrinter *ICore::printer()

Returns the application's printer object.

Always use this printer object for printing, so the different parts of the application re-use its settings.

[static] void ICore::raiseWindow(QWidget *widget)

Raises and activates the window for widget. This contains workarounds for X11.

[static] void ICore::registerWindow(QWidget *window, const Core::Context &context, const Core::Context &actionContext = {})

Registers a window with the specified context. Registered windows are shown in the Window menu and get registered for the various window related actions, like the minimize, zoom, fullscreen and close actions. The context for the actions is context by default, but can be overridden with actionContext.

Whenever the application focus is in window, its context is made active.

[static] void ICore::removeAdditionalContext(const Core::Context &context)

Removes context from the list of active additional contexts.

See also updateAdditionalContexts().

[static] void ICore::removeContextObject(Core::IContext *context)

Unregisters a context object from the list of registered IContext instances. IContext instances are automatically removed when they are deleted.

See also addContextObject(), updateAdditionalContexts(), and currentContextObjects().

[static] Utils::FilePath ICore::resourcePath(const QString &rel = {})

Returns the absolute path for the relative path rel that is used for resources like project templates and the debugger macros.

This abstraction is needed to avoid platform-specific code all over the place, since on macOS, for example, the resources are part of the application bundle.

See also userResourcePath().

[static] void ICore::restart()

Restarts Qt Creator and restores the last session.

[signal] void ICore::saveSettingsRequested(Core::ICore::SaveSettingsReason reason)

Signals that the user has requested that the global settings should be saved to disk for a reason.

At the moment that happens when the application is closed, and on Save All.

[static] Utils::QtcSettings *ICore::settings(QSettings::Scope scope = QSettings::UserScope)

Returns the application's main settings object.

You can use it to retrieve or set application-wide settings (in contrast to session or project specific settings).

If scope is QSettings::UserScope (the default), the settings will be read from the user's settings, with a fallback to global settings provided with Qt Creator.

If scope is QSettings::SystemScope, only the installation settings shipped with the current version of Qt Creator will be read. This functionality exists for internal purposes only.

[static] void ICore::showNewItemDialog(const QString &title, const QList<Core::IWizardFactory *> &factories, const Utils::FilePath &defaultLocation = {}, const QVariantMap &extraVariables = {})

Opens a dialog where the user can choose from a set of factories that create new files or projects.

The title argument is shown as the dialog title. The path where the files will be created (if the user does not change it) is set in defaultLocation. Defaults to DocumentManager::projectsDirectory() or DocumentManager::fileDialogLastVisitedDirectory(), depending on wizard kind.

Additional variables for the wizards are set in extraVariables.

See also Core::DocumentManager, isNewItemDialogRunning(), and newItemDialog().

[static] bool ICore::showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr)

Opens the options dialog on the specified page. The dialog's parent defaults to dialogParent(). If the dialog is already shown when this method is called, it is just switched to the specified page.

Returns whether the user accepted the dialog.

See also msgShowOptionsDialog() and msgShowOptionsDialogToolTip().

[static] bool ICore::showOptionsDialog(const Utils::Id page, Utils::Id item, QWidget *parent = nullptr)

Opens the options dialog on the specified page. The dialog's parent defaults to dialogParent(). If the dialog is already shown when this method is called, it is just switched to the specified page. Pre-selects some part of the dialog specified by item which the dialog knows how to interpret.

Returns whether the user accepted the dialog.

See also msgShowOptionsDialog() and msgShowOptionsDialogToolTip().

[static] bool ICore::showWarningWithOptions(const QString &title, const QString &text, const QString &details = QString(), Utils::Id settingsId = {}, QWidget *parent = nullptr)

Creates a message box with parent that contains a Configure button for opening the settings page specified by settingsId.

The dialog has title and displays the message text and detailed information specified by details.

Use this function to display configuration errors and to point users to the setting they should fix.

Returns true if the user accepted the settings dialog.

See also showOptionsDialog().

[static] void ICore::updateAdditionalContexts(const Core::Context &remove, const Core::Context &add, Core::ICore::ContextPriority priority = ContextPriority::Low)

Removes the contexts specified by remove from the list of active additional contexts, and adds the contexts specified by add with priority.

The additional contexts are not associated with an IContext instance.

High priority additional contexts have higher priority than the contexts added by IContext instances, low priority additional contexts have lower priority than the contexts added by IContext instances.

See also addContextObject() and The Action Manager and Commands.

[static] QString ICore::userInterfaceLanguage()

Returns the locale string for the user interface language that is currently configured in Qt Creator. Use this to install your plugin's translation file with QTranslator.

[static] Utils::FilePath ICore::userResourcePath(const QString &rel = {})

Returns the absolute path for the relative path rel in the users directory that is used for resources like project templates.

Use this function for finding the place for resources that the user may write to, for example, to allow for custom palettes or templates.

See also resourcePath().

[static] QString ICore::versionString()

Returns a string with the IDE's name and version, in the form "Qt Creator X.Y.Z". Use this for "Generated by" strings and similar tasks.

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.