mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-17 00:09:36 -04:00
[processing] add ParameterPoint for selecting point on canvas (fix #5733)
This commit is contained in:
parent
143f3d6e53
commit
58d40d16fa
@ -215,6 +215,37 @@ class ParameterExtent(Parameter):
|
||||
return '##' + self.name + '=extent'
|
||||
|
||||
|
||||
class ParameterPoint(Parameter):
|
||||
|
||||
def __init__(self, name='', description='', default=None, optional=False):
|
||||
Parameter.__init__(self, name, description, default, optional)
|
||||
# The value is a string in the form "x, y"
|
||||
|
||||
def setValue(self, text):
|
||||
if text is None:
|
||||
if not self.optional:
|
||||
return False
|
||||
self.value = None
|
||||
return True
|
||||
|
||||
tokens = unicode(text).split(',')
|
||||
if len(tokens) != 2:
|
||||
return False
|
||||
try:
|
||||
float(tokens[0])
|
||||
float(tokens[1])
|
||||
self.value = text
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def getValueAsCommandLineParameter(self):
|
||||
return '"' + unicode(self.value) + '"'
|
||||
|
||||
def getAsScriptCode(self):
|
||||
return '##' + self.name + '=point'
|
||||
|
||||
|
||||
class ParameterFile(Parameter):
|
||||
|
||||
def __init__(self, name='', description='', isFolder=False, optional=True, ext=None):
|
||||
|
@ -26,8 +26,14 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import Qt
|
||||
from PyQt4.QtGui import QMessageBox, QApplication, QCursor, QColor, QPalette, QPushButton, QWidget,\
|
||||
QVBoxLayout
|
||||
from PyQt4.QtGui import (QMessageBox,
|
||||
QApplication,
|
||||
QCursor,
|
||||
QColor,
|
||||
QPalette,
|
||||
QPushButton,
|
||||
QWidget,
|
||||
QVBoxLayout)
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
@ -54,6 +60,7 @@ from processing.core.parameters import ParameterString
|
||||
from processing.core.parameters import ParameterNumber
|
||||
from processing.core.parameters import ParameterFile
|
||||
from processing.core.parameters import ParameterCrs
|
||||
from processing.core.parameters import ParameterPoint
|
||||
from processing.core.parameters import ParameterGeometryPredicate
|
||||
|
||||
from processing.core.outputs import OutputRaster
|
||||
@ -152,7 +159,7 @@ class AlgorithmDialog(AlgorithmDialogBase):
|
||||
options = dataobjects.getVectorLayers([param.datatype], sorting=False)
|
||||
return param.setValue([options[i] for i in widget.selectedoptions])
|
||||
elif isinstance(param, (ParameterNumber, ParameterFile, ParameterCrs,
|
||||
ParameterExtent)):
|
||||
ParameterExtent, ParameterPoint)):
|
||||
return param.setValue(widget.getValue())
|
||||
elif isinstance(param, ParameterString):
|
||||
if param.multiline:
|
||||
|
@ -38,6 +38,7 @@ from processing.gui.FileSelectionPanel import FileSelectionPanel
|
||||
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
|
||||
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
|
||||
from processing.gui.FixedTablePanel import FixedTablePanel
|
||||
from processing.gui.PointSelectionPanel import PointSelectionPanel
|
||||
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
|
||||
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
|
||||
from processing.gui.GeometryPredicateSelectionPanel import GeometryPredicateSelectionPanel
|
||||
@ -48,6 +49,7 @@ from processing.core.parameters import ParameterTable
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.parameters import ParameterExtent
|
||||
from processing.core.parameters import ParameterCrs
|
||||
from processing.core.parameters import ParameterPoint
|
||||
from processing.core.parameters import ParameterBoolean
|
||||
from processing.core.parameters import ParameterSelection
|
||||
from processing.core.parameters import ParameterFixedTable
|
||||
@ -155,6 +157,8 @@ class BatchPanel(BASE, WIDGET):
|
||||
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):
|
||||
|
@ -36,7 +36,17 @@ from qgis.core import *
|
||||
|
||||
from PyQt4 import uic
|
||||
from PyQt4.QtCore import QCoreApplication, QVariant
|
||||
from PyQt4.QtGui import QWidget, QLayout, QVBoxLayout, QHBoxLayout, QToolButton, QIcon, QLabel, QCheckBox, QComboBox, QLineEdit, QPlainTextEdit
|
||||
from PyQt4.QtGui import (QWidget,
|
||||
QLayout,
|
||||
QVBoxLayout,
|
||||
QHBoxLayout,
|
||||
QToolButton,
|
||||
QIcon,
|
||||
QLabel,
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QLineEdit,
|
||||
QPlainTextEdit)
|
||||
|
||||
from processing.core.ProcessingConfig import ProcessingConfig
|
||||
|
||||
@ -49,6 +59,7 @@ from processing.gui.NumberInputPanel import NumberInputPanel
|
||||
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
|
||||
from processing.gui.FileSelectionPanel import FileSelectionPanel
|
||||
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
|
||||
from processing.gui.PointSelectionPanel import PointSelectionPanel
|
||||
from processing.gui.GeometryPredicateSelectionPanel import \
|
||||
GeometryPredicateSelectionPanel
|
||||
|
||||
@ -66,6 +77,7 @@ from processing.core.parameters import ParameterExtent
|
||||
from processing.core.parameters import ParameterFile
|
||||
from processing.core.parameters import ParameterCrs
|
||||
from processing.core.parameters import ParameterString
|
||||
from processing.core.parameters import ParameterPoint
|
||||
from processing.core.parameters import ParameterGeometryPredicate
|
||||
|
||||
from processing.core.outputs import OutputRaster
|
||||
@ -184,6 +196,8 @@ class ParametersPanel(BASE, WIDGET):
|
||||
desc = param.description
|
||||
if isinstance(param, ParameterExtent):
|
||||
desc += self.tr(' (xmin, xmax, ymin, ymax)')
|
||||
if isinstance(param, ParameterPoint):
|
||||
desc += self.tr(' (x, y)')
|
||||
try:
|
||||
if param.optional:
|
||||
desc += self.tr(' [optional]')
|
||||
@ -376,6 +390,8 @@ class ParametersPanel(BASE, WIDGET):
|
||||
param.isInteger)
|
||||
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, ParameterString):
|
||||
|
46
python/plugins/processing/gui/PointMapTool.py
Normal file
46
python/plugins/processing/gui/PointMapTool.py
Normal file
@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
PointMapTool.py
|
||||
---------------------
|
||||
Date : February 2016
|
||||
Copyright : (C) 2016 by Alexander Bruy
|
||||
Email : alexander dot bruy 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__ = 'Alexander Bruy'
|
||||
__date__ = 'February 2016'
|
||||
__copyright__ = '(C) 2016, Alexander Bruy'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import Qt
|
||||
|
||||
from qgis.gui import QgsMapToolEmitPoint
|
||||
|
||||
|
||||
class PointMapTool(QgsMapToolEmitPoint):
|
||||
|
||||
def __init__(self, canvas):
|
||||
QgsMapToolEmitPoint.__init__(self, canvas)
|
||||
|
||||
self.canvas = canvas
|
||||
self.cursor = Qt.ArrowCursor
|
||||
|
||||
def activate(self):
|
||||
self.canvas.setCursor(self.cursor)
|
||||
|
||||
def canvasPressEvent(self, event):
|
||||
pnt = self.toMapCoordinates(event.pos())
|
||||
self.canvasClicked.emit(pnt, event.button())
|
91
python/plugins/processing/gui/PointSelectionPanel.py
Normal file
91
python/plugins/processing/gui/PointSelectionPanel.py
Normal file
@ -0,0 +1,91 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
PointSelectionPanel.py
|
||||
---------------------
|
||||
Date : February 2016
|
||||
Copyright : (C) 2016 by Alexander Bruy
|
||||
Email : alexander dot bruy 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__ = 'Alexander Bruy'
|
||||
__date__ = 'February 2016'
|
||||
__copyright__ = '(C) 2016, Alexander Bruy'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from PyQt4 import uic
|
||||
from PyQt4.QtGui import QCursor
|
||||
|
||||
from qgis.gui import QgsMessageBar
|
||||
from qgis.utils import iface
|
||||
|
||||
from processing.gui.PointMapTool import PointMapTool
|
||||
|
||||
pluginPath = os.path.split(os.path.dirname(__file__))[0]
|
||||
WIDGET, BASE = uic.loadUiType(
|
||||
os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
|
||||
|
||||
|
||||
class PointSelectionPanel(BASE, WIDGET):
|
||||
|
||||
def __init__(self, dialog, default=None):
|
||||
super(PointSelectionPanel, self).__init__(None)
|
||||
self.setupUi(self)
|
||||
|
||||
self.btnSelect.clicked.connect(self.selectOnCanvas)
|
||||
|
||||
self.dialog = dialog
|
||||
|
||||
canvas = iface.mapCanvas()
|
||||
self.prevMapTool = canvas.mapTool()
|
||||
|
||||
self.tool = PointMapTool(canvas)
|
||||
self.tool.canvasClicked.connect(self.updatePoint)
|
||||
|
||||
if default:
|
||||
tokens = unicode(default).split(',')
|
||||
if len(tokens) == 2:
|
||||
try:
|
||||
float(tokens[0])
|
||||
float(tokens[1])
|
||||
self.leText.setText(unicode(default))
|
||||
except:
|
||||
pass
|
||||
|
||||
def selectOnCanvas(self):
|
||||
canvas = iface.mapCanvas()
|
||||
canvas.setMapTool(self.tool)
|
||||
self.dialog.showMinimized()
|
||||
|
||||
def updatePoint(self, point, button):
|
||||
s = '{},{}'.format(point.x(), point.y())
|
||||
|
||||
self.leText.setText(s)
|
||||
canvas = iface.mapCanvas()
|
||||
canvas.setMapTool(self.prevMapTool)
|
||||
self.dialog.showNormal()
|
||||
self.dialog.raise_()
|
||||
self.dialog.activateWindow()
|
||||
|
||||
def getValue(self):
|
||||
if unicode(self.leText.text()).strip() != '':
|
||||
return unicode(self.leText.text())
|
||||
else:
|
||||
return None
|
||||
|
||||
def setPointFromString(self, s):
|
||||
self.leText.setText(s)
|
Loading…
x
Reference in New Issue
Block a user