Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WMS: Better logic to pick the legend URL
QGIS had two problems: 1) It was using the specified legend URL only if its mime type was matching the layer's mime type. There is no reason for that. 2) When QGIS was using the default layer (empty string), it was not even trying to find out in what style to pick the legend URL. (cherry-picked from 69bed21)
- Loading branch information
Showing
4 changed files
with
126 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <QFile> | ||
#include <QObject> | ||
#include <QtTest/QtTest> | ||
#include <qgswmsprovider.h> | ||
#include <qgsapplication.h> | ||
|
||
/** \ingroup UnitTests | ||
* This is a unit test for the WMS provider. | ||
*/ | ||
class TestQgsWmsProvider: public QObject | ||
{ | ||
Q_OBJECT | ||
private slots: | ||
|
||
void initTestCase() | ||
{ | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
|
||
QFile file( QString( TEST_DATA_DIR ) + "/provider/GetCapabilities.xml" ); | ||
QVERIFY( file.open( QIODevice::ReadOnly | QIODevice::Text ) ); | ||
const QByteArray content = file.readAll(); | ||
QVERIFY( content.size() > 0 ); | ||
const QgsWmsParserSettings config; | ||
|
||
mCapabilities = new QgsWmsCapabilities(); | ||
QVERIFY( mCapabilities->parseResponse( content, config ) ); | ||
} | ||
|
||
//runs after all tests | ||
void cleanupTestCase() | ||
{ | ||
delete mCapabilities; | ||
QgsApplication::exitQgis(); | ||
} | ||
|
||
void legendGraphicsWithStyle() | ||
{ | ||
QgsWmsProvider provider( "http://localhost:8380/mapserv?xxx&layers=agri_zones&styles=fb_style&format=image/jpg", mCapabilities ); | ||
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://www.example.com/fb.png?" ) ); | ||
} | ||
|
||
void legendGraphicsWithSecondStyle() | ||
{ | ||
QgsWmsProvider provider( "http://localhost:8380/mapserv?xxx&layers=agri_zones&styles=yt_style&format=image/jpg", mCapabilities ); | ||
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://www.example.com/yt.png?" ) ); | ||
} | ||
|
||
void legendGraphicsWithoutStyleWithDefault() | ||
{ | ||
QgsWmsProvider provider( "http://localhost:8380/mapserv?xxx&layers=buildings&styles=&format=image/jpg", mCapabilities ); | ||
//only one style, can guess default => use it | ||
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://www.example.com/buildings.png?" ) ); | ||
} | ||
|
||
void legendGraphicsWithoutStyleWithoutDefault() | ||
{ | ||
QgsWmsProvider provider( "http://localhost:8380/mapserv?xxx&layers=agri_zones&styles=&format=image/jpg", mCapabilities ); | ||
//two style, cannot guess default => use the WMS GetLegendGraphics | ||
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://localhost:8380/mapserv?" ) ); | ||
} | ||
|
||
private: | ||
QgsWmsCapabilities* mCapabilities; | ||
}; | ||
|
||
QTEST_MAIN( TestQgsWmsProvider ) | ||
#include "testqgswmsprovider.moc" |