1
/***************************************************************************
2
qgsmaptooladdring.cpp - map tool to cut rings in polygon and multipolygon features
5
copyright : (C) 2007 by Marco Hugentobler
6
email : marco dot hugentobler at karto dot baug dot ethz dot ch
7
***************************************************************************
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
14
***************************************************************************/
17
#include "qgsmaptooladdring.h"
18
#include "qgsgeometry.h"
19
#include "qgsmapcanvas.h"
20
#include "qgsproject.h"
21
#include "qgsrubberband.h"
22
#include "qgsvectorlayer.h"
23
#include <QMessageBox>
24
#include <QMouseEvent>
26
QgsMapToolAddRing::QgsMapToolAddRing( QgsMapCanvas* canvas ): QgsMapToolCapture( canvas, QgsMapToolCapture::CapturePolygon )
31
QgsMapToolAddRing::~QgsMapToolAddRing()
36
void QgsMapToolAddRing::canvasReleaseEvent( QMouseEvent * e )
38
//check if we operate on a vector layer
39
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
43
QMessageBox::information( 0, tr( "Not a vector layer" ),
44
tr( "The current layer is not a vector layer" ) );
48
if ( !vlayer->isEditable() )
50
QMessageBox::information( 0, tr( "Layer not editable" ),
51
tr( "Cannot edit the vector layer. To make it editable, go to the file item "
52
"of the layer, right click and check 'Allow Editing'." ) );
56
//add point to list and to rubber band
57
int error = addVertex( e->pos() );
60
//current layer is not a vector layer
63
else if ( error == 2 )
65
//problem with coordinate transformation
66
QMessageBox::information( 0, tr( "Coordinate transform error" ),
67
tr( "Cannot transform the point to the layers coordinate system" ) );
71
if ( e->button() == Qt::LeftButton )
75
else if ( e->button() == Qt::RightButton )
82
mCaptureList.push_back( *mCaptureList.begin() );
84
vlayer->beginEditCommand( tr( "Ring added" ) );
85
int addRingReturnCode = vlayer->addRing( mCaptureList );
86
if ( addRingReturnCode != 0 )
89
//todo: open message box to communicate errors
90
if ( addRingReturnCode == 1 )
92
errorMessage = tr( "A problem with geometry type occured" );
94
else if ( addRingReturnCode == 2 )
96
errorMessage = tr( "The inserted Ring is not closed" );
98
else if ( addRingReturnCode == 3 )
100
errorMessage = tr( "The inserted Ring is not a valid geometry" );
102
else if ( addRingReturnCode == 4 )
104
errorMessage = tr( "The inserted Ring crosses existing rings" );
106
else if ( addRingReturnCode == 5 )
108
errorMessage = tr( "The inserted Ring is not contained in a feature" );
112
errorMessage = tr( "An unknown error occured" );
114
QMessageBox::critical( 0, tr( "Error, could not add ring" ), errorMessage );
115
vlayer->destroyEditCommand();
119
vlayer->endEditCommand();
121
mCaptureList.clear();