diff --git a/share/qtcreator/templates/qml/qtquick1_1/main.qml b/share/qtcreator/templates/qml/qtquick_1_1/main.qml similarity index 100% rename from share/qtcreator/templates/qml/qtquick1_1/main.qml rename to share/qtcreator/templates/qml/qtquick_1_1/main.qml diff --git a/share/qtcreator/templates/qml/qtquick1_1/main.qmlproject b/share/qtcreator/templates/qml/qtquick_1_1/main.qmlproject similarity index 100% rename from share/qtcreator/templates/qml/qtquick1_1/main.qmlproject rename to share/qtcreator/templates/qml/qtquick_1_1/main.qmlproject diff --git a/share/qtcreator/templates/qml/qtquick1_1/template.xml b/share/qtcreator/templates/qml/qtquick_1_1/template.xml similarity index 100% rename from share/qtcreator/templates/qml/qtquick1_1/template.xml rename to share/qtcreator/templates/qml/qtquick_1_1/template.xml diff --git a/share/qtcreator/templates/qml/qtquick2/main.qml b/share/qtcreator/templates/qml/qtquick_2_0/main.qml similarity index 100% rename from share/qtcreator/templates/qml/qtquick2/main.qml rename to share/qtcreator/templates/qml/qtquick_2_0/main.qml diff --git a/share/qtcreator/templates/qml/qtquick2/main.qmlproject b/share/qtcreator/templates/qml/qtquick_2_0/main.qmlproject similarity index 100% rename from share/qtcreator/templates/qml/qtquick2/main.qmlproject rename to share/qtcreator/templates/qml/qtquick_2_0/main.qmlproject diff --git a/share/qtcreator/templates/qml/qtquick2/template.xml b/share/qtcreator/templates/qml/qtquick_2_0/template.xml similarity index 100% rename from share/qtcreator/templates/qml/qtquick2/template.xml rename to share/qtcreator/templates/qml/qtquick_2_0/template.xml diff --git a/share/qtcreator/templates/qml/qtquickcontrols/main.qml b/share/qtcreator/templates/qml/qtquickcontrols_1_0/main.qml similarity index 100% rename from share/qtcreator/templates/qml/qtquickcontrols/main.qml rename to share/qtcreator/templates/qml/qtquickcontrols_1_0/main.qml diff --git a/share/qtcreator/templates/qml/qtquickcontrols/main.qmlproject b/share/qtcreator/templates/qml/qtquickcontrols_1_0/main.qmlproject similarity index 100% rename from share/qtcreator/templates/qml/qtquickcontrols/main.qmlproject rename to share/qtcreator/templates/qml/qtquickcontrols_1_0/main.qmlproject diff --git a/share/qtcreator/templates/qml/qtquickcontrols/template.xml b/share/qtcreator/templates/qml/qtquickcontrols_1_0/template.xml similarity index 100% rename from share/qtcreator/templates/qml/qtquickcontrols/template.xml rename to share/qtcreator/templates/qml/qtquickcontrols_1_0/template.xml diff --git a/share/qtcreator/templates/qtquick1app/app.pro b/share/qtcreator/templates/qtquick/qtquick_1_1/app.pro similarity index 100% rename from share/qtcreator/templates/qtquick1app/app.pro rename to share/qtcreator/templates/qtquick/qtquick_1_1/app.pro diff --git a/share/qtcreator/templates/qtquick1app/main.cpp b/share/qtcreator/templates/qtquick/qtquick_1_1/main.cpp similarity index 82% rename from share/qtcreator/templates/qtquick1app/main.cpp rename to share/qtcreator/templates/qtquick/qtquick_1_1/main.cpp index 70b2e9ea7eb..da0c3075555 100644 --- a/share/qtcreator/templates/qtquick1app/main.cpp +++ b/share/qtcreator/templates/qtquick/qtquick_1_1/main.cpp @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) QtQuick1ApplicationViewer viewer; viewer.addImportPath(QLatin1String("modules")); // ADDIMPORTPATH viewer.setOrientation(QtQuick1ApplicationViewer::ScreenOrientationAuto); // ORIENTATION - viewer.setMainQmlFile(QLatin1String("qml/app/qtquick10/main.qml")); // MAINQML + viewer.setMainQmlFile(QLatin1String("qml/app/main.qml")); // MAINQML viewer.showExpanded(); return app.exec(); diff --git a/share/qtcreator/templates/qtquick1app/qml/app/main.qml b/share/qtcreator/templates/qtquick/qtquick_1_1/qml/app/main.qml similarity index 100% rename from share/qtcreator/templates/qtquick1app/qml/app/main.qml rename to share/qtcreator/templates/qtquick/qtquick_1_1/qml/app/main.qml diff --git a/share/qtcreator/templates/qtquick1app/qtquick1applicationviewer/qtquick1applicationviewer.cpp b/share/qtcreator/templates/qtquick/qtquick_1_1/qtquick1applicationviewer/qtquick1applicationviewer.cpp similarity index 100% rename from share/qtcreator/templates/qtquick1app/qtquick1applicationviewer/qtquick1applicationviewer.cpp rename to share/qtcreator/templates/qtquick/qtquick_1_1/qtquick1applicationviewer/qtquick1applicationviewer.cpp diff --git a/share/qtcreator/templates/qtquick1app/qtquick1applicationviewer/qtquick1applicationviewer.h b/share/qtcreator/templates/qtquick/qtquick_1_1/qtquick1applicationviewer/qtquick1applicationviewer.h similarity index 100% rename from share/qtcreator/templates/qtquick1app/qtquick1applicationviewer/qtquick1applicationviewer.h rename to share/qtcreator/templates/qtquick/qtquick_1_1/qtquick1applicationviewer/qtquick1applicationviewer.h diff --git a/share/qtcreator/templates/qtquick1app/qtquick1applicationviewer/qtquick1applicationviewer.pri b/share/qtcreator/templates/qtquick/qtquick_1_1/qtquick1applicationviewer/qtquick1applicationviewer.pri similarity index 100% rename from share/qtcreator/templates/qtquick1app/qtquick1applicationviewer/qtquick1applicationviewer.pri rename to share/qtcreator/templates/qtquick/qtquick_1_1/qtquick1applicationviewer/qtquick1applicationviewer.pri diff --git a/share/qtcreator/templates/qtquick/qtquick_1_1/template.xml b/share/qtcreator/templates/qtquick/qtquick_1_1/template.xml new file mode 100644 index 00000000000..78a45b4ba50 --- /dev/null +++ b/share/qtcreator/templates/qtquick/qtquick_1_1/template.xml @@ -0,0 +1,9 @@ + + diff --git a/share/qtcreator/templates/qtquick2app/app.pro b/share/qtcreator/templates/qtquick/qtquick_2_0/app.pro similarity index 100% rename from share/qtcreator/templates/qtquick2app/app.pro rename to share/qtcreator/templates/qtquick/qtquick_2_0/app.pro diff --git a/share/qtcreator/templates/qtquick2app/main.cpp b/share/qtcreator/templates/qtquick/qtquick_2_0/main.cpp similarity index 73% rename from share/qtcreator/templates/qtquick2app/main.cpp rename to share/qtcreator/templates/qtquick/qtquick_2_0/main.cpp index fb3846ec627..fd469063288 100644 --- a/share/qtcreator/templates/qtquick2app/main.cpp +++ b/share/qtcreator/templates/qtquick/qtquick_2_0/main.cpp @@ -6,7 +6,7 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); QtQuick2ApplicationViewer viewer; - viewer.setMainQmlFile(QStringLiteral("qml/app/qtquick20/main.qml")); // MAINQML + viewer.setMainQmlFile(QStringLiteral("qml/app/main.qml")); // MAINQML viewer.showExpanded(); return app.exec(); diff --git a/share/qtcreator/templates/qtquick2app/qml/app/main.qml b/share/qtcreator/templates/qtquick/qtquick_2_0/qml/app/main.qml similarity index 100% rename from share/qtcreator/templates/qtquick2app/qml/app/main.qml rename to share/qtcreator/templates/qtquick/qtquick_2_0/qml/app/main.qml diff --git a/share/qtcreator/templates/qtquick2app/qtquick2applicationviewer/qtquick2applicationviewer.cpp b/share/qtcreator/templates/qtquick/qtquick_2_0/qtquick2applicationviewer/qtquick2applicationviewer.cpp similarity index 100% rename from share/qtcreator/templates/qtquick2app/qtquick2applicationviewer/qtquick2applicationviewer.cpp rename to share/qtcreator/templates/qtquick/qtquick_2_0/qtquick2applicationviewer/qtquick2applicationviewer.cpp diff --git a/share/qtcreator/templates/qtquick2app/qtquick2applicationviewer/qtquick2applicationviewer.h b/share/qtcreator/templates/qtquick/qtquick_2_0/qtquick2applicationviewer/qtquick2applicationviewer.h similarity index 100% rename from share/qtcreator/templates/qtquick2app/qtquick2applicationviewer/qtquick2applicationviewer.h rename to share/qtcreator/templates/qtquick/qtquick_2_0/qtquick2applicationviewer/qtquick2applicationviewer.h diff --git a/share/qtcreator/templates/qtquick2app/qtquick2applicationviewer/qtquick2applicationviewer.pri b/share/qtcreator/templates/qtquick/qtquick_2_0/qtquick2applicationviewer/qtquick2applicationviewer.pri similarity index 100% rename from share/qtcreator/templates/qtquick2app/qtquick2applicationviewer/qtquick2applicationviewer.pri rename to share/qtcreator/templates/qtquick/qtquick_2_0/qtquick2applicationviewer/qtquick2applicationviewer.pri diff --git a/share/qtcreator/templates/qtquick/qtquick_2_0/template.xml b/share/qtcreator/templates/qtquick/qtquick_2_0/template.xml new file mode 100644 index 00000000000..b3868c71618 --- /dev/null +++ b/share/qtcreator/templates/qtquick/qtquick_2_0/template.xml @@ -0,0 +1,9 @@ + + diff --git a/share/qtcreator/templates/qtquick2controls/app.pro b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/app.pro similarity index 100% rename from share/qtcreator/templates/qtquick2controls/app.pro rename to share/qtcreator/templates/qtquick/qtquickcontrols_1_0/app.pro diff --git a/share/qtcreator/templates/qtquick2controls/main.cpp b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/main.cpp similarity index 71% rename from share/qtcreator/templates/qtquick2controls/main.cpp rename to share/qtcreator/templates/qtquick/qtquickcontrols_1_0/main.cpp index a06bf0157d4..18fd2076cf2 100644 --- a/share/qtcreator/templates/qtquick2controls/main.cpp +++ b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/main.cpp @@ -5,7 +5,7 @@ int main(int argc, char *argv[]) Application app(argc, argv); QtQuick2ControlsApplicationViewer viewer; - viewer.setMainQmlFile(QStringLiteral("qml/app/qtquick21/main.qml")); // MAINQML + viewer.setMainQmlFile(QStringLiteral("qml/app/main.qml")); // MAINQML viewer.show(); return app.exec(); diff --git a/share/qtcreator/templates/qtquick2controls/qml/app/main.qml b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/qml/app/main.qml similarity index 100% rename from share/qtcreator/templates/qtquick2controls/qml/app/main.qml rename to share/qtcreator/templates/qtquick/qtquickcontrols_1_0/qml/app/main.qml diff --git a/share/qtcreator/templates/qtquick2controls/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.cpp b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.cpp similarity index 100% rename from share/qtcreator/templates/qtquick2controls/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.cpp rename to share/qtcreator/templates/qtquick/qtquickcontrols_1_0/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.cpp diff --git a/share/qtcreator/templates/qtquick2controls/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.h b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.h similarity index 100% rename from share/qtcreator/templates/qtquick2controls/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.h rename to share/qtcreator/templates/qtquick/qtquickcontrols_1_0/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.h diff --git a/share/qtcreator/templates/qtquick2controls/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.pri b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.pri similarity index 100% rename from share/qtcreator/templates/qtquick2controls/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.pri rename to share/qtcreator/templates/qtquick/qtquickcontrols_1_0/qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.pri diff --git a/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/template.xml b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/template.xml new file mode 100644 index 00000000000..45b12b8207a --- /dev/null +++ b/share/qtcreator/templates/qtquick/qtquickcontrols_1_0/template.xml @@ -0,0 +1,9 @@ + + diff --git a/share/qtcreator/translations/extract-qtquickwizards.xq b/share/qtcreator/translations/extract-qtquickwizards.xq new file mode 100644 index 00000000000..cbe3a3be748 --- /dev/null +++ b/share/qtcreator/translations/extract-qtquickwizards.xq @@ -0,0 +1,6 @@ +let $prefix := string("QT_TRANSLATE_NOOP("QmakeProjectManager::QtQuickAppWizard", "") +let $suffix := concat("")", codepoints-to-string(10)) +for $file in tokenize($files, string("\|")) + let $doc := doc($file) + for $text in ($doc/*:template/*:description, $doc/*:template/*:displayname) + return fn:concat($prefix, data($text), $suffix) diff --git a/share/qtcreator/translations/translations.pro b/share/qtcreator/translations/translations.pro index 547f7557a96..d209ca73c13 100644 --- a/share/qtcreator/translations/translations.pro +++ b/share/qtcreator/translations/translations.pro @@ -22,6 +22,7 @@ TRANSLATIONS = $$prependAll(LANGUAGES, $$PWD/qtcreator_,.ts) MIME_TR_H = $$OUT_PWD/mime_tr.h CUSTOMWIZARD_TR_H = $$OUT_PWD/customwizard_tr.h QMLWIZARD_TR_H = $$OUT_PWD/qmlwizard_tr.h +QTQUICKWIZARD_TR_H = $$OUT_PWD/qtquickwizard_tr.h EXTERNALTOOLS_TR_H = $$OUT_PWD/externaltools_tr.h for(dir, $$list($$files($$IDE_SOURCE_TREE/src/plugins/*))):MIMETYPES_FILES += $$files($$dir/*.mimetypes.xml) @@ -33,6 +34,9 @@ CUSTOMWIZARD_FILES = \"$$join(CUSTOMWIZARD_FILES, |)\" for(dir, $$list($$files($$IDE_SOURCE_TREE/share/qtcreator/templates/qml/*))):QMLWIZARD_FILES += $$files($$dir/template.xml) QMLWIZARD_FILES = \"$$join(QMLWIZARD_FILES, |)\" +for(dir, $$list($$files($$IDE_SOURCE_TREE/share/qtcreator/templates/qtquick/*))):QTQUICKWIZARD_FILES += $$files($$dir/template.xml) +QTQUICKWIZARD_FILES = \"$$join(QTQUICKWIZARD_FILES, |)\" + for(file, $$list($$files($$IDE_SOURCE_TREE/src/share/qtcreator/externaltools/*))):EXTERNALTOOLS_FILES += $$files($$file) EXTERNALTOOLS_FILES = \"$$join(EXTERNALTOOLS_FILES, |)\" @@ -40,6 +44,7 @@ extract.commands += \ $$XMLPATTERNS -output $$MIME_TR_H -param files=$$MIMETYPES_FILES $$PWD/extract-mimetypes.xq $$escape_expand(\\n\\t) \ $$XMLPATTERNS -output $$CUSTOMWIZARD_TR_H -param files=$$CUSTOMWIZARD_FILES $$PWD/extract-customwizards.xq $$escape_expand(\\n\\t) \ $$XMLPATTERNS -output $$QMLWIZARD_TR_H -param files=$$QMLWIZARD_FILES $$PWD/extract-qmlwizards.xq $$escape_expand(\\n\\t) \ + $$XMLPATTERNS -output $$QTQUICKWIZARD_TR_H -param files=$$QTQUICKWIZARD_FILES $$PWD/extract-qtquickwizards.xq $$escape_expand(\\n\\t) \ $$XMLPATTERNS -output $$EXTERNALTOOLS_TR_H -param files=$$EXTERNALTOOLS_FILES $$PWD/extract-externaltools.xq QMAKE_EXTRA_TARGETS += extract @@ -59,12 +64,12 @@ files = $$files($$PWD/*_??.ts) $$PWD/qtcreator_untranslated.ts for(file, files) { lang = $$replace(file, .*_([^/]*)\\.ts, \\1) v = ts-$${lang}.commands - $$v = cd $$wd && $$LUPDATE $$sources $$MIME_TR_H $$CUSTOMWIZARD_TR_H $$QMLWIZARD_TR_H $$EXTERNALTOOLS_TR_H -ts $$file + $$v = cd $$wd && $$LUPDATE $$sources $$MIME_TR_H $$CUSTOMWIZARD_TR_H $$QMLWIZARD_TR_H $$QTQUICKWIZARD_TR_H $$EXTERNALTOOLS_TR_H -ts $$file v = ts-$${lang}.depends $$v = extract QMAKE_EXTRA_TARGETS += ts-$$lang } -ts-all.commands = cd $$wd && $$LUPDATE $$sources $$MIME_TR_H $$CUSTOMWIZARD_TR_H $$QMLWIZARD_TR_H $$EXTERNALTOOLS_TR_H -ts $$files +ts-all.commands = cd $$wd && $$LUPDATE $$sources $$MIME_TR_H $$CUSTOMWIZARD_TR_H $$QMLWIZARD_TR_H $$QTQUICKWIZARD_TR_H$$EXTERNALTOOLS_TR_H -ts $$files ts-all.depends = extract QMAKE_EXTRA_TARGETS += ts-all diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 910f002f72c..c86f57cd6af 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -429,10 +429,10 @@ bool QmakeProject::fromMap(const QVariantMap &map) foreach (QmakeProFileNode *node, applicationProFiles(QmakeProject::ExactAndCumulativeParse)) { const QString path = node->path(); - qtQuickApp.setComponentSet(QtQuickApp::QtQuick10Components); - updateBoilerPlateCodeFiles(&qtQuickApp, path); - qtQuickApp.setComponentSet(QtQuickApp::QtQuick20Components); - updateBoilerPlateCodeFiles(&qtQuickApp, path); + foreach (TemplateInfo info, QtQuickApp::templateInfos()) { + qtQuickApp.setTemplateInfo(info); + updateBoilerPlateCodeFiles(&qtQuickApp, path); + } updateBoilerPlateCodeFiles(&html5App, path); } return true; diff --git a/src/plugins/qmakeprojectmanager/wizards/qtquickapp.cpp b/src/plugins/qmakeprojectmanager/wizards/qtquickapp.cpp index 740ba71ba36..bb93d200431 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtquickapp.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/qtquickapp.cpp @@ -30,6 +30,7 @@ #include "qtquickapp.h" #include +#include #include #include @@ -43,20 +44,152 @@ namespace QmakeProjectManager { namespace Internal { +static QString templateRootDirectory() +{ + return Core::ICore::resourcePath() + QLatin1String("/templates/qtquick/"); +} + +static QStringList templateNames() +{ + QStringList templateNameList; + const QDir templateRoot(templateRootDirectory()); + + foreach (const QFileInfo &subDirectory, + templateRoot.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) + templateNameList.append(subDirectory.fileName()); + + return templateNameList; +} + +// Return locale language attribute "de_UTF8" -> "de", empty string for "C" +static QString languageSetting() +{ +#ifdef QT_CREATOR + QString name = Core::ICore::userInterfaceLanguage(); + const int underScorePos = name.indexOf(QLatin1Char('_')); + if (underScorePos != -1) + name.truncate(underScorePos); + if (name.compare(QLatin1String("C"), Qt::CaseInsensitive) == 0) + name.clear(); + return name; +#else + return QLocale::system().name(); +#endif +} + +static inline bool assignLanguageElementText(QXmlStreamReader &reader, + const QString &desiredLanguage, + QString *target) +{ + const QStringRef elementLanguage = reader.attributes().value(QLatin1String("xml:lang")); + if (elementLanguage.isEmpty()) { + // Try to find a translation for our Wizards + *target = QCoreApplication::translate("QmakeProjectManager::QtQuickAppWizard", + reader.readElementText().toLatin1().constData()); + return true; + } + if (elementLanguage == desiredLanguage) { + *target = reader.readElementText(); + return true; + } + return false; +} + +static bool parseTemplateXml(QXmlStreamReader &reader, TemplateInfo *info) +{ + const QString locale = languageSetting(); + + static const QLatin1String tag_template("template"); + static const QLatin1String tag_displayName("displayname"); + static const QLatin1String tag_description("description"); + static const QLatin1String attribute_featuresRequired("featuresRequired"); + static const QLatin1String attribute_openEditor("openeditor"); + static const QLatin1String attribute_priority("priority"); + static const QLatin1String attribute_viewerdir("viewerdir"); + static const QLatin1String attribute_viewerclassname("viewerclassname"); + static const QLatin1String attribute_stubversionminor("stubversionminor"); + + while (!reader.atEnd() && !reader.hasError()) { + reader.readNext(); + if (reader.tokenType() != QXmlStreamReader::StartElement) + continue; + + if (reader.name() == tag_template) { + info->openFile = reader.attributes().value(attribute_openEditor).toString(); + if (reader.attributes().hasAttribute(attribute_priority)) + info->priority = reader.attributes().value(attribute_priority).toString(); + + if (reader.attributes().hasAttribute(attribute_featuresRequired)) + info->featuresRequired = reader.attributes().value(attribute_featuresRequired).toString(); + + if (reader.attributes().hasAttribute(attribute_viewerdir)) + info->viewerDir = reader.attributes().value(attribute_viewerdir).toString(); + + if (reader.attributes().hasAttribute(attribute_viewerclassname)) + info->viewerClassName = reader.attributes().value(attribute_viewerclassname).toString(); + + if (reader.attributes().hasAttribute(attribute_stubversionminor)) + info->stubVersionMinor = reader.attributes().value(attribute_stubversionminor).toString().toInt(); + + } else if (reader.name() == tag_displayName) { + if (!assignLanguageElementText(reader, locale, &info->displayName)) + continue; + } else if (reader.name() == tag_description) { + if (!assignLanguageElementText(reader, locale, &info->description)) + continue; + } + } + if (reader.hasError()) { + qWarning() << reader.errorString(); + return false; + } + + return true; +} + +class TemplateInfoList +{ +public: + TemplateInfoList() + { + QMultiMap multiMap; + foreach (const QString &templateName, templateNames()) { + const QString templatePath = templateRootDirectory() + templateName; + QFile xmlFile(templatePath + QLatin1String("/template.xml")); + if (!xmlFile.open(QIODevice::ReadOnly)) { + qWarning().nospace() << QString::fromLatin1("Cannot open %1").arg(QDir::toNativeSeparators(QFileInfo(xmlFile.fileName()).absoluteFilePath())); + continue; + } + TemplateInfo info; + info.templateName = templateName; + info.templatePath = templatePath; + QXmlStreamReader reader(&xmlFile); + if (parseTemplateXml(reader, &info)) + multiMap.insert(info.priority, info); + } + m_templateInfoList = multiMap.values(); + } + QList templateInfoList() const { return m_templateInfoList; } + +private: + QList m_templateInfoList; +}; + +Q_GLOBAL_STATIC(TemplateInfoList, templateInfoList) + +QList QtQuickApp::templateInfos() +{ + return templateInfoList()->templateInfoList(); +} + QtQuickApp::QtQuickApp() : AbstractMobileApp() - , m_componentSet(QtQuick10Components) { } -void QtQuickApp::setComponentSet(ComponentSet componentSet) +void QtQuickApp::setTemplateInfo(const TemplateInfo &templateInfo) { - m_componentSet = componentSet; -} - -QtQuickApp::ComponentSet QtQuickApp::componentSet() const -{ - return m_componentSet; + m_templateInfo = templateInfo; } QString QtQuickApp::pathExtended(int fileType) const @@ -88,28 +221,12 @@ QString QtQuickApp::pathExtended(int fileType) const QString QtQuickApp::originsRoot() const { - switch (m_componentSet) { - case QtQuickControls10: return templatesRoot() + QLatin1String("qtquick2controls/"); - case QtQuick20Components: return templatesRoot() + QLatin1String("qtquick2app/"); - case QtQuick10Components: return templatesRoot() + QLatin1String("qtquick1app/"); - } - - qWarning() << "QtQuickApp::originsRoot() - unhandled component set" - << m_componentSet; - return QString(); + return m_templateInfo.templatePath + QLatin1Char('/'); } QString QtQuickApp::mainWindowClassName() const { - switch (m_componentSet) { - case QtQuickControls10: return QLatin1String("QtQuick2ControlsApplicationViewer"); - case QtQuick20Components: return QLatin1String("QtQuick2ApplicationViewer"); - case QtQuick10Components: return QLatin1String("QtQuick1ApplicationViewer"); - } - - qWarning() << "QtQuickApp::mainWindowClassName() - unhandled component set" - << m_componentSet; - return QString(); + return m_templateInfo.viewerClassName; } bool QtQuickApp::adaptCurrentMainCppTemplateLine(QString &line) const @@ -162,15 +279,7 @@ bool QtQuickApp::useExistingMainQml() const QString QtQuickApp::appViewerBaseName() const { - switch (m_componentSet) { - case QtQuickControls10: return QLatin1String("qtquick2controlsapplicationviewer"); - case QtQuick20Components: return QLatin1String("qtquick2applicationviewer"); - case QtQuick10Components: return QLatin1String("qtquick1applicationviewer"); - } - - qWarning() << "QtQuickApp::appViewerBaseName() - unhandled component set" - << m_componentSet; - return QString(); + return m_templateInfo.viewerDir; } QString QtQuickApp::fileName(QtQuickApp::ExtendedFileType type) const @@ -217,7 +326,7 @@ QByteArray QtQuickApp::generateFileExtended(int fileType, int QtQuickApp::stubVersionMinor() const { - return (m_componentSet == QtQuick20Components || m_componentSet == QtQuickControls10) ? 5 : 24; + return m_templateInfo.stubVersionMinor; } QList QtQuickApp::updateableFiles(const QString &mainProFile) const diff --git a/src/plugins/qmakeprojectmanager/wizards/qtquickapp.h b/src/plugins/qmakeprojectmanager/wizards/qtquickapp.h index aa77b4ca533..e421a42dcb4 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtquickapp.h +++ b/src/plugins/qmakeprojectmanager/wizards/qtquickapp.h @@ -47,6 +47,22 @@ struct QtQuickAppGeneratedFileInfo : public AbstractGeneratedFileInfo QtQuickAppGeneratedFileInfo() : AbstractGeneratedFileInfo() {} }; +class TemplateInfo +{ +public: + TemplateInfo() : stubVersionMinor(9) {} + QString templateName; + QString templatePath; + QString displayName; + QString description; + QString openFile; + QString featuresRequired; + QString priority; + QString viewerClassName; + QString viewerDir; + int stubVersionMinor; +}; + class QtQuickApp : public AbstractMobileApp { public: @@ -63,16 +79,11 @@ public: QmlDirProFileRelative }; - enum ComponentSet { - QtQuick10Components, - QtQuick20Components, - QtQuickControls10 - }; - QtQuickApp(); - void setComponentSet(ComponentSet componentSet); - ComponentSet componentSet() const; + static QList templateInfos(); + + void setTemplateInfo(const TemplateInfo &templateInfo); #ifndef CREATORLESSTEST virtual Core::GeneratedFiles generateFiles(QString *errorMessage) const; @@ -103,7 +114,7 @@ private: QList deploymentFolders() const; QFileInfo m_mainQmlFile; - ComponentSet m_componentSet; + TemplateInfo m_templateInfo; }; } // namespace Internal diff --git a/src/plugins/qmakeprojectmanager/wizards/qtquickappwizard.cpp b/src/plugins/qmakeprojectmanager/wizards/qtquickappwizard.cpp index ddc6f19af96..f2481916889 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtquickappwizard.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/qtquickappwizard.cpp @@ -49,7 +49,7 @@ class QtQuickAppWizardDialog : public AbstractMobileAppWizardDialog public: explicit QtQuickAppWizardDialog(QWidget *parent, const Core::WizardDialogParameters ¶meters); - QtQuickApp::ComponentSet componentSet() const { return m_componentSetPage->componentSet(); } + TemplateInfo templateInfo() const; protected: void initializePage(int id); @@ -76,26 +76,26 @@ QtQuickAppWizardDialog::QtQuickAppWizardDialog(QWidget *parent, void QtQuickAppWizardDialog::initializePage(int id) { if (page(id) == kitsPage()) { - Core::FeatureSet features = Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_1); - QtQuickApp::ComponentSet components = componentSet(); - switch (components) { - case QtQuickApp::QtQuick10Components: - features = Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_1); - break; - case QtQuickApp::QtQuick20Components: - features = Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_2); - break; - case QtQuickApp::QtQuickControls10: - features = Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_2) - | Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_CONTROLS); - break; + QStringList stringList = + templateInfo().featuresRequired.split(QLatin1Char(','), QString::SkipEmptyParts); + Core::FeatureSet features; + foreach (const QString &string, stringList) { + Core::Feature feature(Core::Id::fromString(string.trimmed())); + features |= feature; } + setRequiredFeatures(features); updateKitsPage(); } AbstractMobileAppWizardDialog::initializePage(id); } +TemplateInfo QtQuickAppWizardDialog::templateInfo() const +{ + return m_componentSetPage->templateInfo(); +} + + class QtQuickAppWizardPrivate { class QtQuickApp *app; @@ -143,7 +143,7 @@ void QtQuickAppWizard::prepareGenerateFiles(const QWizard *w, { Q_UNUSED(errorMessage) const QtQuickAppWizardDialog *wizard = qobject_cast(w); - d->app->setComponentSet(wizard->componentSet()); + d->app->setTemplateInfo(wizard->templateInfo()); } QString QtQuickAppWizard::fileToOpenPostGeneration() const diff --git a/src/plugins/qmakeprojectmanager/wizards/qtquickappwizardpages.cpp b/src/plugins/qmakeprojectmanager/wizards/qtquickappwizardpages.cpp index 0ba72a631ce..899b6722267 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtquickappwizardpages.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/qtquickappwizardpages.cpp @@ -42,31 +42,6 @@ public: QLabel *m_descriptionLabel; }; -QString QtQuickComponentSetPage::description(QtQuickApp::ComponentSet componentSet) const -{ - const QString basicDescription = tr("Creates a Qt Quick 1 application project that can contain " - "both QML and C++ code and includes a QDeclarativeView.

