QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  mIconSize = 10;
25  mIconType = ICON_X;
26  mColor = QColor( 255, 0, 0 );
27  mPenWidth = 1;
28 }
29 
31 {
32  mIconType = type;
33 }
34 
35 void QgsVertexMarker::setIconSize( int iconSize )
36 {
37  mIconSize = iconSize;
38 }
39 
41 {
42  mCenter = point;
44  setPos( pt );
45 }
46 
47 void QgsVertexMarker::setColor( const QColor& color )
48 {
49  mColor = color;
50 }
51 
53 {
54  mPenWidth = width;
55 }
56 
58 {
59  qreal s = ( mIconSize - 1 ) / 2.0;
60 
61  QPen pen( mColor );
62  pen.setWidth( mPenWidth );
63  p->setPen( pen );
64 
65  switch ( mIconType )
66  {
67  case ICON_NONE:
68  break;
69 
70  case ICON_CROSS:
71  p->drawLine( QLineF( -s, 0, s, 0 ) );
72  p->drawLine( QLineF( 0, -s, 0, s ) );
73  break;
74 
75  case ICON_X:
76  p->drawLine( QLineF( -s, -s, s, s ) );
77  p->drawLine( QLineF( -s, s, s, -s ) );
78  break;
79 
80  case ICON_BOX:
81  p->drawLine( QLineF( -s, -s, s, -s ) );
82  p->drawLine( QLineF( s, -s, s, s ) );
83  p->drawLine( QLineF( s, s, -s, s ) );
84  p->drawLine( QLineF( -s, s, -s, -s ) );
85  break;
86 
87  case ICON_CIRCLE:
88  p->drawEllipse( QPointF( 0, 0 ), s, s );
89  break;
90  }
91 }
92 
93 
95 {
96  qreal s = qreal( mIconSize + mPenWidth ) / 2.0;
97  return QRectF( -s, -s, 2.0*s, 2.0*s );
98 }
99 
101 {
102  setCenter( mCenter );
103 }
void paint(QPainter *p) override
function to be implemented by derived classes
virtual void updatePosition() override
called on changed extent or resize event to update position of the item
QColor mColor
color of the marker
An abstract class for items that can be placed on the map canvas.
void setPenWidth(int width)
QRectF boundingRect() const override
default implementation for canvas items
void drawLine(const QLineF &line)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
QgsVertexMarker(QgsMapCanvas *mapCanvas)
virtual int type() const
QPointF toCanvasCoordinates(const QgsPoint &point) const
transformation from map coordinates to screen coordinates
int mPenWidth
pen width
void setPen(const QColor &color)
void drawEllipse(const QRectF &rectangle)
void setPos(const QPointF &pos)
void setCenter(const QgsPoint &point)
A class to represent a point.
Definition: qgspoint.h:117
void setIconSize(int iconSize)
void setWidth(int width)
int mIconType
icon to be shown
void setColor(const QColor &color)
void setIconType(int iconType)
QgsPoint mCenter
coordinates of the point in the center