Skip to content

Commit c53f881

Browse files
committedJan 15, 2014
Moved WMS capabilities, URI parsing out of provider class.
With this change, all WMS capabilities are kept within one class. When the provider is cloned, the existing capabilities object is passed to new provider, thus not requiring new provider download capabilities again. Data items and GUI dialog do not have to create a dummy provider just in order to get capabilities.
1 parent 680ffe0 commit c53f881

10 files changed

+2867
-2844
lines changed
 

‎src/providers/wms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
SET (WMS_SRCS
3+
qgswmscapabilities.cpp
34
qgswmsprovider.cpp
45
qgswmssourceselect.cpp
56
qgswmsconnection.cpp
@@ -8,6 +9,7 @@ SET (WMS_SRCS
89
qgswmtsdimensions.cpp
910
)
1011
SET (WMS_MOC_HDRS
12+
qgswmscapabilities.h
1113
qgswmsprovider.h
1214
qgswmssourceselect.h
1315
qgswmsconnection.h

‎src/providers/wms/qgswmscapabilities.cpp

Lines changed: 1745 additions & 0 deletions
Large diffs are not rendered by default.

‎src/providers/wms/qgswmscapabilities.h

Lines changed: 715 additions & 0 deletions
Large diffs are not rendered by default.

‎src/providers/wms/qgswmsconnection.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,6 @@ QgsDataSourceURI QgsWMSConnection::uri()
156156
return mUri;
157157
}
158158

159-
QgsWmsProvider * QgsWMSConnection::provider( )
160-
{
161-
// TODO: Create and bind to data provider
162-
163-
// load the server data provider plugin
164-
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
165-
166-
QgsWmsProvider *wmsProvider =
167-
( QgsWmsProvider* ) pReg->provider( "wms", mUri.encodedUri() );
168-
169-
return wmsProvider;
170-
}
171-
172-
173159

174160
QStringList QgsWMSConnection::connectionList()
175161
{

‎src/providers/wms/qgswmsconnection.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <QPushButton>
2626

2727
class QgisApp;
28-
class QgsWmsProvider;
2928
/*class QButtonGroup;*/
3029
/*class QgsNumericSortTreeWidgetItem;*/
3130
class QDomDocument;
@@ -53,7 +52,6 @@ class QgsWMSConnection : public QObject
5352

5453

5554
public:
56-
QgsWmsProvider *provider();
5755
QString connectionInfo();
5856
QString mConnName;
5957
QString mConnectionInfo;

‎src/providers/wms/qgswmsdataitems.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "qgslogger.h"
1818

1919
#include "qgsdatasourceuri.h"
20+
#include "qgswmscapabilities.h"
2021
#include "qgswmsconnection.h"
2122
#include "qgswmssourceselect.h"
2223

@@ -60,18 +61,37 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
6061
#endif
6162
QgsDebugMsg( "encodedUri = " + encodedUri );
6263

63-
QgsWmsProvider *wmsProvider = new QgsWmsProvider( encodedUri );
64-
if ( !wmsProvider ) return children;
64+
QgsWmsSettings wmsSettings;
65+
if ( !wmsSettings.parseUri( encodedUri ) )
66+
{
67+
children.append( new QgsErrorItem( this, tr( "Failed to parse WMS URI" ), mPath + "/error" ) );
68+
return children;
69+
}
6570

66-
// Attention: supportedLayers() gives tree leafes, not top level
67-
if ( !wmsProvider->supportedLayers( mLayerProperties ) )
71+
QgsWmsCapabilitiesDownload capDownload( wmsSettings.baseUrl(), wmsSettings.authorization() );
72+
connect( &capDownload, SIGNAL( statusChanged( QString ) ), this, SLOT( showStatusMessage( QString ) ) );
73+
74+
QApplication::setOverrideCursor( Qt::WaitCursor );
75+
bool res = capDownload.downloadCapabilities();
76+
QApplication::restoreOverrideCursor();
77+
78+
if ( !res )
6879
{
69-
//children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
70-
// TODO: show the error without adding child
80+
children.append( new QgsErrorItem( this, tr( "Failed to download capabilities" ), mPath + "/error" ) );
7181
return children;
7282
}
7383

74-
QgsWmsCapabilitiesProperty mCapabilitiesProperty = wmsProvider->capabilitiesProperty();
84+
QgsWmsCapabilities caps;
85+
if ( !caps.parseResponse( capDownload.response(), wmsSettings.parserSettings() ) )
86+
{
87+
children.append( new QgsErrorItem( this, tr( "Failed to parse capabilities" ), mPath + "/error" ) );
88+
return children;
89+
}
90+
91+
// Attention: supportedLayers() gives tree leafes, not top level
92+
mLayerProperties = caps.supportedLayers();
93+
94+
QgsWmsCapabilitiesProperty mCapabilitiesProperty = caps.capabilitiesProperty();
7595
QgsWmsCapabilityProperty capabilityProperty = mCapabilitiesProperty.capability;
7696

7797
// Top level layer is present max once

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 312 additions & 2113 deletions
Large diffs are not rendered by default.

‎src/providers/wms/qgswmsprovider.h

Lines changed: 28 additions & 673 deletions
Large diffs are not rendered by default.

‎src/providers/wms/qgswmssourceselect.cpp

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "qgswmssourceselect.h"
3737
#include "qgswmtsdimensions.h"
3838
#include "qgsnetworkaccessmanager.h"
39+
#include "qgswmscapabilities.h"
3940

4041
#include <QButtonGroup>
4142
#include <QFileDialog>
@@ -287,14 +288,12 @@ void QgsWMSSourceSelect::clear()
287288
mFeatureCount->setEnabled( false );
288289
}
289290

290-
bool QgsWMSSourceSelect::populateLayerList( QgsWmsProvider *wmsProvider )
291+
bool QgsWMSSourceSelect::populateLayerList( const QgsWmsCapabilities& capabilities )
291292
{
292-
QVector<QgsWmsLayerProperty> layers;
293-
if ( !wmsProvider->supportedLayers( layers ) )
294-
return false;
293+
QVector<QgsWmsLayerProperty> layers = capabilities.supportedLayers();
295294

296295
bool first = true;
297-
foreach ( QString encoding, wmsProvider->supportedImageEncodings() )
296+
foreach ( QString encoding, capabilities.supportedImageEncodings() )
298297
{
299298
int id = mMimeMap.value( encoding, -1 );
300299
if ( id < 0 )
@@ -316,7 +315,7 @@ bool QgsWMSSourceSelect::populateLayerList( QgsWmsProvider *wmsProvider )
316315
QMap<int, QgsNumericSortTreeWidgetItem *> items;
317316
QMap<int, int> layerParents;
318317
QMap<int, QStringList> layerParentNames;
319-
wmsProvider->layerParents( layerParents, layerParentNames );
318+
capabilities.layerParents( layerParents, layerParentNames );
320319

321320
lstLayers->setSortingEnabled( true );
322321

@@ -351,16 +350,15 @@ bool QgsWMSSourceSelect::populateLayerList( QgsWmsProvider *wmsProvider )
351350

352351
lstLayers->sortByColumn( 0, Qt::AscendingOrder );
353352

354-
wmsProvider->supportedTileLayers( mTileLayers );
353+
mTileLayers = capabilities.supportedTileLayers();
355354

356355
tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ), mTileLayers.size() > 0 );
357356
if ( tabServers->isTabEnabled( tabServers->indexOf( tabTilesets ) ) )
358357
tabServers->setCurrentWidget( tabTilesets );
359358

360359
if ( mTileLayers.size() > 0 )
361360
{
362-
QHash<QString, QgsWmtsTileMatrixSet> tileMatrixSets;
363-
wmsProvider->supportedTileMatrixSets( tileMatrixSets );
361+
QHash<QString, QgsWmtsTileMatrixSet> tileMatrixSets = capabilities.supportedTileMatrixSets();
364362

365363
int rows = 0;
366364
foreach ( const QgsWmtsTileLayer &l, mTileLayers )
@@ -442,45 +440,49 @@ void QgsWMSSourceSelect::on_btnConnect_clicked()
442440
mConnName = cmbConnections->currentText();
443441

444442
QgsWMSConnection connection( cmbConnections->currentText() );
445-
QgsWmsProvider *wmsProvider = connection.provider();
446443
mConnectionInfo = connection.connectionInfo();
447444
mUri = connection.uri();
448445

449-
if ( wmsProvider )
446+
QgsWmsSettings wmsSettings;
447+
if ( !wmsSettings.parseUri( mUri.encodedUri() ) )
450448
{
451-
QApplication::setOverrideCursor( Qt::WaitCursor );
452-
453-
connect( wmsProvider, SIGNAL( statusChanged( QString ) ), this, SLOT( showStatusMessage( QString ) ) );
449+
QMessageBox::warning(
450+
this,
451+
tr( "WMS Provider" ),
452+
tr( "Failed to parse WMS URI" )
453+
);
454+
return;
455+
}
454456

455-
// WMS Provider all set up; let's get some layers
457+
QgsWmsCapabilitiesDownload capDownload( wmsSettings.baseUrl(), wmsSettings.authorization() );
458+
connect( &capDownload, SIGNAL( statusChanged( QString ) ), this, SLOT( showStatusMessage( QString ) ) );
456459

457-
if ( !populateLayerList( wmsProvider ) )
458-
{
459-
showError( wmsProvider );
460-
}
461-
else
462-
{
463-
int capabilities = wmsProvider->identifyCapabilities();
464-
QgsDebugMsg( "capabilities = " + QString::number( capabilities ) );
465-
if ( capabilities ) // at least one identify capability
466-
{
467-
mFeatureCount->setEnabled( true );
468-
}
469-
}
470-
471-
delete wmsProvider;
460+
QApplication::setOverrideCursor( Qt::WaitCursor );
461+
bool res = capDownload.downloadCapabilities();
462+
QApplication::restoreOverrideCursor();
472463

473-
QApplication::restoreOverrideCursor();
464+
if ( !res )
465+
{
466+
QMessageBox::warning(
467+
this,
468+
tr( "WMS Provider" ),
469+
tr( "Failed to download capabilities:\n" ) + capDownload.lastError()
470+
);
471+
return;
474472
}
475-
else
473+
474+
QgsWmsCapabilities caps;
475+
if ( !caps.parseResponse( capDownload.response(), wmsSettings.parserSettings() ) )
476476
{
477-
// Let user know we couldn't initialise the WMS provider
478477
QMessageBox::warning(
479478
this,
480479
tr( "WMS Provider" ),
481-
tr( "Could not open the WMS Provider" )
480+
tr( "Failed to parse capabilities:\n" ) + caps.lastError()
482481
);
482+
return;
483483
}
484+
485+
populateLayerList( caps );
484486
}
485487

486488
void QgsWMSSourceSelect::addClicked()

‎src/providers/wms/qgswmssourceselect.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class QButtonGroup;
3333
class QgsNumericSortTreeWidgetItem;
3434
class QDomDocument;
3535
class QDomElement;
36+
class QgsWmsCapabilities;
3637

3738
/*!
3839
* \brief Dialog to create connections and add layers from WMS, etc.
@@ -159,7 +160,7 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
159160
* \retval false if the layers could not be retrieved or parsed -
160161
* see mWmsProvider->errorString() for more info
161162
*/
162-
bool populateLayerList( QgsWmsProvider *wmsProvider );
163+
bool populateLayerList( const QgsWmsCapabilities& capabilities );
163164

164165
//! create an item including possible parents
165166
QgsNumericSortTreeWidgetItem *createItem( int id,

0 commit comments

Comments
 (0)
Please sign in to comment.