def rowCount(self, parent): if parent is None: parent = QModelIndex() if parent.column() > 0: return 0 if not parent.isValid(): return len(self.__root) else: return len(parent.internalPointer())
def _rItem2Index(self, item, parent=None): if parent is None: parent = QModelIndex() if item == self.getItem(parent): return parent if not parent.isValid() or parent.internalPointer().populated: for i in range(self.rowCount(parent)): index = self.index(i, 0, parent) index = self._rItem2Index(item, index) if index.isValid(): return index return QModelIndex()
def index(self, row, column, parent=None): if parent is None: parent = QModelIndex() if not self.hasIndex(row, column, parent): return QModelIndex() if not parent.isValid(): parent_item = self.__root else: parent_item = parent.internalPointer() child_item = parent_item.child(row) return self.createIndex(row, column, child_item)
def parentFromIndex(self, index): index = QModelIndex( index) # explicitly convert from QPersistentModelIndex if index.isValid(): return index.internalPointer() return self._root
def itemFromIndex(self, index): index = QModelIndex( index) # explicitly convert from QPersistentModelIndex if index.isValid(): return index.internalPointer().childAt(index.row()) return self._root
def processJobResult(self, job): log("processJobResult job: %s" % job.getJobId()) job_result = job.getResult() if job_result is None: # TODO Exception self._releaseIndexesByJob(job) return indexes = {} for ngw_resource in job_result.added_resources: if ngw_resource.common.parent is None: index = QModelIndex() new_index = self.addNGWResourceToTree(index, ngw_resource) else: index = indexes.get(ngw_resource.common.parent.id) if index is None: index = self.getIndexByNGWResourceId( ngw_resource.common.parent.id, self.index(0, 0, QModelIndex())) indexes[ngw_resource.common.parent.id] = index item = index.internalPointer() current_ids = [ item.child(i).ngw_resource_id() for i in range(0, item.childCount()) if isinstance(item.child(i), QNGWResourceItem) ] if ngw_resource.common.id not in current_ids: new_index = self.addNGWResourceToTree(index, ngw_resource) else: continue if job_result.main_resource_id == ngw_resource.common.id: if job.model_response is not None: job.model_response.done.emit(new_index) for ngw_resource in job_result.edited_resources: index = self.getIndexByNGWResourceId( ngw_resource.common.parent.id, self.index(0, 0, QModelIndex())) item = index.internalPointer() for i in range(0, item.childCount()): if item.child(i).ngw_resource_id() == ngw_resource.common.id: self.beginRemoveRows(index, i, i) item.removeChild(item.child(i)) self.endRemoveRows() break else: # TODO exception: not find deleted resource in corrent tree self._releaseIndexesByJob(job) return new_index = self.addNGWResourceToTree(index, ngw_resource) if job.model_response is not None: job.model_response.done.emit(new_index) for ngw_resource in job_result.deleted_resources: # log(">>> delete ngw_resource: " + str(ngw_resource)) index = self.getIndexByNGWResourceId( ngw_resource.common.parent.id, self.index(0, 0, QModelIndex())) item = index.internalPointer() for i in range(0, item.childCount()): if item.child(i).ngw_resource_id() == ngw_resource.common.id: self.beginRemoveRows(index, i, i) item.removeChild(item.child(i)) self.endRemoveRows() break else: # TODO exception: not find deleted resource in corrent tree self._releaseIndexesByJob(job) return ngw_resource = item.data(0, QNGWResourceItem.NGWResourceRole) ngw_resource.update() if job.model_response is not None: job.model_response.done.emit(index) self._releaseIndexesByJob(job)
def parentFromIndex(self, index): index = QModelIndex(index) # explicitly convert from QPersistentModelIndex if index.isValid(): return index.internalPointer() return self._root
def itemFromIndex(self, index): index = QModelIndex(index) # explicitly convert from QPersistentModelIndex if index.isValid(): return index.internalPointer().childAt(index.row()) return self._root