forked from qt-creator/qt-creator
HelloWorld: Move the plugin class definition to the .cpp
The latest trend. Change-Id: Ic70739dec71e2102735021f5cf152abae6dfea12 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -2,7 +2,8 @@ add_qtc_plugin(HelloWorld
|
|||||||
SKIP_TRANSLATION
|
SKIP_TRANSLATION
|
||||||
PLUGIN_DEPENDS Core
|
PLUGIN_DEPENDS Core
|
||||||
SOURCES
|
SOURCES
|
||||||
helloworldplugin.cpp helloworldplugin.h
|
helloworldplugin.cpp
|
||||||
helloworldtr.h
|
helloworldtr.h
|
||||||
helloworldwindow.cpp helloworldwindow.h
|
helloworldwindow.cpp
|
||||||
|
helloworldwindow.h
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ QtcPlugin {
|
|||||||
|
|
||||||
files: [
|
files: [
|
||||||
"helloworldplugin.cpp",
|
"helloworldplugin.cpp",
|
||||||
"helloworldplugin.h",
|
|
||||||
"helloworldwindow.cpp",
|
"helloworldwindow.cpp",
|
||||||
"helloworldwindow.h",
|
"helloworldwindow.h",
|
||||||
"helloworldtr.h"
|
"helloworldtr.h"
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "helloworldplugin.h"
|
|
||||||
|
|
||||||
#include "helloworldtr.h"
|
#include "helloworldtr.h"
|
||||||
|
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
@@ -12,6 +10,8 @@
|
|||||||
#include <coreplugin/imode.h>
|
#include <coreplugin/imode.h>
|
||||||
#include <coreplugin/modemanager.h>
|
#include <coreplugin/modemanager.h>
|
||||||
|
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@@ -22,7 +22,7 @@ namespace HelloWorld::Internal {
|
|||||||
|
|
||||||
/*! A mode with a push button based on BaseMode. */
|
/*! A mode with a push button based on BaseMode. */
|
||||||
|
|
||||||
class HelloMode : public Core::IMode
|
class HelloMode final : public Core::IMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HelloMode()
|
HelloMode()
|
||||||
@@ -36,15 +36,29 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class HelloWorldPlugin final : public ExtensionSystem::IPlugin
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "HelloWorld.json")
|
||||||
|
|
||||||
|
public:
|
||||||
|
HelloWorldPlugin();
|
||||||
|
~HelloWorldPlugin() final;
|
||||||
|
|
||||||
|
void initialize() final;
|
||||||
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
|
private:
|
||||||
|
HelloMode *m_helloMode = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! Constructs the Hello World plugin. Normally plugins don't do anything in
|
/*! Constructs the Hello World plugin. Normally plugins don't do anything in
|
||||||
their constructor except for initializing their member variables. The
|
their constructor except for initializing their member variables. The
|
||||||
actual work is done later, in the initialize() and extensionsInitialized()
|
actual work is done later, in the initialize() and extensionsInitialized()
|
||||||
functions.
|
functions.
|
||||||
*/
|
*/
|
||||||
HelloWorldPlugin::HelloWorldPlugin()
|
HelloWorldPlugin::HelloWorldPlugin() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Plugins are responsible for deleting objects they created on the heap, and
|
/*! Plugins are responsible for deleting objects they created on the heap, and
|
||||||
to unregister objects from the plugin manager that they registered there.
|
to unregister objects from the plugin manager that they registered there.
|
||||||
@@ -62,10 +76,10 @@ void HelloWorldPlugin::initialize()
|
|||||||
{
|
{
|
||||||
// Create a unique context for our own view, that will be used for the
|
// Create a unique context for our own view, that will be used for the
|
||||||
// menu entry later.
|
// menu entry later.
|
||||||
Core::Context context("HelloWorld.MainView");
|
const Core::Context context("HelloWorld.MainView");
|
||||||
|
|
||||||
// Create our own menu to place in the Tools menu
|
// Create our own menu to place in the Tools menu
|
||||||
Utils::Id menuId = "HelloWorld.HelloWorldMenu";
|
const Utils::Id menuId = "HelloWorld.HelloWorldMenu";
|
||||||
|
|
||||||
Core::ActionContainer *helloWorldMenu = Core::ActionManager::createMenu(menuId);
|
Core::ActionContainer *helloWorldMenu = Core::ActionManager::createMenu(menuId);
|
||||||
QMenu *menu = helloWorldMenu->menu();
|
QMenu *menu = helloWorldMenu->menu();
|
||||||
@@ -78,15 +92,19 @@ void HelloWorldPlugin::initialize()
|
|||||||
toolsMenu->addMenu(helloWorldMenu);
|
toolsMenu->addMenu(helloWorldMenu);
|
||||||
|
|
||||||
// Create an action to be triggered by a menu entry.
|
// Create an action to be triggered by a menu entry.
|
||||||
// The Action builder registers the action with the action manager
|
// The ActionBuilder registers the action with Core::ActionManager
|
||||||
// on its destruction.
|
// on its destruction.
|
||||||
Core::ActionBuilder hello(this, "HelloWorld.HelloWorldAction");
|
Core::ActionBuilder hello(this, "HelloWorld.HelloWorldAction");
|
||||||
hello.setText(Tr::tr("Say \"&Hello World!\""));
|
hello.setText(Tr::tr("Say \"&Hello World!\""));
|
||||||
hello.setContext(context);
|
hello.setContext(context);
|
||||||
hello.addOnTriggered(this, [this] { sayHelloWorld(); });
|
hello.addToContainer(menuId); // Add the Hello World action command to the menu
|
||||||
|
hello.addOnTriggered(this, [] {
|
||||||
// Add the Hello World action command to the menu
|
// When passing nullptr for the parent, the message box becomes an
|
||||||
hello.addToContainer(menuId);
|
// application-global modal dialog box
|
||||||
|
QMessageBox::information(nullptr,
|
||||||
|
Tr::tr("Hello World!"),
|
||||||
|
Tr::tr("Hello World! Beautiful day today, isn't it?"));
|
||||||
|
});
|
||||||
|
|
||||||
// Add a mode with a push button based on BaseMode.
|
// Add a mode with a push button based on BaseMode.
|
||||||
m_helloMode = new HelloMode;
|
m_helloMode = new HelloMode;
|
||||||
@@ -107,13 +125,6 @@ void HelloWorldPlugin::extensionsInitialized()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelloWorldPlugin::sayHelloWorld()
|
|
||||||
{
|
|
||||||
// When passing nullptr for the parent, the message box becomes an
|
|
||||||
// application-global modal dialog box
|
|
||||||
QMessageBox::information(nullptr,
|
|
||||||
Tr::tr("Hello World!"),
|
|
||||||
Tr::tr("Hello World! Beautiful day today, isn't it?"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace HelloWorld::Internal
|
} // namespace HelloWorld::Internal
|
||||||
|
|
||||||
|
#include <helloworldplugin.moc>
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
|
||||||
|
|
||||||
namespace HelloWorld::Internal {
|
|
||||||
|
|
||||||
class HelloMode;
|
|
||||||
|
|
||||||
class HelloWorldPlugin
|
|
||||||
: public ExtensionSystem::IPlugin
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "HelloWorld.json")
|
|
||||||
|
|
||||||
public:
|
|
||||||
HelloWorldPlugin();
|
|
||||||
~HelloWorldPlugin() override;
|
|
||||||
|
|
||||||
void initialize() override;
|
|
||||||
void extensionsInitialized() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void sayHelloWorld();
|
|
||||||
|
|
||||||
HelloMode *m_helloMode = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace HelloWorld::Internal
|
|
||||||
Reference in New Issue
Block a user