QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgis.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgis.cpp
3 
4  -------------------
5  begin : 2007
6  copyright : (C) 2007 by Gary E. Sherman
7  email : [email protected]
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 #include "qgis.h"
19 #ifndef QGSVERSION
20 #include "qgsversion.h"
21 #endif
22 #include <QCoreApplication>
23 #include <QDate>
24 #include <QTime>
25 #include <QDateTime>
26 #include "qgsconfig.h"
27 #include "qgslogger.h"
28 
29 #include <ogr_api.h>
30 
31 // Version constants
32 //
33 
34 // Version string
35 const char* QGis::QGIS_VERSION = VERSION;
36 
37 // development version
38 const char* QGis::QGIS_DEV_VERSION = QGSVERSION;
39 
40 // Version number used for comparing versions using the
41 // "Check QGIS Version" function
42 const int QGis::QGIS_VERSION_INT = VERSION_INT;
43 
44 // Release name
45 const char* QGis::QGIS_RELEASE_NAME = RELEASE_NAME;
46 
47 #if GDAL_VERSION_NUM >= 1800
48 const CORE_EXPORT QString GEOPROJ4 = "+proj=longlat +datum=WGS84 +no_defs";
49 #else
50 const CORE_EXPORT QString GEOPROJ4 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
51 #endif
52 
53 const CORE_EXPORT QString GEOWKT =
54  "GEOGCS[\"WGS 84\", "
55  " DATUM[\"WGS_1984\", "
56  " SPHEROID[\"WGS 84\",6378137,298.257223563, "
57  " AUTHORITY[\"EPSG\",7030]], "
58  " TOWGS84[0,0,0,0,0,0,0], "
59  " AUTHORITY[\"EPSG\",6326]], "
60  " PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",8901]], "
61  " UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",9108]], "
62  " AXIS[\"Lat\",NORTH], "
63  " AXIS[\"Long\",EAST], "
64  " AUTHORITY[\"EPSG\",4326]]";
65 
66 const CORE_EXPORT QString PROJECT_SCALES =
67  "1:1000000,1:500000,1:250000,1:100000,1:50000,1:25000,"
68  "1:10000,1:5000,1:2500,1:1000,1:500";
69 
70 const CORE_EXPORT QString GEO_EPSG_CRS_AUTHID = "EPSG:4326";
71 
72 const CORE_EXPORT QString GEO_NONE = "NONE";
73 
74 const double QGis::DEFAULT_IDENTIFY_RADIUS = 0.5;
75 
76 // description strings for units
77 // Order must match enum indices
78 const char* QGis::qgisUnitTypes[] =
79 {
80  QT_TRANSLATE_NOOP( "QGis::UnitType", "meters" ),
81  QT_TRANSLATE_NOOP( "QGis::UnitType", "feet" ),
82  QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
83  QT_TRANSLATE_NOOP( "QGis::UnitType", "<unknown>" ),
84  QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
85  QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
86  QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" )
87 };
88 
89 QGis::UnitType QGis::fromLiteral( QString literal, QGis::UnitType defaultType )
90 {
91  for ( unsigned int i = 0; i < ( sizeof( qgisUnitTypes ) / sizeof( qgisUnitTypes[0] ) ); i++ )
92  {
93  if ( literal == qgisUnitTypes[ i ] )
94  {
95  return static_cast<UnitType>( i );
96  }
97  }
98  return defaultType;
99 }
100 
102 {
103  return QString( qgisUnitTypes[ static_cast<int>( unit )] );
104 }
105 
106 QString QGis::tr( QGis::UnitType unit )
107 {
108  return QCoreApplication::translate( "QGis::UnitType", qPrintable( toLiteral( unit ) ) );
109 }
110 
111 void *qgsMalloc( size_t size )
112 {
113  if ( size == 0 || long( size ) < 0 )
114  {
115  QgsDebugMsg( QString( "Negative or zero size %1." ).arg( size ) );
116  return NULL;
117  }
118  void *p = malloc( size );
119  if ( p == NULL )
120  {
121  QgsDebugMsg( QString( "Allocation of %1 bytes failed." ).arg( size ) );
122  }
123  return p;
124 }
125 
126 void *qgsCalloc( size_t nmemb, size_t size )
127 {
128  if ( nmemb == 0 || long( nmemb ) < 0 || size == 0 || long( size ) < 0 )
129  {
130  QgsDebugMsg( QString( "Negative or zero nmemb %1 or size %2." ).arg( nmemb ).arg( size ) );
131  return NULL;
132  }
133  void *p = qgsMalloc( nmemb * size );
134  if ( p != NULL )
135  {
136  memset( p, 0, nmemb * size );
137  }
138  return p;
139 }
140 
141 void qgsFree( void *ptr )
142 {
143  free( ptr );
144 }
145 
146 bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs )
147 {
148  switch ( lhs.type() )
149  {
150  case QVariant::Int:
151  return lhs.toInt() < rhs.toInt();
152  case QVariant::UInt:
153  return lhs.toUInt() < rhs.toUInt();
154  case QVariant::LongLong:
155  return lhs.toLongLong() < rhs.toLongLong();
156  case QVariant::ULongLong:
157  return lhs.toULongLong() < rhs.toULongLong();
158  case QVariant::Double:
159  return lhs.toDouble() < rhs.toDouble();
160  case QVariant::Char:
161  return lhs.toChar() < rhs.toChar();
162  case QVariant::Date:
163  return lhs.toDate() < rhs.toDate();
164  case QVariant::Time:
165  return lhs.toTime() < rhs.toTime();
166  case QVariant::DateTime:
167  return lhs.toDateTime() < rhs.toDateTime();
168  default:
169  return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
170  }
171 }
172 
173 bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs )
174 {
175  return ! qgsVariantLessThan( lhs, rhs );
176 }
177