From be0b962ce8b418cdeefde39bf9b971449bdf1b38 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 23 Mar 2022 10:04:07 +0100 Subject: [PATCH] Utils: add current index parameter to InfoBarEntry::setComboInfo Change-Id: I8933d0583846672a6bebdefec402203375e5e09b Reviewed-by: Eike Ziller --- src/libs/utils/infobar.cpp | 8 ++++++-- src/libs/utils/infobar.h | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/infobar.cpp b/src/libs/utils/infobar.cpp index efe1268f5d4..68f9a43643a 100644 --- a/src/libs/utils/infobar.cpp +++ b/src/libs/utils/infobar.cpp @@ -103,18 +103,20 @@ void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBac m_cancelButtonCallBack = callBack; } -void InfoBarEntry::setComboInfo(const QStringList &list, ComboCallBack callBack) +void InfoBarEntry::setComboInfo(const QStringList &list, ComboCallBack callBack, int currentIndex) { m_comboInfo = Utils::transform(list, [](const QString &string) { return ComboInfo{string, string}; }); m_comboCallBack = callBack; + m_currentComboIndex = currentIndex; } -void InfoBarEntry::setComboInfo(const QList &list, ComboCallBack callBack) +void InfoBarEntry::setComboInfo(const QList &list, ComboCallBack callBack, int currentIndex) { m_comboCallBack = callBack; m_comboInfo = list; + m_currentComboIndex = currentIndex; } void InfoBarEntry::removeCancelButton() @@ -318,6 +320,8 @@ void InfoBarDisplay::update() auto cb = new QComboBox(); for (const InfoBarEntry::ComboInfo &comboInfo : qAsConst(info.m_comboInfo)) cb->addItem(comboInfo.displayText, comboInfo.data); + if (info.m_currentComboIndex >= 0 && info.m_currentComboIndex < cb->count()) + cb->setCurrentIndex(info.m_currentComboIndex); connect(cb, QOverload::of(&QComboBox::currentIndexChanged), [cb, info]() { info.m_comboCallBack({cb->currentText(), cb->currentData()}); }); diff --git a/src/libs/utils/infobar.h b/src/libs/utils/infobar.h index d2196d9db8a..ca3037fabf6 100644 --- a/src/libs/utils/infobar.h +++ b/src/libs/utils/infobar.h @@ -66,8 +66,8 @@ public: QVariant data; }; using ComboCallBack = std::function; - void setComboInfo(const QStringList &list, ComboCallBack callBack); - void setComboInfo(const QList &infos, ComboCallBack callBack); + void setComboInfo(const QStringList &list, ComboCallBack callBack, int currentIndex = -1); + void setComboInfo(const QList &infos, ComboCallBack callBack, int currentIndex = -1); void removeCancelButton(); using DetailsWidgetCreator = std::function; @@ -90,6 +90,7 @@ private: bool m_useCancelButton = true; ComboCallBack m_comboCallBack; QList m_comboInfo; + int m_currentComboIndex = -1; friend class InfoBar; friend class InfoBarDisplay; };