Esempio n. 1
0
 def createWidget(self):
     if self.dialogType == DIALOG_BATCH:
         widget = BatchInputSelectionPanel(self.param, self.row, self.col,
                                           self.dialog)
         widget.valueChanged.connect(
             lambda: self.widgetValueHasChanged.emit(self))
         return widget
     else:
         return None
Esempio n. 2
0
    def createWidget(self):
        if self.dialogType == DIALOG_STANDARD:
            widget = QWidget()
            layout = QHBoxLayout()
            layout.setMargin(0)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.setSpacing(2)
            self.combo = QgsMapLayerComboBox()
            layout.addWidget(self.combo)
            btn = QToolButton()
            btn.setText('...')
            btn.setToolTip(self.tr("Select file"))
            btn.clicked.connect(self.selectFile)
            layout.addWidget(btn)

            widget.setLayout(layout)
            if self.param.optional:
                self.combo.setAllowEmptyLayer(True)
            if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
                self.combo.setShowCrs(True)

            self.combo.setFilters(QgsMapLayerProxyModel.RasterLayer)
            self.combo.setExcludedProviders(['grass'])

            self.combo.currentIndexChanged.connect(
                lambda: self.widgetValueHasChanged.emit(self))
            self.combo.currentTextChanged.connect(
                lambda: self.widgetValueHasChanged.emit(self))
            return widget
        elif self.dialogType == DIALOG_BATCH:
            return BatchInputSelectionPanel(self.param, self.row, self.col,
                                            self.dialog)
        else:
            self.combo = QComboBox()
            layers = self.dialog.getAvailableValuesOfType(
                ParameterRaster, OutputRaster)
            self.combo.setEditable(True)
            for layer in layers:
                self.combo.addItem(self.dialog.resolveValueDescription(layer),
                                   layer)
            if self.param.optional:
                self.combo.setEditText("")

            widget = QWidget()
            layout = QHBoxLayout()
            layout.setMargin(0)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.setSpacing(2)
            layout.addWidget(self.combo)
            btn = QToolButton()
            btn.setText('...')
            btn.setToolTip(self.tr("Select file"))
            btn.clicked.connect(self.selectFile)
            layout.addWidget(btn)
            widget.setLayout(layout)
            return widget
Esempio n. 3
0
    def addRow(self):
        self.wrappers.append([None] * self.tblParameters.columnCount())
        self.tblParameters.setRowCount(self.tblParameters.rowCount() + 1)

        context = dataobjects.createContext()

        wrappers = {}
        row = self.tblParameters.rowCount() - 1
        column = 0
        for param in self.alg.parameterDefinitions():
            if param.flags(
            ) & QgsProcessingParameterDefinition.FlagHidden or param.isDestination(
            ):
                continue

            if isinstance(
                    param,
                (QgsProcessingParameterMapLayer,
                 QgsProcessingParameterRasterLayer,
                 QgsProcessingParameterVectorLayer,
                 QgsProcessingParameterMeshLayer, QgsProcessingParameterFile)):
                self.tblParameters.setCellWidget(
                    row, column,
                    BatchInputSelectionPanel(param, row, column, self.parent))
            else:
                wrapper = WidgetWrapperFactory.create_wrapper(
                    param, self.parent, row, column)
                wrappers[param.name()] = wrapper
                self.setCellWrapper(row, column, wrapper, context)

            column += 1

        for out in self.alg.destinationParameterDefinitions():
            if out.flags() & QgsProcessingParameterDefinition.FlagHidden:
                continue

            self.tblParameters.setCellWidget(
                row, column,
                BatchOutputSelectionPanel(out, self.alg, row, column, self))
            column += 1

        if len(self.alg.destinationParameterDefinitions()) > 0:
            item = QComboBox()
            item.addItem(self.tr('Yes'))
            item.addItem(self.tr('No'))
            item.setCurrentIndex(0)
            self.tblParameters.setCellWidget(row, column, item)

        for wrapper in list(wrappers.values()):
            wrapper.postInitialize(list(wrappers.values()))
