QmlDesigner: Fix the bug for using QMap::asKeyValueRange

This feature is available for QT_VERSION >= 6.4.0. So a compiler
condition is considered to switch the code for different versions.
Also, an old unused function has been removed.

Change-Id: I470812213cfb00c28fcf062d214895cfcba68d69
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Ali Kianian
2023-01-18 12:22:16 +02:00
parent 5818f9226a
commit d0c2ccac8b
2 changed files with 11 additions and 17 deletions

View File

@@ -79,21 +79,6 @@ EType DesignerIconEnums<EType>::value(const QString &keyStr, bool *ok)
return static_cast<EType>(metaEnum.keyToValue(keyStr.toLatin1(), ok)); return static_cast<EType>(metaEnum.keyToValue(keyStr.toLatin1(), ok));
} }
Q_GLOBAL_STATIC(QStringList, _iconFontMandatoryKeys);
const QStringList & iconFontMandatoryKeys()
{
if (_iconFontMandatoryKeys->isEmpty()) {
*_iconFontMandatoryKeys
<< DesignerIconEnums<Theme::Icon>::keyName
<< DesignerIconEnums<Theme::Color>::keyName
<< DesignerIconEnums<QIcon::Mode>::keyName
<< DesignerIconEnums<QIcon::State>::keyName
<< "size";
}
return *_iconFontMandatoryKeys;
}
QJsonObject mergeJsons(const QJsonObject &prior, const QJsonObject &joiner) QJsonObject mergeJsons(const QJsonObject &prior, const QJsonObject &joiner)
{ {
QJsonObject object = prior; QJsonObject object = prior;
@@ -237,8 +222,17 @@ struct JsonMap<QMap<Key, Value>>
static QJsonObject json(const QMap<Key, Value> &map) static QJsonObject json(const QMap<Key, Value> &map)
{ {
QJsonObject output; QJsonObject output;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
for (const auto &[key, val] : map.asKeyValueRange()) for (const auto &[key, val] : map.asKeyValueRange())
output[DesignerIconEnums<Key>::toString(key)] = JsonMap<Value>::json(val); output[DesignerIconEnums<Key>::toString(key)] = JsonMap<Value>::json(val);
#else
const auto mapKeys = map.keys();
for (const Key &key : mapKeys) {
const Value &val = map.value(key);
output[DesignerIconEnums<Key>::toString(key)] = JsonMap<Value>::json(val);
}
#endif
return output; return output;
} }

View File

@@ -24,14 +24,14 @@ public:
QIcon::Mode mode = QIcon::Normal, QIcon::Mode mode = QIcon::Normal,
QIcon::State state = QIcon::Off); QIcon::State state = QIcon::Off);
IconFontHelper();
static IconFontHelper fromJson(const QJsonObject &jsonObject); static IconFontHelper fromJson(const QJsonObject &jsonObject);
QJsonObject toJson() const; QJsonObject toJson() const;
Theme::Icon themeIcon() const; Theme::Icon themeIcon() const;
Theme::Color themeColor() const; Theme::Color themeColor() const;
private: private:
IconFontHelper();
Theme::Icon mThemeIcon; Theme::Icon mThemeIcon;
Theme::Color mThemeColor; Theme::Color mThemeColor;
}; };