Skip to content

Commit

Permalink
[Feature]: Add GetProjectSettings request to QGIS server to have more…
Browse files Browse the repository at this point in the history
… specific information about the project than in GetCapabilities
  • Loading branch information
Marco Hugentobler committed Sep 6, 2012
1 parent 652deba commit bd2af12
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 20 deletions.
13 changes: 9 additions & 4 deletions src/mapserver/qgis_map_serv.cpp
Expand Up @@ -409,17 +409,22 @@ int main( int argc, char * argv[] )
}

QString version = parameterMap.value( "VERSION", "1.3.0" );
bool getProjectSettings = ( request == "GetProjectSettings" );
if ( getProjectSettings )
{
version = "1.3.0"; //getProjectSettings extends WMS 1.3.0 capabilities
}

if ( request == "GetCapabilities" )
if ( request == "GetCapabilities" || getProjectSettings )
{
const QDomDocument* capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath, version );
const QDomDocument* capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath, getProjectSettings ? "projectSettings" : version );
if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
{
QgsDebugMsg( "Capabilities document not found in cache" );
QDomDocument doc;
try
{
doc = theServer->getCapabilities( version );
doc = theServer->getCapabilities( version, getProjectSettings );
}
catch ( QgsMapServiceException& ex )
{
Expand All @@ -428,7 +433,7 @@ int main( int argc, char * argv[] )
delete theServer;
continue;
}
capabilitiesCache.insertCapabilitiesDocument( configFilePath, version, &doc );
capabilitiesCache.insertCapabilitiesDocument( configFilePath, getProjectSettings ? "projectSettings" : version, &doc );
capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath, version );
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/mapserver/qgsconfigparser.h
Expand Up @@ -39,8 +39,9 @@ class QgsConfigParser

virtual ~QgsConfigParser();

/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.*/
virtual void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;
/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
@param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*/
virtual void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc, bool fullProjectSettings = false ) const = 0;

virtual void featureTypeList( QDomElement& parentElement, QDomDocument& doc ) const = 0;

Expand Down
43 changes: 38 additions & 5 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -87,7 +87,7 @@ int QgsProjectParser::numberOfLayers() const
return mProjectLayerElements.size();
}

void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc, bool fullProjectSettings ) const
{
QStringList nonIdentifiableLayers = identifyDisabledLayers();

Expand Down Expand Up @@ -133,7 +133,7 @@ void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement,

QDomElement legendElem = mXMLDoc->documentElement().firstChildElement( "legend" );

addLayers( doc, layerParentElem, legendElem, layerMap, nonIdentifiableLayers );
addLayers( doc, layerParentElem, legendElem, layerMap, nonIdentifiableLayers, fullProjectSettings );

parentElement.appendChild( layerParentElem );
combineExtentAndCrsOfGroupChildren( layerParentElem, doc );
Expand Down Expand Up @@ -216,7 +216,8 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
QDomElement &parentElem,
const QDomElement &legendElem,
const QMap<QString, QgsMapLayer *> &layerMap,
const QStringList &nonIdentifiableLayers ) const
const QStringList &nonIdentifiableLayers,
bool fullProjectSettings ) const
{
QDomNodeList legendChildren = legendElem.childNodes();
for ( int i = 0; i < legendChildren.size(); ++i )
Expand Down Expand Up @@ -268,12 +269,12 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
pLayerMap.insert( layerId( elem ), p->createLayerFromElement( elem ) );
}

p->addLayers( doc, layerElem, embeddedGroupElem, pLayerMap, pIdDisabled );
p->addLayers( doc, layerElem, embeddedGroupElem, pLayerMap, pIdDisabled, fullProjectSettings );
}
}
else //normal (not embedded) legend group
{
addLayers( doc, layerElem, currentChildElem, layerMap, nonIdentifiableLayers );
addLayers( doc, layerElem, currentChildElem, layerMap, nonIdentifiableLayers, fullProjectSettings );
}

// combine bounding boxes of children (groups/layers)
Expand Down Expand Up @@ -349,6 +350,11 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
styleElem.appendChild( styleNameElem );
styleElem.appendChild( styleTitleElem );
layerElem.appendChild( styleElem );

if ( fullProjectSettings )
{
addLayerProjectSettings( layerElem, doc, currentLayer );
}
}
else
{
Expand All @@ -360,6 +366,33 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
}
}

void QgsProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocument& doc, QgsMapLayer* currentLayer )
{
if ( !currentLayer )
{
return;
}

if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vLayer = static_cast<QgsVectorLayer*>( currentLayer );

//attributes
QDomElement attributesElem = doc.createElement( "Attributes" );
const QgsFieldMap& layerFields = vLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = layerFields.constBegin();
for ( ; fieldIt != layerFields.constEnd(); ++fieldIt )
{
QDomElement attributeElem = doc.createElement( "Attribute" );
attributeElem.setAttribute( "name", fieldIt->name() );
attributeElem.setAttribute( "type", QVariant::typeToName( fieldIt->type() ) );
attributeElem.setAttribute( "editType", vLayer->editType( fieldIt.key() ) );
attributesElem.appendChild( attributeElem );
}
layerElem.appendChild( attributesElem );
}
}

void QgsProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& groupElem, QDomDocument& doc ) const
{
QgsRectangle combinedBBox;
Expand Down
10 changes: 7 additions & 3 deletions src/mapserver/qgsprojectparser.h
Expand Up @@ -35,8 +35,9 @@ class QgsProjectParser: public QgsConfigParser
QgsProjectParser( QDomDocument* xmlDoc, const QString& filePath );
virtual ~QgsProjectParser();

/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.*/
virtual void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
@param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*/
virtual void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc, bool fullProjectSettings = false ) const;

virtual void featureTypeList( QDomElement& parentElement, QDomDocument& doc ) const;

Expand Down Expand Up @@ -151,7 +152,10 @@ class QgsProjectParser: public QgsConfigParser
QDomElement &parentLayer,
const QDomElement &legendElem,
const QMap<QString, QgsMapLayer *> &layerMap,
const QStringList &nonIdentifiableLayers ) const;
const QStringList &nonIdentifiableLayers,
bool fullProjectSettings = false ) const;

static void addLayerProjectSettings( QDomElement& layerElem, QDomDocument& doc, QgsMapLayer* currentLayer );

void combineExtentAndCrsOfGroupChildren( QDomElement& groupElement, QDomDocument& doc ) const;

Expand Down
2 changes: 1 addition & 1 deletion src/mapserver/qgssldparser.cpp
Expand Up @@ -140,7 +140,7 @@ int QgsSLDParser::numberOfLayers() const
return ( userLayerList.size() + namedLayerList.size() );
}

void QgsSLDParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
void QgsSLDParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc, bool fullProjectSettings ) const
{
//iterate over all <UserLayer> nodes
if ( mXMLDoc )
Expand Down
2 changes: 1 addition & 1 deletion src/mapserver/qgssldparser.h
Expand Up @@ -54,7 +54,7 @@ class QgsSLDParser: public QgsConfigParser
virtual ~QgsSLDParser();

/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.*/
void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc, bool fullProjectSettings = false ) const;

void featureTypeList( QDomElement &, QDomDocument & ) const {};

Expand Down
4 changes: 2 additions & 2 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -80,7 +80,7 @@ void QgsWMSServer::appendFormats( QDomDocument &doc, QDomElement &elem, const QS
}
}

QDomDocument QgsWMSServer::getCapabilities( QString version )
QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInformation )
{
QgsDebugMsg( "Entering." );
QDomDocument doc;
Expand Down Expand Up @@ -215,7 +215,7 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
QgsDebugMsg( "calling layersAndStylesCapabilities" );
if ( mConfigParser )
{
mConfigParser->layersAndStylesCapabilities( capabilityElement, doc );
mConfigParser->layersAndStylesCapabilities( capabilityElement, doc, fullProjectInformation );
}
QgsDebugMsg( "layersAndStylesCapabilities returned" );

Expand Down
6 changes: 4 additions & 2 deletions src/mapserver/qgswmsserver.h
Expand Up @@ -53,8 +53,10 @@ class QgsWMSServer
/**Constructor. Takes parameter map and a pointer to a renderer object (does not take ownership)*/
QgsWMSServer( QMap<QString, QString> parameters, QgsMapRenderer* renderer );
~QgsWMSServer();
/**Returns an XML file with the capabilities description (as described in the WMS specs)*/
QDomDocument getCapabilities( QString version = "1.3.0" );
/**Returns an XML file with the capabilities description (as described in the WMS specs)
@param version WMS version (1.1.1 or 1.3.0)
@param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*/
QDomDocument getCapabilities( QString version = "1.3.0", bool fullProjectInformation = false );
/**Returns the map legend as an image (or a null pointer in case of error). The caller takes ownership
of the image object*/
QImage* getLegendGraphics();
Expand Down

0 comments on commit bd2af12

Please sign in to comment.