QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsabstractprofilegenerator.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsabstractprofilegenerator.cpp
3  ---------------
4  begin : March 2022
5  copyright : (C) 2022 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
18 #include "qgsprofilesnapping.h"
19 
20 
22  : mRenderContext( context )
23 {
24 
25 }
26 
27 const QTransform &QgsProfileRenderContext::worldTransform() const
28 {
29  return mWorldTransform;
30 }
31 
32 void QgsProfileRenderContext::setWorldTransform( const QTransform &transform )
33 {
34  mWorldTransform = transform;
35 }
36 
38 {
39  return mDistanceRange;
40 }
41 
43 {
44  mDistanceRange = range;
45 }
46 
48 {
49  return mElevationRange;
50 }
51 
53 {
54  mElevationRange = range;
55 }
56 
57 
59 
61 
63 {
64  return QgsProfileSnapResult();
65 }
66 
67 QVector<QgsProfileIdentifyResults> QgsAbstractProfileResults::identify( const QgsProfilePoint &, const QgsProfileIdentifyContext & )
68 {
69  return {};
70 }
71 
72 QVector<QgsProfileIdentifyResults> QgsAbstractProfileResults::identify( const QgsDoubleRange &, const QgsDoubleRange &, const QgsProfileIdentifyContext & )
73 {
74  return {};
75 }
76 
78 {
79 
80 }
81 
82 //
83 // QgsProfileGenerationContext
84 //
85 
86 #define POINTS_TO_MM 2.83464567
87 #define INCH_TO_MM 25.4
88 
90 {
91  double conversionFactor = 1.0;
92  const double pixelsPerMillimeter = mDpi / 25.4;
93  switch ( unit )
94  {
96  conversionFactor = pixelsPerMillimeter;
97  break;
98 
100  conversionFactor = pixelsPerMillimeter / POINTS_TO_MM;
101  break;
102 
104  conversionFactor = pixelsPerMillimeter * INCH_TO_MM;
105  break;
106 
108  {
109  conversionFactor = 1.0 / mMapUnitsPerDistancePixel;
110  break;
111  }
113  conversionFactor = 1.0;
114  break;
115 
119  //not supported
120  conversionFactor = 1.0;
121  break;
122  }
123 
124  return size * conversionFactor;
125 }
126 
128 {
129  return qgsDoubleNear( mMaxErrorMapUnits, other.mMaxErrorMapUnits )
130  && qgsDoubleNear( mMapUnitsPerDistancePixel, other.mMapUnitsPerDistancePixel )
131  && qgsDoubleNear( mDpi, other.mDpi )
132  && mDistanceRange == other.mDistanceRange
133  && mElevationRange == other.mElevationRange;
134 }
135 
137 {
138  return !( *this == other );
139 }
140 
141 Qgis::ProfileGeneratorFlags QgsAbstractProfileGenerator::flags() const
142 {
143  return Qgis::ProfileGeneratorFlags();
144 }
145 
146 QgsProfileIdentifyResults::QgsProfileIdentifyResults( QgsMapLayer *layer, const QVector<QVariantMap> &results )
147  : mLayer( layer )
148  , mResults( results )
149 {
150 
151 }
QgsProfileIdentifyContext
Encapsulates the context of identifying profile results.
Definition: qgsabstractprofilegenerator.h:125
QgsUnitTypes::RenderInches
@ RenderInches
Inches.
Definition: qgsunittypes.h:174
QgsProfileRenderContext::distanceRange
QgsDoubleRange distanceRange() const
Returns the range of distances to include in the render.
Definition: qgsabstractprofilegenerator.cpp:37
QgsAbstractProfileResults::~QgsAbstractProfileResults
virtual ~QgsAbstractProfileResults()
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsProfileRenderContext::setElevationRange
void setElevationRange(const QgsDoubleRange &range)
Sets the range of elevations to include in the render.
Definition: qgsabstractprofilegenerator.cpp:52
INCH_TO_MM
#define INCH_TO_MM
Definition: qgsabstractprofilegenerator.cpp:87
QgsProfileIdentifyResults::QgsProfileIdentifyResults
QgsProfileIdentifyResults(QgsMapLayer *layer=nullptr, const QVector< QVariantMap > &results=QVector< QVariantMap >())
Constructor for QgsProfileIdentifyResult, with the associated map layer.
Definition: qgsabstractprofilegenerator.cpp:146
QgsProfileSnapResult
Encapsulates results of snapping a profile point.
Definition: qgsprofilesnapping.h:56
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
QgsAbstractProfileGenerator
Abstract base class for objects which generate elevation profiles.
Definition: qgsabstractprofilegenerator.h:392
QgsUnitTypes::RenderPercentage
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:172
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsProfileRenderContext::setDistanceRange
void setDistanceRange(const QgsDoubleRange &range)
Sets the range of distances to include in the render.
Definition: qgsabstractprofilegenerator.cpp:42
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
QgsProfileSnapContext
Encapsulates the context of snapping a profile point.
Definition: qgsprofilesnapping.h:30
QgsAbstractProfileResults::identify
virtual QVector< QgsProfileIdentifyResults > identify(const QgsProfilePoint &point, const QgsProfileIdentifyContext &context)
Identify results visible at the specified profile point.
Definition: qgsabstractprofilegenerator.cpp:67
QgsProfilePoint
Encapsulates a point on a distance-elevation profile.
Definition: qgsprofilepoint.h:30
QgsProfileGenerationContext::operator!=
bool operator!=(const QgsProfileGenerationContext &other) const
Definition: qgsabstractprofilegenerator.cpp:136
QgsProfileGenerationContext
Encapsulates the context in which an elevation profile is to be generated.
Definition: qgsabstractprofilegenerator.h:262
QgsAbstractProfileResults::copyPropertiesFromGenerator
virtual void copyPropertiesFromGenerator(const QgsAbstractProfileGenerator *generator)
Copies properties from specified generator to the results object.
Definition: qgsabstractprofilegenerator.cpp:77
QgsProfileGenerationContext::operator==
bool operator==(const QgsProfileGenerationContext &other) const
Definition: qgsabstractprofilegenerator.cpp:127
qgsprofilesnapping.h
QgsProfileGenerationContext::convertDistanceToPixels
double convertDistanceToPixels(double size, QgsUnitTypes::RenderUnit unit) const
Converts a distance size from the specified units to pixels.
Definition: qgsabstractprofilegenerator.cpp:89
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:2265
QgsAbstractProfileGenerator::~QgsAbstractProfileGenerator
virtual ~QgsAbstractProfileGenerator()
QgsProfileRenderContext::QgsProfileRenderContext
QgsProfileRenderContext(QgsRenderContext &context)
Constructor for QgsProfileRenderContext, with the specified embedded render context.
Definition: qgsabstractprofilegenerator.cpp:21
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
QgsDoubleRange
QgsRange which stores a range of double values.
Definition: qgsrange.h:202
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsProfileRenderContext::worldTransform
const QTransform & worldTransform() const
Returns the transform from world coordinates to painter coordinates.
Definition: qgsabstractprofilegenerator.cpp:27
QgsUnitTypes::RenderMetersInMapUnits
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:176
QgsUnitTypes::RenderUnknownUnit
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:175
QgsAbstractProfileGenerator::flags
virtual Qgis::ProfileGeneratorFlags flags() const
Returns flags which reflect how the profile generator operates.
Definition: qgsabstractprofilegenerator.cpp:141
QgsProfileRenderContext::elevationRange
QgsDoubleRange elevationRange() const
Returns the range of elevations to include in the render.
Definition: qgsabstractprofilegenerator.cpp:47
QgsUnitTypes::RenderMapUnits
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170
QgsAbstractProfileResults::snapPoint
virtual QgsProfileSnapResult snapPoint(const QgsProfilePoint &point, const QgsProfileSnapContext &context)
Snaps a point to the generated elevation profile.
Definition: qgsabstractprofilegenerator.cpp:62
QgsProfileRenderContext::setWorldTransform
void setWorldTransform(const QTransform &transform)
Sets the transform from world coordinates to painter coordinates.
Definition: qgsabstractprofilegenerator.cpp:32
qgsabstractprofilegenerator.h
POINTS_TO_MM
#define POINTS_TO_MM
Definition: qgsabstractprofilegenerator.cpp:86