Skip to content
Permalink
Browse files

[FEATURE] QGIS server: possibility to restrict published composers

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Oct 12, 2012
1 parent 539ff69 commit a1a2b252fdb152756fd02eb529737828b39948c3
@@ -19,6 +19,8 @@
#include "qgsprojectproperties.h"

//qgis includes
#include "qgisapp.h"
#include "qgscomposer.h"
#include "qgscontexthelp.h"
#include "qgscoordinatetransform.h"
#include "qgslogger.h"
@@ -261,6 +263,14 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

grpWMSList->setChecked( mWMSList->count() > 0 );

//composer restriction for WMS
values = QgsProject::instance()->readListEntry( "WMSComposerList", "/", &ok );
mWMSComposerGroupBox->setChecked( ok );
if ( ok )
{
mComposerListWidget->addItems( values );
}

bool addWktGeometry = QgsProject::instance()->readBoolEntry( "WMSAddWktGeometry", "/" );
mAddWktGeometryCheckBox->setChecked( addWktGeometry );

@@ -539,6 +549,21 @@ void QgsProjectProperties::apply()
QgsProject::instance()->removeEntry( "WMSCrsList", "/" );
}

//WMS composer restrictions
if ( mWMSComposerGroupBox->isChecked() )
{
QStringList composerTitles;
for ( int i = 0; i < mComposerListWidget->count(); ++i )
{
composerTitles << mComposerListWidget->item( i )->text();
}
QgsProject::instance()->writeEntry( "WMSComposerList", "/", composerTitles );
}
else
{
QgsProject::instance()->removeEntry( "WMSComposerList", "/" );
}

QgsProject::instance()->writeEntry( "WMSAddWktGeometry", "/", mAddWktGeometryCheckBox->isChecked() );

QString maxWidthText = mMaxWidthLineEdit->text();
@@ -747,6 +772,36 @@ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked()
mWMSList->addItems( crsList.values() );
}

void QgsProjectProperties::on_mAddWMSComposerButton_clicked()
{
QSet<QgsComposer*> projectComposers = QgisApp::instance()->printComposers();
QStringList composerTitles;
QSet<QgsComposer*>::const_iterator cIt = projectComposers.constBegin();
for ( ; cIt != projectComposers.constEnd(); ++cIt )
{
composerTitles << ( *cIt )->title();
}

bool ok;
QString name = QInputDialog::getItem( this, tr( "Select print composer" ), tr( "Composer Title" ), composerTitles, 0, false, &ok );
if ( ok )
{
if ( mComposerListWidget->findItems( name, Qt::MatchExactly ).size() < 1 )
{
mComposerListWidget->addItem( name );
}
}
}

void QgsProjectProperties::on_mRemoveWMSComposerButton_clicked()
{
QListWidgetItem* currentItem = mComposerListWidget->currentItem();
if ( currentItem )
{
delete mComposerListWidget->takeItem( mComposerListWidget->row( currentItem ) );
}
}

void QgsProjectProperties::on_pbnWFSLayersSelectAll_clicked()
{
for ( int i = 0; i < twWFSLayers->rowCount(); i++ )
@@ -112,6 +112,8 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
void on_pbnWMSAddSRS_clicked();
void on_pbnWMSRemoveSRS_clicked();
void on_pbnWMSSetUsedSRS_clicked();
void on_mAddWMSComposerButton_clicked();
void on_mRemoveWMSComposerButton_clicked();

/*!
* Slots to select/unselect all the WFS layers
@@ -1440,18 +1440,19 @@ void QgsProjectParser::printCapabilities( QDomElement& parentElement, QDomDocume
return;
}

QDomNodeList composerNodeList = mXMLDoc->elementsByTagName( "Composer" );
if ( composerNodeList.size() < 1 )
QList<QDomElement> composerElemList = publishedComposerElements();
if ( composerElemList.size() < 1 )
{
return;
}

QDomElement composerTemplatesElem = doc.createElement( "ComposerTemplates" );

for ( int i = 0; i < composerNodeList.size(); ++i )
QList<QDomElement>::const_iterator composerElemIt = composerElemList.constBegin();
for ( ; composerElemIt != composerElemList.constEnd(); ++composerElemIt )
{
QDomElement composerTemplateElem = doc.createElement( "ComposerTemplate" );
QDomElement currentComposerElem = composerNodeList.at( i ).toElement();
QDomElement currentComposerElem = *composerElemIt;
if ( currentComposerElem.isNull() )
{
continue;
@@ -1515,10 +1516,11 @@ QDomElement QgsProjectParser::composerByName( const QString& composerName ) cons
return composerElem;
}

QDomNodeList composerNodeList = mXMLDoc->elementsByTagName( "Composer" );
for ( int i = 0; i < composerNodeList.size(); ++i )
QList<QDomElement> composerElemList = publishedComposerElements();
QList<QDomElement>::const_iterator composerIt = composerElemList.constBegin();
for ( ; composerIt != composerElemList.constEnd(); ++composerIt )
{
QDomElement currentComposerElem = composerNodeList.at( i ).toElement();
QDomElement currentComposerElem = *composerIt;
if ( currentComposerElem.attribute( "title" ) == composerName )
{
return currentComposerElem;
@@ -1528,6 +1530,50 @@ QDomElement QgsProjectParser::composerByName( const QString& composerName ) cons
return composerElem;
}

QList<QDomElement> QgsProjectParser::publishedComposerElements() const
{
QList<QDomElement> composerElemList;
if ( !mXMLDoc )
{
return composerElemList;
}

QDomNodeList composerNodeList = mXMLDoc->elementsByTagName( "Composer" );

QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
QDomElement wmsComposerListElem = propertiesElem.firstChildElement( "WMSComposerList" );
if ( wmsComposerListElem.isNull() )
{
for ( unsigned int i = 0; i < composerNodeList.length(); ++i )
{
composerElemList.push_back( composerNodeList.at( i ).toElement() );
}
return composerElemList;
}

QSet<QString> publishedComposerNames;
QDomNodeList valueList = wmsComposerListElem.elementsByTagName( "value" );
for ( int i = 0; i < valueList.size(); ++i )
{
publishedComposerNames.insert( valueList.at( i ).toElement().text() );
}

//remove unpublished composers from list
QString currentComposerName;
QDomElement currentElem;
for ( int i = 0; i < composerNodeList.size(); ++i )
{
currentElem = composerNodeList.at( i ).toElement();
currentComposerName = currentElem.attribute( "title" );
if ( publishedComposerNames.contains( currentComposerName ) )
{
composerElemList.push_back( currentElem );
}
}

return composerElemList;
}

void QgsProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
QDomElement serviceElem = doc.createElement( "Service" );
@@ -169,6 +169,9 @@ class QgsProjectParser: public QgsConfigParser
/**Returns dom element of composer (identified by composer title) or a null element in case of error*/
QDomElement composerByName( const QString& composerName ) const;

/**Returns the composer elements published by this WMS. It is possible to hide composers from the WMS*/
QList<QDomElement> publishedComposerElements() const;

/**Converts a (possibly relative) path to absolute*/
QString convertToAbsolutePath( const QString& file ) const;

0 comments on commit a1a2b25

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