Skip to content

Commit

Permalink
QgsMapToolAddFeature - allow to set capture mode and disable type check
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Sep 23, 2015
1 parent 17cb59f commit d4677c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/app/qgsmaptooladdfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
#include <QMouseEvent>
#include <QSettings>

QgsMapToolAddFeature::QgsMapToolAddFeature( QgsMapCanvas* canvas )
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget() )
QgsMapToolAddFeature::QgsMapToolAddFeature( QgsMapCanvas* canvas, CaptureMode mode )
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), mode )
, mCheckGeometryType( true )
{
mToolName = tr( "Add feature" );
}
Expand Down Expand Up @@ -100,7 +101,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
return;

//check we only use this tool for point/multipoint layers
if ( vlayer->geometryType() != QGis::Point )
if ( vlayer->geometryType() != QGis::Point && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture point' tool on this vector layer" ), QgsMessageBar::WARNING );
return;
Expand Down Expand Up @@ -137,6 +138,11 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
{
g = QgsGeometry::fromMultiPoint( QgsMultiPoint() << savePoint );
}
else
{
// if layer supports more types (mCheckGeometryType is false)
g = QgsGeometry::fromPoint( savePoint );
}

f.setGeometry( g );
f.setValid( true );
Expand All @@ -151,14 +157,14 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
else if ( mode() == CaptureLine || mode() == CapturePolygon )
{
//check we only use the line tool for line/multiline layers
if ( mode() == CaptureLine && vlayer->geometryType() != QGis::Line )
if ( mode() == CaptureLine && vlayer->geometryType() != QGis::Line && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture line' tool on this vector layer" ), QgsMessageBar::WARNING );
return;
}

//check we only use the polygon tool for polygon/multipolygon layers
if ( mode() == CapturePolygon && vlayer->geometryType() != QGis::Polygon )
if ( mode() == CapturePolygon && vlayer->geometryType() != QGis::Polygon && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture polygon' tool on this vector layer" ), QgsMessageBar::WARNING );
return;
Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsmaptooladdfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ class APP_EXPORT QgsMapToolAddFeature : public QgsMapToolCapture
{
Q_OBJECT
public:
QgsMapToolAddFeature( QgsMapCanvas* canvas );
/** @note mode parameter added in QGIS 2.12 */
QgsMapToolAddFeature( QgsMapCanvas* canvas, CaptureMode mode = CaptureNone );
virtual ~QgsMapToolAddFeature();
void cadCanvasReleaseEvent( QgsMapMouseEvent * e ) override;

bool addFeature( QgsVectorLayer *vlayer, QgsFeature *f, bool showModal = true );
void activate() override;

protected:
/** Check if CaptureMode match layer type. Default is true.
* @note Added in 2.12 */
bool mCheckGeometryType;
};

0 comments on commit d4677c7

Please sign in to comment.