QGIS API Documentation  2.99.0-Master (37c43df)
qgis.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgis.h - QGIS namespace
3  -------------------
4  begin : Sat Jun 30 2002
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.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  ***************************************************************************/
17 
18 #ifndef QGIS_H
19 #define QGIS_H
20 
21 #include <QEvent>
22 #include <QString>
23 #include <QRegExp>
24 #include <QMetaType>
25 #include <QVariant>
26 #include <QDateTime>
27 #include <QDate>
28 #include <QTime>
29 #include <QHash>
30 #include <stdlib.h>
31 #include <cfloat>
32 #include <cmath>
33 #include <qnumeric.h>
34 
35 #include <qgswkbtypes.h>
36 
40 class CORE_EXPORT Qgis
41 {
42  public:
43  // Version constants
44  //
46  static QString QGIS_VERSION;
48  static const int QGIS_VERSION_INT;
50  static QString QGIS_RELEASE_NAME;
52  static const char* QGIS_DEV_VERSION;
53 
54  // Enumerations
55  //
56 
60  enum DataType
61  {
62  UnknownDataType = 0,
63  Byte = 1,
64  UInt16 = 2,
65  Int16 = 3,
66  UInt32 = 4,
67  Int32 = 5,
68  Float32 = 6,
69  Float64 = 7,
70  CInt16 = 8,
71  CInt32 = 9,
72  CFloat32 = 10,
73  CFloat64 = 11,
74  ARGB32 = 12,
75  ARGB32_Premultiplied = 13
76  };
77 
79  enum UserEvent
80  {
81  // These first two are useful for threads to alert their parent data providers
82 
84  ProviderExtentCalcEvent = ( QEvent::User + 1 ),
85 
87  ProviderCountCalcEvent
88  };
89 
92  static const double DEFAULT_SEARCH_RADIUS_MM;
93 
95  static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
96 
100  static const QColor DEFAULT_HIGHLIGHT_COLOR;
101 
105 
109 
114  static double SCALE_PRECISION;
115 
116  private:
117  // String representation of unit types (set in qgis.cpp)
118  static const char *qgisUnitTypes[];
119 
120 };
121 
122 // hack to workaround warnings when casting void pointers
123 // retrieved from QLibrary::resolve to function pointers.
124 // It's assumed that this works on all systems supporting
125 // QLibrary
126 #define cast_to_fptr(f) f
127 
135 // based on Boojum's code from http://stackoverflow.com/questions/3556687/prevent-firing-signals-in-qt
136 template<class Object> class QgsSignalBlocker // clazy:exclude=rule-of-three
137 {
138  public:
139 
143  explicit QgsSignalBlocker( Object* object )
144  : mObject( object )
145  , mPreviousState( object->blockSignals( true ) )
146  {}
147 
149  {
150  mObject->blockSignals( mPreviousState );
151  }
152 
154  Object* operator->() { return mObject; }
155 
156  private:
157 
158  Object* mObject;
159  bool mPreviousState;
160 
161 };
162 
175 // based on Boojum's code from http://stackoverflow.com/questions/3556687/prevent-firing-signals-in-qt
176 template<class Object> inline QgsSignalBlocker<Object> whileBlocking( Object* object )
177 {
178  return QgsSignalBlocker<Object>( object );
179 }
180 
184 inline QString qgsDoubleToString( double a, int precision = 17 )
185 {
186  if ( precision )
187  return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
188  else
189  return QString::number( a, 'f', precision );
190 }
191 
196 inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON )
197 {
198  const double diff = a - b;
199  return diff > -epsilon && diff <= epsilon;
200 }
201 
206 inline bool qgsFloatNear( float a, float b, float epsilon = 4 * FLT_EPSILON )
207 {
208  const float diff = a - b;
209  return diff > -epsilon && diff <= epsilon;
210 }
211 
213 inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 )
214 {
215  // The most simple would be to print numbers as %.xe and compare as strings
216  // but that is probably too costly
217  // Then the fastest would be to set some bits directly, but little/big endian
218  // has to be considered (maybe TODO)
219  // Is there a better way?
220  int aexp, bexp;
221  double ar = frexp( a, &aexp );
222  double br = frexp( b, &bexp );
223 
224  return aexp == bexp &&
225  qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) );
226 }
227 
229 inline double qgsRound( double x )
230 {
231  return x < 0.0 ? std::ceil( x - 0.5 ) : std::floor( x + 0.5 );
232 }
233 
242 CORE_EXPORT double qgsPermissiveToDouble( QString string, bool& ok );
243 
252 CORE_EXPORT int qgsPermissiveToInt( QString string, bool& ok );
253 
258 CORE_EXPORT bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );
259 
264 CORE_EXPORT bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );
265 
266 CORE_EXPORT QString qgsVsiPrefix( const QString& path );
267 
272 void CORE_EXPORT *qgsMalloc( size_t size );
273 
280 void CORE_EXPORT *qgsCalloc( size_t nmemb, size_t size );
281 
285 void CORE_EXPORT qgsFree( void *ptr );
286 
290 extern CORE_EXPORT const QString GEOWKT;
291 extern CORE_EXPORT const QString PROJECT_SCALES;
292 
294 extern CORE_EXPORT const QString GEOPROJ4;
296 const long GEOSRID = 4326;
298 const long GEOCRS_ID = 3452;
300 const long GEO_EPSG_CRS_ID = 4326;
302 extern CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID;
304 const int PROJ_PREFIX_LEN = 6;
306 const int ELLPS_PREFIX_LEN = 7;
308 const int LAT_PREFIX_LEN = 7;
309 
312 const int USER_CRS_START_ID = 100000;
313 
315 extern CORE_EXPORT const QString GEO_NONE;
316 
317 //
318 // Constants for point symbols
319 //
320 
322 const double DEFAULT_POINT_SIZE = 2.0;
323 const double DEFAULT_LINE_WIDTH = 0.26;
324 
326 const double DEFAULT_SEGMENT_EPSILON = 1e-8;
327 
328 typedef QMap<QString, QString> QgsStringMap;
329 
336 typedef unsigned long long qgssize;
337 
338 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
339 #define Q_NOWARN_DEPRECATED_PUSH \
340  _Pragma("GCC diagnostic push") \
341  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
342 #define Q_NOWARN_DEPRECATED_POP \
343  _Pragma("GCC diagnostic pop");
344 #elif defined(_MSC_VER)
345 #define Q_NOWARN_DEPRECATED_PUSH \
346  __pragma(warning(push)) \
347  __pragma(warning(disable:4996))
348 #define Q_NOWARN_DEPRECATED_POP \
349  __pragma(warning(pop))
350 #else
351 #define Q_NOWARN_DEPRECATED_PUSH
352 #define Q_NOWARN_DEPRECATED_POP
353 #endif
354 
355 #ifndef QGISEXTERN
356 #ifdef Q_OS_WIN
357 # define QGISEXTERN extern "C" __declspec( dllexport )
358 # ifdef _MSC_VER
359 // do not warn about C bindings returing QString
360 # pragma warning(disable:4190)
361 # endif
362 #else
363 # if defined(__GNUC__) || defined(__clang__)
364 # define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
365 # else
366 # define QGISEXTERN extern "C"
367 # endif
368 #endif
369 #endif
370 #endif
371 
372 #if defined(__clang__)
373 #define FALLTHROUGH //[[clang::fallthrough]]
374 #else
375 #define FALLTHROUGH
376 #endif
CORE_EXPORT QString qgsVsiPrefix(const QString &path)
Definition: qgis.cpp:213
static double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM
Default highlight line/outline minimum width in mm.
Definition: qgis.h:108
static const char * QGIS_DEV_VERSION
The development version.
Definition: qgis.h:52
bool qgsFloatNear(float a, float b, float epsilon=4 *FLT_EPSILON)
Compare two floats (but allow some difference)
Definition: qgis.h:206
DataType
Raster data types.
Definition: qgis.h:60
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
Definition: qgis.h:100
void CORE_EXPORT * qgsCalloc(size_t nmemb, size_t size)
Allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the alloc...
Definition: qgis.cpp:120
static const int QGIS_VERSION_INT
Version number used for comparing versions using the "Check QGIS Version" function.
Definition: qgis.h:48
QMap< QString, QString > QgsStringMap
Definition: qgis.h:328
~QgsSignalBlocker()
Definition: qgis.h:148
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:196
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:40
CORE_EXPORT bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
Definition: qgis.cpp:140
UserEvent
User defined event types.
Definition: qgis.h:79
double qgsRound(double x)
A round function which returns a double to guard against overflows.
Definition: qgis.h:229
QgsSignalBlocker(Object *object)
Constructor for QgsSignalBlocker.
Definition: qgis.h:143
CORE_EXPORT const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
Definition: qgis.cpp:75
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Definition: qgis.h:326
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:184
const int ELLPS_PREFIX_LEN
The length of the string "+ellps=".
Definition: qgis.h:306
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:298
static const double DEFAULT_SEARCH_RADIUS_MM
Identify search radius in mm.
Definition: qgis.h:92
CORE_EXPORT double qgsPermissiveToDouble(QString string, bool &ok)
Converts a string to a double in a permissive way, eg allowing for incorrect numbers of digits betwee...
Definition: qgis.cpp:91
CORE_EXPORT const QString GEOPROJ4
PROJ4 string that represents a geographic coord sys.
Definition: qgis.cpp:53
static double SCALE_PRECISION
Fudge factor used to compare two scales.
Definition: qgis.h:114
RAII signal blocking class.
Definition: qgis.h:136
void CORE_EXPORT qgsFree(void *ptr)
Frees the memory space pointed to by ptr.
Definition: qgis.cpp:135
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
Definition: qgis.h:336
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
Definition: qgis.h:322
static const float DEFAULT_MAPTOPIXEL_THRESHOLD
Default threshold between map coordinates and device coordinates for map2pixel simplification.
Definition: qgis.h:95
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/...
Definition: qgis.h:312
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:176
const long GEOSRID
Magic number for a geographic coord sys in POSTGIS SRID.
Definition: qgis.h:296
bool qgsDoubleNearSig(double a, double b, int significantDigits=10)
Compare two doubles using specified number of significant digits.
Definition: qgis.h:213
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:323
CORE_EXPORT const QString PROJECT_SCALES
Definition: qgis.cpp:69
const int LAT_PREFIX_LEN
The length of the string "+lat_1=".
Definition: qgis.h:308
static QString QGIS_VERSION
Version string.
Definition: qgis.h:46
const int PROJ_PREFIX_LEN
The length of the string "+proj=".
Definition: qgis.h:304
static double DEFAULT_HIGHLIGHT_BUFFER_MM
Default highlight buffer in mm.
Definition: qgis.h:104
CORE_EXPORT int qgsPermissiveToInt(QString string, bool &ok)
Converts a string to an integer in a permissive way, eg allowing for incorrect numbers of digits betw...
Definition: qgis.cpp:98
CORE_EXPORT bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
Definition: qgis.cpp:208
void CORE_EXPORT * qgsMalloc(size_t size)
Allocates size bytes and returns a pointer to the allocated memory.
Definition: qgis.cpp:105
Object * operator->()
Returns pointer to blocked QObject.
Definition: qgis.h:154
const long GEO_EPSG_CRS_ID
Magic number for a geographic coord sys in EpsgCrsId ID format.
Definition: qgis.h:300
CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
Definition: qgis.cpp:73
CORE_EXPORT const QString GEOWKT
Wkt string that represents a geographic coord sys.
Definition: qgis.cpp:56
static QString QGIS_RELEASE_NAME
Release name.
Definition: qgis.h:50