QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
24 class CORE_EXPORT QgsMapUnitScale
25 {
26  public:
27  QgsMapUnitScale() : minScale( 0.0 ), maxScale( 0.0 ) {}
28  QgsMapUnitScale( float _minScale, float _maxScale ) : minScale( _minScale ), maxScale( _maxScale ) {}
29 
31  double minScale;
33  double maxScale;
34 
35  double computeMapUnitsPerPixel( const QgsRenderContext& c ) const
36  {
37  double mup = c.mapToPixel().mapUnitsPerPixel();
38  double renderScale = c.rendererScale(); // Note: this value is 1 / scale
39  if ( minScale != 0 )
40  {
41  mup = qMin( mup / ( minScale * renderScale ), mup );
42  }
43  if ( maxScale != 0 )
44  {
45  mup = qMax( mup / ( maxScale * renderScale ), mup );
46  }
47  return mup;
48  }
49 
50  bool operator==( const QgsMapUnitScale& other ) const
51  {
52  return minScale == other.minScale && maxScale == other.maxScale;
53  }
54 
55  bool operator!=( const QgsMapUnitScale& other ) const
56  {
57  return minScale != other.minScale || maxScale != other.maxScale;
58  }
59 };
60 
61 
62 #endif // QGSMAPUNITSCALE_H
63 
64 
65