Wizard: Update plugin creation to modern way

- Removed header file and global file as redundant
- Updated github workflow for creating artefacts

Change-Id: I60dc61b660791c57f012e6e38e04b0d84c2cbaf9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Artem Sokolovskii
2024-07-02 11:59:39 +02:00
parent a425a7dea1
commit 250d100787
6 changed files with 83 additions and 113 deletions

View File

@@ -16,11 +16,12 @@ project(%{PluginName})
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(QtCreator REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
set(QtX Qt${QT_VERSION_MAJOR})
find_package(Qt6 COMPONENTS Widgets REQUIRED)
# Add a CMake option that enables building your plugin with tests.
# You don't want your released plugin binaries to contain tests,
@@ -30,7 +31,7 @@ option(WITH_TESTS "Builds with tests" NO)
if(WITH_TESTS)
# Look for QtTest
find_package(${QtX} REQUIRED COMPONENTS Test)
find_package(Qt6 REQUIRED COMPONENTS Test)
# Tell CMake functions like add_qtc_plugin about the QtTest component.
set(IMPLICIT_DEPENDS Qt::Test)
@@ -43,7 +44,7 @@ add_qtc_plugin(%{PluginName}
PLUGIN_DEPENDS
QtCreator::Core
DEPENDS
${QtX}::Widgets
Qt::Widgets
QtCreator::ExtensionSystem
QtCreator::Utils
SOURCES
@@ -51,8 +52,6 @@ add_qtc_plugin(%{PluginName}
.github/workflows/README.md
README.md
%{SrcFileName}
%{HdrFileName}
%{GlobalHdrFileName}
%{ConstantsHdrFileName}
%{TrHdrFileName}
)

View File

@@ -7,6 +7,7 @@ env:
QT_VERSION: %{JS: Util.qtVersion()}
QT_CREATOR_VERSION: %{JS: Util.qtCreatorVersion()}
QT_CREATOR_SNAPSHOT: NO
MACOS_DEPLOYMENT_TARGET: 11.0
CMAKE_VERSION: 3.21.1
NINJA_VERSION: 1.10.1
@@ -107,17 +108,21 @@ jobs:
set(url_os "windows_x86")
set(qt_package_arch_suffix "win64_msvc2019_64")
set(qt_dir_prefix "${qt_version}/msvc2019_64")
set(qt_package_suffix "-Windows-Windows_10_21H2-MSVC2019-Windows-Windows_10_21H2-X86_64")
set(qt_package_suffix "-Windows-Windows_10_22H2-MSVC2019-Windows-Windows_10_22H2-X86_64")
elseif ("${{ runner.os }}" STREQUAL "Linux")
set(url_os "linux_x64")
if (qt_version VERSION_LESS "6.7.0")
set(qt_package_arch_suffix "gcc_64")
else()
set(qt_package_arch_suffix "linux_gcc_64")
endif()
set(qt_dir_prefix "${qt_version}/gcc_64")
set(qt_package_suffix "-Linux-RHEL_8_4-GCC-Linux-RHEL_8_4-X86_64")
set(qt_package_suffix "-Linux-RHEL_8_8-GCC-Linux-RHEL_8_8-X86_64")
elseif ("${{ runner.os }}" STREQUAL "macOS")
set(url_os "mac_x64")
set(qt_package_arch_suffix "clang_64")
set(qt_dir_prefix "${qt_version}/macos")
set(qt_package_suffix "-MacOS-MacOS_12-Clang-MacOS-MacOS_12-X86_64-ARM64")
set(qt_package_suffix "-MacOS-MacOS_13-Clang-MacOS-MacOS_13-X86_64-ARM64")
endif()
set(qt_base_url "https://download.qt.io/online/qtsdkrepository/${url_os}/desktop/qt6_${qt_version_dotless}")
@@ -202,7 +207,7 @@ jobs:
run: |
set(ENV{CC} ${{ matrix.config.cc }})
set(ENV{CXX} ${{ matrix.config.cxx }})
set(ENV{MACOSX_DEPLOYMENT_TARGET} "10.13")
set(ENV{MACOSX_DEPLOYMENT_TARGET} "${{ env.MACOS_DEPLOYMENT_TARGET }}")
if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
execute_process(
@@ -255,6 +260,7 @@ jobs:
release:
if: contains(github.ref, 'tags/v')
runs-on: ubuntu-latest
permissions: write-all
needs: build
steps:

View File

@@ -1,35 +1,42 @@
%{Cpp:LicenseTemplate}\
#include "%{HdrFileName}"
#include "%{ConstantsHdrFileName}"
#include "%{TrHdrFileName}"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <extensionsystem/iplugin.h>
#include <QAction>
#include <QMessageBox>
#include <QMainWindow>
#include <QMenu>
#include <QMessageBox>
namespace %{PluginName}::Internal {
%{CN}::%{CN}()
class %{CN} : public ExtensionSystem::IPlugin
{
// Create your members
}
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "%{PluginName}.json")
%{CN}::~%{CN}()
{
public:
%{CN}()
{
// Create your members
}
~%{CN}() final
{
// Unregister objects from the plugin manager's object pool
// Delete members
}
}
void %{CN}::initialize()
{
void initialize() final
{
// Register objects in the plugin manager's object pool
// Load settings
// Add actions to menus
@@ -42,8 +49,8 @@ void %{CN}::initialize()
// overload.
auto action = new QAction(Tr::tr("%{PluginName} Action"), this);
Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID,
Core::Context(Core::Constants::C_GLOBAL));
Core::Command *cmd = Core::ActionManager::registerAction(
action, Constants::ACTION_ID, Core::Context(Core::Constants::C_GLOBAL));
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+Meta+A")));
connect(action, &QAction::triggered, this, &%{CN}::triggerAction);
@@ -51,28 +58,32 @@ void %{CN}::initialize()
menu->menu()->setTitle(Tr::tr("%{PluginName}"));
menu->addAction(cmd);
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
}
}
void %{CN}::extensionsInitialized()
{
void extensionsInitialized() final
{
// Retrieve objects from the plugin manager's object pool
// In the extensionsInitialized function, a plugin can be sure that all
// plugins that depend on it are completely initialized.
}
}
ExtensionSystem::IPlugin::ShutdownFlag %{CN}::aboutToShutdown()
{
ShutdownFlag aboutToShutdown() final
{
// Save settings
// Disconnect from signals that are not needed during shutdown
// Hide UI (if you add UI that is not in the main window directly)
return SynchronousShutdown;
}
}
void %{CN}::triggerAction()
{
private:
void triggerAction()
{
QMessageBox::information(Core::ICore::mainWindow(),
Tr::tr("Action Triggered"),
Tr::tr("This is an action from %{PluginName}."));
}
}
};
} // namespace %{PluginName}::Internal
#include <%{MocFileName}>

