From e3abd5b3486e117ae1f5880a8304221699f5b14c Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 4 Apr 2020 22:06:27 +0200 Subject: [PATCH] JsonWizard: Fix restoreLastHistoryItem for LineEdit The value was successfully loaded from the history, but overwritten again. Let's now check if the line edit already contains a value (loaded from history) before setting the default text. Change-Id: Ic0acad83f76e0aca76309dfd213183a210d334ac Reviewed-by: Orgad Shaneh Reviewed-by: Christian Kandeler --- .../projectexplorer/jsonwizard/jsonfieldpage.cpp | 13 +++++++++++-- .../projectexplorer/jsonwizard/jsonfieldpage_p.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp index 3b669447f87..5b2b97d43e4 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp @@ -561,7 +561,7 @@ bool LineEditField::validate(MacroExpander *expander, QString *message) m_currentText.clear(); } } else { - w->setText(expander->expand(m_defaultText)); + setDefaultText(w, expander); m_isModified = false; } } else { @@ -579,7 +579,7 @@ void LineEditField::initializeData(MacroExpander *expander) auto w = qobject_cast(widget()); QTC_ASSERT(w, return); m_isValidating = true; - w->setText(expander->expand(m_defaultText)); + setDefaultText(w, expander); w->setPlaceholderText(m_placeholderText); m_isModified = false; m_isValidating = false; @@ -595,6 +595,15 @@ QVariant LineEditField::toSettings() const return qobject_cast(widget())->text(); } +void LineEditField::setDefaultText(FancyLineEdit *edit, MacroExpander *expander) +{ + if (!edit->text().isEmpty()) + return; + + const QString expandedText = expander->expand(m_defaultText); + edit->setText(expandedText); +} + // -------------------------------------------------------------------- // TextEditFieldData: // -------------------------------------------------------------------- diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h index 6e91500b8eb..4a30dae3951 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h @@ -111,6 +111,8 @@ private: void fromSettings(const QVariant &value) override; QVariant toSettings() const override; + void setDefaultText(Utils::FancyLineEdit *edit, Utils::MacroExpander *expander); + bool m_isModified = false; bool m_isValidating = false; bool m_restoreLastHistoryItem = false;