27 #include "qgis_core.h"
36 int QgisEvent = QEvent::User + 1;
71 static QString version();
78 static int versionInt();
85 static QString releaseName();
95 static QString devVersion();
112 Q_ENUM( MessageLevel )
133 ARGB32_Premultiplied = 13
149 Q_ENUM( PythonMacroMode )
161 Q_ENUM( FeatureCountState )
186 Q_ENUM( ScaleMethod )
197 Q_ENUM( SymbolRenderHint )
198 Q_DECLARE_FLAGS( SymbolRenderHints, SymbolRenderHint )
207 RendererShouldUseSymbolLevels = 1 << 0,
210 Q_DECLARE_FLAGS( SymbolFlags, SymbolFlag )
219 FlagIncludeCrosshairsForMarkerSymbols = 1 << 0,
221 Q_ENUM( SymbolPreviewFlag )
222 Q_DECLARE_FLAGS( SymbolPreviewFlags, SymbolPreviewFlag )
241 Q_ENUM( BrowserItemType )
254 Q_ENUM( BrowserItemState )
271 Q_ENUM( BrowserItemCapability )
272 Q_DECLARE_FLAGS( BrowserItemCapabilities, BrowserItemCapability )
295 Q_ENUM( BrowserLayerType )
308 Q_ENUM( BrowserDirectoryMonitoring )
330 Q_ENUM( VectorExportResult )
358 Q_ENUM( UnplacedLabelVisibility )
364 static const
double DEFAULT_SEARCH_RADIUS_MM;
367 static const
float DEFAULT_MAPTOPIXEL_THRESHOLD;
375 static const QColor DEFAULT_HIGHLIGHT_COLOR;
381 static const
double DEFAULT_HIGHLIGHT_BUFFER_MM;
387 static const
double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM;
395 static const
double SCALE_PRECISION;
402 static const
double DEFAULT_Z_COORDINATE;
409 static const
double DEFAULT_M_COORDINATE;
416 static const
double UI_SCALE_FACTOR;
422 static const
double DEFAULT_SNAP_TOLERANCE;
435 static QString defaultProjectScales();
442 static
int geosVersionInt();
449 static
int geosVersionMajor();
456 static
int geosVersionMinor();
463 static
int geosVersionPatch();
470 static QString geosVersion();
483 #define cast_to_fptr(f) f
505 , mPreviousState( object->blockSignals( true ) )
510 mObject->blockSignals( mPreviousState );
518 Object *mObject =
nullptr;
543 CORE_EXPORT uint
qHash(
const QVariant &variant );
555 if (
str.contains( QLatin1Char(
'.' ) ) )
558 int idx =
str.length() - 1;
559 while (
str.at( idx ) ==
'0' && idx > 1 )
563 if ( idx <
str.length() - 1 )
564 str.truncate(
str.at( idx ) ==
'.' ? idx : idx + 1 );
569 if (
str == QLatin1String(
"-0" ) )
571 return QLatin1String(
"0" );
584 const bool aIsNan = std::isnan( a );
585 const bool bIsNan = std::isnan( b );
586 if ( aIsNan || bIsNan )
587 return aIsNan && bIsNan;
598 inline bool qgsDoubleNear(
double a,
double b,
double epsilon = 4 * std::numeric_limits<double>::epsilon() )
600 const bool aIsNan = std::isnan( a );
601 const bool bIsNan = std::isnan( b );
602 if ( aIsNan || bIsNan )
603 return aIsNan && bIsNan;
605 const double diff = a - b;
606 return diff > -epsilon && diff <= epsilon;
615 inline bool qgsFloatNear(
float a,
float b,
float epsilon = 4 * FLT_EPSILON )
617 const bool aIsNan = std::isnan( a );
618 const bool bIsNan = std::isnan( b );
619 if ( aIsNan || bIsNan )
620 return aIsNan && bIsNan;
622 const float diff = a - b;
623 return diff > -epsilon && diff <= epsilon;
629 const bool aIsNan = std::isnan( a );
630 const bool bIsNan = std::isnan( b );
631 if ( aIsNan || bIsNan )
632 return aIsNan && bIsNan;
640 double ar = std::frexp( a, &aexp );
641 double br = std::frexp( b, &bexp );
643 return aexp == bexp &&
652 inline double qgsRound(
double number,
int places )
654 double m = ( number < 0.0 ) ? -1.0 : 1.0;
655 double scaleFactor = std::pow( 10.0, places );
656 return ( std::round( number * m * scaleFactor ) / scaleFactor ) * m;
688 template<
typename To,
typename From>
inline To down_cast( From *f )
691 ( std::is_base_of<From,
692 typename std::remove_pointer<To>::type>::value ),
693 "target type not derived from source type" );
694 Q_ASSERT( f ==
nullptr ||
dynamic_cast<To
>( f ) !=
nullptr );
695 return static_cast<To
>( f );
699 QSet<T> listToSet(
const QList<T> &list )
701 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
704 return QSet<T>( list.begin(), list.end() );
709 QList<T> setToList(
const QSet<T> &set )
711 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
714 return QList<T>( set.begin(), set.end() );
728 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
729 Q_ASSERT( metaEnum.isValid() );
730 QMap<T, QString> enumMap;
731 for (
int idx = 0; idx < metaEnum.keyCount(); ++idx )
733 const char *enumKey = metaEnum.key( idx );
734 enumMap.insert(
static_cast<T
>( metaEnum.keyToValue( enumKey ) ), QString( enumKey ) );
745 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
746 Q_ASSERT( metaEnum.isValid() );
747 return QString::fromUtf8( metaEnum.valueToKey(
static_cast<int>( value ) ) );
758 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
759 Q_ASSERT( metaEnum.isValid() );
761 T v =
static_cast<T
>( metaEnum.keyToValue( key.toUtf8().data(), &ok ) );
771 bool canConvert =
false;
772 int intValue = key.toInt( &canConvert );
773 if ( canConvert && metaEnum.valueToKey( intValue ) )
775 return static_cast<T
>( intValue );
788 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
789 Q_ASSERT( metaEnum.isValid() );
790 return QString::fromUtf8( metaEnum.valueToKeys(
static_cast<int>( value ) ) );
800 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
801 Q_ASSERT( metaEnum.isValid() );
803 T v =
static_cast<T
>( metaEnum.keysToValue( keys.toUtf8().constData(), &ok ) );
863 CORE_EXPORT
bool qgsVariantEqual(
const QVariant &lhs,
const QVariant &rhs );
873 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
881 inline bool operator> (
const QVariant &v1,
const QVariant &v2 )
895 inline bool operator< (
const QVariant &v1,
const QVariant &v2 )
902 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
907 template<> CORE_EXPORT
bool qMapLessThanKey<QVariantList>(
const QVariantList &key1,
const QVariantList &key2 )
SIP_SKIP;
910 CORE_EXPORT QString
qgsVsiPrefix(
const QString &path );
937 #define CONSTLATIN1STRING inline const QLatin1String
939 #define CONSTLATIN1STRING constexpr QLatin1String
943 class ScopedIntIncrementor
947 ScopedIntIncrementor(
int *variable )
948 : mVariable( variable )
953 ScopedIntIncrementor(
const ScopedIntIncrementor &other ) =
delete;
954 ScopedIntIncrementor &operator=(
const ScopedIntIncrementor &other ) =
delete;
964 ~ScopedIntIncrementor()
970 int *mVariable =
nullptr;
980 return QLatin1String(
981 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]] )"""
988 return QLatin1String(
"+proj=longlat +datum=WGS84 +no_defs" );
994 return QLatin1String(
"EPSG:4326" );
1000 return QLatin1String(
"NONE" );
1006 const int PREVIEW_JOB_DELAY_MS = 250;
1009 const int MAXIMUM_LAYER_PREVIEW_TIME_MS = 250;
1054 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
1056 #define Q_NOWARN_DEPRECATED_PUSH \
1057 _Pragma("GCC diagnostic push") \
1058 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
1059 #define Q_NOWARN_DEPRECATED_POP \
1060 _Pragma("GCC diagnostic pop");
1061 #define Q_NOWARN_UNREACHABLE_PUSH
1062 #define Q_NOWARN_UNREACHABLE_POP
1064 #elif defined(_MSC_VER)
1066 #define Q_NOWARN_DEPRECATED_PUSH \
1067 __pragma(warning(push)) \
1068 __pragma(warning(disable:4996))
1069 #define Q_NOWARN_DEPRECATED_POP \
1070 __pragma(warning(pop))
1071 #define Q_NOWARN_UNREACHABLE_PUSH \
1072 __pragma(warning(push)) \
1073 __pragma(warning(disable:4702))
1074 #define Q_NOWARN_UNREACHABLE_POP \
1075 __pragma(warning(pop))
1079 #define Q_NOWARN_DEPRECATED_PUSH
1080 #define Q_NOWARN_DEPRECATED_POP
1081 #define Q_NOWARN_UNREACHABLE_PUSH
1082 #define Q_NOWARN_UNREACHABLE_POP
1089 # define QGISEXTERN extern "C" __declspec( dllexport )
1092 # pragma warning(disable:4190)
1095 # if defined(__GNUC__) || defined(__clang__)
1096 # define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
1098 # define QGISEXTERN extern "C"
1104 #if __cplusplus >= 201500
1105 #define FALLTHROUGH [[fallthrough]];
1106 #elif defined(__clang__)
1107 #define FALLTHROUGH [[clang::fallthrough]];
1108 #elif defined(__GNUC__) && __GNUC__ >= 7
1109 #define FALLTHROUGH [[gnu::fallthrough]];
1115 #if __cplusplus >= 201703L
1116 #define NODISCARD [[nodiscard]]
1117 #elif defined(__clang__)
1118 #define NODISCARD [[nodiscard]]
1119 #elif defined(_MSC_VER)
1121 #elif defined(__has_cpp_attribute)
1122 #if __has_cpp_attribute(nodiscard)
1123 #define NODISCARD [[nodiscard]]
1124 #elif __has_cpp_attribute(gnu::warn_unused_result)
1125 #define NODISCARD [[gnu::warn_unused_result]]
1127 #define NODISCARD Q_REQUIRED_RESULT
1130 #define NODISCARD Q_REQUIRED_RESULT
1133 #if __cplusplus >= 201703L
1134 #define MAYBE_UNUSED [[maybe_unused]]
1135 #elif defined(__clang__)
1136 #define MAYBE_UNUSED [[maybe_unused]]
1137 #elif defined(_MSC_VER)
1138 #define MAYBE_UNUSED
1139 #elif defined(__has_cpp_attribute)
1140 #if __has_cpp_attribute(gnu::unused)
1141 #define MAYBE_UNUSED [[gnu::unused]]
1143 #define MAYBE_UNUSED
1146 #define MAYBE_UNUSED
1154 #if defined(__GNUC__) && !defined(__clang__)
1165 #define DEFAULT_BUILTIN_UNREACHABLE \
1167 __builtin_unreachable();
1169 #define DEFAULT_BUILTIN_UNREACHABLE
1179 QString CORE_EXPORT
geoWkt();
1188 QString CORE_EXPORT
geoNone();
The Qgis class provides global constants for use throughout the application.
static const char * QGIS_DEV_VERSION
The development version.
BrowserItemState
Browser item states.
SymbolRenderHint
Flags controlling behavior of symbols during rendering.
BrowserItemCapability
Browser item capabilities.
BrowserDirectoryMonitoring
Browser directory item monitoring switches.
VectorExportResult
Vector layer export result codes.
ScaleMethod
Scale methods.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
PythonMacroMode
Authorisation to run Python Macros.
UnplacedLabelVisibility
Unplaced label visibility.
BrowserItemType
Browser item types.
BrowserLayerType
Browser item layer types.
DataType
Raster data types.
SymbolPreviewFlag
Flags for controlling how symbol preview images are generated.
SymbolFlag
Flags controlling behavior of symbols.
Base class for all items in the model.
Item that represents a layer that can be opened with one of the providers.
Base class for all map layer types.
RAII signal blocking class.
QgsSignalBlocker(Object *object)
Constructor for QgsSignalBlocker.
Object * operator->()
Returns pointer to blocked QObject.
Abstract base class for all rendered symbols.
This is the class is providing tolerance value in map unit values.
This is the base class for vector data providers.
A convenience class for exporting vector layers to a destination data provider.
FeatureCountState
Enumeration of feature count states.
QgsMapLayerType
Types of layers that can be added to a map.
@ PointCloudLayer
Added in 3.18.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
int significantDigits(const Qgis::DataType rasterDataType)
Returns the maximum number of significant digits a for the given rasterDataType.
CONSTLATIN1STRING geoNone()
Constant that holds the string representation for "No ellips/No CRS".
const double DEFAULT_LINE_WIDTH
CORE_EXPORT uint qHash(const QVariant &variant)
Hash for QVariant.
bool operator>(const QVariant &v1, const QVariant &v2)
Compares two QVariant values and returns whether the first is greater than the second.
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...
CORE_EXPORT QString qgsVsiPrefix(const QString &path)
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...
void CORE_EXPORT * qgsMalloc(size_t size)
Allocates size bytes and returns a pointer to the allocated memory.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value)
Returns the value for the given key of an enum.
const QMap< T, QString > qgsEnumMap()
Returns a map of all enum entries.
const long GEO_EPSG_CRS_ID
Magic number for a geographic coord sys in EpsgCrsId ID format.
CORE_EXPORT bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
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...
bool qgsFloatNear(float a, float b, float epsilon=4 *FLT_EPSILON)
Compare two floats (but allow some difference)
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...
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
CONSTLATIN1STRING geoProj4()
PROJ4 string that represents a geographic coord sys.
T qgsFlagKeysToValue(const QString &keys, const T &defaultValue)
Returns the value corresponding to the given keys of a flag.
bool qgsNanCompatibleEquals(double a, double b)
Compare two doubles, treating nan values as equal.
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
QMap< QString, QString > QgsStringMap
#define CONSTLATIN1STRING
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
CONSTLATIN1STRING geoWkt()
Wkt string that represents a geographic coord sys.
bool qgsDoubleNearSig(double a, double b, int significantDigits=10)
Compare two doubles using specified number of significant digits.
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/....
QString qgsFlagValueToKeys(const T &value)
Returns the value for the given keys of a flag.
void CORE_EXPORT qgsFree(void *ptr)
Frees the memory space pointed to by ptr.
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 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...
CORE_EXPORT bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
const long GEOSRID
Magic number for a geographic coord sys in POSTGIS SRID.
bool operator<(const QVariant &v1, const QVariant &v2)
Compares two QVariant values and returns whether the first is less than the second.
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true)
Returns the value corresponding to the given key of an enum.
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.