Quantum GIS API Documentation
1.7.5-Wroclaw
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
core
composer
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
17
#include "
qgsnumericscalebarstyle.h
"
18
#include "
qgscomposermap.h
"
19
#include "
qgscomposerscalebar.h
"
20
#include <QList>
21
#include <QPainter>
22
23
QgsNumericScaleBarStyle::QgsNumericScaleBarStyle
(
QgsComposerScaleBar
* bar ):
QgsScaleBarStyle
( bar )
24
{
25
26
}
27
28
QgsNumericScaleBarStyle::QgsNumericScaleBarStyle
():
QgsScaleBarStyle
( 0 )
29
{
30
31
}
32
33
QgsNumericScaleBarStyle::~QgsNumericScaleBarStyle
()
34
{
35
36
}
37
38
QString
QgsNumericScaleBarStyle::name
()
const
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 ) );
53
mScaleBar
->
drawText
( p,
mScaleBar
->
pen
().widthF() +
mScaleBar
->
boxContentSpace
(),
mScaleBar
->
boxContentSpace
() +
mScaleBar
->
fontAscentMillimeters
(
mScaleBar
->
font
() ),
scaleText
(),
mScaleBar
->
font
() );
54
55
p->restore();
56
}
57
58
QRectF
QgsNumericScaleBarStyle::calculateBoxSize
()
const
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
74
QString
QgsNumericScaleBarStyle::scaleText
()
const
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
}
Generated on Thu Sep 19 2013 17:30:54 for Quantum GIS API Documentation by
1.8.4