示例#1
0
 def columnCount(
     self,  # pylint: disable=missing-function-docstring
     parent: QModelIndex = QModelIndex()
 ) -> int:
     if parent.isValid():
         return 0
     return 3 + (1 if self.has_z else 0) + (1 if self.has_m else 0)
示例#2
0
    def rowCount(
        self,  # pylint: disable=missing-function-docstring
        parent: QModelIndex = QModelIndex()
    ) -> int:
        if parent.isValid():
            return 0

        if self.feature is None:
            return 0

        return len(self.vertices)
 def flags(self, index: QModelIndex) -> Qt.ItemFlags:
     """
     Item flags.
     """
     flags = super().flags(index)
     if index.isValid():
         return flags | \
             Qt.ItemIsDragEnabled | \
             Qt.ItemIsEnabled | \
             Qt.ItemIsSelectable
     return Qt.ItemIsDropEnabled
示例#4
0
    def _table_double_click(self, index: QModelIndex):
        """
        Triggered when the table is double-clicked
        """
        if not index.isValid():
            return

        point = self.vertex_model.data(index, VertexModel.VERTEX_POINT_ROLE)

        map_point = self.map_canvas.mapSettings().layerToMapCoordinates(
            self.layer, point)
        self.map_canvas.setCenter(QgsPointXY(map_point))
        self.map_canvas.refresh()
示例#5
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()
示例#6
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()
示例#7
0
    def default_tree_action(self, idx: QModelIndex):
        if not idx.isValid():
            return

        item = self.model.itemFromIndex(idx)
        item_data: ProjectTreeData = item.data(Qt.UserRole)

        # This is the default action for all add-able layers including basemaps
        if isinstance(item_data.data, QRaveMapLayer):
            if item_data.data.layer_type in [QRaveMapLayer.LayerTypes.FILE, QRaveMapLayer.LayerTypes.REPORT]:
                self.file_system_open(item_data.data.layer_uri)
            else:
                QRaveMapLayer.add_layer_to_map(item)

        # Expand is the default option for wms because we might need to load the layers
        elif isinstance(item_data.data, QRaveBaseMap):
            if item_data.data.tile_type == 'wms':
                pass
            # All the XYZ layers can be added normally.
            else:
                QRaveMapLayer.add_layer_to_map(item)

        elif item_data.type in [QRaveTreeTypes.PROJECT_ROOT]:
            self.change_meta(item, item_data, True)

        # For folder-y types we want Expand and contract is already implemented as a default
        elif item_data.type in [
            QRaveTreeTypes.PROJECT_FOLDER,
            QRaveTreeTypes.PROJECT_REPEATER_FOLDER,
            QRaveTreeTypes.PROJECT_VIEW_FOLDER,
            QRaveTreeTypes.BASEMAP_ROOT,
            QRaveTreeTypes.BASEMAP_SUPER_FOLDER,
            QRaveTreeTypes.BASEMAP_SUB_FOLDER
        ]:
            # print("Default Folder Action")
            pass

        elif item_data.type == QRaveTreeTypes.PROJECT_VIEW:
            print("Default View Action")
            self.add_view_to_map(item_data)
    def data(self, index: QModelIndex, role=Qt.DisplayRole) -> Union[
            str, QIcon, None]:
        """
        Returns data from the table cell?
        """
        if not index.isValid() or not 0 <= index.row() < self.rowCount():
            return None

        row = index.row()

        if role == Qt.DisplayRole:
            return self.tab[row][1]
        elif role == Qt.DecorationRole:
            if self.tab[row][0] == 'geometry':
                icon = QIcon(':/plugins/groupstats/icons/geom.png')
            elif self.tab[row][0] == 'calculation':
                icon = QIcon(':/plugins/groupstats/icons/calc.png')
            elif self.tab[row][0] == 'text':
                icon = QIcon(':/plugins/groupstats/icons/alpha.png')
            else:
                icon = QIcon(':/plugins/groupstats/icons/digits.png')
            return icon

        return None
示例#9
0
 def on_selection_changed(self, index: QModelIndex):
     self.remove_tool_button.setEnabled(index.isValid())
 def remove_custom_aggregate(self, index: QModelIndex):
     if not index.isValid():
         return
     self.beginRemoveRows(QModelIndex(), index.row(), index.row())
     del self.custom_aggregates[index.row()]
     self.endRemoveRows()
示例#11
0
    def data(self, index: QModelIndex,
             role: Qt.ItemDataRole = Qt.DisplayRole) -> Union[
                 None, QBrush, QFont, Qt.AlignmentFlag, str]:
        """
        Returns data from the table cell?
        """
        if not index.isValid() or not 0 <= index.row() < self.rowCount():
            return None

        row = index.row() - self.offsetY
        column = index.column() - self.offsetX

        if role == Qt.DisplayRole:
            # Table cell data
            if row >= 0 and column >= 0:
                return self.tab[row][column][0]
            # Row descriptions?
            elif column < 0 and row >= 0 and self.rows[0]:
                return self.rows[row + 1][column]
            # Row title field?
            elif row == -1 and column < 0 and self.rows[0]:
                return self.rows[0][column]
            # Column description and names?
            elif column >= -1 and row < 0 and self.columns[0]:
                if self.rows[0]:
                    # Break line?
                    if row == -1:
                        return ''
                    # Descriptions and column names if there is a break line?
                    return self.columns[column + 1][row + 1]
                # Column descriptions and names if there is no break line?
                return self.columns[column + 1][row]

        elif role == Qt.UserRole:
            if row >= 0 and column >= 0:
                return self.tab[row][column][1]

        elif role == Qt.UserRole + 1:
            if row < 0 and column >= 0:
                return 'column'
            elif row >= 0 and column < 0:
                return 'row'
            elif row >= 0 and column >= 0:
                return 'data'

        # Cell filling
        elif role == Qt.BackgroundRole:
            if row < 0 or column < 0:
                # Gray for cells with descriptions and names
                color = QColor(245, 235, 235)
                brush = QBrush(color)
                return brush

        elif role == Qt.TextAlignmentRole:
            if column < 0 and row < -1 and self.rows:
                return Qt.AlignRight | Qt.AlignVCenter
            elif column >= 0 and row < 0:
                return Qt.AlignHCenter | Qt.AlignVCenter
            elif column >= 0 and row >= 0:
                return Qt.AlignRight | Qt.AlignVCenter

        elif role == Qt.FontRole:
            if row < 0 and column < 0:
                font = QFont()
                font.setBold(True)
                return font

        return None