Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsnumericscalebarstyle.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnumericscalebarstyle.cpp
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 "qgscomposermap.h"
19 #include "qgscomposerscalebar.h"
20 #include <QList>
21 #include <QPainter>
22 
24 {
25 
26 }
27 
29 {
30 
31 }
32 
34 {
35 
36 }
37 
39 {
40  return "Numeric";
41 }
42 
43 void QgsNumericScaleBarStyle::draw( QPainter* p, double xOffset ) const
44 {
45  if ( !p || !mScaleBar )
46  {
47  return;
48  }
49 
50  p->save();
51  p->setFont( mScaleBar->font() );
52  p->setPen( QColor( 0, 0, 0 ) );
54 
55  p->restore();
56 }
57 
59 {
60  QRectF rect;
61  if ( !mScaleBar )
62  {
63  return rect;
64  }
65 
66  double textWidth = mScaleBar->textWidthMillimeters( mScaleBar->font(), scaleText() );
67  double textHeight = mScaleBar->fontAscentMillimeters( mScaleBar->font() );
68 
69  return QRectF( mScaleBar->transform().dx(), mScaleBar->transform().dy(), 2 * mScaleBar->boxContentSpace()
70  + 2 * mScaleBar->pen().width() + textWidth,
71  textHeight + 2 * mScaleBar->boxContentSpace() );
72 }
73 
75 {
76  QString scaleBarText;
77  if ( mScaleBar )
78  {
79  //find out scale
80  const QgsComposerMap* composerMap = mScaleBar->composerMap();
81  if ( composerMap )
82  {
83  double scaleDenominator = composerMap->scale();
84  scaleBarText = "1:" + QString::number( scaleDenominator, 'f', 0 );
85  }
86  }
87  return scaleBarText;
88 }