Esempio n. 4
0
 def createWidget(self):
     if self.dialogType == DIALOG_STANDARD:
         layers = dataobjects.getRasterLayers()
         items = []
         if self.param.optional:
             items.append((self.NOT_SELECTED, None))
         for layer in layers:
             items.append((getExtendedLayerName(layer), layer))
         return InputLayerSelectorPanel(items, self.param)
     elif self.dialogType == DIALOG_BATCH:
         return BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
     else:
         widget = QComboBox()
         widget.setEditable(True)
         files = self.dialog.getAvailableValuesOfType(ParameterRaster, OutputRaster)
         for f in files:
             widget.addItem(self.dialog.resolveValueDescription(f), f)
         if self.param.optional:
             widget.setEditText("")
         return widget
Esempio n. 5
0
 def createWidget(self):
     if self.dialogType == DIALOG_STANDARD:
         if self.param.datatype == dataobjects.TYPE_FILE:
             return MultipleInputPanel(datatype=dataobjects.TYPE_FILE)
         else:
             if self.param.datatype == dataobjects.TYPE_RASTER:
                 options = dataobjects.getRasterLayers(sorting=False)
             elif self.param.datatype == dataobjects.TYPE_VECTOR_ANY:
                 options = dataobjects.getVectorLayers(sorting=False)
             else:
                 options = dataobjects.getVectorLayers([self.param.datatype], sorting=False)
             opts = [getExtendedLayerName(opt) for opt in options]
             return MultipleInputPanel(opts)
     elif self.dialogType == DIALOG_BATCH:
         widget = BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
         widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
         return widget
     else:
         options = [self.dialog.resolveValueDescription(opt) for opt in self._getOptions()]
         return MultipleInputPanel(options)
Esempio n. 6
0
 def createWidget(self):
     if self.dialogType == DIALOG_STANDARD:
         if self.param.datatype == dataobjects.TYPE_FILE:
             return MultipleInputPanel(datatype=dataobjects.TYPE_FILE)
         else:
             if self.param.datatype == dataobjects.TYPE_RASTER:
                 options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
             elif self.param.datatype in (dataobjects.TYPE_VECTOR_ANY, dataobjects.TYPE_TABLE):
                 options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
             else:
                 options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.datatype], False)
             opts = [getExtendedLayerName(opt) for opt in options]
             return MultipleInputPanel(opts)
     elif self.dialogType == DIALOG_BATCH:
         widget = BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
         widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
         return widget
     else:
         options = [self.dialog.resolveValueDescription(opt) for opt in self._getOptions()]
         return MultipleInputPanel(options)
Esempio n. 7
0
    def getWidgetFromParameter(self, param, row, col):
        if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable,
                              ParameterMultipleInput)):
            item = BatchInputSelectionPanel(param, row, col, self)
        elif isinstance(param, ParameterBoolean):
            item = QComboBox()
            item.addItem(self.tr('Yes'))
            item.addItem(self.tr('No'))
            if param.default:
                item.setCurrentIndex(0)
            else:
                item.setCurrentIndex(1)
        elif isinstance(param, ParameterSelection):
            item = QComboBox()
            item.addItems(param.options)
        elif isinstance(param, ParameterFixedTable):
            item = FixedTablePanel(param)
        elif isinstance(param, ParameterExtent):
            item = ExtentSelectionPanel(self.parent, self.alg, param.default)
        elif isinstance(param, ParameterPoint):
            item = PointSelectionPanel(self.parent, param.default)
        elif isinstance(param, ParameterCrs):
            item = CrsSelectionPanel(param.default)
        elif isinstance(param, ParameterFile):
            item = FileSelectionPanel(param.isFolder)
        elif isinstance(param, ParameterGeometryPredicate):
            item = GeometryPredicateSelectionPanel(param.enabledPredicates, rows=1)
            width = max(self.tblParameters.columnWidth(col),
                        item.sizeHint().width())
            self.tblParameters.setColumnWidth(col, width)
        else:
            item = QLineEdit()
            try:
                item.setText(unicode(param.default))
            except:
                pass

        return item
