Skip to content

Commit e9817d5

Browse files
committed
[GRASS] editing - all geometry types
1 parent d4677c7 commit e9817d5

11 files changed

+259
-21
lines changed

src/plugins/grass/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ENDIF (WIN32)
2020
# Files
2121

2222
SET (GRASS_PLUGIN_SRCS
23+
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassaddfeature.cpp
2324
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrasseditrenderer.cpp
2425
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassplugin.cpp
2526
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassselect.cpp
@@ -46,6 +47,7 @@ SET (GRASS_PLUGIN_UIS
4647
)
4748

4849
SET (GRASS_PLUGIN_MOC_HDRS
50+
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassaddfeature.h
4951
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrasseditrenderer.h
5052
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassplugin.h
5153
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassselect.h
@@ -149,6 +151,7 @@ SET (GRASS_BROWSER_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/qgis.g.browser.cpp)
149151
INCLUDE_DIRECTORIES(
150152
..
151153
${CMAKE_CURRENT_BINARY_DIR}
154+
../../app
152155
../../core
153156
../../core/geometry
154157
../../core/layertree
@@ -189,6 +192,7 @@ MACRO(ADD_GRASSPLUGIN GRASS_BUILD_VERSION)
189192

190193
TARGET_LINK_LIBRARIES(grassplugin${GRASS_BUILD_VERSION}
191194
qgisgrass${GRASS_BUILD_VERSION}
195+
qgis_app
192196
qgis_gui
193197
${OPENPTY_LIBRARY}
194198
)

src/plugins/grass/qgsgrass_plugin.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<file alias="grass_set_region.png">themes/default/grass_set_region.png</file>
1616
<file alias="grass_shell.png">themes/default/grass_shell.png</file>
1717
<file alias="grass_tools.png">themes/default/grass_tools.png</file>
18+
<file alias="mActionCaptureBoundary.png">themes/default/mActionCaptureBoundary.png</file>
19+
<file alias="mActionCaptureCentroid.png">themes/default/mActionCaptureCentroid.png</file>
1820
<file alias="mapcalc_add_connection.png">themes/default/mapcalc_add_connection.png</file>
1921
<file alias="mapcalc_add_constant.png">themes/default/mapcalc_add_constant.png</file>
2022
<file alias="mapcalc_add_function.png">themes/default/mapcalc_add_function.png</file>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/***************************************************************************
2+
qgsgrassaddfeature.h
3+
-------------------
4+
begin : September, 2015
5+
copyright : (C) 2015 by Radim Blazek
6+
email : radim.blazek@gmail.com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgsgrassaddfeature.h"
18+
19+
QgsGrassAddFeature::QgsGrassAddFeature(QgsMapCanvas* canvas, CaptureMode mode)
20+
: QgsMapToolAddFeature(canvas, mode)
21+
{
22+
mCheckGeometryType = false;
23+
}
24+
25+
QgsGrassAddFeature::~QgsGrassAddFeature()
26+
{
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/***************************************************************************
2+
qgsgrassaddfeature.h
3+
-------------------
4+
begin : September, 2015
5+
copyright : (C) 2015 by Radim Blazek
6+
email : radim.blazek@gmail.com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSGRASSADDFEATURE_H
18+
#define QGSGRASSADDFEATURE_H
19+
20+
#include "qgsmaptooladdfeature.h"
21+
22+
class QgsGrassAddFeature : public QgsMapToolAddFeature
23+
{
24+
Q_OBJECT
25+
public:
26+
QgsGrassAddFeature( QgsMapCanvas* canvas, CaptureMode mode = CaptureNone );
27+
virtual ~QgsGrassAddFeature() override;
28+
};
29+
30+
#endif // QGSGRASSADDFEATURE_H

src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsgrass.h"
2020
#include "qgsgrassprovider.h"
2121

22+
#include "qgsgrassaddfeature.h"
2223
#include "qgsgrasseditrenderer.h"
2324
#include "qgsgrassnewmapset.h"
2425
#include "qgsgrassregion.h"
@@ -81,6 +82,17 @@ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace )
8182
, mCloseMapsetAction( 0 )
8283
, mOpenToolsAction( 0 )
8384
, 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()
8496
{
8597
}
8698

@@ -164,7 +176,7 @@ void QgsGrassPlugin::initGui()
164176
mCloseMapsetAction->setObjectName( "mCloseMapsetAction" );
165177

166178
mOpenToolsAction = new QAction( QIcon(), tr( "Open GRASS Tools" ), this );
167-
mOpenToolsAction->setObjectName( "mOpenToolsAction" );
179+
mOpenToolsAction->setObjectName( "mAddPolygonActionmOpenToolsAction" );
168180
mOpenToolsAction->setWhatsThis( tr( "Open GRASS tools" ) );
169181

170182
mRegionAction = new QAction( QIcon(), tr( "Display Current Grass Region" ), this );
@@ -204,6 +216,60 @@ void QgsGrassPlugin::initGui()
204216
mToolBarPointer->addAction( mOpenToolsAction );
205217
mToolBarPointer->addAction( mRegionAction );
206218

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+
207273
// Set icons to current theme
208274
setCurrentTheme( "" );
209275
// Connect theme change signal
@@ -249,6 +315,37 @@ void QgsGrassPlugin::onCurrentLayerChanged( QgsMapLayer* layer )
249315
{
250316
Q_UNUSED( layer );
251317
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+
}
252349
}
253350

254351
void QgsGrassPlugin::onEditingStarted()
@@ -298,6 +395,8 @@ void QgsGrassPlugin::onEditingStarted()
298395
vectorLayer->updateFields();
299396

300397
connect( vectorLayer, SIGNAL( editingStopped() ), SLOT( onEditingStopped() ) );
398+
399+
resetEditActions();
301400
}
302401

303402
void QgsGrassPlugin::onEditingStopped()
@@ -313,6 +412,48 @@ void QgsGrassPlugin::onEditingStopped()
313412
vectorLayer->styleManager()->setCurrentStyle( style );
314413
}
315414
}
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+
}
316457
}
317458

318459
void QgsGrassPlugin::mapsetChanged()
@@ -593,6 +734,8 @@ void QgsGrassPlugin::newProject()
593734
// Unload the plugin by cleaning up the GUI
594735
void QgsGrassPlugin::unload()
595736
{
737+
mAddFeatureAction->setVisible( true ); // restore QGIS add feature action
738+
596739
// Close mapset
597740
QgsGrass::instance()->closeMapsetWarn();
598741

@@ -611,6 +754,19 @@ void QgsGrassPlugin::unload()
611754
delete mRegionAction;
612755
delete mNewVectorAction;
613756

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+
614770
delete mToolBarPointer;
615771
mToolBarPointer = 0;
616772

src/plugins/grass/qgsgrassplugin.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class QgsGrassRegion;
2626

2727
class QgsMapCanvas;
2828
class QgsMapLayer;
29+
class QgsMapTool;
2930
class QgsRubberBand;
3031
class QgsVectorLayer;
3132

@@ -117,7 +118,13 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
117118
void onEditingStarted();
118119
void onEditingStopped();
119120
void onCurrentLayerChanged( QgsMapLayer* layer );
121+
122+
// Start editing tools
123+
void addFeature();
124+
120125
private:
126+
void resetEditActions();
127+
121128
//! Pointer to our toolbar
122129
QToolBar *mToolBarPointer;
123130
//! Pointer to the QGIS interface object
@@ -145,6 +152,20 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
145152
QAction *mOpenToolsAction;
146153
QAction *mNewVectorAction;
147154

155+
// Editing
156+
QAction *mAddFeatureAction;
157+
QAction *mAddPointAction;
158+
QAction *mAddLineAction;
159+
QAction *mAddBoundaryAction;
160+
QAction *mAddCentroidAction;
161+
QAction *mAddAreaAction;
162+
163+
QgsMapTool *mAddPoint;
164+
QgsMapTool *mAddLine;
165+
QgsMapTool *mAddBoundary;
166+
QgsMapTool *mAddCentroid;
167+
QgsMapTool *mAddArea;
168+
148169
// Names of layer styles before editing started
149170
QMap<QgsVectorLayer *, QString> mOldStyles;
150171
};
Loading
Loading

0 commit comments

Comments
 (0)