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 }; 61 62 QgsVertexMarker( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS ); 63 64 /** 65 * Sets the center \a point of the marker, in map coordinates. 66 * 67 * \see center() 68 */ 69 void setCenter( const QgsPointXY &point ); 70 71 /** 72 * Returns the center point of the marker, in map coordinates. 73 * 74 * \see setCenter() 75 * \since QGIS 3.18 76 */ center()77 QgsPointXY center() const { return mCenter; } 78 79 void setIconType( int iconType ); 80 81 void setIconSize( int iconSize ); 82 83 /** 84 * Sets the stroke \a color for the marker. 85 * \see color() 86 * \see setFillColor() 87 */ 88 void setColor( const QColor &color ); 89 90 /** 91 * Returns the stroke color for the marker. 92 * \see setColor() 93 * \see fillColor() 94 * \since QGIS 3.0 95 */ color()96 QColor color() const { return mColor; } 97 98 /** 99 * Sets the fill \a color for the marker. This setting only 100 * applies to some icon types. 101 * \see fillColor() 102 * \see setColor() 103 * \since QGIS 3.0 104 */ 105 void setFillColor( const QColor &color ); 106 107 /** 108 * Returns the fill \a color for the marker. This setting only 109 * applies to some icon types. 110 * \see setFillColor() 111 * \see color() 112 * \since QGIS 3.0 113 */ fillColor()114 QColor fillColor() const { return mFillColor; } 115 116 void setPenWidth( int width ); 117 118 void paint( QPainter *p ) override; 119 120 QRectF boundingRect() const override; 121 122 void updatePosition() override; 123 124 private: 125 126 //! icon to be shown 127 int mIconType = ICON_X; 128 129 //! size 130 int mIconSize = 10; 131 132 //! coordinates of the point in the center 133 QgsPointXY mCenter; 134 135 //! color of the marker 136 QColor mColor = QColor( 255, 0, 0 ); 137 138 //! pen width 139 int mPenWidth = 1; 140 141 //! Fill color 142 QColor mFillColor = QColor( 0, 0, 0, 0 ); 143 144 }; 145 146 #endif 147