summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Sokolovskii <artem.sokolovskii@qt.io>2022-03-09 16:27:06 +0100
committerArtem Sokolovskii <artem.sokolovskii@qt.io>2022-03-21 12:47:11 +0000
commitb06db48869e8c698997e0777617d775052fd681f (patch)
treef32a39e60546809e59d86bc5b5eac6aa39f8aad7
parent6f520f8783292e6bc31cd96082e4459a61d1a772 (diff)
downloadqt-creator-b06db48869e8c698997e0777617d775052fd681f.tar.gz
Wizard: Improve QtQuick2 extension plugin
- Added options for Kit version - Added CMake support for Qt6.2 - Added options for creating example project, which uses the plugin Task-number: QTCREATORBUG-26982 Change-Id: I808c01bce6e4015a679f2fd69767c13179a25ee5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r--share/qtcreator/templates/wizards/projects/qtquick2-extension/CMakeLists.6.x.txt44
-rw-r--r--share/qtcreator/templates/wizards/projects/qtquick2-extension/example/example.cpp23
-rw-r--r--share/qtcreator/templates/wizards/projects/qtquick2-extension/example/example.qml29
-rw-r--r--share/qtcreator/templates/wizards/projects/qtquick2-extension/object.cpp14
-rw-r--r--share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h7
-rw-r--r--share/qtcreator/templates/wizards/projects/qtquick2-extension/object.qml10
-rw-r--r--share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json142
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp6
8 files changed, 264 insertions, 11 deletions
diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/CMakeLists.6.x.txt b/share/qtcreator/templates/wizards/projects/qtquick2-extension/CMakeLists.6.x.txt
new file mode 100644
index 0000000000..a6ddf3cb48
--- /dev/null
+++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/CMakeLists.6.x.txt
@@ -0,0 +1,44 @@
+cmake_minimum_required(VERSION 3.16)
+
+project(%{ProjectName} VERSION 0.1 LANGUAGES CXX)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
+
+find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
+
+qt_add_library(%{ProjectName} STATIC)
+qt_add_qml_module(%{ProjectName}
+ URI %{ProjectName}
+ VERSION 1.0
+ QML_FILES %{ObjectQml}
+ SOURCES %{ObjectSrc} %{ObjectHdr}
+)
+
+set_target_properties(%{ProjectName} PROPERTIES
+ MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
+ MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
+ MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
+ MACOSX_BUNDLE TRUE
+ WIN32_EXECUTABLE TRUE
+)
+
+target_compile_definitions(%{ProjectName}
+ PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
+target_link_libraries(%{ProjectName}
+ PRIVATE Qt6::Quick)
+
+target_include_directories(%{ProjectName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+
+@if %{CreateExampleProject}
+# Example Project
+qt_add_executable(ExampleProject example/example.cpp)
+qt_add_qml_module(ExampleProject
+ URI ExampleProjectApp
+ VERSION 1.0
+ QML_FILES example/example.qml
+)
+target_link_libraries(ExampleProject PRIVATE Qt6::Quick %{ProjectName}plugin)
+target_compile_definitions(ExampleProject PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
+@endif
diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/example/example.cpp b/share/qtcreator/templates/wizards/projects/qtquick2-extension/example/example.cpp
new file mode 100644
index 0000000000..70a4b10b1c
--- /dev/null
+++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/example/example.cpp
@@ -0,0 +1,23 @@
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+#include <QtQml/qqmlextensionplugin.h>
+
+Q_IMPORT_QML_PLUGIN(%{ProjectName}Plugin)
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QQmlApplicationEngine engine;
+ // The first subfolder is the libraryName followed by the regular
+ // folder structure: LibararyName/Subfolder
+ const QUrl url(u"qrc:/ExampleProjectApp/example/example.qml"_qs);
+ QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
+ &app, [url](QObject *obj, const QUrl &objUrl) {
+ if (!obj && url == objUrl)
+ QCoreApplication::exit(-1);
+ }, Qt::QueuedConnection);
+ engine.load(url);
+
+ return app.exec();
+}
diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/example/example.qml b/share/qtcreator/templates/wizards/projects/qtquick2-extension/example/example.qml
new file mode 100644
index 0000000000..ea6222d39d
--- /dev/null
+++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/example/example.qml
@@ -0,0 +1,29 @@
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls
+import QtQuick.Controls.Material
+import %{ProjectName}
+
+Window {
+ width: 640
+ height: 400
+ visible: true
+ title: qsTr("Example Project")
+
+ %{ObjectName}Controls {
+ id: controls
+ anchors.left: parent.left
+ anchors.top: parent.top
+ anchors.margins: 20
+ width: 100
+ height: 100
+ }
+ %{ObjectName} {
+ id: rect
+ anchors.left: controls.right
+ anchors.top: parent.top
+ anchors.margins: 20
+ width: 100
+ height: 100
+ }
+}
diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.cpp b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.cpp
index a2288c47c1..fa74fbd694 100644
--- a/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.cpp
+++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.cpp
@@ -1,7 +1,9 @@
#include "%{ObjectHdr}"
+#include <QPainter>
+
%{ObjectName}::%{ObjectName}(QQuickItem *parent)
- : QQuickItem(parent)
+ : QQuickPaintedItem(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 +12,16 @@
// setFlag(ItemHasContents, true);
}
+void %{ObjectName}::paint(QPainter *painter)
+{
+ QPen pen(QColorConstants::Red, 2);
+ QBrush brush(QColorConstants::Red);
+
+ painter->setPen(pen);
+ painter->setBrush(brush);
+ painter->drawRect(0, 0, 100, 100);
+}
+
%{ObjectName}::~%{ObjectName}()
{
}
diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h
index e74c4233e8..62144e14e5 100644
--- a/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h
+++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.h
@@ -6,15 +6,16 @@
#define %{OBJECTGUARD}
@endif
-#include <QQuickItem>
+#include <QtQuick/QQuickPaintedItem>
-class %{ObjectName} : public QQuickItem
+class %{ObjectName} : public QQuickPaintedItem
{
Q_OBJECT
+ QML_ELEMENT
Q_DISABLE_COPY(%{ObjectName})
-
public:
explicit %{ObjectName}(QQuickItem *parent = nullptr);
+ void paint(QPainter *painter) override;
~%{ObjectName}() override;
};
diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.qml b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.qml
new file mode 100644
index 0000000000..d27870185b
--- /dev/null
+++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/object.qml
@@ -0,0 +1,10 @@
+import QtQuick %{QtQuickVersion}
+
+Item {
+ id: root
+
+ Rectangle {
+ anchors.fill: root
+ color: "green"
+ }
+}
diff --git a/share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json b/share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json
index 45989fb7de..e4f3741ed3 100644
--- a/share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json
+++ b/share/qtcreator/templates/wizards/projects/qtquick2-extension/wizard.json
@@ -13,16 +13,23 @@
"options":
[
- { "key": "ProjectFile", "value": "%{ProFile}" },
+ { "key": "ProjectFile", "value": "%{JS: value('BuildSystem') === 'qmake' ? value('ProFile') : value('CMakeFile')}" },
{ "key": "ProFile", "value": "%{JS: Util.fileName(value('ProjectDirectory') + '/' + value('ProjectName'), 'pro')}" },
+ { "key": "CMakeFile", "value": "%{ProjectDirectory}/CMakeLists.txt" },
{ "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": "ObjectQml", "value": "%{JS: Util.fileName(value('ObjectName') + 'Controls', 'qml')}" },
{ "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'))}" }
+ { "key": "OBJECTGUARD", "value": "%{JS: Cpp.classToHeaderGuard(value('ObjectName'), Util.preferredSuffix('text/x-c++hdr'))}" },
+ { "key": "IsQt6", "value": "%{JS: value('QtVersion').IsQt6}" },
+ { "key": "QtQuickVersion", "value": "%{JS: value('QtVersion').QtQuickVersion}" },
+ { "key": "QtQuickFeature", "value": "%{JS: (value('QtQuickVersion')=='') ? 'QtSupport.Wizards.FeatureQt.6.2' : 'QtSupport.Wizards.FeatureQtQuick.%{QtQuickVersion}'}" },
+ { "key": "CreateExampleProjectDefault", "value": false },
+ { "key": "TargetName", "value": "%{JS: 'lib' + value('ProjectName')}" }
],
"pages":
@@ -33,12 +40,102 @@
"typeId": "Project"
},
{
+ "trDisplayName": "Define Build System",
+ "trShortTitle": "Build System",
+ "typeId": "Fields",
+ "enabled": "%{JS: !value('IsSubproject')}",
+ "data":
+ [
+ {
+ "name": "BuildSystem",
+ "trDisplayName": "Build system:",
+ "type": "ComboBox",
+ "persistenceKey": "BuildSystemType",
+ "data":
+ {
+ "index": 0,
+ "items":
+ [
+
+ {
+ "trKey": "CMake",
+ "value": "cmake",
+ "condition": "%{JS: value('Plugins').indexOf('CMakeProjectManager') >= 0}"
+ },
+ {
+ "trKey": "qmake",
+ "value": "qmake",
+ "condition": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0}"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
"trDisplayName": "Custom Parameters",
"trShortTitle": "Details",
"typeId": "Fields",
"data":
[
{
+ "name": "QtVersion",
+ "trDisplayName": "Minimal required Qt version:",
+ "type": "ComboBox",
+ "persistenceKey": "QtQuick.minimumQtVersion",
+ "data":
+ {
+ "index": 0,
+ "items":
+ [
+ {
+ "trKey": "Qt 6.2",
+ "value":
+ {
+ "QtQuickVersion": "",
+ "IsQt6": true
+ }
+ },
+ {
+ "trKey": "Qt 5.15",
+ "condition": "%{JS: value('BuildSystem') === 'qmake'}",
+ "value":
+ {
+ "QtQuickVersion": "2.15",
+ "IsQt6": false
+ }
+ },
+ {
+ "trKey": "Qt 5.14",
+ "condition": "%{JS: value('BuildSystem') === 'qmake'}",
+ "value":
+ {
+ "QtQuickVersion": "2.14",
+ "IsQt6": false
+ }
+ },
+ {
+ "trKey": "Qt 5.13",
+ "condition": "%{JS: value('BuildSystem') === 'qmake'}",
+ "value":
+ {
+ "QtQuickVersion": "2.13",
+ "IsQt6": false
+ }
+ },
+ {
+ "trKey": "Qt 5.12",
+ "condition": "%{JS: value('BuildSystem') === 'qmake'}",
+ "value":
+ {
+ "QtQuickVersion": "2.12",
+ "IsQt6": false
+ }
+ }
+ ]
+ }
+ },
+ {
"name": "ObjectName",
"trDisplayName": "Object class-name:",
"mandatory": true,
@@ -59,6 +156,16 @@
"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"
}
+ },
+ {
+ "name": "CreateExampleProject",
+ "trDisplayName": "Create example project",
+ "visible": "%{JS: value('BuildSystem') === 'cmake'}",
+ "type": "CheckBox",
+ "data":
+ {
+ "checked": "%{CreateExampleProjectDefault}"
+ }
}
]
},
@@ -69,7 +176,7 @@
"enabled": "%{JS: !value('IsSubproject')}",
"data": {
"projectFilePath": "%{ProjectFile}",
- "requiredFeatures": [ "QtSupport.Wizards.FeatureQtQuick", "QtSupport.Wizards.FeatureQtQuick.2" ]
+ "requiredFeatures": [ "QtSupport.Wizards.FeatureQtQuick", "%{QtQuickFeature}" ]
}
},
{
@@ -87,7 +194,14 @@
{
"source": "project.pro",
"target": "%{ProFile}",
- "openAsProject": true
+ "openAsProject": true,
+ "condition": "%{JS: value('BuildSystem') === 'qmake'}"
+ },
+ {
+ "source": "CMakeLists.6.x.txt",
+ "target": "CMakeLists.txt",
+ "openAsProject": true,
+ "condition": "%{JS: value('BuildSystem') === 'cmake'}"
},
{
"source": "qmldir",
@@ -96,11 +210,13 @@
{
"source": "plugin.cpp",
"target": "%{PluginSrc}",
- "openInEditor": true
+ "openInEditor": true,
+ "condition": "%{JS: value('BuildSystem') === 'qmake'}"
},
{
"source": "plugin.h",
- "target": "%{PluginHdr}"
+ "target": "%{PluginHdr}",
+ "condition": "%{JS: value('BuildSystem') === 'qmake'}"
},
{
"source": "object.cpp",
@@ -111,6 +227,20 @@
"target": "%{ObjectHdr}"
},
{
+ "source": "object.qml",
+ "target": "%{ObjectQml}"
+ },
+ {
+ "source": "example/example.cpp",
+ "target": "example/example.cpp",
+ "condition": "%{JS: value('CreateExampleProject')}"
+ },
+ {
+ "source": "example/example.qml",
+ "target": "example/example.qml",
+ "condition": "%{JS: value('CreateExampleProject')}"
+ },
+ {
"source": "../git.ignore",
"target": ".gitignore",
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
index d226f6fc89..f074042da2 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
@@ -1265,7 +1265,11 @@ void ComboBoxField::initializeData(MacroExpander *expander)
ListField::initializeData(expander);
// refresh also the current text of the combobox
auto w = qobject_cast<QComboBox *>(widget());
- w->setCurrentIndex(selectionModel()->currentIndex().row());
+ const int row = selectionModel()->currentIndex().row();
+ if (row < w->count() && row > 0)
+ w->setCurrentIndex(row);
+ else
+ w->setCurrentIndex(0);
}
QVariant ComboBoxField::toSettings() const