Skip to content

Commit c3d230c

Browse files
committed
[processing] update extent selection widget
1 parent 24a3e22 commit c3d230c

File tree

3 files changed

+84
-44
lines changed

3 files changed

+84
-44
lines changed

python/plugins/processing/gui/ExtentSelectionPanel.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,39 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from qgis.core import *
29-
from PyQt4 import QtGui, QtCore
3028
from PyQt4.QtCore import *
3129
from PyQt4.QtGui import *
30+
31+
from qgis.core import *
32+
from qgis.utils import iface
33+
3234
from processing.gui.RectangleMapTool import RectangleMapTool
3335
from processing.core.parameters import ParameterRaster
3436
from processing.core.parameters import ParameterVector
3537
from processing.core.parameters import ParameterMultipleInput
3638
from processing.tools import dataobjects
37-
from qgis.utils import iface
3839

39-
class ExtentSelectionPanel(QtGui.QWidget):
40+
from processing.ui.ui_widgetExtentSelector import Ui_Form
41+
42+
class ExtentSelectionPanel(QWidget, Ui_Form):
4043

4144
def __init__(self, dialog, alg, default):
42-
super(ExtentSelectionPanel, self).__init__(None)
45+
QWidget.__init__(self)
46+
self.setupUi(self)
47+
4348
self.dialog = dialog
4449
self.params = alg.parameters
45-
self.horizontalLayout = QtGui.QHBoxLayout(self)
46-
self.horizontalLayout.setSpacing(2)
47-
self.horizontalLayout.setMargin(0)
48-
self.text = QtGui.QLineEdit()
49-
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding,
50-
QtGui.QSizePolicy.Expanding)
5150
if self.canUseAutoExtent():
52-
if hasattr(self.text, 'setPlaceholderText'):
53-
self.text.setPlaceholderText(
51+
if hasattr(self.leExtent, 'setPlaceholderText'):
52+
self.leExtent.setPlaceholderText(
5453
self.tr('[Leave blank to use min covering extent]'))
55-
self.horizontalLayout.addWidget(self.text)
56-
self.pushButton = QtGui.QPushButton()
57-
self.pushButton.setText('...')
58-
self.pushButton.clicked.connect(self.buttonPushed)
59-
self.horizontalLayout.addWidget(self.pushButton)
60-
self.setLayout(self.horizontalLayout)
54+
55+
self.btnSelect.clicked.connect(self.selectExtent)
56+
6157
canvas = iface.mapCanvas()
6258
self.prevMapTool = canvas.mapTool()
6359
self.tool = RectangleMapTool(canvas)
64-
self.connect(self.tool, SIGNAL('rectangleCreated()'), self.fillCoords)
60+
self.tool.rectangleCreated.connect(self.updateExtent)
6561

6662
def canUseAutoExtent(self):
6763
for param in self.params:
@@ -72,28 +68,31 @@ def canUseAutoExtent(self):
7268

7369
return False
7470

75-
def buttonPushed(self):
71+
def selectExtent(self):
7672
popupmenu = QMenu()
77-
useLayerExtentAction = QtGui.QAction(self.tr('Use layer/canvas extent'),
78-
self.pushButton)
79-
useLayerExtentAction.triggered.connect(self.useLayerExtent)
73+
useLayerExtentAction = QAction(
74+
self.tr('Use layer/canvas extent'), self.btnSelect)
75+
selectOnCanvasAction = QAction(
76+
self.tr('Select extent on canvas'), self.btnSelect)
77+
8078
popupmenu.addAction(useLayerExtentAction)
81-
selectOnCanvasAction = QtGui.QAction(self.tr('Select extent on canvas'),
82-
self.pushButton)
83-
selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
8479
popupmenu.addAction(selectOnCanvasAction)
80+
81+
selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
82+
useLayerExtentAction.triggered.connect(self.useLayerExtent)
83+
8584
if self.canUseAutoExtent():
86-
useMincoveringExtentAction = \
87-
QtGui.QAction(self.tr('Use min covering extent from input layers'),
88-
self.pushButton)
85+
useMincoveringExtentAction = QAction(
86+
self.tr('Use min covering extent from input layers'),
87+
self.btnSelect)
8988
useMincoveringExtentAction.triggered.connect(
9089
self.useMinCoveringExtent)
9190
popupmenu.addAction(useMincoveringExtentAction)
9291

93-
popupmenu.exec_(QtGui.QCursor.pos())
92+
popupmenu.exec_(QCursor.pos())
9493

9594
def useMinCoveringExtent(self):
96-
self.text.setText('')
95+
self.leExtent.setText('')
9796

9897
def getMinCoveringExtent(self):
9998
first = True
@@ -119,8 +118,8 @@ def getMinCoveringExtent(self):
119118
self.addToRegion(layer, first)
120119
first = False
121120
if found:
122-
return str(self.xmin) + ',' + str(self.xmax) + ',' \
123-
+ str(self.ymin) + ',' + str(self.ymax)
121+
return '{},{},{},{}'.format(
122+
self.xmin, self.xmax, self.ymin, self.ymax)
124123
else:
125124
return None
126125

@@ -148,8 +147,8 @@ def useLayerExtent(self):
148147
for layer in layers:
149148
extents.append(layer.name())
150149
extentsDict[layer.name()] = layer.extent()
151-
(item, ok) = QtGui.QInputDialog.getItem(self, 'Select extent',
152-
'Use extent from', extents, False)
150+
(item, ok) = QInputDialog.getItem(self, self.tr('Select extent'),
151+
self.tr('Use extent from'), extents, False)
153152
if ok:
154153
self.setValueFromRect(extentsDict[item])
155154

@@ -158,14 +157,15 @@ def selectOnCanvas(self):
158157
canvas.setMapTool(self.tool)
159158
self.dialog.showMinimized()
160159

161-
def fillCoords(self):
160+
def updateExtent(self):
162161
r = self.tool.rectangle()
163162
self.setValueFromRect(r)
164163

165164
def setValueFromRect(self, r):
166-
s = str(r.xMinimum()) + ',' + str(r.xMaximum()) + ',' \
167-
+ str(r.yMinimum()) + ',' + str(r.yMaximum())
168-
self.text.setText(s)
165+
s = '{},{},{},{}'.format(
166+
r.xMinimum(), r.xMaximum(), r.yMinimum(), r.yMaximum())
167+
168+
self.leExtent.setText(s)
169169
self.tool.reset()
170170
canvas = iface.mapCanvas()
171171
canvas.setMapTool(self.prevMapTool)
@@ -174,7 +174,7 @@ def setValueFromRect(self, r):
174174
self.dialog.activateWindow()
175175

176176
def getValue(self):
177-
if str(self.text.text()).strip() != '':
178-
return str(self.text.text())
177+
if str(self.leExtent.text()).strip() != '':
178+
return str(self.leExtent.text())
179179
else:
180180
return self.getMinCoveringExtent()

python/plugins/processing/gui/RectangleMapTool.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
class RectangleMapTool(QgsMapToolEmitPoint):
3535

36+
rectangleCreated = pyqtSignal()
37+
deactovated = pyqtSignal()
38+
3639
def __init__(self, canvas):
3740
self.canvas = canvas
3841
QgsMapToolEmitPoint.__init__(self, self.canvas)
@@ -58,7 +61,7 @@ def canvasPressEvent(self, e):
5861
def canvasReleaseEvent(self, e):
5962
self.isEmittingPoint = False
6063
if self.rectangle() is not None:
61-
self.emit(SIGNAL('rectangleCreated()'))
64+
self.rectangleCreated.emit()
6265

6366
def canvasMoveEvent(self, e):
6467
if not self.isEmittingPoint:
@@ -107,4 +110,4 @@ def setRectangle(self, rect):
107110

108111
def deactivate(self):
109112
QgsMapTool.deactivate(self)
110-
self.emit(SIGNAL('deactivated()'))
113+
self.deactivated.emit()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Form</class>
4+
<widget class="QWidget" name="Form">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>23</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<layout class="QHBoxLayout" name="horizontalLayout">
17+
<property name="spacing">
18+
<number>2</number>
19+
</property>
20+
<property name="margin">
21+
<number>0</number>
22+
</property>
23+
<item>
24+
<widget class="QLineEdit" name="leExtent"/>
25+
</item>
26+
<item>
27+
<widget class="QToolButton" name="btnSelect">
28+
<property name="text">
29+
<string>...</string>
30+
</property>
31+
</widget>
32+
</item>
33+
</layout>
34+
</widget>
35+
<resources/>
36+
<connections/>
37+
</ui>

0 commit comments

Comments
 (0)