From 06c9898dbfb9c3060a0bac5be67d41228f0c7a7d Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 10 Jan 2024 12:19:53 +0100 Subject: [PATCH] HelloWorld: Move the plugin class definition to the .cpp The latest trend. Change-Id: Ic70739dec71e2102735021f5cf152abae6dfea12 Reviewed-by: Eike Ziller Reviewed-by: --- src/plugins/helloworld/CMakeLists.txt | 5 +- src/plugins/helloworld/helloworld.qbs | 1 - src/plugins/helloworld/helloworldplugin.cpp | 55 ++++++++++++--------- src/plugins/helloworld/helloworldplugin.h | 31 ------------ 4 files changed, 36 insertions(+), 56 deletions(-) delete mode 100644 src/plugins/helloworld/helloworldplugin.h diff --git a/src/plugins/helloworld/CMakeLists.txt b/src/plugins/helloworld/CMakeLists.txt index 18a93c47b8b..cbe3c5ce56b 100644 --- a/src/plugins/helloworld/CMakeLists.txt +++ b/src/plugins/helloworld/CMakeLists.txt @@ -2,7 +2,8 @@ add_qtc_plugin(HelloWorld SKIP_TRANSLATION PLUGIN_DEPENDS Core SOURCES - helloworldplugin.cpp helloworldplugin.h + helloworldplugin.cpp helloworldtr.h - helloworldwindow.cpp helloworldwindow.h + helloworldwindow.cpp + helloworldwindow.h ) diff --git a/src/plugins/helloworld/helloworld.qbs b/src/plugins/helloworld/helloworld.qbs index 41f6571426e..211f29c7d61 100644 --- a/src/plugins/helloworld/helloworld.qbs +++ b/src/plugins/helloworld/helloworld.qbs @@ -8,7 +8,6 @@ QtcPlugin { files: [ "helloworldplugin.cpp", - "helloworldplugin.h", "helloworldwindow.cpp", "helloworldwindow.h", "helloworldtr.h" diff --git a/src/plugins/helloworld/helloworldplugin.cpp b/src/plugins/helloworld/helloworldplugin.cpp index bd32a7f1f5a..6f341a6a0b8 100644 --- a/src/plugins/helloworld/helloworldplugin.cpp +++ b/src/plugins/helloworld/helloworldplugin.cpp @@ -1,8 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include "helloworldplugin.h" - #include "helloworldtr.h" #include @@ -12,6 +10,8 @@ #include #include +#include + #include #include #include @@ -22,7 +22,7 @@ namespace HelloWorld::Internal { /*! A mode with a push button based on BaseMode. */ -class HelloMode : public Core::IMode +class HelloMode final : public Core::IMode { public: 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 their constructor except for initializing their member variables. The actual work is done later, in the initialize() and extensionsInitialized() functions. */ -HelloWorldPlugin::HelloWorldPlugin() -{ -} +HelloWorldPlugin::HelloWorldPlugin() = default; /*! Plugins are responsible for deleting objects they created on the heap, and 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 // menu entry later. - Core::Context context("HelloWorld.MainView"); + const Core::Context context("HelloWorld.MainView"); // 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); QMenu *menu = helloWorldMenu->menu(); @@ -78,15 +92,19 @@ void HelloWorldPlugin::initialize() toolsMenu->addMenu(helloWorldMenu); // 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. Core::ActionBuilder hello(this, "HelloWorld.HelloWorldAction"); hello.setText(Tr::tr("Say \"&Hello World!\"")); hello.setContext(context); - hello.addOnTriggered(this, [this] { sayHelloWorld(); }); - - // Add the Hello World action command to the menu - hello.addToContainer(menuId); + hello.addToContainer(menuId); // Add the Hello World action command to the menu + hello.addOnTriggered(this, [] { + // 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?")); + }); // Add a mode with a push button based on BaseMode. 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 + +#include diff --git a/src/plugins/helloworld/helloworldplugin.h b/src/plugins/helloworld/helloworldplugin.h deleted file mode 100644 index 773308b2eb7..00000000000 --- a/src/plugins/helloworld/helloworldplugin.h +++ /dev/null @@ -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 - -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