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
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
Zbl::ZScopedMap Class Reference

A hierarchical map object for creating scopes. More...

#include <ZScopedMap.h>

Inheritance diagram for Zbl::ZScopedMap:
Inheritance graph
[legend]
Collaboration diagram for Zbl::ZScopedMap:
Collaboration graph
[legend]

Public Slots

void set (const QString &key, const QJsonValue &value)
 Sets the specified key in the map to the specified value. Existing values are overwritten. More...
 
bool setMap (QVariantMap map)
 Inserts a set of key/value pairs into the map. Existing values are overwritten. More...
 
bool setScopedMap (QObject *map)
 Inserts a set of key/value pairs into the map. Existing values are overwritten. More...
 
bool remove (const QString &key)
 Removes the specified key from the map. More...
 
void clear ()
 Remove all key/value pairs from the map. More...
 
void loadJSON (const QString &jsonString)
 Parses the supplied JSON string and writes the contained key/value pairs to the map. More...
 

Signals

void itemChanged (const QString key, QVariant value)
 
void mapChanged (QVariantMap newValues)
 
void reset ()
 

Public Member Functions

 ZScopedMap (QObject *parent=0)
 
int getSize () const
 Obtain number of items in the map. More...
 
Q_INVOKABLE bool has (const QString &key) const
 Returns true if the map contains the specified key. More...
 
Q_INVOKABLE QVariant get (const QString &key) const
 Returns the value associated with a specified key in the map. More...
 
Q_INVOKABLE QVariantList keys () const
 Obtain the key names in the map. More...
 
Q_INVOKABLE void invalidate ()
 Issue a scopeChanged signal. All clients should query their values. More...
 
Q_INVOKABLE QString toJSON () const
 Obtain a JSON string representation of the map. More...
 

Static Public Member Functions

static void registerType ()
 Register ZMailbox as a QML type. More...
 

Protected Member Functions

ZBL_DECLARE_LOGGED_OBJECT QString getInitializer () const
 Return the JSON string used to initialize this object. More...
 
void setOuterScope (QObject *outerScope)
 Set the enclosing scope to which unresolved name lookups will be forwarded. More...
 
QObject * getOuterScope ()
 Get the enclosing scope. May be null if this is outermost scope. More...
 
bool isValidType (const QJsonValue &value)
 Test if a value has a type that can be stored in the scope. More...
 
bool isValidType (const QVariant &value)
 Test if a value has a type that can be stored in the scope. More...
 
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. More...
 

Protected Attributes

ZScopedMapm_outerScope
 The scope enclosing this scope, or null if this is outermost scope. More...
 
QVariantMap m_map
 A dictionary of scoped objects. More...
 
QString m_JSON
 JSON string used to initialize this scope. More...
 

Properties

int size
 The number of items in the map. More...
 
QObject outerScope
 The number of items in the map. More...
 
const QString initializer
 A JSON string containing initial key/value pairs for this scope. More...
 

Detailed Description

A hierarchical map object for creating scopes.

This class contains a map of named items. It also may optionally hold a reference to an outer scope. When an outer scope is present name lookups that can't be resolved within this scope are forwarded to the outer scope.

Items in the scope can be modified individually, such that a change notification is issued for each item that changed, or in a batch mode where multiple items can be changed in a single function call and a single notification is issued containing a map of all changed items when the batch is complete.

If this scope has an outer scope it listens for change notifications from the outer scope and propagates those notifications to current listeners only if the names can't be resolved in this scope.

This algorithm allows items defined in this scope to mask items of the same name in ancestor scopes and for listeners of this scope to receive only relevant notifications from ancestor scopes.

Zuble uses this mechanism to define and propagate UI style information.

Definition at line 36 of file ZScopedMap.h.

Constructor & Destructor Documentation

◆ ZScopedMap()

Zbl::ZScopedMap::ZScopedMap ( QObject *  parent = 0)
explicit

Definition at line 34 of file ZScopedMap.cpp.

Member Function Documentation

◆ clear

void Zbl::ZScopedMap::clear ( )
slot

Remove all key/value pairs from the map.

Definition at line 232 of file ZScopedMap.cpp.

◆ get()

QVariant Zbl::ZScopedMap::get ( const QString &  key) const

Returns the value associated with a specified key in the map.

Parameters
keyKey for which a value will be obtained
Returns
The value stored for the specified key

Definition at line 162 of file ZScopedMap.cpp.

Referenced by get().

◆ getInitializer()

QString Zbl::ZScopedMap::getInitializer ( ) const
protected

Return the JSON string used to initialize this object.

Returns
A JSON string, or empyt string is no JSON initializer was specified

Definition at line 143 of file ZScopedMap.cpp.

◆ getOuterScope()

QObject * Zbl::ZScopedMap::getOuterScope ( )
protected

Get the enclosing scope. May be null if this is outermost scope.

Returns

Definition at line 70 of file ZScopedMap.cpp.

◆ getSize()

int Zbl::ZScopedMap::getSize ( ) const

Obtain number of items in the map.

Definition at line 149 of file ZScopedMap.cpp.

◆ has()

bool Zbl::ZScopedMap::has ( const QString &  key) const

Returns true if the map contains the specified key.

Parameters
keyThe key to test
Returns
true if map contains key, false otherwise

Definition at line 154 of file ZScopedMap.cpp.

Referenced by has().

◆ invalidate()

void Zbl::ZScopedMap::invalidate ( )

Issue a scopeChanged signal. All clients should query their values.

Returns
An array containing the name of keys in the map

Definition at line 323 of file ZScopedMap.cpp.

◆ isValidType() [1/2]

bool Zbl::ZScopedMap::isValidType ( const QJsonValue &  value)
protected

Test if a value has a type that can be stored in the scope.

