Skip to content

Commit

Permalink
Initial GetStyles implementation, still segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 6, 2014
1 parent 0ae2b1a commit 25cdea1
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/mapserver/qgis_map_serv.cpp
Expand Up @@ -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
{
Expand All @@ -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 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
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgsconfigparser.h
Expand Up @@ -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(); }
Expand Down
8 changes: 8 additions & 0 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -1924,6 +1924,14 @@ QDomDocument QgsProjectParser::getStyle( const QString& styleName, const QString
return myDocument;
}

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



QgsMapRenderer::OutputUnits QgsProjectParser::outputUnits() const
{
return QgsMapRenderer::Millimeters;
Expand Down
3 changes: 3 additions & 0 deletions src/mapserver/qgsprojectparser.h
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions src/mapserver/qgssldparser.cpp
Expand Up @@ -1412,6 +1412,36 @@ QDomDocument QgsSLDParser::getStyle( const QString& styleName, const QString& la
return styleDoc;
}

// TODO: support multiple layers
QDomDocument QgsSLDParser::getStyles( QStringList& layerList ) const
{
if ( layerList.size() < 1)
{
throw QgsMapServiceException( "LayerNotDefined", "Layer list is empty." );
}

// TODO: loop
QString layerName = layerList.at(0);

QDomElement userLayerElement = findUserLayerElement( layerName );

if ( userLayerElement.isNull() )
{
throw QgsMapServiceException( "LayerNotDefined", "Operation request is for a Layer not offered by the server." );
}

QDomElement userStyleElement = findUserStyleElement( userLayerElement, "" );

if ( userStyleElement.isNull() )
{
throw QgsMapServiceException( "StyleNotDefined", "Operation request references a Style not offered by the server." );
}

QDomDocument styleDoc;
styleDoc.appendChild( styleDoc.importNode( userStyleElement, true ) );
return styleDoc;
}

QString QgsSLDParser::layerNameFromUri( const QString& uri ) const
{
//file based?
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgssldparser.h
Expand Up @@ -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; }

Expand Down
Binary file added src/mapserver/qgssldparser.h.gch
Binary file not shown.
20 changes: 20 additions & 0 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -601,6 +601,26 @@ 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;
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgswmsserver.h
Expand Up @@ -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, ...)
Expand Down

0 comments on commit 25cdea1

Please sign in to comment.