1 /***************************************************************************
2     qgsmaptooldeletering.h  - delete a ring from polygon
3     ---------------------
4     begin                : April 2009
5     copyright            : (C) 2009 by Richard Kostecky
6     email                : csf dot kostej at mail dot com
7  ***************************************************************************
8  *                                                                         *
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.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPTOOLDELETERING_H
17 #define QGSMAPTOOLDELETERING_H
18 
19 #include "qgsmaptooledit.h"
20 #include "qgis_app.h"
21 #include "qgsgeometry.h"
22 #include "qgsfeatureid.h"
23 
24 
25 class QgsVertexMarker;
26 //! Map tool to delete vertices from line/polygon features
27 
28 class APP_EXPORT QgsMapToolDeleteRing : public QgsMapToolEdit
29 {
30     Q_OBJECT
31 
32   public:
33     QgsMapToolDeleteRing( QgsMapCanvas *canvas );
34     ~QgsMapToolDeleteRing() override;
35 
36     void canvasMoveEvent( QgsMapMouseEvent *e ) override;
37 
38     void canvasPressEvent( QgsMapMouseEvent *e ) override;
39 
40     void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
41 
42     //! called when map tool is being deactivated
43     void deactivate() override;
44 
45   private:
46     QgsVectorLayer *vlayer = nullptr;
47 
48     //! delete inner ring from the geometry
49     void deleteRing( QgsFeatureId fId, int beforeVertexNr, QgsVectorLayer *vlayer );
50 
51     //! Returns the ring number in polygon
52     int ringNumInPolygon( const QgsGeometry &g, int vertexNr );
53 
54     //! Returns the ring number in multipolygon and set parNum to index of the part
55     int ringNumInMultiPolygon( const QgsGeometry &g, int vertexNr, int &partNum );
56 
57     /**
58      * Returns the geometry of the ring under the point p and sets fid to the feature id,
59      * partNum to the part number in the feature and ringNum to the ring number in the part
60      */
61     QgsGeometry ringUnderPoint( const QgsPointXY &p, QgsFeatureId &fid, int &partNum, int &ringNum );
62 
63     /* Rubberband that shows the ring being deleted*/
64     QgsRubberBand *mRubberBand = nullptr;
65 
66     //The feature, part and ring the mouse was pressed in, to  check we are still in the same ring at release
67     QgsFeatureId mPressedFid;
68     int mPressedPartNum;
69     int mPressedRingNum;
70 };
71 
72 #endif
73