Пример #1
0
    def _vertex_selection_changed(self):
        """
        Triggered when the selected vertex is changed
        """
        selection = self.table_view.selectionModel().selectedIndexes()
        vertex_number = None
        if selection:
            selected_index = self.vertex_model.index(
                self.table_view.selectionModel().selectedIndexes()[0].row(), 0)
            if selected_index.isValid():
                vertex_number = self.vertex_model.data(
                    selected_index, VertexModel.VERTEX_NUMBER_ROLE)

                point = self.vertex_model.data(selected_index,
                                               VertexModel.VERTEX_POINT_ROLE)
                map_point = self.map_canvas.mapSettings(
                ).layerToMapCoordinates(self.layer, point)

                if SettingsRegistry.center_on_selected():
                    self.map_canvas.setCenter(QgsPointXY(map_point))
                    self.map_canvas.refresh()

                if SettingsRegistry.flash_vertex():
                    geom = QgsGeometry(map_point)
                    self.map_canvas.flashGeometries([geom])

        feature_id = None
        if self.vertex_model.feature is not None:
            feature_id = self.vertex_model.feature.id()

        self.selected_vertex_changed.emit(feature_id, vertex_number)
Пример #2
0
 def _label_filter_changed(self, _: int):
     """
     Called when the label filter combobox value is changed
     """
     SettingsRegistry.set_label_filtering(
         int(self.filtering_combo.currentData())
     )
     self.label_filter_changed.emit()
Пример #3
0
 def __init__(self, parent: QObject = None):
     super().__init__(parent)
     self.feature: Optional[QgsFeature] = None
     self.vertices: List[Union[QgsVertexId, QgsPoint]] = []
     self.has_z = False
     self.has_m = False
     self.number_format = SettingsRegistry.number_format()
    def set_selected_vertex(self, feature_id: Optional[int],
                            vertex_number: Optional[int]):
        """
        Triggered when the selected vertex is changed
        """
        if self.current_vertex_number == vertex_number and self.current_feature_id == feature_id:
            return

        needs_redraw = SettingsRegistry.label_filtering() == SettingsRegistry.LABEL_SELECTED or \
                       (
                                   SettingsRegistry.label_filtering() == SettingsRegistry.LABEL_ALL and feature_id != self.current_feature_id)

        self.current_feature_id = feature_id
        self.current_vertex_number = vertex_number
        self._remove_current_generator()
        self._reset_generator(not needs_redraw)
Пример #5
0
 def number_format_changed(self):
     """
     Called when the predefined number format is changed, and we need to update everything
     """
     self.number_format = SettingsRegistry.number_format()
     self.dataChanged.emit(
         self.index(0, 0),
         self.index(self.rowCount() - 1,
                    self.columnCount() - 1))
    def __init__(self,
                 source: QgsFeatureSource,
                 layer_type: QgsWkbTypes.GeometryType,
                 selection: list,
                 vertex_number=Optional[int],
                 topological_geometries: Optional[Dict[int,
                                                       QgsGeometry]] = None):
        if layer_type == QgsWkbTypes.LineGeometry:
            symbol = QgsLineSymbol()
        else:
            symbol = QgsFillSymbol()

        marker_line = QgsMarkerLineSymbolLayer()
        marker_line.setRotateMarker(False)
        marker_line.setPlacement(QgsMarkerLineSymbolLayer.Vertex)

        vertex_marker_symbol = SettingsRegistry.vertex_symbol()
        # not so nice, but required to allow us to dynamically change this color mid-way through rendering
        for layer in vertex_marker_symbol:
            layer.setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor,
                                         QgsProperty.fromValue(None))

        font_marker_symbol = QgsMarkerSymbol()

        text_format = SettingsRegistry.vertex_format()
        font_marker = TextRendererMarkerSymbolLayer(text_format, vertex_number)
        font_marker.setSubSymbol(vertex_marker_symbol)

        font_marker_symbol.changeSymbolLayer(0, font_marker)
        marker_line.setSubSymbol(font_marker_symbol)

        symbol.changeSymbolLayer(0, marker_line)

        symbol.setClipFeaturesToExtent(False)

        super().__init__(symbol)

        self.selection = sorted(selection)
        self.feature_index = 0
        self.vertex_number = vertex_number
        self.source = source

        self.topological_geometries = topological_geometries
Пример #7
0
    def restore_settings(self):
        """
        Restores saved settings
        """
        current_label_filter = SettingsRegistry.label_filtering()
        self.filtering_combo.setCurrentIndex(self.filtering_combo.findData(current_label_filter))
        self.check_center_on_selection.setChecked(SettingsRegistry.center_on_selected())
        self.check_flash_feature.setChecked(SettingsRegistry.flash_feature())
        self.check_flash_vertex.setChecked(SettingsRegistry.flash_vertex())

        self.point_symbol_button.setSymbol(SettingsRegistry.vertex_symbol())
        self.vertex_font_button.setTextFormat(SettingsRegistry.vertex_format())
        self.number_format = SettingsRegistry.number_format()
