diff options
author | Samuel Ghinet <samuel.ghinet@qt.io> | 2022-01-17 13:24:05 +0200 |
---|---|---|
committer | Samuel Ghinet <samuel.ghinet@qt.io> | 2022-01-20 08:56:08 +0000 |
commit | d023dfca1e93e0945a1cd2477540873b1aa86277 (patch) | |
tree | 5a3b46ee49511010a016460f1153d9476310e1cf | |
parent | f708e0e70c144400f5582dacd6123c4f3cf777cc (diff) | |
download | qt-creator-d023dfca1e93e0945a1cd2477540873b1aa86277.tar.gz |
Fix creating a project from a Recent preset with custom size
When creating a project from a Recent preset, everything worked well if
the user selected a predefined size. However, when typing a custom width
and custom height, the recent was saved with the selected/active item in
the screen size combobox.
This patch does the following to fix the issue:
* Save the recent info with the screen size written in the text fields
(since they're updated when the user selects a different size from
combobox but the user can type in any other value, the text fields
always reflect the user's choice of width and height)
* When loading a preset for display in the UI, if the preset was saved
with a custom size that does not exist in the predefined list (i.e. in
the combobox), whether that is a custom size or a different
orientation of a predefined size, then append an item into the screen
size combobox so that this custom size will appear as one of the
predefined sizes for the preset. This is both for visual reasons (so
that the combobox would have a valid item active on display) and in
order to be able to save in the backend model this choice (when the
user decides to create the project)
* Update the ListField::selectRow function so that it does not attempt
to select an item that does not exist. The reason is that, when the
user clicks "Create" to create the project, the QWizard will be reset
to the first page, and any modification we might have made to the
model of the screen size combobox will be gone - and thus the
selection would be invalid, which would normally cause the wizard to
fail on page->isComplete(). By not allowing it to select an item in
this case, we rely on the custom width and custom height fields to
hold the real values.
Task-number: QDS-5691
Change-Id: I9e848c5f4957252eb414da7e7146f9f8e7be760c
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r-- | src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp | 15 | ||||
-rw-r--r-- | src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h | 4 | ||||
-rw-r--r-- | src/plugins/studiowelcome/createproject.cpp | 1 | ||||
-rw-r--r-- | src/plugins/studiowelcome/qdsnewdialog.cpp | 29 | ||||
-rw-r--r-- | src/plugins/studiowelcome/qdsnewdialog.h | 2 | ||||
-rw-r--r-- | src/plugins/studiowelcome/screensizemodel.h | 6 |
6 files changed, 39 insertions, 18 deletions
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp index d6080f4e90..393f6840c9 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp @@ -1157,12 +1157,16 @@ QStandardItemModel *ListField::itemModel() return m_itemModel; } -void ListField::selectRow(int row) +bool ListField::selectRow(int row) { - auto index = itemModel()->index(row, 0); + QModelIndex index = itemModel()->index(row, 0); + if (!index.isValid()) + return false; + selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); this->updateIndex(); + return true; } QItemSelectionModel *ListField::selectionModel() const @@ -1271,12 +1275,15 @@ QVariant ComboBoxField::toSettings() const return {}; } -void ComboBoxField::selectRow(int row) +bool ComboBoxField::selectRow(int row) { - ListField::selectRow(row); + if (!ListField::selectRow(row)) + return false; auto w = qobject_cast<QComboBox *>(widget()); w->setCurrentIndex(row); + + return true; } int ComboBoxField::selectedRow() const diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h index ed89746d0b..db8a1b06fb 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h @@ -282,7 +282,7 @@ public: ~ListField() override; QStandardItemModel *model() { return m_itemModel; } - virtual void selectRow(int row); + virtual bool selectRow(int row); protected: bool parseData(const QVariant &data, QString *errorMessage) override; @@ -351,7 +351,7 @@ private: } public: - void selectRow(int row) override; + bool selectRow(int row) override; int selectedRow() const; }; diff --git a/src/plugins/studiowelcome/createproject.cpp b/src/plugins/studiowelcome/createproject.cpp index 1b6dd93e9d..ce3b83945f 100644 --- a/src/plugins/studiowelcome/createproject.cpp +++ b/src/plugins/studiowelcome/createproject.cpp @@ -68,6 +68,7 @@ void CreateProject::processFieldPage(ProjectExplorer::JsonFieldPage *page) auto widthField = dynamic_cast<ProjectExplorer::LineEditField *>(page->jsonField("CustomScreenWidth")); auto heightField = dynamic_cast<ProjectExplorer::LineEditField *>(page->jsonField("CustomScreenHeight")); + // TODO: use m_wizard to set these text items? if (widthField && heightField) { if (!m_customWidth.isEmpty() && !m_customHeight.isEmpty()) { widthField->setText(m_customWidth); diff --git a/src/plugins/studiowelcome/qdsnewdialog.cpp b/src/plugins/studiowelcome/qdsnewdialog.cpp index 83a966caeb..0324a7de93 100644 --- a/src/plugins/studiowelcome/qdsnewdialog.cpp +++ b/src/plugins/studiowelcome/qdsnewdialog.cpp @@ -170,17 +170,26 @@ void QdsNewDialog::onProjectCanBeCreatedChanged(bool value) emit fieldsValidChanged(); } +void QdsNewDialog::updateScreenSizes() +{ + int index = m_wizard.screenSizeIndex(m_currentPreset->screenSizeName); + if (index > -1) { + setScreenSizeIndex(index); + } else { + index = m_screenSizeModel->appendItem(m_currentPreset->screenSizeName); + setScreenSizeIndex(index); + } + + m_screenSizeModel->reset(); +} + void QdsNewDialog::onWizardCreated(QStandardItemModel *screenSizeModel, QStandardItemModel *styleModel) { m_screenSizeModel->setBackendModel(screenSizeModel); m_styleModel->setBackendModel(styleModel); if (m_qmlDetailsLoaded) { - int index = m_wizard.screenSizeIndex(m_currentPreset->screenSizeName); - if (index > -1) - setScreenSizeIndex(index); - - m_screenSizeModel->reset(); + updateScreenSizes(); emit haveVirtualKeyboardChanged(); emit haveTargetQtVersionChanged(); @@ -288,11 +297,7 @@ void QdsNewDialog::setWizardFactories(QList<Core::IWizardFactory *> factories_, emit projectLocationChanged(); // So that QML knows to update the field if (m_qmlDetailsLoaded) { - int index = m_wizard.screenSizeIndex(m_currentPreset->screenSizeName); - if (index > -1) - setScreenSizeIndex(index); - - m_screenSizeModel->reset(); + updateScreenSizes(); } if (m_qmlStylesLoaded) @@ -334,9 +339,9 @@ void QdsNewDialog::accept() .execute(); PresetItem item = m_wizard.preset(); - QString screenSize = m_wizard.screenSizeName(m_qmlScreenSizeIndex); + QString customSizeName = m_qmlCustomWidth + " x " + m_qmlCustomHeight; - m_recentsStore.add(item.categoryId, item.name, screenSize); + m_recentsStore.add(item.categoryId, item.name, customSizeName); m_dialog->close(); m_dialog->deleteLater(); diff --git a/src/plugins/studiowelcome/qdsnewdialog.h b/src/plugins/studiowelcome/qdsnewdialog.h index 476750e540..a4afa69e92 100644 --- a/src/plugins/studiowelcome/qdsnewdialog.h +++ b/src/plugins/studiowelcome/qdsnewdialog.h @@ -131,6 +131,8 @@ private: QString projectDescription() const { return m_qmlProjectDescription; } + void updateScreenSizes(); + private slots: void onDeletingWizard(); void onWizardCreated(QStandardItemModel *screenSizeModel, QStandardItemModel *styleModel); diff --git a/src/plugins/studiowelcome/screensizemodel.h b/src/plugins/studiowelcome/screensizemodel.h index 597811146e..0bde90c269 100644 --- a/src/plugins/studiowelcome/screensizemodel.h +++ b/src/plugins/studiowelcome/screensizemodel.h @@ -87,6 +87,12 @@ public: return {}; } + int appendItem(const QString &text) + { + m_backendModel->appendRow(new QStandardItem{text}); + return rowCount(QModelIndex{}) - 1; + } + QHash<int, QByteArray> roleNames() const override { if (m_backendModel) |