QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsvertexmarker.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvertexmarker.cpp - 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#include "qgsvertexmarker.h"
17
18#include <QPainter>
19
21 : QgsMapCanvasItem( mapCanvas )
22{
23 updatePath();
24}
25
27{
28 mIconType = type;
29 updatePath();
30}
31
32void QgsVertexMarker::setIconSize( int iconSize )
33{
34 mIconSize = iconSize;
35 updatePath();
36}
37
39{
40 mCenter = point;
41 const QPointF pt = toCanvasCoordinates( mCenter );
42 setPos( pt );
43}
44
45void QgsVertexMarker::setColor( const QColor &color )
46{
47 mColor = color;
48 update();
49}
50
52{
53 mFillColor = color;
54 update();
55}
56
58{
59 mPenWidth = width;
60}
61
62void QgsVertexMarker::paint( QPainter *p )
63{
64 QPen pen( mColor );
65 pen.setWidth( mPenWidth );
66 p->setPen( pen );
67 const QBrush brush( mFillColor );
68 p->setBrush( brush );
69 p->drawPath( mPath );
70}
71
72void QgsVertexMarker::updatePath()
73{
74 mPath = QPainterPath();
75
76 const qreal s = ( mIconSize - 1 ) / 2.0;
77
78 switch ( mIconType )
79 {
80 case ICON_NONE:
81 break;
82
83 case ICON_CROSS:
84 mPath.moveTo( QPointF( -s, 0 ) );
85 mPath.lineTo( QPointF( s, 0 ) );
86 mPath.moveTo( QPointF( 0, -s ) );
87 mPath.lineTo( QPointF( 0, s ) );
88 break;
89
90 case ICON_X:
91 mPath.moveTo( QPointF( -s, -s ) );
92 mPath.lineTo( QPointF( s, s ) );
93 mPath.moveTo( QPointF( -s, s ) );
94 mPath.lineTo( QPointF( s, -s ) );
95 break;
96
97 case ICON_BOX:
98 mPath.addRect( QRectF( -s, -s, s * 2, s * 2 ) );
99 break;
100
101 case ICON_CIRCLE:
102 mPath.addEllipse( QPointF( 0, 0 ), s, s );
103 break;
104
106 mPath.moveTo( QPointF( -s, -s ) );
107 mPath.lineTo( QPointF( s, -s ) );
108 mPath.lineTo( QPointF( -s, s ) );
109 mPath.lineTo( QPointF( s, s ) );
110 mPath.lineTo( QPointF( -s, -s ) );
111 break;
112
113 case ICON_TRIANGLE:
114 mPath.moveTo( QPointF( -s, s ) );
115 mPath.lineTo( QPointF( s, s ) );
116 mPath.lineTo( QPointF( 0, -s ) );
117 mPath.lineTo( QPointF( -s, s ) );
118 break;
119
120 case ICON_RHOMBUS:
121 mPath.moveTo( QPointF( 0, -s ) );
122 mPath.lineTo( QPointF( -s, 0 ) );
123 mPath.lineTo( QPointF( 0, s ) );
124 mPath.lineTo( QPointF( s, 0 ) );
125 mPath.lineTo( QPointF( 0, -s ) );
126 break;
127
129 mPath.moveTo( QPointF( -s, -s ) );
130 mPath.lineTo( QPointF( s, -s ) );
131 mPath.lineTo( QPointF( 0, s ) );
132 mPath.lineTo( QPointF( -s, -s ) );
133 break;
134 }
135}
136
138{
139 const qreal s = qreal( mIconSize + mPenWidth ) / 2.0;
140 return QRectF( -s, -s, 2.0 * s, 2.0 * s );
141}
142
144{
145 setCenter( mCenter );
146}
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
QgsMapCanvasItem(QgsMapCanvas *mapCanvas)
protected constructor: cannot be constructed directly
Map canvas is a class for displaying all GIS data types on a canvas.
Represents a 2D point.
Definition qgspointxy.h:60
QColor color() const
Returns the stroke color for the marker.
void setFillColor(const QColor &color)
Sets the fill color for the marker.
void setPenWidth(int width)
@ ICON_TRIANGLE
Added in QGIS 3.12.
@ ICON_DOUBLE_TRIANGLE
Added in QGIS 3.0.
@ ICON_INVERTED_TRIANGLE
Added in QGIS 3.20.
@ ICON_RHOMBUS
Added in QGIS 3.12.
void setIconSize(int iconSize)
void setCenter(const QgsPointXY &point)
Sets the center point of the marker, in map coordinates.
QRectF boundingRect() const override
void setIconType(int iconType)
void setColor(const QColor &color)
Sets the stroke color for the marker.
void updatePosition() override
called on changed extent or resize event to update position of the item
void paint(QPainter *p) override
function to be implemented by derived classes
QgsVertexMarker(QgsMapCanvas *mapCanvas)