ProjectExplorer: Allow to add custom output parsers programatically

This enables plugins to add custom parsers to the global pool.

Fixes: QTCREATORBUG-24403
Change-Id: Id600c12fc66876879a5a2975139d72f87c4f2e30
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2020-07-30 14:54:10 +02:00
parent 996f490e97
commit 4bbf76a344
6 changed files with 83 additions and 62 deletions

View File

@@ -59,7 +59,6 @@ const char channelKey[] = "Channel";
const char exampleKey[] = "Example";
namespace ProjectExplorer {
namespace Internal {
bool CustomParserExpression::operator ==(const CustomParserExpression &other) const
{
@@ -177,6 +176,33 @@ void CustomParserSettings::fromMap(const QVariantMap &map)
warning.fromMap(map.value(warningKey).toMap());
}
CustomParsersAspect::CustomParsersAspect(Target *target)
{
Q_UNUSED(target)
setId("CustomOutputParsers");
setSettingsKey("CustomOutputParsers");
setDisplayName(tr("Custom Output Parsers"));
setConfigWidgetCreator([this] {
const auto widget = new Internal::CustomParsersSelectionWidget;
widget->setSelectedParsers(m_parsers);
connect(widget, &Internal::CustomParsersSelectionWidget::selectionChanged,
this, [this, widget] { m_parsers = widget->selectedParsers(); });
return widget;
});
}
void CustomParsersAspect::fromMap(const QVariantMap &map)
{
m_parsers = transform(map.value(settingsKey()).toList(), &Utils::Id::fromSetting);
}
void CustomParsersAspect::toMap(QVariantMap &map) const
{
map.insert(settingsKey(), transform(m_parsers, &Utils::Id::toSetting));
}
namespace Internal {
CustomParser::CustomParser(const CustomParserSettings &settings)
{
setObjectName("CustomParser");
@@ -192,8 +218,8 @@ void CustomParser::setSettings(const CustomParserSettings &settings)
CustomParser *CustomParser::createFromId(Utils::Id id)
{
const Internal::CustomParserSettings parser = findOrDefault(ProjectExplorerPlugin::customParsers(),
[id](const Internal::CustomParserSettings &p) { return p.id == id; });
const CustomParserSettings parser = findOrDefault(ProjectExplorerPlugin::customParsers(),
[id](const CustomParserSettings &p) { return p.id == id; });
if (parser.id.isValid())
return new CustomParser(parser);
return nullptr;
@@ -347,31 +373,6 @@ void CustomParsersSelectionWidget::updateSummary()
setSummaryText(tr("There are %n custom parsers active", nullptr, parsers.count()));
}
CustomParsersAspect::CustomParsersAspect(Target *target)
{
Q_UNUSED(target)
setId("CustomOutputParsers");
setSettingsKey("CustomOutputParsers");
setDisplayName(tr("Custom Output Parsers"));
setConfigWidgetCreator([this] {
const auto widget = new CustomParsersSelectionWidget;
widget->setSelectedParsers(m_parsers);
connect(widget, &CustomParsersSelectionWidget::selectionChanged,
this, [this, widget] { m_parsers = widget->selectedParsers(); });
return widget;
});
}
void CustomParsersAspect::fromMap(const QVariantMap &map)
{
m_parsers = transform(map.value(settingsKey()).toList(), &Utils::Id::fromSetting);
}
void CustomParsersAspect::toMap(QVariantMap &map) const
{
map.insert(settingsKey(), transform(m_parsers, &Utils::Id::toSetting));
}
} // namespace Internal
// Unit tests: