QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgssingleboxscalebarstyle.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssingleboxscalebarstyle.h
3  ------------------
4  begin : June 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : marco.hugentobler@karto.baug.ethz.ch
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 
18 #include "qgscomposerscalebar.h"
19 #include "qgscomposerutils.h"
20 #include <QList>
21 #include <QPainter>
22 
24 {
25 
26 }
27 
29 {
30 
31 }
32 
34 {
35  //nothing to do...
36 }
37 
38 void QgsSingleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
39 {
40  if ( !mScaleBar )
41  {
42  return;
43  }
45 
46  p->save();
47  //antialiasing on
48  p->setRenderHint( QPainter::Antialiasing, true );
49  p->setPen( mScaleBar->pen() );
50 
51 
52  QList<QPair<double, double> > segmentInfo;
53  mScaleBar->segmentPositions( segmentInfo );
54 
55  bool useColor = true; //alternate brush color/white
56 
57  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
58  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
59  {
60  if ( useColor ) //alternating colors
61  {
62  p->setBrush( mScaleBar->brush() );
63  }
64  else //secondary color
65  {
66  p->setBrush( mScaleBar->brush2() );
67  }
68 
69  QRectF segmentRect( segmentIt->first + xOffset, barTopPosition, segmentIt->second, mScaleBar->height() );
70  p->drawRect( segmentRect );
71  useColor = !useColor;
72  }
73 
74  p->restore();
75 
76  //draw labels using the default method
77  drawLabels( p );
78 }
79 
81 {
82  return "Single Box";
83 }
84 
A scale bar item that can be added to a map composition.
virtual void drawLabels(QPainter *p) const
double boxContentSpace() const
void draw(QPainter *p, double xOffset=0) const
void segmentPositions(QList< QPair< double, double > > &posWidthList) const
Returns the x - positions of the segment borders (in item coordinates) and the width of the segment...
static double fontAscentMM(const QFont &font)
Calculate font ascent in millimeters, including workarounds for QT font rendering issues...
double labelBarSpace() const
Abstraction of composer scale bar style.
QPen pen() const
Returns the pen used for drawing the scalebar.
const QgsComposerScaleBar * mScaleBar
QBrush brush() const
Returns the primary brush for the scalebar.
QBrush brush2() const
Returns the secondary brush for the scalebar.