示例#1
0
    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())
示例#2
0
    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())
示例#3
0
    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()
示例#4
0
文件: db_model.py 项目: pcav/QGIS-1
    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()
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
 def parentFromIndex(self, index):
     index = QModelIndex(
         index)  # explicitly convert from QPersistentModelIndex
     if index.isValid():
         return index.internalPointer()
     return self._root
示例#8
0
 def itemFromIndex(self, index):
     index = QModelIndex(
         index)  # explicitly convert from QPersistentModelIndex
     if index.isValid():
         return index.internalPointer().childAt(index.row())
     return self._root
示例#9
0
    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)
示例#10
0
文件: model.py 项目: cvhciKIT/sloth
 def parentFromIndex(self, index):
     index = QModelIndex(index)  # explicitly convert from QPersistentModelIndex
     if index.isValid():
         return index.internalPointer()
     return self._root
示例#11
0
文件: model.py 项目: cvhciKIT/sloth
 def itemFromIndex(self, index):
     index = QModelIndex(index)  # explicitly convert from QPersistentModelIndex
     if index.isValid():
         return index.internalPointer().childAt(index.row())
     return self._root