mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
refs #297 Added CVariantMap derived from CDictionary.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include "propertyindexvariantmap.h"
|
#include "propertyindexvariantmap.h"
|
||||||
#include "namevariantpairlist.h"
|
#include "namevariantpairlist.h"
|
||||||
#include "variantlist.h"
|
#include "variantlist.h"
|
||||||
|
#include "variantmap.h"
|
||||||
#include "statusmessagelist.h"
|
#include "statusmessagelist.h"
|
||||||
#include "pixmap.h"
|
#include "pixmap.h"
|
||||||
#include "iconlist.h"
|
#include "iconlist.h"
|
||||||
@@ -92,6 +93,7 @@ void BlackMisc::registerMetadata()
|
|||||||
CPropertyIndex::registerMetadata();
|
CPropertyIndex::registerMetadata();
|
||||||
CVariant::registerMetadata();
|
CVariant::registerMetadata();
|
||||||
CVariantList::registerMetadata();
|
CVariantList::registerMetadata();
|
||||||
|
CVariantMap::registerMetadata();
|
||||||
CPropertyIndex::registerMetadata();
|
CPropertyIndex::registerMetadata();
|
||||||
CPropertyIndexList::registerMetadata();
|
CPropertyIndexList::registerMetadata();
|
||||||
CPropertyIndexVariantMap::registerMetadata();
|
CPropertyIndexVariantMap::registerMetadata();
|
||||||
|
|||||||
36
src/blackmisc/variantmap.cpp
Normal file
36
src/blackmisc/variantmap.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "blackmisc/variantmap.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
|
||||||
|
QJsonObject CVariantMap::toJson() const
|
||||||
|
{
|
||||||
|
QJsonObject json;
|
||||||
|
for (auto it = cbegin(); it != cend(); ++it)
|
||||||
|
{
|
||||||
|
json.insert(it.key(), it.value().toJson());
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CVariantMap::convertFromJson(const QJsonObject &json)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
for (auto it = json.begin(); it != json.end(); ++it)
|
||||||
|
{
|
||||||
|
CVariant value;
|
||||||
|
value.convertFromJson(it.value().toObject());
|
||||||
|
implementationOf(*this).insert(cend(), it.key(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
62
src/blackmisc/variantmap.h
Normal file
62
src/blackmisc/variantmap.h
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#ifndef BLACKMISC_VARIANTMAP_H
|
||||||
|
#define BLACKMISC_VARIANTMAP_H
|
||||||
|
|
||||||
|
#include "blackmisc/variant.h"
|
||||||
|
#include "blackmisc/dictionary.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Map of { QString, CVariant } pairs.
|
||||||
|
*
|
||||||
|
* Using QMap as implementation type so keys are sorted.
|
||||||
|
*/
|
||||||
|
class BLACKMISC_EXPORT CVariantMap :
|
||||||
|
public CDictionary<QString, CVariant, QMap>,
|
||||||
|
public Mixin::MetaType<CVariantMap>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CVariantMap)
|
||||||
|
|
||||||
|
//! Default constructor.
|
||||||
|
CVariantMap() {}
|
||||||
|
|
||||||
|
//! Initializer list constructor.
|
||||||
|
CVariantMap(std::initializer_list<std::pair<QString, CVariant>> il) : CDictionary(il) {}
|
||||||
|
|
||||||
|
//! Copy constructor.
|
||||||
|
CVariantMap(const CVariantMap &) = default;
|
||||||
|
|
||||||
|
//! Move constructor.
|
||||||
|
CVariantMap(CVariantMap &&other) : CDictionary(std::move(other)) {}
|
||||||
|
|
||||||
|
//! Copy assignment operator.
|
||||||
|
CVariantMap &operator =(const CVariantMap &other) { CDictionary::operator =(other); return *this; }
|
||||||
|
|
||||||
|
//! Move assignment operator.
|
||||||
|
CVariantMap &operator =(CVariantMap &&other) { CDictionary::operator =(std::move(other)); return *this; }
|
||||||
|
|
||||||
|
//! \copydoc BlackMisc::CValueObject::toJson
|
||||||
|
QJsonObject toJson() const;
|
||||||
|
|
||||||
|
//! \copydoc BlackMisc::CValueObject::convertFromJson
|
||||||
|
void convertFromJson(const QJsonObject &json);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::CVariantMap)
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user