@@ -15,11 +15,10 @@ def __init__(self, iface):
15
15
self .iface = iface
16
16
self .canvas = self .iface .mapCanvas ()
17
17
18
- self .clipper = ClipperSelector (self .canvas )
19
-
20
18
self .setupUi (self )
21
19
BasePluginWidget .__init__ (self , self .iface , "gdal_merge.py" , None , self .iface .mainWindow ())
22
20
21
+ self .extentSelector .setCanvas (self .canvas )
23
22
self .outputFormat = Utils .fillRasterOutputFormat ()
24
23
25
24
self .inputFiles = QStringList ()
@@ -29,50 +28,28 @@ def __init__(self, iface):
29
28
[
30
29
(self .outputFileEdit , SIGNAL ("textChanged(const QString &)" )),
31
30
(self .noDataSpin , SIGNAL ("valueChanged(int)" ), self .noDataCheck ),
32
- (self .pctCheck , SIGNAL ("stateChanged(int)" ))
31
+ (self .pctCheck , SIGNAL ("stateChanged(int)" )),
32
+ ( self .extentSelector , [SIGNAL ("selectionStarted()" ), SIGNAL ("newExtentDefined()" )] )
33
33
]
34
34
)
35
35
36
36
self .connect (self .selectOutputFileButton , SIGNAL ("clicked()" ), self .fillOutputFileEdit )
37
- self .connect (self .clipper , SIGNAL ("clippingRectangleCreated()" ), self .fillCoords )
38
- self .connect (self .x1CoordEdit , SIGNAL ("textChanged(const QString &)" ), self .coordsChanged )
39
- self .connect (self .x2CoordEdit , SIGNAL ("textChanged(const QString &)" ), self .coordsChanged )
40
- self .connect (self .y1CoordEdit , SIGNAL ("textChanged(const QString &)" ), self .coordsChanged )
41
- self .connect (self .y2CoordEdit , SIGNAL ("textChanged(const QString &)" ), self .coordsChanged )
42
- self .connect (self .clipper , SIGNAL ("deactivated()" ), self .pauseClipping )
43
- self .connect (self .btnEnableClip , SIGNAL ("clicked()" ), self .startClipping )
37
+ self .connect (self .extentSelector , SIGNAL ("newExtentDefined()" ), self .checkRun )
38
+ self .connect (self .extentSelector , SIGNAL ("selectionStarted()" ), self .checkRun )
44
39
45
40
def show_ (self ):
46
41
self .connect (self .canvas , SIGNAL ("layersChanged()" ), self .fillInputFiles )
47
- self .btnEnableClip . setVisible ( False )
42
+ self .extentSelector . start ( )
48
43
BasePluginWidget .show_ (self )
49
44
50
45
self .fillInputFiles ()
51
- self .fillCoords ()
46
+ self .checkRun ()
52
47
53
48
def onClosing (self ):
54
49
self .disconnect (self .canvas , SIGNAL ("layersChanged()" ), self .fillInputFiles )
55
- self .stopClipping ()
50
+ self .extentSelector . stop ()
56
51
BasePluginWidget .onClosing (self )
57
52
58
- def stopClipping (self ):
59
- self .isClippingStarted = False
60
- self .canvas .unsetMapTool (self .clipper )
61
- self .clipper .reset ()
62
- self .btnEnableClip .setVisible (False )
63
-
64
- def startClipping (self ):
65
- self .canvas .setMapTool (self .clipper )
66
- self .isClippingStarted = True
67
- self .btnEnableClip .setVisible (False )
68
- self .coordsChanged ()
69
-
70
- def pauseClipping (self ):
71
- if not self .isClippingStarted :
72
- return
73
-
74
- self .btnEnableClip .setVisible (True )
75
-
76
53
def fillInputFiles (self ):
77
54
self .inputFiles = QStringList ()
78
55
@@ -88,59 +65,19 @@ def fillInputFiles(self):
88
65
self .inputFiles << layer .source ()
89
66
90
67
if self .inputFiles .isEmpty ():
91
- self .stopClipping ()
68
+ self .extentSelector . stop ()
92
69
93
70
if self .isVisible () and self .warningDialog .isHidden ():
94
71
msg = QString ( self .tr ("No active raster layers. You must add almost one raster layer to continue." ) )
95
72
self .warningDialog .showMessage (msg )
96
73
else :
97
74
self .warningDialog .hide ()
98
- self .startClipping ()
99
-
100
- self .checkRun ()
101
-
102
- def isCoordsValid (self ):
103
- return not ( self .x1CoordEdit .text ().isEmpty () or \
104
- self .x2CoordEdit .text ().isEmpty () or \
105
- self .y1CoordEdit .text ().isEmpty () or \
106
- self .y2CoordEdit .text ().isEmpty () )
107
-
108
- def coordsChanged (self ):
109
- if not self .isCoordsValid ():
110
- self .clipper .setClippingRectangle (None )
111
- else :
112
- point1 = QgsPoint ( float (self .x1CoordEdit .text ()), float (self .y1CoordEdit .text ()) )
113
- point2 = QgsPoint ( float (self .x2CoordEdit .text ()), float (self .y2CoordEdit .text ()) )
114
- rect = QgsRectangle (point1 , point2 )
115
-
116
- self .clipper .setClippingRectangle (rect )
117
-
118
- self .checkRun ()
119
-
120
- def fillCoords (self ):
121
- rect = self .clipper .clippingRectangle ()
122
- if rect != None :
123
- self .x1CoordEdit .setText ( str (rect .xMinimum ()) )
124
- self .x2CoordEdit .setText ( str (rect .xMaximum ()) )
125
- self .y1CoordEdit .setText ( str (rect .yMaximum ()) )
126
- self .y2CoordEdit .setText ( str (rect .yMinimum ()) )
127
- else :
128
- self .x1CoordEdit .clear ()
129
- self .x2CoordEdit .clear ()
130
- self .y1CoordEdit .clear ()
131
- self .y2CoordEdit .clear ()
75
+ self .extentSelector .start ()
132
76
133
77
self .checkRun ()
134
78
135
79
def checkRun (self ):
136
- self .someValueChanged ()
137
-
138
- self .x1CoordEdit .setEnabled ( not self .inputFiles .isEmpty () )
139
- self .x2CoordEdit .setEnabled ( not self .inputFiles .isEmpty () )
140
- self .y1CoordEdit .setEnabled ( not self .inputFiles .isEmpty () )
141
- self .y2CoordEdit .setEnabled ( not self .inputFiles .isEmpty () )
142
-
143
- self .base .enableRun ( not self .inputFiles .isEmpty () and self .isCoordsValid () )
80
+ self .base .enableRun ( not self .inputFiles .isEmpty () and self .extentSelector .getExtent () != None )
144
81
145
82
def fillOutputFileEdit (self ):
146
83
lastUsedFilter = Utils .FileFilter .lastUsedRasterFilter ()
@@ -163,8 +100,8 @@ def getArguments(self):
163
100
arguments << str (self .noDataSpin .value ())
164
101
if self .pctCheck .isChecked ():
165
102
arguments << "-pct"
166
- if self .isCoordsValid ():
167
- rect = self .clipper . clippingRectangle ()
103
+ if self .extentSelector . isCoordsValid ():
104
+ rect = self .extentSelector . getExtent ()
168
105
if rect != None :
169
106
arguments << "-ul_lr"
170
107
arguments << str (rect .xMinimum ())
@@ -186,77 +123,3 @@ def getOutputFileName(self):
186
123
def addLayerIntoCanvas (self , fileInfo ):
187
124
self .iface .addRasterLayer (fileInfo .filePath ())
188
125
189
-
190
- class ClipperSelector (QgsMapToolEmitPoint ):
191
- def __init__ (self , canvas ):
192
- self .canvas = canvas
193
- QgsMapToolEmitPoint .__init__ (self , self .canvas )
194
-
195
- self .rubberBand = QgsRubberBand ( self .canvas , True ) # true, its a polygon
196
- self .rubberBand .setColor ( Qt .red )
197
- self .rubberBand .setWidth ( 1 )
198
-
199
- self .isEmittingPoint = False
200
-
201
- self .startPoint = self .endPoint = None
202
-
203
- def reset (self ):
204
- self .isEmittingPoint = False
205
- self .rubberBand .reset ( True ) # true, its a polygon
206
-
207
- def canvasPressEvent (self , e ):
208
- self .startPoint = self .toMapCoordinates ( e .pos () )
209
- self .endPoint = self .startPoint
210
- self .isEmittingPoint = True
211
-
212
- self .showRect (self .startPoint , self .endPoint )
213
-
214
- def canvasReleaseEvent (self , e ):
215
- self .isEmittingPoint = False
216
- self .emit ( SIGNAL ("clippingRectangleCreated()" ) )
217
-
218
- def canvasMoveEvent (self , e ):
219
- if not self .isEmittingPoint :
220
- return
221
-
222
- self .endPoint = self .toMapCoordinates ( e .pos () )
223
- self .showRect (self .startPoint , self .endPoint )
224
-
225
- def showRect (self , startPoint , endPoint ):
226
- self .rubberBand .reset ( True ) # true, it's a polygon
227
-
228
- if startPoint .x () == endPoint .x () or startPoint .y () == endPoint .y ():
229
- return
230
-
231
- point1 = QgsPoint (startPoint .x (), startPoint .y ())
232
- point2 = QgsPoint (startPoint .x (), endPoint .y ())
233
- point3 = QgsPoint (endPoint .x (), endPoint .y ())
234
- point4 = QgsPoint (endPoint .x (), startPoint .y ())
235
-
236
- self .rubberBand .addPoint ( point1 , False )
237
- self .rubberBand .addPoint ( point2 , False )
238
- self .rubberBand .addPoint ( point3 , False )
239
- self .rubberBand .addPoint ( point4 , True ) # true to update canvas
240
- self .rubberBand .show ()
241
-
242
- def clippingRectangle (self ):
243
- if self .startPoint == None or self .endPoint == None :
244
- return None
245
- elif self .startPoint .x () == self .endPoint .x () or self .startPoint .y () == self .endPoint .y ():
246
- return None
247
-
248
- return QgsRectangle (self .startPoint , self .endPoint )
249
-
250
- def setClippingRectangle (self , rect ):
251
- if rect == None :
252
- self .reset ()
253
- return
254
-
255
- self .startPoint = QgsPoint (rect .xMaximum (), rect .yMaximum ())
256
- self .endPoint = QgsPoint (rect .xMinimum (), rect .yMinimum ())
257
- self .showRect (self .startPoint , self .endPoint )
258
-
259
- def deactivate (self ):
260
- QgsMapTool .deactivate (self )
261
- self .emit (SIGNAL ("deactivated()" ))
262
-
0 commit comments