Esempio n. 8
0
    def createWidget(self):
        if self.dialogType == DIALOG_STANDARD:
            widget = QWidget()
            layout = QHBoxLayout()
            layout.setMargin(0)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.setSpacing(2)
            self.combo = QgsMapLayerComboBox()
            layout.addWidget(self.combo)
            btn = QToolButton()
            btn.setText('...')
            btn.setToolTip(self.tr("Select file"))
            btn.clicked.connect(self.selectFile)
            layout.addWidget(btn)

            widget.setLayout(layout)

            filters = QgsMapLayerProxyModel.Filters()
            if self.param.datatype == [-1] or -1 in self.param.datatype:
                filters = QgsMapLayerProxyModel.HasGeometry
            if QgsWkbTypes.PointGeometry in self.param.datatype:
                filters |= QgsMapLayerProxyModel.PointLayer
            if QgsWkbTypes.LineGeometry in self.param.datatype:
                filters |= QgsMapLayerProxyModel.LineLayer
            if QgsWkbTypes.PolygonGeometry in self.param.datatype:
                filters |= QgsMapLayerProxyModel.PolygonLayer

            try:
                if iface.activeLayer().type() == QgsMapLayer.VectorLayer:
                    self.combo.setLayer(iface.activeLayer())
            except:
                pass

            if self.param.optional:
                self.combo.setAllowEmptyLayer(True)
            if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
                self.combo.setShowCrs(True)

            self.combo.setFilters(filters)
            self.combo.setExcludedProviders(['grass'])

            self.combo.currentIndexChanged.connect(
                lambda: self.widgetValueHasChanged.emit(self))
            self.combo.currentTextChanged.connect(
                lambda: self.widgetValueHasChanged.emit(self))
            return widget

        elif self.dialogType == DIALOG_BATCH:
            widget = BatchInputSelectionPanel(self.param, self.row, self.col,
                                              self.dialog)
            widget.valueChanged.connect(
                lambda: self.widgetValueHasChanged.emit(self))
            return widget
        else:
            self.combo = QComboBox()
            layers = self.dialog.getAvailableValuesOfType(
                ParameterVector, OutputVector)
            self.combo.setEditable(True)
            for layer in layers:
                self.combo.addItem(self.dialog.resolveValueDescription(layer),
                                   layer)
            if self.param.optional:
                self.combo.setEditText("")

            widget = QWidget()
            layout = QHBoxLayout()
            layout.setMargin(0)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.setSpacing(2)
            layout.addWidget(self.combo)
            btn = QToolButton()
            btn.setText('...')
            btn.setToolTip(self.tr("Select file"))
            btn.clicked.connect(self.selectFile)
            layout.addWidget(btn)
            widget.setLayout(layout)
            return widget
Esempio n. 9
0
    def createWidget(self):
        if self.dialogType == DIALOG_STANDARD:
            widget = QWidget()
            layout = QHBoxLayout()
            layout.setMargin(0)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.setSpacing(2)
            self.combo = QgsMapLayerComboBox()
            layout.addWidget(self.combo)
            btn = QToolButton()
            btn.setText('...')
            btn.setToolTip(self.tr("Select file"))
            btn.clicked.connect(self.selectFile)
            layout.addWidget(btn)

            widget.setLayout(layout)

            if self.param.optional:
                self.combo.setAllowEmptyLayer(True)

            self.combo.setFilters(QgsMapLayerProxyModel.VectorLayer)
            self.combo.setExcludedProviders(['grass'])
            try:
                if iface.activeLayer().type() == QgsMapLayer.VectorLayer:
                    self.combo.setLayer(iface.activeLayer())
            except:
                pass

            self.combo.currentIndexChanged.connect(
                lambda: self.widgetValueHasChanged.emit(self))
            self.combo.currentTextChanged.connect(
                lambda: self.widgetValueHasChanged.emit(self))
            return widget

        elif self.dialogType == DIALOG_BATCH:
            return BatchInputSelectionPanel(self.param, self.row, self.col,
                                            self.dialog)
        else:
            self.combo = QComboBox()
            layers = self.dialog.getAvailableValuesOfType(
                ParameterRaster, OutputRaster)
            self.combo.setEditable(True)
            tables = self.dialog.getAvailableValuesOfType(
                ParameterTable, OutputTable)
            layers = self.dialog.getAvailableValuesOfType(
                ParameterVector, OutputVector)
            if self.param.optional:
                self.combo.addItem(self.NOT_SELECTED, None)
            for table in tables:
                self.combo.addItem(self.dialog.resolveValueDescription(table),
                                   table)
            for layer in layers:
                self.combo.addItem(self.dialog.resolveValueDescription(layer),
                                   layer)

            widget = QWidget()
            layout = QHBoxLayout()
            layout.setMargin(0)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.setSpacing(2)
            layout.addWidget(self.combo)
            btn = QToolButton()
            btn.setText('...')
            btn.setToolTip(self.tr("Select file"))
            btn.clicked.connect(self.selectFile)
            layout.addWidget(btn)
            widget.setLayout(layout)
            return widget
