mgear.vendor.qjsonmodel module¶
Python adaptation of https://github.com/dridk/QJsonModel
Supports Python 2 and 3 with PySide, PySide2, PyQt4 or PyQt5. Requires https://github.com/mottosso/Qt.py
- Usage:
Use it like you would the C++ version.
>>> import qjsonmodel >>> model = qjsonmodel.QJsonModel() >>> model.load({"key": "value"})
- Test:
Run the provided example to sanity check your Python, dependencies and Qt binding.
$ python qjsonmodel.py
- Changes:
This module differs from the C++ version in the following ways.
Setters and getters are replaced by Python properties
Objects are sorted by default, disabled via load(sort=False)
load() takes a Python dictionary as opposed to a string or file handle.
- To load from a string, use built-in json.loads()
>>> import json >>> document = json.loads("{'key': 'value'}") >>> model.load(document)
- To load from a file, use with open(fname)
>>> import json >>> with open("file.json") as f: ... document = json.load(f) ... model.load(document)
-
class
mgear.vendor.qjsonmodel.
QJsonModel
(parent=None)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
-
clear
()¶
-
columnCount
(parent=<sphinx.ext.autodoc.importer._MockObject object>)¶
-
data
(index, role)¶
-
flags
(index)¶
-
genJson
(item)¶
-
headerData
(section, orientation, role)¶
-
index
(row, column, parent=<sphinx.ext.autodoc.importer._MockObject object>)¶
-
json
(root=None)¶ Serialise model as JSON-compliant dictionary
Parameters: root (QJsonTreeItem, optional) – Serialise from here defaults to the the top-level item Returns: model as dict
-
load
(document)¶ Load from dictionary
Parameters: document (dict) – JSON-compatible dictionary
-
parent
(index)¶
-
rowCount
(parent=<sphinx.ext.autodoc.importer._MockObject object>)¶
-
setData
(index, value, role)¶
-