Skip to content

Commit

Permalink
More WMS improvements:
Browse files Browse the repository at this point in the history
* 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@4979 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Mar 7, 2006
1 parent e036c9b commit c628d6e
Show file tree
Hide file tree
Showing 8 changed files with 469 additions and 87 deletions.
6 changes: 6 additions & 0 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -94,18 +94,24 @@ class QgsRasterDataProvider : public QgsDataProvider
virtual QString getMetadata() = 0;

/**
* \brief Returns the caption error text for the last error in this provider
*
* If an operation returns 0 (e.g. draw()), this function
* returns the text of the error associated with the failure.
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*
*/
virtual QString errorCaptionString() = 0;

/**
* \brief Returns the verbose error text for the last error in this provider
*
* If an operation returns 0 (e.g. draw()), this function
* returns the text of the error associated with the failure.
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*
*/
virtual QString errorString() = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsmaplayer.h
Expand Up @@ -290,15 +290,15 @@ class QgsMapLayer : public QObject
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*/
QString errorCaptionString();
virtual QString errorCaptionString();

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


public slots:
Expand Down
88 changes: 71 additions & 17 deletions src/gui/qgsserversourceselect.cpp
Expand Up @@ -35,11 +35,14 @@

#include <iostream>

static long DEFAULT_WMS_EPSG = 4326; // WGS 84


QgsServerSourceSelect::QgsServerSourceSelect(QgisApp * app, QWidget * parent, Qt::WFlags fl)
: QDialog(parent, fl),
qgisApp(app),
wmsProvider(0),
m_Epsg(0)
mWmsProvider(0),
m_Epsg(DEFAULT_WMS_EPSG)
{
setupUi(this);
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
Expand All @@ -61,12 +64,11 @@ QgsServerSourceSelect::QgsServerSourceSelect(QgisApp * app, QWidget * parent, Qt
hbox->addStretch();
btnGrpImageEncoding->setLayout(hbox);

// set up the WMS connections we already know about
populateConnectionList();
// connect the double-click signal to the addSingleLayer slot in the parent

//disable the 'where clause' box for 0.4 release
// groupBox3->hide();

// set up the default WMS Coordinate Reference System
labelCoordRefSys->setText( descriptionForEpsg(m_Epsg) );
}

QgsServerSourceSelect::~QgsServerSourceSelect()
Expand Down Expand Up @@ -143,11 +145,14 @@ void QgsServerSourceSelect::on_btnHelp_clicked()

}

void QgsServerSourceSelect::populateLayerList(QgsWmsProvider* wmsProvider)
bool QgsServerSourceSelect::populateLayerList(QgsWmsProvider* wmsProvider)
{
std::vector<QgsWmsLayerProperty> layers;

layers = wmsProvider->supportedLayers();
if (!wmsProvider->supportedLayers(layers))
{
return FALSE;
}

lstLayers->clear();

Expand Down Expand Up @@ -202,6 +207,8 @@ void QgsServerSourceSelect::populateLayerList(QgsWmsProvider* wmsProvider)
{
btnAdd->setEnabled(FALSE);
}

return TRUE;
}


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

wmsProvider =
mWmsProvider =
(QgsWmsProvider*) pReg->getProvider( "wms", m_connInfo );

if (wmsProvider)
if (mWmsProvider)
{
connect(wmsProvider, SIGNAL(setStatus(QString)), this, SLOT(showStatusMessage(QString)));
connect(mWmsProvider, SIGNAL(setStatus(QString)), this, SLOT(showStatusMessage(QString)));

populateLayerList(wmsProvider);
if (!populateLayerList(mWmsProvider))
{
showError(mWmsProvider);
}
}
else
{
// TODO: Let user know we couldn't initialise the WMS provider
// Let user know we couldn't initialise the WMS provider
QMessageBox::warning(
this,
tr("WMS Provider"),
tr("Could not open the WMS Provider")
);
}

}
Expand All @@ -375,12 +390,12 @@ void QgsServerSourceSelect::on_btnAdd_clicked()

