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>
This commit is contained in:
Eike Ziller
2019-03-25 16:36:52 +01:00
parent 6d0d227974
commit 241efa353d
20 changed files with 342 additions and 604 deletions

View File

@@ -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();
}

View File

@@ -1,11 +0,0 @@
#include "%INCLUDE%"
%CLASS%::%CLASS%(QWidget *parent)
: %BASECLASS%(parent)
{
}
%CLASS%::~%CLASS%()
{
}

View File

@@ -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%

View File

@@ -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;
}

View File

@@ -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%

View File

@@ -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>

View File

@@ -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)

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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}')}\

View File

@@ -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

View File

@@ -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>

View File

@@ -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'}"
}
]
}
]
}

View File

@@ -19,11 +19,9 @@ HEADERS += \
profilehighlighter.h \
profilehoverhandler.h \
wizards/qtprojectparameters.h \
wizards/guiappwizard.h \
wizards/libraryparameters.h \
wizards/librarywizard.h \
wizards/librarywizarddialog.h \
wizards/guiappwizarddialog.h \
wizards/modulespage.h \
wizards/filespage.h \
wizards/qtwizard.h \
@@ -59,11 +57,9 @@ SOURCES += \
profilehighlighter.cpp \
profilehoverhandler.cpp \
wizards/qtprojectparameters.cpp \
wizards/guiappwizard.cpp \
wizards/libraryparameters.cpp \
wizards/librarywizard.cpp \
wizards/librarywizarddialog.cpp \
wizards/guiappwizarddialog.cpp \
wizards/modulespage.cpp \
wizards/filespage.cpp \
wizards/qtwizard.cpp \

View File

