PropertyStorage <-> QVariantMap

This commit is contained in:
2020-11-25 18:16:38 +03:00
parent ee6f264466
commit f891a69ee0
2 changed files with 19 additions and 0 deletions

View File

@@ -2,6 +2,23 @@
#include "qad_types.h" #include "qad_types.h"
PropertyStorage::PropertyStorage(const QVariantMap & pl) {
QMapIterator<QString, QVariant> it(pl);
while (it.hasNext()) {
it.next();
props << Property(it.key(), "", it.value());
}
}
QVariantMap PropertyStorage::toVariantMap() const {
QVariantMap ret;
foreach (const Property & p, props)
ret[p.name] = p.value;
return ret;
}
bool PropertyStorage::isPropertyExists(const QString & _name) const { bool PropertyStorage::isPropertyExists(const QString & _name) const {
for (int i = 0; i < props.size(); ++i) for (int i = 0; i < props.size(); ++i)
if (props[i].name == _name) if (props[i].name == _name)

View File

@@ -48,6 +48,7 @@ public:
}; };
PropertyStorage(const QList<Property> & pl) {props = pl;} PropertyStorage(const QList<Property> & pl) {props = pl;}
PropertyStorage(const QVariantMap & pl);
typedef QList<Property>::const_iterator const_iterator; typedef QList<Property>::const_iterator const_iterator;
typedef QList<Property>::iterator iterator; typedef QList<Property>::iterator iterator;
@@ -83,6 +84,7 @@ public:
QList<Property> & properties() {return props;} QList<Property> & properties() {return props;}
const QList<Property> & properties() const {return props;} const QList<Property> & properties() const {return props;}
const PropertyStorage & propertyStorage() const {return *this;} const PropertyStorage & propertyStorage() const {return *this;}
QVariantMap toVariantMap() const;
bool isPropertyExists(const QString & _name) const; bool isPropertyExists(const QString & _name) const;
void clearProperties() {props.clear();} void clearProperties() {props.clear();}
void addProperty(const Property & p); void addProperty(const Property & p);