From c06fab97f1b214aa5c57a49bd7ceee17eeee308e Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 31 May 2022 17:10:42 +0200 Subject: [PATCH] Wizards: Port "Code Snippet" Project Wizard to .json wizard Code Snippet is the last .xml-based wizard shipped with Qt Creator. This change ports it to the .json-based wizard format. Instead of supporting just qmake-based projects (like it did), the new version supports just CMake-based projects. Change-Id: Ie64114165fff5d56ddf82041cc4d5f90c44fe77b Reviewed-by: hjk --- .../wizards/codesnippet/CMakeLists.txt | 37 ++++++ .../templates/wizards/codesnippet/main.cpp | 2 +- .../templates/wizards/codesnippet/project.pro | 17 --- .../templates/wizards/codesnippet/wizard.json | 113 ++++++++++++++++++ .../templates/wizards/codesnippet/wizard.xml | 49 -------- 5 files changed, 151 insertions(+), 67 deletions(-) create mode 100644 share/qtcreator/templates/wizards/codesnippet/CMakeLists.txt delete mode 100644 share/qtcreator/templates/wizards/codesnippet/project.pro create mode 100644 share/qtcreator/templates/wizards/codesnippet/wizard.json delete mode 100644 share/qtcreator/templates/wizards/codesnippet/wizard.xml diff --git a/share/qtcreator/templates/wizards/codesnippet/CMakeLists.txt b/share/qtcreator/templates/wizards/codesnippet/CMakeLists.txt new file mode 100644 index 00000000000..603186293d9 --- /dev/null +++ b/share/qtcreator/templates/wizards/codesnippet/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.5) + +project(%{ProjectName} VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS %{QtModule}) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS %{QtModule}) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(%{ProjectName} MANUAL_FINALIZATION %{CppFileName}) +else() + if(ANDROID) + add_library(%{ProjectName} SHARED %{CppFileName}) + else() + add_executable(%{ProjectName} %{CppFileName}) + endif() +endif() + +target_link_libraries(%{ProjectName} PRIVATE Qt${QT_VERSION_MAJOR}::%{QtModule}) + +install(TARGETS %{ProjectName} +@if %{MacOSBundle} + BUNDLE DESTINATION . +@endif + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +set_target_properties(%{ProjectName} PROPERTIES MACOSX_BUNDLE %{MacOSBundleValue}) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(%{ProjectName}) +endif() diff --git a/share/qtcreator/templates/wizards/codesnippet/main.cpp b/share/qtcreator/templates/wizards/codesnippet/main.cpp index 59d189b301a..cd2231693a1 100644 --- a/share/qtcreator/templates/wizards/codesnippet/main.cpp +++ b/share/qtcreator/templates/wizards/codesnippet/main.cpp @@ -1 +1 @@ -%CODE% +%{CodeSnippet} diff --git a/share/qtcreator/templates/wizards/codesnippet/project.pro b/share/qtcreator/templates/wizards/codesnippet/project.pro deleted file mode 100644 index 6dafac76de3..00000000000 --- a/share/qtcreator/templates/wizards/codesnippet/project.pro +++ /dev/null @@ -1,17 +0,0 @@ -TEMPLATE = app -@if "%TYPE%" == "core" -QT = core -@else -QT = core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -@endif -@if "%CONSOLE%" == "true" -CONFIG += console -@endif -@if "%APP_BUNDLE%" == "false" -CONFIG -= app_bundle -@endif -CONFIG += c++11 - -SOURCES += \\ - main.%CppSourceSuffix% diff --git a/share/qtcreator/templates/wizards/codesnippet/wizard.json b/share/qtcreator/templates/wizards/codesnippet/wizard.json new file mode 100644 index 00000000000..40757cf5715 --- /dev/null +++ b/share/qtcreator/templates/wizards/codesnippet/wizard.json @@ -0,0 +1,113 @@ +{ + "version": 1, + "supportedProjectTypes": [ "CMakeProjectManager.CMakeProject" ], + "id": "Z.Snippet", + "category": "H.Project", + "trDescription": "Creates a CMake-based test project for which a code snippet can be entered.", + "trDisplayName": "Code Snippet", + "trDisplayCategory": "Other Project", + "featuresRequired": [ "QtSupport.Wizards.FeatureQt" ], + "enabled": "%{JS: value('Plugins').indexOf('CMakeProjectManager') >= 0}", + + "options": + [ + { "key": "ProjectFile", "value": "%{ProjectDirectory}/CMakeLists.txt" }, + { "key": "CppFileName", "value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src')}" }, + { "key": "MacOSBundleValue", "value": "%{JS: %{MacOSBundle} ? 'TRUE' : 'FALSE' }" } + ], + "pages": + [ + { + "trDisplayName": "Project Location", + "trShortTitle": "Location", + "typeId": "Project", + "data": + { + "trDescription": "Creates a CMake-based test project for which a code snippet can be entered." + } + }, + { + "trDisplayName": "Define Code snippet", + "trShortTitle": "Code snippet", + "typeId": "Fields", + "data": + [ + { + "name": "CodeSnippet", + "trDisplayName": "Code:", + "type": "TextEdit", + "data": + { + "trText": "int main(int argc, char *argv[])\n{\n return 0;\n}" + } + }, + { + "name": "QtModule", + "trDisplayName": "Use Qt Modules:", + "type": "ComboBox", + "persistenceKey": "QtModule", + "data": + { + "index": 1, + "items": + [ + { + "trKey": "QtCore", + "value": "Core" + }, + { + "trKey": "QtCore, QtWidgets", + "value": "Widgets" + } + ] + } + }, + { + "name": "MacOSBundle", + "trDisplayName": "Application bundle (macOS)", + "type": "CheckBox", + "persistenceKey": "MacOSBundle", + "data": + { + "checked": true + } + } + ] + }, + { + "trDisplayName": "Kit Selection", + "trShortTitle": "Kits", + "typeId": "Kits", + "enabled": "%{JS: !value('IsSubproject')}", + "data": + { + "projectFilePath": "%{ProjectFile}" + } + }, + { + "trDisplayName": "Project Management", + "trShortTitle": "Summary", + "typeId": "Summary" + } + ], + + "generators": + [ + { + "typeId": "File", + "data": + [ + { + "source": "CMakeLists.txt", + "target": "%{ProjectFile}", + "openAsProject": true + }, + { + "source": "main.cpp", + "target": "%{CppFileName}", + "openInEditor": true + } + ] + } + ] +} diff --git a/share/qtcreator/templates/wizards/codesnippet/wizard.xml b/share/qtcreator/templates/wizards/codesnippet/wizard.xml deleted file mode 100644 index 2acffc8c6fd..00000000000 --- a/share/qtcreator/templates/wizards/codesnippet/wizard.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - Creates a qmake-based test project for which a code snippet can be entered. - Code Snippet; - Other Project - - - - - Snippet Parameters - - - - Code: - - - Type: - - - - Headless (QtCore) - - - Gui application (QtCore, QtGui, QtWidgets) - - - - - - - Console application - - - - Application bundle (Mac) - - -