Skip to content
Permalink
Browse files
Partial fix for #38 (Saved WMS layers do not reload).
Now, the fact the WMS raster provider was used, the layer names, layer styles and image formatting is stored in the project file (and restores OK).  However upon initial testing the extent doesn't appear to be restored.  I will need to address that later.



git-svn-id: http://svn.osgeo.org/qgis/trunk@5603 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Jul 16, 2006
1 parent e06bdce commit 3916b1ccc3dae297e69f4b199bdedc0d525bb09c
Showing with 165 additions and 17 deletions.
  1. +15 −4 src/core/qgsdataprovider.h
  2. +6 −1 src/core/qgsrasterdataprovider.h
  3. +14 −2 src/providers/wms/qgswmsprovider.cpp
  4. +9 −1 src/providers/wms/qgswmsprovider.h
  5. +119 −7 src/raster/qgsrasterlayer.cpp
  6. +2 −2 src/raster/qgsrasterlayer.h
@@ -199,19 +199,30 @@ class QgsDataProvider : public QObject
{
return QString::null;
}

/**
* Sub-layers handled by this provider, in order from bottom to top
*
* Sub-layers are used when the provider's source can combine layers
* it knows about in some way before it hands them off to the provider.
*/
virtual QStringList subLayers()
virtual QStringList subLayers() const
{
return QStringList(); // Empty
}



/**
* Sub-layer styles for each sub-layer handled by this provider,
* in order from bottom to top
*
* Sub-layer styles are used to abstract the way the provider's source can symbolise
* layers in some way at the server, before it serves them to the provider.
*/
virtual QStringList subLayerStyles() const
{
return QStringList(); // Empty
}

/** return the number of layers for the current data source
@note
@@ -70,11 +70,16 @@ class QgsRasterDataProvider : public QgsDataProvider
//! get raster image encodings supported by (e.g.) the WMS Server, expressed as MIME types
virtual QStringList supportedImageEncodings() = 0;

/**
* Get the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server
*/
virtual QString imageEncoding() const = 0;

/**
* Set the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server
*/
virtual void setImageEncoding(QString const & mimeType) = 0;

/**
* Set the image projection (in WMS CRS format) used in the transfer from (e.g.) the WMS server
*/
@@ -319,6 +319,12 @@ void QgsWmsProvider::setSubLayerVisibility(QString const & name, bool vis)
}


QString QgsWmsProvider::imageEncoding() const
{
return imageMimeType;
}


void QgsWmsProvider::setImageEncoding(QString const & mimeType)
{
#ifdef QGISDEBUG
@@ -1882,13 +1888,19 @@ QStringList QgsWmsProvider::supportedImageEncodings()
return mCapabilities.capability.request.getMap.format;
}

QStringList QgsWmsProvider::subLayers()

QStringList QgsWmsProvider::subLayers() const
{
return activeSubLayers;
}


QStringList QgsWmsProvider::subLayerStyles() const
{
return activeSubStyles;
}


