Skip to content

Commit 25cdea1

Browse files
committedJan 6, 2014
Initial GetStyles implementation, still segfaults
1 parent 0ae2b1a commit 25cdea1

File tree

9 files changed

+89
-1
lines changed

9 files changed

+89
-1
lines changed
 

‎src/mapserver/qgis_map_serv.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ int main( int argc, char * argv[] )
692692
delete theServer;
693693
continue;
694694
}
695-
else if ( request.compare( "GetStyles", Qt::CaseInsensitive ) == 0 || request.compare( "GetStyle", Qt::CaseInsensitive ) == 0 ) // GetStyle for compatibility with earlier QGIS versions
695+
else if ( request.compare( "GetStyle", Qt::CaseInsensitive ) == 0 ) // GetStyle for compatibility with earlier QGIS versions
696696
{
697697
try
698698
{
@@ -708,6 +708,27 @@ int main( int argc, char * argv[] )
708708
delete theServer;
709709
continue;
710710
}
711+
else if ( request.compare( "GetStyles", Qt::CaseInsensitive ) == 0 )
712+
{
713+
// GetStyles is only defined for WMS1.1.1/SLD1.0
714+
if ( version != "1.1.1") {
715+
theRequestHandler->sendServiceException( QgsMapServiceException( "OperationNotSupported", "GetStyles is only available in WMS version 1.1.1" ) );
716+
} else {
717+
try
718+
{
719+
QDomDocument doc = theServer->getStyles();
720+
theRequestHandler->sendGetStyleResponse( doc );
721+
}
722+
catch ( QgsMapServiceException& ex )
723+
{
724+
theRequestHandler->sendServiceException( ex );
725+
}
726+
}
727+
728+
delete theRequestHandler;
729+
delete theServer;
730+
continue;
731+
}
711732
else if ( request.compare( "GetLegendGraphic", Qt::CaseInsensitive ) == 0 ||
712733
request.compare( "GetLegendGraphics", Qt::CaseInsensitive ) == 0 )
713734
// GetLegendGraphics for compatibility with earlier QGIS versions

‎src/mapserver/qgsconfigparser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class QgsConfigParser
7878

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

8284
/**Returns the names of the published wfs layers (not the ids as in wfsLayers() )*/
8385
virtual QStringList wfsLayerNames() const { return QStringList(); }

‎src/mapserver/qgsprojectparser.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,14 @@ QDomDocument QgsProjectParser::getStyle( const QString& styleName, const QString
19241924
return myDocument;
19251925
}
19261926

1927+
QDomDocument QgsProjectParser::getStyles( QStringList& layerList ) const
1928+
{
1929+
QDomDocument myDocument = QDomDocument();
1930+
return myDocument;
1931+
}
1932+
1933+
1934+
19271935
QgsMapRenderer::OutputUnits QgsProjectParser::outputUnits() const
19281936
{
19291937
return QgsMapRenderer::Millimeters;

‎src/mapserver/qgsprojectparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class QgsProjectParser: public QgsConfigParser
7171

7272
/**Returns the xml fragment of a style*/
7373
virtual QDomDocument getStyle( const QString& styleName, const QString& layerName ) const;
74+
/**Returns the xml fragment of layers styles*/
75+
virtual QDomDocument getStyles( QStringList& layerList ) const;
76+
7477

7578
/**Returns if output are MM or PIXEL*/
7679
virtual QgsMapRenderer::OutputUnits outputUnits() const;

‎src/mapserver/qgssldparser.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,36 @@ QDomDocument QgsSLDParser::getStyle( const QString& styleName, const QString& la
14121412
return styleDoc;
14131413
}
14141414

1415+
// TODO: support multiple layers
1416+
QDomDocument QgsSLDParser::getStyles( QStringList& layerList ) const
1417+
{
1418+
if ( layerList.size() < 1)
1419+
{
1420+
throw QgsMapServiceException( "LayerNotDefined", "Layer list is empty." );
1421+
}
1422+
1423+
// TODO: loop
1424+
QString layerName = layerList.at(0);
1425+
1426+
QDomElement userLayerElement = findUserLayerElement( layerName );
1427+
1428+
if ( userLayerElement.isNull() )
1429+
{
1430+
throw QgsMapServiceException( "LayerNotDefined", "Operation request is for a Layer not offered by the server." );
1431+
}
1432+
1433+
QDomElement userStyleElement = findUserStyleElement( userLayerElement, "" );
1434+
1435+
if ( userStyleElement.isNull() )
1436+
{
1437+
throw QgsMapServiceException( "StyleNotDefined", "Operation request references a Style not offered by the server." );
1438+
}
1439+
1440+
QDomDocument styleDoc;
1441+
styleDoc.appendChild( styleDoc.importNode( userStyleElement, true ) );
1442+
return styleDoc;
1443+
}
1444+
14151445
QString QgsSLDParser::layerNameFromUri( const QString& uri ) const
14161446
{
14171447
//file based?

‎src/mapserver/qgssldparser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class QgsSLDParser: public QgsConfigParser
7777

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

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

‎src/mapserver/qgssldparser.h.gch

181 Bytes
Binary file not shown.

‎src/mapserver/qgswmsserver.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,26 @@ QDomDocument QgsWMSServer::getStyle()
601601
return mConfigParser->getStyle( styleName, layerName );
602602
}
603603

604+
// GetStyles is only defined for WMS1.1.1/SLD1.0
605+
QDomDocument QgsWMSServer::getStyles()
606+
{
607+
608+
QDomDocument doc;
609+
610+
if ( !mParameterMap.contains( "LAYERS" ) )
611+
{
612+
throw QgsMapServiceException( "LayerNotSpecified", "Layers is mandatory for GetStyles operation" );
613+
}
614+
615+
QStringList layersList = mParameterMap[ "LAYERS" ].split( ",", QString::SkipEmptyParts );
616+
if ( layersList.size() < 1 )
617+
{
618+
throw QgsMapServiceException( "LayerNotSpecified", "Layers is mandatory for GetStyles operation" );
619+
}
620+
621+
return mConfigParser->getStyles( layersList );
622+
}
623+
604624
QByteArray* QgsWMSServer::getPrint( const QString& formatString )
605625
{
606626
QStringList layersList, stylesList, layerIdList;

‎src/mapserver/qgswmsserver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class QgsWMSServer
7272
QImage* getMap();
7373
/**Returns an SLD file with the style of the requested layer. Exception is raised in case of troubles :-)*/
7474
QDomDocument getStyle();
75+
/**Returns an SLD file with the styles of the requested layers. Exception is raised in case of troubles :-)*/
76+
QDomDocument getStyles();
7577

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

0 commit comments

Comments
 (0)
Please sign in to comment.