QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsmapunitscale.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapunitscale.h
3  Struct for storing maximum and minimum scales for measurements in map units
4  -------------------
5  begin : April 2014
6  copyright : (C) Sandro Mani
7  email : smani at sourcepole dot ch
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  ***************************************************************************/
17 
18 #ifndef QGSMAPUNITSCALE_H
19 #define QGSMAPUNITSCALE_H
20 
21 #include <QtCore>
22 #include "qgsrendercontext.h"
23 
33 class CORE_EXPORT QgsMapUnitScale
34 {
35  public:
36 
41  QgsMapUnitScale( double minScale = 0.0, double maxScale = 0.0 )
42  : minScale( minScale )
43  , maxScale( maxScale )
44  , minSizeMMEnabled( false )
45  , minSizeMM( 0.0 )
46  , maxSizeMMEnabled( false )
47  , maxSizeMM( 0.0 )
48  {}
49 
51  double minScale;
53  double maxScale;
54 
58  double minSizeMM;
62  double maxSizeMM;
63 
69  double computeMapUnitsPerPixel( const QgsRenderContext& c ) const
70  {
71  double mup = c.mapToPixel().mapUnitsPerPixel();
72  double renderScale = c.rendererScale(); // Note: this value is 1 / scale
73  if ( !qgsDoubleNear( minScale, 0 ) )
74  {
75  mup = qMin( mup / ( minScale * renderScale ), mup );
76  }
77  if ( !qgsDoubleNear( maxScale, 0 ) )
78  {
79  mup = qMax( mup / ( maxScale * renderScale ), mup );
80  }
81  return mup;
82  }
83 
84  bool operator==( const QgsMapUnitScale& other ) const
85  {
86  return qgsDoubleNear( minScale, other.minScale )
87  && qgsDoubleNear( maxScale, other.maxScale )
88  && minSizeMMEnabled == other.minSizeMMEnabled
89  && qgsDoubleNear( minSizeMM, other.minSizeMM )
90  && maxSizeMMEnabled == other.maxSizeMMEnabled
91  && qgsDoubleNear( maxSizeMM, other.maxSizeMM );
92  }
93 
94  bool operator!=( const QgsMapUnitScale& other ) const
95  {
96  return !operator==( other );
97  }
98 };
99 
100 
101 #endif // QGSMAPUNITSCALE_H
102 
103 
104 
double rendererScale() const
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
double computeMapUnitsPerPixel(const QgsRenderContext &c) const
Computes a map units per pixel scaling factor, respecting the minimum and maximum scales set for the ...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:353
double maxScale
The maximum scale, or 0.0 if unset.
bool operator!=(const QgsMapUnitScale &other) const
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
double mapUnitsPerPixel() const
Return current map units per pixel.
bool operator==(const QgsMapUnitScale &other) const
Contains information about the context of a rendering operation.
QgsMapUnitScale(double minScale=0.0, double maxScale=0.0)
Constructor for QgsMapUnitScale.
const QgsMapToPixel & mapToPixel() const
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
Struct for storing maximum and minimum scales for measurements in map units.
double minScale
The minimum scale, or 0.0 if unset.
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.