Skip to content

Commit

Permalink
[GRASS] editing - all geometry types
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Sep 23, 2015
1 parent d4677c7 commit e9817d5
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/plugins/grass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ENDIF (WIN32)
# Files

SET (GRASS_PLUGIN_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassaddfeature.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrasseditrenderer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassplugin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassselect.cpp
Expand All @@ -46,6 +47,7 @@ SET (GRASS_PLUGIN_UIS
)

SET (GRASS_PLUGIN_MOC_HDRS
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassaddfeature.h
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrasseditrenderer.h
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassplugin.h
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassselect.h
Expand Down Expand Up @@ -149,6 +151,7 @@ SET (GRASS_BROWSER_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/qgis.g.browser.cpp)
INCLUDE_DIRECTORIES(
..
${CMAKE_CURRENT_BINARY_DIR}
../../app
../../core
../../core/geometry
../../core/layertree
Expand Down Expand Up @@ -189,6 +192,7 @@ MACRO(ADD_GRASSPLUGIN GRASS_BUILD_VERSION)

TARGET_LINK_LIBRARIES(grassplugin${GRASS_BUILD_VERSION}
qgisgrass${GRASS_BUILD_VERSION}
qgis_app
qgis_gui
${OPENPTY_LIBRARY}
)
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/grass/qgsgrass_plugin.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<file alias="grass_set_region.png">themes/default/grass_set_region.png</file>
<file alias="grass_shell.png">themes/default/grass_shell.png</file>
<file alias="grass_tools.png">themes/default/grass_tools.png</file>
<file alias="mActionCaptureBoundary.png">themes/default/mActionCaptureBoundary.png</file>
<file alias="mActionCaptureCentroid.png">themes/default/mActionCaptureCentroid.png</file>
<file alias="mapcalc_add_connection.png">themes/default/mapcalc_add_connection.png</file>
<file alias="mapcalc_add_constant.png">themes/default/mapcalc_add_constant.png</file>
<file alias="mapcalc_add_function.png">themes/default/mapcalc_add_function.png</file>
Expand Down
27 changes: 27 additions & 0 deletions src/plugins/grass/qgsgrassaddfeature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/***************************************************************************
qgsgrassaddfeature.h
-------------------
begin : September, 2015
copyright : (C) 2015 by Radim Blazek
email : radim.blazek@gmail.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. *
* *
***************************************************************************/

#include "qgsgrassaddfeature.h"

QgsGrassAddFeature::QgsGrassAddFeature(QgsMapCanvas* canvas, CaptureMode mode)
: QgsMapToolAddFeature(canvas, mode)
{
mCheckGeometryType = false;
}

QgsGrassAddFeature::~QgsGrassAddFeature()
{
}
30 changes: 30 additions & 0 deletions src/plugins/grass/qgsgrassaddfeature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/***************************************************************************
qgsgrassaddfeature.h
-------------------
begin : September, 2015
copyright : (C) 2015 by Radim Blazek
email : radim.blazek@gmail.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. *
* *
***************************************************************************/

#ifndef QGSGRASSADDFEATURE_H
#define QGSGRASSADDFEATURE_H

#include "qgsmaptooladdfeature.h"

class QgsGrassAddFeature : public QgsMapToolAddFeature
{
Q_OBJECT
public:
QgsGrassAddFeature( QgsMapCanvas* canvas, CaptureMode mode = CaptureNone );
virtual ~QgsGrassAddFeature() override;
};

#endif // QGSGRASSADDFEATURE_H
158 changes: 157 additions & 1 deletion src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsgrass.h"
#include "qgsgrassprovider.h"

#include "qgsgrassaddfeature.h"
#include "qgsgrasseditrenderer.h"
#include "qgsgrassnewmapset.h"
#include "qgsgrassregion.h"
Expand Down Expand Up @@ -81,6 +82,17 @@ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace )
, mCloseMapsetAction( 0 )
, mOpenToolsAction( 0 )
, mNewVectorAction( 0 )
, mAddFeatureAction( 0 )
, mAddPointAction( 0 )
, mAddLineAction( 0 )
, mAddBoundaryAction( 0 )
, mAddCentroidAction( 0 )
, mAddAreaAction( 0 )
, mAddPoint( 0 )
, mAddLine( 0 )
, mAddBoundary( 0 )
, mAddCentroid( 0 )
, mAddArea()
{
}

Expand Down Expand Up @@ -164,7 +176,7 @@ void QgsGrassPlugin::initGui()
mCloseMapsetAction->setObjectName( "mCloseMapsetAction" );

mOpenToolsAction = new QAction( QIcon(), tr( "Open GRASS Tools" ), this );
mOpenToolsAction->setObjectName( "mOpenToolsAction" );
mOpenToolsAction->setObjectName( "mAddPolygonActionmOpenToolsAction" );
mOpenToolsAction->setWhatsThis( tr( "Open GRASS tools" ) );

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

// Editing
mAddPointAction = new QAction( QgsApplication::getThemeIcon( "/mActionCapturePoint.png" ), tr( "Add Point" ), this );
mAddPointAction->setObjectName( "mAddPointAction" );
mAddPointAction->setCheckable( true );

mAddLineAction = new QAction( QgsApplication::getThemeIcon( "/mActionCaptureLine.png" ), tr( "Add Line" ), this );
mAddLineAction->setObjectName( "mAddLineAction" );
mAddLineAction->setCheckable( true );

mAddBoundaryAction = new QAction( getThemeIcon( "mActionCaptureBoundary.png" ), tr( "Add Boundary" ), this );
mAddBoundaryAction->setObjectName( "mAddBoundaryAction" );
mAddBoundaryAction->setCheckable( true );

mAddCentroidAction = new QAction( getThemeIcon( "mActionCaptureCentroid.png" ), tr( "Add Centroid" ), this );
mAddCentroidAction->setObjectName( "mAddCentroidAction" );
mAddCentroidAction->setCheckable( true );

mAddAreaAction = new QAction( QgsApplication::getThemeIcon( "/mActionCapturePolygon.png" ), tr( "Add Area" ), this );
mAddAreaAction->setObjectName( "mAddAreaAction" );
mAddAreaAction->setCheckable( true );

connect( mAddPointAction, SIGNAL( triggered() ), SLOT( addFeature() ) );
connect( mAddLineAction, SIGNAL( triggered() ), SLOT( addFeature() ) );
connect( mAddBoundaryAction, SIGNAL( triggered() ), SLOT( addFeature() ) );
connect( mAddCentroidAction, SIGNAL( triggered() ), SLOT( addFeature() ) );
connect( mAddAreaAction, SIGNAL( triggered() ), SLOT( addFeature() ) );

mAddFeatureAction = qGisInterface->actionAddFeature();

mAddFeatureAction->actionGroup()->addAction( mAddPointAction );
mAddFeatureAction->actionGroup()->addAction( mAddLineAction );
mAddFeatureAction->actionGroup()->addAction( mAddBoundaryAction );
mAddFeatureAction->actionGroup()->addAction( mAddCentroidAction );
mAddFeatureAction->actionGroup()->addAction( mAddAreaAction );

qGisInterface->digitizeToolBar()->insertAction( mAddFeatureAction, mAddPointAction );
qGisInterface->digitizeToolBar()->insertAction( mAddFeatureAction, mAddLineAction );
qGisInterface->digitizeToolBar()->insertAction( mAddFeatureAction, mAddBoundaryAction );
qGisInterface->digitizeToolBar()->insertAction( mAddFeatureAction, mAddCentroidAction );
qGisInterface->digitizeToolBar()->insertAction( mAddFeatureAction, mAddAreaAction );

resetEditActions();

mAddPoint = new QgsGrassAddFeature( qGisInterface->mapCanvas(), QgsMapToolAdvancedDigitizing::CapturePoint );
mAddPoint->setAction( mAddPointAction );
mAddLine = new QgsGrassAddFeature( qGisInterface->mapCanvas(), QgsMapToolAdvancedDigitizing::CaptureLine );
mAddLine->setAction( mAddLineAction );
mAddBoundary = new QgsGrassAddFeature( qGisInterface->mapCanvas(), QgsMapToolAdvancedDigitizing::CaptureLine );
mAddBoundary->setAction( mAddBoundaryAction );
mAddCentroid = new QgsGrassAddFeature( qGisInterface->mapCanvas(), QgsMapToolAdvancedDigitizing::CapturePoint );
mAddCentroid->setAction( mAddCentroidAction );
mAddArea = new QgsGrassAddFeature( qGisInterface->mapCanvas(), QgsMapToolAdvancedDigitizing::CapturePolygon );
mAddArea->setAction( mAddAreaAction );

// Set icons to current theme
setCurrentTheme( "" );
// Connect theme change signal
Expand Down Expand Up @@ -249,6 +315,37 @@ void QgsGrassPlugin::onCurrentLayerChanged( QgsMapLayer* layer )
{
Q_UNUSED( layer );
QgsDebugMsg( "Entered" );
resetEditActions();
}

void QgsGrassPlugin::resetEditActions()
{
QgsDebugMsg( "Entered" );

QgsGrassProvider* grassProvider = 0;
QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( qGisInterface->activeLayer() );
if ( vectorLayer )
{
grassProvider = dynamic_cast<QgsGrassProvider*>( vectorLayer->dataProvider() );
}
if ( grassProvider && vectorLayer->editBuffer() )
{
mAddFeatureAction->setVisible( false );
mAddPointAction->setVisible( true );
mAddLineAction->setVisible( true );
mAddBoundaryAction->setVisible( true );
mAddCentroidAction->setVisible( true );
mAddAreaAction->setVisible( true );
}
else
{
mAddFeatureAction->setVisible( true );
mAddPointAction->setVisible( false );
mAddLineAction->setVisible( false );
mAddBoundaryAction->setVisible( false );
mAddCentroidAction->setVisible( false );
mAddAreaAction->setVisible( false );
}
}

void QgsGrassPlugin::onEditingStarted()
Expand Down Expand Up @@ -298,6 +395,8 @@ void QgsGrassPlugin::onEditingStarted()
vectorLayer->updateFields();

connect( vectorLayer, SIGNAL( editingStopped() ), SLOT( onEditingStopped() ) );

resetEditActions();
}

void QgsGrassPlugin::onEditingStopped()
Expand All @@ -313,6 +412,48 @@ void QgsGrassPlugin::onEditingStopped()
vectorLayer->styleManager()->setCurrentStyle( style );
}
}
resetEditActions();
}

