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 <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2019-10-28 12:09:32 +01:00
parent 6b17cd91a6
commit 0d81e90bb1
2 changed files with 11 additions and 6 deletions

View File

@@ -1116,11 +1116,8 @@ void ComboBoxField::setup(JsonFieldPage *page, const QString &name)
selectionModel()->blockSignals(true); selectionModel()->blockSignals(true);
w->blockSignals(false); w->blockSignals(false);
}); });
page->registerObjectAsFieldWithName<QItemSelectionModel>(name, selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { page->registerObjectAsFieldWithName<QComboBox>(name, w, QOverload<int>::of(&QComboBox::activated), [w]() {
const QModelIndex i = selectionModel()->currentIndex(); return w->currentData(ValueRole);
if (i.isValid())
return i.data(ValueRole);
return QVariant();
}); });
QObject::connect(selectionModel(), &QItemSelectionModel::selectionChanged, page, [page]() { QObject::connect(selectionModel(), &QItemSelectionModel::selectionChanged, page, [page]() {
emit page->completeChanged(); emit page->completeChanged();
@@ -1143,6 +1140,13 @@ void ComboBoxField::initializeData(MacroExpander *expander)
w->setCurrentIndex(selectionModel()->currentIndex().row()); w->setCurrentIndex(selectionModel()->currentIndex().row());
} }
QVariant ComboBoxField::toSettings() const
{
if (auto w = qobject_cast<QComboBox*>(widget()))
return w->currentData(ValueRole);
return {};
}
void IconListField::setup(JsonFieldPage *page, const QString &name) void IconListField::setup(JsonFieldPage *page, const QString &name)
{ {
auto w = qobject_cast<QListView*>(widget()); auto w = qobject_cast<QListView*>(widget());

View File

@@ -236,10 +236,11 @@ private:
class ComboBoxField : public ListField class ComboBoxField : public ListField
{ {
public: private:
void setup(JsonFieldPage *page, const QString &name) override; void setup(JsonFieldPage *page, const QString &name) override;
QWidget *createWidget(const QString &displayName, JsonFieldPage *page) override; QWidget *createWidget(const QString &displayName, JsonFieldPage *page) override;
void initializeData(Utils::MacroExpander *expander) override; void initializeData(Utils::MacroExpander *expander) override;
QVariant toSettings() const override;
}; };
class IconListField : public ListField class IconListField : public ListField