Пример #8
0
    def _active_feature_changed(self):
        """
        Triggered when the active feature is changed
        """
        if self._block_feature_changes:
            return

        selected_index = self.feature_model.index(
            self.feature_combo.currentIndex(), 0)
        if selected_index.isValid():
            feature = self.feature_model.data(selected_index,
                                              FeatureModel.FEATURE_ROLE)
            changed = self.vertex_model.feature is None or feature is None or self.vertex_model.feature.id(
            ) != feature.id()
            self.vertex_model.set_feature(feature)

            if feature is not None:
                self.label_part_count.setText(
                    str(feature.geometry().constGet().numGeometries(
                    ) if feature.geometry().isMultipart() else 1))
                self.label_vertex_count.setText(
                    str(feature.geometry().constGet().nCoordinates()))
                self.label_geometry_type.setText(
                    QgsWkbTypes.translatedDisplayString(
                        feature.geometry().wkbType()))
                self.button_zoom.setEnabled(True)
            else:
                self.label_geometry_type.clear()
                self.label_part_count.clear()
                self.label_vertex_count.clear()
                self.button_zoom.setEnabled(False)

            if changed and feature is not None and SettingsRegistry.flash_feature(
            ):
                self.map_canvas.flashGeometries([feature.geometry()],
                                                self.layer.crs())

        else:
            self.vertex_model.set_feature(None)
            self.label_geometry_type.clear()
            self.label_part_count.clear()
            self.label_vertex_count.clear()
            self.button_zoom.setEnabled(False)

        self._vertex_selection_changed()
Пример #9
0
    def _zoom_to_feature(self):
        """
        Zooms to the extent of the selected feature
        """
        selected_index = self.feature_model.index(
            self.feature_combo.currentIndex(), 0)
        if selected_index.isValid():
            feature = self.feature_model.data(selected_index,
                                              FeatureModel.FEATURE_ROLE)

            ct = QgsCoordinateTransform(
                self.layer.crs(),
                self.map_canvas.mapSettings().destinationCrs(),
                QgsProject.instance())
            try:
                bounds = ct.transformBoundingBox(
                    feature.geometry().boundingBox())
                self.map_canvas.zoomToFeatureExtent(bounds)
                if SettingsRegistry.flash_feature():
                    self.map_canvas.flashGeometries([feature.geometry()],
                                                    self.layer.crs())
            except QgsCsException:
                pass
Пример #10
0
    def createRenderer(self) -> QgsSingleSymbolRenderer:  # pylint: disable=missing-function-docstring
        filtering = SettingsRegistry.label_filtering()

        topological = self.topological and self.layer.selectedFeatureCount(
        ) == 2

        if filtering == SettingsRegistry.LABEL_NONE:
            return QgsNullSymbolRenderer()
        if filtering == SettingsRegistry.LABEL_SELECTED:
            if self.feature_id is None or self.vertex_number is None:
                # labeling selected vertex only, and no selection => no renderer
                return QgsNullSymbolRenderer()
            selection = {self.feature_id}
            vertex_number = self.vertex_number
        else:
            selection = self.layer.selectedFeatureIds()
            vertex_number = None

        if topological:
            request = QgsFeatureRequest().setFilterFids(
                self.layer.selectedFeatureIds()).setNoAttributes()
            topological_geometries = {
                f.id(): f.geometry()
                for f in self.layer.getFeatures(request)
            }
        else:
            topological_geometries = None

        layer_source = QgsVectorLayerFeatureSource(self.layer)

        return VertexHighlighterRenderer(
            source=layer_source,
            layer_type=self.layer_type,
            selection=selection,
            vertex_number=vertex_number,
            topological_geometries=topological_geometries,
        )
Пример #11
0
 def _vertex_format_changed(self):
     """
     Called when the vertex text format is changed
     """
     SettingsRegistry.set_vertex_format(self.vertex_font_button.textFormat())
     self.vertex_text_format_changed.emit()
Пример #12
0
    def _reset_settings(self):
        """
        Resets settings to their defaults
        """
        self.point_symbol_button.setSymbol(SettingsRegistry.default_vertex_symbol())
        SettingsRegistry.set_vertex_symbol(SettingsRegistry.default_vertex_symbol())

        self.vertex_font_button.setTextFormat(SettingsRegistry.default_vertex_format())
        SettingsRegistry.set_vertex_format(SettingsRegistry.default_vertex_format())

        self.number_format = SettingsRegistry.default_number_format()
        SettingsRegistry.set_number_format(self.number_format)

        SettingsRegistry.set_center_on_selected(False)
        self.check_center_on_selection.setChecked(False)
        self.check_flash_feature.setChecked(False)
        self.check_flash_vertex.setChecked(True)

        self.vertex_symbol_changed.emit()
        self.vertex_text_format_changed.emit()
        self.number_format_changed.emit()
Пример #13
0
 def _flash_vertex_changed(self):
     """
     Triggered when the flash vertex option is toggled
     """
     SettingsRegistry.set_flash_vertex(self.check_flash_vertex.isChecked())
Пример #14
0
 def _flash_feature_changed(self):
     """
     Triggered when the flash feature option is toggled
     """
     SettingsRegistry.set_flash_feature(self.check_flash_feature.isChecked())
Пример #15
0
 def _center_on_selected_changed(self):
     """
     Triggered when the center on selection option is toggled
     """
     SettingsRegistry.set_center_on_selected(self.check_center_on_selection.isChecked())
Пример #16
0
 def _on_changed():
     self.number_format = format_widget.format()
     SettingsRegistry.set_number_format(self.number_format)
     self.number_format_changed.emit()
Пример #17
0
 def _point_symbol_changed(self):
     """
     Called when the marker symbol type is changed
     """
     SettingsRegistry.set_vertex_symbol(self.point_symbol_button.symbol())
     self.vertex_symbol_changed.emit()