diff --git a/src/libs/utils/infobar.cpp b/src/libs/utils/infobar.cpp index 694709ad5f0..cb416715725 100644 --- a/src/libs/utils/infobar.cpp +++ b/src/libs/utils/infobar.cpp @@ -85,9 +85,11 @@ InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _ { } -void InfoBarEntry::addCustomButton(const QString &buttonText, CallBack callBack) +void InfoBarEntry::addCustomButton(const QString &buttonText, + CallBack callBack, + const QString &tooltip) { - m_buttons.append({buttonText, callBack}); + m_buttons.append({buttonText, callBack, tooltip}); } void InfoBarEntry::setCancelButtonInfo(CallBack callBack) @@ -103,20 +105,26 @@ void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBac m_cancelButtonCallBack = callBack; } -void InfoBarEntry::setComboInfo(const QStringList &list, ComboCallBack callBack, int currentIndex) +void InfoBarEntry::setComboInfo(const QStringList &list, + ComboCallBack callBack, + const QString &tooltip, + int currentIndex) { - m_comboInfo = Utils::transform(list, [](const QString &string) { + auto comboInfos = Utils::transform(list, [](const QString &string) { return ComboInfo{string, string}; }); - m_comboCallBack = callBack; - m_currentComboIndex = currentIndex; + setComboInfo(comboInfos, callBack, tooltip, currentIndex); } -void InfoBarEntry::setComboInfo(const QList &list, ComboCallBack callBack, int currentIndex) +void InfoBarEntry::setComboInfo(const QList &list, + ComboCallBack callBack, + const QString &tooltip, + int currentIndex) { - m_comboCallBack = callBack; - m_comboInfo = list; - m_currentComboIndex = currentIndex; + m_combo.entries = list; + m_combo.callback = callBack; + m_combo.tooltip = tooltip; + m_combo.currentIndex = currentIndex; } void InfoBarEntry::removeCancelButton() @@ -316,14 +324,15 @@ void InfoBarDisplay::update() m_isShowingDetailsWidget = false; } - if (!info.m_comboInfo.isEmpty()) { + if (!info.m_combo.entries.isEmpty()) { auto cb = new QComboBox(); - for (const InfoBarEntry::ComboInfo &comboInfo : qAsConst(info.m_comboInfo)) + cb->setToolTip(info.m_combo.tooltip); + for (const InfoBarEntry::ComboInfo &comboInfo : qAsConst(info.m_combo.entries)) cb->addItem(comboInfo.displayText, comboInfo.data); - if (info.m_currentComboIndex >= 0 && info.m_currentComboIndex < cb->count()) - cb->setCurrentIndex(info.m_currentComboIndex); + if (info.m_combo.currentIndex >= 0 && info.m_combo.currentIndex < cb->count()) + cb->setCurrentIndex(info.m_combo.currentIndex); connect(cb, QOverload::of(&QComboBox::currentIndexChanged), this, [cb, info]() { - info.m_comboCallBack({cb->currentText(), cb->currentData()}); + info.m_combo.callback({cb->currentText(), cb->currentData()}); }, Qt::QueuedConnection); hbox->addWidget(cb); @@ -332,6 +341,7 @@ void InfoBarDisplay::update() for (const InfoBarEntry::Button &button : qAsConst(info.m_buttons)) { auto infoWidgetButton = new QToolButton; infoWidgetButton->setText(button.text); + infoWidgetButton->setToolTip(button.tooltip); connect(infoWidgetButton, &QAbstractButton::clicked, [button]() { button.callback(); }); hbox->addWidget(infoWidgetButton); } diff --git a/src/libs/utils/infobar.h b/src/libs/utils/infobar.h index ca3037fabf6..d6562b8b59f 100644 --- a/src/libs/utils/infobar.h +++ b/src/libs/utils/infobar.h @@ -57,7 +57,7 @@ public: InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression = GlobalSuppression::Disabled); using CallBack = std::function; - void addCustomButton(const QString &_buttonText, CallBack callBack); + void addCustomButton(const QString &_buttonText, CallBack callBack, const QString &tooltip = {}); void setCancelButtonInfo(CallBack callBack); void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack); struct ComboInfo @@ -66,8 +66,8 @@ public: QVariant data; }; using ComboCallBack = std::function; - void setComboInfo(const QStringList &list, ComboCallBack callBack, int currentIndex = -1); - void setComboInfo(const QList &infos, ComboCallBack callBack, int currentIndex = -1); + void setComboInfo(const QStringList &list, ComboCallBack callBack, const QString &tooltip = {}, int currentIndex = -1); + void setComboInfo(const QList &infos, ComboCallBack callBack, const QString &tooltip = {}, int currentIndex = -1); void removeCancelButton(); using DetailsWidgetCreator = std::function; @@ -78,6 +78,15 @@ private: { QString text; CallBack callback; + QString tooltip; + }; + + struct Combo + { + ComboCallBack callback; + QList entries; + QString tooltip; + int currentIndex = -1; }; Id m_id; @@ -88,9 +97,7 @@ private: GlobalSuppression m_globalSuppression; DetailsWidgetCreator m_detailsWidgetCreator; bool m_useCancelButton = true; - ComboCallBack m_comboCallBack; - QList m_comboInfo; - int m_currentComboIndex = -1; + Combo m_combo; friend class InfoBar; friend class InfoBarDisplay; };