Skip to content

Commit 4872d94

Browse files
author
morb_au
committed
More WMS improvements:
* Errors report to the GUI in many more cases (not just the console when QGIS_DEBUG was defined) - both HTTP connection errors and WMS Service Exceptions from the server. However, non-standard HTTP responses (e.g. 500 Server Error) are not handled yet. * The WMS selection GUI was cleaned up in the CRS selection group box - as users select layers, the number of available CRSs is displayed. Also, the current selection is now displayed as the friendly description, not the proj4 string. * There is a better chance of a valid CRS being sent to the server in more situations (with WMS therefore appearing to work more often!). * In QgsSpatialRefSys, initialise the mIsValidFlag properly. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4979 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 274ef7a commit 4872d94

8 files changed

+469
-87
lines changed

src/core/qgsrasterdataprovider.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,24 @@ class QgsRasterDataProvider : public QgsDataProvider
9494
virtual QString getMetadata() = 0;
9595

9696
/**
97+
* \brief Returns the caption error text for the last error in this provider
98+
*
9799
* If an operation returns 0 (e.g. draw()), this function
98100
* returns the text of the error associated with the failure.
99101
* Interactive users of this provider can then, for example,
100102
* call a QMessageBox to display the contents.
103+
*
101104
*/
102105
virtual QString errorCaptionString() = 0;
103106

104107
/**
108+
* \brief Returns the verbose error text for the last error in this provider
109+
*
105110
* If an operation returns 0 (e.g. draw()), this function
106111
* returns the text of the error associated with the failure.
107112
* Interactive users of this provider can then, for example,
108113
* call a QMessageBox to display the contents.
114+
*
109115
*/
110116
virtual QString errorString() = 0;
111117

src/gui/qgsmaplayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ class QgsMapLayer : public QObject
290290
* Interactive users of this provider can then, for example,
291291
* call a QMessageBox to display the contents.
292292
*/
293-
QString errorCaptionString();
293+
virtual QString errorCaptionString();
294294

295295
/**
296296
* If an operation returns 0 (e.g. draw()), this function
297297
* returns the text of the error associated with the failure.
298298
* Interactive users of this provider can then, for example,
299299
* call a QMessageBox to display the contents.
300300
*/
301-
QString errorString();
301+
virtual QString errorString();
302302

303303

304304
public slots:

src/gui/qgsserversourceselect.cpp

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@
3535

3636
#include <iostream>
3737

38+
static long DEFAULT_WMS_EPSG = 4326; // WGS 84
39+
40+
3841
QgsServerSourceSelect::QgsServerSourceSelect(QgisApp * app, QWidget * parent, Qt::WFlags fl)
3942
: QDialog(parent, fl),
4043
qgisApp(app),
41-
wmsProvider(0),
42-
m_Epsg(0)
44+
mWmsProvider(0),
45+
m_Epsg(DEFAULT_WMS_EPSG)
4346
{
4447
setupUi(this);
4548
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
@@ -61,12 +64,11 @@ QgsServerSourceSelect::QgsServerSourceSelect(QgisApp * app, QWidget * parent, Qt
6164
hbox->addStretch();
6265
btnGrpImageEncoding->setLayout(hbox);
6366

67+
// set up the WMS connections we already know about
6468
populateConnectionList();
65-
// connect the double-click signal to the addSingleLayer slot in the parent
66-
67-
//disable the 'where clause' box for 0.4 release
68-
// groupBox3->hide();
6969

70+
// set up the default WMS Coordinate Reference System
71+
labelCoordRefSys->setText( descriptionForEpsg(m_Epsg) );
7072
}
7173

7274
QgsServerSourceSelect::~QgsServerSourceSelect()
@@ -143,11 +145,14 @@ void QgsServerSourceSelect::on_btnHelp_clicked()
143145

144146
}
145147

146-
void QgsServerSourceSelect::populateLayerList(QgsWmsProvider* wmsProvider)
148+
bool QgsServerSourceSelect::populateLayerList(QgsWmsProvider* wmsProvider)
147149
{
148150
std::vector<QgsWmsLayerProperty> layers;
149151

150-
layers = wmsProvider->supportedLayers();
152+
if (!wmsProvider->supportedLayers(layers))
153+
{
154+
return FALSE;
155+
}
151156

152157
lstLayers->clear();
153158

@@ -202,6 +207,8 @@ void QgsServerSourceSelect::populateLayerList(QgsWmsProvider* wmsProvider)
202207
{
203208
btnAdd->setEnabled(FALSE);
204209
}
210+
211+
return TRUE;
205212
}
206213

