Esempio n. 1
0
    def showLayerSelectionDialog(self):
        if (isinstance(self.param, ParameterRaster) or
                (isinstance(self.param, ParameterMultipleInput) and
                 self.param.datatype == dataobjects.TYPE_RASTER)):
            layers = dataobjects.getRasterLayers()
        elif isinstance(self.param, ParameterTable):
            layers = dataobjects.getTables()
        else:
            if isinstance(self.param, ParameterVector):
                datatype = self.param.datatype
            else:
                datatype = [self.param.datatype]
            layers = dataobjects.getVectorLayers(datatype)

        dlg = MultipleInputDialog([layer.name() for layer in layers])
        dlg.exec_()
        if dlg.selectedoptions is not None:
            selected = dlg.selectedoptions
            if len(selected) == 1:
                self.setValue(layers[selected[0]])
            else:
                if isinstance(self.param, ParameterMultipleInput):
                    self.text.setText(';'.join(layers[idx].name() for idx in selected))
                else:
                    rowdif = len(selected) - (self._table().rowCount() - self.row)
                    for i in range(rowdif):
                        self._panel().addRow()
                    for i, layeridx in enumerate(selected):
                        self._table().cellWidget(i + self.row,
                                                 self.col).setValue(layers[layeridx])
    def showLayerSelectionDialog(self):
        if (isinstance(self.param, ParameterRaster)
                or (isinstance(self.param, ParameterMultipleInput)
                    and self.param.datatype == dataobjects.TYPE_RASTER)):
            layers = dataobjects.getRasterLayers()
        elif isinstance(self.param, ParameterTable):
            layers = dataobjects.getTables()
        else:
            if isinstance(self.param, ParameterVector):
                datatype = self.param.datatype
            else:
                datatype = [self.param.datatype]
            layers = dataobjects.getVectorLayers(datatype)

        dlg = MultipleInputDialog([layer.name() for layer in layers])
        dlg.exec_()
        if dlg.selectedoptions is not None:
            selected = dlg.selectedoptions
            if len(selected) == 1:
                self.setValue(layers[selected[0]])
            else:
                if isinstance(self.param, ParameterMultipleInput):
                    self.text.setText(';'.join(layers[idx].name()
                                               for idx in selected))
                else:
                    rowdif = len(selected) - (self._table().rowCount() -
                                              self.row)
                    for i in range(rowdif):
                        self._panel().addRow()
                    for i, layeridx in enumerate(selected):
                        self._table().cellWidget(
                            i + self.row, self.col).setValue(layers[layeridx])
Esempio n. 3
0
    def showSelectionDialog(self):

        dlg = MultipleInputDialog(self.options, self.selectedoptions)
        dlg.exec_()
        if dlg.selectedoptions is not None:
            self.selectedoptions = dlg.selectedoptions
            self.label.setText(str(len(self.selectedoptions))
                               + ' elements selected')
Esempio n. 4
0
    def showSelectionDialog(self):

        dlg = MultipleInputDialog(self.options, self.selectedoptions)
        dlg.exec_()
        if dlg.selectedoptions is not None:
            self.selectedoptions = dlg.selectedoptions
            self.label.setText(
                str(len(self.selectedoptions)) + ' elements selected')
