QGIS API Documentation
2.8.2-Wien
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
src
core
diagram
qgsdiagram.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsdiagram.cpp
3
---------------------
4
begin : March 2011
5
copyright : (C) 2011 by Marco Hugentobler
6
email : marco dot hugentobler at sourcepole dot ch
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
#include "
qgsdiagram.h
"
16
#include "
qgsdiagramrendererv2.h
"
17
#include "
qgsrendercontext.h
"
18
#include "
qgsexpression.h
"
19
20
#include <QPainter>
21
22
23
24
QgsDiagram::QgsDiagram
()
25
{
26
27
}
28
29
QgsDiagram::QgsDiagram
(
const
QgsDiagram
& other )
30
{
31
Q_UNUSED( other );
32
// do not copy the cached expression map - the expressions need to be created and prepared with getExpression(...) call
33
}
34
35
36
void
QgsDiagram::clearCache
()
37
{
38
QMapIterator<QString, QgsExpression*> i( mExpressions );
39
while
( i.hasNext() )
40
{
41
i.next();
42
delete
i.value();
43
}
44
mExpressions.clear();
45
}
46
47
QgsExpression
*
QgsDiagram::getExpression
(
const
QString& expression,
const
QgsFields
* fields )
48
{
49
if
( !mExpressions.contains( expression ) )
50
{
51
QgsExpression
* expr =
new
QgsExpression
( expression );
52
expr->
prepare
( *fields );
53
mExpressions[expression] = expr;
54
}
55
return
mExpressions[expression];
56
}
57
58
void
QgsDiagram::setPenWidth
( QPen& pen,
const
QgsDiagramSettings
& s,
const
QgsRenderContext
& c )
59
{
60
if
( s.
sizeType
==
QgsDiagramSettings::MM
)
61
{
62
pen.setWidthF( s.
penWidth
* c.
scaleFactor
() );
63
}
64
else
65
{
66
pen.setWidthF( s.
penWidth
/ c.
mapToPixel
().
mapUnitsPerPixel
() );
67
}
68
}
69
70
71
QSizeF
QgsDiagram::sizePainterUnits
(
const
QSizeF&
size
,
const
QgsDiagramSettings
& s,
const
QgsRenderContext
& c )
72
{
73
if
( s.
sizeType
==
QgsDiagramSettings::MM
)
74
{
75
return
QSizeF( size.width() * c.
scaleFactor
(), size.height() * c.
scaleFactor
() );
76
}
77
else
78
{
79
return
QSizeF( size.width() / c.
mapToPixel
().
mapUnitsPerPixel
(), size.height() / c.
mapToPixel
().
mapUnitsPerPixel
() );
80
}
81
}
82
83
float
QgsDiagram::sizePainterUnits
(
float
l,
const
QgsDiagramSettings
& s,
const
QgsRenderContext
& c )
84
{
85
if
( s.
sizeType
==
QgsDiagramSettings::MM
)
86
{
87
return
l * c.
scaleFactor
();
88
}
89
else
90
{
91
return
l / c.
mapToPixel
().
mapUnitsPerPixel
();
92
}
93
}
94
95
QFont
QgsDiagram::scaledFont
(
const
QgsDiagramSettings
& s,
const
QgsRenderContext
& c )
96
{
97
QFont f = s.
font
;
98
if
( s.
sizeType
==
QgsDiagramSettings::MM
)
99
{
100
f.setPixelSize( s.
font
.pointSizeF() * 0.376 * c.
scaleFactor
() );
101
}
102
else
103
{
104
f.setPixelSize( s.
font
.pointSizeF() / c.
mapToPixel
().
mapUnitsPerPixel
() );
105
}
106
107
return
f;
108
}
109
110
void
QgsDiagram::renderDiagram
(
const
QgsAttributes
& attributes,
QgsRenderContext
& c,
const
QgsDiagramSettings
& s,
const
QPointF& position )
111
{
112
QgsFeature
feature;
113
feature.
setAttributes
( attributes );
114
renderDiagram
( feature, c, s, position );
115
}
116
117
QSizeF
QgsDiagram::diagramSize
(
const
QgsAttributes
& attributes,
const
QgsRenderContext
& c,
const
QgsDiagramSettings
& s,
const
QgsDiagramInterpolationSettings
& is )
118
{
119
QgsFeature
feature;
120
feature.
setAttributes
( attributes );
121
return
diagramSize
( feature, c, s, is );
122
}
Generated on Sun May 10 2015 16:33:23 for QGIS API Documentation by
1.8.1.2