forked from qt-creator/qt-creator
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:
@@ -16,11 +16,12 @@ project(%{PluginName})
|
|||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_AUTORCC ON)
|
set(CMAKE_AUTORCC ON)
|
||||||
set(CMAKE_AUTOUIC 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(QtCreator REQUIRED COMPONENTS Core)
|
||||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
find_package(Qt6 COMPONENTS Widgets REQUIRED)
|
||||||
set(QtX Qt${QT_VERSION_MAJOR})
|
|
||||||
|
|
||||||
# Add a CMake option that enables building your plugin with tests.
|
# Add a CMake option that enables building your plugin with tests.
|
||||||
# You don't want your released plugin binaries to contain 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)
|
if(WITH_TESTS)
|
||||||
# Look for QtTest
|
# 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.
|
# Tell CMake functions like add_qtc_plugin about the QtTest component.
|
||||||
set(IMPLICIT_DEPENDS Qt::Test)
|
set(IMPLICIT_DEPENDS Qt::Test)
|
||||||
@@ -43,7 +44,7 @@ add_qtc_plugin(%{PluginName}
|
|||||||
PLUGIN_DEPENDS
|
PLUGIN_DEPENDS
|
||||||
QtCreator::Core
|
QtCreator::Core
|
||||||
DEPENDS
|
DEPENDS
|
||||||
${QtX}::Widgets
|
Qt::Widgets
|
||||||
QtCreator::ExtensionSystem
|
QtCreator::ExtensionSystem
|
||||||
QtCreator::Utils
|
QtCreator::Utils
|
||||||
SOURCES
|
SOURCES
|
||||||
@@ -51,8 +52,6 @@ add_qtc_plugin(%{PluginName}
|
|||||||
.github/workflows/README.md
|
.github/workflows/README.md
|
||||||
README.md
|
README.md
|
||||||
%{SrcFileName}
|
%{SrcFileName}
|
||||||
%{HdrFileName}
|
|
||||||
%{GlobalHdrFileName}
|
|
||||||
%{ConstantsHdrFileName}
|
%{ConstantsHdrFileName}
|
||||||
%{TrHdrFileName}
|
%{TrHdrFileName}
|
||||||
)
|
)
|
||||||
|
@@ -7,6 +7,7 @@ env:
|
|||||||
QT_VERSION: %{JS: Util.qtVersion()}
|
QT_VERSION: %{JS: Util.qtVersion()}
|
||||||
QT_CREATOR_VERSION: %{JS: Util.qtCreatorVersion()}
|
QT_CREATOR_VERSION: %{JS: Util.qtCreatorVersion()}
|
||||||
QT_CREATOR_SNAPSHOT: NO
|
QT_CREATOR_SNAPSHOT: NO
|
||||||
|
MACOS_DEPLOYMENT_TARGET: 11.0
|
||||||
CMAKE_VERSION: 3.21.1
|
CMAKE_VERSION: 3.21.1
|
||||||
NINJA_VERSION: 1.10.1
|
NINJA_VERSION: 1.10.1
|
||||||
|
|
||||||
@@ -107,17 +108,21 @@ jobs:
|
|||||||
set(url_os "windows_x86")
|
set(url_os "windows_x86")
|
||||||
set(qt_package_arch_suffix "win64_msvc2019_64")
|
set(qt_package_arch_suffix "win64_msvc2019_64")
|
||||||
set(qt_dir_prefix "${qt_version}/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")
|
elseif ("${{ runner.os }}" STREQUAL "Linux")
|
||||||
set(url_os "linux_x64")
|
set(url_os "linux_x64")
|
||||||
set(qt_package_arch_suffix "gcc_64")
|
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_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")
|
elseif ("${{ runner.os }}" STREQUAL "macOS")
|
||||||
set(url_os "mac_x64")
|
set(url_os "mac_x64")
|
||||||
set(qt_package_arch_suffix "clang_64")
|
set(qt_package_arch_suffix "clang_64")
|
||||||
set(qt_dir_prefix "${qt_version}/macos")
|
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()
|
endif()
|
||||||
|
|
||||||
set(qt_base_url "https://download.qt.io/online/qtsdkrepository/${url_os}/desktop/qt6_${qt_version_dotless}")
|
set(qt_base_url "https://download.qt.io/online/qtsdkrepository/${url_os}/desktop/qt6_${qt_version_dotless}")
|
||||||
@@ -202,7 +207,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set(ENV{CC} ${{ matrix.config.cc }})
|
set(ENV{CC} ${{ matrix.config.cc }})
|
||||||
set(ENV{CXX} ${{ matrix.config.cxx }})
|
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")
|
if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
|
||||||
execute_process(
|
execute_process(
|
||||||
@@ -255,6 +260,7 @@ jobs:
|
|||||||
release:
|
release:
|
||||||
if: contains(github.ref, 'tags/v')
|
if: contains(github.ref, 'tags/v')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions: write-all
|
||||||
needs: build
|
needs: build
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@@ -1,78 +1,89 @@
|
|||||||
%{Cpp:LicenseTemplate}\
|
%{Cpp:LicenseTemplate}\
|
||||||
#include "%{HdrFileName}"
|
|
||||||
#include "%{ConstantsHdrFileName}"
|
#include "%{ConstantsHdrFileName}"
|
||||||
#include "%{TrHdrFileName}"
|
#include "%{TrHdrFileName}"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
#include <coreplugin/icontext.h>
|
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
|
#include <coreplugin/icontext.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
namespace %{PluginName}::Internal {
|
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}()
|
||||||
// Unregister objects from the plugin manager's object pool
|
{
|
||||||
// Delete members
|
// Create your members
|
||||||
}
|
}
|
||||||
|
|
||||||
void %{CN}::initialize()
|
~%{CN}() final
|
||||||
{
|
{
|
||||||
// Register objects in the plugin manager's object pool
|
// Unregister objects from the plugin manager's object pool
|
||||||
// Load settings
|
// Delete members
|
||||||
// Add actions to menus
|
}
|
||||||
// Connect to other plugins' signals
|
|
||||||
// In the initialize function, a plugin can be sure that the plugins it
|
|
||||||
// depends on have initialized their members.
|
|
||||||
|
|
||||||
// If you need access to command line arguments or to report errors, use the
|
void initialize() final
|
||||||
// bool IPlugin::initialize(const QStringList &arguments, QString *errorString)
|
{
|
||||||
// overload.
|
// Register objects in the plugin manager's object pool
|
||||||
|
// Load settings
|
||||||
|
// Add actions to menus
|
||||||
|
// Connect to other plugins' signals
|
||||||
|
// In the initialize function, a plugin can be sure that the plugins it
|
||||||
|
// depends on have initialized their members.
|
||||||
|
|
||||||
auto action = new QAction(Tr::tr("%{PluginName} Action"), this);
|
// If you need access to command line arguments or to report errors, use the
|
||||||
Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID,
|
// bool IPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||||
Core::Context(Core::Constants::C_GLOBAL));
|
// overload.
|
||||||
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+Meta+A")));
|
|
||||||
connect(action, &QAction::triggered, this, &%{CN}::triggerAction);
|
|
||||||
|
|
||||||
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID);
|
auto action = new QAction(Tr::tr("%{PluginName} Action"), this);
|
||||||
menu->menu()->setTitle(Tr::tr("%{PluginName}"));
|
Core::Command *cmd = Core::ActionManager::registerAction(
|
||||||
menu->addAction(cmd);
|
action, Constants::ACTION_ID, Core::Context(Core::Constants::C_GLOBAL));
|
||||||
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
|
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+Meta+A")));
|
||||||
}
|
connect(action, &QAction::triggered, this, &%{CN}::triggerAction);
|
||||||
|
|
||||||
void %{CN}::extensionsInitialized()
|
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID);
|
||||||
{
|
menu->menu()->setTitle(Tr::tr("%{PluginName}"));
|
||||||
// Retrieve objects from the plugin manager's object pool
|
menu->addAction(cmd);
|
||||||
// In the extensionsInitialized function, a plugin can be sure that all
|
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
|
||||||
// plugins that depend on it are completely initialized.
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ExtensionSystem::IPlugin::ShutdownFlag %{CN}::aboutToShutdown()
|
void extensionsInitialized() final
|
||||||
{
|
{
|
||||||
// Save settings
|
// Retrieve objects from the plugin manager's object pool
|
||||||
// Disconnect from signals that are not needed during shutdown
|
// In the extensionsInitialized function, a plugin can be sure that all
|
||||||
// Hide UI (if you add UI that is not in the main window directly)
|
// plugins that depend on it are completely initialized.
|
||||||
return SynchronousShutdown;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void %{CN}::triggerAction()
|
ShutdownFlag aboutToShutdown() final
|
||||||
{
|
{
|
||||||
QMessageBox::information(Core::ICore::mainWindow(),
|
// Save settings
|
||||||
Tr::tr("Action Triggered"),
|
// Disconnect from signals that are not needed during shutdown
|
||||||
Tr::tr("This is an action from %{PluginName}."));
|
// Hide UI (if you add UI that is not in the main window directly)
|
||||||
}
|
return SynchronousShutdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void triggerAction()
|
||||||
|
{
|
||||||
|
QMessageBox::information(Core::ICore::mainWindow(),
|
||||||
|
Tr::tr("Action Triggered"),
|
||||||
|
Tr::tr("This is an action from %{PluginName}."));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace %{PluginName}::Internal
|
} // namespace %{PluginName}::Internal
|
||||||
|
|
||||||
|
#include <%{MocFileName}>
|
||||||
|
@@ -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
|
|
@@ -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
|
|
@@ -19,8 +19,7 @@
|
|||||||
{ "key": "LibraryDefine", "value": "%{JS: Cpp.headerGuard(value('PluginName')) + '_LIBRARY'}" },
|
{ "key": "LibraryDefine", "value": "%{JS: Cpp.headerGuard(value('PluginName')) + '_LIBRARY'}" },
|
||||||
{ "key": "LibraryExport", "value": "%{JS: Cpp.headerGuard(value('PluginName')) + '_EXPORT'}" },
|
{ "key": "LibraryExport", "value": "%{JS: Cpp.headerGuard(value('PluginName')) + '_EXPORT'}" },
|
||||||
{ "key": "SrcFileName", "value": "%{JS: Util.fileName(value('PluginNameLower'), Util.preferredSuffix('text/x-c++src'))}" },
|
{ "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": "MocFileName", "value": "%{JS: Util.fileName(value('PluginNameLower'), 'moc')}" },
|
||||||
{ "key": "GlobalHdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower') + '_global', Util.preferredSuffix('text/x-c++hdr'))}" },
|
|
||||||
{ "key": "ConstantsHdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower') + 'constants', Util.preferredSuffix('text/x-c++hdr'))}" },
|
{ "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": "TrHdrFileName", "value": "%{JS: Util.fileName(value('PluginNameLower') + 'tr', Util.preferredSuffix('text/x-c++hdr'))}" },
|
||||||
{ "key": "CN", "value": "%{JS: Cpp.className(value('PluginName') + 'Plugin')}" },
|
{ "key": "CN", "value": "%{JS: Cpp.className(value('PluginName') + 'Plugin')}" },
|
||||||
@@ -170,14 +169,6 @@
|
|||||||
"source": "myplugin.cpp",
|
"source": "myplugin.cpp",
|
||||||
"target": "%{SrcFileName}"
|
"target": "%{SrcFileName}"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"source": "myplugin.h",
|
|
||||||
"target": "%{HdrFileName}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "myplugin_global.h",
|
|
||||||
"target": "%{GlobalHdrFileName}"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"source": "mypluginconstants.h",
|
"source": "mypluginconstants.h",
|
||||||
"target": "%{ConstantsHdrFileName}"
|
"target": "%{ConstantsHdrFileName}"
|
||||||
@@ -197,7 +188,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"source": "../projects/git.ignore",
|
"source": "../projects/git.ignore",
|
||||||
"target": ".gitignore",
|
"target": ".gitignore"
|
||||||
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
|
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user