void QgsGrassPlugin::addFeature()
{
QgsDebugMsg( "entered" );
QgsGrassProvider* grassProvider = 0;
QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( qGisInterface->activeLayer() );
if ( vectorLayer )
{
grassProvider = dynamic_cast<QgsGrassProvider*>( vectorLayer->dataProvider() );
}
if ( !grassProvider )
{
QgsDebugMsg( "grassProvider is null" );
return;
}
if ( sender() == mAddPointAction )
{
qGisInterface->mapCanvas()->setMapTool( mAddPoint );
grassProvider->setNewFeatureType( GV_POINT );
}
else if ( sender() == mAddLineAction )
{
qGisInterface->mapCanvas()->setMapTool( mAddLine );
grassProvider->setNewFeatureType( GV_LINE );
}
else if ( sender() == mAddBoundaryAction )
{
qGisInterface->mapCanvas()->setMapTool( mAddBoundary );
grassProvider->setNewFeatureType( GV_BOUNDARY );
}
else if ( sender() == mAddCentroidAction )
{
qGisInterface->mapCanvas()->setMapTool( mAddCentroid );
grassProvider->setNewFeatureType( GV_CENTROID );
}
else if ( sender() == mAddAreaAction )
{
qGisInterface->mapCanvas()->setMapTool( mAddArea );
grassProvider->setNewFeatureType( GV_AREA );
}
}

