VariantDataModel encapsulates QVariant and can be used as a model for any type of QVariant supported data structure (map, list, atomic variant such as double, int, ...)
More...
#include <VariantDataModel.h>
Collaboration diagram for VariantDataModel:Public Types | |
| enum | VariantNodeType { Atomic , List , Map } |
| The different types that can be stored in a VariantDataModel. More... | |
Public Member Functions | |
constructors | |
Default constructor: build an atomic invalid VariantDataModel | |
| VariantDataModel () | |
| VariantDataModel (const QVariant &variant) | |
| Build an atomic VariantDataModel with the given variant value. | |
| VariantDataModel (const QVariantList &variant) | |
| Build a list VariantDataModel from the given variant list It recursively build the VariantDataModel (hence if the given variant contains atomic, list or map elements their VariantDataModel representation will be inserted in the list) | |
| VariantDataModel (const QVariantMap &variant) | |
| Build a map VariantDataModel from the given variant map It recursively build the VariantDataModel (hence if the given variant contains atomic, list or map elements their VariantDataModel representation will be inserted in the map) | |
| VariantDataModel (const VariantDataModel &other) | |
| Copy constructor. | |
informative methods | |
true if there was data modification since the instantiation or the last reset | |
| bool | isModified () const |
| bool | isValid () const |
| true if this is the invalid VariantDataModel | |
| QString | typeString () const |
| either "Atomic", "List" or "Map" | |
| QString | getName () |
| same as typeString() (unused) | |
set/get/test | |
affectation to the given newValue (can be atomic, list or map) | |
| VariantDataModel & | operator= (QVariant newValue) |
| QVariant | getValue () const |
| get the encapsulated value (can be atomic, list or map) | |
| QString | toString () const |
| Get the QVariant value as a string (for atomic type) | |
| operator QString () const | |
| utility function to automatically convert to QString in statement | |
| QString | toJsonString () const |
| Get the string representing this model in JSON format: | |
| void | remove () |
| Clear all encapsulated data As this method renders the data model invalid (same effect as = QVariant()), this VariantDataModel will therefore not be added to its parent in the subsequent getValue(), toString()... | |
| bool | operator== (const VariantDataModel &other) const |
| equality test (use QVariant/QVariantList/QVariantMap == operator) | |
| bool | operator== (const QVariant &v) const |
| bool | operator== (const QVariantList &v) const |
| bool | operator== (const QVariantMap &v) const |
| bool | operator!= (const VariantDataModel &other) const |
| inequality test (opposite of ==) | |
| bool | operator!= (const QVariant &v) const |
| bool | operator!= (const QVariantList &v) const |
| bool | operator!= (const QVariantMap &v) const |
| VariantDataModel & | last () |
| Returned value depends on the VariantDataModel type: | |
| int | size () const |
| Returned value depends on the VariantDataModel type: | |
| bool | isEmpty () const |
| Returned value depends on the VariantDataModel type: | |
| void | reset () |
| reset the modified flag (recursively for list and map) | |
Map management | |
This methods are useful when the VariantDataModel is a map | |
| VariantDataModel & | value (const QString &key) |
| Returned value depends on the VariantDataModel type: | |
| VariantDataModel & | operator[] (const QString &key) |
| Returned value depends on the VariantDataModel type: | |
| const VariantDataModel | operator[] (const QString &key) const |
| const version of operator[](QString) | |
| bool | contains (const QString &key) const |
| Returned value depends on the VariantDataModel type: | |
| void | insert (const QString &key, const VariantDataModel &value) |
| Behaviour depends on the VariantDataModel type: | |
| void | insert (const QString &key, const QVariant &value) |
| Behaviour depends on the VariantDataModel type: | |
| int | remove (const QString &key) |
| Behaviour and returned value depends on the VariantDataModel type: | |
List management | |
This methods are useful when the VariantDataModel is a List | |
| VariantDataModel & | at (int i) |
| Returned value depends on the VariantDataModel type: | |
| VariantDataModel & | operator[] (int i) |
| same as at(int) | |
| const VariantDataModel | operator[] (int i) const |
| const version of operator[](int) | |
| bool | removeOne (const VariantDataModel &item) |
| Behaviour and returned value depends on the VariantDataModel type: | |
| bool | removeAt (int i) |
| Behaviour and returned value depends on the VariantDataModel type: | |
| void | append (const VariantDataModel &item) |
| Behaviour depends on the VariantDataModel type: | |
STL-style iterators | |
| QList< VariantDataModel >::iterator | begin () |
| Returns an STL-style iterator pointing to the first item in the list. | |
| QList< VariantDataModel >::const_iterator | begin () const |
| const version of begin() | |
| QList< VariantDataModel >::iterator | end () |
| Returns an STL-style iterator pointing to the imaginary item after the last item in the list. | |
| QList< VariantDataModel >::const_iterator | end () const |
| const version of end() | |
| QMap< QString, VariantDataModel >::iterator | beginMap () |
| Returns a STL-style iterator pointing to the first item in the map. | |
| QMap< QString, VariantDataModel >::const_iterator | beginMap () const |
| const version of beginMap() | |
| QMap< QString, VariantDataModel >::iterator | endMap () |
| Returns an STL-style iterator pointing to the imaginary item after the last item in the map. | |
| QMap< QString, VariantDataModel >::const_iterator | endMap () const |
| const version of endMap() | |
Static Public Member Functions | |
static utility method | |
Build the model from the given JSON string (must be representing a JSON object) | |
| static const VariantDataModel | fromJsonString (const QString &jsonString) |
| static const VariantDataModel | fromJsonObject (const QJsonObject &jsonObject) |
| Build the model from the given JSON object. | |
| static VariantDataModel & | invalid () |
| get the invalid VariantDataModel | |
Protected Member Functions | |
| void | setName (const QString &name) |
| set the name of the VariantDataModel | |
Protected Attributes | |
| bool | isModifiedFlag |
| true if there was a modification in the value, item or pair since instanciation or last reset | |
| QString | name |
| name (unused, equals to typeString()) | |
| VariantNodeType | type |
| type can be Atomic, List or Map depending on how the VariantDataModel was instantiated | |
Static Protected Attributes | |
| static VariantDataModel | invalidVariantDataModel |
| The default VariantDataModel, an Atomic VariantDataModel with invalid status. | |
VariantDataModel encapsulates QVariant and can be used as a model for any type of QVariant supported data structure (map, list, atomic variant such as double, int, ...)
Advantages over QVariant
VariantDataModelQVariant (e.g., adding a element in an array is seen as "in place" and is not done in a new array)VariantDataModel supports atomic (single value QVariant such as string, numeric value), list (using QVariantList) and map (using QVariantMap).
VariantDataModel can be build directly from JSON string, JSON object, QVariant, QVariantList and QVariantMap. VariantDataModel offers utility methods to access, insert, remove data in place
Prints
The different types that can be stored in a VariantDataModel.
| Enumerator | |
|---|---|
| Atomic | Atomic type (string, numeric values, boolean) |
| List | List of VariantDataModel. |
| Map | Map of <QString (key), VariantDataModel (value)> |
| VariantDataModel::VariantDataModel | ( | ) |
References Atomic, isModifiedFlag, name, and type.
Referenced by insert(), and VariantDataModel().
Here is the caller graph for this function:| VariantDataModel::VariantDataModel | ( | const QVariant & | variant | ) |
Build an atomic VariantDataModel with the given variant value.
References Atomic, isModifiedFlag, List, name, type, typeString(), and VariantDataModel().
Here is the call graph for this function:| VariantDataModel::VariantDataModel | ( | const QVariantList & | variant | ) |
Build a list VariantDataModel from the given variant list It recursively build the VariantDataModel (hence if the given variant contains atomic, list or map elements their VariantDataModel representation will be inserted in the list)
References isModifiedFlag, List, name, type, and typeString().
Here is the call graph for this function:| VariantDataModel::VariantDataModel | ( | const QVariantMap & | variant | ) |
Build a map VariantDataModel from the given variant map It recursively build the VariantDataModel (hence if the given variant contains atomic, list or map elements their VariantDataModel representation will be inserted in the map)
References isModifiedFlag, Map, name, type, and typeString().
Here is the call graph for this function:| VariantDataModel::VariantDataModel | ( | const VariantDataModel & | other | ) |
Copy constructor.
References isModifiedFlag, name, and type.
| void VariantDataModel::append | ( | const VariantDataModel & | item | ) |
Behaviour depends on the VariantDataModel type:
References getValue(), isModifiedFlag, List, type, and typeString().
Referenced by CamiTKExtensionModelPresenter::plusButtonClicked(), and CamiTKPropertyListFieldEditor::plusButtonClicked().
Here is the call graph for this function:
Here is the caller graph for this function:| VariantDataModel & VariantDataModel::at | ( | int | i | ) |
Returned value depends on the VariantDataModel type:
References invalid(), List, type, and typeString().
Referenced by operator[]().
Here is the call graph for this function:
Here is the caller graph for this function:| QList< VariantDataModel >::iterator VariantDataModel::begin | ( | ) |
Returns an STL-style iterator pointing to the first item in the list.
| QList< VariantDataModel >::const_iterator VariantDataModel::begin | ( | ) | const |
const version of begin()
| QMap< QString, VariantDataModel >::iterator VariantDataModel::beginMap | ( | ) |
Returns a STL-style iterator pointing to the first item in the map.
| QMap< QString, VariantDataModel >::const_iterator VariantDataModel::beginMap | ( | ) | const |
const version of beginMap()
| bool VariantDataModel::contains | ( | const QString & | key | ) | const |
Returned value depends on the VariantDataModel type:
References Map, type, and typeString().
Referenced by CamiTKExtensionModel::load().
Here is the call graph for this function:
Here is the caller graph for this function:| QList< VariantDataModel >::iterator VariantDataModel::end | ( | ) |
Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
| QList< VariantDataModel >::const_iterator VariantDataModel::end | ( | ) | const |
const version of end()
| QMap< QString, VariantDataModel >::iterator VariantDataModel::endMap | ( | ) |
Returns an STL-style iterator pointing to the imaginary item after the last item in the map.
| QMap< QString, VariantDataModel >::const_iterator VariantDataModel::endMap | ( | ) | const |
const version of endMap()
|
static |
Build the model from the given JSON object.
References isModifiedFlag, Map, name, type, and typeString().
Here is the call graph for this function:
|
static |
References isModifiedFlag, Map, name, type, and typeString().
Here is the call graph for this function:| QString VariantDataModel::getName | ( | ) |
same as typeString() (unused)
References name.
Referenced by QtPropertyFieldEditor::getWidget().
Here is the caller graph for this function:| QVariant VariantDataModel::getValue | ( | ) | const |
get the encapsulated value (can be atomic, list or map)
References Atomic, List, and type.
Referenced by append(), CamiTKPropertyFieldEditor::buildTypeDependentEditors(), camitk::CppHotPlugAction::CppHotPlugAction(), ExtensionGenerator::generate(), ListFieldEditor::getWidget(), camitk::HotPlugAction::HotPlugAction(), camitk::HotPlugActionExtension::HotPlugActionExtension(), QtPropertyFieldEditor::QtPropertyFieldEditor(), removeOne(), CamiTKExtensionModel::toJSON(), and toString().
Here is the caller graph for this function:| void VariantDataModel::insert | ( | const QString & | key, |
| const QVariant & | value | ||
| ) |
Behaviour depends on the VariantDataModel type:
References insert(), Map, toString(), type, typeString(), value(), and VariantDataModel().
Here is the call graph for this function:| void VariantDataModel::insert | ( | const QString & | key, |
| const VariantDataModel & | value | ||
| ) |
Behaviour depends on the VariantDataModel type:
References isModifiedFlag, Map, type, typeString(), and value().
Referenced by insert(), and CamiTKExtensionModel::resetModel().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
get the invalid VariantDataModel
References invalidVariantDataModel.
Referenced by at(), isValid(), operator[](), operator[](), operator[](), and value().
Here is the caller graph for this function:| bool VariantDataModel::isEmpty | ( | ) | const |
Returned value depends on the VariantDataModel type:
References Atomic, List, and type.
Referenced by size().
Here is the caller graph for this function:| bool VariantDataModel::isModified | ( | ) | const |
References Atomic, isModifiedFlag, List, and type.
Referenced by CamiTKExtensionModel::isModified().
Here is the caller graph for this function:| bool VariantDataModel::isValid | ( | ) | const |
true if this is the invalid VariantDataModel
References invalid().
Referenced by ActionTabPresenter::ActionTabPresenter(), CamiTKPropertyFieldEditor::buildTypeDependentEditors(), CamiTKExtensionModelPresenter::CamiTKExtensionModelPresenter(), ExtensionTabPresenter::ExtensionTabPresenter(), CamiTKExtensionModelPresenter::isHotPlug(), CamiTKExtensionModelPresenter::isPython(), camitk::HotPlugActionExtension::newHotPlugActionExtension(), and CamiTKExtensionModelPresenter::tabCloseRequest().
Here is the call graph for this function:
Here is the caller graph for this function:| VariantDataModel & VariantDataModel::last | ( | ) |
Returned value depends on the VariantDataModel type:
(*this)References Atomic, List, and type.
Referenced by CamiTKExtensionModelPresenter::plusButtonClicked(), and CamiTKPropertyListFieldEditor::plusButtonClicked().
Here is the caller graph for this function:| VariantDataModel::operator QString | ( | ) | const |
utility function to automatically convert to QString in statement
| bool VariantDataModel::operator!= | ( | const QVariant & | v | ) | const |
| bool VariantDataModel::operator!= | ( | const QVariantList & | v | ) | const |
| bool VariantDataModel::operator!= | ( | const QVariantMap & | v | ) | const |
| bool VariantDataModel::operator!= | ( | const VariantDataModel & | other | ) | const |
inequality test (opposite of ==)
| VariantDataModel & VariantDataModel::operator= | ( | QVariant | newValue | ) |
| bool VariantDataModel::operator== | ( | const QVariantList & | v | ) | const |
| bool VariantDataModel::operator== | ( | const QVariantMap & | v | ) | const |
| bool VariantDataModel::operator== | ( | const VariantDataModel & | other | ) | const |
| VariantDataModel & VariantDataModel::operator[] | ( | const QString & | key | ) |
Returned value depends on the VariantDataModel type:
References invalid(), List, Map, type, and typeString().
Here is the call graph for this function:| const VariantDataModel VariantDataModel::operator[] | ( | const QString & | key | ) | const |
const version of operator[](QString)
References invalid(), List, Map, type, and typeString().
Here is the call graph for this function:| VariantDataModel & VariantDataModel::operator[] | ( | int | i | ) |
| const VariantDataModel VariantDataModel::operator[] | ( | int | i | ) | const |
const version of operator[](int)
References invalid(), List, type, and typeString().
Here is the call graph for this function:| void VariantDataModel::remove | ( | ) |
Clear all encapsulated data As this method renders the data model invalid (same effect as = QVariant()), this VariantDataModel will therefore not be added to its parent in the subsequent getValue(), toString()...
It is still present in the parent VariantDataModel (as there are no members that links the current VariantDataModel to its parent), but can be considered as removed as it won't be added to the value in any subsequent getValue(), toString()...
References Atomic, isModifiedFlag, and type.
Referenced by CamiTKPropertyFieldEditor::buildTypeDependentEditors(), FieldEditor::deleteButtonClicked(), and CamiTKExtensionModelPresenter::tabCloseRequest().
Here is the caller graph for this function:| int VariantDataModel::remove | ( | const QString & | key | ) |
Behaviour and returned value depends on the VariantDataModel type:
References isModifiedFlag, Map, type, and typeString().
Here is the call graph for this function:| bool VariantDataModel::removeAt | ( | int | i | ) |
Behaviour and returned value depends on the VariantDataModel type:
References isModifiedFlag, List, type, and typeString().
Here is the call graph for this function:| bool VariantDataModel::removeOne | ( | const VariantDataModel & | item | ) |
Behaviour and returned value depends on the VariantDataModel type:
References getValue(), isModifiedFlag, List, type, and typeString().
Here is the call graph for this function:| void VariantDataModel::reset | ( | ) |
reset the modified flag (recursively for list and map)
References isModifiedFlag.
Referenced by CamiTKExtensionModel::save().
Here is the caller graph for this function:
|
protected |
set the name of the VariantDataModel
References name.
| int VariantDataModel::size | ( | ) | const |
Returned value depends on the VariantDataModel type:
References Atomic, isEmpty(), List, and type.
Referenced by ActionTabPresenter::ActionTabPresenter(), CamiTKExtensionModelPresenter::CamiTKExtensionModelPresenter(), camitk::HotPlugActionExtension::declaredActionCount(), camitk::CppHotPlugActionExtension::initActions(), and CamiTKExtensionModelPresenter::plusButtonClicked().
Here is the call graph for this function:
Here is the caller graph for this function:| QString VariantDataModel::toJsonString | ( | ) | const |
Get the string representing this model in JSON format:
"[ ..., ... ]")"{ ..., ... }") | QString VariantDataModel::toString | ( | ) | const |
Get the QVariant value as a string (for atomic type)
References getValue().
Referenced by CamiTKPropertyFieldEditor::buildTypeDependentEditors(), QtPropertyFieldEditor::getWidget(), insert(), CamiTKExtensionModelPresenter::isHotPlug(), CamiTKExtensionModelPresenter::isPython(), and camitk::HotPlugActionExtension::newHotPlugActionExtension().
Here is the call graph for this function:
Here is the caller graph for this function:| QString VariantDataModel::typeString | ( | ) | const |
either "Atomic", "List" or "Map"
References Atomic, List, and type.
Referenced by append(), at(), contains(), fromJsonObject(), fromJsonString(), insert(), insert(), operator[](), operator[](), operator[](), remove(), removeAt(), removeOne(), value(), VariantDataModel(), VariantDataModel(), and VariantDataModel().
Here is the caller graph for this function:| VariantDataModel & VariantDataModel::value | ( | const QString & | key | ) |
Returned value depends on the VariantDataModel type:
References invalid(), Map, type, and typeString().
Referenced by insert(), and insert().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprotected |
The default VariantDataModel, an Atomic VariantDataModel with invalid status.
Referenced by invalid().
|
protected |
true if there was a modification in the value, item or pair since instanciation or last reset
Referenced by append(), fromJsonObject(), fromJsonString(), insert(), isModified(), remove(), remove(), removeAt(), removeOne(), reset(), VariantDataModel(), VariantDataModel(), VariantDataModel(), VariantDataModel(), and VariantDataModel().
|
protected |
name (unused, equals to typeString())
Referenced by fromJsonObject(), fromJsonString(), getName(), setName(), VariantDataModel(), VariantDataModel(), VariantDataModel(), VariantDataModel(), and VariantDataModel().
|
protected |
type can be Atomic, List or Map depending on how the VariantDataModel was instantiated
Referenced by append(), at(), contains(), fromJsonObject(), fromJsonString(), getValue(), insert(), insert(), isEmpty(), isModified(), last(), operator=(), operator==(), operator==(), operator[](), operator[](), operator[](), remove(), remove(), removeAt(), removeOne(), size(), toJsonString(), typeString(), value(), VariantDataModel(), VariantDataModel(), VariantDataModel(), VariantDataModel(), and VariantDataModel().