QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 <QPainter>
17 
18 #include "qgsvertexmarker.h"
19 
20 
22  : QgsMapCanvasItem( mapCanvas )
23 {}
24 
26 {
27  mIconType = type;
28 }
29 
31 {
32  mIconSize = iconSize;
33 }
34 
36 {
37  mCenter = point;
38  QPointF pt = toCanvasCoordinates( mCenter );
39  setPos( pt );
40 }
41 
42 void QgsVertexMarker::setColor( const QColor &color )
43 {
44  mColor = color;
45  update();
46 }
47 
48 void QgsVertexMarker::setFillColor( const QColor &color )
49 {
50  mFillColor = color;
51  update();
52 }
53 
55 {
56  mPenWidth = width;
57 }
58 
59 void QgsVertexMarker::paint( QPainter *p )
60 {
61  qreal s = ( mIconSize - 1 ) / 2.0;
62 
63  QPen pen( mColor );
64  pen.setWidth( mPenWidth );
65  p->setPen( pen );
66  QBrush brush( mFillColor );
67  p->setBrush( brush );
68 
69  switch ( mIconType )
70  {
71  case ICON_NONE:
72  break;
73 
74  case ICON_CROSS:
75  p->drawLine( QLineF( -s, 0, s, 0 ) );
76  p->drawLine( QLineF( 0, -s, 0, s ) );
77  break;
78 
79  case ICON_X:
80  p->drawLine( QLineF( -s, -s, s, s ) );
81  p->drawLine( QLineF( -s, s, s, -s ) );
82  break;
83 
84  case ICON_BOX:
85  p->drawLine( QLineF( -s, -s, s, -s ) );
86  p->drawLine( QLineF( s, -s, s, s ) );
87  p->drawLine( QLineF( s, s, -s, s ) );
88  p->drawLine( QLineF( -s, s, -s, -s ) );
89  break;
90 
91  case ICON_CIRCLE:
92  p->drawEllipse( QPointF( 0, 0 ), s, s );
93  break;
94 
96  p->drawLine( QLineF( -s, -s, s, -s ) );
97  p->drawLine( QLineF( -s, s, s, s ) );
98  p->drawLine( QLineF( -s, -s, s, s ) );
99  p->drawLine( QLineF( s, -s, -s, s ) );
100  break;
101 
102  case ICON_TRIANGLE:
103  p->drawLine( QLineF( -s, s, s, s ) );
104  p->drawLine( QLineF( s, s, 0, -s ) );
105  p->drawLine( QLineF( 0, -s, -s, s ) );
106  break;
107  case ICON_RHOMBUS:
108  p->drawLine( QLineF( 0, -s, -s, 0 ) );
109  p->drawLine( QLineF( -s, 0, 0, s ) );
110  p->drawLine( QLineF( 0, s, s, 0 ) );
111  p->drawLine( QLineF( s, 0, 0, -s ) );
112  break;
113  }
114 }
115 
116 
118 {
119  qreal s = qreal( mIconSize + mPenWidth ) / 2.0;
120  return QRectF( -s, -s, 2.0 * s, 2.0 * s );
121 }
122 
124 {
125  setCenter( mCenter );
126 }
An abstract class for items that can be placed on the map canvas.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
A class to represent a 2D point.
Definition: qgspointxy.h:44
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_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)
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.