207214

@@ -344,18 +351,26 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
344351
// load the server data provider plugin
345352
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
346353

347-
wmsProvider =
354+
mWmsProvider =
348355
(QgsWmsProvider*) pReg->getProvider( "wms", m_connInfo );
349356

350-
if (wmsProvider)
357+
if (mWmsProvider)
351358
{
352-
connect(wmsProvider, SIGNAL(setStatus(QString)), this, SLOT(showStatusMessage(QString)));
359+
connect(mWmsProvider, SIGNAL(setStatus(QString)), this, SLOT(showStatusMessage(QString)));
353360

354-
populateLayerList(wmsProvider);
361+
if (!populateLayerList(mWmsProvider))
362+
{
363+
showError(mWmsProvider);
364+
}
355365
}
356366
else
357367
{
358-
// TODO: Let user know we couldn't initialise the WMS provider
368+
// Let user know we couldn't initialise the WMS provider
369+
QMessageBox::warning(
370+
this,
371+
tr("WMS Provider"),
372+
tr("Could not open the WMS Provider")
373+
);
359374
}
360375

361376
}
@@ -375,12 +390,12 @@ void QgsServerSourceSelect::on_btnAdd_clicked()
375390

376391
void QgsServerSourceSelect::on_btnChangeSpatialRefSys_clicked()
377392
{
378-
if (!wmsProvider)
393+
if (!mWmsProvider)
379394
{
380395
return;
381396
}
382397

383-
QSet<QString> crsFilter = wmsProvider->supportedCrsForLayers(m_selectedLayers);
398+
QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers(m_selectedLayers);
384399

385400
QgsLayerProjectionSelector * mySelector =
386401
new QgsLayerProjectionSelector(this);
@@ -393,15 +408,15 @@ void QgsServerSourceSelect::on_btnChangeSpatialRefSys_clicked()
393408

394409
if (mySelector->exec())
395410
{
396-
// TODO: assign EPSG back to the WMS provider
397411
m_Epsg = mySelector->getCurrentEpsg();
398412
}
399413
else
400414
{
401415
// NOOP
402416
}
403417

404-
labelSpatialRefSys->setText( mySelector->getCurrentProj4String() );
418+
labelCoordRefSys->setText( descriptionForEpsg(m_Epsg) );
419+
// labelCoordRefSys->setText( mySelector->getCurrentProj4String() );
405420

406421
delete mySelector;
407422

@@ -477,6 +492,18 @@ void QgsServerSourceSelect::on_lstLayers_selectionChanged()
477492
// If we got some selected items, let the user play with projections
478493
if (newSelectedLayers.count() > 0)
479494
{
495+
// Determine how many CRSs there are to play with
496+
if (mWmsProvider)
497+
{
498+
QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers(newSelectedLayers);
499+
500+
gbCRS->setTitle(
501+
QString( tr("Coordinate Reference System (%1 available)") )
502+
.arg( crsFilter.count() )
503+
);
504+
505+
}
506+
480507
btnChangeSpatialRefSys->setEnabled(TRUE);
481508
}
482509
else
@@ -510,6 +537,7 @@ QStringList QgsServerSourceSelect::selectedStylesForSelectedLayers()
510537
return m_selectedStylesForSelectedLayers;
511538
}
512539

540+
513541
QString QgsServerSourceSelect::selectedImageEncoding()
514542
{
515543
// TODO: Match this hard coded list to the list of formats Qt reports it can actually handle.
@@ -525,6 +553,7 @@ QString QgsServerSourceSelect::selectedImageEncoding()
525553

526554
}
527555

556+
528557
QString QgsServerSourceSelect::selectedCrs()
529558
{
530559
if (m_Epsg)
@@ -538,6 +567,7 @@ QString QgsServerSourceSelect::selectedCrs()
538567
}
539568
}
540569

