forked from qt-creator/qt-creator
Utils: allow passing data via info bar combo box
Change-Id: I47daa83a533a76eb4ad0ab3f5cf8c04faf389b98 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -103,7 +103,15 @@ void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBac
|
|||||||
m_cancelButtonCallBack = callBack;
|
m_cancelButtonCallBack = callBack;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBarEntry::setComboInfo(const QStringList &list, InfoBarEntry::ComboCallBack callBack)
|
void InfoBarEntry::setComboInfo(const QStringList &list, ComboCallBack callBack)
|
||||||
|
{
|
||||||
|
m_comboInfo = Utils::transform(list, [](const QString &string) {
|
||||||
|
return ComboInfo{string, string};
|
||||||
|
});
|
||||||
|
m_comboCallBack = callBack;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InfoBarEntry::setComboInfo(const QList<ComboInfo> &list, ComboCallBack callBack)
|
||||||
{
|
{
|
||||||
m_comboCallBack = callBack;
|
m_comboCallBack = callBack;
|
||||||
m_comboInfo = list;
|
m_comboInfo = list;
|
||||||
@@ -308,9 +316,10 @@ void InfoBarDisplay::update()
|
|||||||
|
|
||||||
if (!info.m_comboInfo.isEmpty()) {
|
if (!info.m_comboInfo.isEmpty()) {
|
||||||
auto cb = new QComboBox();
|
auto cb = new QComboBox();
|
||||||
cb->addItems(info.m_comboInfo);
|
for (const InfoBarEntry::ComboInfo &comboInfo : qAsConst(info.m_comboInfo))
|
||||||
connect(cb, &QComboBox::currentTextChanged, [info](const QString &text) {
|
cb->addItem(comboInfo.displayText, comboInfo.data);
|
||||||
info.m_comboCallBack(text);
|
connect(cb, &QComboBox::currentIndexChanged, [cb, info]() {
|
||||||
|
info.m_comboCallBack({cb->currentText(), cb->currentData()});
|
||||||
});
|
});
|
||||||
|
|
||||||
hbox->addWidget(cb);
|
hbox->addWidget(cb);
|
||||||
|
@@ -60,8 +60,14 @@ public:
|
|||||||
void addCustomButton(const QString &_buttonText, CallBack callBack);
|
void addCustomButton(const QString &_buttonText, CallBack callBack);
|
||||||
void setCancelButtonInfo(CallBack callBack);
|
void setCancelButtonInfo(CallBack callBack);
|
||||||
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
|
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
|
||||||
using ComboCallBack = std::function<void(const QString &)>;
|
struct ComboInfo
|
||||||
|
{
|
||||||
|
QString displayText;
|
||||||
|
QVariant data;
|
||||||
|
};
|
||||||
|
using ComboCallBack = std::function<void(const ComboInfo &)>;
|
||||||
void setComboInfo(const QStringList &list, ComboCallBack callBack);
|
void setComboInfo(const QStringList &list, ComboCallBack callBack);
|
||||||
|
void setComboInfo(const QList<ComboInfo> &infos, ComboCallBack callBack);
|
||||||
void removeCancelButton();
|
void removeCancelButton();
|
||||||
|
|
||||||
using DetailsWidgetCreator = std::function<QWidget*()>;
|
using DetailsWidgetCreator = std::function<QWidget*()>;
|
||||||
@@ -83,7 +89,7 @@ private:
|
|||||||
DetailsWidgetCreator m_detailsWidgetCreator;
|
DetailsWidgetCreator m_detailsWidgetCreator;
|
||||||
bool m_useCancelButton = true;
|
bool m_useCancelButton = true;
|
||||||
ComboCallBack m_comboCallBack;
|
ComboCallBack m_comboCallBack;
|
||||||
QStringList m_comboInfo;
|
QList<ComboInfo> m_comboInfo;
|
||||||
friend class InfoBar;
|
friend class InfoBar;
|
||||||
friend class InfoBarDisplay;
|
friend class InfoBarDisplay;
|
||||||
};
|
};
|
||||||
|
@@ -143,12 +143,15 @@ void McuSupportPlugin::askUserAboutMcuSupportKitsUpgrade()
|
|||||||
Utils::InfoBarEntry info(upgradeMcuSupportKits,
|
Utils::InfoBarEntry info(upgradeMcuSupportKits,
|
||||||
tr("New version of Qt for MCUs detected. Upgrade existing Kits?"),
|
tr("New version of Qt for MCUs detected. Upgrade existing Kits?"),
|
||||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||||
static McuKitManager::UpgradeOption selectedOption = McuKitManager::UpgradeOption::Keep;
|
using McuKitManager::UpgradeOption;
|
||||||
|
static UpgradeOption selectedOption = UpgradeOption::Keep;
|
||||||
|
|
||||||
const QStringList options = {tr("Create new kits"), tr("Replace existing kits")};
|
const QList<Utils::InfoBarEntry::ComboInfo> infos
|
||||||
info.setComboInfo(options, [options](const QString &selected) {
|
= {{tr("Create new kits"), QVariant::fromValue(UpgradeOption::Keep)},
|
||||||
selectedOption = options.indexOf(selected) == 0 ? McuKitManager::UpgradeOption::Keep
|
{tr("Replace existing kits"), QVariant::fromValue(UpgradeOption::Replace)}};
|
||||||
: McuKitManager::UpgradeOption::Replace;
|
|
||||||
|
info.setComboInfo(infos, [](const Utils::InfoBarEntry::ComboInfo &selected) {
|
||||||
|
selectedOption = selected.data.value<UpgradeOption>();
|
||||||
});
|
});
|
||||||
|
|
||||||
info.addCustomButton(tr("Proceed"), [upgradeMcuSupportKits] {
|
info.addCustomButton(tr("Proceed"), [upgradeMcuSupportKits] {
|
||||||
|
@@ -3254,8 +3254,8 @@ void TextEditorWidgetPrivate::updateSyntaxInfoBar(const Highlighter::Definitions
|
|||||||
BaseTextEditor::tr("More than one highlight definition was found for this file. "
|
BaseTextEditor::tr("More than one highlight definition was found for this file. "
|
||||||
"Which one should be used to highlight this file?"));
|
"Which one should be used to highlight this file?"));
|
||||||
info.setComboInfo(Utils::transform(definitions, &Highlighter::Definition::name),
|
info.setComboInfo(Utils::transform(definitions, &Highlighter::Definition::name),
|
||||||
[this](const QString &definition) {
|
[this](const InfoBarEntry::ComboInfo &info) {
|
||||||
this->configureGenericHighlighter(Highlighter::definitionForName(definition));
|
this->configureGenericHighlighter(Highlighter::definitionForName(info.displayText));
|
||||||
});
|
});
|
||||||
|
|
||||||
info.addCustomButton(BaseTextEditor::tr("Remember My Choice"), [multiple, this]() {
|
info.addCustomButton(BaseTextEditor::tr("Remember My Choice"), [multiple, this]() {
|
||||||
|
Reference in New Issue
Block a user