Skip to content
Permalink
Browse files

Merge pull request #1058 from elpaso/master

GetStyles split from GetStyle
  • Loading branch information
mhugent committed Jan 9, 2014
2 parents 9b0652f + 1f9c378 commit 1b0296935df239f0dce2545635d3b595fff33391
@@ -692,7 +692,7 @@ int main( int argc, char * argv[] )
delete theServer;
continue;
}
else if ( request.compare( "GetStyles", Qt::CaseInsensitive ) == 0 || request.compare( "GetStyle", Qt::CaseInsensitive ) == 0 ) // GetStyle for compatibility with earlier QGIS versions
else if ( request.compare( "GetStyle", Qt::CaseInsensitive ) == 0 ) // GetStyle for compatibility with earlier QGIS versions
{
try
{
@@ -708,6 +708,27 @@ int main( int argc, char * argv[] )
delete theServer;
continue;
}
else if ( request.compare( "GetStyles", Qt::CaseInsensitive ) == 0 )
{
// GetStyles is only defined for WMS1.1.1/SLD1.0
if ( version != "1.1.1") {
theRequestHandler->sendServiceException( QgsMapServiceException( "OperationNotSupported", "GetStyles method is only available in WMS version 1.1.1" ) );
} else {
try
{
QDomDocument doc = theServer->getStyles();
theRequestHandler->sendGetStyleResponse( doc );
}
catch ( QgsMapServiceException& ex )
{
theRequestHandler->sendServiceException( ex );
}
}

delete theRequestHandler;
delete theServer;
continue;
}
else if ( request.compare( "GetLegendGraphic", Qt::CaseInsensitive ) == 0 ||
request.compare( "GetLegendGraphics", Qt::CaseInsensitive ) == 0 )
// GetLegendGraphics for compatibility with earlier QGIS versions
@@ -774,3 +795,4 @@ int main( int argc, char * argv[] )
QgsDebugMsg( "************* all done ***************" );
return 0;
}

@@ -78,6 +78,8 @@ class QgsConfigParser

/**Returns the xml fragment of a style*/
virtual QDomDocument getStyle( const QString& styleName, const QString& layerName ) const = 0;
/**Returns the xml fragment of layer styles*/
virtual QDomDocument getStyles( QStringList& layerList ) const = 0;

/**Returns the names of the published wfs layers (not the ids as in wfsLayers() )*/
virtual QStringList wfsLayerNames() const { return QStringList(); }
@@ -1543,9 +1543,7 @@ void QgsProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocu
{
QgsVectorLayer* vLayer = static_cast<QgsVectorLayer*>( currentLayer );
const QSet<QString>& excludedAttributes = vLayer->excludeAttributesWMS();

//displayfield
layerElem.setAttribute( "displayField", vLayer->displayField() );
QString displayField = vLayer->displayField();

//attributes
QDomElement attributesElem = doc.createElement( "Attributes" );
@@ -1557,6 +1555,11 @@ void QgsProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocu
{
continue;
}
// field alias in case of displayField
if ( field.name() == displayField )
{
displayField = vLayer->attributeDisplayName( idx );
}
QDomElement attributeElem = doc.createElement( "Attribute" );
attributeElem.setAttribute( "name", vLayer->attributeDisplayName( idx ) );
attributeElem.setAttribute( "type", QVariant::typeToName( field.type() ) );
@@ -1569,6 +1572,8 @@ void QgsProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocu
attributeElem.setAttribute( "precision", field.precision() );
attributesElem.appendChild( attributeElem );
}
//displayfield
layerElem.setAttribute( "displayField", displayField );
layerElem.appendChild( attributesElem );
}
}
@@ -1932,6 +1937,58 @@ QDomDocument QgsProjectParser::getStyle( const QString& styleName, const QString
return myDocument;
}