void QgsServerSourceSelect::on_btnChangeSpatialRefSys_clicked()
{
if (!wmsProvider)
if (!mWmsProvider)
{
return;
}

QSet<QString> crsFilter = wmsProvider->supportedCrsForLayers(m_selectedLayers);
QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers(m_selectedLayers);

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

if (mySelector->exec())
{
// TODO: assign EPSG back to the WMS provider
m_Epsg = mySelector->getCurrentEpsg();
}
else
{
// NOOP
}

labelSpatialRefSys->setText( mySelector->getCurrentProj4String() );
labelCoordRefSys->setText( descriptionForEpsg(m_Epsg) );
// labelCoordRefSys->setText( mySelector->getCurrentProj4String() );

delete mySelector;

Expand Down Expand Up @@ -477,6 +492,18 @@ void QgsServerSourceSelect::on_lstLayers_selectionChanged()
// If we got some selected items, let the user play with projections
if (newSelectedLayers.count() > 0)
{
// Determine how many CRSs there are to play with
if (mWmsProvider)
{
QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers(newSelectedLayers);

gbCRS->setTitle(
QString( tr("Coordinate Reference System (%1 available)") )
.arg( crsFilter.count() )
);

}

btnChangeSpatialRefSys->setEnabled(TRUE);
}
else
Expand Down Expand Up @@ -510,6 +537,7 @@ QStringList QgsServerSourceSelect::selectedStylesForSelectedLayers()
return m_selectedStylesForSelectedLayers;
}


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

}


QString QgsServerSourceSelect::selectedCrs()
{
if (m_Epsg)
Expand All @@ -538,6 +567,7 @@ QString QgsServerSourceSelect::selectedCrs()
}
}


void QgsServerSourceSelect::showStatusMessage(QString const & theMessage)
{
labelStatus->setText(theMessage);
Expand All @@ -547,4 +577,28 @@ void QgsServerSourceSelect::showStatusMessage(QString const & theMessage)
}


void QgsServerSourceSelect::showError(QgsWmsProvider * wms)
{
QMessageBox::warning(
this,
wms->errorCaptionString(),
tr("Could not understand the response. The") + " " + wms->name() + " " +
tr("provider said") + ":\n" +
wms->errorString()
);

}


QString QgsServerSourceSelect::descriptionForEpsg(long epsg)
{
// We'll assume this function isn't called very often,
// so please forgive the lack of caching of results

QgsSpatialRefSys qgisSrs = QgsSpatialRefSys(epsg, QgsSpatialRefSys::EPSG);

return qgisSrs.description();
}


// ENDS
18 changes: 15 additions & 3 deletions src/gui/qgsserversourceselect.h
Expand Up @@ -96,18 +96,30 @@ public slots:
//! Set status message to theMessage
void showStatusMessage(QString const & theMessage);

//! show whatever error is exposed by the QgsWmsProvider.
void showError(QgsWmsProvider * wms);


private:

//! Populate the layer list - private for now.
void populateLayerList(QgsWmsProvider* wmsProvider);
/**
* \brief Populate the layer list - private for now.
*
* \retval FALSE if the layers could not be retreived or parsed -
* see mWmsProvider->errorString() for more info
*/
bool populateLayerList(QgsWmsProvider* wmsProvider);

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

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

//! Returns a textual description for the EPSG number
QString descriptionForEpsg(long epsg);


QString m_connName;
QString m_connInfo;
QStringList m_selectedLayers;
Expand All @@ -126,7 +138,7 @@ public slots:
QButtonGroup* m_imageFormatBtns;

//! The WMS provider that retreives information for this dialog
QgsWmsProvider * wmsProvider;
QgsWmsProvider * mWmsProvider;

static const int context_id = 710979116;
};
Expand Down
22 changes: 17 additions & 5 deletions src/gui/qgsspatialrefsys.cpp
Expand Up @@ -26,9 +26,16 @@

//--------------------------

QgsSpatialRefSys::QgsSpatialRefSys() : mMapUnits(QGis::UNKNOWN) {}
QgsSpatialRefSys::QgsSpatialRefSys()
: mMapUnits(QGis::UNKNOWN),
mIsValidFlag(0)
{
// NOOP
}

QgsSpatialRefSys::QgsSpatialRefSys(QString theWkt) : mMapUnits(QGis::UNKNOWN)
QgsSpatialRefSys::QgsSpatialRefSys(QString theWkt)
: mMapUnits(QGis::UNKNOWN),
mIsValidFlag(0)
{
createFromWkt(theWkt);
}
Expand All @@ -41,10 +48,15 @@ QgsSpatialRefSys::QgsSpatialRefSys(long theSrsId,
long theSRID,
long theEpsg,
bool theGeoFlag)
: mMapUnits(QGis::UNKNOWN)
{}
: mMapUnits(QGis::UNKNOWN),
mIsValidFlag(0)
{
// NOOP
}

QgsSpatialRefSys::QgsSpatialRefSys(const long theId, SRS_TYPE theType) : mMapUnits(QGis::UNKNOWN)
QgsSpatialRefSys::QgsSpatialRefSys(const long theId, SRS_TYPE theType)
: mMapUnits(QGis::UNKNOWN),
mIsValidFlag(0)
{
createFromId(theId, theType);
}
Expand Down

0 comments on commit c628d6e

Please sign in to comment.