Esempio n. 5
0
    def showLayerSelectionDialog(self):
        layers = []
        if isinstance(self.parameterDefinition,
                      QgsProcessingParameterRasterLayer):
            layers = QgsProcessingUtils.compatibleRasterLayers(
                QgsProject.instance())
        elif isinstance(
                self.parameterDefinition, QgsProcessingParameterMultipleLayers
        ) and self.parameterDefinition.layerType() == QgsProcessing.TypeRaster:
            layers = QgsProcessingUtils.compatibleRasterLayers(
                QgsProject.instance())
        elif isinstance(self.parameterDefinition,
                        QgsProcessingParameterVectorLayer):
            layers = QgsProcessingUtils.compatibleVectorLayers(
                QgsProject.instance())
        elif isinstance(self.parameterDefinition,
                        QgsProcessingParameterMapLayer):
            layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance())
        elif isinstance(self.parameterDefinition,
                        QgsProcessingParameterMeshLayer):
            layers = QgsProcessingUtils.compatibleMeshLayers(
                QgsProject.instance())
        elif isinstance(
                self.parameterDefinition, QgsProcessingParameterMultipleLayers
        ) and self.parameterDefinition.layerType() == QgsProcessing.TypeMesh:
            layers = QgsProcessingUtils.compatibleMeshLayers(
                QgsProject.instance())
        else:
            datatypes = [QgsProcessing.TypeVectorAnyGeometry]
            if isinstance(self.parameterDefinition,
                          QgsProcessingParameterFeatureSource):
                datatypes = self.parameterDefinition.dataTypes()
            elif isinstance(self.parameterDefinition,
                            QgsProcessingParameterMultipleLayers):
                datatypes = [self.parameterDefinition.layerType()]

            if QgsProcessing.TypeVectorAnyGeometry not in datatypes:
                layers = QgsProcessingUtils.compatibleVectorLayers(
                    QgsProject.instance(), datatypes)
            else:
                layers = QgsProcessingUtils.compatibleVectorLayers(
                    QgsProject.instance())

        dlg = MultipleInputDialog([layer.name() for layer in layers])
        dlg.exec_()

        if not dlg.selectedoptions:
            return

        selected = dlg.selectedoptions

        context = dataobjects.createContext()

        first_row = self.panel.batchRowCount(
        ) if self.panel.batchRowCount() > 1 else 0
        for row, selected_idx in enumerate(selected):
            value = layers[selected_idx].id()
            self.setRowValue(first_row + row, value, context)
Esempio n. 6
0
    def showLayerSelectionDialog(self):
        layers = []
        if (isinstance(self.param, QgsProcessingParameterRasterLayer) or
            (isinstance(self.param, QgsProcessingParameterMultipleLayers)
             and self.param.layerType() == QgsProcessing.TypeRaster)):
            layers = QgsProcessingUtils.compatibleRasterLayers(
                QgsProject.instance())
        elif isinstance(self.param, QgsProcessingParameterVectorLayer):
            layers = QgsProcessingUtils.compatibleVectorLayers(
                QgsProject.instance())
        else:
            datatypes = [QgsProcessing.TypeVectorAnyGeometry]
            if isinstance(self.param, QgsProcessingParameterFeatureSource):
                datatypes = self.param.dataTypes()
            elif isinstance(self.param, QgsProcessingParameterMultipleLayers):
                datatypes = [self.param.layerType()]

            if QgsProcessing.TypeVectorAnyGeometry not in datatypes:
                layers = QgsProcessingUtils.compatibleVectorLayers(
                    QgsProject.instance(), datatypes)
            else:
                layers = QgsProcessingUtils.compatibleVectorLayers(
                    QgsProject.instance())

        dlg = MultipleInputDialog([layer.name() for layer in layers])
        dlg.exec_()

        def generate_layer_id(layer):
            # prefer layer name if unique
            if len([
                    l for l in layers
                    if l.name().lower() == layer.name().lower()
            ]) == 1:
                return layer.name()
            else:
                # otherwise fall back to layer id
                return layer.id()

        if dlg.selectedoptions is not None:
            selected = dlg.selectedoptions
            if len(selected) == 1:
                self.setValue(generate_layer_id(layers[selected[0]]))
            else:
                if isinstance(self.param,
                              QgsProcessingParameterMultipleLayers):
                    self.text.setText(';'.join(layers[idx].id()
                                               for idx in selected))
                else:
                    rowdif = len(selected) - (self._table().rowCount() -
                                              self.row)
                    for i in range(rowdif):
                        self._panel().addRow()
                    for i, layeridx in enumerate(selected):
                        self._table().cellWidget(
                            i + self.row, self.col).setValue(
                                generate_layer_id(layers[layeridx]))
