Example #1
0
    def __init__(self, show_marker_count=False, show_orientation=False, show_placement=False, parent=None):
        super(MarkerSettingsWidget, self).__init__(parent)
        self.setupUi(self)

        self.code_combo.setEditable(True)
        self.code_combo.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred)
        self.code_combo.setMinimumWidth(QFontMetrics(self.font()).width('X') * 40)

        self.field_code_combo.setAllowEmptyFieldName(True)

        self.field_rotation_combo.setFilters(QgsFieldProxyModel.Numeric)
        self.field_rotation_combo.setAllowEmptyFieldName(True)

        self.setFocusProxy(self.field_code_combo)

        self.field_code_combo.fieldChanged.connect(self.field_code_changed)
        self.field_rotation_combo.fieldChanged.connect(self.field_rotation_changed)
        self.code_combo.currentTextChanged.connect(self.on_code_changed)
        self.marker_count_spin.valueChanged.connect(self.marker_count_changed)
        self.marker_distance_spin.valueChanged.connect(self.marker_distance_changed)

        if not show_marker_count:
            self.marker_count_label.setVisible(False)
            self.marker_count_spin.setVisible(False)
            self.spacing_label.setVisible(False)
            self.spacing_combo.setVisible(False)
            self.spacing_stacked_widget.setVisible(False)
        if not show_orientation:
            self.orientation_label.setVisible(False)
            self.orientation_combo.setVisible(False)
        if not show_placement:
            self.placement_label.setVisible(False)
            self.placement_combo.setVisible(False)

        self.orientation_combo.addItem("0°", 0.0)
        self.orientation_combo.addItem("90°", 90.0)
        self.orientation_combo.addItem("180°", 180.0)
        self.orientation_combo.addItem("270°", 270.0)

        self.placement_combo.addItem(GuiUtils.get_icon('include_endpoints.svg'), self.tr('Include Endpoints'), True)
        self.placement_combo.addItem(GuiUtils.get_icon('exclude_endpoints.svg'), self.tr('Exclude Endpoints'), False)

        self.spacing_combo.addItem(self.tr('Via Count'), 0)
        self.spacing_combo.addItem(self.tr('Via Distance'), 1)

        self.orientation_combo.currentIndexChanged.connect(self.on_orientation_changed)
        self.placement_combo.currentIndexChanged.connect(self.on_placement_changed)
        self.spacing_combo.currentIndexChanged.connect(self.on_spacing_changed)

        self.marker_count_spin.setMinimum(2)

        self.layer = None
    def designer_opened(self, designer: QgsLayoutDesignerInterface):
        """
        Called whenever a new layout designer window is opened
        """
        toggle_unplaced_labels_action = QAction(
            self.tr('Show Unplaced Labels on Maps'), parent=designer)
        toggle_unplaced_labels_action.setCheckable(True)
        toggle_unplaced_labels_action.setIcon(
            GuiUtils.get_icon('show_unplaced_labels.svg'))

        # determine initial check state
        layout = designer.layout()
        maps = [
            item for item in layout.items()
            if isinstance(item, QgsLayoutItemMap)
        ]
        initial_checked = bool(maps) and all(
            m.mapFlags() & QgsLayoutItemMap.ShowUnplacedLabels for m in maps)
        toggle_unplaced_labels_action.setChecked(initial_checked)
        toggle_unplaced_labels_action.toggled.connect(
            partial(self.toggle_unplaced_labels, designer))
        toggle_unplaced_labels_action.setShortcut(QKeySequence('Ctrl+Shift+U'))

        tb = designer.actionsToolbar()
        tb.addSeparator()
        tb.addAction(toggle_unplaced_labels_action)
        designer.viewMenu().addSeparator()
        designer.viewMenu().addAction(toggle_unplaced_labels_action)
    def create_tools(self):
        """
        Creates all map tools ands add them to the QGIS interface
        """
        action_single_point_templated_marker = QAction(
            GuiUtils.get_icon('single_point_templated_marker.svg'),
            self.tr('Single Point Templated Marker'))
        action_single_point_templated_marker.setCheckable(True)
        self.tools[SinglePointTemplatedMarkerTool.
                   ID] = SinglePointTemplatedMarkerTool(
                       self.iface.mapCanvas(), self.iface.cadDockWidget(),
                       self.iface, action_single_point_templated_marker)
        self.tools[SinglePointTemplatedMarkerTool.ID].setAction(
            action_single_point_templated_marker)
        action_single_point_templated_marker.triggered.connect(
            partial(self.switch_tool, SinglePointTemplatedMarkerTool.ID))
        action_single_point_templated_marker.setData(
            SinglePointTemplatedMarkerTool.ID)
        self.toolbar.addAction(action_single_point_templated_marker)
        self.actions.append(action_single_point_templated_marker)

        self.get_map_tool_action_group().addAction(
            action_single_point_templated_marker)

        # single point at center of line tool

        action_single_point_at_center_of_line = QAction(
            GuiUtils.get_icon('marker_at_center_of_line.svg'),
            self.tr('Single Point Templated Marker Via Two Points'))
        action_single_point_at_center_of_line.setCheckable(True)
        self.tools[
            TwoPointTemplatedMarkerTool.ID] = TwoPointTemplatedMarkerTool(
                self.iface.mapCanvas(), self.iface.cadDockWidget(), self.iface,
                action_single_point_at_center_of_line)
        self.tools[TwoPointTemplatedMarkerTool.ID].setAction(
            action_single_point_at_center_of_line)
        action_single_point_at_center_of_line.triggered.connect(
            partial(self.switch_tool, TwoPointTemplatedMarkerTool.ID))
        action_single_point_at_center_of_line.setData(
            TwoPointTemplatedMarkerTool.ID)
        self.toolbar.addAction(action_single_point_at_center_of_line)
        self.actions.append(action_single_point_at_center_of_line)

        self.get_map_tool_action_group().addAction(
            action_single_point_at_center_of_line)

        # multi point tool

        action_multi_point_templated_marker = QAction(
            GuiUtils.get_icon('multi_point_templated_marker.svg'),
            self.tr('Multiple Point Templated Marker Along LineString'))
        action_multi_point_templated_marker.setCheckable(True)
        self.tools[
            MultiPointTemplatedMarkerTool.ID] = MultiPointTemplatedMarkerTool(
                self.iface.mapCanvas(), self.iface.cadDockWidget(), self.iface,
                action_multi_point_templated_marker)
        self.tools[MultiPointTemplatedMarkerTool.ID].setAction(
            action_multi_point_templated_marker)
        action_multi_point_templated_marker.triggered.connect(
            partial(self.switch_tool, MultiPointTemplatedMarkerTool.ID))
        action_multi_point_templated_marker.setData(
            MultiPointTemplatedMarkerTool.ID)
        self.toolbar.addAction(action_multi_point_templated_marker)
        self.actions.append(action_multi_point_templated_marker)

        self.get_map_tool_action_group().addAction(
            action_single_point_templated_marker)

        # multi at center of segment point tool

        action_multi_point_center_segment_templated_marker = QAction(
            GuiUtils.get_icon('multi_point_templated_marker_at_center.svg'),
            self.tr('Multiple Point Templated Marker At Center Of Segments'))
        action_multi_point_center_segment_templated_marker.setCheckable(True)
        self.tools[MultiPointSegmentCenterTemplatedMarkerTool.
                   ID] = MultiPointSegmentCenterTemplatedMarkerTool(
                       self.iface.mapCanvas(), self.iface.cadDockWidget(),
                       self.iface,
                       action_multi_point_center_segment_templated_marker)
        self.tools[MultiPointSegmentCenterTemplatedMarkerTool.ID].setAction(
            action_multi_point_center_segment_templated_marker)
        action_multi_point_center_segment_templated_marker.triggered.connect(
            partial(self.switch_tool,
                    MultiPointSegmentCenterTemplatedMarkerTool.ID))
        action_multi_point_center_segment_templated_marker.setData(
            MultiPointSegmentCenterTemplatedMarkerTool.ID)
        self.toolbar.addAction(
            action_multi_point_center_segment_templated_marker)
        self.actions.append(action_multi_point_center_segment_templated_marker)

        self.get_map_tool_action_group().addAction(
            action_single_point_templated_marker)

        self.enable_actions_for_layer(self.iface.activeLayer())
 def testGetIcon(self):
     """
     Tests get_icon
     """
     self.assertFalse(GuiUtils.get_icon('plugin.svg').isNull())
     self.assertTrue(GuiUtils.get_icon('not_an_icon.svg').isNull())
 def icon(self):
     """
     Returns the provider's icon
     """
     return GuiUtils.get_icon("plugin.svg")