@@ -38,41 +38,44 @@ bool SHPFileHelper::_validateSHPFiles(const QString &shpFile, int *utmZone, bool
3838 errorString.clear ();
3939
4040 if (!shpFile.endsWith (QStringLiteral (" .shp" ))) {
41- errorString = QString (_errorPrefix).arg (QObject::tr (" File is not a .shp file: %1" ).arg (shpFile));
41+ errorString = QString (_errorPrefix).arg (QString (QT_TRANSLATE_NOOP (" SHP" , " File is not a .shp file: %1" )).arg (shpFile));
42+ return false ;
4243 }
4344
4445 const QString prjFilename = shpFile.left (shpFile.length () - 4 ) + QStringLiteral (" .prj" );
4546 QFile prjFile (prjFilename);
4647 if (!prjFile.exists ()) {
47- errorString = QString (_errorPrefix).arg (QObject::tr (" File not found: %1" ).arg (prjFilename));
48+ errorString = QString (_errorPrefix).arg (QString (QT_TRANSLATE_NOOP (" SHP" , " File not found: %1" )).arg (prjFilename));
49+ return false ;
4850 }
4951
5052 if (!prjFile.open (QIODevice::ReadOnly | QIODevice::Text)) {
51- errorString = QString (_errorPrefix).arg (QObject::tr (" PRJ file open failed: %1" ), prjFile.errorString ());
53+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP (" SHP" , " PRJ file open failed: %1" ), prjFile.errorString ());
54+ return false ;
5255 }
5356
5457 QTextStream strm (&prjFile);
5558 const QString line = strm.readLine ();
5659 if (line.startsWith (QStringLiteral (" GEOGCS[\" GCS_WGS_1984\" ," ))) {
5760 *utmZone = 0 ;
5861 *utmSouthernHemisphere = false ;
59- } else if (!line.startsWith (QStringLiteral (" PROJCS[\" WGS_1984_UTM_Zone_" ))) {
60- errorString = QString (_errorPrefix).arg (QObject::tr (" Only WGS84 or UTM projections are supported." ));
61- }
62-
63- static QRegularExpression regEx (QStringLiteral (" ^PROJCS\\ [\" WGS_1984_UTM_Zone_(\\ d+){1,2}([NS]{1})" ));
64- const QRegularExpressionMatch regExMatch = regEx.match (line);
65- const QStringList rgCapture = regExMatch.capturedTexts ();
66- if (rgCapture.count () == 3 ) {
67- const int zone = rgCapture[1 ].toInt ();
68- if ((zone >= 1 ) && (zone <= 60 )) {
69- *utmZone = zone;
70- *utmSouthernHemisphere = (rgCapture[2 ] == QStringLiteral (" S" ));
62+ } else if (line.startsWith (QStringLiteral (" PROJCS[\" WGS_1984_UTM_Zone_" ))) {
63+ static QRegularExpression regEx (QStringLiteral (" ^PROJCS\\ [\" WGS_1984_UTM_Zone_(\\ d+){1,2}([NS]{1})" ));
64+ const QRegularExpressionMatch regExMatch = regEx.match (line);
65+ const QStringList rgCapture = regExMatch.capturedTexts ();
66+ if (rgCapture.count () == 3 ) {
67+ const int zone = rgCapture[1 ].toInt ();
68+ if ((zone >= 1 ) && (zone <= 60 )) {
69+ *utmZone = zone;
70+ *utmSouthernHemisphere = (rgCapture[2 ] == QStringLiteral (" S" ));
71+ }
7172 }
72- }
7373
74- if (*utmZone == 0 ) {
75- errorString = QString (_errorPrefix).arg (QObject::tr (" UTM projection is not in supported format. Must be PROJCS[\" WGS_1984_UTM_Zone_##N/S" ));
74+ if (*utmZone == 0 ) {
75+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP (" SHP" , " UTM projection is not in supported format. Must be PROJCS[\" WGS_1984_UTM_Zone_##N/S" ));
76+ }
77+ } else {
78+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP (" SHP" , " Only WGS84 or UTM projections are supported." ));
7679 }
7780
7881 return errorString.isEmpty ();
@@ -81,14 +84,14 @@ bool SHPFileHelper::_validateSHPFiles(const QString &shpFile, int *utmZone, bool
8184
8285SHPHandle SHPFileHelper::_loadShape (const QString &shpFile, int *utmZone, bool *utmSouthernHemisphere, QString &errorString)
8386{
84- SHPHandle shpHandle = Q_NULLPTR ;
87+ SHPHandle shpHandle = nullptr ;
8588
8689 errorString.clear ();
8790
8891 if (_validateSHPFiles (shpFile, utmZone, utmSouthernHemisphere, errorString)) {
8992 shpHandle = SHPOpen (shpFile.toUtf8 ().constData (), " rb" );
9093 if (!shpHandle) {
91- errorString = QString (_errorPrefix).arg (QObject::tr ( " SHPOpen failed." ));
94+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP ( " SHP " , " SHPOpen failed." ));
9295 }
9396 }
9497
@@ -97,7 +100,9 @@ SHPHandle SHPFileHelper::_loadShape(const QString &shpFile, int *utmZone, bool *
97100
98101ShapeFileHelper::ShapeType SHPFileHelper::determineShapeType (const QString &shpFile, QString &errorString)
99102{
100- ShapeFileHelper::ShapeType shapeType = ShapeFileHelper::Error;
103+ using ShapeType = ShapeFileHelper::ShapeType;
104+
105+ ShapeType shapeType = ShapeType::Error;
101106
102107 errorString.clear ();
103108
@@ -106,14 +111,14 @@ ShapeFileHelper::ShapeType SHPFileHelper::determineShapeType(const QString &shpF
106111 SHPHandle shpHandle = SHPFileHelper::_loadShape (shpFile, &utmZone, &utmSouthernHemisphere, errorString);
107112 if (errorString.isEmpty ()) {
108113 int cEntities, type;
109- SHPGetInfo (shpHandle, &cEntities /* pnEntities */ , &type, Q_NULLPTR /* padfMinBound */ , Q_NULLPTR /* padfMaxBound */ );
114+ SHPGetInfo (shpHandle, &cEntities /* pnEntities */ , &type, nullptr /* padfMinBound */ , nullptr /* padfMaxBound */ );
110115 qCDebug (SHPFileHelperLog) << " SHPGetInfo" << shpHandle << cEntities << type;
111116 if (cEntities != 1 ) {
112- errorString = QString (_errorPrefix).arg (QObject::tr ( " More than one entity found." ));
117+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP ( " SHP " , " More than one entity found." ));
113118 } else if (type == SHPT_POLYGON) {
114- shapeType = ShapeFileHelper ::Polygon;
119+ shapeType = ShapeType ::Polygon;
115120 } else {
116- errorString = QString (_errorPrefix).arg (QObject::tr ( " No supported types found." ));
121+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP ( " SHP " , " No supported types found." ));
117122 }
118123 }
119124
@@ -124,30 +129,29 @@ ShapeFileHelper::ShapeType SHPFileHelper::determineShapeType(const QString &shpF
124129
125130bool SHPFileHelper::loadPolygonFromFile (const QString &shpFile, QList<QGeoCoordinate> &vertices, QString &errorString)
126131{
132+ static constexpr double vertexFilterMeters = 5 ;
127133 int utmZone = 0 ;
128134 bool utmSouthernHemisphere = false ;
129- double vertexFilterMeters = 5 ;
130- SHPHandle shpHandle = Q_NULLPTR;
131- SHPObject *shpObject = Q_NULLPTR;
135+ SHPObject *shpObject = nullptr ;
132136
133137 errorString.clear ();
134138 vertices.clear ();
135139
136- shpHandle = SHPFileHelper::_loadShape (shpFile, &utmZone, &utmSouthernHemisphere, errorString);
140+ SHPHandle shpHandle = SHPFileHelper::_loadShape (shpFile, &utmZone, &utmSouthernHemisphere, errorString);
137141 if (!errorString.isEmpty ()) {
138142 goto Error;
139143 }
140144
141145 int cEntities, shapeType;
142- SHPGetInfo (shpHandle, &cEntities, &shapeType, Q_NULLPTR /* padfMinBound */ , Q_NULLPTR /* padfMaxBound */ );
146+ SHPGetInfo (shpHandle, &cEntities, &shapeType, nullptr /* padfMinBound */ , nullptr /* padfMaxBound */ );
143147 if (shapeType != SHPT_POLYGON) {
144- errorString = QString (_errorPrefix).arg (QObject::tr ( " File does not contain a polygon." ));
148+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP ( " SHP " , " File does not contain a polygon." ));
145149 goto Error;
146150 }
147151
148152 shpObject = SHPReadObject (shpHandle, 0 );
149153 if (shpObject->nParts != 1 ) {
150- errorString = QString (_errorPrefix).arg (QObject::tr ( " Only single part polygons are supported." ));
154+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP ( " SHP " , " Only single part polygons are supported." ));
151155 goto Error;
152156 }
153157
0 commit comments