1 /***************************************************************************
2     qgsmaptooledit.h  -  base class for editing map tools
3     ---------------------
4     begin                : Juli 2007
5     copyright            : (C) 2007 by Marco Hugentobler
6     email                : marco dot hugentobler at karto dot baug dot ethz dot ch
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 QGSMAPTOOLEDIT_H
17 #define QGSMAPTOOLEDIT_H
18 
19 #include "qgswkbtypes.h"
20 #include "qgsmaptool.h"
21 #include "qgis_gui.h"
22 
23 class QgsRubberBand;
24 class QgsGeometryRubberBand;
25 class QgsVectorLayer;
26 class QKeyEvent;
27 
28 /**
29  * \ingroup gui
30  * \brief Base class for map tools that edit vector geometry
31 */
32 class GUI_EXPORT QgsMapToolEdit: public QgsMapTool
33 {
34     Q_OBJECT
35 
36   public:
37     QgsMapToolEdit( QgsMapCanvas *canvas );
38 
flags()39     Flags flags() const override { return QgsMapTool::EditTool; }
40 
41     /**
42      * Returns default Z value
43      * Use for set Z coordinate to new vertex for 2.5d geometries
44      */
45     double defaultZValue() const;
46 
47   private slots:
48     //! Vector layers' editingStopped SIGNAL will eventually trigger a clean
49     void connectLayers( const QList<QgsMapLayer *> &layers );
50 
51     /**
52      * Makes sure rubber bands are removed if there
53      * is no editable layer left in the project
54      */
55     void cleanCanvas();
56 
57   protected:
58 
59     //! Returns stroke color for rubber bands (from global settings)
60     static QColor digitizingStrokeColor();
61     //! Returns stroke width for rubber bands (from global settings)
62     static int digitizingStrokeWidth();
63     //! Returns fill color for rubber bands (from global settings)
64     static QColor digitizingFillColor();
65 
66     /**
67      * Creates a rubber band with the color/line width from
68      *   the QGIS settings. The caller takes ownership of the
69      *   returned object
70      *   \param geometryType
71      *   \param alternativeBand if TRUE, rubber band will be set with more transparency and a dash pattern. default is FALSE.
72      */
73     QgsRubberBand *createRubberBand( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry, bool alternativeBand = false ) SIP_FACTORY;
74 
75     QgsGeometryRubberBand *createGeometryRubberBand( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry, bool alternativeBand = false ) const SIP_FACTORY;
76 
77     //! Returns the current vector layer of the map canvas or 0
78     QgsVectorLayer *currentVectorLayer();
79 
80     //! Result of addTopologicalPoints
81     enum TopologicalResult
82     {
83       Success = 0, //!< AddTopologicalPoints was successful
84       InvalidCanvas = 1, //!< AddTopologicalPoints failed due to an invalid canvas
85       InvalidLayer = 2, //!< AddTopologicalPoints failed due to an invalid canvas
86     };
87 
88     /**
89      * Adds a list of \a vertices to other features to keep topology up to date, e.g. to neighbouring polygons.
90      * The \a vertices list specifies a set of topological points to add, in the layer's coordinate reference system.
91      * \deprecated since QGIS 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.
92      */
93     Q_DECL_DEPRECATED TopologicalResult addTopologicalPoints( const QVector<QgsPointXY> &vertices )  SIP_DEPRECATED;
94 
95     /**
96      * Adds a list of \a vertices to other features to keep topology up to date, e.g. to neighbouring polygons.
97      * The \a vertices list specifies a set of topological points to add, in the layer's coordinate reference system.
98      * \since QGIS 3.10
99      */
100     TopologicalResult addTopologicalPoints( const QVector<QgsPoint> &vertices );
101 
102     //! Display a timed message bar noting the active layer is not vector.
103     void notifyNotVectorLayer();
104     //! Display a timed message bar noting the active vector layer is not editable.
105     void notifyNotEditableLayer();
106 
107   private:
108     //! Returns a list of layers filtered to just editable spatial vector layers
109     QList<QgsVectorLayer *> editableVectorLayers();
110 };
111 
112 #endif
113