WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZScopedMap.h
Go to the documentation of this file.
1 #ifndef ZScopedMap_H
2 #define ZScopedMap_H
3 
4 #include <QObject>
5 #include <QVariant>
6 #include "zglobal.h"
7 
8 namespace Zbl
9 {
10 
36 class ZScopedMap : public QObject
37 {
38  Q_OBJECT
39 public:
40  explicit ZScopedMap(QObject *parent = 0);
41 
42 
47  static void registerType();
48 
49 
54  Q_PROPERTY(int size READ getSize)
55 
56 
60  Q_PROPERTY(QObject* outerScope READ getOuterScope WRITE setOuterScope)
61 
69  Q_PROPERTY(const QString& initializer READ getInitializer WRITE loadJSON)
70 
71 
72  // TBD: properties: outerScope, JSON initializer string
73 
74  // TDB: methods: to/from JSON object, connectObject method
75 
76 
80  int getSize() const;
81 
90  Q_INVOKABLE bool has(const QString& key) const;
91 
101  Q_INVOKABLE QVariant get(const QString& key) const;
102 
109  Q_INVOKABLE QVariantList keys() const;
110 
116  Q_INVOKABLE void invalidate();
117 
123  Q_INVOKABLE QString toJSON() const;
124 
125 
126  // TBD: add insertScope function to insert a scope between this scope and
127  // its outer scope. And inverse removeScope function.
128 
129 signals:
130 
131 
132  void itemChanged(const QString key, QVariant value);
133 
134  void mapChanged(QVariantMap newValues);
135 
136  void reset();
137 
138 public slots:
139 
153  void set(const QString& key, const QJsonValue& value);
154 
155 
156 
166  bool setMap(QVariantMap map);
167 
176  bool setScopedMap(QObject* map);
177 
187  bool remove(const QString& key);
188 
189 
193  void clear();
194 
195 
205  void loadJSON(const QString& jsonString);
206 
207 
208 protected:
209 
211 
219  QString getInitializer() const;
220 
228  void setOuterScope(QObject* outerScope);
229 
235  QObject* getOuterScope();
236 
237 
243  bool isValidType(const QJsonValue& value);
244 
250  bool isValidType(const QVariant& value);
251 
270  bool setValue(QVariantMap& map, const QString& key, QVariant value, bool emitSignal=false);
271 
272 
279 
280 
284  QVariantMap m_map;
285 
290  QString m_JSON;
291 
292 };
293 
294 
295 } // Zbl
296 
297 #endif // ZScopedMap_H
bool isValidType(const QJsonValue &value)
Test if a value has a type that can be stored in the scope.
Definition: ZScopedMap.cpp:237
ZScopedMap(QObject *parent=0)
Definition: ZScopedMap.cpp:34
QVariantMap m_map
A dictionary of scoped objects.
Definition: ZScopedMap.h:284
#define ZBL_DECLARE_LOGGED_OBJECT
Definition: zglobal.h:94
int size
The number of items in the map.
Definition: ZScopedMap.h:54
QObject outerScope
The number of items in the map.
Definition: ZScopedMap.h:60
const QString initializer
A JSON string containing initial key/value pairs for this scope.
Definition: ZScopedMap.h:69
int getSize() const
Obtain number of items in the map.
Definition: ZScopedMap.cpp:149
bool setMap(QVariantMap map)
Inserts a set of key/value pairs into the map. Existing values are overwritten.
Definition: ZScopedMap.cpp:277
Definition: ZAndGate.cpp:6
ZBL_DECLARE_LOGGED_OBJECT QString getInitializer() const
Return the JSON string used to initialize this object.
Definition: ZScopedMap.cpp:143
bool setScopedMap(QObject *map)
Inserts a set of key/value pairs into the map. Existing values are overwritten.
Definition: ZScopedMap.cpp:309
Q_INVOKABLE QVariantList keys() const
Obtain the key names in the map.
Definition: ZScopedMap.cpp:207
void set(const QString &key, const QJsonValue &value)
Sets the specified key in the map to the specified value. Existing values are overwritten.
Definition: ZScopedMap.cpp:172
ZScopedMap * m_outerScope
The scope enclosing this scope, or null if this is outermost scope.
Definition: ZScopedMap.h:278
QObject * getOuterScope()
Get the enclosing scope. May be null if this is outermost scope.
Definition: ZScopedMap.cpp:70
Q_INVOKABLE bool has(const QString &key) const
Returns true if the map contains the specified key.
Definition: ZScopedMap.cpp:154
bool setValue(QVariantMap &map, const QString &key, QVariant value, bool emitSignal=false)
Sets the specified key in the map to the specified value. Existing values are overwritten.
Definition: ZScopedMap.cpp:182
void loadJSON(const QString &jsonString)
Parses the supplied JSON string and writes the contained key/value pairs to the map.
Definition: ZScopedMap.cpp:75
Q_INVOKABLE void invalidate()
Issue a scopeChanged signal. All clients should query their values.
Definition: ZScopedMap.cpp:323
QString m_JSON
JSON string used to initialize this scope.
Definition: ZScopedMap.h:290
void clear()
Remove all key/value pairs from the map.
Definition: ZScopedMap.cpp:232
void itemChanged(const QString key, QVariant value)
void mapChanged(QVariantMap newValues)
A hierarchical map object for creating scopes.
Definition: ZScopedMap.h:36
Q_INVOKABLE QString toJSON() const
Obtain a JSON string representation of the map.
Definition: ZScopedMap.cpp:130
Q_INVOKABLE QVariant get(const QString &key) const
Returns the value associated with a specified key in the map.
Definition: ZScopedMap.cpp:162
static void registerType()
Register ZMailbox as a QML type.
Definition: ZScopedMap.cpp:39
bool remove(const QString &key)
Removes the specified key from the map.
Definition: ZScopedMap.cpp:202
void setOuterScope(QObject *outerScope)
Set the enclosing scope to which unresolved name lookups will be forwarded.
Definition: ZScopedMap.cpp:46