forked from qt-creator/qt-creator
Utils: add current index parameter to InfoBarEntry::setComboInfo
Change-Id: I8933d0583846672a6bebdefec402203375e5e09b Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -103,18 +103,20 @@ void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBac
|
|||||||
m_cancelButtonCallBack = callBack;
|
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) {
|
m_comboInfo = Utils::transform(list, [](const QString &string) {
|
||||||
return ComboInfo{string, string};
|
return ComboInfo{string, string};
|
||||||
});
|
});
|
||||||
m_comboCallBack = callBack;
|
m_comboCallBack = callBack;
|
||||||
|
m_currentComboIndex = currentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBarEntry::setComboInfo(const QList<ComboInfo> &list, ComboCallBack callBack)
|
void InfoBarEntry::setComboInfo(const QList<ComboInfo> &list, ComboCallBack callBack, int currentIndex)
|
||||||
{
|
{
|
||||||
m_comboCallBack = callBack;
|
m_comboCallBack = callBack;
|
||||||
m_comboInfo = list;
|
m_comboInfo = list;
|
||||||
|
m_currentComboIndex = currentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBarEntry::removeCancelButton()
|
void InfoBarEntry::removeCancelButton()
|
||||||
@@ -318,6 +320,8 @@ void InfoBarDisplay::update()
|
|||||||
auto cb = new QComboBox();
|
auto cb = new QComboBox();
|
||||||
for (const InfoBarEntry::ComboInfo &comboInfo : qAsConst(info.m_comboInfo))
|
for (const InfoBarEntry::ComboInfo &comboInfo : qAsConst(info.m_comboInfo))
|
||||||
cb->addItem(comboInfo.displayText, comboInfo.data);
|
cb->addItem(comboInfo.displayText, comboInfo.data);
|
||||||
|
if (info.m_currentComboIndex >= 0 && info.m_currentComboIndex < cb->count())
|
||||||
|
cb->setCurrentIndex(info.m_currentComboIndex);
|
||||||
connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), [cb, info]() {
|
connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), [cb, info]() {
|
||||||
info.m_comboCallBack({cb->currentText(), cb->currentData()});
|
info.m_comboCallBack({cb->currentText(), cb->currentData()});
|
||||||
});
|
});
|
||||||
|
@@ -66,8 +66,8 @@ public:
|
|||||||
QVariant data;
|
QVariant data;
|
||||||
};
|
};
|
||||||
using ComboCallBack = std::function<void(const ComboInfo &)>;
|
using ComboCallBack = std::function<void(const ComboInfo &)>;
|
||||||
void setComboInfo(const QStringList &list, ComboCallBack callBack);
|
void setComboInfo(const QStringList &list, ComboCallBack callBack, int currentIndex = -1);
|
||||||
void setComboInfo(const QList<ComboInfo> &infos, ComboCallBack callBack);
|
void setComboInfo(const QList<ComboInfo> &infos, ComboCallBack callBack, int currentIndex = -1);
|
||||||
void removeCancelButton();
|
void removeCancelButton();
|
||||||
|
|
||||||
using DetailsWidgetCreator = std::function<QWidget*()>;
|
using DetailsWidgetCreator = std::function<QWidget*()>;
|
||||||
@@ -90,6 +90,7 @@ private:
|
|||||||
bool m_useCancelButton = true;
|
bool m_useCancelButton = true;
|
||||||
ComboCallBack m_comboCallBack;
|
ComboCallBack m_comboCallBack;
|
||||||
QList<ComboInfo> m_comboInfo;
|
QList<ComboInfo> m_comboInfo;
|
||||||
|
int m_currentComboIndex = -1;
|
||||||
friend class InfoBar;
|
friend class InfoBar;
|
||||||
friend class InfoBarDisplay;
|
friend class InfoBarDisplay;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user