qgis源码学习3之core模块的qgis.h文件
来源:互联网 发布:统计图用什么软件 编辑:程序博客网 时间:2024/05/16 17:42
这是文件是整个软件的基础文件。里面主要定义了一个QGis这个类。类里面定义了版本信息、各种基础的类型例如:图元类型、单位类型、几何类型、基础的数据类型、event类型。和一些基础的函数,例如double转字符串函数。下面对qgis.h进行了注释。
/*************************************************************************** qgis.h - QGIS namespace ------------------- begin : Sat Jun 30 2002 copyright : (C) 2002 by Gary E.Sherman email : sherman at mrcc.com ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#ifndef QGIS_H#define QGIS_H#include <QEvent>#include <QString>#include <QRegExp>#include <QMetaType>#include <QVariant>#include <stdlib.h>#include <cfloat>#include <cmath>#include <qnumeric.h>/** \ingroup core * The QGis class provides global constants for use throughout the application. */class CORE_EXPORT QGis{ public: // Version constants // // Version string版本信息 static const char* QGIS_VERSION; // Version number used for comparing versions using the "Check QGIS Version" function static const int QGIS_VERSION_INT; // Release name static const char* QGIS_RELEASE_NAME; // The development version static const char* QGIS_DEV_VERSION; // Enumerations // //! Used for symbology operations // Feature types图元的类型 enum WkbType { WKBUnknown = 0, WKBPoint = 1,//点 WKBLineString, WKBPolygon, WKBMultiPoint, WKBMultiLineString, WKBMultiPolygon, WKBNoGeometry = 100, //attributes only WKBPoint25D = 0x80000001, WKBLineString25D, WKBPolygon25D, WKBMultiPoint25D, WKBMultiLineString25D, WKBMultiPolygon25D, }; static WkbType singleType( WkbType type )//图元的多个类型对应的单类型 { switch ( type ) { case WKBMultiPoint: return WKBPoint;//例如这个,多个点自然是由很多单个点组成的。 case WKBMultiLineString: return WKBLineString; case WKBMultiPolygon: return WKBPolygon; case WKBMultiPoint25D: return WKBPoint25D; case WKBMultiLineString25D: return WKBLineString25D; case WKBMultiPolygon25D: return WKBPolygon25D; default: return type; } } static WkbType multiType( WkbType type )//图元的单类型对应的多类型 { switch ( type ) { case WKBPoint: return WKBMultiPoint; case WKBLineString: return WKBMultiLineString; case WKBPolygon: return WKBMultiPolygon; case WKBPoint25D: return WKBMultiPoint25D; case WKBLineString25D: return WKBMultiLineString25D; case WKBPolygon25D: return WKBMultiPolygon25D; default: return type; } } static WkbType flatType( WkbType type )//没有用过这个函数,暂时不知道 { switch ( type ) { case WKBPoint25D: return WKBPoint; case WKBLineString25D: return WKBLineString; case WKBPolygon25D: return WKBPolygon; case WKBMultiPoint25D: return WKBMultiPoint; case WKBMultiLineString25D: return WKBMultiLineString; case WKBMultiPolygon25D: return WKBMultiPolygon; default: return type; } } static bool isSingleType( WkbType type )//是不是单类型 { switch ( flatType( type ) ) { case WKBPoint: case WKBLineString: case WKBPolygon: return true; default: return false; } } static bool isMultiType( WkbType type )//是不是多类型 { switch ( flatType( type ) ) { case WKBMultiPoint: case WKBMultiLineString: case WKBMultiPolygon: return true; default: return false; } } static int wkbDimensions( WkbType type )//这个图元对应的是几维的 { switch ( type ) { case WKBUnknown: return 0; case WKBNoGeometry: return 0; case WKBPoint25D: return 3;//这种类型的是3维的 case WKBLineString25D: return 3; case WKBPolygon25D: return 3; case WKBMultiPoint25D: return 3; case WKBMultiLineString25D: return 3; case WKBMultiPolygon25D: return 3; default: return 2; } } enum GeometryType//几何类型。图元中包含几何这个成员。 { Point, Line, Polygon,//多边形 UnknownGeometry, NoGeometry }; //! description strings for geometry types static const char *vectorGeometryType( GeometryType type )//几何类型的描述,这个函数应该不支持国际化吧 { switch ( type ) { case Point: return "Point"; case Line: return "Line"; case Polygon: return "Polygon"; case UnknownGeometry: return "Unknown geometry"; case NoGeometry: return "No geometry"; default: return "Invalid type"; } } //! description strings for feature types static const char *featureType( WkbType type )//得到图元的描述字符串 { switch ( type ) { case WKBUnknown: return "WKBUnknown"; case WKBPoint: return "WKBPoint"; case WKBLineString: return "WKBLineString"; case WKBPolygon: return "WKBPolygon"; case WKBMultiPoint: return "WKBMultiPoint"; case WKBMultiLineString: return "WKBMultiLineString"; case WKBMultiPolygon: return "WKBMultiPolygon"; case WKBNoGeometry: return "WKBNoGeometry"; case WKBPoint25D: return "WKBPoint25D"; case WKBLineString25D: return "WKBLineString25D"; case WKBPolygon25D: return "WKBPolygon25D"; case WKBMultiPoint25D: return "WKBMultiPoint25D"; case WKBMultiLineString25D: return "WKBMultiLineString25D"; case WKBMultiPolygon25D: return "WKBMultiPolygon25D"; default: return "invalid wkbtype"; } } /** Raster data types. * This is modified and extended copy of GDALDataType. */ enum DataType//数据类型。相当重要。 { /*! Unknown or unspecified type */ UnknownDataType = 0, /*! Eight bit unsigned integer (quint8) */ Byte = 1, /*! Sixteen bit unsigned integer (quint16) */ UInt16 = 2, /*! Sixteen bit signed integer (qint16) */ Int16 = 3, /*! Thirty two bit unsigned integer (quint32) */ UInt32 = 4, /*! Thirty two bit signed integer (qint32) */ Int32 = 5, /*! Thirty two bit floating point (float) */ Float32 = 6, /*! Sixty four bit floating point (double) */ Float64 = 7, /*! Complex Int16 */ CInt16 = 8, /*! Complex Int32 */ CInt32 = 9, /*! Complex Float32 */ CFloat32 = 10, /*! Complex Float64 */ CFloat64 = 11, /*! Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32 */ ARGB32 = 12, /*! Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied */ ARGB32_Premultiplied = 13 }; /** Map units that qgis supports * @note that QGIS < 1.4 api had only Meters, Feet, Degrees and UnknownUnit * @note and QGIS >1.8 returns to that */ enum UnitType//单位类型 { Meters = 0,//米 Feet = 1,//英尺 Degrees = 2, //for 1.0 api backwards compatibility UnknownUnit = 3, // for [1.4;1.8] api compatibility DecimalDegrees = 2, // was 2 DegreesMinutesSeconds = 2, // was 4 DegreesDecimalMinutes = 2, // was 5 NauticalMiles = 7 }; //! Provides the canonical name of the type value // Added in version 2.0把对应的单位转换为可以显示的字符串,内部的实现是通过查一个数组qgisUnitTypes[] //来实现的。 static QString toLiteral( QGis::UnitType unit ); //! Converts from the canonical name to the type value // Added in version 2.0把字符串转换为对应的单位类型。同样是通过查找qgisUnitTypes[]实现的 static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit ); //! Provides translated version of the type value // Added in version 2.0 static QString tr( QGis::UnitType unit ); //! Returns the conversion factor between the specified units static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit ); //! User defined event types enum UserEvent { // These first two are useful for threads to alert their parent data providers //! The extents have been calculated by a provider of a layer ProviderExtentCalcEvent = ( QEvent::User + 1 ),//计算完毕图层的延展(显示用的),可以简单的认为是缩放。 //! The row count has been calculated by a provider of a layer ProviderCountCalcEvent//这里耍了个小技巧,enum类型可以自动++。没有用过这个event }; /** Old search radius in % of canvas width * @deprecated since 2.3, use DEFAULT_SEARCH_RADIUS_MM */ static const double DEFAULT_IDENTIFY_RADIUS; /** Identify search radius in mm * @note added in 2.3 */ static const double DEFAULT_SEARCH_RADIUS_MM; //! Default threshold between map coordinates and device coordinates for map2pixel simplification static const float DEFAULT_MAPTOPIXEL_THRESHOLD; /** Default highlight color. The transparency is expected to only be applied to polygon * fill. Lines and outlines are rendered opaque. * @note added in 2.3 */ static const QColor DEFAULT_HIGHLIGHT_COLOR; /** Default highlight buffer in mm. * @note added in 2.3 */ static double DEFAULT_HIGHLIGHT_BUFFER_MM; /** Default highlight line/outline minimum width in mm. * @note added in 2.3 */ static double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM; private: // String representation of unit types (set in qgis.cpp) static const char *qgisUnitTypes[];};// hack to workaround warnings when casting void pointers// retrieved from QLibrary::resolve to function pointers.// It's assumed that this works on all systems supporting// QLibraryinline void ( *cast_to_fptr( void *p ) )(){ union { void *p; void ( *f )(); } u; u.p = p; return u.f;}//// return a string representation of a double//inline QString qgsDoubleToString( const double &a )//把double类型转换为字符串{ return QString::number( a, 'f', 17 ).remove( QRegExp( "\\.?0+$" ) );}//// compare two doubles (but allow some difference)//inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON ){ const double diff = a - b; return diff > -epsilon && diff <= epsilon;}//// compare two doubles using specified number of significant digits//inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 ){ // The most simple would be to print numbers as %.xe and compare as strings // but that is probably too costly // Then the fastest would be to set some bits directly, but little/big endian // has to be considered (maybe TODO) // Is there a better way? int aexp, bexp; double ar = frexp( a, &aexp ); double br = frexp( b, &bexp ); return aexp == bexp && qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) ) ;}bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );QString qgsVsiPrefix( QString path );/** Allocates size bytes and returns a pointer to the allocated memory. Works like C malloc() but prints debug message by QgsLogger if allocation fails. @param size size in bytes */void CORE_EXPORT *qgsMalloc( size_t size );/** Allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. Works like C calloc() but prints debug message by QgsLogger if allocation fails. @param nmemb number of elements @param size size of element in bytes */void CORE_EXPORT *qgsCalloc( size_t nmemb, size_t size );/** Frees the memory space pointed to by ptr. Works like C free(). @param ptr pointer to memory space */void CORE_EXPORT qgsFree( void *ptr );/** Wkt string that represents a geographic coord sys * @note added in 1.8 to replace GEOWkt */extern CORE_EXPORT const QString GEOWKT;extern CORE_EXPORT const QString PROJECT_SCALES;/** PROJ4 string that represents a geographic coord sys */extern CORE_EXPORT const QString GEOPROJ4;/** Magic number for a geographic coord sys in POSTGIS SRID */const long GEOSRID = 4326;/** Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id */const long GEOCRS_ID = 3452;/** Magic number for a geographic coord sys in EpsgCrsId ID format */const long GEO_EPSG_CRS_ID = 4326;/** Geographic coord sys from EPSG authority */extern CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID;/** The length of the string "+proj=" */const int PROJ_PREFIX_LEN = 6;/** The length of the string "+ellps=" */const int ELLPS_PREFIX_LEN = 7;/** The length of the string "+lat_1=" */const int LAT_PREFIX_LEN = 7;/** Magick number that determines whether a projection crsid is a system (srs.db) * or user (~/.qgis.qgis.db) defined projection. */const int USER_CRS_START_ID = 100000;//! Constant that holds the string representation for "No ellips/No CRS"// Added in version 2.0extern CORE_EXPORT const QString GEO_NONE;//// Constants for point symbols///** Magic number that determines the minimum allowable point size for point symbols */const double MINIMUM_POINT_SIZE = 0.1;/** Magic number that determines the default point size for point symbols */const double DEFAULT_POINT_SIZE = 2.0;const double DEFAULT_LINE_WIDTH = 0.26;/** default snapping tolerance for segments (@note added in 1.8) */const double DEFAULT_SEGMENT_EPSILON = 1e-8;typedef QMap<QString, QString> QgsStringMap;/** qgssize is used instead of size_t, because size_t is stdlib type, unknown * by SIP, and it would be hard to define size_t correctly in SIP. * Currently used "unsigned long long" was introduced in C++11 (2011) * but it was supported already before C++11 on common platforms. * "unsigned long long int" gives syntax error in SIP. * KEEP IN SYNC WITH qgssize defined in SIP! */typedef unsigned long long qgssize;#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)#define Q_NOWARN_DEPRECATED_PUSH \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")#define Q_NOWARN_DEPRECATED_POP \ _Pragma("GCC diagnostic pop")#elif defined(_MSC_VER)#define Q_NOWARN_DEPRECATED_PUSH \ __pragma(warning(push)) \ __pragma(warning(disable:4996))#define Q_NOWARN_DEPRECATED_POP \ __pragma(warning(pop))#else#define Q_NOWARN_DEPRECATED_PUSH#define Q_NOWARN_DEPRECATED_POP#endif// FIXME: also in qgisinterface.h#ifndef QGISEXTERN#ifdef WIN32# define QGISEXTERN extern "C" __declspec( dllexport )# ifdef _MSC_VER// do not warn about C bindings returing QString# pragma warning(disable:4190)# endif#else# define QGISEXTERN extern "C"#endif#endif#endif
0 0
- qgis源码学习3之core模块的qgis.h文件
- qgis 源码学习之core的gps模块
- qgis源码学习2之core模块的raster
- QGis provider模块的编写
- qgis
- QGIS学习之-环境搭建
- QGIS学习之-显示SVG图片
- QGIS源码编译问题
- QGIS源码编译
- Qgis打开arcgis的MDB文件
- QGIS开发之矢量图层的使用
- Qgis学习笔记系列
- qgis学习资料
- QGIS学习一
- qgis二次开发之编译
- qgis二次开发之编译
- Qgis 数据的入库
- Windows7下编译QGis源码
- android单元测试最佳实践一:android studio测试环境搭建
- 如何在android的jni线程中实现回调
- Perl 使用Frame(放置其他控件的地方)
- 项目一--新输入的数字对应结点放在链表末尾
- 【NS2】TCP相关计算
- qgis源码学习3之core模块的qgis.h文件
- UIImageView, 添加动画,滑动条Slider控件,用户交互
- C++的第一个程序:Hello World
- 飞思卡尔i.MX 6Quad Android 4.2.2的中兴和Ublox 3G驱动移植
- javascript数组操作篇:《随机获取N项》
- POJ 1769 Minimizing maximizer
- tinkphp3.2数据库操作一(函数部分)
- C#导出List数据到xml文件[附源码]
- OpenMP与C++:事半功倍地获得多线程的好处