@@ -19,9 +19,6 @@ email : sherman at mrcc.com
19
19
#include " qgsogrprovider.h"
20
20
#include " qgslogger.h"
21
21
22
- #include < iostream>
23
- #include < cassert>
24
-
25
22
#define CPL_SUPRESS_CPLUSPLUS
26
23
#include < gdal.h> // to collect version information
27
24
#include < ogr_api.h>
@@ -81,43 +78,41 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
81
78
// If there is no & in the uri, then the uri is just the filename. The loaded
82
79
// layer will be layer 0.
83
80
// this is not true for geojson
84
- if ( ! uri.contains ( ' |' , Qt::CaseSensitive ) )
81
+ if ( !uri.contains ( ' |' , Qt::CaseSensitive ) )
85
82
{
86
83
mFilePath = uri;
87
84
mLayerIndex = 0 ;
88
85
mLayerName = QString::null;
89
86
}
90
87
else
91
88
{
92
- // If we get here, there are some options added to the filename. We must parse
93
- // the different parts separated by &, and among each option, the name and the
94
- // value around the =.
95
- // A valid uri is of the form: filename&option1=value1&option2=value2,...
96
-
97
89
QStringList theURIParts = uri.split ( " |" );
98
90
mFilePath = theURIParts.at ( 0 );
99
91
100
92
for ( int i = 1 ; i < theURIParts.size (); i++ )
101
93
{
102
- QStringList theInstruction = theURIParts.at ( i ).split ( " =" );
103
- if ( theInstruction.at ( 0 ) == QString ( " layerid" ) )
94
+ QString part = theURIParts.at ( i );
95
+ int pos = part.indexOf ( " =" );
96
+ QString field = part.left ( pos );
97
+ QString value = part.mid ( pos + 1 );
98
+
99
+ if ( field == " layerid" )
104
100
{
105
101
bool ok;
106
- mLayerIndex = theInstruction. at ( 1 ) .toInt ( &ok );
102
+ mLayerIndex = value .toInt ( &ok );
107
103
if ( ! ok )
108
104
{
109
105
mLayerIndex = -1 ;
110
106
}
111
107
}
112
-
113
- if ( theInstruction.at ( 0 ) == QString ( " layername" ) )
108
+ else if ( field == " layername" )
114
109
{
115
- mLayerName = theInstruction. at ( 1 ) ;
110
+ mLayerName = value ;
116
111
}
117
112
118
- if ( theInstruction. at ( 0 ) == QString ( " subset" ) )
113
+ if ( field == " subset" )
119
114
{
120
- mSubsetString = theInstruction. at ( 1 ) ;
115
+ mSubsetString = value ;
121
116
}
122
117
}
123
118
}
@@ -126,7 +121,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
126
121
QgsDebugMsg ( " mLayerIndex: " + QString::number ( mLayerIndex ) );
127
122
QgsDebugMsg ( " mLayerName: " + mLayerName );
128
123
QgsDebugMsg ( " mSubsetString: " + mSubsetString );
129
- CPLSetConfigOption (" OGR_ORGANIZE_POLYGONS" , " SKIP" );
124
+ CPLSetConfigOption ( " OGR_ORGANIZE_POLYGONS" , " SKIP" );
130
125
CPLPushErrorHandler ( CPLQuietErrorHandler );
131
126
ogrDataSource = OGROpen ( QFile::encodeName ( mFilePath ).constData (), TRUE , &ogrDriver );
132
127
CPLPopErrorHandler ();
@@ -245,6 +240,7 @@ bool QgsOgrProvider::setSubsetString( QString theSQL )
245
240
{
246
241
uri += QString ( " |subset=%1" ).arg ( mSubsetString );
247
242
}
243
+
248
244
setDataSourceUri ( uri );
249
245
250
246
OGR_L_ResetReading ( ogrLayer );
0 commit comments