From af46310681cbb264512718e3478d8f81c8cf93f0 Mon Sep 17 00:00:00 2001 From: Ali Kianian Date: Thu, 10 Oct 2024 12:29:02 +0300 Subject: [PATCH] QmlDesigner: Enable 'automatic cmake generation' by wizard Task-number: QDS-13344 Change-Id: Ie3e5baf42e31375df8d2d00cb5bf916b2b8bd2ad Reviewed-by: Mahmoud Badri Reviewed-by: Thomas Hartmann --- .../imports/NewProjectDialog/Details.qml | 15 ++ .../projects/application-3d/wizard.json | 10 + .../application-extended-3d/wizard.json | 10 + .../projects/application/wizard.json | 10 + .../projects/common/app.qmlproject.tpl | 4 + src/plugins/studiowelcome/CMakeLists.txt | 1 + src/plugins/studiowelcome/createproject.cpp | 3 + src/plugins/studiowelcome/createproject.h | 6 + src/plugins/studiowelcome/fieldhelper.cpp | 89 +++++++++ src/plugins/studiowelcome/fieldhelper.h | 46 +++++ src/plugins/studiowelcome/presetmodel.cpp | 1 + src/plugins/studiowelcome/presetmodel.h | 1 + src/plugins/studiowelcome/qdsnewdialog.cpp | 55 +++++- src/plugins/studiowelcome/qdsnewdialog.h | 15 ++ src/plugins/studiowelcome/userpresets.cpp | 18 +- src/plugins/studiowelcome/userpresets.h | 7 +- src/plugins/studiowelcome/wizardhandler.cpp | 177 ++++-------------- src/plugins/studiowelcome/wizardhandler.h | 7 +- 18 files changed, 313 insertions(+), 162 deletions(-) create mode 100644 src/plugins/studiowelcome/fieldhelper.cpp create mode 100644 src/plugins/studiowelcome/fieldhelper.h diff --git a/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml b/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml index f905191eff9..ccad08f738a 100644 --- a/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml +++ b/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml @@ -391,6 +391,21 @@ Item { visible: BackendApi.haveVirtualKeyboard } + StudioControls.CheckBox { + id: enableCMakeGeneration + actionIndicatorVisible: false + text: qsTr("Enable Cmake Generation") + font.pixelSize: DialogValues.defaultPixelSize + checked: BackendApi.enableCMakeGeneration + visible: BackendApi.hasCMakeGeneration + } + + Binding { + target: BackendApi + property: "enableCMakeGeneration" + value: enableCMakeGeneration.checked + } + RowLayout { // Target Qt Version width: parent.width visible: BackendApi.haveTargetQtVersion diff --git a/share/qtcreator/qmldesigner/studio_templates/projects/application-3d/wizard.json b/share/qtcreator/qmldesigner/studio_templates/projects/application-3d/wizard.json index afb00fa253c..ae3dfe5a4ab 100644 --- a/share/qtcreator/qmldesigner/studio_templates/projects/application-3d/wizard.json +++ b/share/qtcreator/qmldesigner/studio_templates/projects/application-3d/wizard.json @@ -32,6 +32,7 @@ { "key": "ScreenWidth", "value": "%{JS: value('UseStandardResolution') === 'true' ? %{ScreenFactor}.ScreenWidth : value('CustomScreenWidth')}" }, { "key": "ScreenHeight", "value": "%{JS: value('UseStandardResolution') === 'true' ? %{ScreenFactor}.ScreenHeight : value('CustomScreenHeight')}" }, { "key": "UseVirtualKeyboardDefault", "value": "%{JS: false}" }, + { "key": "EnableCMakeGenerationDefault", "value": "%{JS: true}" }, { "key": "QtQuick3DVersion", "value": "%{JS: %{TargetQtVersion}.TargetQuick3DVersion}" } ], @@ -208,6 +209,15 @@ "checked": "%{UseVirtualKeyboardDefault}" } }, + { + "name": "EnableCMakeGeneration", + "trDisplayName": "Enable CMake Genertion", + "type": "CheckBox", + "data": + { + "checked": "%{EnableCMakeGenerationDefault}" + } + }, { "name": "CustomScreenWidth", "trDisplayName": "Custom screen width:", diff --git a/share/qtcreator/qmldesigner/studio_templates/projects/application-extended-3d/wizard.json b/share/qtcreator/qmldesigner/studio_templates/projects/application-extended-3d/wizard.json index ccfcd01a983..a0cccc15915 100644 --- a/share/qtcreator/qmldesigner/studio_templates/projects/application-extended-3d/wizard.json +++ b/share/qtcreator/qmldesigner/studio_templates/projects/application-extended-3d/wizard.json @@ -32,6 +32,7 @@ { "key": "ScreenWidth", "value": "%{JS: value('UseStandardResolution') === 'true' ? %{ScreenFactor}.ScreenWidth : value('CustomScreenWidth')}" }, { "key": "ScreenHeight", "value": "%{JS: value('UseStandardResolution') === 'true' ? %{ScreenFactor}.ScreenHeight : value('CustomScreenHeight')}" }, { "key": "UseVirtualKeyboardDefault", "value": "%{JS: false}" }, + { "key": "EnableCMakeGenerationDefault", "value": "%{JS: true}" }, { "key": "QtQuick3DVersion", "value": "%{JS: %{TargetQtVersion}.TargetQuick3DVersion}" } ], @@ -208,6 +209,15 @@ "checked": "%{UseVirtualKeyboardDefault}" } }, + { + "name": "EnableCMakeGeneration", + "trDisplayName": "Enable CMake Genertion", + "type": "CheckBox", + "data": + { + "checked": "%{EnableCMakeGenerationDefault}" + } + }, { "name": "CustomScreenWidth", "trDisplayName": "Custom screen width:", diff --git a/share/qtcreator/qmldesigner/studio_templates/projects/application/wizard.json b/share/qtcreator/qmldesigner/studio_templates/projects/application/wizard.json index 0aab9b601f3..a7eb00ae0f5 100644 --- a/share/qtcreator/qmldesigner/studio_templates/projects/application/wizard.json +++ b/share/qtcreator/qmldesigner/studio_templates/projects/application/wizard.json @@ -31,6 +31,7 @@ { "key": "ScreenWidth", "value": "%{JS: value('UseStandardResolution') === 'true' ? %{ScreenFactor}.ScreenWidth : value('CustomScreenWidth')}" }, { "key": "ScreenHeight", "value": "%{JS: value('UseStandardResolution') === 'true' ? %{ScreenFactor}.ScreenHeight : value('CustomScreenHeight')}" }, { "key": "UseVirtualKeyboardDefault", "value": "%{JS: false}" }, + { "key": "EnableCMakeGenerationDefault", "value": "%{JS: true}" }, { "key": "DefaultStyle", "value": "Basic" } ], @@ -207,6 +208,15 @@ "checked": "%{UseVirtualKeyboardDefault}" } }, + { + "name": "EnableCMakeGeneration", + "trDisplayName": "Enable CMake Genertion", + "type": "CheckBox", + "data": + { + "checked": "%{EnableCMakeGenerationDefault}" + } + }, { "name": "CustomScreenWidth", "trDisplayName": "Custom screen width:", diff --git a/share/qtcreator/qmldesigner/studio_templates/projects/common/app.qmlproject.tpl b/share/qtcreator/qmldesigner/studio_templates/projects/common/app.qmlproject.tpl index 7e4e70fb9b9..615cc8d2348 100644 --- a/share/qtcreator/qmldesigner/studio_templates/projects/common/app.qmlproject.tpl +++ b/share/qtcreator/qmldesigner/studio_templates/projects/common/app.qmlproject.tpl @@ -103,6 +103,10 @@ Project { /* Required for deployment */ targetDirectory: "/opt/%{ProjectName}" +@if %{EnableCMakeGeneration} + enableCMakeGeneration: true +@endif + qdsVersion: "4.6" quickVersion: "%{QtQuickVersion}" diff --git a/src/plugins/studiowelcome/CMakeLists.txt b/src/plugins/studiowelcome/CMakeLists.txt index c4db40db5e9..ead7b757893 100644 --- a/src/plugins/studiowelcome/CMakeLists.txt +++ b/src/plugins/studiowelcome/CMakeLists.txt @@ -4,6 +4,7 @@ add_qtc_plugin(StudioWelcome PLUGIN_DEPENDS Core ProjectExplorer QtSupport QmlDesigner DEFINES STUDIO_QML_PATH="${CMAKE_CURRENT_SOURCE_DIR}/qml/" SOURCES + fieldhelper.cpp fieldhelper.h studiowelcomeplugin.cpp studiowelcomeplugin.h newprojectdialogimageprovider.cpp newprojectdialogimageprovider.h presetmodel.cpp presetmodel.h diff --git a/src/plugins/studiowelcome/createproject.cpp b/src/plugins/studiowelcome/createproject.cpp index 6ed783780cb..5ed59a339e4 100644 --- a/src/plugins/studiowelcome/createproject.cpp +++ b/src/plugins/studiowelcome/createproject.cpp @@ -43,6 +43,9 @@ void CreateProject::processFieldPage(ProjectExplorer::JsonFieldPage *page) if (page->jsonField("UseVirtualKeyboard")) m_wizard.setUseVirtualKeyboard(m_useVirtualKeyboard); + if (page->jsonField("EnableCMakeGeneration")) + m_wizard.enableCMakeGeneration(m_enableCMakeGeneration); + auto widthField = dynamic_cast(page->jsonField("CustomScreenWidth")); auto heightField = dynamic_cast(page->jsonField("CustomScreenHeight")); diff --git a/src/plugins/studiowelcome/createproject.h b/src/plugins/studiowelcome/createproject.h index e1b0af34205..b9abe2d2edb 100644 --- a/src/plugins/studiowelcome/createproject.h +++ b/src/plugins/studiowelcome/createproject.h @@ -28,6 +28,11 @@ public: CreateProject &withStyle(int styleIndex) { m_styleIndex = styleIndex; return *this; } CreateProject &useQtVirtualKeyboard(bool value) { m_useVirtualKeyboard = value; return *this; } + CreateProject &enableCMakeGeneration(bool value) + { + m_enableCMakeGeneration = value; + return *this; + } CreateProject &saveAsDefaultLocation(bool value) { m_saveAsDefaultLocation = value; return *this; } CreateProject &withTargetQtVersion(int targetQtVersionIndex) { m_targetQtVersionIndex = targetQtVersionIndex; return *this; } @@ -48,6 +53,7 @@ private: QString m_customHeight; int m_styleIndex = -1; bool m_useVirtualKeyboard = false; + bool m_enableCMakeGeneration = false; bool m_saveAsDefaultLocation = false; int m_targetQtVersionIndex = -1; }; diff --git a/src/plugins/studiowelcome/fieldhelper.cpp b/src/plugins/studiowelcome/fieldhelper.cpp new file mode 100644 index 00000000000..5fdf3532be3 --- /dev/null +++ b/src/plugins/studiowelcome/fieldhelper.cpp @@ -0,0 +1,89 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "fieldhelper.h" + +#include +#include + +#include + +using namespace StudioWelcome::FieldHelper; + +CheckBoxHelper::CheckBoxHelper(ProjectExplorer::JsonFieldPage *detailsPage, const QString &fieldName) + : m_field(dynamic_cast(detailsPage->jsonField(fieldName))) +{} + +void CheckBoxHelper::setChecked(bool value) +{ + QTC_ASSERT(m_field, return); + + m_field->setChecked(value); +} + +ComboBoxHelper::ComboBoxHelper(ProjectExplorer::JsonFieldPage *detailsPage, const QString &fieldName) + : m_field(dynamic_cast(detailsPage->jsonField(fieldName))) +{} + +void ComboBoxHelper::selectIndex(int index) +{ + QTC_ASSERT(m_field, return); + + m_field->selectRow(index); +} + +QString ComboBoxHelper::text(int index) const +{ + QTC_ASSERT(m_field, return {}); + + QStandardItemModel *model = m_field->model(); + if (index < 0 || index >= model->rowCount()) + return {}; + + return model->item(index)->text(); +} + +int ComboBoxHelper::indexOf(const QString &text) const +{ + QTC_ASSERT(m_field, return -1); + + const QStandardItemModel *model = m_field->model(); + for (int i = 0; i < model->rowCount(); ++i) { + const QStandardItem *item = model->item(i, 0); + const QString text = item->text(); + + if (text == text) + return i; + } + + return -1; +} + +int ComboBoxHelper::selectedIndex() const +{ + QTC_ASSERT(m_field, return -1); + + return m_field->selectedRow(); +} + +QStandardItemModel *ComboBoxHelper::model() const +{ + QTC_ASSERT(m_field, return {}); + + return m_field->model(); +} + +QStringList ComboBoxHelper::allTexts() const +{ + QTC_ASSERT(m_field, return {}); + + QStandardItemModel *model = m_field->model(); + const int rows = model->rowCount(); + QStringList result; + result.reserve(rows); + + for (int i = 0; i < rows; ++i) + result.append(model->item(i)->text()); + + return result; +} diff --git a/src/plugins/studiowelcome/fieldhelper.h b/src/plugins/studiowelcome/fieldhelper.h new file mode 100644 index 00000000000..886e49d0df8 --- /dev/null +++ b/src/plugins/studiowelcome/fieldhelper.h @@ -0,0 +1,46 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include + +QT_FORWARD_DECLARE_CLASS(QStandardItemModel) + +namespace ProjectExplorer { +class JsonFieldPage; +class CheckBoxField; +class ComboBoxField; +} + +namespace StudioWelcome::FieldHelper { + +class CheckBoxHelper +{ +public: + CheckBoxHelper(ProjectExplorer::JsonFieldPage *detailsPage, const QString &fieldName); + + void setChecked(bool value); + +private: + ProjectExplorer::CheckBoxField *m_field = nullptr; +}; + +class ComboBoxHelper +{ +public: + ComboBoxHelper(ProjectExplorer::JsonFieldPage *detailsPage, const QString &fieldName); + + void selectIndex(int index); + + QString text(int index) const; + int indexOf(const QString &text) const; + int selectedIndex() const; + QStandardItemModel *model() const; + QStringList allTexts() const; + +private: + ProjectExplorer::ComboBoxField *m_field = nullptr; +}; + +} // namespace StudioWelcome::FieldHelper diff --git a/src/plugins/studiowelcome/presetmodel.cpp b/src/plugins/studiowelcome/presetmodel.cpp index 06e8def612b..e4562872b7a 100644 --- a/src/plugins/studiowelcome/presetmodel.cpp +++ b/src/plugins/studiowelcome/presetmodel.cpp @@ -93,6 +93,7 @@ PresetItems PresetData::makeUserPresets(const PresetItems &wizardPresets, presetItem->qtVersion = userPresetData.qtVersion; presetItem->styleName = userPresetData.styleName; presetItem->useQtVirtualKeyboard = userPresetData.useQtVirtualKeyboard; + presetItem->enableCMakeGeneration = userPresetData.enableCMakeGeneration; presetItem->create = foundPreset->create; presetItem->description = foundPreset->description; diff --git a/src/plugins/studiowelcome/presetmodel.h b/src/plugins/studiowelcome/presetmodel.h index f23ec2ea778..94f11fb9aff 100644 --- a/src/plugins/studiowelcome/presetmodel.h +++ b/src/plugins/studiowelcome/presetmodel.h @@ -80,6 +80,7 @@ struct UserPresetItem : public PresetItem public: QString userName; bool useQtVirtualKeyboard; + bool enableCMakeGeneration; QString qtVersion; QString styleName; }; diff --git a/src/plugins/studiowelcome/qdsnewdialog.cpp b/src/plugins/studiowelcome/qdsnewdialog.cpp index 1fa82e55034..1032e7fceea 100644 --- a/src/plugins/studiowelcome/qdsnewdialog.cpp +++ b/src/plugins/studiowelcome/qdsnewdialog.cpp @@ -133,6 +133,15 @@ void QdsNewDialog::setProjectLocation(const QString &location) m_wizard.setProjectLocation(m_qmlProjectLocation); } +void QdsNewDialog::setHasCMakeGeneration(bool haveCmakeGen) +{ + if (m_qmlHasCMakeGeneration == haveCmakeGen) + return; + + m_qmlHasCMakeGeneration = haveCmakeGen; + emit hasCMakeGenerationChanged(); +} + void QdsNewDialog::onStatusMessageChanged(Utils::InfoLabel::InfoType type, const QString &message) { switch (type) { @@ -192,9 +201,16 @@ void QdsNewDialog::onWizardCreated(QStandardItemModel *screenSizeModel, QStandar auto userPreset = m_currentPreset->asUserPreset(); if (m_qmlDetailsLoaded) { + setHasCMakeGeneration(m_wizard.hasCMakeGeneration()); + + if (m_currentPreset->isUserPreset()) { + if (getHaveVirtualKeyboard()) + setUseVirtualKeyboard(userPreset->useQtVirtualKeyboard); + if (hasCMakeGeneration()) + setEnableCMakeGeneration(userPreset->enableCMakeGeneration); + } + m_targetQtVersions.clear(); - if (m_currentPreset->isUserPreset() && m_wizard.haveVirtualKeyboard()) - setUseVirtualKeyboard(userPreset->useQtVirtualKeyboard); if (m_wizard.haveTargetQtVersion()) { m_targetQtVersions = m_wizard.targetQtVersionNames(); int index = m_currentPreset->isUserPreset() ? m_wizard.targetQtVersionIndex(userPreset->qtVersion) @@ -227,6 +243,15 @@ void QdsNewDialog::onWizardCreated(QStandardItemModel *screenSizeModel, QStandar } } +void QdsNewDialog::setEnableCMakeGeneration(bool newQmlEnableCMakeGeneration) +{ + if (m_qmlEnableCMakeGeneration == newQmlEnableCMakeGeneration) + return; + + m_qmlEnableCMakeGeneration = newQmlEnableCMakeGeneration; + emit enableCMakeGenerationChanged(); +} + QString QdsNewDialog::currentPresetQmlPath() const { if (!m_currentPreset || m_currentPreset->qmlPath.isEmpty()) @@ -385,6 +410,11 @@ bool QdsNewDialog::getHaveTargetQtVersion() const return m_wizard.haveTargetQtVersion(); } +bool QdsNewDialog::hasCMakeGeneration() const +{ + return m_qmlHasCMakeGeneration; +} + void QdsNewDialog::accept() { CreateProject create{m_wizard}; @@ -395,6 +425,7 @@ void QdsNewDialog::accept() .withScreenSizes(m_qmlScreenSizeIndex, m_qmlCustomWidth, m_qmlCustomHeight) .withStyle(getStyleIndex()) .useQtVirtualKeyboard(m_qmlUseVirtualKeyboard) + .enableCMakeGeneration(m_qmlEnableCMakeGeneration) .saveAsDefaultLocation(m_qmlSaveAsDefaultLocation) .withTargetQtVersion(m_qmlTargetQtVersionIndex) .execute(); @@ -446,6 +477,7 @@ UserPresetData QdsNewDialog::currentUserPresetData(const QString &displayName) c QString targetQtVersion = ""; QString styleName = ""; bool useVirtualKeyboard = false; + bool enableCMakeGeneration = false; if (m_wizard.haveTargetQtVersion()) targetQtVersion = m_wizard.targetQtVersionName(m_qmlTargetQtVersionIndex); @@ -456,13 +488,18 @@ UserPresetData QdsNewDialog::currentUserPresetData(const QString &displayName) c if (m_wizard.haveVirtualKeyboard()) useVirtualKeyboard = m_qmlUseVirtualKeyboard; - UserPresetData preset = {m_currentPreset->categoryId, - m_currentPreset->wizardName, - displayName, - screenSize, - useVirtualKeyboard, - targetQtVersion, - styleName}; + if (m_wizard.hasCMakeGeneration()) + enableCMakeGeneration = m_qmlEnableCMakeGeneration; + + UserPresetData preset{ + m_currentPreset->categoryId, + m_currentPreset->wizardName, + displayName, + screenSize, + useVirtualKeyboard, + enableCMakeGeneration, + targetQtVersion, + styleName}; return preset; } diff --git a/src/plugins/studiowelcome/qdsnewdialog.h b/src/plugins/studiowelcome/qdsnewdialog.h index 95bfa52fe9b..b5aee2ff065 100644 --- a/src/plugins/studiowelcome/qdsnewdialog.h +++ b/src/plugins/studiowelcome/qdsnewdialog.h @@ -34,7 +34,13 @@ public: Q_PROPERTY(QString customHeight MEMBER m_qmlCustomHeight) Q_PROPERTY(int styleIndex MEMBER m_qmlStyleIndex READ getStyleIndex WRITE setStyleIndex) Q_PROPERTY(bool useVirtualKeyboard MEMBER m_qmlUseVirtualKeyboard READ getUseVirtualKeyboard WRITE setUseVirtualKeyboard NOTIFY useVirtualKeyboardChanged) + Q_PROPERTY( + bool enableCMakeGeneration + MEMBER m_qmlEnableCMakeGeneration + WRITE setEnableCMakeGeneration + NOTIFY enableCMakeGenerationChanged) Q_PROPERTY(bool haveVirtualKeyboard MEMBER m_qmlHaveVirtualKeyboard READ getHaveVirtualKeyboard NOTIFY haveVirtualKeyboardChanged) + Q_PROPERTY(bool hasCMakeGeneration READ hasCMakeGeneration NOTIFY hasCMakeGenerationChanged) Q_PROPERTY(bool haveTargetQtVersion MEMBER m_qmlHaveTargetQtVersion READ getHaveTargetQtVersion NOTIFY haveTargetQtVersionChanged) Q_PROPERTY(int targetQtVersionIndex MEMBER m_qmlTargetQtVersionIndex READ getTargetQtVersionIndex WRITE setTargetQtVersionIndex NOTIFY targetQtVersionIndexChanged) Q_PROPERTY(bool saveAsDefaultLocation MEMBER m_qmlSaveAsDefaultLocation WRITE setSaveAsDefaultLocation) @@ -85,12 +91,15 @@ public: bool getFieldsValid() const { return m_qmlFieldsValid; } bool getHaveVirtualKeyboard() const; bool getHaveTargetQtVersion() const; + bool hasCMakeGeneration() const; void setSaveAsDefaultLocation(bool value) { m_qmlSaveAsDefaultLocation = value; } QString getStatusMessage() const { return m_qmlStatusMessage; } QString getStatusType() const { return m_qmlStatusType; } + void setEnableCMakeGeneration(bool newQmlEnableCMakeGeneration); + public slots: void accept(); void reject(); @@ -102,7 +111,9 @@ signals: void projectLocationChanged(); void projectDescriptionChanged(); void useVirtualKeyboardChanged(); + void enableCMakeGenerationChanged(); void haveVirtualKeyboardChanged(); + void hasCMakeGenerationChanged(); void haveTargetQtVersionChanged(); void statusMessageChanged(); void statusTypeChanged(); @@ -129,6 +140,8 @@ private: emit projectDescriptionChanged(); } + void setHasCMakeGeneration(bool haveCmakeGen); + QString projectDescription() const { return m_qmlProjectDescription; } void updateScreenSizes(); @@ -156,7 +169,9 @@ private: // m_qmlStyleIndex is like a cache, so it needs to be updated on get() mutable int m_qmlStyleIndex = -1; bool m_qmlUseVirtualKeyboard = false; + bool m_qmlEnableCMakeGeneration = false; bool m_qmlHaveVirtualKeyboard = false; + bool m_qmlHasCMakeGeneration = false; bool m_qmlHaveTargetQtVersion = false; bool m_qmlSaveAsDefaultLocation = false; bool m_qmlFieldsValid = false; diff --git a/src/plugins/studiowelcome/userpresets.cpp b/src/plugins/studiowelcome/userpresets.cpp index ddc8a406261..cd551f5efe0 100644 --- a/src/plugins/studiowelcome/userpresets.cpp +++ b/src/plugins/studiowelcome/userpresets.cpp @@ -67,13 +67,16 @@ void UserPresetsStore::savePresets(const std::vector &presetItem QJsonArray jsonArray; for (const auto &preset : presetItems) { - QJsonObject obj({{"categoryId", preset.categoryId}, - {"wizardName", preset.wizardName}, - {"name", preset.name}, - {"screenSize", preset.screenSize}, - {"useQtVirtualKeyboard", preset.useQtVirtualKeyboard}, - {"qtVersion", preset.qtVersion}, - {"styleName", preset.styleName}}); + QJsonObject obj{ + {"categoryId", preset.categoryId}, + {"wizardName", preset.wizardName}, + {"name", preset.name}, + {"screenSize", preset.screenSize}, + {"useQtVirtualKeyboard", preset.useQtVirtualKeyboard}, + {"enableCMakeGeneration", preset.enableCMakeGeneration}, + {"qtVersion", preset.qtVersion}, + {"styleName", preset.styleName}, + }; jsonArray.append(QJsonValue{obj}); } @@ -164,6 +167,7 @@ std::vector UserPresetsStore::fetchAll() const preset.name = obj["name"].toString(); preset.screenSize = obj["screenSize"].toString(); preset.useQtVirtualKeyboard = obj["useQtVirtualKeyboard"].toBool(); + preset.enableCMakeGeneration = obj["enableCMakeGeneration"].toBool(); preset.qtVersion = obj["qtVersion"].toString(); preset.styleName = obj["styleName"].toString(); diff --git a/src/plugins/studiowelcome/userpresets.h b/src/plugins/studiowelcome/userpresets.h index 6ea15e8b60f..ae6686279d8 100644 --- a/src/plugins/studiowelcome/userpresets.h +++ b/src/plugins/studiowelcome/userpresets.h @@ -20,6 +20,7 @@ struct UserPresetData QString screenSize; bool useQtVirtualKeyboard; + bool enableCMakeGeneration; QString qtVersion; QString styleName; @@ -36,6 +37,7 @@ inline QDebug &operator<<(QDebug &d, const UserPresetData &preset) d << "UserPreset{category = " << preset.categoryId; d << "; wizardName = " << preset.wizardName; d << "; name = " << preset.name; + d << "; cmakeGeneration = " << preset.enableCMakeGeneration; d << "; screenSize = " << preset.screenSize; d << "; keyboard = " << preset.useQtVirtualKeyboard; d << "; qt = " << preset.qtVersion; @@ -48,9 +50,10 @@ inline QDebug &operator<<(QDebug &d, const UserPresetData &preset) inline bool operator==(const UserPresetData &lhs, const UserPresetData &rhs) { return lhs.categoryId == rhs.categoryId && lhs.wizardName == rhs.wizardName - && lhs.name == rhs.name && lhs.screenSize == rhs.screenSize + && lhs.enableCMakeGeneration == rhs.enableCMakeGeneration && lhs.name == rhs.name + && lhs.screenSize == rhs.screenSize && lhs.useQtVirtualKeyboard == rhs.useQtVirtualKeyboard && lhs.qtVersion == rhs.qtVersion - && lhs.styleName == rhs.styleName;; + && lhs.styleName == rhs.styleName; } enum class StorePolicy {UniqueNames, UniqueValues}; diff --git a/src/plugins/studiowelcome/wizardhandler.cpp b/src/plugins/studiowelcome/wizardhandler.cpp index b86d33a1dfb..a1882f50a2e 100644 --- a/src/plugins/studiowelcome/wizardhandler.cpp +++ b/src/plugins/studiowelcome/wizardhandler.cpp @@ -1,20 +1,21 @@ // Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include -#include - #include "wizardhandler.h" +#include "fieldhelper.h" #include #include - #include #include #include +#include +#include + using namespace StudioWelcome; +using namespace StudioWelcome::FieldHelper; void WizardHandler::reset(const std::shared_ptr &presetInfo, int presetSelection) { @@ -57,8 +58,8 @@ void WizardHandler::setupWizard() emit wizardCreationFailed(); return; } - auto *screenFactorModel = getScreenFactorModel(m_detailsPage); - auto *styleModel = getStyleModel(m_detailsPage); + auto *screenFactorModel = getScreenFactorModel(); + auto *styleModel = getStyleModel(); emit wizardCreated(screenFactorModel, styleModel); } @@ -105,16 +106,9 @@ void WizardHandler::initializeFieldsPage(QWizardPage *page) fieldsPage->initializePage(); } -QStandardItemModel *WizardHandler::getScreenFactorModel(ProjectExplorer::JsonFieldPage *page) +QStandardItemModel *WizardHandler::getScreenFactorModel() { - auto *field = page->jsonField("ScreenFactor"); - if (!field) - return nullptr; - - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return nullptr); - - return cbfield->model(); + return ComboBoxHelper(m_detailsPage, "ScreenFactor").model(); } bool WizardHandler::haveStyleModel() const @@ -122,16 +116,9 @@ bool WizardHandler::haveStyleModel() const return m_wizard->hasField("ControlsStyle"); } -QStandardItemModel *WizardHandler::getStyleModel(ProjectExplorer::JsonFieldPage *page) +QStandardItemModel *WizardHandler::getStyleModel() { - auto *field = page->jsonField("ControlsStyle"); - if (!field) - return nullptr; - - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return nullptr); - - return cbfield->model(); + return ComboBoxHelper(m_detailsPage, "ControlsStyle").model(); } void WizardHandler::onWizardResetting() @@ -147,61 +134,27 @@ void WizardHandler::onWizardResetting() void WizardHandler::setScreenSizeIndex(int index) { - auto *field = m_detailsPage->jsonField("ScreenFactor"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return); - - cbfield->selectRow(index); + ComboBoxHelper(m_detailsPage, "ScreenFactor").selectIndex(index); } QString WizardHandler::screenSizeName(int index) const { - auto *field = m_detailsPage->jsonField("ScreenFactor"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return ""); - - QStandardItemModel *model = cbfield->model(); - if (index < 0 || index >= model->rowCount()) - return {}; - - QString text = model->item(index)->text(); - return text; + return ComboBoxHelper(m_detailsPage, "ScreenFactor").text(index); } int WizardHandler::screenSizeIndex() const { - auto *field = m_detailsPage->jsonField("ScreenFactor"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return -1); - - return cbfield->selectedRow(); + return ComboBoxHelper(m_detailsPage, "ScreenFactor").selectedIndex(); } int WizardHandler::screenSizeIndex(const QString &sizeName) const { - auto *field = m_detailsPage->jsonField("ScreenFactor"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return false); - - const QStandardItemModel *model = cbfield->model(); - for (int i = 0; i < model->rowCount(); ++i) { - const QStandardItem *item = model->item(i, 0); - const QString text = item->text(); - - if (text == sizeName) - return i; - } - - return -1; + return ComboBoxHelper(m_detailsPage, "ScreenFactor").indexOf(sizeName); } void WizardHandler::setTargetQtVersionIndex(int index) { - auto *field = m_detailsPage->jsonField("TargetQtVersion"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return); - - cbfield->selectRow(index); + ComboBoxHelper(m_detailsPage, "TargetQtVersion").selectIndex(index); } bool WizardHandler::haveTargetQtVersion() const @@ -211,117 +164,47 @@ bool WizardHandler::haveTargetQtVersion() const QString WizardHandler::targetQtVersionName(int index) const { - auto *field = m_detailsPage->jsonField("TargetQtVersion"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return ""); - - QStandardItemModel *model = cbfield->model(); - if (index < 0 || index >= model->rowCount()) - return {}; - - QString text = model->item(index)->text(); - return text; + return ComboBoxHelper(m_detailsPage, "TargetQtVersion").text(index); } QStringList WizardHandler::targetQtVersionNames() const { - auto *field = m_detailsPage->jsonField("TargetQtVersion"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return {}); - - QStandardItemModel *model = cbfield->model(); - QStringList targetVersions; - - for (int i = 0; i < model->rowCount(); ++i) - targetVersions.append(model->item(i)->text()); - - return targetVersions; + return ComboBoxHelper(m_detailsPage, "TargetQtVersion").allTexts(); } int WizardHandler::targetQtVersionIndex(const QString &qtVersionName) const { - auto *field = m_detailsPage->jsonField("TargetQtVersion"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return -1); - - const QStandardItemModel *model = cbfield->model(); - for (int i = 0; i < model->rowCount(); ++i) { - const QStandardItem *item = model->item(i, 0); - const QString text = item->text(); - - if (text == qtVersionName) - return i; - } - - return -1; + return ComboBoxHelper(m_detailsPage, "TargetQtVersion").indexOf(qtVersionName); } int WizardHandler::targetQtVersionIndex() const { - auto *field = m_detailsPage->jsonField("TargetQtVersion"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return -1); - - return cbfield->selectedRow(); + return ComboBoxHelper(m_detailsPage, "TargetQtVersion").selectedIndex(); } void WizardHandler::setStyleIndex(int index) { - auto *field = m_detailsPage->jsonField("ControlsStyle"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return); - - cbfield->selectRow(index); + ComboBoxHelper(m_detailsPage, "ControlsStyle").selectIndex(index); } int WizardHandler::styleIndex() const { - auto *field = m_detailsPage->jsonField("ControlsStyle"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return -1); - - return cbfield->selectedRow(); + return ComboBoxHelper(m_detailsPage, "ControlsStyle").selectedIndex(); } int WizardHandler::styleIndex(const QString &styleName) const { - auto *field = m_detailsPage->jsonField("ControlsStyle"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return -1); - - const QStandardItemModel *model = cbfield->model(); - for (int i = 0; i < model->rowCount(); ++i) { - const QStandardItem *item = model->item(i, 0); - const QString text = item->text(); - - if (text == styleName) - return i; - } - - return -1; + return ComboBoxHelper(m_detailsPage, "ControlsStyle").indexOf(styleName); } QString WizardHandler::styleName(int index) const { - auto *field = m_detailsPage->jsonField("ControlsStyle"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return ""); - - QStandardItemModel *model = cbfield->model(); - if (index < 0 || index >= model->rowCount()) - return {}; - - QString text = model->item(index)->text(); - return text; + return ComboBoxHelper(m_detailsPage, "ControlsStyle").text(index); } void WizardHandler::setUseVirtualKeyboard(bool value) { - auto *field = m_detailsPage->jsonField("UseVirtualKeyboard"); - auto *cbfield = dynamic_cast(field); - QTC_ASSERT(cbfield, return); - - cbfield->setChecked(value); + CheckBoxHelper(m_detailsPage, "UseVirtualKeyboard").setChecked(value); } bool WizardHandler::haveVirtualKeyboard() const @@ -329,6 +212,16 @@ bool WizardHandler::haveVirtualKeyboard() const return m_wizard->hasField("UseVirtualKeyboard"); } +void WizardHandler::enableCMakeGeneration(bool value) +{ + CheckBoxHelper(m_detailsPage, "EnableCMakeGeneration").setChecked(value); +} + +bool WizardHandler::hasCMakeGeneration() const +{ + return m_wizard->hasField("EnableCMakeGeneration"); +} + void WizardHandler::run(const std::function &processPage) { m_wizard->restart(); diff --git a/src/plugins/studiowelcome/wizardhandler.h b/src/plugins/studiowelcome/wizardhandler.h index e6009dd9362..640ebb41342 100644 --- a/src/plugins/studiowelcome/wizardhandler.h +++ b/src/plugins/studiowelcome/wizardhandler.h @@ -48,6 +48,9 @@ public: void setUseVirtualKeyboard(bool value); bool haveVirtualKeyboard() const; + void enableCMakeGeneration(bool value); + bool hasCMakeGeneration() const; + void setProjectName(const QString &name); void setProjectLocation(const Utils::FilePath &location); @@ -67,8 +70,8 @@ private: void initializeProjectPage(QWizardPage *page); void initializeFieldsPage(QWizardPage *page); - QStandardItemModel *getScreenFactorModel(ProjectExplorer::JsonFieldPage *page); - QStandardItemModel *getStyleModel(ProjectExplorer::JsonFieldPage *page); + QStandardItemModel *getScreenFactorModel(); + QStandardItemModel *getStyleModel(); private slots: void onWizardResetting();