QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
27 #include "qgis_core.h"
36 int QgisEvent = QEvent::User + 1;
55 static QString version();
62 static int versionInt();
69 static QString releaseName();
79 static QString devVersion();
116 ARGB32_Premultiplied = 13
131 Q_ENUM( PythonMacroMode )
137 static const
double DEFAULT_SEARCH_RADIUS_MM;
140 static const
float DEFAULT_MAPTOPIXEL_THRESHOLD;
148 static const QColor DEFAULT_HIGHLIGHT_COLOR;
154 static const
double DEFAULT_HIGHLIGHT_BUFFER_MM;
160 static const
double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM;
168 static const
double SCALE_PRECISION;
175 static const
double DEFAULT_Z_COORDINATE;
182 static const
double UI_SCALE_FACTOR;
188 static const
double DEFAULT_SNAP_TOLERANCE;
201 static QString defaultProjectScales();
208 #define cast_to_fptr(f) f
230 , mPreviousState( object->blockSignals( true ) )
235 mObject->blockSignals( mPreviousState );
243 Object *mObject =
nullptr;
268 CORE_EXPORT uint
qHash(
const QVariant &variant );
279 QString str = QString::number( a,
'f',
precision );
280 if ( str.contains( QLatin1Char(
'.' ) ) )
283 int idx = str.length() - 1;
284 while ( str.at( idx ) ==
'0' && idx > 1 )
288 if ( idx < str.length() - 1 )
289 str.truncate( str.at( idx ) ==
'.' ? idx : idx + 1 );
297 const QString str( QString::number( a,
'f',
precision ) );
298 if ( str == QLatin1String(
"-0" ) )
300 return QLatin1String(
"0" );
315 inline bool qgsDoubleNear(
double a,
double b,
double epsilon = 4 * std::numeric_limits<double>::epsilon() )
317 if ( std::isnan( a ) || std::isnan( b ) )
318 return std::isnan( a ) && std::isnan( b ) ;
320 const double diff = a - b;
321 return diff > -epsilon && diff <= epsilon;
330 inline bool qgsFloatNear(
float a,
float b,
float epsilon = 4 * FLT_EPSILON )
332 if ( std::isnan( a ) || std::isnan( b ) )
333 return std::isnan( a ) && std::isnan( b ) ;
335 const float diff = a - b;
336 return diff > -epsilon && diff <= epsilon;
342 if ( std::isnan( a ) || std::isnan( b ) )
343 return std::isnan( a ) && std::isnan( b ) ;
351 double ar = std::frexp( a, &aexp );
352 double br = std::frexp( b, &bexp );
354 return aexp == bexp &&
363 inline double qgsRound(
double number,
int places )
365 double m = ( number < 0.0 ) ? -1.0 : 1.0;
366 double scaleFactor = std::pow( 10.0, places );
367 return ( std::round( number * m * scaleFactor ) / scaleFactor ) * m;
396 template <
typename T>
struct QgsAddConst {
typedef const T Type; };
398 template <
typename T>
399 constexpr
typename QgsAddConst<T>::Type &as_const( T &t ) noexcept {
return t; }
401 template <
typename T>
402 void as_const(
const T && ) =
delete;
406 template<
class T>
struct _Unique_if
408 typedef std::unique_ptr<T> _Single_object;
411 template<
class T>
struct _Unique_if<T[]>
413 typedef std::unique_ptr<T[]> _Unknown_bound;
416 template<
class T,
size_t N>
struct _Unique_if<T[N]>
418 typedef void _Known_bound;
421 template<
class T,
class... Args>
422 typename _Unique_if<T>::_Single_object
423 make_unique( Args &&... args )
425 return std::unique_ptr<T>(
new T( std::forward<Args>( args )... ) );
429 typename _Unique_if<T>::_Unknown_bound
430 make_unique(
size_t n )
432 typedef typename std::remove_extent<T>::type U;
433 return std::unique_ptr<T>(
new U[n]() );
436 template<
class T,
class... Args>
437 typename _Unique_if<T>::_Known_bound
438 make_unique( Args &&... ) =
delete;
452 template<
typename... Args>
struct overload
454 template<
typename C,
typename R>
455 static constexpr
auto of( R( C::*pmf )( Args... ) ) -> decltype( pmf )
462 QSet<T> listToSet(
const QList<T> &list )
464 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
467 return QSet<T>( list.begin(), list.end() );
472 QList<T> setToList(
const QSet<T> &set )
474 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
477 return QList<T>( set.begin(), set.end() );
491 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
492 Q_ASSERT( metaEnum.isValid() );
493 QMap<T, QString> enumMap;
494 for (
int idx = 0; idx < metaEnum.keyCount(); ++idx )
496 const char *enumKey = metaEnum.key( idx );
497 enumMap.insert(
static_cast<T
>( metaEnum.keyToValue( enumKey ) ), QString( enumKey ) );
508 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
509 Q_ASSERT( metaEnum.isValid() );
510 return QString::fromUtf8( metaEnum.valueToKey(
static_cast<int>( value ) ) );
521 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
522 Q_ASSERT( metaEnum.isValid() );
524 T v =
static_cast<T
>( metaEnum.keyToValue( key.toUtf8().data(), &ok ) );
534 bool canConvert =
false;
535 int intValue = key.toInt( &canConvert );
536 if ( canConvert && metaEnum.valueToKey( intValue ) )
538 return static_cast<T
>( intValue );
551 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
552 Q_ASSERT( metaEnum.isValid() );
553 return QString::fromUtf8( metaEnum.valueToKeys(
static_cast<int>( value ) ) );
563 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
564 Q_ASSERT( metaEnum.isValid() );
566 T v =
static_cast<T
>( metaEnum.keysToValue( keys.toUtf8().constData(), &ok ) );
626 CORE_EXPORT
bool qgsVariantEqual(
const QVariant &lhs,
const QVariant &rhs );
643 CORE_EXPORT QString
qgsVsiPrefix(
const QString &path );
670 #define CONSTLATIN1STRING inline const QLatin1String
672 #define CONSTLATIN1STRING constexpr QLatin1String
681 #if PROJ_VERSION_MAJOR>=6
682 return QLatin1String(
683 R
"""(GEOGCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["unknown"],AREA["World"],BBOX[-90,-180,90,180]],ID["EPSG",4326]] )"""
686 return QLatin1String(
687 "GEOGCS[\"WGS 84\", "
688 " DATUM[\"WGS_1984\", "
689 " SPHEROID[\"WGS 84\",6378137,298.257223563, "
690 " AUTHORITY[\"EPSG\",\"7030\"]], "
691 " TOWGS84[0,0,0,0,0,0,0], "
692 " AUTHORITY[\"EPSG\",\"6326\"]], "
693 " PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]], "
694 " UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]], "
695 " AXIS[\"Lat\",NORTH], "
696 " AXIS[\"Long\",EAST], "
697 " AUTHORITY[\"EPSG\",\"4326\"]]"
705 return QLatin1String(
"+proj=longlat +datum=WGS84 +no_defs" );
711 return QLatin1String(
"EPSG:4326" );
717 return QLatin1String(
"NONE" );
723 const int PREVIEW_JOB_DELAY_MS = 250;
726 const int MAXIMUM_LAYER_PREVIEW_TIME_MS = 250;
771 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
773 #define Q_NOWARN_DEPRECATED_PUSH \
774 _Pragma("GCC diagnostic push") \
775 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
776 #define Q_NOWARN_DEPRECATED_POP \
777 _Pragma("GCC diagnostic pop");
778 #define Q_NOWARN_UNREACHABLE_PUSH
779 #define Q_NOWARN_UNREACHABLE_POP
781 #elif defined(_MSC_VER)
783 #define Q_NOWARN_DEPRECATED_PUSH \
784 __pragma(warning(push)) \
785 __pragma(warning(disable:4996))
786 #define Q_NOWARN_DEPRECATED_POP \
787 __pragma(warning(pop))
788 #define Q_NOWARN_UNREACHABLE_PUSH \
789 __pragma(warning(push)) \
790 __pragma(warning(disable:4702))
791 #define Q_NOWARN_UNREACHABLE_POP \
792 __pragma(warning(pop))
796 #define Q_NOWARN_DEPRECATED_PUSH
797 #define Q_NOWARN_DEPRECATED_POP
798 #define Q_NOWARN_UNREACHABLE_PUSH
799 #define Q_NOWARN_UNREACHABLE_POP
806 # define QGISEXTERN extern "C" __declspec( dllexport )
809 # pragma warning(disable:4190)
812 # if defined(__GNUC__) || defined(__clang__)
813 # define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
815 # define QGISEXTERN extern "C"
821 #if __cplusplus >= 201500
822 #define FALLTHROUGH [[fallthrough]];
823 #elif defined(__clang__)
824 #define FALLTHROUGH [[clang::fallthrough]];
825 #elif defined(__GNUC__) && __GNUC__ >= 7
826 #define FALLTHROUGH [[gnu::fallthrough]];
832 #if __cplusplus >= 201703L
833 #define NODISCARD [[nodiscard]]
834 #elif defined(__clang__)
835 #define NODISCARD [[nodiscard]]
836 #elif defined(_MSC_VER)
837 #define NODISCARD // no support
838 #elif defined(__has_cpp_attribute)
839 #if __has_cpp_attribute(nodiscard)
840 #define NODISCARD [[nodiscard]]
841 #elif __has_cpp_attribute(gnu::warn_unused_result)
842 #define NODISCARD [[gnu::warn_unused_result]]
844 #define NODISCARD Q_REQUIRED_RESULT
847 #define NODISCARD Q_REQUIRED_RESULT
850 #if __cplusplus >= 201703L
851 #define MAYBE_UNUSED [[maybe_unused]]
852 #elif defined(__clang__)
853 #define MAYBE_UNUSED [[maybe_unused]]
854 #elif defined(_MSC_VER)
855 #define MAYBE_UNUSED // no support
856 #elif defined(__has_cpp_attribute)
857 #if __has_cpp_attribute(gnu::unused)
858 #define MAYBE_UNUSED [[gnu::unused]]
876 QString CORE_EXPORT
geoWkt();
CONSTLATIN1STRING geoWkt()
Wkt string that represents a geographic coord sys.
DataType
Raster data types.
QString qgsFlagValueToKeys(const T &value)
Returns the value for the given keys of a flag.
CORE_EXPORT bool qMapLessThanKey< QVariantList >(const QVariantList &key1, const QVariantList &key2)
Compares two QVariantList values and returns whether the first is less than the second.
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/....
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
CORE_EXPORT uint qHash(const QVariant &variant)
Hash for QVariant.
QgsSignalBlocker(Object *object)
Constructor for QgsSignalBlocker.
bool qgsDoubleNearSig(double a, double b, int significantDigits=10)
Compare two doubles using specified number of significant digits.
#define CONSTLATIN1STRING
CORE_EXPORT bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
const long GEO_EPSG_CRS_ID
Magic number for a geographic coord sys in EpsgCrsId ID format.
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
RAII signal blocking class.
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
CONSTLATIN1STRING geoProj4()
PROJ4 string that represents a geographic coord sys.
@ NotForThisSession
Macros will not be run for this session.
void CORE_EXPORT qgsFree(void *ptr)
Frees the memory space pointed to by ptr.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
CORE_EXPORT qlonglong qgsPermissiveToLongLong(QString string, bool &ok)
Converts a string to an qlonglong in a permissive way, e.g., allowing for incorrect numbers of digits...
CORE_EXPORT QString qgsVsiPrefix(const QString &path)
bool qgsFloatNear(float a, float b, float epsilon=4 *FLT_EPSILON)
Compare two floats (but allow some difference)
CORE_EXPORT bool qgsVariantEqual(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether they are equal, two NULL values are always treated a...
const QMap< T, QString > qgsEnumMap()
Returns a map of all enum entries.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
CONSTLATIN1STRING geoNone()
Constant that holds the string representation for "No ellips/No CRS".
const long GEOSRID
Magic number for a geographic coord sys in POSTGIS SRID.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
const double DEFAULT_LINE_WIDTH
Object * operator->()
Returns pointer to blocked QObject.
CORE_EXPORT bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
static const char * QGIS_DEV_VERSION
The development version.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true)
Returns the value corresponding to the given key of an enum.
CORE_EXPORT int qgsPermissiveToInt(QString string, bool &ok)
Converts a string to an integer in a permissive way, e.g., allowing for incorrect numbers of digits b...
QMap< QString, QString > QgsStringMap
MessageLevel
Level for messages This will be used both for message log and message bar in application.
This is the class is providing tolerance value in map unit values.
int significantDigits(const Qgis::DataType rasterDataType)
Returns the maximum number of significant digits a for the given rasterDataType.
CORE_EXPORT double qgsPermissiveToDouble(QString string, bool &ok)
Converts a string to a double in a permissive way, e.g., allowing for incorrect numbers of digits bet...
void CORE_EXPORT * qgsMalloc(size_t size)
Allocates size bytes and returns a pointer to the allocated memory.
The Qgis class provides global constants for use throughout the application.
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...
QString qgsEnumValueToKey(const T &value)
Returns the value for the given key of an enum.
T qgsFlagKeysToValue(const QString &keys, const T &defaultValue)
Returns the value corresponding to the given keys of a flag.
PythonMacroMode
Authorisation to run Python Macros.
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...