forked from qt-creator/qt-creator
Core: add combo info to info bar entry
This allows user to show a combo box for a stringlist. Every time the user changes the selection a callback is called. Change-Id: I27e16843465e6006cccdc3502e76be852b584dfa Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QComboBox>
|
||||
|
||||
static const char C_SUPPRESSED_WARNINGS[] = "SuppressedWarnings";
|
||||
|
||||
@@ -73,6 +74,12 @@ void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBac
|
||||
m_cancelButtonCallBack = callBack;
|
||||
}
|
||||
|
||||
void InfoBarEntry::setComboInfo(const QStringList &list, InfoBarEntry::ComboCallBack callBack)
|
||||
{
|
||||
m_comboCallBack = callBack;
|
||||
m_comboInfo = list;
|
||||
}
|
||||
|
||||
void InfoBarEntry::removeCancelButton()
|
||||
{
|
||||
m_useCancelButton = false;
|
||||
@@ -242,7 +249,7 @@ void InfoBarDisplay::update()
|
||||
|
||||
QLabel *infoWidgetLabel = new QLabel(info.m_infoText);
|
||||
infoWidgetLabel->setWordWrap(true);
|
||||
hbox->addWidget(infoWidgetLabel);
|
||||
hbox->addWidget(infoWidgetLabel, 1);
|
||||
|
||||
if (info.m_detailsWidgetCreator) {
|
||||
if (m_isShowingDetailsWidget) {
|
||||
@@ -270,6 +277,16 @@ void InfoBarDisplay::update()
|
||||
m_isShowingDetailsWidget = false;
|
||||
}
|
||||
|
||||
if (!info.m_comboInfo.isEmpty()) {
|
||||
auto cb = new QComboBox();
|
||||
cb->addItems(info.m_comboInfo);
|
||||
connect(cb, &QComboBox::currentTextChanged, [info](const QString &text) {
|
||||
info.m_comboCallBack(text);
|
||||
});
|
||||
|
||||
hbox->addWidget(cb);
|
||||
}
|
||||
|
||||
if (!info.m_buttonText.isEmpty()) {
|
||||
auto infoWidgetButton = new QToolButton;
|
||||
infoWidgetButton->setText(info.m_buttonText);
|
||||
|
@@ -61,6 +61,8 @@ public:
|
||||
void setCustomButtonInfo(const QString &_buttonText, CallBack callBack);
|
||||
void setCancelButtonInfo(CallBack callBack);
|
||||
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
|
||||
using ComboCallBack = std::function<void(const QString &)>;
|
||||
void setComboInfo(const QStringList &list, ComboCallBack callBack);
|
||||
void removeCancelButton();
|
||||
|
||||
using DetailsWidgetCreator = std::function<QWidget*()>;
|
||||
@@ -76,6 +78,8 @@ private:
|
||||
GlobalSuppressionMode m_globalSuppression;
|
||||
DetailsWidgetCreator m_detailsWidgetCreator;
|
||||
bool m_useCancelButton = true;
|
||||
ComboCallBack m_comboCallBack;
|
||||
QStringList m_comboInfo;
|
||||
friend class InfoBar;
|
||||
friend class InfoBarDisplay;
|
||||
};
|
||||
|
Reference in New Issue
Block a user