diff options
author | Eike Ziller <eike.ziller@qt.io> | 2019-03-25 16:36:52 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2019-03-27 09:44:17 +0000 |
commit | 241efa353db74aca3c91c7810ae794ad8f5c7b65 (patch) | |
tree | a77a07112f2cad7fcc8e95ae525e164b60dcd16d /share/qtcreator/templates | |
parent | 6d0d2279746e3bbcd50a4b56e734a28c36bf44c5 (diff) |
Move Qt Widgets Application wizard to JSON
Adding support for CMake as well as QMake
Task-number: QTCREATORBUG-17308
Change-Id: I615b58921918ec87f935e0f11d3dd23ec20f0ac1
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'share/qtcreator/templates')
13 files changed, 342 insertions, 92 deletions
diff --git a/share/qtcreator/templates/qt4project/main.cpp b/share/qtcreator/templates/qt4project/main.cpp deleted file mode 100644 index cc228553ac..0000000000 --- a/share/qtcreator/templates/qt4project/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "%INCLUDE%" -#include <%QAPP_INCLUDE%> - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - %CLASS% w; -%SHOWMETHOD% - return a.exec(); -} diff --git a/share/qtcreator/templates/qt4project/mywidget.cpp b/share/qtcreator/templates/qt4project/mywidget.cpp deleted file mode 100644 index ae355e98dd..0000000000 --- a/share/qtcreator/templates/qt4project/mywidget.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "%INCLUDE%" - -%CLASS%::%CLASS%(QWidget *parent) - : %BASECLASS%(parent) -{ -} - -%CLASS%::~%CLASS%() -{ - -} diff --git a/share/qtcreator/templates/qt4project/mywidget.h b/share/qtcreator/templates/qt4project/mywidget.h deleted file mode 100644 index 993914c8cc..0000000000 --- a/share/qtcreator/templates/qt4project/mywidget.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef %PRE_DEF% -#define %PRE_DEF% - -#include <%BASECLASS%> - -class %CLASS% : public %BASECLASS% -{ - Q_OBJECT - -public: - %CLASS%(QWidget *parent = 0); - ~%CLASS%(); -}; - -#endif // %PRE_DEF% diff --git a/share/qtcreator/templates/qt4project/mywidget_form.cpp b/share/qtcreator/templates/qt4project/mywidget_form.cpp deleted file mode 100644 index b7e3ae6200..0000000000 --- a/share/qtcreator/templates/qt4project/mywidget_form.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "%INCLUDE%" -#include "%UI_HDR%" - -%CLASS%::%CLASS%(QWidget *parent) - : %BASECLASS%(parent), ui(new Ui::%CLASS%) -{ - ui->setupUi(this); -} - -%CLASS%::~%CLASS%() -{ - delete ui; -} diff --git a/share/qtcreator/templates/qt4project/mywidget_form.h b/share/qtcreator/templates/qt4project/mywidget_form.h deleted file mode 100644 index f519708a52..0000000000 --- a/share/qtcreator/templates/qt4project/mywidget_form.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef %PRE_DEF% -#define %PRE_DEF% - -#include <%BASECLASS%> - -namespace Ui -{ - class %CLASS%; -} - -class %CLASS% : public %BASECLASS% -{ - Q_OBJECT - -public: - %CLASS%(QWidget *parent = 0); - ~%CLASS%(); - -private: - Ui::%CLASS% *ui; -}; - -#endif // %PRE_DEF% diff --git a/share/qtcreator/templates/qt4project/widget.ui b/share/qtcreator/templates/qt4project/widget.ui deleted file mode 100644 index 2ac9f1d7c7..0000000000 --- a/share/qtcreator/templates/qt4project/widget.ui +++ /dev/null @@ -1,20 +0,0 @@ -<ui version="4.0"> - <class>%CLASS%</class> - <widget class="%BASECLASS%" name="%CLASS%" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>%WIDGET_WIDTH%</width> - <height>%WIDGET_HEIGHT%</height> - </rect> - </property> - <property name="windowTitle" > - <string>%CLASS%</string> - </property>%CENTRAL_WIDGET% - </widget> - <layoutDefault spacing="6" margin="11" /> - <pixmapfunction></pixmapfunction> - <resources/> - <connections/> -</ui> diff --git a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/CMakeLists.txt b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/CMakeLists.txt new file mode 100644 index 0000000000..75a2beb233 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.1) + +project(%{ProjectName} LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Qt5 COMPONENTS Widgets REQUIRED) + +add_executable(${PROJECT_NAME} + "%{MainFileName}" + "%{SrcFileName}" + "%{HdrFileName}" +@if %{GenerateForm} + "%{FormFileName}" +@endif +) + +target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets) diff --git a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/main.cpp b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/main.cpp new file mode 100644 index 0000000000..5c64f1d05e --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/main.cpp @@ -0,0 +1,12 @@ +%{Cpp:LicenseTemplate}\ +#include "%{HdrFileName}" + +%{JS: QtSupport.qtIncludes([ 'QtGui/QApplication' ], [ 'QtWidgets/QApplication' ]) }\ + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + %{Class} w; + w.show(); + return a.exec(); +} diff --git a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/project.pro b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/project.pro new file mode 100644 index 0000000000..a5362aa9bc --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/project.pro @@ -0,0 +1,33 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \\ + %{MainFileName} \\ + %{SrcFileName} + +HEADERS += \\ + %{HdrFileName} +@if %{GenerateForm} + +FORMS += \\ + %{FormFileName} +@endif + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.cpp b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.cpp new file mode 100644 index 0000000000..ee0d05a5ab --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.cpp @@ -0,0 +1,26 @@ +%{Cpp:LicenseTemplate}\ +#include "%{HdrFileName}" +@if %{GenerateForm} +#include "%{UiHdrFileName}" +@endif +%{JS: Cpp.openNamespaces('%{Class}')}\ + +%{CN}::%{CN}(QWidget *parent) + : %{BaseClass}(parent) +@if %{GenerateForm} + , ui(new Ui::%{CN}) +@endif +{ +@if %{GenerateForm} + ui->setupUi(this); +@endif +} + +%{CN}::~%{CN}() +{ +@if %{GenerateForm} + delete ui; +@endif +} + +%{JS: Cpp.closeNamespaces('%{Class}')}\ diff --git a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.h b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.h new file mode 100644 index 0000000000..4ce74ac814 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.h @@ -0,0 +1,32 @@ +%{Cpp:LicenseTemplate}\ +@if '%{Cpp:PragmaOnce}' +#pragma once +@else +#ifndef %{GUARD} +#define %{GUARD} +@endif + +%{JS: QtSupport.qtIncludes([ 'QtGui/%{BaseClass}' ], [ 'QtWidgets/%{BaseClass}' ]) }\ +%{JS: Cpp.openNamespaces('%{Class}')}\ +@if %{GenerateForm} + +namespace Ui { class %{CN}; } +@endif + +class %{CN} : public %{BaseClass} +{ + Q_OBJECT + +public: + %{CN}(QWidget *parent = nullptr); + ~%{CN}(); +@if %{GenerateForm} + +private: + Ui::%{CN} *ui; +@endif +}; +%{JS: Cpp.closeNamespaces('%{Class}')}\ +@if ! '%{Cpp:PragmaOnce}' +#endif // %{GUARD} +@endif diff --git a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.ui b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.ui new file mode 100644 index 0000000000..1b21b83109 --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/widget.ui @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>%{Class}</class> + <widget class="%{BaseClass}" name="%{Class}"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>%{CN}</string> + </property> +@if '%{BaseClass}' === 'QMainWindow' + <widget class="QWidget" name="centralwidget"/> + <widget class="QMenuBar" name="menubar"/> + <widget class="QStatusBar" name="statusbar"/> +@endif + </widget> + <resources/> + <connections/> +</ui> diff --git a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/wizard.json b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/wizard.json new file mode 100644 index 0000000000..1eaddb794b --- /dev/null +++ b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/wizard.json @@ -0,0 +1,192 @@ +{ + "version": 1, + "supportedProjectTypes": [ "CMakeProjectManager.CMakeProject", "Qt4ProjectManager.Qt4Project" ], + "id": "C.QtWidgets", + "category": "F.Application", + "trDescription": "Creates a Qt application for the desktop. Includes a Qt Designer-based main window.\n\nPreselects a desktop Qt for building the application if available.", + "trDisplayName": "Qt Widgets Application", + "trDisplayCategory": "Application", + "icon": "../../global/guiapplication.png", + "featuresRequired": [ "QtSupport.Wizards.FeatureQt" ], + "enabled": "%{JS: [ %{Plugins} ].indexOf('QmakeProjectManager') >= 0 || [ %{Plugins} ].indexOf('CMakeProjectManager') >= 0}", + + "options": + [ + { "key": "ProjectFile", "value": "%{JS: '%{BuildSystem}' === 'qmake' ? '%{ProFile}' : '%{CMakeFile}'}" }, + { "key": "ProFile", "value": "%{JS: Util.fileName('%{ProjectDirectory}/%{ProjectName}', 'pro')}" }, + { "key": "CMakeFile", "value": "%{ProjectDirectory}/CMakeLists.txt" }, + { "key": "MainFileName", "value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src')}" }, + { "key": "UiHdrFileName", "value": "%{JS: ('%{BuildSystem}' === 'cmake' ? (Util.path('%{FormFileName}') + '/') : '') + 'ui_' + Util.completeBaseName('%{FormFileName}') + '.h'}" }, + { "key": "CN", "value": "%{JS: Cpp.className('%{Class}')}" }, + { "key": "GUARD", "value": "%{JS: Cpp.headerGuard('%{HdrFileName}')}" } + ], + + "pages": + [ + { + "trDisplayName": "Project Location", + "trShortTitle": "Location", + "typeId": "Project", + "data": { "trDescription": "This wizard generates a Qt Widgets Application project. The application derives by default from QApplication and includes an empty widget." } + }, + { + "trDisplayName": "Define Build System", + "trShortTitle": "Build System", + "typeId": "Fields", + "enabled": "%{JS: ! %{IsSubproject}}", + "data": + [ + { + "name": "BuildSystem", + "trDisplayName": "Build system:", + "type": "ComboBox", + "data": + { + "index": 0, + "items": + [ + { + "trKey": "QMake", + "value": "qmake", + "condition": "%{JS: [ %{Plugins} ].indexOf('QmakeProjectManager') >= 0}" + }, + { + "trKey": "CMake", + "value": "cmake", + "condition": "%{JS: [ %{Plugins} ].indexOf('CMakeProjectManager') >= 0}" + } + ] + } + } + ] + }, + { + "trDisplayName": "Kit Selection", + "trShortTitle": "Kits", + "typeId": "Kits", + "enabled": "%{JS: ! %{IsSubproject}}", + "data": { "projectFilePath": "%{ProjectFile}" } + }, + { + "trDisplayName": "Class Information", + "trShortTitle": "Details", + "typeId": "Fields", + "data": + [ + { + "name": "ClassPageDescription", + "type": "Label", + "data": + { + "trText": "Specify basic information about the classes for which you want to generate skeleton source code files.", + "wordWrap": true + } + }, + { + "name": "Sp0", + "type": "Spacer" + }, + { + "name": "Class", + "trDisplayName": "Class name:", + "mandatory": true, + "type": "LineEdit", + "data": + { + "validator": "(?:(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*|)", + "trText": "%{JS: '%{BaseClass}'.slice(1)}" + } + }, + { + "name": "BaseClass", + "trDisplayName": "Base class:", + "type": "ComboBox", + "data": + { + "items": [ "QMainWindow", "QWidget", "QDialog" ] + } + }, + { + "name": "Sp1", + "type": "Spacer" + }, + { + "name": "HdrFileName", + "type": "LineEdit", + "trDisplayName": "Header file:", + "mandatory": true, + "data": { "trText": "%{JS: Cpp.classToFileName('%{Class}', '%{JS: Util.preferredSuffix('text/x-c++hdr')}')}" } + }, + { + "name": "SrcFileName", + "type": "LineEdit", + "trDisplayName": "Source file:", + "mandatory": true, + "data": { "trText": "%{JS: Cpp.classToFileName('%{Class}', '%{JS: Util.preferredSuffix('text/x-c++src')}')}" } + }, + { + "name": "GenerateForm", + "type": "CheckBox", + "trDisplayName": "Generate form:", + "data": { "checked": true } + }, + { + "name": "FormFileName", + "type": "LineEdit", + "trDisplayName": "Form file:", + "enabled": "%{GenerateForm}", + "mandatory": true, + "data": { "trText": "%{JS: Cpp.classToFileName('%{Class}', 'ui')}" } + } + ] + }, + { + "trDisplayName": "Project Management", + "trShortTitle": "Summary", + "typeId": "Summary" + } + ], + "generators": + [ + { + "typeId": "File", + "data": + [ + { + "source": "project.pro", + "target": "%{ProFile}", + "openAsProject": true, + "condition": "%{JS: '%{BuildSystem}' === 'qmake'}" + }, + { + "source": "CMakeLists.txt", + "openAsProject": true, + "condition": "%{JS: '%{BuildSystem}' === 'cmake'}" + }, + { + "source": "main.cpp", + "target": "%{MainFileName}", + "openInEditor": true + }, + { + "source": "widget.cpp", + "target": "%{SrcFileName}" + }, + { + "source": "widget.h", + "target": "%{HdrFileName}" + }, + { + "source": "widget.ui", + "target": "%{FormFileName}", + "condition": "%{GenerateForm}" + }, + { + "source": "../git.ignore", + "target": ".gitignore", + "condition": "%{JS: ! %{IsSubproject} && '%{VersionControl}' === 'G.Git'}" + } + ] + } + ] +} |