Skip to content
Permalink
Browse files

Another WMS improvement:

* The Identify map tool is now disabled if none of the layers from the WMS server are "queryable".  This saves the WMS server the bother of returning an error if we tried to Identify anyway.
Coding:
* The QgsRasterDataProvider now has the concept of "capabilities" like the QgsVectorDataProvider (not to be confused with Capabilities in the WMS Standard).  The only capability dealt with at this time is the ability to Identify.



git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5080 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au
morb_au committed Mar 23, 2006
1 parent 05af397 commit 9094e48f9bb6826a7a154856395ad34b2ee233be
@@ -30,3 +30,24 @@ QgsRasterDataProvider::QgsRasterDataProvider( QString const & uri )
}


QString QgsRasterDataProvider::capabilitiesString() const
{
QStringList abilitiesList;

int abilities = capabilities();

if (abilities & QgsRasterDataProvider::Identify)
{
abilitiesList += "Identify";
#ifdef QGISDEBUG
std::cerr << "QgsRasterDataProvider::capabilitiesString "
<< "Identify" << std::endl;
#endif

}

return abilitiesList.join(", ");
}


// ENDS
@@ -43,9 +43,17 @@ class QgsRasterDataProvider : public QgsDataProvider
{

Q_OBJECT

public:

//! If you add to this, please also add to capabilitiesString()
enum Capability
{
NoCapabilities = 0,
Identify = 1
// Capability2 = 1 << 1, , etc
};


QgsRasterDataProvider();

@@ -78,9 +86,21 @@ class QgsRasterDataProvider : public QgsDataProvider
*/
virtual QImage* draw(QgsRect const & viewExtent, int pixelWidth, int pixelHeight) = 0;




/** Returns a bitmask containing the supported capabilities
Note, some capabilities may change depending on whether
a spatial filter is active on this provider, so it may
be prudent to check this value per intended operation.
*/
virtual int capabilities() const
{
return QgsRasterDataProvider::NoCapabilities;
}

/**
* Returns the above in friendly format.
*/
QString capabilitiesString() const;


// TODO: Get the supported formats by this provider

@@ -4863,6 +4863,8 @@ void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
{
mActionSelect->setEnabled(true);
mActionOpenTable->setEnabled(true);
mActionIdentify->setEnabled(true);

const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>(layer);
const QgsVectorDataProvider* dprovider = vlayer->getDataProvider();
if(vlayer)
@@ -4950,6 +4952,21 @@ void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
mActionAddVertex->setEnabled(false);
mActionDeleteVertex->setEnabled(false);
mActionMoveVertex->setEnabled(false);

const QgsRasterLayer* vlayer = dynamic_cast<const QgsRasterLayer*> (layer);
const QgsRasterDataProvider* dprovider = vlayer->getDataProvider();
if (vlayer)
{
// does provider allow the identify map tool?
if (dprovider->capabilities() & QgsRasterDataProvider::Identify)
{
mActionIdentify->setEnabled(TRUE);
}
else
{
mActionIdentify->setEnabled(FALSE);
}
}
}
}

@@ -675,7 +675,7 @@ bool QgsWmsProvider::retrieveServerCapabilities(bool forceRefresh)
#endif

bool domOK;
domOK = parseCapabilitiesDOM(httpcapabilitiesresponse, capabilities);
domOK = parseCapabilitiesDOM(httpcapabilitiesresponse, mCapabilities);

