Skip to content
Permalink
Browse files

[Feature]: Add GetProjectSettings request to QGIS server to have more…

… specific information about the project than in GetCapabilities
  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Sep 6, 2012
1 parent 652deba commit bd2af12dbd9b594e74f71c1847c47ec0e83f8740
@@ -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 )
{
@@ -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
@@ -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;

@@ -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();

@@ -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 );
@@ -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 )
@@ -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)
@@ -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
{
@@ -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;
@@ -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;

@@ -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;

@@ -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 )
@@ -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 {};

@@ -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;
@@ -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" );

@@ -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();

0 comments on commit bd2af12

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