예제 #1
0
    def on_style_edit(self):
        # QgsRenderV2PropertiesDialog has a Cancel button that is not correctly plugged
        # rewrap the widget with a buttonbox
        dlg = QDialog(self)

        dlg.layout = QVBoxLayout(dlg)
        dlg.widget = QgsRendererPropertiesDialog(
            self.parameters.layer, self.style, True
        )
        dlg.widget.setLayout(dlg.layout)
        dlg.buttons = QDialogButtonBox(dlg)

        dlg.layout.addWidget(dlg.widget)
        dlg.layout.addWidget(dlg.buttons)

        dlg.buttons.setOrientation(Qt.Horizontal)
        dlg.buttons.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok)

        def on_style_edit_accept(d):
            # this will update the layer's style
            dlg.widget.onOK()
            dlg.accept()

        dlg.buttons.accepted.connect(lambda d=dlg: on_style_edit_accept(d))
        dlg.buttons.rejected.connect(dlg.reject)

        r = dlg.exec_()
        if r == 1:
            self.update_style_preview(self.parameters.layer)
    def layer_properties(self):
        layer = self.view.currentLayer()
        # if it is a vector layer and has a valid geometry
        if layer.type() == 0 and layer.geometryType() not in [3, 4]:
            # wrap style dialog with the buttons ok and cancel so that we can apply changes
            dlg = QDialog()
            dlg.widget = QgsRendererPropertiesDialog(self.view.currentLayer(),
                                                     QgsStyle.defaultStyle(),
                                                     True)
            dlg.layout = QVBoxLayout(dlg)
            dlg.buttons = QDialogButtonBox(dlg)
            dlg.layout.addWidget(dlg.widget)
            dlg.layout.addWidget(dlg.buttons)
            dlg.buttons.setOrientation(Qt.Horizontal)
            dlg.buttons.setStandardButtons(QDialogButtonBox.Cancel
                                           | QDialogButtonBox.Ok)

            # set signals
            def on_style_edit_accept(d):
                # this will update the layer's style
                dlg.widget.onOK()
                dlg.accept()

            dlg.buttons.accepted.connect(lambda d=dlg: on_style_edit_accept(d))
            dlg.buttons.rejected.connect(dlg.reject)
            dlg.exec_()
            self.canvas.refresh()
        elif layer.type() == 1 and layer.rasterType() != 2:
            dlg = QDialog()
            dlg.widget = QgsSingleBandPseudoColorRendererWidget(layer)
            dlg.layout = QVBoxLayout(dlg)
            dlg.buttons = QDialogButtonBox(dlg)
            dlg.layout.addWidget(dlg.widget)
            dlg.layout.addWidget(dlg.buttons)
            dlg.buttons.setOrientation(Qt.Horizontal)
            dlg.buttons.setStandardButtons(QDialogButtonBox.Cancel
                                           | QDialogButtonBox.Ok)

            # set signals
            def on_rasterstyle_edit_accept(d):
                # this will update the layer's style
                renderer = dlg.widget.renderer()
                layer.setRenderer(renderer)
                dlg.accept()

            dlg.buttons.accepted.connect(
                lambda d=dlg: on_rasterstyle_edit_accept(d))
            dlg.buttons.rejected.connect(dlg.reject)
            dlg.exec_()
            self.canvas.refresh()
        elif layer.type() == 1 and layer.rasterType() == 2:
            logger.info("multiband")
예제 #3
0
    def setSelectedLayerStyleWidget(self, layerType, selected, unselected):
        """
        Get selected layer and display the corresponding style widget
        in the right panel
        """
        lt = self.layersTable[layerType]
        table = lt['tableWidget']
        sm = table.selectionModel()
        lines = sm.selectedRows()
        showStyle = True

        # Empty label widget if style must not been displayed
        w = QLabel()
        w.setText('')
        layer = None

        # Refresh Style tab
        if len(lines) != 1:
            showStyle = False

        if showStyle:
            row = lines[0].row()

            # Get layer
            layerId = table.item(row, 0).data(Qt.EditRole)
            lr = QgsProject.instance()
            layer = lr.mapLayer(layerId)
            if not layer:
                showStyle = False
            else:
                self.styleLayer = layer

        if showStyle and layer:
            # Choose widget depending on layer
            if layer.type() == 0 and layer.geometryType() not in [3, 4]:
                w = QgsRendererPropertiesDialog(layer, QgsStyle.defaultStyle(), True)

        # Make the widget visible
        self.styleWidget = w
        self.styleLayer = layer
        self.dlg.styleScrollArea.setWidget(w)
예제 #4
0
    def __init__(self, layer, canvas, parent=None):
        QDialog.__init__(self)
        self.setupUi(self)
        self.layer = layer

        self.setWindowTitle("{} - style editor".format(self.layer.name()))

        if self.layer.type() == QgsMapLayer.VectorLayer:
            self.StyleEditorWidget = QgsRendererPropertiesDialog(
                self.layer, QgsStyle(), True, parent)

        if self.layer.type() == QgsMapLayer.RasterLayer:
            self.StyleEditorWidget = QgsRendererRasterPropertiesWidget(
                self.layer, canvas, parent)

        self.scrollArea.setWidget(self.StyleEditorWidget)

        self.DialogButtons.button(QDialogButtonBox.Cancel).clicked.connect(
            self.reject)
        self.DialogButtons.button(QDialogButtonBox.Ok).clicked.connect(
            self.accept)
        self.DialogButtons.button(QDialogButtonBox.Apply).clicked.connect(
            self.apply)