Skip to content

Commit

Permalink
[processing] Use standard QGIS projection selection widget for CRS pa…
Browse files Browse the repository at this point in the history
…rams
  • Loading branch information
nyalldawson committed Nov 13, 2016
1 parent fbc12a8 commit 3ef7b3b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 92 deletions.
3 changes: 2 additions & 1 deletion python/plugins/processing/algs/gdal/warp.py
Expand Up @@ -75,11 +75,12 @@ def getIcon(self):
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Warp (reproject)')
self.group, self.i18n_group = self.trAlgorithm('[GDAL] Projections')
self.tags = self.tr('transform,reproject,crs,srs')
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer'), False))
self.addParameter(ParameterCrs(self.SOURCE_SRS,
self.tr('Source SRS'), '', optional=True))
self.addParameter(ParameterCrs(self.DEST_SRS,
self.tr('Destination SRS'), ''))
self.tr('Destination SRS'), 'EPSG:4326'))
self.addParameter(ParameterString(self.NO_DATA,
self.tr("Nodata value, leave blank to take the nodata value from input"),
'', optional=True))
Expand Down
9 changes: 9 additions & 0 deletions python/plugins/processing/algs/qgis/ReprojectLayer.py
Expand Up @@ -25,12 +25,17 @@

__revision__ = '$Format:%H$'

import os

from qgis.core import QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsFeature
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterCrs
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
from qgis.PyQt.QtGui import QIcon

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]


class ReprojectLayer(GeoAlgorithm):
Expand All @@ -39,9 +44,13 @@ class ReprojectLayer(GeoAlgorithm):
TARGET_CRS = 'TARGET_CRS'
OUTPUT = 'OUTPUT'

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'warp.png'))

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Reproject layer')
self.group, self.i18n_group = self.trAlgorithm('Vector general tools')
self.tags = self.tr('transform,reproject,crs,srs,warp')

self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer')))
Expand Down
76 changes: 0 additions & 76 deletions python/plugins/processing/gui/CrsSelectionPanel.py

This file was deleted.

26 changes: 17 additions & 9 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -36,13 +36,12 @@

from qgis.core import QgsCoordinateReferenceSystem, QgsVectorLayer
from qgis.PyQt.QtWidgets import QCheckBox, QComboBox, QLineEdit, QPlainTextEdit
from qgis.gui import QgsFieldExpressionWidget, QgsExpressionLineEdit
from qgis.gui import QgsFieldExpressionWidget, QgsExpressionLineEdit, QgsProjectionSelectionWidget
from qgis.PyQt.QtCore import pyqtSignal, QObject, QVariant

from processing.gui.NumberInputPanel import NumberInputPanel
from processing.gui.InputLayerSelectorPanel import InputLayerSelectorPanel
from processing.modeler.MultilineTextPanel import MultilineTextPanel
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
from processing.gui.PointSelectionPanel import PointSelectionPanel
from processing.core.parameters import (ParameterBoolean,
ParameterPoint,
Expand Down Expand Up @@ -222,23 +221,32 @@ def createWidget(self):
widget.setEditText(self.param.default)
return widget
else:
return CrsSelectionPanel()

widget = QgsProjectionSelectionWidget()
if self.param.optional:
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)

if self.param.default:
crs = QgsCoordinateReferenceSystem(self.param.default)
widget.setCrs(crs)

return widget

def setValue(self, value):
if self.dialogType == DIALOG_MODELER:
self.setComboValue(value)
else:
if isinstance(value, str): # authId
self.widget.crs = value
else:
self.widget.crs = QgsCoordinateReferenceSystem(value).authid()
self.widget.updateText()
self.widget.setCrs(QgsCoordinateReferenceSystem(value))

def value(self):
if self.dialogType == DIALOG_MODELER:
return self.comboValue()
else:
return self.widget.getValue()
crs = self.widget.crs()
if crs.isValid():
return self.widget.crs().authid()
else:
return None


class ExtentWidgetWrapper(WidgetWrapper):
Expand Down
Expand Up @@ -28,7 +28,8 @@

import math

from qgis.gui import QgsExpressionLineEdit
from qgis.gui import QgsExpressionLineEdit, QgsProjectionSelectionWidget
from qgis.core import QgsCoordinateReferenceSystem
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import (QDialog,
QVBoxLayout,
Expand All @@ -54,7 +55,6 @@
ParameterFile,
ParameterPoint,
ParameterCrs)
from processing.gui.CrsSelectionPanel import CrsSelectionPanel


class ModelerParameterDefinitionDialog(QDialog):
Expand Down Expand Up @@ -247,10 +247,12 @@ def setupUi(self):
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or
isinstance(self.param, ParameterCrs)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = CrsSelectionPanel('EPSG:4326')
self.selector = QgsProjectionSelectionWidget()
if self.param is not None:
self.defaultTextBox.setAuthId(self.param.default)
self.verticalLayout.addWidget(self.defaultTextBox)
self.selector.setCrs(QgsCoordinateReferenceSystem(self.param.default))
else:
self.selector.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
self.verticalLayout.addWidget(self.selector)

self.verticalLayout.addSpacing(20)
self.requiredCheck = QCheckBox()
Expand Down Expand Up @@ -361,7 +363,7 @@ def okPressed(self):
str(self.defaultTextBox.text()))
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or
isinstance(self.param, ParameterCrs)):
self.param = ParameterCrs(name, description, self.defaultTextBox.getValue())
self.param = ParameterCrs(name, description, default=self.selector.crs().authid())
self.param.optional = not self.requiredCheck.isChecked()
self.close()

Expand Down

0 comments on commit 3ef7b3b

Please sign in to comment.