QmlDesigner: Load the value from wizard if preset is not available

If the user preset is not available, we should load the resolved
default values from the wizard.

The patch enables the loading for the following parameters:
    1. UseVirtualKeyboard
    2. EnableCMakeGeneration
    3. styleName

Fixes: QDS-13946
Fixes: QDS-13949
Change-Id: I8ad122eec1d14abd95762922cd5955b3af01b154
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Ali Kianian
2024-12-30 15:59:28 +02:00
parent d611782566
commit e185f9d49a
7 changed files with 44 additions and 3 deletions

View File

@@ -931,6 +931,14 @@ void CheckBoxField::setChecked(bool value)
emit w->clicked(value);
}
bool CheckBoxField::isChecked() const
{
auto w = qobject_cast<QCheckBox *>(widget());
QTC_ASSERT(w, return false);
return w->isChecked();
}
bool CheckBoxField::validate(MacroExpander *expander, QString *message)
{
if (!JsonFieldPage::Field::validate(expander, message))

View File

@@ -215,6 +215,7 @@ public:
bool suppressName() const override { return true; }
void setChecked(bool);
bool isChecked() const;
private:
bool parseData(const QVariant &data, QString *errorMessage) override;

View File

@@ -21,6 +21,12 @@ void CheckBoxHelper::setChecked(bool value)
m_field->setChecked(value);
}
bool CheckBoxHelper::isChecked() const
{
QTC_ASSERT(m_field, return false);
return m_field->isChecked();
}
ComboBoxHelper::ComboBoxHelper(ProjectExplorer::JsonFieldPage *detailsPage, const QString &fieldName)
: m_field(dynamic_cast<ProjectExplorer::ComboBoxField *>(detailsPage->jsonField(fieldName)))
{}

View File

@@ -21,6 +21,7 @@ public:
CheckBoxHelper(ProjectExplorer::JsonFieldPage *detailsPage, const QString &fieldName);
void setChecked(bool value);
bool isChecked() const;
private:
ProjectExplorer::CheckBoxField *m_field = nullptr;

View File

@@ -205,6 +205,13 @@ void QdsNewDialog::onWizardCreated(QStandardItemModel *screenSizeModel, QStandar
setEnableCMakeGeneration(userPreset->enableCMakeGeneration);
setStyleName(userPreset->styleName);
} else {
if (getHaveVirtualKeyboard())
setUseVirtualKeyboard(m_wizard.virtualKeyboardUsed());
if (hasCMakeGeneration())
setEnableCMakeGeneration(m_wizard.cmakeGenerationEnabled());
setStyleName(m_wizard.styleName());
}
m_targetQtVersions.clear();
@@ -440,7 +447,7 @@ UserPresetData QdsNewDialog::currentUserPresetData(const QString &displayName) c
targetQtVersion = m_wizard.targetQtVersionName(m_qmlTargetQtVersionIndex);
if (m_wizard.haveStyleModel())
styleName = m_wizard.styleName(getStyleIndex());
styleName = m_wizard.styleNameAt(getStyleIndex());
if (m_wizard.haveVirtualKeyboard())
useVirtualKeyboard = m_qmlUseVirtualKeyboard;

View File

@@ -197,11 +197,16 @@ int WizardHandler::styleIndex(const QString &styleName) const
return ComboBoxHelper(m_detailsPage, "ControlsStyle").indexOf(styleName);
}
QString WizardHandler::styleName(int index) const
QString WizardHandler::styleNameAt(int index) const
{
return ComboBoxHelper(m_detailsPage, "ControlsStyle").text(index);
}
QString WizardHandler::styleName() const
{
return styleNameAt(styleIndex());
}
void WizardHandler::setUseVirtualKeyboard(bool value)
{
CheckBoxHelper(m_detailsPage, "UseVirtualKeyboard").setChecked(value);
@@ -212,6 +217,11 @@ bool WizardHandler::haveVirtualKeyboard() const
return m_wizard->hasField("UseVirtualKeyboard");
}
bool WizardHandler::virtualKeyboardUsed() const
{
return CheckBoxHelper(m_detailsPage, "UseVirtualKeyboard").isChecked();
}
void WizardHandler::enableCMakeGeneration(bool value)
{
CheckBoxHelper(m_detailsPage, "EnableCMakeGeneration").setChecked(value);
@@ -222,6 +232,11 @@ bool WizardHandler::hasCMakeGeneration() const
return m_wizard->hasField("EnableCMakeGeneration");
}
bool WizardHandler::cmakeGenerationEnabled() const
{
return CheckBoxHelper(m_detailsPage, "EnableCMakeGeneration").isChecked();
}
void WizardHandler::run(const std::function<void(QWizardPage *)> &processPage)
{
m_wizard->restart();

View File

@@ -40,16 +40,19 @@ public:
void setStyleIndex(int index);
int styleIndex() const;
int styleIndex(const QString &styleName) const;
QString styleName(int index) const;
QString styleNameAt(int index) const;
QString styleName() const;
bool haveStyleModel() const;
void destroyWizard();
void setUseVirtualKeyboard(bool value);
bool haveVirtualKeyboard() const;
bool virtualKeyboardUsed() const;
void enableCMakeGeneration(bool value);
bool hasCMakeGeneration() const;
bool cmakeGenerationEnabled() const;
void setProjectName(const QString &name);
void setProjectLocation(const Utils::FilePath &location);