QDomDocument QgsProjectParser::getStyles( QStringList& layerList ) const
{
QDomDocument myDocument = QDomDocument();

QDomNode header = myDocument.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" );
myDocument.appendChild( header );

// Create the root element
QDomElement root = myDocument.createElementNS( "http://www.opengis.net/sld", "StyledLayerDescriptor" );
root.setAttribute( "version", "1.1.0" );
root.setAttribute( "xsi:schemaLocation", "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" );
root.setAttribute( "xmlns:ogc", "http://www.opengis.net/ogc" );
root.setAttribute( "xmlns:se", "http://www.opengis.net/se" );
root.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
myDocument.appendChild( root );

for ( int i = 0; i < layerList.size(); i++)
{
QString layerName;
QString typeName;
layerName = layerList.at( i );
typeName = layerName.replace(" ", "_");
QList<QgsMapLayer*> currentLayerList = mapLayerFromTypeName( typeName );
if ( currentLayerList.size() < 1 )
{
throw QgsMapServiceException( "Error", QString( "The layer for the TypeName '%1' is not found" ).arg( layerName ) );
}
for ( int j = 0; j < currentLayerList.size(); j++)
{
QgsMapLayer* currentLayer = currentLayerList.at( j );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( !layer )
{
throw QgsMapServiceException( "Error", QString( "Could not get style because:\n%1" ).arg( "Non-vector layers not supported yet" ) );
}
// Create the NamedLayer element
QDomElement namedLayerNode = myDocument.createElement( "NamedLayer" );
root.appendChild( namedLayerNode );

QString errorMsg;
if ( !layer->writeSld( namedLayerNode, myDocument, errorMsg ) )
{
throw QgsMapServiceException( "Error", QString( "Could not get style because:\n%1" ).arg( errorMsg ) );
}
}
}
return myDocument;
}



QgsMapRenderer::OutputUnits QgsProjectParser::outputUnits() const
{
return QgsMapRenderer::Millimeters;
@@ -71,6 +71,9 @@ class QgsProjectParser: public QgsConfigParser

/**Returns the xml fragment of a style*/
virtual QDomDocument getStyle( const QString& styleName, const QString& layerName ) const;
/**Returns the xml fragment of layers styles*/
virtual QDomDocument getStyles( QStringList& layerList ) const;


/**Returns if output are MM or PIXEL*/
virtual QgsMapRenderer::OutputUnits outputUnits() const;
@@ -1412,6 +1412,29 @@ QDomDocument QgsSLDParser::getStyle( const QString& styleName, const QString& la
return styleDoc;
}

QDomDocument QgsSLDParser::getStyles( QStringList& layerList ) const
{
QDomDocument styleDoc;
for ( int i = 0; i < layerList.size(); i++)
{
QString layerName;
QString typeName;
layerName = layerList.at( i );
QDomElement userLayerElement = findUserLayerElement( layerName );
if ( userLayerElement.isNull() )
{
throw QgsMapServiceException( "LayerNotDefined", "Operation request is for a Layer not offered by the server." );
}
QDomNodeList userStyleList = userLayerElement.elementsByTagName( "UserStyle" );
for ( int j = 0; j < userStyleList.size(); j++)
{
QDomElement userStyleElement = userStyleList.item( i ).toElement();
styleDoc.appendChild( styleDoc.importNode( userStyleElement, true ) );
}
}
return styleDoc;
}

QString QgsSLDParser::layerNameFromUri( const QString& uri ) const
{
//file based?
@@ -77,6 +77,8 @@ class QgsSLDParser: public QgsConfigParser

/**Returns the xml fragment of a style*/
QDomDocument getStyle( const QString& styleName, const QString& layerName ) const;
/**Returns the xml fragment of layers styles*/
QDomDocument getStyles( QStringList& layerList ) const;

virtual void setParameterMap( const QMap<QString, QString>& parameterMap ) { mParameterMap = parameterMap; }

@@ -601,6 +601,24 @@ QDomDocument QgsWMSServer::getStyle()
return mConfigParser->getStyle( styleName, layerName );
}

// GetStyles is only defined for WMS1.1.1/SLD1.0
QDomDocument QgsWMSServer::getStyles()
{
QDomDocument doc;
if ( !mParameterMap.contains( "LAYERS" ) )
{
throw QgsMapServiceException( "LayerNotSpecified", "Layers is mandatory for GetStyles operation" );
}

QStringList layersList = mParameterMap[ "LAYERS" ].split( ",", QString::SkipEmptyParts );
if ( layersList.size() < 1 )
{
throw QgsMapServiceException( "LayerNotSpecified", "Layers is mandatory for GetStyles operation" );
}

return mConfigParser->getStyles( layersList );
}

QByteArray* QgsWMSServer::getPrint( const QString& formatString )
{
QStringList layersList, stylesList, layerIdList;
@@ -72,6 +72,8 @@ class QgsWMSServer
QImage* getMap();
/**Returns an SLD file with the style of the requested layer. Exception is raised in case of troubles :-)*/
QDomDocument getStyle();
/**Returns an SLD file with the styles of the requested layers. Exception is raised in case of troubles :-)*/
QDomDocument getStyles();

/**Returns printed page as binary
@param formatString out: format of the print output (e.g. pdf, svg, png, ...)

0 comments on commit 1b02969

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