void QgsWmsProvider::showStatusMessage(QString const & theMessage)
{
// Pass-through
@@ -404,6 +404,11 @@ class QgsWmsProvider : public QgsRasterDataProvider
*/
void setSubLayerVisibility(QString const & name, bool vis);

/**
* Get the image encoding (as a MIME type) used in the transfer from the WMS server
*/
QString imageEncoding() const;

/**
* Set the image encoding (as a MIME type) used in the transfer from the WMS server
*/
@@ -478,7 +483,10 @@ class QgsWmsProvider : public QgsRasterDataProvider
* layers in some way at the server, before it serves them to this
* WMS client.
*/
QStringList subLayers();
QStringList subLayers() const;

QStringList subLayerStyles() const;


// TODO: Get the WMS connection

@@ -3595,9 +3595,9 @@ QPixmap QgsRasterLayer::getDetailedLegendQPixmap(int theLabelCountInt=3)

// Useful for Provider mode

QStringList QgsRasterLayer::subLayers()
QStringList QgsRasterLayer::subLayers() const
{

if (dataProvider)
{
return dataProvider->subLayers();
@@ -4482,13 +4482,71 @@ Raster layer project file XML of form:
bool QgsRasterLayer::readXML_( QDomNode & layer_node )
{
//! @NOTE Make sure to read the file first so stats etc are initialised properly!

if ( ! readFile( source() ) ) // Data source name set in
// QgsMapLayer::readXML()

//process provider key
QDomNode pkeyNode = layer_node.namedItem("provider");

if (pkeyNode.isNull())
{
QgsLogger::warning(QString(__FILE__) + ":" + QString(__LINE__) + " unable to read from raster file " + source());
return false;
mProviderKey = "";
}
else
{
QDomElement pkeyElt = pkeyNode.toElement();
mProviderKey = pkeyElt.text();
}

// Open the raster source based on provider and datasource

if (!mProviderKey.isEmpty())
{
// Go down the raster-data-provider paradigm

// Collect provider-specific information

QDomNode rpNode = layer_node.namedItem("rasterproperties");

// Collect sublayer names and styles
QStringList layers;
QStringList styles;
QDomElement layerElement = rpNode.firstChildElement("wmsSublayer");
while (!layerElement.isNull())
{
// TODO: sublayer visibility - post-0.8 release timeframe

// collect name for the sublayer
layers += layerElement.namedItem("name").toElement().text();

// collect style for the sublayer
styles += layerElement.namedItem("style").toElement().text();

layerElement = layerElement.nextSiblingElement("wmsSublayer");
}

// Collect format
QString format = rpNode.namedItem("wmsFormat").toElement().text();

// Convert CRS from the coordinate transformation node
// which was collected earlier in QgsMapLayer::readXML()
QString crs = QString("EPSG:%1")
.arg(mCoordinateTransform->sourceSRS().epsg());

setDataProvider( mProviderKey, layers, styles, format, crs );
}
else
{
// Go down the monolithic-gdal-provider paradigm

if (!readFile(source())) // Data source name set in
// QgsMapLayer::readXML()
{
QgsLogger::warning(QString(__FILE__) + ":" + QString(__LINE__) +
" unable to read from raster file " + source());
return false;
}

}

QDomNode mnl = layer_node.namedItem("rasterproperties");

QDomNode snode = mnl.namedItem("showDebugOverlayFlag");
@@ -4552,10 +4610,64 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )

mapLayerNode.setAttribute( "type", "raster" );

// add provider node

QDomElement provider = document.createElement( "provider" );
QDomText providerText = document.createTextNode( mProviderKey );
provider.appendChild( providerText );
layer_node.appendChild( provider );

// <rasterproperties>
QDomElement rasterPropertiesElement = document.createElement( "rasterproperties" );
mapLayerNode.appendChild( rasterPropertiesElement );

if (!mProviderKey.isEmpty())
{
QStringList sl = subLayers();
QStringList sls = dataProvider->subLayerStyles();

QStringList::const_iterator layerStyle = sls.begin();

// <rasterproperties><wmsSublayer>
for ( QStringList::const_iterator layerName = sl.begin();
layerName != sl.end();
++layerName )
{

#ifdef QGISDEBUG
std::cout << "<rasterproperties><wmsSublayer> " << layerName->toLocal8Bit().data() << std::endl;
#endif

QDomElement sublayerElement = document.createElement("wmsSublayer");

// TODO: sublayer visibility - post-0.8 release timeframe

// <rasterproperties><wmsSublayer><name>
QDomElement sublayerNameElement = document.createElement("name");
QDomText sublayerNameText = document.createTextNode(*layerName);
sublayerNameElement.appendChild(sublayerNameText);
sublayerElement.appendChild(sublayerNameElement);

// <rasterproperties><wmsSublayer><style>
QDomElement sublayerStyleElement = document.createElement("style");
QDomText sublayerStyleText = document.createTextNode(*layerStyle);
sublayerStyleElement.appendChild(sublayerStyleText);
sublayerElement.appendChild(sublayerStyleElement);

rasterPropertiesElement.appendChild(sublayerElement);

// This assumes there are exactly the same number of "layerName"s as there are "layerStyle"s
++layerStyle;
}

// <rasterproperties><wmsFormat>
QDomElement formatElement = document.createElement("wmsFormat");
QDomText formatText =
document.createTextNode(dataProvider->imageEncoding());
formatElement.appendChild(formatText);
rasterPropertiesElement.appendChild(formatElement);
}

// <showDebugOverlayFlag>
QDomElement showDebugOverlayFlagElement = document.createElement( "showDebugOverlayFlag" );

@@ -704,7 +704,7 @@ class QgsRasterLayer : public QgsMapLayer
* (Useful for providers that manage their own layers, such as WMS)
*
*/
QStringList subLayers();
QStringList subLayers() const;

/**
* Reorders the *previously selected* sublayers of this layer from bottom to top
@@ -1078,7 +1078,7 @@ public slots:
//! pointer for loading the provider library
QLibrary *myLib;

//! Pointer to data provider derived from the abastract base class QgsDataProvider
//! Pointer to data provider derived from the abstract base class QgsDataProvider
QgsRasterDataProvider *dataProvider;

/**Flag indicating wheter the layer is in editing mode or not*/

0 comments on commit 3916b1c

Please sign in to comment.