Esempio n. 10
0
    def getWidgetFromParameter(self, param, row, col):
        if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable,
                              ParameterMultipleInput)):
            item = BatchInputSelectionPanel(param, row, col, self)
        elif isinstance(param, ParameterBoolean):
            item = QComboBox()
            item.addItem(self.tr('Yes'))
            item.addItem(self.tr('No'))
            if param.default:
                item.setCurrentIndex(0)
            else:
                item.setCurrentIndex(1)
        elif isinstance(param, ParameterSelection):
            item = QComboBox()
            item.addItems(param.options)
        elif isinstance(param, ParameterFixedTable):
            item = FixedTablePanel(param)
        elif isinstance(param, ParameterExtent):
            item = ExtentSelectionPanel(self.parent, self.alg, param.default)
        elif isinstance(param, ParameterCrs):
            item = CrsSelectionPanel(param.default)
        elif isinstance(param, ParameterFile):
            item = FileSelectionPanel(param.isFolder)
        elif isinstance(param, ParameterGeometryPredicate):
            item = GeometryPredicateSelectionPanel(param.enabledPredicates,
                                                   rows=1)
            width = max(self.tblParameters.columnWidth(col),
                        item.sizeHint().width())
            self.tblParameters.setColumnWidth(col, width)
        else:
            item = QLineEdit()
            try:
                item.setText(unicode(param.default))
            except:
                pass

        return item
    def getWidgetFromParameter(self, param, row, col):
        if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable, ParameterMultipleInput)):
            item = BatchInputSelectionPanel(param, row, col, self)
        elif isinstance(param, ParameterBoolean):
            item = QtGui.QComboBox()
            item.addItem("Yes")
            item.addItem("No")
            if param.default:
                item.setCurrentIndex(0)
            else:
                item.setCurrentIndex(1)
        elif isinstance(param, ParameterSelection):
            item = QtGui.QComboBox()
            item.addItems(param.options)
        elif isinstance(param, ParameterFixedTable):
            item = FixedTablePanel(param)
        elif isinstance(param, ParameterExtent):
            item = ExtentSelectionPanel(self, self.alg, param.default)
        elif isinstance(param, ParameterCrs):
            item = CrsSelectionPanel(param.default)
        elif isinstance(param, ParameterFile):
            item = FileSelectionPanel(param.isFolder)
        else:
            item = QtGui.QLineEdit()
            try:
                item.setText(str(param.default))
            except:
                pass

        return item
Esempio n. 12
0
    def getWidgetFromParameter(self, param, row, col):
        if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable,
                              ParameterMultipleInput)):
            item = BatchInputSelectionPanel(param, row, col, self)
        elif isinstance(param, ParameterBoolean):
            item = QtGui.QComboBox()
            item.addItem('Yes')
            item.addItem('No')
            if param.default:
                item.setCurrentIndex(0)
            else:
                item.setCurrentIndex(1)
        elif isinstance(param, ParameterSelection):
            item = QtGui.QComboBox()
            item.addItems(param.options)
        elif isinstance(param, ParameterFixedTable):
            item = FixedTablePanel(param)
        elif isinstance(param, ParameterExtent):
            item = ExtentSelectionPanel(self, self.alg, param.default)
        elif isinstance(param, ParameterCrs):
            item = CrsSelectionPanel(param.default)
        elif isinstance(param, ParameterFile):
            item = FileSelectionPanel(param.isFolder)
        else:
            item = QtGui.QLineEdit()
            try:
                item.setText(str(param.default))
            except:
                pass

        return item