Esempio n. 7
0
 def showSelectionDialog(self):
     if self.datatype is None:
         dlg = MultipleInputDialog(self.options, self.selectedoptions)
     else:
         dlg = MultipleFileInputDialog(self.selectedoptions)
     dlg.exec_()
     if dlg.selectedoptions is not None:
         self.selectedoptions = dlg.selectedoptions
         self.leText.setText(self.tr("%d elements selected") % len(self.selectedoptions))
         self.selectionChanged.emit()
Esempio n. 8
0
 def showSelectionDialog(self):
     if self.datatype is None:
         dlg = MultipleInputDialog(self.options, self.selectedoptions)
     else:
         dlg = MultipleFileInputDialog(self.selectedoptions)
     dlg.exec_()
     if dlg.selectedoptions is not None:
         self.selectedoptions = dlg.selectedoptions
         self.leText.setText(
             self.tr('%d elements selected') % len(self.selectedoptions))
Esempio n. 9
0
 def showSelectionDialog(self):
     if self.datatype is None:
         dlg = MultipleInputDialog(self.options, self.selectedoptions)
     else:
         dlg = MultipleFileInputDialog(self.selectedoptions)
     dlg.exec_()
     if dlg.selectedoptions is not None:
         self.selectedoptions = dlg.selectedoptions
         self.leText.setText(
             self.tr('{0} elements selected').format(len(self.selectedoptions)))
         self.selectionChanged.emit()
    def showLayerSelectionDialog(self):
        layers = []
        if (isinstance(self.param, QgsProcessingParameterRasterLayer) or
            (isinstance(self.param, QgsProcessingParameterMultipleLayers) and
                self.param.layerType() == QgsProcessing.TypeRaster)):
            layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance())
        elif isinstance(self.param, QgsProcessingParameterVectorLayer):
            layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
        elif (isinstance(self.param, QgsProcessingParameterMeshLayer) or
              (isinstance(self.param, QgsProcessingParameterMultipleLayers) and
                  self.param.layerType() == QgsProcessing.TypeMesh)):
            layers = QgsProcessingUtils.compatibleMeshLayers(QgsProject.instance())
        else:
            datatypes = [QgsProcessing.TypeVectorAnyGeometry]
            if isinstance(self.param, QgsProcessingParameterFeatureSource):
                datatypes = self.param.dataTypes()
            elif isinstance(self.param, QgsProcessingParameterMultipleLayers):
                datatypes = [self.param.layerType()]

            if QgsProcessing.TypeVectorAnyGeometry not in datatypes:
                layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), datatypes)
            else:
                layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())

        dlg = MultipleInputDialog([layer.name() for layer in layers])
        dlg.exec_()

        def generate_layer_id(layer):
            # prefer layer name if unique
            if len([l for l in layers if l.name().lower() == layer.name().lower()]) == 1:
                return layer.name()
            else:
                # otherwise fall back to layer id
                return layer.id()

        if dlg.selectedoptions is not None:
            selected = dlg.selectedoptions
            if len(selected) == 1:
                self.setValue(generate_layer_id(layers[selected[0]]))
            else:
                if isinstance(self.param, QgsProcessingParameterMultipleLayers):
                    self.text.setText(';'.join(layers[idx].id() for idx in selected))
                else:
                    rowdif = len(selected) - (self._table().rowCount() - self.row)
                    for i in range(rowdif):
                        self._panel().addRow()
                    for i, layeridx in enumerate(selected):
                        self._table().cellWidget(i + self.row,
                                                 self.col).setValue(generate_layer_id(layers[layeridx]))
