forked from qt-creator/qt-creator
Examples: Read meta data, which includes categories
Task-number: QTCREATORBUG-28546
Change-Id: I11505d4f8b8eaef3f525185cd45757b6f41012ec
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
(cherry picked from commit e060f82fa5
)
This commit is contained in:
@@ -43,6 +43,35 @@ static QStringList trimStringList(const QStringList &stringlist)
|
|||||||
return Utils::transform(stringlist, [](const QString &str) { return str.trimmed(); });
|
return Utils::transform(stringlist, [](const QString &str) { return str.trimmed(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QHash<QString, QStringList> parseMeta(QXmlStreamReader *reader)
|
||||||
|
{
|
||||||
|
QHash<QString, QStringList> result;
|
||||||
|
while (!reader->atEnd()) {
|
||||||
|
switch (reader->readNext()) {
|
||||||
|
case QXmlStreamReader::StartElement:
|
||||||
|
if (reader->name() == QLatin1String("entry")) {
|
||||||
|
const QString key = reader->attributes().value("name").toString();
|
||||||
|
if (key.isEmpty()) {
|
||||||
|
reader->raiseError("Tag \"entry\" requires \"name\" attribute");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const QString value = reader->readElementText(
|
||||||
|
QXmlStreamReader::ErrorOnUnexpectedElement);
|
||||||
|
if (!value.isEmpty())
|
||||||
|
result[key].append(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case QXmlStreamReader::EndElement:
|
||||||
|
if (reader->name() == QLatin1String("meta"))
|
||||||
|
return result;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static QList<ExampleItem *> parseExamples(QXmlStreamReader *reader,
|
static QList<ExampleItem *> parseExamples(QXmlStreamReader *reader,
|
||||||
const FilePath &projectsOffset,
|
const FilePath &projectsOffset,
|
||||||
const FilePath &examplesInstallPath)
|
const FilePath &examplesInstallPath)
|
||||||
@@ -95,6 +124,8 @@ static QList<ExampleItem *> parseExamples(QXmlStreamReader *reader,
|
|||||||
item->platforms = trimStringList(
|
item->platforms = trimStringList(
|
||||||
reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement)
|
reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement)
|
||||||
.split(QLatin1Char(','), Qt::SkipEmptyParts));
|
.split(QLatin1Char(','), Qt::SkipEmptyParts));
|
||||||
|
} else if (reader->name() == QLatin1String("meta")) {
|
||||||
|
item->metaData = parseMeta(reader);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QXmlStreamReader::EndElement:
|
case QXmlStreamReader::EndElement:
|
||||||
|
@@ -28,6 +28,7 @@ public:
|
|||||||
QString videoUrl;
|
QString videoUrl;
|
||||||
QString videoLength;
|
QString videoLength;
|
||||||
QStringList platforms;
|
QStringList platforms;
|
||||||
|
QHash<QString, QStringList> metaData;
|
||||||
};
|
};
|
||||||
|
|
||||||
QTSUPPORT_EXPORT Utils::expected_str<QList<ExampleItem *>> parseExamples(
|
QTSUPPORT_EXPORT Utils::expected_str<QList<ExampleItem *>> parseExamples(
|
||||||
|
@@ -25,6 +25,8 @@ private slots:
|
|||||||
tst_Examples::tst_Examples() = default;
|
tst_Examples::tst_Examples() = default;
|
||||||
tst_Examples::~tst_Examples() = default;
|
tst_Examples::~tst_Examples() = default;
|
||||||
|
|
||||||
|
using MetaData = QHash<QString, QStringList>;
|
||||||
|
|
||||||
static ExampleItem fetchItem()
|
static ExampleItem fetchItem()
|
||||||
{
|
{
|
||||||
QFETCH(QString, name);
|
QFETCH(QString, name);
|
||||||
@@ -43,6 +45,7 @@ static ExampleItem fetchItem()
|
|||||||
QFETCH(QString, videoUrl);
|
QFETCH(QString, videoUrl);
|
||||||
QFETCH(QString, videoLength);
|
QFETCH(QString, videoLength);
|
||||||
QFETCH(QStringList, platforms);
|
QFETCH(QStringList, platforms);
|
||||||
|
QFETCH(MetaData, metaData);
|
||||||
ExampleItem item;
|
ExampleItem item;
|
||||||
item.name = name;
|
item.name = name;
|
||||||
item.description = description;
|
item.description = description;
|
||||||
@@ -60,6 +63,7 @@ static ExampleItem fetchItem()
|
|||||||
item.videoUrl = videoUrl;
|
item.videoUrl = videoUrl;
|
||||||
item.videoLength = videoLength;
|
item.videoLength = videoLength;
|
||||||
item.platforms = platforms;
|
item.platforms = platforms;
|
||||||
|
item.metaData = metaData;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +87,7 @@ void tst_Examples::parsing_data()
|
|||||||
QTest::addColumn<QString>("videoUrl");
|
QTest::addColumn<QString>("videoUrl");
|
||||||
QTest::addColumn<QString>("videoLength");
|
QTest::addColumn<QString>("videoLength");
|
||||||
QTest::addColumn<QStringList>("platforms");
|
QTest::addColumn<QStringList>("platforms");
|
||||||
|
QTest::addColumn<MetaData>("metaData");
|
||||||
|
|
||||||
QTest::addRow("example")
|
QTest::addRow("example")
|
||||||
<< QByteArray(R"raw(
|
<< QByteArray(R"raw(
|
||||||
@@ -115,7 +120,7 @@ void tst_Examples::parsing_data()
|
|||||||
"manifest/widgets/widgets/analogclock/analogclock.cpp")}
|
"manifest/widgets/widgets/analogclock/analogclock.cpp")}
|
||||||
<< FilePath::fromUserInput("manifest/widgets/widgets/analogclock/analogclock.cpp")
|
<< FilePath::fromUserInput("manifest/widgets/widgets/analogclock/analogclock.cpp")
|
||||||
<< FilePaths() << Example << true << false << false << ""
|
<< FilePaths() << Example << true << false << false << ""
|
||||||
<< "" << QStringList();
|
<< "" << QStringList() << MetaData({{"category", {"Graphics"}}, {"tags", {"widgets"}}});
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Examples::parsing()
|
void tst_Examples::parsing()
|
||||||
@@ -148,6 +153,7 @@ void tst_Examples::parsing()
|
|||||||
QCOMPARE(item.videoUrl, expected.videoUrl);
|
QCOMPARE(item.videoUrl, expected.videoUrl);
|
||||||
QCOMPARE(item.videoLength, expected.videoLength);
|
QCOMPARE(item.videoLength, expected.videoLength);
|
||||||
QCOMPARE(item.platforms, expected.platforms);
|
QCOMPARE(item.platforms, expected.platforms);
|
||||||
|
QCOMPARE(item.metaData, expected.metaData);
|
||||||
qDeleteAll(*result);
|
qDeleteAll(*result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user