QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 }
QgsVertexMarker::setIconType
void setIconType(int iconType)
Definition: qgsvertexmarker.cpp:25
QgsVertexMarker::ICON_TRIANGLE
@ ICON_TRIANGLE
Added in QGIS 3.12.
Definition: qgsvertexmarker.h:58
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsVertexMarker::ICON_CIRCLE
@ ICON_CIRCLE
Definition: qgsvertexmarker.h:56
QgsVertexMarker::QgsVertexMarker
QgsVertexMarker(QgsMapCanvas *mapCanvas)
Definition: qgsvertexmarker.cpp:21
QgsVertexMarker::ICON_NONE
@ ICON_NONE
Definition: qgsvertexmarker.h:52
QgsVertexMarker::setIconSize
void setIconSize(int iconSize)
Definition: qgsvertexmarker.cpp:30
QgsVertexMarker::ICON_CROSS
@ ICON_CROSS
Definition: qgsvertexmarker.h:53
QgsVertexMarker::ICON_DOUBLE_TRIANGLE
@ ICON_DOUBLE_TRIANGLE
Added in QGIS 3.0.
Definition: qgsvertexmarker.h:57
QgsGuiUtils::iconSize
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
Definition: qgsguiutils.cpp:264
QgsVertexMarker::color
QColor color() const
Returns the stroke color for the marker.
Definition: qgsvertexmarker.h:83
QgsVertexMarker::ICON_RHOMBUS
@ ICON_RHOMBUS
Added in QGIS 3.12.
Definition: qgsvertexmarker.h:59
QgsVertexMarker::boundingRect
QRectF boundingRect() const override
Definition: qgsvertexmarker.cpp:117
QgsMapCanvasItem
Definition: qgsmapcanvasitem.h:33
QgsVertexMarker::setFillColor
void setFillColor(const QColor &color)
Sets the fill color for the marker.
Definition: qgsvertexmarker.cpp:48
QgsMapCanvasItem::toCanvasCoordinates
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
Definition: qgsmapcanvasitem.cpp:61
QgsVertexMarker::updatePosition
void updatePosition() override
called on changed extent or resize event to update position of the item
Definition: qgsvertexmarker.cpp:123
QgsVertexMarker::ICON_BOX
@ ICON_BOX
Definition: qgsvertexmarker.h:55
qgsvertexmarker.h
QgsVertexMarker::setPenWidth
void setPenWidth(int width)
Definition: qgsvertexmarker.cpp:54
QgsVertexMarker::setCenter
void setCenter(const QgsPointXY &point)
Definition: qgsvertexmarker.cpp:35
QgsVertexMarker::setColor
void setColor(const QColor &color)
Sets the stroke color for the marker.
Definition: qgsvertexmarker.cpp:42
QgsPointXY
Definition: qgspointxy.h:43
QgsVertexMarker::paint
void paint(QPainter *p) override
function to be implemented by derived classes
Definition: qgsvertexmarker.cpp:59
QgsVertexMarker::ICON_X
@ ICON_X
Definition: qgsvertexmarker.h:54