void QgsGrassPlugin::mapsetChanged()
Expand Down Expand Up @@ -593,6 +734,8 @@ void QgsGrassPlugin::newProject()
// Unload the plugin by cleaning up the GUI
void QgsGrassPlugin::unload()
{
mAddFeatureAction->setVisible( true ); // restore QGIS add feature action

// Close mapset
QgsGrass::instance()->closeMapsetWarn();

Expand All @@ -611,6 +754,19 @@ void QgsGrassPlugin::unload()
delete mRegionAction;
delete mNewVectorAction;

delete mAddFeatureAction;
delete mAddPointAction;
delete mAddLineAction;
delete mAddBoundaryAction;
delete mAddCentroidAction;
delete mAddAreaAction;

delete mAddPoint;
delete mAddLine;
delete mAddBoundary;
delete mAddCentroid;
delete mAddArea;

delete mToolBarPointer;
mToolBarPointer = 0;

Expand Down
21 changes: 21 additions & 0 deletions src/plugins/grass/qgsgrassplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class QgsGrassRegion;

class QgsMapCanvas;
class QgsMapLayer;
class QgsMapTool;
class QgsRubberBand;
class QgsVectorLayer;

Expand Down Expand Up @@ -117,7 +118,13 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
void onEditingStarted();
void onEditingStopped();
void onCurrentLayerChanged( QgsMapLayer* layer );

// Start editing tools
void addFeature();

private:
void resetEditActions();

//! Pointer to our toolbar
QToolBar *mToolBarPointer;
//! Pointer to the QGIS interface object
Expand Down Expand Up @@ -145,6 +152,20 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
QAction *mOpenToolsAction;
QAction *mNewVectorAction;

// Editing
QAction *mAddFeatureAction;
QAction *mAddPointAction;
QAction *mAddLineAction;
QAction *mAddBoundaryAction;
QAction *mAddCentroidAction;
QAction *mAddAreaAction;

QgsMapTool *mAddPoint;
QgsMapTool *mAddLine;
QgsMapTool *mAddBoundary;
QgsMapTool *mAddCentroid;
QgsMapTool *mAddArea;

// Names of layer styles before editing started
QMap<QgsVectorLayer *, QString> mOldStyles;
};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e9817d5

Please sign in to comment.