View File

@@ -1,27 +0,0 @@
%{Cpp:LicenseTemplate}\
#pragma once
#include "%{GlobalHdrFileName}"
#include <extensionsystem/iplugin.h>
namespace %{PluginName}::Internal {
class %{CN} : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "%{PluginName}.json")
public:
%{CN}();
~%{CN}() override;
void initialize() override;
void extensionsInitialized() override;
ShutdownFlag aboutToShutdown() override;
private:
void triggerAction();
};
} // namespace %{PluginName}::Internal

View File

@@ -1,10 +0,0 @@
%{Cpp:LicenseTemplate}\
#pragma once
#include <qglobal.h>
#if defined(%{LibraryDefine})
# define %{LibraryExport} Q_DECL_EXPORT
#else
# define %{LibraryExport} Q_DECL_IMPORT
#endif

View File

@@ -19,8 +19,7 @@
{ "key": "LibraryDefine", "value": "%{JS: Cpp.headerGuard(value('PluginName')) + '_LIBRARY'}" },
{ "key": "LibraryExport", "value": "%{JS: Cpp.headerGuard(value('PluginName')) + '_EXPORT'}" },
{ "key": "SrcFileName", "value": "%{JS: Util.fileName(value('PluginNameLower'), Util.preferredSuffix('text/x-c++src'))}" },
{ "key": "HdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower'), Util.preferredSuffix('text/x-c++hdr'))}" },
{ "key": "GlobalHdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower') + '_global', Util.preferredSuffix('text/x-c++hdr'))}" },
{ "key": "MocFileName", "value": "%{JS: Util.fileName(value('PluginNameLower'), 'moc')}" },
{ "key": "ConstantsHdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower') + 'constants', Util.preferredSuffix('text/x-c++hdr'))}" },
{ "key": "TrHdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower') + 'tr', Util.preferredSuffix('text/x-c++hdr'))}" },
{ "key": "CN", "value": "%{JS: Cpp.className(value('PluginName') + 'Plugin')}" },
@@ -170,14 +169,6 @@
"source": "myplugin.cpp",
"target": "%{SrcFileName}"
},
{
"source": "myplugin.h",
"target": "%{HdrFileName}"
},
{
"source": "myplugin_global.h",
"target": "%{GlobalHdrFileName}"
},
{
"source": "mypluginconstants.h",
"target": "%{ConstantsHdrFileName}"
@@ -197,7 +188,7 @@
},
{
"source": "../projects/git.ignore",
"target": ".gitignore",
"target": ".gitignore"
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
}
]