@@ -78,8 +78,6 @@ Project {
prefix: "wizards/"
files: [
"filespage.cpp", "filespage.h",
"guiappwizard.cpp", "guiappwizard.h",
"guiappwizarddialog.cpp", "guiappwizarddialog.h",
"libraryparameters.cpp", "libraryparameters.h",
"librarywizard.cpp", "librarywizard.h",
"librarywizarddialog.cpp", "librarywizarddialog.h",

View File

@@ -33,7 +33,6 @@
#include "qmakemakestep.h"
#include "qmakebuildconfiguration.h"
#include "desktopqmakerunconfiguration.h"
#include "wizards/guiappwizard.h"
#include "wizards/librarywizard.h"
#include "wizards/simpleprojectwizard.h"
#include "wizards/subdirsprojectwizard.h"
@@ -151,7 +150,6 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
IWizardFactory::registerFactoryCreator([] {
return QList<IWizardFactory *> {
new SubdirsProjectWizard,
new GuiAppWizard,
new LibraryWizard,
new CustomWidgetWizard,
new SimpleProjectWizard

View File

@@ -1,270 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "guiappwizard.h"
#include "guiappwizarddialog.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <cpptools/abstracteditorsupport.h>
#include <designer/cpp/formclasswizardparameters.h>
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/invoker.h>
#include <qtsupport/qtsupportconstants.h>
#include <utils/fileutils.h>
#include <QCoreApplication>
#include <QDir>
#include <QTextStream>
#include <QSharedPointer>
static const char mainSourceFileC[] = "main";
static const char mainSourceShowC[] = " w.show();\n";
static const char mainSourceMobilityShowC[] = " w.show();\n";
static const char mainWindowUiContentsC[] =
"\n <widget class=\"QMenuBar\" name=\"menuBar\" />"
"\n <widget class=\"QToolBar\" name=\"mainToolBar\" />"
"\n <widget class=\"QWidget\" name=\"centralWidget\" />"
"\n <widget class=\"QStatusBar\" name=\"statusBar\" />";
static const char mainWindowMobileUiContentsC[] =
"\n <widget class=\"QWidget\" name=\"centralWidget\" />";
static const char *baseClassesC[] = {"QMainWindow", "QWidget", "QDialog"};
static inline QStringList baseClasses()
{
QStringList rc;
for (auto baseClass : baseClassesC)
rc.push_back(QLatin1String(baseClass));
return rc;
}
namespace QmakeProjectManager {
namespace Internal {
GuiAppWizard::GuiAppWizard()
{
setId("C.Qt4Gui");
setCategory(QLatin1String(ProjectExplorer::Constants::QT_APPLICATION_WIZARD_CATEGORY));
setDisplayCategory(QCoreApplication::translate("ProjectExplorer",
ProjectExplorer::Constants::QT_APPLICATION_WIZARD_CATEGORY_DISPLAY));
setDisplayName(tr("Qt Widgets Application"));
setDescription(tr("Creates a Qt application for the desktop. "
"Includes a Qt Designer-based main window.\n\n"
"Preselects a desktop Qt for building the application if available."));
setIcon(QIcon(QLatin1String(":/wizards/images/gui.png")));
setRequiredFeatures({QtSupport::Constants::FEATURE_QWIDGETS});
}
Core::BaseFileWizard *GuiAppWizard::create(QWidget *parent, const Core::WizardDialogParameters &parameters) const
{
GuiAppWizardDialog *dialog = new GuiAppWizardDialog(this, displayName(), icon(), parent, parameters);
dialog->setProjectName(GuiAppWizardDialog::uniqueProjectName(parameters.defaultPath()));
// Order! suffixes first to generate files correctly
dialog->setLowerCaseFiles(QtWizard::lowerCaseFiles());
dialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix());
dialog->setBaseClasses(baseClasses());
return dialog;
}
// Use the class generation utils provided by the designer plugin
static inline bool generateFormClass(const GuiAppParameters &params,
const Core::GeneratedFile &uiFile,
Core::GeneratedFile *formSource,
Core::GeneratedFile *formHeader,
QString *errorMessage)
{
// Retrieve parameters from settings
Designer::FormClassWizardParameters fp;
fp.uiTemplate = uiFile.contents();
fp.uiFile = uiFile.path();
fp.className = params.className;
fp.sourceFile = params.sourceFileName;
fp.headerFile = params.headerFileName;
fp.usePragmaOnce = CppTools::AbstractEditorSupport::usePragmaOnce();
QString headerContents;
QString sourceContents;
// Invoke code generation service of Qt Designer plugin.
if (QObject *codeGenerator = ExtensionSystem::PluginManager::getObjectByName("QtDesignerFormClassCodeGenerator")) {
const QVariant code = ExtensionSystem::invoke<QVariant>(codeGenerator, "generateFormClassCode", fp);
if (code.type() == QVariant::List) {
const QVariantList vl = code.toList();
if (vl.size() == 2) {
headerContents = vl.front().toString();
sourceContents = vl.back().toString();
}
}
}
if (headerContents.isEmpty() || sourceContents.isEmpty()) {
*errorMessage = QString::fromLatin1("Failed to obtain Designer plugin code generation service.");
return false;
}
formHeader->setContents(headerContents);
formSource->setContents(sourceContents);
return true;
}
Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
QString *errorMessage) const
{
const auto *dialog = qobject_cast<const GuiAppWizardDialog *>(w);
const QtProjectParameters projectParams = dialog->projectParameters();
const QString projectPath = projectParams.projectPath();
const GuiAppParameters params = dialog->parameters();
// Generate file names. Note that the path for the project files is the
// newly generated project directory.
const QString templatePath = templateDir();
// Create files: main source
QString contents;
const QString mainSourceFileName = buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix());
Core::GeneratedFile mainSource(mainSourceFileName);
if (!parametrizeTemplate(templatePath, QLatin1String("main.cpp"), params, &contents, errorMessage))
return Core::GeneratedFiles();
mainSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(mainSourceFileName)
+ contents);
// Create files: form source with or without form
const QString formSourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix());
const QString formHeaderName = buildFileName(projectPath, params.headerFileName, headerSuffix());
Core::GeneratedFile formSource(formSourceFileName);
Core::GeneratedFile formHeader(formHeaderName);
formSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
QSharedPointer<Core::GeneratedFile> form;
if (params.designerForm) {
// Create files: form
const QString formName = buildFileName(projectPath, params.formFileName, formSuffix());
form = QSharedPointer<Core::GeneratedFile>(new Core::GeneratedFile(formName));
if (!parametrizeTemplate(templatePath, QLatin1String("widget.ui"), params, &contents, errorMessage))
return Core::GeneratedFiles();
form->setContents(contents);
if (!generateFormClass(params, *form, &formSource, &formHeader, errorMessage))
return Core::GeneratedFiles();
} else {
const QString formSourceTemplate = QLatin1String("mywidget.cpp");
if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage))
return Core::GeneratedFiles();
formSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(formSourceFileName)
+ contents);
// Create files: form header
const QString formHeaderTemplate = QLatin1String("mywidget.h");
if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage))
return Core::GeneratedFiles();
formHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(formHeaderName)
+ contents);
}
// Create files: profile
const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix());
Core::GeneratedFile profile(profileName);
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
contents.clear();
{
QTextStream proStr(&contents);
QtProjectParameters::writeProFileHeader(proStr);
projectParams.writeProFile(proStr);
proStr << "\nCONFIG += c++11"; // ensure all Qt5 versions can handle the source
proStr << "\n\nSOURCES +="
<< " \\\n " << Utils::FileName::fromString(mainSourceFileName).fileName()
<< " \\\n " << Utils::FileName::fromString(formSource.path()).fileName()
<< "\n\nHEADERS +="
<< " \\\n " << Utils::FileName::fromString(formHeader.path()).fileName();
if (params.designerForm)
proStr << "\n\nFORMS +="
<< " \\\n " << Utils::FileName::fromString(form->path()).fileName();
if (params.isMobileApplication) {
proStr << "\n\nCONFIG += mobility"
<< "\nMOBILITY = "
<< "\n";
}
proStr << "\n\n# Default rules for deployment.\n"
"qnx: target.path = /tmp/$${TARGET}/bin\n"
"else: unix:!android: target.path = /opt/$${TARGET}/bin\n"
"!isEmpty(target.path): INSTALLS += target\n";
}
profile.setContents(contents);
// List
Core::GeneratedFiles rc;
rc << mainSource << formSource << formHeader;
if (params.designerForm)
rc << *form;
rc << profile;
return rc;
}
bool GuiAppWizard::parametrizeTemplate(const QString &templatePath, const QString &templateName,
const GuiAppParameters &params,
QString *target, QString *errorMessage)
{
const QString fileName = templatePath + QLatin1Char('/') + templateName;
Utils::FileReader reader;
if (!reader.fetch(fileName, QIODevice::Text, errorMessage))
return false;
QString contents = QString::fromUtf8(reader.data());
contents.replace(QLatin1String("%QAPP_INCLUDE%"), QLatin1String("QApplication"));
contents.replace(QLatin1String("%INCLUDE%"), params.headerFileName);
contents.replace(QLatin1String("%CLASS%"), params.className);
contents.replace(QLatin1String("%BASECLASS%"), params.baseClassName);
contents.replace(QLatin1String("%WIDGET_HEIGHT%"), QString::number(params.widgetHeight));
contents.replace(QLatin1String("%WIDGET_WIDTH%"), QString::number(params.widgetWidth));
if (params.isMobileApplication)
contents.replace(QLatin1String("%SHOWMETHOD%"), QString::fromLatin1(mainSourceMobilityShowC));
else
contents.replace(QLatin1String("%SHOWMETHOD%"), QString::fromLatin1(mainSourceShowC));
// Replace include guards with pragma once
if (CppTools::AbstractEditorSupport::usePragmaOnce()) {
contents.replace(QLatin1String("#ifndef %PRE_DEF%\n#define %PRE_DEF%"), "#pragma once");
contents.replace(QLatin1String("#endif // %PRE_DEF%\n"), QString());
}
const QChar dot = QLatin1Char('.');
QString preDef = params.headerFileName.toUpper();
preDef.replace(dot, QLatin1Char('_'));
contents.replace(QLatin1String("%PRE_DEF%"), preDef);
const QString uiFileName = params.formFileName;
QString uiHdr = QLatin1String("ui_");
uiHdr += uiFileName.left(uiFileName.indexOf(dot));
uiHdr += QLatin1String(".h");
contents.replace(QLatin1String("%UI_HDR%"), uiHdr);
if (params.baseClassName == QLatin1String("QMainWindow")) {
if (params.isMobileApplication)
contents.replace(QLatin1String("%CENTRAL_WIDGET%"), QLatin1String(mainWindowMobileUiContentsC));
else
contents.replace(QLatin1String("%CENTRAL_WIDGET%"), QLatin1String(mainWindowUiContentsC));
} else {
contents.remove(QLatin1String("%CENTRAL_WIDGET%"));
}
*target = contents;
return true;
}
} // namespace Internal
} // namespace QmakeProjectManager