Parameters
valueThe value to test
Returns
true if value is of type that can be stored, false if an invalid type

Definition at line 237 of file ZScopedMap.cpp.

Referenced by loadJSON(), set(), and setMap().

◆ isValidType() [2/2]

bool Zbl::ZScopedMap::isValidType ( const QVariant &  value)
protected

Test if a value has a type that can be stored in the scope.

Parameters
valueThe value to test
Returns
true if value is of type that can be stored, false if an invalid type

Definition at line 255 of file ZScopedMap.cpp.

◆ itemChanged

void Zbl::ZScopedMap::itemChanged ( const QString  key,
QVariant  value 
)
signal

Referenced by setValue().

◆ keys()

QVariantList Zbl::ZScopedMap::keys ( ) const

Obtain the key names in the map.

Returns
An array containing the name of keys in the map

Definition at line 207 of file ZScopedMap.cpp.

◆ loadJSON

void Zbl::ZScopedMap::loadJSON ( const QString &  jsonString)
slot

Parses the supplied JSON string and writes the contained key/value pairs to the map.

Existing values are overwritten.

Parameters
jsonStringA JSON string containing key/value pairs to be written

Definition at line 75 of file ZScopedMap.cpp.

◆ mapChanged

void Zbl::ZScopedMap::mapChanged ( QVariantMap  newValues)
signal

Referenced by setMap().

◆ registerType()

void Zbl::ZScopedMap::registerType ( )
static

Register ZMailbox as a QML type.

Definition at line 39 of file ZScopedMap.cpp.

Referenced by Zbl::Zblcore::registerTypes().

◆ remove

bool Zbl::ZScopedMap::remove ( const QString &  key)
slot

Removes the specified key from the map.

Parameters
keyThe key that will be removed.
Returns
true if the key was removed from the map, false if the key didn't exist in the map

Definition at line 202 of file ZScopedMap.cpp.

◆ reset

void Zbl::ZScopedMap::reset ( )
signal

Referenced by invalidate(), and setOuterScope().

◆ set

void Zbl::ZScopedMap::set ( const QString &  key,
const QJsonValue &  value 
)
slot

Sets the specified key in the map to the specified value. Existing values are overwritten.

Any previous value for the specified key will be overwritten with the new value. An itemChanged will be issued after the value is changed.

Parameters
keyThe key for which a value will be set
valueThe value to set in the map.

Definition at line 172 of file ZScopedMap.cpp.

◆ setMap

bool Zbl::ZScopedMap::setMap ( QVariantMap  map)
slot

Inserts a set of key/value pairs into the map. Existing values are overwritten.

This method allows use of native javascript objects to set values in the map. A mapChanged signal will be issued after the values are inserted.

Parameters
mapa QVariantMap containg the values to insert.

Definition at line 277 of file ZScopedMap.cpp.

Referenced by setScopedMap().

◆ setOuterScope()

void Zbl::ZScopedMap::setOuterScope ( QObject *  outerScope)
protected

Set the enclosing scope to which unresolved name lookups will be forwarded.

Parameters
outerScopeA ZScopedMap object

Definition at line 46 of file ZScopedMap.cpp.

◆ setScopedMap

bool Zbl::ZScopedMap::setScopedMap ( QObject *  map)
slot

Inserts a set of key/value pairs into the map. Existing values are overwritten.

A mapChanged signal will be issued after the values are inserted.

Parameters
mapa ZScopedMap object containg the values to insert.

Definition at line 309 of file ZScopedMap.cpp.

◆ setValue()

bool Zbl::ZScopedMap::setValue ( QVariantMap &  map,
const QString &  key,
QVariant  value,
bool  emitSignal = false 
)
protected

Sets the specified key in the map to the specified value. Existing values are overwritten.

Any previous value for the specified key will be overwritten with the new value.

The value will NOT be wrtten if it was already set to the same value or if it was an invalid data type.

Parameters
keyThe key for which a value will be set
valueThe value to set in the map.
Returns
true if the value was a valid type, false if value type was invalid

Definition at line 182 of file ZScopedMap.cpp.

Referenced by set(), and setMap().

◆ toJSON()

QString Zbl::ZScopedMap::toJSON ( ) const

Obtain a JSON string representation of the map.

Returns

Definition at line 130 of file ZScopedMap.cpp.

Member Data Documentation

◆ m_JSON

QString Zbl::ZScopedMap::m_JSON
protected

JSON string used to initialize this scope.

Definition at line 290 of file ZScopedMap.h.

Referenced by getInitializer(), and loadJSON().

◆ m_map

QVariantMap Zbl::ZScopedMap::m_map
protected

A dictionary of scoped objects.

Definition at line 284 of file ZScopedMap.h.

Referenced by clear(), get(), getSize(), has(), keys(), loadJSON(), remove(), set(), setMap(), setScopedMap(), setValue(), and toJSON().

◆ m_outerScope

ZScopedMap* Zbl::ZScopedMap::m_outerScope
protected

The scope enclosing this scope, or null if this is outermost scope.

Definition at line 278 of file ZScopedMap.h.

Referenced by get(), getOuterScope(), has(), and setOuterScope().

Property Documentation

◆ initializer

const QString Zbl::ZScopedMap::initializer
readwrite

A JSON string containing initial key/value pairs for this scope.

This optional JSON init string is parsed at object creation time and its key/value pairs are added to the scope.

Definition at line 69 of file ZScopedMap.h.

◆ outerScope

QObject Zbl::ZScopedMap::outerScope
readwrite

The number of items in the map.

Definition at line 60 of file ZScopedMap.h.

Referenced by setOuterScope().

◆ size

int Zbl::ZScopedMap::size
read

The number of items in the map.

Definition at line 54 of file ZScopedMap.h.


The documentation for this class was generated from the following files: