26
26
#include < qgsrasterlayer.h>
27
27
#include < qgsdataitem.h>
28
28
#include " qgsconfig.h"
29
+ #include < qgsrenderer.h>
30
+ #include < qgsuniquevaluerenderer.h>
29
31
30
32
#include < gdal.h>
31
33
@@ -43,9 +45,15 @@ class TestZipLayer: public QObject
43
45
int mMaxScanZipSetting ;
44
46
int mScanZipSetting ;
45
47
46
- bool testPassthruVector ( QString myFileName );
47
- bool testPassthruRaster ( QString myFileName );
48
+ // get map layer using Passthru
49
+ QgsMapLayer * getLayer ( QString myPath, QString myName, QString myProviderKey );
50
+ bool testZipItemPassthru ( QString myFileName, QString myProviderKey );
51
+ // get map layer using QgsZipItem (only 1 child)
52
+ QgsMapLayer * getZipLayer ( QString myPath, QString myName );
53
+ // test item(s) in zip item (supply name or test all)
48
54
bool testZipItem ( QString myFileName, QString myChildName );
55
+ // get layer transparency to test for .qml loading
56
+ int getLayerTransparency ( QString myFileName, QString myProviderKey, int myScanZipSetting = 1 );
49
57
50
58
private slots:
51
59
@@ -65,28 +73,57 @@ class TestZipLayer: public QObject
65
73
void testZipItemRaster ();
66
74
void testZipItemVector ();
67
75
void testZipItemAll ();
68
-
76
+ // test that styles are loaded from .qml files outside zip files
77
+ void testZipItemVectorTransparency ();
78
+ void testGipItemVectorTransparency ();
79
+ void testZipItemRasterTransparency ();
80
+ void testGZipItemRasterTransparency ();
69
81
};
70
82
71
- bool TestZipLayer::testPassthruVector ( QString myFileName )
83
+
84
+ QgsMapLayer *TestZipLayer::getLayer ( QString myPath, QString myName, QString myProviderKey )
72
85
{
73
- QFileInfo myFileInfo ( myFileName );
74
- QgsVectorLayer * myVectorLayer;
75
- myVectorLayer = new QgsVectorLayer ( myFileInfo.filePath (),
76
- myFileInfo.completeBaseName (), " ogr" );
77
- bool ok = myVectorLayer->isValid ();
78
- delete myVectorLayer;
79
- return ok;
86
+ if ( myName == " " )
87
+ {
88
+ QFileInfo myFileInfo ( myPath );
89
+ myName = myFileInfo.completeBaseName ();
90
+ }
91
+ QgsMapLayer *myLayer = NULL ;
92
+
93
+ if ( myProviderKey == " ogr" )
94
+ {
95
+ myLayer = new QgsVectorLayer ( myPath, myName, " ogr" );
96
+ }
97
+ else if ( myProviderKey == " gdal" )
98
+ {
99
+ myLayer = new QgsRasterLayer ( myPath, myName, " gdal" );
100
+ }
101
+ // item should not have other provider key, but if it does will return NULL
102
+
103
+ return myLayer;
80
104
}
81
105
82
- bool TestZipLayer::testPassthruRaster ( QString myFileName )
106
+ QgsMapLayer * TestZipLayer::getZipLayer ( QString myPath, QString myName )
83
107
{
84
- QFileInfo myFileInfo ( myFileName );
85
- QgsRasterLayer * myRasterLayer;
86
- myRasterLayer = new QgsRasterLayer ( myFileInfo.filePath (),
87
- myFileInfo.completeBaseName (), " gdal" );
88
- bool ok = myRasterLayer->isValid ();
89
- delete myRasterLayer;
108
+ QgsMapLayer *myLayer = NULL ;
109
+ QgsDirectoryItem *dirItem = new QgsDirectoryItem ( NULL , " /" , " " );
110
+ QgsDataItem* myItem = QgsZipItem::itemFromPath ( dirItem, myPath, myName );
111
+ if ( myItem )
112
+ {
113
+ QgsLayerItem *layerItem = dynamic_cast <QgsLayerItem*>( myItem );
114
+ if ( layerItem )
115
+ myLayer = getLayer ( layerItem->path (), layerItem->name (), layerItem->providerKey () );
116
+ }
117
+ delete dirItem;
118
+ return myLayer;
119
+ }
120
+
121
+ bool TestZipLayer::testZipItemPassthru ( QString myFileName, QString myProviderKey )
122
+ {
123
+ QgsMapLayer * myLayer = getLayer ( myFileName, " " , myProviderKey );
124
+ bool ok = myLayer && myLayer->isValid ();
125
+ if ( myLayer )
126
+ delete myLayer;
90
127
return ok;
91
128
}
92
129
@@ -111,33 +148,18 @@ bool TestZipLayer::testZipItem( QString myFileName, QString myChildName = "" )
111
148
QgsDebugMsg ( QString ( " child name=%1 provider=%2 path=%3" ).arg ( layerItem->name () ).arg ( layerItem->providerKey () ).arg ( layerItem->path () ) );
112
149
if ( myChildName == " " || myChildName == item->name () )
113
150
{
114
- QgsMapLayer* myLayer = NULL ;
115
- if ( layerItem->providerKey () == " ogr" )
116
- {
117
- myLayer = new QgsVectorLayer ( item->path (), item->name (), " ogr" );
118
- }
119
- else if ( layerItem->providerKey () == " gdal" )
120
- {
121
- myLayer = new QgsRasterLayer ( item->path (), item->name (), " gdal" );
122
- }
123
- else
124
- {
125
- // item should not have other provider key, but if it does the test will fail
126
- ok = false ;
127
- QWARN ( QString ( " Invalid provider %1" ).arg ( layerItem->providerKey () ).toLocal8Bit ().data () );
128
- break ;
129
- }
130
- if ( myLayer != NULL )
151
+ QgsMapLayer* layer = getLayer ( layerItem->path (), layerItem->name (), layerItem->providerKey () );
152
+ if ( layer != NULL )
131
153
{
132
154
// we got a layer, check if it is valid and exit
133
- QgsDebugMsg ( QString ( " valid: %1" ).arg ( myLayer->isValid () ) );
134
- ok = myLayer->isValid ();
135
- delete myLayer;
155
+ // if no child name given in argument, then pass to next one (unless current child is invalid)
156
+ QgsDebugMsg ( QString ( " valid: %1" ).arg ( layer->isValid () ) );
157
+ ok = layer->isValid ();
158
+ delete layer;
136
159
if ( ! ok )
137
160
{
138
- QWARN ( QString ( " Invalid item %1" ).arg ( layerItem->path () ).toLocal8Bit ().data () );
161
+ QWARN ( QString ( " Invalid layer %1" ).arg ( layerItem->path () ).toLocal8Bit ().data () );
139
162
}
140
- // if no child name given, then pass to next one (unless current child is invalid)
141
163
if ( myChildName == " " )
142
164
{
143
165
if ( ! ok )
@@ -150,14 +172,14 @@ bool TestZipLayer::testZipItem( QString myFileName, QString myChildName = "" )
150
172
}
151
173
else
152
174
{
153
- QWARN ( QString ( " Invalid item %1" ).arg ( layerItem->path () ).toLocal8Bit ().data () );
175
+ QWARN ( QString ( " Invalid layer %1" ).arg ( layerItem->path () ).toLocal8Bit ().data () );
154
176
break ;
155
177
}
156
178
}
157
179
}
158
180
else
159
181
{
160
- QWARN ( QString ( " Invalid item %1" ).arg ( layerItem->path () ).toLocal8Bit ().data () );
182
+ QWARN ( QString ( " Invalid layer %1" ).arg ( layerItem->path () ).toLocal8Bit ().data () );
161
183
break ;
162
184
}
163
185
}
@@ -166,6 +188,24 @@ bool TestZipLayer::testZipItem( QString myFileName, QString myChildName = "" )
166
188
return ok;
167
189
}
168
190
191
+ int TestZipLayer::getLayerTransparency ( QString myFileName, QString myProviderKey, int myScanZipSetting )
192
+ {
193
+ int myTransparency = -1 ;
194
+ mSettings .setValue ( " /qgis/scanZipInBrowser" , myScanZipSetting );
195
+ QgsMapLayer * myLayer = NULL ;
196
+ if ( myScanZipSetting == 1 )
197
+ myLayer = getLayer ( myFileName, " " , myProviderKey );
198
+ else
199
+ myLayer = getZipLayer ( myFileName, " " );
200
+ if ( myLayer && myLayer->isValid () )
201
+ myTransparency = myLayer->getTransparency ();
202
+ if ( myLayer )
203
+ delete myLayer;
204
+ return myTransparency;
205
+ }
206
+
207
+
208
+ // slots
169
209
void TestZipLayer::initTestCase ()
170
210
{
171
211
QgsApplication::init ();
@@ -192,7 +232,7 @@ void TestZipLayer::cleanupTestCase()
192
232
193
233
void TestZipLayer::testPassthruVectorZip ()
194
234
{
195
- QString myFileName = mDataDir + " points .zip" ;
235
+ QString myFileName = mDataDir + " points2 .zip" ;
196
236
QgsDebugMsg ( " GDAL: " + QString ( GDAL_RELEASE_NAME ) );
197
237
#if GDAL_VERSION_NUM < 1800
198
238
myFileName = " /vsizip/" + myFileName + " /points.shp" ;
@@ -201,7 +241,7 @@ void TestZipLayer::testPassthruVectorZip()
201
241
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
202
242
{
203
243
mSettings .setValue ( " /qgis/scanZipInBrowser" , i );
204
- QVERIFY ( testPassthruVector ( myFileName ) );
244
+ QVERIFY ( testZipItemPassthru ( myFileName, " ogr " ) );
205
245
}
206
246
}
207
247
@@ -210,7 +250,7 @@ void TestZipLayer::testPassthruVectorGzip()
210
250
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
211
251
{
212
252
mSettings .setValue ( " /qgis/scanZipInBrowser" , i );
213
- QVERIFY ( testPassthruVector ( mDataDir + " points .geojson.gz" ) );
253
+ QVERIFY ( testZipItemPassthru ( mDataDir + " points3 .geojson.gz" , " ogr " ) );
214
254
}
215
255
}
216
256
@@ -219,7 +259,7 @@ void TestZipLayer::testPassthruRasterZip()
219
259
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
220
260
{
221
261
mSettings .setValue ( " /qgis/scanZipInBrowser" , i );
222
- QVERIFY ( testPassthruRaster ( mDataDir + " landsat_b1.zip" ) );
262
+ QVERIFY ( testZipItemPassthru ( mDataDir + " landsat_b1.zip" , " gdal " ) );
223
263
}
224
264
}
225
265
@@ -228,7 +268,7 @@ void TestZipLayer::testPassthruRasterGzip()
228
268
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
229
269
{
230
270
mSettings .setValue ( " /qgis/scanZipInBrowser" , i );
231
- QVERIFY ( testPassthruRaster ( mDataDir + " landsat_b1.tif.gz" ) );
271
+ QVERIFY ( testZipItemPassthru ( mDataDir + " landsat_b1.tif.gz" , " gdal " ) );
232
272
}
233
273
}
234
274
@@ -270,9 +310,43 @@ void TestZipLayer::testZipItemAll()
270
310
QVERIFY ( testZipItem ( mDataDir + " testzip.zip" , " " ) );
271
311
}
272
312
273
- QTEST_MAIN ( TestZipLayer )
274
- #include " moc_testziplayer.cxx"
275
313
314
+ void TestZipLayer::testZipItemVectorTransparency ()
315
+ {
316
+ int myTarget = 250 ;
317
+ int myTransparency = getLayerTransparency ( mDataDir + " points2.zip" , " ogr" , 1 );
318
+ QVERIFY2 (( myTransparency == myTarget ), QString ( " Transparency is %1, should be %2" ).arg ( myTransparency ).arg ( myTarget ).toLocal8Bit ().data () );
319
+ myTransparency = getLayerTransparency ( mDataDir + " points2.zip" , " ogr" , 2 );
320
+ QVERIFY2 (( myTransparency == myTarget ), QString ( " Transparency is %1, should be %2" ).arg ( myTransparency ).arg ( myTarget ).toLocal8Bit ().data () );
321
+ }
322
+
323
+ void TestZipLayer::testGipItemVectorTransparency ()
324
+ {
325
+ int myTarget = 250 ;
326
+ int myTransparency = getLayerTransparency ( mDataDir + " points3.geojson.gz" , " ogr" , 1 );
327
+ QVERIFY2 (( myTransparency == myTarget ), QString ( " Transparency is %1, should be %2" ).arg ( myTransparency ).arg ( myTarget ).toLocal8Bit ().data () );
328
+ myTransparency = getLayerTransparency ( mDataDir + " points3.geojson.gz" , " ogr" , 2 );
329
+ QVERIFY2 (( myTransparency == myTarget ), QString ( " Transparency is %1, should be %2" ).arg ( myTransparency ).arg ( myTarget ).toLocal8Bit ().data () );
330
+ }
276
331
332
+ void TestZipLayer::testZipItemRasterTransparency ()
333
+ {
334
+ int myTarget = 250 ;
335
+ int myTransparency = getLayerTransparency ( mDataDir + " landsat_b1.zip" , " gdal" , 1 );
336
+ QVERIFY2 (( myTransparency == myTarget ), QString ( " Transparency is %1, should be %2" ).arg ( myTransparency ).arg ( myTarget ).toLocal8Bit ().data () );
337
+ myTransparency = getLayerTransparency ( mDataDir + " landsat_b1.zip" , " gdal" , 2 );
338
+ QVERIFY2 (( myTransparency == myTarget ), QString ( " Transparency is %1, should be %2" ).arg ( myTransparency ).arg ( myTarget ).toLocal8Bit ().data () );
339
+ }
340
+
341
+ void TestZipLayer::testGZipItemRasterTransparency ()
342
+ {
343
+ int myTarget = 250 ;
344
+ int myTransparency = getLayerTransparency ( mDataDir + " landsat_b1.tif.gz" , " gdal" , 1 );
345
+ QVERIFY2 (( myTransparency == myTarget ), QString ( " Transparency is %1, should be %2" ).arg ( myTransparency ).arg ( myTarget ).toLocal8Bit ().data () );
346
+ myTransparency = getLayerTransparency ( mDataDir + " landsat_b1.tif.gz" , " gdal" , 2 );
347
+ QVERIFY2 (( myTransparency == myTarget ), QString ( " Transparency is %1, should be %2" ).arg ( myTransparency ).arg ( myTarget ).toLocal8Bit ().data () );
348
+ }
277
349
278
350
351
+ QTEST_MAIN ( TestZipLayer )
352
+ #include " moc_testziplayer.cxx"
0 commit comments