Esempio n. 11
0
    def showLayerSelectionDialog(self):
        layers = []
        if (isinstance(self.param, QgsProcessingParameterRasterLayer) or
            (isinstance(self.param, QgsProcessingParameterMultipleLayers)
             and self.param.layerType()
             == QgsProcessingParameterDefinition.TypeRaster)):
            layers = QgsProcessingUtils.compatibleRasterLayers(
                QgsProject.instance())
        elif isinstance(self.param, QgsProcessingParameterTable):
            layers = QgsProcessingUtils.compatibleVectorLayers(
                QgsProject.instance())
        else:
            datatypes = [QgsProcessingParameterDefinition.TypeVectorAny]
            if isinstance(self.param, QgsProcessingParameterFeatureSource):
                datatypes = self.param.dataTypes()
            elif isinstance(self.param, QgsProcessingParameterMultipleLayers):
                datatypes = [self.param.layerType()]

            if QgsProcessingParameterDefinition.TypeVectorAny not in datatypes:
                layers = QgsProcessingUtils.compatibleVectorLayers(
                    QgsProject.instance(), datatypes)
            else:
                layers = QgsProcessingUtils.compatibleVectorLayers(
                    QgsProject.instance())

        dlg = MultipleInputDialog([layer.name() for layer in layers])
        dlg.exec_()
        if dlg.selectedoptions is not None:
            selected = dlg.selectedoptions
            if len(selected) == 1:
                self.setValue(layers[selected[0]].id())
            else:
                if isinstance(self.param,
                              QgsProcessingParameterMultipleLayers):
                    self.text.setText(';'.join(layers[idx].id()
                                               for idx in selected))
                else:
                    rowdif = len(selected) - (self._table().rowCount() -
                                              self.row)
                    for i in range(rowdif):
                        self._panel().addRow()
                    for i, layeridx in enumerate(selected):
                        self._table().cellWidget(i + self.row,
                                                 self.col).setValue(
                                                     layers[layeridx].id())
Esempio n. 12
0
 def showSelectionDialog(self):
     #=======================================================================
     # #If there is a datatype, we use it to create the list of options
     # if self.datatype is not None:
     #    if self.datatype == ParameterMultipleInput.TYPE_RASTER:
     #        options = QGisLayers.getRasterLayers()
     #    elif self.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
     #        options = QGisLayers.getVectorLayers()
     #    else:
     #        options = QGisLayers.getVectorLayers(self.datatype)
     #    opts = []
     #    for opt in options:
     #        opts.append(opt.name())
     #    self.options = opts
     #=======================================================================
     dlg = MultipleInputDialog(self.options, self.selectedoptions)
     dlg.exec_()
     if dlg.selectedoptions != None:
         self.selectedoptions = dlg.selectedoptions
         self.label.setText(str(len(self.selectedoptions)) + " elements selected")
Esempio n. 13
0
    def showLayerSelectionDialog(self):
        layers = []
        if (isinstance(self.param, QgsProcessingParameterRasterLayer) or
                (isinstance(self.param, QgsProcessingParameterMultipleLayers) and
                 self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster)):
            layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance())
        elif isinstance(self.param, QgsProcessingParameterVectorLayer):
            layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
        else:
            datatypes = [QgsProcessingParameterDefinition.TypeVectorAny]
            if isinstance(self.param, QgsProcessingParameterFeatureSource):
                datatypes = self.param.dataTypes()
            elif isinstance(self.param, QgsProcessingParameterMultipleLayers):
                datatypes = [self.param.layerType()]

            if QgsProcessingParameterDefinition.TypeVectorAny not in datatypes:
                layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), datatypes)
            else:
                layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())

        dlg = MultipleInputDialog([layer.name() for layer in layers])
        dlg.exec_()
        if dlg.selectedoptions is not None:
            selected = dlg.selectedoptions
            if len(selected) == 1:
                self.setValue(layers[selected[0]].id())
            else:
                if isinstance(self.param, QgsProcessingParameterMultipleLayers):
                    self.text.setText(';'.join(layers[idx].id() for idx in selected))
                else:
                    rowdif = len(selected) - (self._table().rowCount() - self.row)
                    for i in range(rowdif):
                        self._panel().addRow()
                    for i, layeridx in enumerate(selected):
                        self._table().cellWidget(i + self.row,
                                                 self.col).setValue(layers[layeridx].id())