##
#
# One document object in Json format.
# (Just to get the idea of data structure)
#
{
"_id": {
"_id": "5273df1f01d418250767b0a3",
"__type__": "Base.ObjectId"
}
"__type__": "Base.BaseDoc.BaseFlow.Comment",
"name": "Topic",
"timestamp": {
"date": 1383332671257,
"__type__": "date.datetime"
},
"author": null,
"_ns": "MyProject",
"_lock": {
"__type__": "UUID",
"uuid": "e83ad88206bf4e2181d1f848b4708165"
},
"comments": {
"__type__": "Base.RefSet"
"_references": [
{
"_type": "Base.BaseDoc.BaseFlow.Comment",
"_id": {
"_id": "527a6b9f01d418250767b135",
"__type__": "Base.ObjectId"
},
"_ns": "MyProject",
"_db": null,
"_lock": {
"__type__": "UUID",
"uuid": "2470196b220f496590a2adc9645f53b6"
},
"__type__": "Base.Ref"
},
{
"_type": "Base.BaseDoc.BaseFlow.Comment",
"_id": {
"_id": "527a6b2701d418250767b133",
"__type__": "Base.ObjectId"
},
"_ns": "MyProject",
"_db": null,
"_lock": null,
"__type__": "Base.Ref"
},
],
},
"text": "Comment content text ...",
}
##
#
# One document object in Json format.
# (Just to get the idea of data structure)
#
{
"_id": {
"_id": "5273df1f01d418250767b0a3",
"__type__": "Base.ObjectId"
}
"__type__": "Base.BaseDoc.BaseFlow.Comment",
"name": "Topic",
"timestamp": {
"date": 1383332671257,
"__type__": "date.datetime"
},
"author": null,
"_ns": "MyProject",
"_lock": {
"__type__": "UUID",
"uuid": "e83ad88206bf4e2181d1f848b4708165"
},
"comments": {
"__type__": "Base.RefSet"
"_references": [
{
"_type": "Base.BaseDoc.BaseFlow.Comment",
"_id": {
"_id": "527a6b9f01d418250767b135",
"__type__": "Base.ObjectId"
},
"_ns": "MyProject",
"_db": null,
"_lock": {
"__type__": "UUID",
"uuid": "2470196b220f496590a2adc9645f53b6"
},
"__type__": "Base.Ref"
},
{
"_type": "Base.BaseDoc.BaseFlow.Comment",
"_id": {
"_id": "527a6b2701d418250767b133",
"__type__": "Base.ObjectId"
},
"_ns": "MyProject",
"_db": null,
"_lock": null,
"__type__": "Base.Ref"
},
],
},
"text": "Comment content text ...",
}
To copy to clipboard, switch view to plain text mode
##
#
# Proxy model that replaces Ref items
# with the actual referenced tree
#
def __init__(self, parent = None):
super(DocSolvedRefsProxyModel, self).__init__(parent = parent)
self._mappingTo = dict()
self._mappingFrom = dict()
return self.sourceModel().rowCount(self.mapToSource(index))
return self.sourceModel().columnCount(self.mapToSource(index))
def index
(self, row, column, parentIndex
= QModelIndex()): # to be implemented
def parent(self, childIndex=None):
if childIndex is None:
# Trying to get parent widget.
# Nothing to do with model / view.
# to be implemented
if not proxyIndex.isValid():
return self._mappingTo[proxyIndex]
if not sourceIndex.isValid():
if sourceIndex in self._mappingFrom:
return self._mappingFrom[sourceIndex]
else:
# checkin for refs & creating mapping
item = sourceIndex.internalPointer()
# Item.obj() method is used to get the actual object contained inside item.
obj = item.obj()
if isinstance(obj, Ref):
proxyIndex = ???
self._mappingTo[proxyIndex] = sourceIndex
self._mappingFrom[sourceIndex] = proxyIndex
##
#
# Proxy model that replaces Ref items
# with the actual referenced tree
#
class DocSolvedRefsProxyModel(QAbstractProxyModel):
def __init__(self, parent = None):
super(DocSolvedRefsProxyModel, self).__init__(parent = parent)
self._mappingTo = dict()
self._mappingFrom = dict()
def rowCount(self, index=QModelIndex()):
return self.sourceModel().rowCount(self.mapToSource(index))
def columnCount(self, index=QModelIndex()):
return self.sourceModel().columnCount(self.mapToSource(index))
def index(self, row, column, parentIndex = QModelIndex()):
# to be implemented
return QModelIndex()
def parent(self, childIndex=None):
if childIndex is None:
# Trying to get parent widget.
# Nothing to do with model / view.
return QObject.parent(self)
# to be implemented
return QModelIndex()
def mapToSource(self, proxyIndex=QModelIndex()):
if not proxyIndex.isValid():
return QModelIndex()
return self._mappingTo[proxyIndex]
def mapFromSource(self, sourceIndex=QModelIndex()):
if not sourceIndex.isValid():
return QModelIndex()
if sourceIndex in self._mappingFrom:
return self._mappingFrom[sourceIndex]
else:
# checkin for refs & creating mapping
item = sourceIndex.internalPointer()
# Item.obj() method is used to get the actual object contained inside item.
obj = item.obj()
if isinstance(obj, Ref):
proxyIndex = ???
self._mappingTo[proxyIndex] = sourceIndex
self._mappingFrom[sourceIndex] = proxyIndex
To copy to clipboard, switch view to plain text mode
Bookmarks