diff --git a/autotests/propertyinfotest.cpp b/autotests/propertyinfotest.cpp --- a/autotests/propertyinfotest.cpp +++ b/autotests/propertyinfotest.cpp @@ -104,6 +104,14 @@ PropertyMap propMap2 = toPropertyMap(toVariantMap(propMap)); QCOMPARE(propMap, propMap2); + + QVariantMap varMap = toNamedVariantMap(propMap); + QCOMPARE(varMap.value(QStringLiteral("title")).toString(), QStringLiteral("Title")); + const auto artists = varMap.values(QStringLiteral("artist")); + QVERIFY(artists.contains(QVariant(QStringLiteral("Artist1")))); + QVERIFY(artists.contains(QVariant(QStringLiteral("Artist2")))); + QCOMPARE(varMap.value(QStringLiteral("lyricist")).toStringList().join(", "), QStringLiteral("Lyricist1, Lyricist2")); + QCOMPARE(varMap.value(QStringLiteral("releaseYear")).toInt(), 2019); } QTEST_GUILESS_MAIN(PropertyInfoTest) diff --git a/src/propertyinfo.h b/src/propertyinfo.h --- a/src/propertyinfo.h +++ b/src/propertyinfo.h @@ -97,5 +97,23 @@ Private* d; }; +/** + * Converts a PropertyMap to a QVariantMap. + * The name of the Property::Property enum + * as defined by PropertyInfo is used as key. + * @since 5.56 + */ +inline QVariantMap toNamedVariantMap(const PropertyMap& propMap) +{ + QVariantMap map; + PropertyMap::const_iterator it = propMap.constBegin(); + for (; it != propMap.constEnd(); it++) { + PropertyInfo pi(it.key()); + map.insertMulti(pi.name(), it.value()); + } + + return map; +} + } #endif // _KFILEMETADATA_PROPERTYINFO_H