From c2a4bebad4ac1170bf89de5bd18d012b83b27f8a Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Thu, 18 Nov 2021 11:54:49 +0200 Subject: [PATCH] Fix: QDS New Project dialog shows incorrect items in the screen size combobox The index in the backend wizard's combobox was not loaded when initializing the QML combobox. Task-number: QDS-5523 Change-Id: I48583ff1ca85f840e9b7314a4e0ed734364c326a Reviewed-by: Miikka Heikkinen Reviewed-by: Mahmoud Badri --- .../imports/NewProjectDialog/Details.qml | 20 +++++++++++-------- src/plugins/studiowelcome/qdsnewdialog.cpp | 5 +++++ src/plugins/studiowelcome/qdsnewdialog.h | 1 + src/plugins/studiowelcome/wizardhandler.cpp | 9 +++++++++ src/plugins/studiowelcome/wizardhandler.h | 1 + 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml b/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml index 786f17db064..7399db69149 100644 --- a/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml +++ b/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml @@ -192,25 +192,29 @@ Item { SC.ComboBox { // Screen Size ComboBox id: screenSizeComboBox actionIndicatorVisible: false - currentIndex: 1 + currentIndex: -1 model: screenSizeModel textRole: "display" width: parent.width font.pixelSize: DialogValues.defaultPixelSize onActivated: (index) => { - // NOTE: item 0 is activated when the screenSizeModel is reset - dialogBox.setScreenSizeIndex(index); + dialogBox.setScreenSizeIndex(index); - var r = screenSizeModel.screenSizes(index); - widthField.realValue = r.width; - heightField.realValue = r.height; - } + var size = screenSizeModel.screenSizes(index); + widthField.realValue = size.width; + heightField.realValue = size.height; + } Connections { target: screenSizeModel function onModelReset() { - screenSizeComboBox.activated(screenSizeComboBox.currentIndex) + var newIndex = screenSizeComboBox.currentIndex > -1 + ? screenSizeComboBox.currentIndex + : dialogBox.screenSizeIndex() + + screenSizeComboBox.currentIndex = newIndex + screenSizeComboBox.activated(newIndex) } } } // Screen Size ComboBox diff --git a/src/plugins/studiowelcome/qdsnewdialog.cpp b/src/plugins/studiowelcome/qdsnewdialog.cpp index 9afca814dda..62def1d397e 100644 --- a/src/plugins/studiowelcome/qdsnewdialog.cpp +++ b/src/plugins/studiowelcome/qdsnewdialog.cpp @@ -195,6 +195,11 @@ void QdsNewDialog::setScreenSizeIndex(int index) m_qmlScreenSizeIndex = index; } +int QdsNewDialog::screenSizeIndex() const +{ + return m_wizard.screenSizeIndex(); +} + void QdsNewDialog::setTargetQtVersion(int index) { m_wizard.setTargetQtVersionIndex(index); diff --git a/src/plugins/studiowelcome/qdsnewdialog.h b/src/plugins/studiowelcome/qdsnewdialog.h index ede50bc97a7..8e331bd125e 100644 --- a/src/plugins/studiowelcome/qdsnewdialog.h +++ b/src/plugins/studiowelcome/qdsnewdialog.h @@ -66,6 +66,7 @@ public: Q_INVOKABLE QString currentProjectQmlPath() const; Q_INVOKABLE void setScreenSizeIndex(int index); // called when ComboBox item is "activated" + Q_INVOKABLE int screenSizeIndex() const; Q_INVOKABLE void setTargetQtVersion(int index); Q_INVOKABLE QString chooseProjectLocation(); diff --git a/src/plugins/studiowelcome/wizardhandler.cpp b/src/plugins/studiowelcome/wizardhandler.cpp index fce7aa120f9..c8c6c85d12e 100644 --- a/src/plugins/studiowelcome/wizardhandler.cpp +++ b/src/plugins/studiowelcome/wizardhandler.cpp @@ -174,6 +174,15 @@ void WizardHandler::setScreenSizeIndex(int index) cbfield->selectRow(index); } +int WizardHandler::screenSizeIndex() const +{ + auto *field = m_detailsPage->jsonField("ScreenFactor"); + auto *cbfield = dynamic_cast(field); + QTC_ASSERT(cbfield, return -1); + + return cbfield->selectedRow(); +} + void WizardHandler::setTargetQtVersionIndex(int index) { auto *field = m_detailsPage->jsonField("TargetQtVersion"); diff --git a/src/plugins/studiowelcome/wizardhandler.h b/src/plugins/studiowelcome/wizardhandler.h index a828d595f66..ad9424bc441 100644 --- a/src/plugins/studiowelcome/wizardhandler.h +++ b/src/plugins/studiowelcome/wizardhandler.h @@ -50,6 +50,7 @@ public: //TODO: location should not be needed in reset() -- only when creating the project void reset(const ProjectItem &projectInfo, int projectSelection, const Utils::FilePath &location); void setScreenSizeIndex(int index); + int screenSizeIndex() const; void setTargetQtVersionIndex(int index); bool haveTargetQtVersion() const; void setStyleIndex(int index);