if (!domOK)
{
@@ -1592,6 +1592,8 @@ void QgsWmsProvider::parseLayer(QDomElement const & e, QgsWmsLayerProperty& laye
// We have all the information we need to properly evaluate a layer definition
// TODO: Save this somewhere

// Store if the layer is queryable
mQueryableForLayer[ layerProperty.name ] = layerProperty.queryable;

// Store the available Coordinate Reference Systems for the layer so that it
// can be combined with others later in supportedCrsForLayers()
@@ -1832,7 +1834,7 @@ QString QgsWmsProvider::wmsVersion()

QStringList QgsWmsProvider::supportedImageEncodings()
{
return capabilities.capability.request.getMap.format;
return mCapabilities.capability.request.getMap.format;
}


@@ -1842,18 +1844,6 @@ QStringList QgsWmsProvider::subLayers()
}


/*
int QgsWmsProvider::capabilities() const
{
return ( QgsVectorDataProvider::AddFeatures |
QgsVectorDataProvider::DeleteFeatures |
QgsVectorDataProvider::ChangeAttributeValues |
QgsVectorDataProvider::AddAttributes |
QgsVectorDataProvider::DeleteAttributes );
}
*/


void QgsWmsProvider::showStatusMessage(QString const & theMessage)
{
// Pass-through
@@ -1929,6 +1919,48 @@ bool QgsWmsProvider::calculateExtent()

}


int QgsWmsProvider::capabilities() const
{
int capability = 0;
bool canIdentify = FALSE;

#ifdef QGISDEBUG
std::cout << "QgsWmsProvider::capabilities: entering." << std::endl;
#endif

// Test for the ability to use the Identify map tool
for ( QStringList::const_iterator it = activeSubLayers.begin();
it != activeSubLayers.end();
++it )
{
// Is sublayer visible?
if (TRUE == activeSubLayerVisibility.find( *it )->second)
{
// Is sublayer queryable?
if (TRUE == mQueryableForLayer.find( *it )->second)
{
#ifdef QGISDEBUG
std::cout << "QgsWmsProvider::capabilities: '" << (*it).toLocal8Bit().data() << "' is queryable." << std::endl;
#endif
canIdentify = TRUE;
}
}
}

// Collect all the test results into one bitmask
if (canIdentify)
{
capability = (capability | QgsRasterDataProvider::Identify);
}

#ifdef QGISDEBUG
std::cout << "QgsWmsProvider::capabilities: exiting with '" << capability << "'." << std::endl;
#endif
return capability;
}


QString QgsWmsProvider::getMetadata()
{

@@ -1956,31 +1988,31 @@ QString QgsWmsProvider::getMetadata()
myMetadataQString += tr("WMS Version");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.version;
myMetadataQString += mCapabilities.version;
myMetadataQString += "</td></tr>";

// Service Title
myMetadataQString += "<tr><td bgcolor=\"gray\">";
myMetadataQString += tr("Title");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.service.title;
myMetadataQString += mCapabilities.service.title;
myMetadataQString += "</td></tr>";

// Service Abstract
myMetadataQString += "<tr><td bgcolor=\"gray\">";
myMetadataQString += tr("Abstract");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.service.abstract;
myMetadataQString += mCapabilities.service.abstract;
myMetadataQString += "</td></tr>";

// Service Keywords
myMetadataQString += "<tr><td bgcolor=\"gray\">";
myMetadataQString += tr("Keywords");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.service.keywordList.join("<br />");
myMetadataQString += mCapabilities.service.keywordList.join("<br />");
myMetadataQString += "</td></tr>";

// Service Online Resource
@@ -1996,43 +2028,43 @@ QString QgsWmsProvider::getMetadata()
myMetadataQString += tr("Contact Person");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.service.contactInformation.contactPersonPrimary.contactPerson;
myMetadataQString += mCapabilities.service.contactInformation.contactPersonPrimary.contactPerson;
myMetadataQString += "<br />";
myMetadataQString += capabilities.service.contactInformation.contactPosition;
myMetadataQString += mCapabilities.service.contactInformation.contactPosition;
myMetadataQString += "<br />";
myMetadataQString += capabilities.service.contactInformation.contactPersonPrimary.contactOrganization;
myMetadataQString += mCapabilities.service.contactInformation.contactPersonPrimary.contactOrganization;
myMetadataQString += "</td></tr>";

// Service Fees
myMetadataQString += "<tr><td bgcolor=\"gray\">";
myMetadataQString += tr("Fees");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.service.fees;
myMetadataQString += mCapabilities.service.fees;
myMetadataQString += "</td></tr>";

// Service Access Constraints
myMetadataQString += "<tr><td bgcolor=\"gray\">";
myMetadataQString += tr("Access Constraints");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.service.accessConstraints;
myMetadataQString += mCapabilities.service.accessConstraints;
myMetadataQString += "</td></tr>";

// GetMap Request Formats
myMetadataQString += "<tr><td bgcolor=\"gray\">";
myMetadataQString += tr("Image Formats");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.capability.request.getMap.format.join("<br />");
myMetadataQString += mCapabilities.capability.request.getMap.format.join("<br />");
myMetadataQString += "</td></tr>";

// GetFeatureInfo Request Formats
myMetadataQString += "<tr><td bgcolor=\"gray\">";
myMetadataQString += tr("Identify Formats");
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"gray\">";
myMetadataQString += capabilities.capability.request.getFeatureInfo.format.join("<br />");
myMetadataQString += mCapabilities.capability.request.getFeatureInfo.format.join("<br />");
myMetadataQString += "</td></tr>";

// Layer Count (as managed by this provider)
@@ -486,15 +486,20 @@ class QgsWmsProvider : public QgsRasterDataProvider

// TODO: Get the table name associated with this provider instance

/**Returns a bitmask containing the supported capabilities*/
// int capabilities() const;
/** Returns a bitmask containing the supported capabilities
Note, some capabilities may change depending on which
sublayers are visible on this provider, so it may
be prudent to check this value per intended operation.
*/
int capabilities() const;

/**
* Get metadata in a format suitable for feeding directly
* into a subset of the GUI raster properties "Metadata" tab.
*/
QString getMetadata();


/**
* \brief Identify details from a WMS Server from the last screen update
*
@@ -732,7 +737,7 @@ public slots:
/**
* Parsed capabilities of the WMS Server
*/
QgsWmsCapabilitiesProperty capabilities;
QgsWmsCapabilitiesProperty mCapabilities;

/**
* layers hosted by the WMS Server
@@ -749,6 +754,12 @@ public slots:
*/
std::map<QString, std::vector<QString> > crsForLayer;

/**
* WMS "queryable" per layer
* Used in determining if the Identify map tool can be useful on the rendered WMS map layer.
*/
std::map<QString, bool> mQueryableForLayer;

/**
* Active sublayers managed by this provider in a draw function, in order from bottom to top
* (some may not be visible in a draw function, cf. activeSubLayerVisibility)
@@ -5239,4 +5239,16 @@ QString QgsRasterLayer::errorString()
}


QgsRasterDataProvider* QgsRasterLayer::getDataProvider()
{
return dataProvider;
}

const QgsRasterDataProvider* QgsRasterLayer::getDataProvider() const
{
return dataProvider;
}



// ENDS
@@ -783,6 +783,19 @@ class QgsRasterLayer : public QgsMapLayer
*/
QString errorString();

/** Returns the data provider
*
* \retval 0 if not using the data provider model (i.e. directly using GDAL)
*/
QgsRasterDataProvider* getDataProvider();

/** Returns the data provider in a const-correct manner
*
* \retval 0 if not using the data provider model (i.e. directly using GDAL)
*/
const QgsRasterDataProvider* getDataProvider() const;



public slots:
/** \brief Mutator for transparency level. Should be between 0 and 255 */

0 comments on commit 9094e48

Please sign in to comment.
You can’t perform that action at this time.