QGIS API Documentation  2.12.0-Lyon
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 ( minScale != 0 )
74  {
75  mup = qMin( mup / ( minScale * renderScale ), mup );
76  }
77  if ( 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 minScale == other.minScale && maxScale == other.maxScale
87  && minSizeMMEnabled == other.minSizeMMEnabled
88  && minSizeMM == other.minSizeMM
89  && maxSizeMMEnabled == other.maxSizeMMEnabled
90  && maxSizeMM == other.maxSizeMM;
91  }
92 
93  bool operator!=( const QgsMapUnitScale& other ) const
94  {
95  return !operator==( other );
96  }
97 };
98 
99 
100 #endif // QGSMAPUNITSCALE_H
101 
102 
103 
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
bool operator==(const QgsMapUnitScale &other) const
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
double rendererScale() const
double computeMapUnitsPerPixel(const QgsRenderContext &c) const
Computes a map units per pixel scaling factor, respecting the minimum and maximum scales set for the ...
double maxScale
The maximum scale, or 0.0 if unset.
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
double mapUnitsPerPixel() const
Return current map units per pixel.
Contains information about the context of a rendering operation.
QgsMapUnitScale(double minScale=0.0, double maxScale=0.0)
Constructor for QgsMapUnitScale.
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
Struct for storing maximum and minimum scales for measurements in map units.
const QgsMapToPixel & mapToPixel() const
bool operator!=(const QgsMapUnitScale &other) const
double minScale
The minimum scale, or 0.0 if unset.
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.