View File

@@ -1,54 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "qtwizard.h"
namespace QmakeProjectManager {
namespace Internal {
struct GuiAppParameters;
class GuiAppWizard : public QtWizard
{
Q_OBJECT
public:
GuiAppWizard();
private:
Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters &parameters) const override;
Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const override;
private:
static bool parametrizeTemplate(const QString &templatePath, const QString &templateName,
const GuiAppParameters &params,
QString *target, QString *errorMessage);
};
} // namespace Internal
} // namespace QmakeProjectManager

View File

@@ -1,108 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "guiappwizarddialog.h"
#include "filespage.h"
#include <projectexplorer/projectexplorerconstants.h>
namespace QmakeProjectManager {
namespace Internal {
GuiAppWizardDialog::GuiAppWizardDialog(const Core::BaseFileWizardFactory *factory,
const QString &templateName,
const QIcon &icon, QWidget *parent,
const Core::WizardDialogParameters &parameters) :
BaseQmakeProjectWizardDialog(factory, false, parent, parameters),
m_filesPage(new FilesPage)
{
setWindowIcon(icon);
setWindowTitle(templateName);
setSelectedModules(QLatin1String("core gui"), true);
setIntroDescription(tr("This wizard generates a Qt Widgets Application "
"project. The application derives by default from QApplication "
"and includes an empty widget."));
addModulesPage();
if (!parameters.extraValues().contains(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS)))
addTargetSetupPage();
m_filesPage->setFormInputCheckable(true);
m_filesPage->setClassTypeComboVisible(false);
addPage(m_filesPage);
addExtensionPages(extensionPages());
}
void GuiAppWizardDialog::setBaseClasses(const QStringList &baseClasses)
{
m_filesPage->setBaseClassChoices(baseClasses);
if (!baseClasses.empty())
m_filesPage->setBaseClassName(baseClasses.front());
}
void GuiAppWizardDialog::setSuffixes(const QString &header, const QString &source, const QString &form)
{
m_filesPage->setSuffixes(header, source, form);
}
void GuiAppWizardDialog::setLowerCaseFiles(bool l)
{
m_filesPage->setLowerCaseFiles(l);
}
QtProjectParameters GuiAppWizardDialog::projectParameters() const
{
QtProjectParameters rc;
rc.type = QtProjectParameters::GuiApp;
rc.flags |= QtProjectParameters::WidgetsRequiredFlag;
rc.fileName = projectName();
rc.path = path();
rc.selectedModules = selectedModulesList();
rc.deselectedModules = deselectedModulesList();
return rc;
}
GuiAppParameters GuiAppWizardDialog::parameters() const
{
GuiAppParameters rc;
rc.className = m_filesPage->className();
rc.baseClassName = m_filesPage->baseClassName();
rc.sourceFileName = m_filesPage->sourceFileName();
rc.headerFileName = m_filesPage->headerFileName();
rc.formFileName = m_filesPage->formFileName();
rc.designerForm = m_filesPage->formInputChecked();
if (isQtPlatformSelected("Android.Device.Type")) { // FIXME: Is this really necessary?
rc.isMobileApplication = true;
rc.widgetWidth = 800;
rc.widgetHeight = 480;
}
return rc;
}
} // namespace Internal
} // namespace QmakeProjectManager

View File

@@ -1,72 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "qtwizard.h"
namespace QmakeProjectManager {
namespace Internal {
struct QtProjectParameters;
class FilesPage;
// Additional parameters required besides QtProjectParameters
struct GuiAppParameters
{
QString className;
QString baseClassName;
QString sourceFileName;
QString headerFileName;
QString formFileName;
int widgetWidth = 400;
int widgetHeight = 300;
bool designerForm = true;
bool isMobileApplication = false;
};
class GuiAppWizardDialog : public BaseQmakeProjectWizardDialog
{
Q_OBJECT
public:
explicit GuiAppWizardDialog(const Core::BaseFileWizardFactory *factory, const QString &templateName,
const QIcon &icon,
QWidget *parent,
const Core::WizardDialogParameters &parameters);
void setBaseClasses(const QStringList &baseClasses);
void setSuffixes(const QString &header, const QString &source, const QString &form);
void setLowerCaseFiles(bool l);
QtProjectParameters projectParameters() const;
GuiAppParameters parameters() const;
private:
FilesPage *m_filesPage;
};
} // namespace Internal
} // namespace QmakeProjectManager