570+
541571
void QgsServerSourceSelect::showStatusMessage(QString const & theMessage)
542572
{
543573
labelStatus->setText(theMessage);
@@ -547,4 +577,28 @@ void QgsServerSourceSelect::showStatusMessage(QString const & theMessage)
547577
}
548578

549579

580+
void QgsServerSourceSelect::showError(QgsWmsProvider * wms)
581+
{
582+
QMessageBox::warning(
583+
this,
584+
wms->errorCaptionString(),
585+
tr("Could not understand the response. The") + " " + wms->name() + " " +
586+
tr("provider said") + ":\n" +
587+
wms->errorString()
588+
);
589+
590+
}
591+
592+
593+
QString QgsServerSourceSelect::descriptionForEpsg(long epsg)
594+
{
595+
// We'll assume this function isn't called very often,
596+
// so please forgive the lack of caching of results
597+
598+
QgsSpatialRefSys qgisSrs = QgsSpatialRefSys(epsg, QgsSpatialRefSys::EPSG);
599+
600+
return qgisSrs.description();
601+
}
602+
603+
550604
// ENDS

src/gui/qgsserversourceselect.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,30 @@ public slots:
9696
//! Set status message to theMessage
9797
void showStatusMessage(QString const & theMessage);
9898

99+
//! show whatever error is exposed by the QgsWmsProvider.
100+
void showError(QgsWmsProvider * wms);
101+
99102

100103
private:
101104

102-
//! Populate the layer list - private for now.
103-
void populateLayerList(QgsWmsProvider* wmsProvider);
105+
/**
106+
* \brief Populate the layer list - private for now.
107+
*
108+
* \retval FALSE if the layers could not be retreived or parsed -
109+
* see mWmsProvider->errorString() for more info
110+
*/
111+
bool populateLayerList(QgsWmsProvider* wmsProvider);
104112

105113
//! Populate the image encoding button group - private for now.
106114
void populateImageEncodingGroup(QgsWmsProvider* wmsProvider);
107115

108116
//! Returns the common CRSs for the selected layers.
109117
std::set<QString> crsForSelection();
110118

119+
//! Returns a textual description for the EPSG number
120+
QString descriptionForEpsg(long epsg);
121+
122+
111123
QString m_connName;
112124
QString m_connInfo;
113125
QStringList m_selectedLayers;
@@ -126,7 +138,7 @@ public slots:
126138
QButtonGroup* m_imageFormatBtns;
127139

128140
//! The WMS provider that retreives information for this dialog
129-
QgsWmsProvider * wmsProvider;
141+
QgsWmsProvider * mWmsProvider;
130142

131143
static const int context_id = 710979116;
132144
};

src/gui/qgsspatialrefsys.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@
2626

2727
//--------------------------
2828

29-
QgsSpatialRefSys::QgsSpatialRefSys() : mMapUnits(QGis::UNKNOWN) {}
29+
QgsSpatialRefSys::QgsSpatialRefSys()
30+
: mMapUnits(QGis::UNKNOWN),
31+
mIsValidFlag(0)
32+
{
33+
// NOOP
34+
}
3035

31-
QgsSpatialRefSys::QgsSpatialRefSys(QString theWkt) : mMapUnits(QGis::UNKNOWN)
36+
QgsSpatialRefSys::QgsSpatialRefSys(QString theWkt)
37+
: mMapUnits(QGis::UNKNOWN),
38+
mIsValidFlag(0)
3239
{
3340
createFromWkt(theWkt);
3441
}
@@ -41,10 +48,15 @@ QgsSpatialRefSys::QgsSpatialRefSys(long theSrsId,
4148
long theSRID,
4249
long theEpsg,
4350
bool theGeoFlag)
44-
: mMapUnits(QGis::UNKNOWN)
45-
{}
51+
: mMapUnits(QGis::UNKNOWN),
52+
mIsValidFlag(0)
53+
{
54+
// NOOP
55+
}
4656

47-
QgsSpatialRefSys::QgsSpatialRefSys(const long theId, SRS_TYPE theType) : mMapUnits(QGis::UNKNOWN)
57+
QgsSpatialRefSys::QgsSpatialRefSys(const long theId, SRS_TYPE theType)
58+
: mMapUnits(QGis::UNKNOWN),
59+
mIsValidFlag(0)
4860
{
4961
createFromId(theId, theType);
5062
}

0 commit comments

Comments
 (0)