19
19
#include " qgsgrass.h"
20
20
#include " qgsgrassprovider.h"
21
21
22
+ #include " qgsgrassaddfeature.h"
22
23
#include " qgsgrasseditrenderer.h"
23
24
#include " qgsgrassnewmapset.h"
24
25
#include " qgsgrassregion.h"
@@ -81,6 +82,17 @@ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace )
81
82
, mCloseMapsetAction( 0 )
82
83
, mOpenToolsAction( 0 )
83
84
, mNewVectorAction( 0 )
85
+ , mAddFeatureAction( 0 )
86
+ , mAddPointAction( 0 )
87
+ , mAddLineAction( 0 )
88
+ , mAddBoundaryAction( 0 )
89
+ , mAddCentroidAction( 0 )
90
+ , mAddAreaAction( 0 )
91
+ , mAddPoint( 0 )
92
+ , mAddLine( 0 )
93
+ , mAddBoundary( 0 )
94
+ , mAddCentroid( 0 )
95
+ , mAddArea()
84
96
{
85
97
}
86
98
@@ -164,7 +176,7 @@ void QgsGrassPlugin::initGui()
164
176
mCloseMapsetAction ->setObjectName ( " mCloseMapsetAction" );
165
177
166
178
mOpenToolsAction = new QAction ( QIcon (), tr ( " Open GRASS Tools" ), this );
167
- mOpenToolsAction ->setObjectName ( " mOpenToolsAction " );
179
+ mOpenToolsAction ->setObjectName ( " mAddPolygonActionmOpenToolsAction " );
168
180
mOpenToolsAction ->setWhatsThis ( tr ( " Open GRASS tools" ) );
169
181
170
182
mRegionAction = new QAction ( QIcon (), tr ( " Display Current Grass Region" ), this );
@@ -204,6 +216,60 @@ void QgsGrassPlugin::initGui()
204
216
mToolBarPointer ->addAction ( mOpenToolsAction );
205
217
mToolBarPointer ->addAction ( mRegionAction );
206
218
219
+ // Editing
220
+ mAddPointAction = new QAction ( QgsApplication::getThemeIcon ( " /mActionCapturePoint.png" ), tr ( " Add Point" ), this );
221
+ mAddPointAction ->setObjectName ( " mAddPointAction" );
222
+ mAddPointAction ->setCheckable ( true );
223
+
224
+ mAddLineAction = new QAction ( QgsApplication::getThemeIcon ( " /mActionCaptureLine.png" ), tr ( " Add Line" ), this );
225
+ mAddLineAction ->setObjectName ( " mAddLineAction" );
226
+ mAddLineAction ->setCheckable ( true );
227
+
228
+ mAddBoundaryAction = new QAction ( getThemeIcon ( " mActionCaptureBoundary.png" ), tr ( " Add Boundary" ), this );
229
+ mAddBoundaryAction ->setObjectName ( " mAddBoundaryAction" );
230
+ mAddBoundaryAction ->setCheckable ( true );
231
+
232
+ mAddCentroidAction = new QAction ( getThemeIcon ( " mActionCaptureCentroid.png" ), tr ( " Add Centroid" ), this );
233
+ mAddCentroidAction ->setObjectName ( " mAddCentroidAction" );
234
+ mAddCentroidAction ->setCheckable ( true );
235
+
236
+ mAddAreaAction = new QAction ( QgsApplication::getThemeIcon ( " /mActionCapturePolygon.png" ), tr ( " Add Area" ), this );
237
+ mAddAreaAction ->setObjectName ( " mAddAreaAction" );
238
+ mAddAreaAction ->setCheckable ( true );
239
+
240
+ connect ( mAddPointAction , SIGNAL ( triggered () ), SLOT ( addFeature () ) );
241
+ connect ( mAddLineAction , SIGNAL ( triggered () ), SLOT ( addFeature () ) );
242
+ connect ( mAddBoundaryAction , SIGNAL ( triggered () ), SLOT ( addFeature () ) );
243
+ connect ( mAddCentroidAction , SIGNAL ( triggered () ), SLOT ( addFeature () ) );
244
+ connect ( mAddAreaAction , SIGNAL ( triggered () ), SLOT ( addFeature () ) );
245
+
246
+ mAddFeatureAction = qGisInterface->actionAddFeature ();
247
+
248
+ mAddFeatureAction ->actionGroup ()->addAction ( mAddPointAction );
249
+ mAddFeatureAction ->actionGroup ()->addAction ( mAddLineAction );
250
+ mAddFeatureAction ->actionGroup ()->addAction ( mAddBoundaryAction );
251
+ mAddFeatureAction ->actionGroup ()->addAction ( mAddCentroidAction );
252
+ mAddFeatureAction ->actionGroup ()->addAction ( mAddAreaAction );
253
+
254
+ qGisInterface->digitizeToolBar ()->insertAction ( mAddFeatureAction , mAddPointAction );
255
+ qGisInterface->digitizeToolBar ()->insertAction ( mAddFeatureAction , mAddLineAction );
256
+ qGisInterface->digitizeToolBar ()->insertAction ( mAddFeatureAction , mAddBoundaryAction );
257
+ qGisInterface->digitizeToolBar ()->insertAction ( mAddFeatureAction , mAddCentroidAction );
258
+ qGisInterface->digitizeToolBar ()->insertAction ( mAddFeatureAction , mAddAreaAction );
259
+
260
+ resetEditActions ();
261
+
262
+ mAddPoint = new QgsGrassAddFeature ( qGisInterface->mapCanvas (), QgsMapToolAdvancedDigitizing::CapturePoint );
263
+ mAddPoint ->setAction ( mAddPointAction );
264
+ mAddLine = new QgsGrassAddFeature ( qGisInterface->mapCanvas (), QgsMapToolAdvancedDigitizing::CaptureLine );
265
+ mAddLine ->setAction ( mAddLineAction );
266
+ mAddBoundary = new QgsGrassAddFeature ( qGisInterface->mapCanvas (), QgsMapToolAdvancedDigitizing::CaptureLine );
267
+ mAddBoundary ->setAction ( mAddBoundaryAction );
268
+ mAddCentroid = new QgsGrassAddFeature ( qGisInterface->mapCanvas (), QgsMapToolAdvancedDigitizing::CapturePoint );
269
+ mAddCentroid ->setAction ( mAddCentroidAction );
270
+ mAddArea = new QgsGrassAddFeature ( qGisInterface->mapCanvas (), QgsMapToolAdvancedDigitizing::CapturePolygon );
271
+ mAddArea ->setAction ( mAddAreaAction );
272
+
207
273
// Set icons to current theme
208
274
setCurrentTheme ( " " );
209
275
// Connect theme change signal
@@ -249,6 +315,37 @@ void QgsGrassPlugin::onCurrentLayerChanged( QgsMapLayer* layer )
249
315
{
250
316
Q_UNUSED ( layer );
251
317
QgsDebugMsg ( " Entered" );
318
+ resetEditActions ();
319
+ }
320
+
321
+ void QgsGrassPlugin::resetEditActions ()
322
+ {
323
+ QgsDebugMsg ( " Entered" );
324
+
325
+ QgsGrassProvider* grassProvider = 0 ;
326
+ QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( qGisInterface->activeLayer () );
327
+ if ( vectorLayer )
328
+ {
329
+ grassProvider = dynamic_cast <QgsGrassProvider*>( vectorLayer->dataProvider () );
330
+ }
331
+ if ( grassProvider && vectorLayer->editBuffer () )
332
+ {
333
+ mAddFeatureAction ->setVisible ( false );
334
+ mAddPointAction ->setVisible ( true );
335
+ mAddLineAction ->setVisible ( true );
336
+ mAddBoundaryAction ->setVisible ( true );
337
+ mAddCentroidAction ->setVisible ( true );
338
+ mAddAreaAction ->setVisible ( true );
339
+ }
340
+ else
341
+ {
342
+ mAddFeatureAction ->setVisible ( true );
343
+ mAddPointAction ->setVisible ( false );
344
+ mAddLineAction ->setVisible ( false );
345
+ mAddBoundaryAction ->setVisible ( false );
346
+ mAddCentroidAction ->setVisible ( false );
347
+ mAddAreaAction ->setVisible ( false );
348
+ }
252
349
}
253
350
254
351
void QgsGrassPlugin::onEditingStarted ()
@@ -298,6 +395,8 @@ void QgsGrassPlugin::onEditingStarted()
298
395
vectorLayer->updateFields ();
299
396
300
397
connect ( vectorLayer, SIGNAL ( editingStopped () ), SLOT ( onEditingStopped () ) );
398
+
399
+ resetEditActions ();
301
400
}
302
401
303
402
void QgsGrassPlugin::onEditingStopped ()
@@ -313,6 +412,48 @@ void QgsGrassPlugin::onEditingStopped()
313
412
vectorLayer->styleManager ()->setCurrentStyle ( style );
314
413
}
315
414
}
415
+ resetEditActions ();
416
+ }
417
+
418
+ void QgsGrassPlugin::addFeature ()
419
+ {
420
+ QgsDebugMsg ( " entered" );
421
+ QgsGrassProvider* grassProvider = 0 ;
422
+ QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( qGisInterface->activeLayer () );
423
+ if ( vectorLayer )
424
+ {
425
+ grassProvider = dynamic_cast <QgsGrassProvider*>( vectorLayer->dataProvider () );
426
+ }
427
+ if ( !grassProvider )
428
+ {
429
+ QgsDebugMsg ( " grassProvider is null" );
430
+ return ;
431
+ }
432
+ if ( sender () == mAddPointAction )
433
+ {
434
+ qGisInterface->mapCanvas ()->setMapTool ( mAddPoint );
435
+ grassProvider->setNewFeatureType ( GV_POINT );
436
+ }
437
+ else if ( sender () == mAddLineAction )
438
+ {
439
+ qGisInterface->mapCanvas ()->setMapTool ( mAddLine );
440
+ grassProvider->setNewFeatureType ( GV_LINE );
441
+ }
442
+ else if ( sender () == mAddBoundaryAction )
443
+ {
444
+ qGisInterface->mapCanvas ()->setMapTool ( mAddBoundary );
445
+ grassProvider->setNewFeatureType ( GV_BOUNDARY );
446
+ }
447
+ else if ( sender () == mAddCentroidAction )
448
+ {
449
+ qGisInterface->mapCanvas ()->setMapTool ( mAddCentroid );
450
+ grassProvider->setNewFeatureType ( GV_CENTROID );
451
+ }
452
+ else if ( sender () == mAddAreaAction )
453
+ {
454
+ qGisInterface->mapCanvas ()->setMapTool ( mAddArea );
455
+ grassProvider->setNewFeatureType ( GV_AREA );
456
+ }
316
457
}
317
458
318
459
void QgsGrassPlugin::mapsetChanged ()
@@ -593,6 +734,8 @@ void QgsGrassPlugin::newProject()
593
734
// Unload the plugin by cleaning up the GUI
594
735
void QgsGrassPlugin::unload ()
595
736
{
737
+ mAddFeatureAction ->setVisible ( true ); // restore QGIS add feature action
738
+
596
739
// Close mapset
597
740
QgsGrass::instance ()->closeMapsetWarn ();
598
741
@@ -611,6 +754,19 @@ void QgsGrassPlugin::unload()
611
754
delete mRegionAction ;
612
755
delete mNewVectorAction ;
613
756
757
+ delete mAddFeatureAction ;
758
+ delete mAddPointAction ;
759
+ delete mAddLineAction ;
760
+ delete mAddBoundaryAction ;
761
+ delete mAddCentroidAction ;
762
+ delete mAddAreaAction ;
763
+
764
+ delete mAddPoint ;
765
+ delete mAddLine ;
766
+ delete mAddBoundary ;
767
+ delete mAddCentroid ;
768
+ delete mAddArea ;
769
+
614
770
delete mToolBarPointer ;
615
771
mToolBarPointer = 0 ;
616
772
0 commit comments