"); - const QString basicDescription2 = tr("Creates a Qt Quick 2 application project that can contain " - "both QML and C++ code and includes a QQuickView.

"); - switch (componentSet) { - case QtQuickApp::QtQuickControls10: - return basicDescription2 + tr("Creates a deployable Qt Quick application using " - "Qt Quick Controls. All files and directories that " - "reside in the same directory as the main .qml file " - "are deployed. You can modify the contents of the " - "directory any time before deploying.\n\nRequires Qt 5.1 or newer."); - case QtQuickApp::QtQuick20Components: - return basicDescription2 + tr("The built-in QML types in the QtQuick 2 namespace allow " - "you to write cross-platform applications with " - "a custom look and feel.\n\nRequires Qt 5.0 or newer."); - case QtQuickApp::QtQuick10Components: - return basicDescription + tr("The built-in QML types in the QtQuick 1 namespace allow " - "you to write cross-platform applications with " - "a custom look and feel.\n\nRequires Qt 4.8 or newer."); - } - return QString(); -} - QtQuickComponentSetPage::QtQuickComponentSetPage(QWidget *parent) : QWizardPage(parent) , d(new QtQuickComponentSetPagePrivate) @@ -77,9 +52,8 @@ QtQuickComponentSetPage::QtQuickComponentSetPage(QWidget *parent) QLabel *label = new QLabel(tr("Qt Quick component set:"), this); d->m_versionComboBox = new QComboBox(this); - d->m_versionComboBox->addItem(tr("Qt Quick Controls 1.0"), QtQuickApp::QtQuickControls10); - d->m_versionComboBox->addItem(tr("Qt Quick 2.0"), QtQuickApp::QtQuick20Components); - d->m_versionComboBox->addItem(tr("Qt Quick 1.1"), QtQuickApp::QtQuick10Components); + foreach (const TemplateInfo &templateInfo, QtQuickApp::templateInfos()) + d->m_versionComboBox->addItem(templateInfo.displayName); l->addWidget(label); l->addWidget(d->m_versionComboBox); @@ -87,7 +61,8 @@ QtQuickComponentSetPage::QtQuickComponentSetPage(QWidget *parent) d->m_descriptionLabel = new QLabel(this); d->m_descriptionLabel->setWordWrap(true); d->m_descriptionLabel->setTextFormat(Qt::RichText); - connect(d->m_versionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateDescription(int))); + connect(d->m_versionComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(updateDescription(int))); updateDescription(d->m_versionComboBox->currentIndex()); mainLayout->addLayout(l); @@ -99,19 +74,20 @@ QtQuickComponentSetPage::~QtQuickComponentSetPage() delete d; } -QtQuickApp::ComponentSet QtQuickComponentSetPage::componentSet(int index) const +TemplateInfo QtQuickComponentSetPage::templateInfo() const { - return (QtQuickApp::ComponentSet)d->m_versionComboBox->itemData(index).toInt(); -} - -QtQuickApp::ComponentSet QtQuickComponentSetPage::componentSet() const -{ - return componentSet(d->m_versionComboBox->currentIndex()); + if (QtQuickApp::templateInfos().isEmpty()) + return TemplateInfo(); + return QtQuickApp::templateInfos().at(d->m_versionComboBox->currentIndex()); } void QtQuickComponentSetPage::updateDescription(int index) { - d->m_descriptionLabel->setText(description(componentSet(index))); + if (QtQuickApp::templateInfos().isEmpty()) + return; + + const TemplateInfo templateInfo = QtQuickApp::templateInfos().at(index); + d->m_descriptionLabel->setText(templateInfo.description); } } // namespace Internal diff --git a/src/plugins/qmakeprojectmanager/wizards/qtquickappwizardpages.h b/src/plugins/qmakeprojectmanager/wizards/qtquickappwizardpages.h index 7530cb2e97c..461b3da0a11 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtquickappwizardpages.h +++ b/src/plugins/qmakeprojectmanager/wizards/qtquickappwizardpages.h @@ -44,15 +44,12 @@ public: explicit QtQuickComponentSetPage(QWidget *parent = 0); virtual ~QtQuickComponentSetPage(); - QtQuickApp::ComponentSet componentSet() const; + TemplateInfo templateInfo() const; private slots: void updateDescription(int index); private: - QtQuickApp::ComponentSet componentSet(int index) const; - QString description(QtQuickApp::ComponentSet componentSet) const; - class QtQuickComponentSetPagePrivate *d; };