QGIS API Documentation  2.8.2-Wien
 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 : [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 
18 #include "qgscomposerscalebar.h"
19 #include "qgscomposerutils.h"
20 #include <QList>
21 #include <QPainter>
22 
24 {
25 
26 }
27 
28 QgsSingleBoxScaleBarStyle::QgsSingleBoxScaleBarStyle(): QgsScaleBarStyle( 0 )
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  QList<QPair<double, double> > segmentInfo;
52  mScaleBar->segmentPositions( segmentInfo );
53 
54  bool useColor = true; //alternate brush color/white
55 
56  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
57  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
58  {
59  if ( useColor ) //alternating colors
60  {
61  p->setBrush( mScaleBar->brush() );
62  }
63  else //secondary color
64  {
65  p->setBrush( mScaleBar->brush2() );
66  }
67 
68  QRectF segmentRect( segmentIt->first + xOffset, barTopPosition, segmentIt->second, mScaleBar->height() );
69  p->drawRect( segmentRect );
70  useColor = !useColor;
71  }
72 
73  p->restore();
74 
75  //draw labels using the default method
76  drawLabels( p );
77 }
78 
80 {
81  return "Single Box";
82 }
83