2016-01-07 17:52:07 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
GdalAlgorithmDialog.py
|
|
|
|
---------------------
|
|
|
|
Date : May 2015
|
|
|
|
Copyright : (C) 2015 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'May 2015'
|
|
|
|
__copyright__ = '(C) 2015, Victor Olaya'
|
|
|
|
|
2017-08-05 22:58:16 +02:00
|
|
|
from qgis.PyQt.QtCore import QCoreApplication
|
2017-02-10 17:59:53 +02:00
|
|
|
from qgis.PyQt.QtWidgets import (QWidget,
|
|
|
|
QVBoxLayout,
|
|
|
|
QPushButton,
|
|
|
|
QLabel,
|
|
|
|
QPlainTextEdit,
|
|
|
|
QLineEdit,
|
|
|
|
QComboBox,
|
|
|
|
QCheckBox,
|
2017-07-26 09:45:27 +10:00
|
|
|
QSizePolicy,
|
|
|
|
QDialogButtonBox)
|
2017-02-10 17:59:53 +02:00
|
|
|
|
2017-08-14 05:24:59 +10:00
|
|
|
from qgis.core import (QgsProcessingFeedback,
|
|
|
|
QgsProcessingParameterDefinition)
|
2017-08-14 05:41:00 +10:00
|
|
|
from qgis.gui import (QgsMessageBar,
|
2017-11-29 15:09:19 +10:00
|
|
|
QgsProjectionSelectionWidget,
|
|
|
|
QgsProcessingAlgorithmDialogBase)
|
2017-02-10 17:59:53 +02:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
from processing.gui.AlgorithmDialog import AlgorithmDialog
|
|
|
|
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
|
|
|
|
from processing.gui.ParametersPanel import ParametersPanel
|
2016-01-06 10:28:52 +01:00
|
|
|
from processing.gui.MultipleInputPanel import MultipleInputPanel
|
2016-01-19 09:00:13 +01:00
|
|
|
from processing.gui.NumberInputPanel import NumberInputPanel
|
2018-05-29 20:46:57 +10:00
|
|
|
from processing.gui.DestinationSelectionPanel import DestinationSelectionPanel
|
2018-09-11 14:25:22 +10:00
|
|
|
from processing.gui.wrappers import WidgetWrapper
|
2017-08-14 05:19:29 +10:00
|
|
|
from processing.tools.dataobjects import createContext
|
2015-05-07 13:14:01 +02:00
|
|
|
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
class GdalAlgorithmDialog(AlgorithmDialog):
|
|
|
|
|
2018-09-26 08:57:11 +10:00
|
|
|
def __init__(self, alg, parent=None):
|
|
|
|
super().__init__(alg, parent=parent)
|
2017-11-29 15:09:19 +10:00
|
|
|
self.mainWidget().parametersHaveChanged()
|
2015-05-07 13:14:01 +02:00
|
|
|
|
2017-11-29 15:09:19 +10:00
|
|
|
def getParametersPanel(self, alg, parent):
|
|
|
|
return GdalParametersPanel(parent, alg)
|
2015-05-07 13:14:01 +02:00
|
|
|
|
2016-09-19 11:52:31 +03:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
class GdalParametersPanel(ParametersPanel):
|
|
|
|
|
|
|
|
def __init__(self, parent, alg):
|
|
|
|
ParametersPanel.__init__(self, parent, alg)
|
|
|
|
|
|
|
|
w = QWidget()
|
|
|
|
layout = QVBoxLayout()
|
2015-05-21 13:48:26 +02:00
|
|
|
layout.setMargin(0)
|
2015-05-07 13:14:01 +02:00
|
|
|
layout.setSpacing(6)
|
|
|
|
label = QLabel()
|
2015-12-09 08:56:15 +01:00
|
|
|
label.setText(self.tr("GDAL/OGR console call"))
|
2015-05-07 13:14:01 +02:00
|
|
|
layout.addWidget(label)
|
|
|
|
self.text = QPlainTextEdit()
|
2015-05-21 13:48:26 +02:00
|
|
|
self.text.setReadOnly(True)
|
2015-05-07 13:14:01 +02:00
|
|
|
layout.addWidget(self.text)
|
|
|
|
w.setLayout(layout)
|
2015-05-21 13:48:26 +02:00
|
|
|
self.layoutMain.addWidget(w)
|
2015-05-07 13:14:01 +02:00
|
|
|
|
|
|
|
self.connectParameterSignals()
|
|
|
|
self.parametersHaveChanged()
|
|
|
|
|
|
|
|
def connectParameterSignals(self):
|
2016-11-17 12:06:24 +01:00
|
|
|
for wrapper in list(self.wrappers.values()):
|
2018-09-11 14:25:22 +10:00
|
|
|
wrapper.widgetValueHasChanged.connect(self.parametersHaveChanged)
|
|
|
|
|
|
|
|
# TODO - remove when all wrappers correctly emit widgetValueHasChanged!
|
|
|
|
|
|
|
|
# For compatibility with 3.x API, we need to check whether the wrapper is
|
|
|
|
# the deprecated WidgetWrapper class. If not, it's the newer
|
|
|
|
# QgsAbstractProcessingParameterWidgetWrapper class
|
|
|
|
# TODO QGIS 4.0 - remove
|
|
|
|
if issubclass(wrapper.__class__, WidgetWrapper):
|
|
|
|
w = wrapper.widget
|
|
|
|
else:
|
|
|
|
w = wrapper.wrappedWidget()
|
|
|
|
|
2017-08-14 05:41:00 +10:00
|
|
|
self.connectWidgetChangedSignals(w)
|
2017-08-15 20:57:27 +10:00
|
|
|
for c in w.findChildren(QWidget):
|
2017-08-14 05:41:00 +10:00
|
|
|
self.connectWidgetChangedSignals(c)
|
2018-09-11 14:25:22 +10:00
|
|
|
|
2018-05-29 20:46:57 +10:00
|
|
|
for output_widget in self.outputWidgets.values():
|
|
|
|
self.connectWidgetChangedSignals(output_widget)
|
2017-08-14 05:41:00 +10:00
|
|
|
|
|
|
|
def connectWidgetChangedSignals(self, w):
|
2017-08-14 05:55:50 +10:00
|
|
|
if isinstance(w, QLineEdit):
|
|
|
|
w.textChanged.connect(self.parametersHaveChanged)
|
|
|
|
elif isinstance(w, QComboBox):
|
|
|
|
w.currentIndexChanged.connect(self.parametersHaveChanged)
|
|
|
|
elif isinstance(w, QgsProjectionSelectionWidget):
|
|
|
|
w.crsChanged.connect(self.parametersHaveChanged)
|
|
|
|
elif isinstance(w, QCheckBox):
|
|
|
|
w.stateChanged.connect(self.parametersHaveChanged)
|
|
|
|
elif isinstance(w, MultipleInputPanel):
|
|
|
|
w.selectionChanged.connect(self.parametersHaveChanged)
|
|
|
|
elif isinstance(w, NumberInputPanel):
|
|
|
|
w.hasChanged.connect(self.parametersHaveChanged)
|
2018-05-29 20:46:57 +10:00
|
|
|
elif isinstance(w, DestinationSelectionPanel):
|
|
|
|
w.destinationChanged.connect(self.parametersHaveChanged)
|
2015-05-07 13:14:01 +02:00
|
|
|
|
|
|
|
def parametersHaveChanged(self):
|
2017-08-14 05:19:29 +10:00
|
|
|
context = createContext()
|
|
|
|
feedback = QgsProcessingFeedback()
|
2015-05-07 13:14:01 +02:00
|
|
|
try:
|
2017-11-29 15:09:19 +10:00
|
|
|
parameters = self.parent.getParameterValues()
|
2017-05-15 16:16:32 +10:00
|
|
|
for output in self.alg.destinationParameterDefinitions():
|
2017-08-14 05:19:29 +10:00
|
|
|
if not output.name() in parameters or parameters[output.name()] is None:
|
2017-05-15 16:16:32 +10:00
|
|
|
parameters[output.name()] = self.tr("[temporary file]")
|
2017-08-14 05:24:59 +10:00
|
|
|
for p in self.alg.parameterDefinitions():
|
2019-07-14 10:14:04 +03:00
|
|
|
if p.flags() & QgsProcessingParameterDefinition.FlagHidden:
|
|
|
|
continue
|
|
|
|
|
2017-08-14 05:55:50 +10:00
|
|
|
if (not p.name() in parameters and not p.flags() & QgsProcessingParameterDefinition.FlagOptional) \
|
2018-03-21 15:10:16 +10:00
|
|
|
or (not p.checkValueIsAcceptable(parameters[p.name()])):
|
2017-08-14 05:24:59 +10:00
|
|
|
# not ready yet
|
|
|
|
self.text.setPlainText('')
|
|
|
|
return
|
|
|
|
|
2017-12-08 13:51:30 +10:00
|
|
|
commands = self.alg.getConsoleCommands(parameters, context, feedback, executing=False)
|
2015-05-07 13:14:01 +02:00
|
|
|
commands = [c for c in commands if c not in ['cmd.exe', '/C ']]
|
|
|
|
self.text.setPlainText(" ".join(commands))
|
2016-01-08 10:32:43 +02:00
|
|
|
except AlgorithmDialogBase.InvalidParameterValue as e:
|
2017-05-16 15:21:41 +10:00
|
|
|
self.text.setPlainText(self.tr("Invalid value for parameter '{0}'").format(e.parameter.description()))
|
2019-02-22 20:24:56 +01:00
|
|
|
except AlgorithmDialogBase.InvalidOutputExtension as e:
|
|
|
|
self.text.setPlainText(e.message)
|