27 #include "qgis_core.h" 36 int QgisEvent = QEvent::User + 1;
95 ARGB32_Premultiplied = 13
115 static const
double DEFAULT_SEARCH_RADIUS_MM;
118 static const
float DEFAULT_MAPTOPIXEL_THRESHOLD;
124 static const QColor DEFAULT_HIGHLIGHT_COLOR;
129 static const
double DEFAULT_HIGHLIGHT_BUFFER_MM;
134 static const
double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM;
141 static const
double SCALE_PRECISION;
147 static const
double DEFAULT_Z_COORDINATE;
154 static const
double UI_SCALE_FACTOR;
160 static const
double DEFAULT_SNAP_TOLERANCE;
173 #define cast_to_fptr(f) f 195 , mPreviousState( object->blockSignals( true ) )
200 mObject->blockSignals( mPreviousState );
208 Object *mObject =
nullptr;
233 CORE_EXPORT uint
qHash(
const QVariant &variant );
244 QString str = QString::number( a,
'f',
precision );
245 if ( str.contains( QLatin1Char(
'.' ) ) )
248 int idx = str.length() - 1;
249 while ( str.at( idx ) ==
'0' && idx > 1 )
253 if ( idx < str.length() - 1 )
254 str.truncate( str.at( idx ) ==
'.' ? idx : idx + 1 );
262 const QString str( QString::number( a,
'f',
precision ) );
263 if ( str == QLatin1String(
"-0" ) )
265 return QLatin1String(
"0" );
280 inline bool qgsDoubleNear(
double a,
double b,
double epsilon = 4 * std::numeric_limits<double>::epsilon() )
282 if ( std::isnan( a ) || std::isnan( b ) )
283 return std::isnan( a ) && std::isnan( b ) ;
285 const double diff = a - b;
286 return diff > -epsilon && diff <= epsilon;
295 inline bool qgsFloatNear(
float a,
float b,
float epsilon = 4 * FLT_EPSILON )
297 if ( std::isnan( a ) || std::isnan( b ) )
298 return std::isnan( a ) && std::isnan( b ) ;
300 const float diff = a - b;
301 return diff > -epsilon && diff <= epsilon;
307 if ( std::isnan( a ) || std::isnan( b ) )
308 return std::isnan( a ) && std::isnan( b ) ;
316 double ar = std::frexp( a, &aexp );
317 double br = std::frexp( b, &bexp );
319 return aexp == bexp &&
320 std::round( ar * std::pow( 10.0, significantDigits ) ) == std::round( br * std::pow( 10.0, significantDigits ) );
328 inline double qgsRound(
double number,
int places )
330 double m = ( number < 0.0 ) ? -1.0 : 1.0;
331 double scaleFactor = std::pow( 10.0, places );
332 return ( std::round( number * m * scaleFactor ) / scaleFactor ) * m;
361 template <
typename T>
struct QgsAddConst {
typedef const T Type; };
363 template <
typename T>
364 constexpr
typename QgsAddConst<T>::Type &as_const( T &t ) noexcept {
return t; }
366 template <
typename T>
367 void as_const(
const T && ) =
delete;
371 template<
class T>
struct _Unique_if
373 typedef std::unique_ptr<T> _Single_object;
376 template<
class T>
struct _Unique_if<T[]>
378 typedef std::unique_ptr<T[]> _Unknown_bound;
381 template<
class T,
size_t N>
struct _Unique_if<T[N]>
383 typedef void _Known_bound;
386 template<
class T,
class... Args>
387 typename _Unique_if<T>::_Single_object
388 make_unique( Args &&... args )
390 return std::unique_ptr<T>(
new T( std::forward<Args>( args )... ) );
394 typename _Unique_if<T>::_Unknown_bound
395 make_unique(
size_t n )
397 typedef typename std::remove_extent<T>::type U;
398 return std::unique_ptr<T>(
new U[n]() );
401 template<
class T,
class... Args>
402 typename _Unique_if<T>::_Known_bound
403 make_unique( Args &&... ) =
delete;
417 template<
typename... Args>
struct overload
419 template<
typename C,
typename R>
420 static constexpr
auto of( R( C::*pmf )( Args... ) ) -> decltype( pmf )
436 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
437 Q_ASSERT( metaEnum.isValid() );
438 QMap<T, QString> enumMap;
439 for (
int idx = 0; idx < metaEnum.keyCount(); ++idx )
441 const char *enumKey = metaEnum.key( idx );
442 enumMap.insert( static_cast<T>( metaEnum.keyToValue( enumKey ) ), QString( enumKey ) );
453 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
454 Q_ASSERT( metaEnum.isValid() );
455 return QString::fromUtf8( metaEnum.valueToKey( static_cast<int>( value ) ) );
465 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
466 Q_ASSERT( metaEnum.isValid() );
468 T v =
static_cast<T
>( metaEnum.keyToValue( key.toUtf8().data(), &ok ) );
528 CORE_EXPORT
bool qgsVariantEqual(
const QVariant &lhs,
const QVariant &rhs );
539 CORE_EXPORT QString
qgsVsiPrefix(
const QString &path );
567 extern CORE_EXPORT
const QString
GEOWKT;
571 extern CORE_EXPORT
const QString
GEOPROJ4;
587 extern CORE_EXPORT
const QString
GEO_NONE;
604 const int PREVIEW_JOB_DELAY_MS = 250;
607 const int MAXIMUM_LAYER_PREVIEW_TIME_MS = 250;
624 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__) 626 #define Q_NOWARN_DEPRECATED_PUSH \ 627 _Pragma("GCC diagnostic push") \ 628 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\""); 629 #define Q_NOWARN_DEPRECATED_POP \ 630 _Pragma("GCC diagnostic pop"); 631 #define Q_NOWARN_UNREACHABLE_PUSH 632 #define Q_NOWARN_UNREACHABLE_POP 634 #elif defined(_MSC_VER) 636 #define Q_NOWARN_DEPRECATED_PUSH \ 637 __pragma(warning(push)) \ 638 __pragma(warning(disable:4996)) 639 #define Q_NOWARN_DEPRECATED_POP \ 640 __pragma(warning(pop)) 641 #define Q_NOWARN_UNREACHABLE_PUSH \ 642 __pragma(warning(push)) \ 643 __pragma(warning(disable:4702)) 644 #define Q_NOWARN_UNREACHABLE_POP \ 645 __pragma(warning(pop)) 649 #define Q_NOWARN_DEPRECATED_PUSH 650 #define Q_NOWARN_DEPRECATED_POP 651 #define Q_NOWARN_UNREACHABLE_PUSH 652 #define Q_NOWARN_UNREACHABLE_POP 659 # define QGISEXTERN extern "C" __declspec( dllexport ) 662 # pragma warning(disable:4190) 665 # if defined(__GNUC__) || defined(__clang__) 666 # define QGISEXTERN extern "C" __attribute__ ((visibility ("default"))) 668 # define QGISEXTERN extern "C" 674 #if __cplusplus >= 201500 675 #define FALLTHROUGH [[fallthrough]]; 676 #elif defined(__clang__) 677 #define FALLTHROUGH [[clang::fallthrough]]; 678 #elif defined(__GNUC__) && __GNUC__ >= 7 679 #define FALLTHROUGH [[gnu::fallthrough]]; 685 #if __cplusplus >= 201703L 686 #define NODISCARD [[nodiscard]] 687 #elif defined(__clang__) 688 #define NODISCARD [[nodiscard]] 689 #elif defined(_MSC_VER) 690 #define NODISCARD // no support 691 #elif defined(__has_cpp_attribute) 692 #if __has_cpp_attribute(nodiscard) 693 #define NODISCARD [[nodiscard]] 694 #elif __has_cpp_attribute(gnu::warn_unused_result) 695 #define NODISCARD [[gnu::warn_unused_result]] 697 #define NODISCARD Q_REQUIRED_RESULT 700 #define NODISCARD Q_REQUIRED_RESULT 703 #if __cplusplus >= 201703L 704 #define MAYBE_UNUSED [[maybe_unused]] 705 #elif defined(__clang__) 706 #define MAYBE_UNUSED [[maybe_unused]] 707 #elif defined(_MSC_VER) 708 #define MAYBE_UNUSED // no support 709 #elif defined(__has_cpp_attribute) 710 #if __has_cpp_attribute(gnu::unused) 711 #define MAYBE_UNUSED [[gnu::unused]] CORE_EXPORT QString qgsVsiPrefix(const QString &path)
static const QString QGIS_VERSION
Version string.
static const char * QGIS_DEV_VERSION
The development version.
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...
QString qgsEnumValueToKey(const T &value)
Returns the value for the given key of an enum.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
DataType
Raster data types.
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...
MessageLevel
Level for messages This will be used both for message log and message bar in application.
static const int QGIS_VERSION_INT
Version number used for comparing versions using the "Check QGIS Version" function.
QMap< QString, QString > QgsStringMap
The Qgis class provides global constants for use throughout the application.
CORE_EXPORT bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
QgsSignalBlocker(Object *object)
Constructor for QgsSignalBlocker.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue)
Returns the value corresponding to the given key of an enum.
CORE_EXPORT const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Macros will not be run for this session.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
This is the class is providing tolerance value in map unit values.
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
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...
CORE_EXPORT const QString GEOPROJ4
PROJ4 string that represents a geographic coord sys.
RAII signal blocking class.
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...
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...
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/...
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.
const long GEOSRID
Magic number for a geographic coord sys in POSTGIS SRID.
static const QString QGIS_RELEASE_NAME
Release name.
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places...
bool qgsDoubleNearSig(double a, double b, int significantDigits=10)
Compare two doubles using specified number of significant digits.
const double DEFAULT_LINE_WIDTH
CORE_EXPORT const QString PROJECT_SCALES
PythonMacroMode
Authorisation to run Python Macros.
CORE_EXPORT uint qHash(const QVariant &variant)
Hash for QVariant.
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 qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
void CORE_EXPORT * qgsMalloc(size_t size)
Allocates size bytes and returns a pointer to the allocated memory.
Object * operator->()
Returns pointer to blocked QObject.
const long GEO_EPSG_CRS_ID
Magic number for a geographic coord sys in EpsgCrsId ID format.
CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
CORE_EXPORT const QString GEOWKT
Wkt string that represents a geographic coord sys.