QGIS API Documentation  master-6227475
src/core/qgis.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                                 qgis.cpp
00003 
00004                              -------------------
00005     begin                : 2007
00006     copyright            : (C) 2007 by Gary E. Sherman
00007     email                : sherman@mrcc.com
00008 ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 #include "qgis.h"
00019 #ifndef QGSVERSION
00020 #include "qgsversion.h"
00021 #endif
00022 #include <QCoreApplication>
00023 #include <QDate>
00024 #include <QTime>
00025 #include <QDateTime>
00026 #include "qgsconfig.h"
00027 #include "qgslogger.h"
00028 
00029 #include <ogr_api.h>
00030 
00031 // Version constants
00032 //
00033 
00034 // Version string
00035 const char* QGis::QGIS_VERSION = VERSION;
00036 
00037 // development version
00038 const char* QGis::QGIS_DEV_VERSION = QGSVERSION;
00039 
00040 // Version number used for comparing versions using the
00041 // "Check QGIS Version" function
00042 const int QGis::QGIS_VERSION_INT = VERSION_INT;
00043 
00044 // Release name
00045 const char* QGis::QGIS_RELEASE_NAME = RELEASE_NAME;
00046 
00047 #if GDAL_VERSION_NUM >= 1800
00048 const CORE_EXPORT QString GEOPROJ4 = "+proj=longlat +datum=WGS84 +no_defs";
00049 #else
00050 const CORE_EXPORT QString GEOPROJ4 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
00051 #endif
00052 
00053 const CORE_EXPORT QString GEOWKT =
00054   "GEOGCS[\"WGS 84\", "
00055   "  DATUM[\"WGS_1984\", "
00056   "    SPHEROID[\"WGS 84\",6378137,298.257223563, "
00057   "      AUTHORITY[\"EPSG\",7030]], "
00058   "    TOWGS84[0,0,0,0,0,0,0], "
00059   "    AUTHORITY[\"EPSG\",6326]], "
00060   "  PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",8901]], "
00061   "  UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",9108]], "
00062   "  AXIS[\"Lat\",NORTH], "
00063   "  AXIS[\"Long\",EAST], "
00064   "  AUTHORITY[\"EPSG\",4326]]";
00065 
00066 const CORE_EXPORT QString PROJECT_SCALES =
00067   "1:1000000,1:500000,1:250000,1:100000,1:50000,1:25000,"
00068   "1:10000,1:5000,1:2500,1:1000,1:500";
00069 
00070 const CORE_EXPORT QString GEO_EPSG_CRS_AUTHID = "EPSG:4326";
00071 
00072 const CORE_EXPORT QString GEO_NONE = "NONE";
00073 
00074 const double QGis::DEFAULT_IDENTIFY_RADIUS = 0.5;
00075 
00076 // description strings for units
00077 // Order must match enum indices
00078 const char* QGis::qgisUnitTypes[] =
00079 {
00080   QT_TRANSLATE_NOOP( "QGis::UnitType", "meters" ),
00081   QT_TRANSLATE_NOOP( "QGis::UnitType", "feet" ),
00082   QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
00083   QT_TRANSLATE_NOOP( "QGis::UnitType", "<unknown>" ),
00084   QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
00085   QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
00086   QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" )
00087 };
00088 
00089 QGis::UnitType QGis::fromLiteral( QString literal, QGis::UnitType defaultType )
00090 {
00091   for ( unsigned int i = 0; i < ( sizeof( qgisUnitTypes ) / sizeof( qgisUnitTypes[0] ) ); i++ )
00092   {
00093     if ( literal == qgisUnitTypes[ i ] )
00094     {
00095       return static_cast<UnitType>( i );
00096     }
00097   }
00098   return defaultType;
00099 }
00100 
00101 QString QGis::toLiteral( QGis::UnitType unit )
00102 {
00103   return QString( qgisUnitTypes[ static_cast<int>( unit )] );
00104 }
00105 
00106 QString QGis::tr( QGis::UnitType unit )
00107 {
00108   return QCoreApplication::translate( "QGis::UnitType", qPrintable( toLiteral( unit ) ) );
00109 }
00110 
00111 void *qgsMalloc( size_t size )
00112 {
00113   if ( size == 0 || long( size ) < 0 )
00114   {
00115     QgsDebugMsg( QString( "Negative or zero size %1." ).arg( size ) );
00116     return NULL;
00117   }
00118   void *p = malloc( size );
00119   if ( p == NULL )
00120   {
00121     QgsDebugMsg( QString( "Allocation of %1 bytes failed." ).arg( size ) );
00122   }
00123   return p;
00124 }
00125 
00126 void *qgsCalloc( size_t nmemb, size_t size )
00127 {
00128   if ( nmemb == 0 || long( nmemb ) < 0 || size == 0 || long( size ) < 0 )
00129   {
00130     QgsDebugMsg( QString( "Negative or zero nmemb %1 or size %2." ).arg( nmemb ).arg( size ) );
00131     return NULL;
00132   }
00133   void *p = qgsMalloc( nmemb * size );
00134   if ( p != NULL )
00135   {
00136     memset( p, 0, nmemb * size );
00137   }
00138   return p;
00139 }
00140 
00141 void qgsFree( void *ptr )
00142 {
00143   free( ptr );
00144 }
00145 
00146 bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs )
00147 {
00148   switch ( lhs.type() )
00149   {
00150     case QVariant::Int:
00151       return lhs.toInt() < rhs.toInt();
00152     case QVariant::UInt:
00153       return lhs.toUInt() < rhs.toUInt();
00154     case QVariant::LongLong:
00155       return lhs.toLongLong() < rhs.toLongLong();
00156     case QVariant::ULongLong:
00157       return lhs.toULongLong() < rhs.toULongLong();
00158     case QVariant::Double:
00159       return lhs.toDouble() < rhs.toDouble();
00160     case QVariant::Char:
00161       return lhs.toChar() < rhs.toChar();
00162     case QVariant::Date:
00163       return lhs.toDate() < rhs.toDate();
00164     case QVariant::Time:
00165       return lhs.toTime() < rhs.toTime();
00166     case QVariant::DateTime:
00167       return lhs.toDateTime() < rhs.toDateTime();
00168     default:
00169       return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
00170   }
00171 }
00172 
00173 bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs )
00174 {
00175   return ! qgsVariantLessThan( lhs, rhs );
00176 }
00177 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines