Skip to content

Commit d4677c7

Browse files
committedSep 23, 2015
QgsMapToolAddFeature - allow to set capture mode and disable type check
1 parent 17cb59f commit d4677c7

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
 

‎src/app/qgsmaptooladdfeature.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
#include <QMouseEvent>
3636
#include <QSettings>
3737

38-
QgsMapToolAddFeature::QgsMapToolAddFeature( QgsMapCanvas* canvas )
39-
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget() )
38+
QgsMapToolAddFeature::QgsMapToolAddFeature( QgsMapCanvas* canvas, CaptureMode mode )
39+
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), mode )
40+
, mCheckGeometryType( true )
4041
{
4142
mToolName = tr( "Add feature" );
4243
}
@@ -100,7 +101,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
100101
return;
101102

102103
//check we only use this tool for point/multipoint layers
103-
if ( vlayer->geometryType() != QGis::Point )
104+
if ( vlayer->geometryType() != QGis::Point && mCheckGeometryType )
104105
{
105106
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture point' tool on this vector layer" ), QgsMessageBar::WARNING );
106107
return;
@@ -137,6 +138,11 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
137138
{
138139
g = QgsGeometry::fromMultiPoint( QgsMultiPoint() << savePoint );
139140
}
141+
else
142+
{
143+
// if layer supports more types (mCheckGeometryType is false)
144+
g = QgsGeometry::fromPoint( savePoint );
145+
}
140146

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

160166
//check we only use the polygon tool for polygon/multipolygon layers
161-
if ( mode() == CapturePolygon && vlayer->geometryType() != QGis::Polygon )
167+
if ( mode() == CapturePolygon && vlayer->geometryType() != QGis::Polygon && mCheckGeometryType )
162168
{
163169
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture polygon' tool on this vector layer" ), QgsMessageBar::WARNING );
164170
return;

‎src/app/qgsmaptooladdfeature.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ class APP_EXPORT QgsMapToolAddFeature : public QgsMapToolCapture
2121
{
2222
Q_OBJECT
2323
public:
24-
QgsMapToolAddFeature( QgsMapCanvas* canvas );
24+
/** @note mode parameter added in QGIS 2.12 */
25+
QgsMapToolAddFeature( QgsMapCanvas* canvas, CaptureMode mode = CaptureNone );
2526
virtual ~QgsMapToolAddFeature();
2627
void cadCanvasReleaseEvent( QgsMapMouseEvent * e ) override;
2728

2829
bool addFeature( QgsVectorLayer *vlayer, QgsFeature *f, bool showModal = true );
2930
void activate() override;
31+
32+
protected:
33+
/** Check if CaptureMode match layer type. Default is true.
34+
* @note Added in 2.12 */
35+
bool mCheckGeometryType;
3036
};

0 commit comments

Comments
 (0)
Please sign in to comment.