QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsticksscalebarstyle.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsticksscalebarstyle.cpp
3  -------------------------
4  begin : June 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgsticksscalebarstyle.h"
18 #include "qgscomposerscalebar.h"
19 #include <QPainter>
20 
22 {
24 }
25 
27 {
29 }
30 
32 {
33 
34 }
35 
37 {
38  switch ( mTickPosition )
39  {
40  case TicksUp:
41  return "Line Ticks Up";
42  case TicksDown:
43  return "Line Ticks Down";
44  case TicksMiddle:
45  return "Line Ticks Middle";
46  }
47  return ""; // to make gcc happy
48 }
49 
50 void QgsTicksScaleBarStyle::draw( QPainter* p, double xOffset ) const
51 {
52  if ( !mScaleBar )
53  {
54  return;
55  }
57  double middlePosition = barTopPosition + mScaleBar->height() / 2.0;
58  double bottomPosition = barTopPosition + mScaleBar->height();
59 
60  p->save();
61  p->setPen( mScaleBar->pen() );
62 
63  QList<QPair<double, double> > segmentInfo;
64  mScaleBar->segmentPositions( segmentInfo );
65 
66  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
67  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
68  {
69  p->drawLine( segmentIt->first + xOffset, barTopPosition, segmentIt->first + xOffset, barTopPosition + mScaleBar->height() );
70  switch ( mTickPosition )
71  {
72  case TicksDown:
73  p->drawLine( xOffset + segmentIt->first, barTopPosition, xOffset + segmentIt->first + mScaleBar->segmentMillimeters(), barTopPosition );
74  break;
75  case TicksMiddle:
76  p->drawLine( xOffset + segmentIt->first, middlePosition, xOffset + segmentIt->first + mScaleBar->segmentMillimeters(), middlePosition );
77  break;
78  case TicksUp:
79  p->drawLine( xOffset + segmentIt->first, bottomPosition, xOffset + segmentIt->first + mScaleBar->segmentMillimeters(), bottomPosition );
80  break;
81  }
82  }
83 
84  //draw last tick
85  if ( !segmentInfo.isEmpty() )
86  {
87  double lastTickPositionX = segmentInfo.last().first + mScaleBar->segmentMillimeters();
88  p->drawLine( lastTickPositionX + xOffset, barTopPosition, lastTickPositionX + xOffset, barTopPosition + mScaleBar->height() );
89  }
90 
91  p->restore();
92 
93  //draw labels using the default method
94  drawLabels( p );
95 }
96 
97