diff --git a/src/libs/utils/CMakeLists.txt b/src/libs/utils/CMakeLists.txt index 0d231e47ad8..72c18e3346f 100644 --- a/src/libs/utils/CMakeLists.txt +++ b/src/libs/utils/CMakeLists.txt @@ -163,7 +163,6 @@ add_qtc_library(Utils statuslabel.cpp statuslabel.h store.cpp store.h storekey.h - storefrommap.h stringtable.cpp stringtable.h stringutils.cpp stringutils.h styleanimator.cpp styleanimator.h diff --git a/src/libs/utils/store.cpp b/src/libs/utils/store.cpp index 9b31a16c541..1c7cac8c59f 100644 --- a/src/libs/utils/store.cpp +++ b/src/libs/utils/store.cpp @@ -27,4 +27,76 @@ Store storeFromVariant(const QVariant &value) return value.value(); } +#ifdef QTC_USE_STORE +static QVariantList storeListFromMapList(const QVariantList &mapList) +{ + QVariantList storeList; + + for (const auto &mapEntry : mapList) { + if (mapEntry.type() == QVariant::Map) + storeList.append(QVariant::fromValue(storeFromMap(mapEntry.toMap()))); + else if (mapEntry.type() == QVariant::List) + storeList.append(QVariant::fromValue(storeListFromMapList(mapEntry.toList()))); + else + storeList.append(mapEntry); + } + + return storeList; +} + +static QVariantList mapListFromStoreList(const QVariantList &storeList) +{ + QVariantList mapList; + + for (const auto &storeEntry : storeList) { + if (storeEntry.metaType() == QMetaType::fromType()) + mapList.append(QVariant::fromValue(mapFromStore(storeEntry.value()))); + else if (storeEntry.type() == QVariant::List) + mapList.append(QVariant::fromValue(mapListFromStoreList(storeEntry.toList()))); + else + mapList.append(storeEntry); + } + + return mapList; +} +#endif + +Store storeFromMap(const QVariantMap &map) +{ +#ifdef QTC_USE_STORE + Store store; + for (auto it = map.begin(); it != map.end(); ++it) { + if (it.value().type() == QVariant::Map) { + store.insert(keyFromString(it.key()), QVariant::fromValue(storeFromMap(it->toMap()))); + } else if (it.value().type() == QVariant::List) { + store.insert(keyFromString(it.key()), + QVariant::fromValue(storeListFromMapList(it->toList()))); + } else { + store.insert(keyFromString(it.key()), it.value()); + } + } + return store; +#else + return map; +#endif +} + +QVariantMap mapFromStore(const Store &store) +{ +#ifdef QTC_USE_STORE + QVariantMap map; + for (auto it = store.begin(); it != store.end(); ++it) { + if (it.value().metaType() == QMetaType::fromType()) + map.insert(stringFromKey(it.key()), mapFromStore(it->value())); + else if (it.value().type() == QVariant::List) + map.insert(stringFromKey(it.key()), mapListFromStoreList(it->toList())); + else + map.insert(stringFromKey(it.key()), it.value()); + } + return map; +#else + return store; +#endif +} + } // Utils diff --git a/src/libs/utils/store.h b/src/libs/utils/store.h index 09609e308a8..8cdf5682d23 100644 --- a/src/libs/utils/store.h +++ b/src/libs/utils/store.h @@ -24,4 +24,7 @@ QTCREATOR_UTILS_EXPORT QStringList stringsFromKeys(const KeyList &list); QTCREATOR_UTILS_EXPORT QVariant variantFromStore(const Store &store); QTCREATOR_UTILS_EXPORT Store storeFromVariant(const QVariant &value); +QTCREATOR_UTILS_EXPORT Store storeFromMap(const QVariantMap &map); +QTCREATOR_UTILS_EXPORT QVariantMap mapFromStore(const Store &store); + } // Utils diff --git a/src/libs/utils/storefrommap.h b/src/libs/utils/storefrommap.h deleted file mode 100644 index 6d2d760f86f..00000000000 --- a/src/libs/utils/storefrommap.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2023 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include "store.h" - -namespace Utils { - -#ifdef QTC_USE_STORE - -inline Store storeFromMap(const QVariantMap &map); -inline QVariantMap mapFromStore(const Store &store); - -inline QVariantList storeListFromMapList(const QVariantList &mapList) -{ - QVariantList storeList; - - for (const auto &mapEntry : mapList) { - if (mapEntry.type() == QVariant::Map) - storeList.append(QVariant::fromValue(storeFromMap(mapEntry.toMap()))); - else if (mapEntry.type() == QVariant::List) - storeList.append(QVariant::fromValue(storeListFromMapList(mapEntry.toList()))); - else - storeList.append(mapEntry); - } - - return storeList; -} - -inline QVariantList mapListFromStoreList(const QVariantList &storeList) -{ - QVariantList mapList; - - for (const auto &storeEntry : storeList) { - if (storeEntry.metaType() == QMetaType::fromType()) - mapList.append(QVariant::fromValue(mapFromStore(storeEntry.value()))); - else if (storeEntry.type() == QVariant::List) - mapList.append(QVariant::fromValue(mapListFromStoreList(storeEntry.toList()))); - else - mapList.append(storeEntry); - } - - return mapList; -} - -inline Store storeFromMap(const QVariantMap &map) -{ - Store store; - for (auto it = map.begin(); it != map.end(); ++it) { - if (it.value().type() == QVariant::Map) { - store.insert(keyFromString(it.key()), QVariant::fromValue(storeFromMap(it->toMap()))); - } else if (it.value().type() == QVariant::List) { - store.insert(keyFromString(it.key()), - QVariant::fromValue(storeListFromMapList(it->toList()))); - } else { - store.insert(keyFromString(it.key()), it.value()); - } - } - return store; -} - -inline QVariantMap mapFromStore(const Store &store) -{ - QVariantMap map; - for (auto it = store.begin(); it != store.end(); ++it) { - if (it.value().metaType() == QMetaType::fromType()) - map.insert(stringFromKey(it.key()), mapFromStore(it->value())); - else if (it.value().type() == QVariant::List) - map.insert(stringFromKey(it.key()), mapListFromStoreList(it->toList())); - else - map.insert(stringFromKey(it.key()), it.value()); - } - return map; -} - -#else - -inline Store storeFromMap(const QVariantMap &map) -{ - return map; -} - -inline QVariantMap mapFromStore(const Store &store) -{ - return store; -} - -#endif - -} // namespace Utils diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index b6d0839167a..021c1d37f26 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -296,7 +296,6 @@ Project { "store.cpp", "store.h", "storekey.h", - "storefrommap.h", "stringtable.cpp", "stringtable.h", "stringutils.cpp",