QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
layout
qgslayoutreportcontext.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslayoutreportcontext.cpp
3
--------------------
4
begin : July 2017
5
copyright : (C) 2017 by Nyall Dawson
6
email : nyall dot dawson at gmail dot com
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 "
qgslayoutreportcontext.h
"
18
19
#include "
qgsfeature.h
"
20
#include "
qgslayout.h
"
21
#include "
qgsvectorlayer.h
"
22
23
#include "moc_qgslayoutreportcontext.cpp"
24
25
QgsLayoutReportContext::QgsLayoutReportContext
(
QgsLayout
*layout )
26
: QObject( layout )
27
, mLayout( layout )
28
{}
29
30
void
QgsLayoutReportContext::setFeature
(
const
QgsFeature
&
feature
)
31
{
32
mFeature =
feature
;
33
mGeometryCache.clear();
34
emit
changed
();
35
}
36
37
QgsGeometry
QgsLayoutReportContext::currentGeometry
(
const
QgsCoordinateReferenceSystem
&crs )
const
38
{
39
if
( !crs.
isValid
() )
40
{
41
// no projection, return the native geometry
42
return
mFeature.geometry();
43
}
44
45
if
( !mLayer || !mFeature.isValid() || !mFeature.hasGeometry() )
46
{
47
return
QgsGeometry
();
48
}
49
50
if
( mLayer->crs() == crs )
51
{
52
// no projection, return the native geometry
53
return
mFeature.geometry();
54
}
55
56
const
auto
it = mGeometryCache.constFind( crs.
srsid
() );
57
if
( it != mGeometryCache.constEnd() )
58
{
59
// we have it in cache, return it
60
return
it.value();
61
}
62
63
QgsGeometry
transformed = mFeature.geometry();
64
transformed.
transform
(
QgsCoordinateTransform
( mLayer->crs(), crs, mLayout->project() ) );
65
mGeometryCache[crs.
srsid
()] = transformed;
66
return
transformed;
67
}
68
69
QgsVectorLayer
*
QgsLayoutReportContext::layer
()
const
70
{
71
return
mLayer;
72
}
73
74
void
QgsLayoutReportContext::setLayer
(
QgsVectorLayer
*
layer
)
75
{
76
mLayer =
layer
;
77
emit
layerChanged
(
layer
);
78
emit
changed
();
79
}
80
81
void
QgsLayoutReportContext::setPredefinedScales
(
const
QVector<qreal> &scales )
82
{
83
mPredefinedScales = scales;
84
// make sure the list is sorted
85
std::sort( mPredefinedScales.begin(), mPredefinedScales.end() );
// clazy:exclude=detaching-member
86
}
QgsCoordinateReferenceSystem
Represents a coordinate reference system (CRS).
Definition
qgscoordinatereferencesystem.h:216
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition
qgscoordinatereferencesystem.cpp:1024
QgsCoordinateReferenceSystem::srsid
long srsid() const
Returns the internal CRS ID, if available.
Definition
qgscoordinatereferencesystem.cpp:1232
QgsCoordinateTransform
Handles coordinate transforms between two coordinate systems.
Definition
qgscoordinatetransform.h:63
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition
qgsfeature.h:60
QgsGeometry
A geometry is the spatial representation of a feature.
Definition
qgsgeometry.h:267
QgsGeometry::transform
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
Definition
qgsgeometry.cpp:4177
QgsLayoutReportContext::setLayer
void setLayer(QgsVectorLayer *layer)
Sets the vector layer associated with the layout's context.
Definition
qgslayoutreportcontext.cpp:74
QgsLayoutReportContext::setFeature
void setFeature(const QgsFeature &feature)
Sets the current feature for evaluating the layout.
Definition
qgslayoutreportcontext.cpp:30
QgsLayoutReportContext::feature
QgsFeature feature() const
Returns the current feature for evaluating the layout.
Definition
qgslayoutreportcontext.h:59
QgsLayoutReportContext::setPredefinedScales
Q_DECL_DEPRECATED void setPredefinedScales(const QVector< qreal > &scales)
Sets the list of predefined scales to use with the layout.
Definition
qgslayoutreportcontext.cpp:81
QgsLayoutReportContext::layerChanged
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
QgsLayoutReportContext::QgsLayoutReportContext
QgsLayoutReportContext(QgsLayout *layout)
Constructor for QgsLayoutReportContext.
Definition
qgslayoutreportcontext.cpp:25
QgsLayoutReportContext::changed
void changed()
Emitted certain settings in the context is changed, e.g.
QgsLayoutReportContext::layer
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
Definition
qgslayoutreportcontext.cpp:69
QgsLayoutReportContext::currentGeometry
QgsGeometry currentGeometry(const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Returns the current feature() geometry in the given crs.
Definition
qgslayoutreportcontext.cpp:37
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition
qgslayout.h:51
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
qgsfeature.h
qgslayout.h
qgslayoutreportcontext.h
qgsvectorlayer.h
Generated on
for QGIS API Documentation by
1.17.0