1 /***************************************************************************
2     qgsvertexmarker.h  - canvas item which shows a simple vertex marker
3     ---------------------
4     begin                : February 2006
5     copyright            : (C) 2006 by Martin Dobias
6     email                : wonder.sk at gmail 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 QGSVERTEXMARKER_H
17 #define QGSVERTEXMARKER_H
18 
19 #include "qgsmapcanvasitem.h"
20 #include "qgspointxy.h"
21 #include "qgis_gui.h"
22 
23 class QPainter;
24 
25 #ifdef SIP_RUN
26 % ModuleHeaderCode
27 // For ConvertToSubClassCode.
28 #include <qgsvertexmarker.h>
29 % End
30 #endif
31 
32 /**
33  * \ingroup gui
34  * \brief A class for marking vertices of features using e.g. circles or 'x'.
35  */
36 class GUI_EXPORT QgsVertexMarker : public QgsMapCanvasItem
37 {
38 
39 #ifdef SIP_RUN
40     SIP_CONVERT_TO_SUBCLASS_CODE
41     if ( dynamic_cast<QgsVertexMarker *>( sipCpp ) )
42       sipType = sipType_QgsVertexMarker;
43     else
44       sipType = nullptr;
45     SIP_END
46 #endif
47   public:
48 
49     //! Icons
50     enum IconType
51     {
52       ICON_NONE,
53       ICON_CROSS,
54       ICON_X,
55       ICON_BOX,
56       ICON_CIRCLE,
57       ICON_DOUBLE_TRIANGLE,    //!< Added in QGIS 3.0
58       ICON_TRIANGLE,  //!< Added in QGIS 3.12
59       ICON_RHOMBUS,  //!< Added in QGIS 3.12
60       ICON_INVERTED_TRIANGLE, //!< Added in QGIS 3.20
61     };
62 
63     QgsVertexMarker( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS );
64 
65     /**
66      * Sets the center \a point of the marker, in map coordinates.
67      *
68      * \see center()
69      */
70     void setCenter( const QgsPointXY &point );
71 
72     /**
73      * Returns the center point of the marker, in map coordinates.
74      *
75      * \see setCenter()
76      * \since QGIS 3.18
77      */
center()78     QgsPointXY center() const { return mCenter; }
79 
80     void setIconType( int iconType );
81 
82     void setIconSize( int iconSize );
83 
84     /**
85      * Sets the stroke \a color for the marker.
86      * \see color()
87      * \see setFillColor()
88      */
89     void setColor( const QColor &color );
90 
91     /**
92      * Returns the stroke color for the marker.
93      * \see setColor()
94      * \see fillColor()
95      * \since QGIS 3.0
96      */
color()97     QColor color() const { return mColor; }
98 
99     /**
100      * Sets the fill \a color for the marker. This setting only
101      * applies to some icon types.
102      * \see fillColor()
103      * \see setColor()
104      * \since QGIS 3.0
105      */
106     void setFillColor( const QColor &color );
107 
108     /**
109      * Returns the fill \a color for the marker. This setting only
110      * applies to some icon types.
111      * \see setFillColor()
112      * \see color()
113      * \since QGIS 3.0
114      */
fillColor()115     QColor fillColor() const { return mFillColor; }
116 
117     void setPenWidth( int width );
118 
119     void paint( QPainter *p ) override;
120 
121     QRectF boundingRect() const override;
122 
123     void updatePosition() override;
124 
125   private:
126 
127     void updatePath();
128 
129     //! icon to be shown
130     int mIconType = ICON_X;
131 
132     QPainterPath mPath;
133 
134     //! size
135     int mIconSize = 10;
136 
137     //! coordinates of the point in the center
138     QgsPointXY mCenter;
139 
140     //! color of the marker
141     QColor mColor = QColor( 255, 0, 0 );
142 
143     //! pen width
144     int mPenWidth = 1;
145 
146     //! Fill color
147     QColor mFillColor = QColor( 0, 0, 0, 0 );
148 
149 };
150 
151 #endif
152