From 6c9f75ff4a6a98cb45fa48928b1d8ef25d3d14ad Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 27 Aug 2019 16:38:03 +0200 Subject: [PATCH] Transform Qt Quick 2 Extension Plugin wizard to JSON Change-Id: I0e59219adeb5b3aa08a99da7c0bb657d793ba2e1 Reviewed-by: Christian Kandeler --- .../{ => projects}/qtquick2-extension/lib.png | Bin .../qtquick2-extension/lib@2x.png | Bin .../qtquick2-extension/object.cpp | 8 +- .../projects/qtquick2-extension/object.h | 23 ++++ .../projects/qtquick2-extension/plugin.cpp | 12 ++ .../qtquick2-extension/plugin.h | 9 +- .../qtquick2-extension/project.pro | 18 +-- .../projects/qtquick2-extension/qmldir | 2 + .../projects/qtquick2-extension/wizard.json | 109 ++++++++++++++++++ .../wizards/qtquick2-extension/object.h | 22 ---- .../wizards/qtquick2-extension/plugin.cpp | 11 -- .../wizards/qtquick2-extension/qmldir | 2 - .../wizards/qtquick2-extension/wizard.xml | 66 ----------- 13 files changed, 164 insertions(+), 118 deletions(-) rename share/qtcreator/templates/wizards/{ => projects}/qtquick2-extension/lib.png (100%) rename share/qtcreator/templates/wizards/{ => projects}/qtquick2-extension/lib@2x.png (100%) rename share/qtcreator/templates/wizards/{ => projects}/qtquick2-extension/object.cpp (62%) create mode 100644 share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h create mode 100644 share/qtcreator/templates/wizards/projects/qtquick2-extension/plugin.cpp rename share/qtcreator/templates/wizards/{ => projects}/qtquick2-extension/plugin.h (61%) rename share/qtcreator/templates/wizards/{ => projects}/qtquick2-extension/project.pro (56%) create mode 100644 share/qtcreator/templates/wizards/projects/qtquick2-extension/qmldir create mode 100644 share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json delete mode 100644 share/qtcreator/templates/wizards/qtquick2-extension/object.h delete mode 100644 share/qtcreator/templates/wizards/qtquick2-extension/plugin.cpp delete mode 100644 share/qtcreator/templates/wizards/qtquick2-extension/qmldir delete mode 100644 share/qtcreator/templates/wizards/qtquick2-extension/wizard.xml diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/lib.png b/share/qtcreator/templates/wizards/projects/qtquick2-extension/lib.png similarity index 100% rename from share/qtcreator/templates/wizards/qtquick2-extension/lib.png rename to share/qtcreator/templates/wizards/projects/qtquick2-extension/lib.png diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/lib@2x.png b/share/qtcreator/templates/wizards/projects/qtquick2-extension/lib@2x.png similarity index 100% rename from share/qtcreator/templates/wizards/qtquick2-extension/lib@2x.png rename to share/qtcreator/templates/wizards/projects/qtquick2-extension/lib@2x.png diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/object.cpp b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.cpp similarity index 62% rename from share/qtcreator/templates/wizards/qtquick2-extension/object.cpp rename to share/qtcreator/templates/wizards/projects/qtquick2-extension/object.cpp index 15fe4052427..a2288c47c1c 100644 --- a/share/qtcreator/templates/wizards/qtquick2-extension/object.cpp +++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.cpp @@ -1,7 +1,7 @@ -#include "%ObjectName:l%.%CppHeaderSuffix%" +#include "%{ObjectHdr}" -%ObjectName%::%ObjectName%(QQuickItem *parent): - QQuickItem(parent) +%{ObjectName}::%{ObjectName}(QQuickItem *parent) + : QQuickItem(parent) { // By default, QQuickItem does not draw anything. If you subclass // QQuickItem to create a visual item, you will need to uncomment the @@ -10,6 +10,6 @@ // setFlag(ItemHasContents, true); } -%ObjectName%::~%ObjectName%() +%{ObjectName}::~%{ObjectName}() { } diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h new file mode 100644 index 00000000000..e74c4233e87 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h @@ -0,0 +1,23 @@ +%{Cpp:LicenseTemplate}\ +@if '%{Cpp:PragmaOnce}' +#pragma once +@else +#ifndef %{OBJECTGUARD} +#define %{OBJECTGUARD} +@endif + +#include + +class %{ObjectName} : public QQuickItem +{ + Q_OBJECT + Q_DISABLE_COPY(%{ObjectName}) + +public: + explicit %{ObjectName}(QQuickItem *parent = nullptr); + ~%{ObjectName}() override; +}; + +@if ! '%{Cpp:PragmaOnce}' +#endif // %{OBJECTGUARD} +@endif diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/plugin.cpp b/share/qtcreator/templates/wizards/projects/qtquick2-extension/plugin.cpp new file mode 100644 index 00000000000..69afb9baddf --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/plugin.cpp @@ -0,0 +1,12 @@ +#include "%{PluginHdr}" + +#include "%{ObjectHdr}" + +#include + +void %{PluginName}::registerTypes(const char *uri) +{ + // @uri %{Uri} + qmlRegisterType<%{ObjectName}>(uri, 1, 0, "%{ObjectName}"); +} + diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/plugin.h b/share/qtcreator/templates/wizards/projects/qtquick2-extension/plugin.h similarity index 61% rename from share/qtcreator/templates/wizards/qtquick2-extension/plugin.h rename to share/qtcreator/templates/wizards/projects/qtquick2-extension/plugin.h index a7a18893ef4..539aee0d5d6 100644 --- a/share/qtcreator/templates/wizards/qtquick2-extension/plugin.h +++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/plugin.h @@ -1,13 +1,14 @@ +%{Cpp:LicenseTemplate}\ @if '%{Cpp:PragmaOnce}' #pragma once @else -#ifndef %ProjectName:h%_PLUGIN_H -#define %ProjectName:h%_PLUGIN_H +#ifndef %{PLUGINGUARD} +#define %{PLUGINGUARD} @endif #include -class %ProjectName:s%Plugin : public QQmlExtensionPlugin +class %{PluginName} : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) @@ -17,5 +18,5 @@ public: }; @if ! '%{Cpp:PragmaOnce}' -#endif // %ProjectName:h%_PLUGIN_H +#endif // %{PLUGINGUARD} @endif diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/project.pro b/share/qtcreator/templates/wizards/projects/qtquick2-extension/project.pro similarity index 56% rename from share/qtcreator/templates/wizards/qtquick2-extension/project.pro rename to share/qtcreator/templates/wizards/projects/qtquick2-extension/project.pro index b9677739e41..78d4325d320 100644 --- a/share/qtcreator/templates/wizards/qtquick2-extension/project.pro +++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/project.pro @@ -1,26 +1,26 @@ TEMPLATE = lib -TARGET = %ProjectName% +TARGET = %{ProjectName} QT += qml quick CONFIG += plugin c++11 TARGET = $$qtLibraryTarget($$TARGET) -uri = %Uri% +uri = %{Uri} # Input -SOURCES += \ - %ProjectName:l%_plugin.%CppSourceSuffix% \ - %ObjectName:l%.%CppSourceSuffix% +SOURCES += \\ + %{PluginSrc} \\ + %{ObjectSrc} -HEADERS += \ - %ProjectName:l%_plugin.%CppHeaderSuffix% \ - %ObjectName:l%.%CppHeaderSuffix% +HEADERS += \\ + %{PluginHdr} \\ + %{ObjectHdr} DISTFILES = qmldir !equals(_PRO_FILE_PWD_, $$OUT_PWD) { copy_qmldir.target = $$OUT_PWD/qmldir copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir - copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" + copy_qmldir.commands = $(COPY_FILE) "$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)" "$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)" QMAKE_EXTRA_TARGETS += copy_qmldir PRE_TARGETDEPS += $$copy_qmldir.target } diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/qmldir b/share/qtcreator/templates/wizards/projects/qtquick2-extension/qmldir new file mode 100644 index 00000000000..8a3038ae486 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/qmldir @@ -0,0 +1,2 @@ +module %{Uri} +plugin %{ProjectName} diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json b/share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json new file mode 100644 index 00000000000..f548d18c9bd --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json @@ -0,0 +1,109 @@ +{ + "version": 1, + "supportedProjectTypes": [ "Qt4ProjectManager.Qt4Project" ], + "id": "M.QtQuick2ExtensionPlugin", + "category": "G.Library", + "trDescription": "Creates a C++ plugin to load Qt Quick extensions dynamically into applications using the QQmlEngine class.", + "trDisplayName": "Qt Quick 2 Extension Plugin", + "trDisplayCategory": "Library", + "icon": "lib.png", + "featuresRequired": [ "QtSupport.Wizards.FeatureQtQuick", "QtSupport.Wizards.FeatureQtQuick.2" ], + "enabled": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0}", + + "options": + [ + { "key": "ProjectFile", "value": "%{ProFile}" }, + { "key": "ProFile", "value": "%{JS: Util.fileName(value('ProjectDirectory') + '/' + value('ProjectName'), 'pro')}" }, + { "key": "PluginBaseFileName", "value": "%{JS: value('ProjectName') + '_plugin'}" }, + { "key": "PluginSrc", "value": "%{JS: Cpp.classToFileName(value('PluginBaseFileName'), Util.preferredSuffix('text/x-c++src'))}" }, + { "key": "PluginHdr", "value": "%{JS: Cpp.classToFileName(value('PluginBaseFileName'), Util.preferredSuffix('text/x-c++hdr'))}" }, + { "key": "ObjectSrc", "value": "%{JS: Cpp.classToFileName(value('ObjectName'), Util.preferredSuffix('text/x-c++src'))}" }, + { "key": "ObjectHdr", "value": "%{JS: Cpp.classToFileName(value('ObjectName'), Util.preferredSuffix('text/x-c++hdr'))}" }, + { "key": "PluginName", "value": "%{JS: value('ProjectName').charAt(0).toUpperCase() + value('ProjectName').slice(1) + 'Plugin' }" }, + { "key": "PLUGINGUARD", "value": "%{JS: Cpp.classToHeaderGuard(value('PluginBaseFileName'), Util.preferredSuffix('text/x-c++hdr'))}" }, + { "key": "OBJECTGUARD", "value": "%{JS: Cpp.classToHeaderGuard(value('ObjectName'), Util.preferredSuffix('text/x-c++hdr'))}" } + ], + + "pages": + [ + { + "trDisplayName": "Project Location", + "trShortTitle": "Location", + "typeId": "Project" + }, + { + "trDisplayName": "Custom Parameters", + "trShortTitle": "Details", + "typeId": "Fields", + "data": + [ + { + "name": "ObjectName", + "trDisplayName": "Object class-name:", + "mandatory": true, + "type": "LineEdit", + "data": + { + "validator": "^[A-Za-z0-9_]+$", + "trText": "MyItem" + } + }, + { + "name": "Uri", + "trDisplayName": "URI:", + "mandatory": true, + "type": "LineEdit", + "data": + { + "validator": "^[A-Za-z0-9]+([A-Za-z0-9-]*[A-Za-z0-9]+)?(\.[A-Za-z0-9]+([-A-Za-z0-9]*[A-Za-z0-9]+)?)*$", + "trText": "com.mycompany.qmlcomponents" + } + } + ] + }, + { + "trDisplayName": "Project Management", + "trShortTitle": "Summary", + "typeId": "Summary" + } + ], + "generators": + [ + { + "typeId": "File", + "data": + [ + { + "source": "project.pro", + "target": "%{ProFile}", + "openAsProject": true + }, + { + "source": "qmldir", + "target": "qmldir" + }, + { + "source": "plugin.cpp", + "target": "%{PluginSrc}" + }, + { + "source": "plugin.h", + "target": "%{PluginHdr}" + }, + { + "source": "object.cpp", + "target": "%{ObjectSrc}" + }, + { + "source": "object.h", + "target": "%{ObjectHdr}" + }, + { + "source": "../git.ignore", + "target": ".gitignore", + "condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}" + } + ] + } + ] +} diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/object.h b/share/qtcreator/templates/wizards/qtquick2-extension/object.h deleted file mode 100644 index cabd5229db3..00000000000 --- a/share/qtcreator/templates/wizards/qtquick2-extension/object.h +++ /dev/null @@ -1,22 +0,0 @@ -@if '%{Cpp:PragmaOnce}' -#pragma once -@else -#ifndef %ObjectName:u%_H -#define %ObjectName:u%_H -@endif - -#include - -class %ObjectName% : public QQuickItem -{ - Q_OBJECT - Q_DISABLE_COPY(%ObjectName%) - -public: - explicit %ObjectName%(QQuickItem *parent = nullptr); - ~%ObjectName%() override; -}; - -@if ! '%{Cpp:PragmaOnce}' -#endif // %ObjectName:u%_H -@endif diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/plugin.cpp b/share/qtcreator/templates/wizards/qtquick2-extension/plugin.cpp deleted file mode 100644 index c4ff1b1732a..00000000000 --- a/share/qtcreator/templates/wizards/qtquick2-extension/plugin.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "%ProjectName:l%_plugin.%CppHeaderSuffix%" -#include "%ObjectName:l%.%CppHeaderSuffix%" - -#include - -void %ProjectName:s%Plugin::registerTypes(const char *uri) -{ - // @uri %Uri% - qmlRegisterType<%ObjectName%>(uri, 1, 0, "%ObjectName:c%"); -} - diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/qmldir b/share/qtcreator/templates/wizards/qtquick2-extension/qmldir deleted file mode 100644 index f1f54802f3a..00000000000 --- a/share/qtcreator/templates/wizards/qtquick2-extension/qmldir +++ /dev/null @@ -1,2 +0,0 @@ -module %Uri% -plugin %ProjectName% diff --git a/share/qtcreator/templates/wizards/qtquick2-extension/wizard.xml b/share/qtcreator/templates/wizards/qtquick2-extension/wizard.xml deleted file mode 100644 index 2c3a288c0c9..00000000000 --- a/share/qtcreator/templates/wizards/qtquick2-extension/wizard.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - lib.png - Creates a C++ plugin to load extensions dynamically into applications using the QQmlEngine class. Requires Qt 5.0 or newer. - Qt Quick 2 Extension Plugin - Library - - - - - - - - - - Custom QML Extension Plugin Parameters - - - - Object class-name: - - - - URI: - - - - - The project name and the object class-name cannot be the same. - - -