Utils: Introduce a Storage class

... mapping Keys (currently QString) to Data (currently QVariant),
i.e. effectively an oddly named QVariantMap.

Plan is to

    1. make QVariantMap using loading/saving related functions to use
       Storage instead of QVariant map,
    2. replace QString by a UTF-8 container (QByteArray for starters)
    3. add/remove parts of the map interface so that neither decoration
       of string literals in user code are needed, nor that
       unnecessary allocations happen.

Long term Storage could cover some of the current JSON uses, with
Storage's implementation possibly switching over to something
based on JSON (or CBOR?) directly, to be closer what we typically
send over the wire.

Change-Id: Ic33b8e95fed5268d6298b5391ff42cbb582b56c4
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-08-23 14:10:58 +02:00
parent dc6b40a5c0
commit 753c00543d
4 changed files with 26 additions and 0 deletions

View File

@@ -161,6 +161,7 @@ add_qtc_library(Utils
sortfiltermodel.h
span.h
statuslabel.cpp statuslabel.h
storage.cpp storage.h
stringtable.cpp stringtable.h
stringutils.cpp stringutils.h
styleanimator.cpp styleanimator.h

View File

@@ -0,0 +1,9 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "storage.h"
namespace Utils {
} // Utils

14
src/libs/utils/storage.h Normal file
View File

@@ -0,0 +1,14 @@
// 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 <QVariantMap>
namespace Utils {
using Key = QString;
using Data = QVariant;
using Storage = QMap<Key, Data>;
} // Utils

View File

@@ -293,6 +293,8 @@ Project {
"../3rdparty/span/span.hpp",
"statuslabel.cpp",
"statuslabel.h",
"storage.cpp",
"storage.h",
"stringtable.cpp",
"stringtable.h",
"stringutils.cpp",