QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgscommandlineutils.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgscommandlineutils.cpp
3 ---------------------------
4 begin : June 2021
5 copyright : (C) 2021 by Etienne Trimaille
6 email : etienne dot trimaille at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsapplication.h"
19#include "qgscommandlineutils.h"
20#include "qgsgeos.h"
21#include "qgsprojutils.h"
22#include "qgsversion.h"
23
24#include <sqlite3.h>
25#include <ogr_api.h>
26#include <gdal_version.h>
27#include <proj.h>
28#include <QSysInfo>
29
31{
32
33 // QGIS main version
34 QString versionString = QStringLiteral( "QGIS %1 '%2' (%3)\n" ).arg( VERSION, RELEASE_NAME, QGSVERSION );
35
36 // QGIS code revision
37 if ( QString( Qgis::devVersion() ) == QLatin1String( "exported" ) )
38 {
39 versionString += QLatin1String( "QGIS code branch" );
40 if ( Qgis::version().endsWith( QLatin1String( "Master" ) ) )
41 {
42 versionString += QLatin1String( "master\n" );
43 }
44 else
45 {
46 versionString += QStringLiteral( "Release %1.%2\n" ).arg( Qgis::versionInt() / 10000 ).arg( Qgis::versionInt() / 100 % 100 );
47 }
48 }
49 else
50 {
51 versionString += QStringLiteral( "QGIS code revision %1\n" ).arg( Qgis::devVersion() );
52 }
53
54 // Qt version
55 const QString qtVersionCompiled{ QT_VERSION_STR };
56 const QString qtVersionRunning{ qVersion() };
57 if ( qtVersionCompiled != qtVersionRunning )
58 {
59 versionString += QStringLiteral( "Compiled against Qt %1\n" ).arg( qtVersionCompiled );
60 versionString += QStringLiteral( "Running against Qt %1\n" ).arg( qtVersionRunning );
61 }
62 else
63 {
64 versionString += QStringLiteral( "Qt version %1\n" ).arg( qtVersionCompiled );
65 }
66
67 // Python version
68 versionString += QStringLiteral( "Python version %1\n" ).arg( PYTHON_VERSION );
69
70 // GDAL version
71 const QString gdalVersionCompiled { GDAL_RELEASE_NAME };
72 const QString gdalVersionRunning { GDALVersionInfo( "RELEASE_NAME" ) };
73 if ( gdalVersionCompiled != gdalVersionRunning )
74 {
75 versionString += QStringLiteral( "Compiled against GDAL/OGR %1\n" ).arg( gdalVersionCompiled );
76 versionString += QStringLiteral( "Running against GDAL/OGR %1\n" ).arg( gdalVersionRunning );
77 }
78 else
79 {
80 versionString += QStringLiteral( "GDAL/OGR version %1\n" ).arg( gdalVersionCompiled );
81 }
82
83 // proj
84 const PJ_INFO info = proj_info();
85 const QString projVersionCompiled { QStringLiteral( "%1.%2.%3" ).arg( PROJ_VERSION_MAJOR ).arg( PROJ_VERSION_MINOR ).arg( PROJ_VERSION_PATCH ) };
86 const QString projVersionRunning { info.version };
87 if ( projVersionCompiled != projVersionRunning )
88 {
89 versionString += QStringLiteral( "Compiled against PROJ %1\n" ).arg( projVersionCompiled );
90 versionString += QStringLiteral( "Running against PROJ %2\n" ).arg( projVersionRunning );
91 }
92 else
93 {
94 versionString += QStringLiteral( "PROJ version %1\n" ).arg( projVersionCompiled );
95 }
96
97 // CRS database versions
98 versionString += QStringLiteral( "EPSG Registry database version %1 (%2)\n" ).arg( QgsProjUtils::epsgRegistryVersion(), QgsProjUtils::epsgRegistryDate().toString( Qt::ISODate ) );
99
100 // GEOS version
101 const QString geosVersionCompiled { GEOS_CAPI_VERSION };
102 const QString geosVersionRunning { GEOSversion() };
103 if ( geosVersionCompiled != geosVersionRunning )
104 {
105 versionString += QStringLiteral( "Compiled against GEOS %1\n" ).arg( geosVersionCompiled );
106 versionString += QStringLiteral( "Running against GEOS %1\n" ).arg( geosVersionRunning );
107 }
108 else
109 {
110 versionString += QStringLiteral( "GEOS version %1\n" ).arg( geosVersionCompiled );
111 }
112
113 // SQLite version
114 const QString sqliteVersionCompiled { SQLITE_VERSION };
115 const QString sqliteVersionRunning { sqlite3_libversion() };
116 if ( sqliteVersionCompiled != sqliteVersionRunning )
117 {
118 versionString += QStringLiteral( "Compiled against SQLite %1\n" ).arg( sqliteVersionCompiled );
119 versionString += QStringLiteral( "Running against SQLite %1\n" ).arg( sqliteVersionRunning );
120 }
121 else
122 {
123 versionString += QStringLiteral( "SQLite version %1\n" ).arg( sqliteVersionCompiled );
124 }
125
126 // Operating system
127 versionString += QStringLiteral( "OS %1\n" ).arg( QSysInfo::prettyProductName() );
128
129#ifdef QGISDEBUG
130 versionString += QLatin1String( "This copy of QGIS writes debugging output.\n" );
131#endif
132
133 return versionString;
134}
static QString version()
Version string.
Definition: qgis.cpp:277
static QString devVersion()
The development version.
Definition: qgis.cpp:294
static int versionInt()
Version number used for comparing versions using the "Check QGIS Version" function.
Definition: qgis.cpp:282
static QString allVersions()
Display all versions in the standard output stream.
static QDate epsgRegistryDate()
Returns the EPSG registry database release date used by the proj library.
static QString epsgRegistryVersion()
Returns the EPSG registry database version used by the proj library (e.g.