From 0d81e90bb1f4f4d20feed6a9afcab6861d0447a1 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 28 Oct 2019 12:09:32 +0100 Subject: [PATCH] Wizards: Fix ComboBox implementation The ComboBoxField class used the QComboBox view's selection model as the source for the current value, which makes no sense, as the item that was last selected was not necessarily activated by the user. Fixes: QTCREATORBUG-23149 Change-Id: I8587dd20381e142b91f13a987e54c86b8f6237c8 Reviewed-by: Eike Ziller --- .../projectexplorer/jsonwizard/jsonfieldpage.cpp | 14 +++++++++----- .../projectexplorer/jsonwizard/jsonfieldpage_p.h | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp index 432a22fec1c..956b5f2109b 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp @@ -1116,11 +1116,8 @@ void ComboBoxField::setup(JsonFieldPage *page, const QString &name) selectionModel()->blockSignals(true); w->blockSignals(false); }); - page->registerObjectAsFieldWithName(name, selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { - const QModelIndex i = selectionModel()->currentIndex(); - if (i.isValid()) - return i.data(ValueRole); - return QVariant(); + page->registerObjectAsFieldWithName(name, w, QOverload::of(&QComboBox::activated), [w]() { + return w->currentData(ValueRole); }); QObject::connect(selectionModel(), &QItemSelectionModel::selectionChanged, page, [page]() { emit page->completeChanged(); @@ -1143,6 +1140,13 @@ void ComboBoxField::initializeData(MacroExpander *expander) w->setCurrentIndex(selectionModel()->currentIndex().row()); } +QVariant ComboBoxField::toSettings() const +{ + if (auto w = qobject_cast(widget())) + return w->currentData(ValueRole); + return {}; +} + void IconListField::setup(JsonFieldPage *page, const QString &name) { auto w = qobject_cast(widget()); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h index 62db37aff65..6e91500b8eb 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h @@ -236,10 +236,11 @@ private: class ComboBoxField : public ListField { -public: +private: void setup(JsonFieldPage *page, const QString &name) override; QWidget *createWidget(const QString &displayName, JsonFieldPage *page) override; void initializeData(Utils::MacroExpander *expander) override; + QVariant toSettings() const override; }; class IconListField : public ListField