@@ -38,41 +38,44 @@ bool SHPFileHelper::_validateSHPFiles(const QString &shpFile, int *utmZone, bool
38
38
errorString.clear ();
39
39
40
40
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 ;
42
43
}
43
44
44
45
const QString prjFilename = shpFile.left (shpFile.length () - 4 ) + QStringLiteral (" .prj" );
45
46
QFile prjFile (prjFilename);
46
47
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 ;
48
50
}
49
51
50
52
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 ;
52
55
}
53
56
54
57
QTextStream strm (&prjFile);
55
58
const QString line = strm.readLine ();
56
59
if (line.startsWith (QStringLiteral (" GEOGCS[\" GCS_WGS_1984\" ," ))) {
57
60
*utmZone = 0 ;
58
61
*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
+ }
71
72
}
72
- }
73
73
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." ));
76
79
}
77
80
78
81
return errorString.isEmpty ();
@@ -81,14 +84,14 @@ bool SHPFileHelper::_validateSHPFiles(const QString &shpFile, int *utmZone, bool
81
84
82
85
SHPHandle SHPFileHelper::_loadShape (const QString &shpFile, int *utmZone, bool *utmSouthernHemisphere, QString &errorString)
83
86
{
84
- SHPHandle shpHandle = Q_NULLPTR ;
87
+ SHPHandle shpHandle = nullptr ;
85
88
86
89
errorString.clear ();
87
90
88
91
if (_validateSHPFiles (shpFile, utmZone, utmSouthernHemisphere, errorString)) {
89
92
shpHandle = SHPOpen (shpFile.toUtf8 ().constData (), " rb" );
90
93
if (!shpHandle) {
91
- errorString = QString (_errorPrefix).arg (QObject::tr ( " SHPOpen failed." ));
94
+ errorString = QString (_errorPrefix).arg (QT_TRANSLATE_NOOP ( " SHP " , " SHPOpen failed." ));
92
95
}
93
96
}
94
97
@@ -97,7 +100,9 @@ SHPHandle SHPFileHelper::_loadShape(const QString &shpFile, int *utmZone, bool *
97
100
98
101
ShapeFileHelper::ShapeType SHPFileHelper::determineShapeType (const QString &shpFile, QString &errorString)
99
102
{
100
- ShapeFileHelper::ShapeType shapeType = ShapeFileHelper::Error;
103
+ using ShapeType = ShapeFileHelper::ShapeType;
104
+
105
+ ShapeType shapeType = ShapeType::Error;
101
106
102
107
errorString.clear ();
103
108
@@ -106,14 +111,14 @@ ShapeFileHelper::ShapeType SHPFileHelper::determineShapeType(const QString &shpF
106
111
SHPHandle shpHandle = SHPFileHelper::_loadShape (shpFile, &utmZone, &utmSouthernHemisphere, errorString);
107
112
if (errorString.isEmpty ()) {
108
113
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 */ );
110
115
qCDebug (SHPFileHelperLog) << " SHPGetInfo" << shpHandle << cEntities << type;
111
116
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." ));
113
118
} else if (type == SHPT_POLYGON) {
114
- shapeType = ShapeFileHelper ::Polygon;
119
+ shapeType = ShapeType ::Polygon;
115
120
} 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." ));
117
122
}
118
123
}
119
124
@@ -124,30 +129,29 @@ ShapeFileHelper::ShapeType SHPFileHelper::determineShapeType(const QString &shpF
124
129
125
130
bool SHPFileHelper::loadPolygonFromFile (const QString &shpFile, QList<QGeoCoordinate> &vertices, QString &errorString)
126
131
{
132
+ static constexpr double vertexFilterMeters = 5 ;
127
133
int utmZone = 0 ;
128
134
bool utmSouthernHemisphere = false ;
129
- double vertexFilterMeters = 5 ;
130
- SHPHandle shpHandle = Q_NULLPTR;
131
- SHPObject *shpObject = Q_NULLPTR;
135
+ SHPObject *shpObject = nullptr ;
132
136
133
137
errorString.clear ();
134
138
vertices.clear ();
135
139
136
- shpHandle = SHPFileHelper::_loadShape (shpFile, &utmZone, &utmSouthernHemisphere, errorString);
140
+ SHPHandle shpHandle = SHPFileHelper::_loadShape (shpFile, &utmZone, &utmSouthernHemisphere, errorString);
137
141
if (!errorString.isEmpty ()) {
138
142
goto Error;
139
143
}
140
144
141
145
int cEntities, shapeType;
142
- SHPGetInfo (shpHandle, &cEntities, &shapeType, Q_NULLPTR /* padfMinBound */ , Q_NULLPTR /* padfMaxBound */ );
146
+ SHPGetInfo (shpHandle, &cEntities, &shapeType, nullptr /* padfMinBound */ , nullptr /* padfMaxBound */ );
143
147
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." ));
145
149
goto Error;
146
150
}
147
151
148
152
shpObject = SHPReadObject (shpHandle, 0 );
149
153
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." ));
151
155
goto Error;
152
156
}
153
157
0 commit comments