Core::Feature: Add some functionality currently implemented in Core::Feature

Convert a QSet<Id> to/from a stringlist and add the methods to create
versioned ids and id sets.

Most of the code goes into Core::Id, but the code to generate sets of
versioned ids moves into BaseQtVersion which is the only user.

Change-Id: Id52474fac2aa0563e48b2b714dcfef533350c729
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2015-11-30 11:47:39 +01:00
parent 7b32b63707
commit 3a35d36b02
3 changed files with 54 additions and 0 deletions

View File

@@ -30,6 +30,7 @@
#include "id.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QByteArray>
@@ -245,6 +246,29 @@ Id Id::fromSetting(const QVariant &variant)
return Id(theId(ba));
}
Id Id::versionedId(const QByteArray &prefix, int major, int minor)
{
if (major < 0)
return fromName(prefix);
QByteArray result = prefix + '.';
result += QString::number(major).toLatin1();
if (minor < 0)
return fromName(result);
return fromName(result + '.' + QString::number(minor).toLatin1());
}
QSet<Id> Id::fromStringList(const QStringList &list)
{
return QSet<Id>::fromList(Utils::transform(list, [](const QString &s) { return Id::fromString(s); }));
}
QStringList Id::toStringList(const QSet<Id> &ids)
{
return Utils::transform(ids.toList(), [](Id i) { return i.toString(); });
}
/*!
Constructs a derived id.