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
132 Q_ENUM( PythonMacroMode )
138 static const
double DEFAULT_SEARCH_RADIUS_MM;
141 static const
float DEFAULT_MAPTOPIXEL_THRESHOLD;
149 static const QColor DEFAULT_HIGHLIGHT_COLOR;
155 static const
double DEFAULT_HIGHLIGHT_BUFFER_MM;
161 static const
double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM;
169 static const
double SCALE_PRECISION;
176 static const
double DEFAULT_Z_COORDINATE;
183 static const
double UI_SCALE_FACTOR;
189 static const
double DEFAULT_SNAP_TOLERANCE;
202 static QString defaultProjectScales();
209 #define cast_to_fptr(f) f
231 , mPreviousState( object->blockSignals( true ) )
236 mObject->blockSignals( mPreviousState );
244 Object *mObject =
nullptr;
269 CORE_EXPORT uint
qHash(
const QVariant &variant );
280 QString str = QString::number( a,
'f',
precision );
281 if ( str.contains( QLatin1Char(
'.' ) ) )
284 int idx = str.length() - 1;
285 while ( str.at( idx ) ==
'0' && idx > 1 )
289 if ( idx < str.length() - 1 )
290 str.truncate( str.at( idx ) ==
'.' ? idx : idx + 1 );
298 const QString str( QString::number( a,
'f',
precision ) );
299 if ( str == QLatin1String(
"-0" ) )
301 return QLatin1String(
"0" );
316 inline bool qgsDoubleNear(
double a,
double b,
double epsilon = 4 * std::numeric_limits<double>::epsilon() )
318 if ( std::isnan( a ) || std::isnan( b ) )
319 return std::isnan( a ) && std::isnan( b ) ;
321 const double diff = a - b;
322 return diff > -epsilon && diff <= epsilon;
331 inline bool qgsFloatNear(
float a,
float b,
float epsilon = 4 * FLT_EPSILON )
333 if ( std::isnan( a ) || std::isnan( b ) )
334 return std::isnan( a ) && std::isnan( b ) ;
336 const float diff = a - b;
337 return diff > -epsilon && diff <= epsilon;
343 if ( std::isnan( a ) || std::isnan( b ) )
344 return std::isnan( a ) && std::isnan( b ) ;
352 double ar = std::frexp( a, &aexp );
353 double br = std::frexp( b, &bexp );
355 return aexp == bexp &&
364 inline double qgsRound(
double number,
int places )
366 double m = ( number < 0.0 ) ? -1.0 : 1.0;
367 double scaleFactor = std::pow( 10.0, places );
368 return ( std::round( number * m * scaleFactor ) / scaleFactor ) * m;
397 template <
typename T>
struct QgsAddConst {
typedef const T Type; };
399 template <
typename T>
400 constexpr
typename QgsAddConst<T>::Type &as_const( T &t ) noexcept {
return t; }
402 template <
typename T>
403 void as_const(
const T && ) =
delete;
407 template<
class T>
struct _Unique_if
409 typedef std::unique_ptr<T> _Single_object;
412 template<
class T>
struct _Unique_if<T[]>
414 typedef std::unique_ptr<T[]> _Unknown_bound;
417 template<
class T,
size_t N>
struct _Unique_if<T[N]>
419 typedef void _Known_bound;
422 template<
class T,
class... Args>
423 typename _Unique_if<T>::_Single_object
424 make_unique( Args &&... args )
426 return std::unique_ptr<T>(
new T( std::forward<Args>( args )... ) );
430 typename _Unique_if<T>::_Unknown_bound
431 make_unique(
size_t n )
433 typedef typename std::remove_extent<T>::type U;
434 return std::unique_ptr<T>(
new U[n]() );
437 template<
class T,
class... Args>
438 typename _Unique_if<T>::_Known_bound
439 make_unique( Args &&... ) =
delete;
453 template<
typename... Args>
struct overload
455 template<
typename C,
typename R>
456 static constexpr
auto of( R( C::*pmf )( Args... ) ) -> decltype( pmf )
463 QSet<T> listToSet(
const QList<T> &list )
465 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
468 return QSet<T>( list.begin(), list.end() );
473 QList<T> setToList(
const QSet<T> &set )
475 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
478 return QList<T>( set.begin(), set.end() );
492 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
493 Q_ASSERT( metaEnum.isValid() );
494 QMap<T, QString> enumMap;
495 for (
int idx = 0; idx < metaEnum.keyCount(); ++idx )
497 const char *enumKey = metaEnum.key( idx );
498 enumMap.insert(
static_cast<T
>( metaEnum.keyToValue( enumKey ) ), QString( enumKey ) );
509 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
510 Q_ASSERT( metaEnum.isValid() );
511 return QString::fromUtf8( metaEnum.valueToKey(
static_cast<int>( value ) ) );
522 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
523 Q_ASSERT( metaEnum.isValid() );
525 T v =
static_cast<T
>( metaEnum.keyToValue( key.toUtf8().data(), &ok ) );
535 bool canConvert =
false;
536 int intValue = key.toInt( &canConvert );
537 if ( canConvert && metaEnum.valueToKey( intValue ) )
539 return static_cast<T
>( intValue );
552 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
553 Q_ASSERT( metaEnum.isValid() );
554 return QString::fromUtf8( metaEnum.valueToKeys(
static_cast<int>( value ) ) );
564 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
565 Q_ASSERT( metaEnum.isValid() );
567 T v =
static_cast<T
>( metaEnum.keysToValue( keys.toUtf8().constData(), &ok ) );
627 CORE_EXPORT
bool qgsVariantEqual(
const QVariant &lhs,
const QVariant &rhs );
644 CORE_EXPORT QString
qgsVsiPrefix(
const QString &path );
671 #define CONSTLATIN1STRING inline const QLatin1String
673 #define CONSTLATIN1STRING constexpr QLatin1String
682 #if PROJ_VERSION_MAJOR>=6
683 return QLatin1String(
684 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]] )"""
687 return QLatin1String(
688 "GEOGCS[\"WGS 84\", "
689 " DATUM[\"WGS_1984\", "
690 " SPHEROID[\"WGS 84\",6378137,298.257223563, "
691 " AUTHORITY[\"EPSG\",\"7030\"]], "
692 " TOWGS84[0,0,0,0,0,0,0], "
693 " AUTHORITY[\"EPSG\",\"6326\"]], "
694 " PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]], "
695 " UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]], "
696 " AXIS[\"Lat\",NORTH], "
697 " AXIS[\"Long\",EAST], "
698 " AUTHORITY[\"EPSG\",\"4326\"]]"
706 return QLatin1String(
"+proj=longlat +datum=WGS84 +no_defs" );
712 return QLatin1String(
"EPSG:4326" );
718 return QLatin1String(
"NONE" );
724 const int PREVIEW_JOB_DELAY_MS = 250;
727 const int MAXIMUM_LAYER_PREVIEW_TIME_MS = 250;
772 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
774 #define Q_NOWARN_DEPRECATED_PUSH \
775 _Pragma("GCC diagnostic push") \
776 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
777 #define Q_NOWARN_DEPRECATED_POP \
778 _Pragma("GCC diagnostic pop");
779 #define Q_NOWARN_UNREACHABLE_PUSH
780 #define Q_NOWARN_UNREACHABLE_POP
782 #elif defined(_MSC_VER)
784 #define Q_NOWARN_DEPRECATED_PUSH \
785 __pragma(warning(push)) \
786 __pragma(warning(disable:4996))
787 #define Q_NOWARN_DEPRECATED_POP \
788 __pragma(warning(pop))
789 #define Q_NOWARN_UNREACHABLE_PUSH \
790 __pragma(warning(push)) \
791 __pragma(warning(disable:4702))
792 #define Q_NOWARN_UNREACHABLE_POP \
793 __pragma(warning(pop))
797 #define Q_NOWARN_DEPRECATED_PUSH
798 #define Q_NOWARN_DEPRECATED_POP
799 #define Q_NOWARN_UNREACHABLE_PUSH
800 #define Q_NOWARN_UNREACHABLE_POP
807 # define QGISEXTERN extern "C" __declspec( dllexport )
810 # pragma warning(disable:4190)
813 # if defined(__GNUC__) || defined(__clang__)
814 # define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
816 # define QGISEXTERN extern "C"
822 #if __cplusplus >= 201500
823 #define FALLTHROUGH [[fallthrough]];
824 #elif defined(__clang__)
825 #define FALLTHROUGH [[clang::fallthrough]];
826 #elif defined(__GNUC__) && __GNUC__ >= 7
827 #define FALLTHROUGH [[gnu::fallthrough]];
833 #if __cplusplus >= 201703L
834 #define NODISCARD [[nodiscard]]
835 #elif defined(__clang__)
836 #define NODISCARD [[nodiscard]]
837 #elif defined(_MSC_VER)
839 #elif defined(__has_cpp_attribute)
840 #if __has_cpp_attribute(nodiscard)
841 #define NODISCARD [[nodiscard]]
842 #elif __has_cpp_attribute(gnu::warn_unused_result)
843 #define NODISCARD [[gnu::warn_unused_result]]
845 #define NODISCARD Q_REQUIRED_RESULT
848 #define NODISCARD Q_REQUIRED_RESULT
851 #if __cplusplus >= 201703L
852 #define MAYBE_UNUSED [[maybe_unused]]
853 #elif defined(__clang__)
854 #define MAYBE_UNUSED [[maybe_unused]]
855 #elif defined(_MSC_VER)
857 #elif defined(__has_cpp_attribute)
858 #if __has_cpp_attribute(gnu::unused)
859 #define MAYBE_UNUSED [[gnu::unused]]
877 QString CORE_EXPORT
geoWkt();
The Qgis class provides global constants for use throughout the application.
static const char * QGIS_DEV_VERSION
The development version.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
PythonMacroMode
Authorisation to run Python Macros.
@ NotForThisSession
Macros will not be run for this session.
DataType
Raster data types.
RAII signal blocking class.
QgsSignalBlocker(Object *object)
Constructor for QgsSignalBlocker.
Object * operator->()
Returns pointer to blocked QObject.
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.
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.
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.
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.
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.
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.
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.