QGIS API Documentation  2.8.6-Wien
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 ) : minScale( minScale ), maxScale( maxScale ) {}
42 
44  double minScale;
46  double maxScale;
47 
53  double computeMapUnitsPerPixel( const QgsRenderContext& c ) const
54  {
55  double mup = c.mapToPixel().mapUnitsPerPixel();
56  double renderScale = c.rendererScale(); // Note: this value is 1 / scale
57  if ( minScale != 0 )
58  {
59  mup = qMin( mup / ( minScale * renderScale ), mup );
60  }
61  if ( maxScale != 0 )
62  {
63  mup = qMax( mup / ( maxScale * renderScale ), mup );
64  }
65  return mup;
66  }
67 
68  bool operator==( const QgsMapUnitScale& other ) const
69  {
70  return minScale == other.minScale && maxScale == other.maxScale;
71  }
72 
73  bool operator!=( const QgsMapUnitScale& other ) const
74  {
75  return minScale != other.minScale || maxScale != other.maxScale;
76  }
77 };
78 
79 
80 #endif // QGSMAPUNITSCALE_H
81 
82 
83 
bool operator==(const QgsMapUnitScale &other) const
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.
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.
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.