PluginView: Functional style dependency list creation

Change-Id: I08c6aeb8be55e73a9d8e55e264046afc19c9e4b9
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Eike Ziller
2016-06-22 13:44:19 +02:00
parent 73dbcb49fd
commit b9bd611e25
3 changed files with 21 additions and 18 deletions

View File

@@ -29,6 +29,8 @@
#include "pluginmanager.h" #include "pluginmanager.h"
#include "pluginspec.h" #include "pluginspec.h"
#include <utils/algorithm.h>
#include <QDir> #include <QDir>
#include <QRegExp> #include <QRegExp>
@@ -88,23 +90,6 @@ void PluginDetailsView::update(PluginSpec *spec)
const QString platformString = tr("%1 (current: \"%2\")").arg(pluginPlatformString, const QString platformString = tr("%1 (current: \"%2\")").arg(pluginPlatformString,
PluginManager::platformName()); PluginManager::platformName());
m_ui->platforms->setText(platformString); m_ui->platforms->setText(platformString);
QStringList depStrings; const QStringList depStrings = Utils::transform<QList>(spec->dependencies(), &PluginDependency::toString);
foreach (const PluginDependency &dep, spec->dependencies()) {
QString depString = dep.name;
depString += QLatin1String(" (");
depString += dep.version;
switch (dep.type) {
case PluginDependency::Required:
break;
case PluginDependency::Optional:
depString += QLatin1String(", optional");
break;
case PluginDependency::Test:
depString += QLatin1String(", test");
break;
}
depString += QLatin1Char(')');
depStrings.append(depString);
}
m_ui->dependencies->addItems(depStrings); m_ui->dependencies->addItems(depStrings);
} }

View File

@@ -146,6 +146,23 @@ bool PluginDependency::operator==(const PluginDependency &other) const
return name == other.name && version == other.version && type == other.type; return name == other.name && version == other.version && type == other.type;
} }
static QString typeString(PluginDependency::Type type)
{
switch (type) {
case PluginDependency::Required:
return QString();
case PluginDependency::Optional:
return ", optional";
case PluginDependency::Test:
return ", test";
}
}
QString PluginDependency::toString() const
{
return name + " (" + version + typeString(type) + ")";
}
/*! /*!
\internal \internal
*/ */

View File

@@ -63,6 +63,7 @@ struct EXTENSIONSYSTEM_EXPORT PluginDependency
QString version; QString version;
Type type; Type type;
bool operator==(const PluginDependency &other) const; bool operator==(const PluginDependency &other) const;
QString toString() const;
}; };
uint qHash(const ExtensionSystem::PluginDependency &value); uint qHash(const ExtensionSystem::PluginDependency &value);