20 #include "qgsversion.h"
22 #include <QCoreApplication>
28 #include "qgsconfig.h"
36 #define xstr(x) str(x)
74 string.remove( QLocale().groupSeparator() );
75 return QLocale().toDouble(
string, &ok );
81 string.remove( QLocale().groupSeparator() );
82 return QLocale().toInt(
string, &ok );
88 string.remove( QLocale().groupSeparator() );
89 return QLocale().toLongLong(
string, &ok );
94 if ( size == 0 ||
long( size ) < 0 )
96 QgsDebugMsg( QStringLiteral(
"Negative or zero size %1." ).arg( size ) );
99 void *p = malloc( size );
102 QgsDebugMsg( QStringLiteral(
"Allocation of %1 bytes failed." ).arg( size ) );
109 if ( nmemb == 0 ||
long( nmemb ) < 0 || size == 0 ||
long( size ) < 0 )
111 QgsDebugMsg( QStringLiteral(
"Negative or zero nmemb %1 or size %2." ).arg( nmemb ).arg( size ) );
117 memset( p, 0, nmemb * size );
130 if ( !lhs.isValid() )
131 return rhs.isValid();
132 else if ( lhs.isNull() )
133 return rhs.isValid() && !rhs.isNull();
134 else if ( !rhs.isValid() || rhs.isNull() )
137 switch ( lhs.type() )
140 return lhs.toInt() < rhs.toInt();
142 return lhs.toUInt() < rhs.toUInt();
143 case QVariant::LongLong:
144 return lhs.toLongLong() < rhs.toLongLong();
145 case QVariant::ULongLong:
146 return lhs.toULongLong() < rhs.toULongLong();
147 case QVariant::Double:
148 return lhs.toDouble() < rhs.toDouble();
150 return lhs.toChar() < rhs.toChar();
152 return lhs.toDate() < rhs.toDate();
154 return lhs.toTime() < rhs.toTime();
155 case QVariant::DateTime:
156 return lhs.toDateTime() < rhs.toDateTime();
158 return lhs.toBool() < rhs.toBool();
162 const QList<QVariant> &lhsl = lhs.toList();
163 const QList<QVariant> &rhsl = rhs.toList();
165 int i, n = std::min( lhsl.size(), rhsl.size() );
166 for ( i = 0; i < n && lhsl[i].type() == rhsl[i].type() &&
qgsVariantEqual( lhsl[i], rhsl[i] ); i++ )
170 return lhsl.size() < rhsl.size();
175 case QVariant::StringList:
177 const QStringList &lhsl = lhs.toStringList();
178 const QStringList &rhsl = rhs.toStringList();
180 int i, n = std::min( lhsl.size(), rhsl.size() );
181 for ( i = 0; i < n && lhsl[i] == rhsl[i]; i++ )
185 return lhsl.size() < rhsl.size();
187 return lhsl[i] < rhsl[i];
191 return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
202 if ( path.startsWith( QLatin1String(
"/vsizip/" ), Qt::CaseInsensitive ) )
203 return QStringLiteral(
"/vsizip/" );
204 else if ( path.endsWith( QLatin1String(
".shp.zip" ), Qt::CaseInsensitive ) )
207 if ( GDALIdentifyDriverEx( path.toUtf8().constData(), GDAL_OF_VECTOR,
nullptr,
nullptr ) )
209 return QStringLiteral(
"/vsizip/" );
211 else if ( path.endsWith( QLatin1String(
".zip" ), Qt::CaseInsensitive ) )
212 return QStringLiteral(
"/vsizip/" );
213 else if ( path.startsWith( QLatin1String(
"/vsitar/" ), Qt::CaseInsensitive ) ||
214 path.endsWith( QLatin1String(
".tar" ), Qt::CaseInsensitive ) ||
215 path.endsWith( QLatin1String(
".tar.gz" ), Qt::CaseInsensitive ) ||
216 path.endsWith( QLatin1String(
".tgz" ), Qt::CaseInsensitive ) )
217 return QStringLiteral(
"/vsitar/" );
218 else if ( path.startsWith( QLatin1String(
"/vsigzip/" ), Qt::CaseInsensitive ) ||
219 path.endsWith( QLatin1String(
".gz" ), Qt::CaseInsensitive ) )
220 return QStringLiteral(
"/vsigzip/" );
225 uint
qHash(
const QVariant &variant )
227 if ( !variant.isValid() || variant.isNull() )
228 return std::numeric_limits<uint>::max();
230 switch ( variant.type() )
233 return qHash( variant.toInt() );
235 return qHash( variant.toUInt() );
237 return qHash( variant.toBool() );
238 case QVariant::Double:
239 return qHash( variant.toDouble() );
240 case QVariant::LongLong:
241 return qHash( variant.toLongLong() );
242 case QVariant::ULongLong:
243 return qHash( variant.toULongLong() );
244 case QVariant::String:
245 return qHash( variant.toString() );
247 return qHash( variant.toChar() );
249 return qHash( variant.toList() );
250 case QVariant::StringList:
251 return qHash( variant.toStringList() );
252 case QVariant::ByteArray:
253 return qHash( variant.toByteArray() );
255 return qHash( variant.toDate() );
257 return qHash( variant.toTime() );
258 case QVariant::DateTime:
259 return qHash( variant.toDateTime() );
261 case QVariant::Locale:
262 case QVariant::RegularExpression:
263 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
264 case QVariant::RegExp:
266 return qHash( variant.toString() );
271 return std::numeric_limits<uint>::max();
276 return ( lhs.isNull() == rhs.isNull() && lhs == rhs ) || ( lhs.isNull() && rhs.isNull() && lhs.isValid() && rhs.isValid() );
281 return QStringLiteral(
"1:1000000,1:500000,1:250000,1:100000,1:50000,1:25000,"
282 "1:10000,1:5000,1:2500,1:1000,1:500" );
287 return QString::fromUtf8( VERSION );
299 return QString::fromUtf8( RELEASE_NAME );
309 return GEOSversion();
314 static const int version = QStringLiteral(
"%1%2%3" )
315 .arg( GEOS_VERSION_MAJOR, 2, 10, QChar(
'0' ) )
316 .arg( GEOS_VERSION_MINOR, 2, 10, QChar(
'0' ) )
324 return GEOS_VERSION_MAJOR;
329 return GEOS_VERSION_MINOR;
334 static const int version = atoi(
xstr( GEOS_VERSION_PATCH ) );
338 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
340 bool qMapLessThanKey<QVariantList>(
const QVariantList &key1,
const QVariantList &key2 )
static const double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM
Default highlight line/stroke minimum width in mm.
static QString version()
Version string.
static const double DEFAULT_Z_COORDINATE
Default Z coordinate value.
static const char * QGIS_DEV_VERSION
The development version.
static QString geosVersion()
GEOS string version linked.
static const double DEFAULT_SNAP_TOLERANCE
Default snapping distance tolerance.
static const QgsTolerance::UnitType DEFAULT_SNAP_UNITS
Default snapping distance units.
static const double DEFAULT_M_COORDINATE
Default M coordinate value.
static const double DEFAULT_HIGHLIGHT_BUFFER_MM
Default highlight buffer in mm.
static int geosVersionPatch()
GEOS Patch version number linked.
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
static const double SCALE_PRECISION
Fudge factor used to compare two scales.
static QString devVersion()
The development version.
static QString releaseName()
Release name.
static QString defaultProjectScales()
A string with default project scales.
static const float DEFAULT_MAPTOPIXEL_THRESHOLD
Default threshold between map coordinates and device coordinates for map2pixel simplification.
static int geosVersionMajor()
GEOS Major version number linked.
static const double DEFAULT_SEARCH_RADIUS_MM
Identify search radius in mm.
static int versionInt()
Version number used for comparing versions using the "Check QGIS Version" function.
static int geosVersionMinor()
GEOS Minor version number linked.
static int geosVersionInt()
GEOS version number linked.
static const double UI_SCALE_FACTOR
UI scaling factor.
UnitType
Type of unit of tolerance value from settings.
@ Pixels
Pixels unit of tolerance.
qlonglong qgsPermissiveToLongLong(QString string, bool &ok)
Converts a string to an qlonglong in a permissive way, e.g., allowing for incorrect numbers of digits...
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...
uint qHash(const QVariant &variant)
Hash for QVariant.
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...
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...
void qgsFree(void *ptr)
Frees the memory space pointed to by ptr.
QString qgsVsiPrefix(const QString &path)
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
void * 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...
void * qgsMalloc(size_t size)
Allocates size bytes and returns a pointer to the allocated memory.
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.