def data(
            self,  # pylint: disable=missing-function-docstring, too-many-return-statements
            index: QModelIndex,
            role: int = Qt.DisplayRole):
        if index.row() < 0 or index.row() >= len(self.vertices):
            return None

        if role in (Qt.DisplayRole, Qt.ToolTipRole, Qt.EditRole):
            if index.column() == VertexModel.COLUMN_ID:
                return index.row() + 1

            context = QgsNumericFormatContext()
            if index.column() == VertexModel.COLUMN_X:
                return self.number_format.formatDouble(
                    self.vertices[index.row()][1].x(), context)
            if index.column() == VertexModel.COLUMN_Y:
                return self.number_format.formatDouble(
                    self.vertices[index.row()][1].y(), context)
            if index.column() == VertexModel.COLUMN_Y + 1 and self.has_z:
                return self.number_format.formatDouble(
                    self.vertices[index.row()][1].z(), context)

            return self.number_format.formatDouble(
                self.vertices[index.row()][1].m(), context)

        if role == VertexModel.VERTEX_NUMBER_ROLE:
            return index.row() + 1
        if role == VertexModel.VERTEX_POINT_ROLE:
            return self.vertices[index.row()][1]

        return None
    def data(self, index: QModelIndex, role: int = ...):
        if index.row() < 0 or index.row() >= self.rowCount(QModelIndex()):
            return None

        if role == Qt.DisplayRole:
            if index.column() == Column.TitleColumn.value:
                return self.custom_aggregates[index.row()].title
            if index.column() == Column.RelationColumn.value:
                return self.custom_aggregates[index.row()].relation_name()
            if index.column() == Column.AggregateColumn.value:
                return self.custom_aggregates[index.row()].aggregate
            if index.column() == Column.FieldColumn.value:
                return self.custom_aggregates[index.row()].field

        if role == Qt.EditRole and index.column() == Column.TitleColumn.value:
            return self.custom_aggregates[index.row()].title

        if role == Role.RelationRole.value:
            return self.custom_aggregates[index.row()].relation()

        if role == Role.RelationIdRole.value:
            return self.custom_aggregates[index.row()].relation_id

        if role == Role.AggregateRole.value:
                return self.custom_aggregates[index.row()].aggregate

        if role == Role.FieldRole.value:
            return self.custom_aggregates[index.row()].field

        return None
Exemple #3
0
 def createEditor(self, parent, option, index: QModelIndex):
     fc = QgsFieldComboBox(parent)
     relation = index.model().data(index, Role.RelationRole.value)
     print('hey', relation, index.column())
     if relation:
         fc.setLayer(relation.referencingLayer())
     return fc
    def setData(self, index: QModelIndex, value, role: int = Qt.EditRole) -> bool:
        if index.row() < 0 or index.row() >= self.rowCount(QModelIndex()):
            return False

        if index.column() == Column.TitleColumn.value:
            self.custom_aggregates[index.row()].title = value
            return True

        if index.column() == Column.RelationColumn.value:
            self.custom_aggregates[index.row()].relation_id = value
            return True

        if index.column() == Column.AggregateColumn.value:
            self.custom_aggregates[index.row()].aggregate = value
            return True

        if index.column() == Column.FieldColumn.value:
            self.custom_aggregates[index.row()].field = value
            return True

        return False
Exemple #5
0
    def dataChanged(self, t_l: QModelIndex, b_r: QModelIndex,
                    roles: Optional[List[int]] = None) -> None:

        # This may need to go at end of slot
        super().dataChanged(t_l, b_r, roles=roles)

        # Note: empty roles indicates *everything* has changed, not nothing
        if roles is not None and (roles == [] or Qt.CheckStateRole in roles):
            if LOG_VERBOSE:
                log.debug('Node (un)checked')
            checked = set()
            unchecked = set()

            def update_queues(indx):
                node: PlanetNode = self._search_model.get_node(indx)
                if node.is_base_image() and node.can_be_downloaded():
                    if node.checked_state() == Qt.Checked:
                        checked.add(node)
                    elif node.checked_state() == Qt.Unchecked:
                        unchecked.add(node)

            # Note: if parent of t_l and b_r differ, we ignore undefined input
            if t_l == b_r:
                if LOG_VERBOSE:
                    log.debug('Nodes (un)checked is single')
                update_queues(t_l)
            elif t_l.parent() == b_r.parent():
                if LOG_VERBOSE:
                    log.debug('Nodes (un)checked have same parent')
                parent = t_l.parent()
                col = t_l.column()
                for row in range(b_r.row(), t_l.row() + 1):
                    m_indx = self._search_model.index(row, col, parent=parent)
                    update_queues(m_indx)

            if checked or unchecked:
                if LOG_VERBOSE:
                    log.debug(f'Nodes checked: {checked}')
                    log.debug(f'Nodes unchecked: {unchecked}')
                self._update_checked_queue(checked, unchecked)
    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