QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
43  QPointF pt = toCanvasCoordinates( mCenter );
44  setPos( pt );
45 }
46 
47 void QgsVertexMarker::setColor( const QColor& color )
48 {
49  mColor = color;
50 }
51 
53 {
54  mPenWidth = width;
55 }
56 
57 void QgsVertexMarker::paint( QPainter* p )
58 {
59  qreal s = ( mIconSize - 1 ) / 2;
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 }
88 
89 
91 {
92  qreal s = qreal( mIconSize + mPenWidth ) / 2.0;
93  return QRectF( -s, -s, 2.0*s, 2.0*s );
94 }
95 
97 {
98  setCenter( mCenter );
99 }