Utils: add tooltip parameter for info bar controls

Change-Id: I395dea4240d09b3721a24e04016c6db4076449b5
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2022-03-25 07:50:35 +01:00
parent 5924716e21
commit b165e5f0ad
2 changed files with 38 additions and 21 deletions

View File

@@ -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<ComboInfo> &list, ComboCallBack callBack, int currentIndex)
void InfoBarEntry::setComboInfo(const QList<ComboInfo> &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<int>::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);
}

View File

@@ -57,7 +57,7 @@ public:
InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression = GlobalSuppression::Disabled);
using CallBack = std::function<void()>;
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(const ComboInfo &)>;
void setComboInfo(const QStringList &list, ComboCallBack callBack, int currentIndex = -1);
void setComboInfo(const QList<ComboInfo> &infos, ComboCallBack callBack, int currentIndex = -1);
void setComboInfo(const QStringList &list, ComboCallBack callBack, const QString &tooltip = {}, int currentIndex = -1);
void setComboInfo(const QList<ComboInfo> &infos, ComboCallBack callBack, const QString &tooltip = {}, int currentIndex = -1);
void removeCancelButton();
using DetailsWidgetCreator = std::function<QWidget*()>;
@@ -78,6 +78,15 @@ private:
{
QString text;
CallBack callback;
QString tooltip;
};
struct Combo
{
ComboCallBack callback;
QList<ComboInfo> 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<ComboInfo> m_comboInfo;
int m_currentComboIndex = -1;
Combo m_combo;
friend class InfoBar;
friend class InfoBarDisplay;
};