diff --git a/autotests/propertyinfotest.h b/autotests/propertyinfotest.h --- a/autotests/propertyinfotest.h +++ b/autotests/propertyinfotest.h @@ -31,6 +31,7 @@ private Q_SLOTS: void testNameIdMapping(); void testFormatAsDisplayString(); + void testVariantMapConversion(); }; } diff --git a/autotests/propertyinfotest.cpp b/autotests/propertyinfotest.cpp --- a/autotests/propertyinfotest.cpp +++ b/autotests/propertyinfotest.cpp @@ -93,4 +93,17 @@ QCOMPARE(framerate.formatAsDisplayString(QVariant(23)), QStringLiteral("23 fps")); } +void PropertyInfoTest::testVariantMapConversion() +{ + PropertyMap propMap; + propMap.insertMulti(Property::Title, QStringLiteral("Title")); + propMap.insertMulti(Property::Artist, QStringLiteral("Artist1")); + propMap.insertMulti(Property::Artist, QStringLiteral("Artist2")); + propMap.insertMulti(Property::Lyricist, QStringList({QStringLiteral("Lyricist1"), QStringLiteral("Lyricist2")})); + propMap.insertMulti(Property::ReleaseYear, 2019); + + PropertyMap propMap2 = toPropertyMap(toVariantMap(propMap)); + QCOMPARE(propMap, propMap2); +} + QTEST_GUILESS_MAIN(PropertyInfoTest) diff --git a/src/properties.h b/src/properties.h --- a/src/properties.h +++ b/src/properties.h @@ -362,8 +362,19 @@ } // namespace Property +/** + * PropertyMap is a map which stores the results as + * pairs + * obtained from the extractors. + */ typedef QMap PropertyMap; +/** + * Converts a PropertyMap to a QVariantMap. + * The Property::Property enum is converted to its integer + * representation and stored as a string as key in the + * QVariantMap. + */ inline QVariantMap toVariantMap(const PropertyMap& propMap) { QVariantMap varMap; PropertyMap::const_iterator it = propMap.constBegin(); @@ -375,6 +386,11 @@ return varMap; } +/** + * Converts a QVariantMap to a PropertyMap. The keys of + * the QVariantMap must contain the integer representation + * of the Property::Property enum as a string. + */ inline PropertyMap toPropertyMap(const QVariantMap& varMap) { PropertyMap propMap; QVariantMap::const_iterator it = varMap.constBegin();