QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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
18#include "moc_qgslayoutreportcontext.cpp"
19#include "qgsfeature.h"
20#include "qgslayout.h"
21#include "qgsvectorlayer.h"
22
24 : QObject( layout )
25 , mLayout( layout )
26{}
27
29{
30 mFeature = feature;
31 mGeometryCache.clear();
32 emit changed();
33}
34
36{
37 if ( !crs.isValid() )
38 {
39 // no projection, return the native geometry
40 return mFeature.geometry();
41 }
42
43 if ( !mLayer || !mFeature.isValid() || !mFeature.hasGeometry() )
44 {
45 return QgsGeometry();
46 }
47
48 if ( mLayer->crs() == crs )
49 {
50 // no projection, return the native geometry
51 return mFeature.geometry();
52 }
53
54 const auto it = mGeometryCache.constFind( crs.srsid() );
55 if ( it != mGeometryCache.constEnd() )
56 {
57 // we have it in cache, return it
58 return it.value();
59 }
60
61 QgsGeometry transformed = mFeature.geometry();
62 transformed.transform( QgsCoordinateTransform( mLayer->crs(), crs, mLayout->project() ) );
63 mGeometryCache[crs.srsid()] = transformed;
64 return transformed;
65}
66
68{
69 return mLayer;
70}
71
73{
74 mLayer = layer;
75 emit layerChanged( layer );
76 emit changed();
77}
78
79void QgsLayoutReportContext::setPredefinedScales( const QVector<qreal> &scales )
80{
81 mPredefinedScales = scales;
82 // make sure the list is sorted
83 std::sort( mPredefinedScales.begin(), mPredefinedScales.end() ); // clazy:exclude=detaching-member
84}
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
long srsid() const
Returns the internal CRS ID, if available.
Class for doing transforms between two map coordinate systems.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QgsGeometry geometry
Definition qgsfeature.h:69
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool isValid() const
Returns the validity of this feature.
A geometry is the spatial representation of a feature.
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.
void setLayer(QgsVectorLayer *layer)
Sets the vector layer associated with the layout's context.
void setFeature(const QgsFeature &feature)
Sets the current feature for evaluating the layout.
QgsFeature feature() const
Returns the current feature for evaluating the layout.
Q_DECL_DEPRECATED void setPredefinedScales(const QVector< qreal > &scales)
Sets the list of predefined scales to use with the layout.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
QgsLayoutReportContext(QgsLayout *layout)
Constructor for QgsLayoutReportContext.
void changed()
Emitted certain settings in the context is changed, e.g.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
QgsGeometry currentGeometry(const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Returns the current feature() geometry in the given crs.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
QgsProject * project() const
The project associated with the layout.
Represents a vector layer which manages a vector based data sets.
const QgsCoordinateReferenceSystem & crs