Skip to content

Commit

Permalink
Load/Save restricted layers for WMS server
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Oct 16, 2012
1 parent d96f068 commit 78ae218
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
27 changes: 25 additions & 2 deletions src/app/qgsembedlayerdialog.cpp
Expand Up @@ -23,13 +23,22 @@
#include <QMessageBox>
#include <QSettings>

QgsEmbedLayerDialog::QgsEmbedLayerDialog( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
QgsEmbedLayerDialog::QgsEmbedLayerDialog( QWidget * parent, const QString& projectFile, Qt::WindowFlags f ): QDialog( parent, f )
{
setupUi( this );

QSettings settings;
restoreGeometry( settings.value( "/Windows/EmbedLayer/geometry" ).toByteArray() );

if ( !projectFile.isEmpty() )
{
mProjectFileLineEdit->setText( projectFile );
mProjectFileLabel->hide();
mProjectFileLineEdit->hide();
mBrowseFileToolButton->hide();
changeProjectFile();
}

QObject::connect( mButtonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
}

Expand Down Expand Up @@ -72,6 +81,20 @@ QList< QPair < QString, QString > > QgsEmbedLayerDialog::embeddedLayers() const
return result;
}

QStringList QgsEmbedLayerDialog::layersAndGroupNames() const
{
QStringList result;

QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
QList<QTreeWidgetItem*>::iterator itemIt = items.begin();
for ( ; itemIt != items.end(); ++itemIt )
{
result.push_back(( *itemIt )->text( 0 ) );
}

return result;
}

void QgsEmbedLayerDialog::on_mBrowseFileToolButton_clicked()
{
//line edit might emit editingFinished signal when loosing focus
Expand Down Expand Up @@ -110,7 +133,7 @@ void QgsEmbedLayerDialog::changeProjectFile()
}

//check we are not embedding from/to the same project
if ( mProjectFileLineEdit->text() == QgsProject::instance()->fileName() )
if ( mProjectFileLineEdit->isVisible() && mProjectFileLineEdit->text() == QgsProject::instance()->fileName() )
{
QMessageBox::critical( 0, tr( "Recursive embeding not possible" ), tr( "It is not possible to embed layers / groups from the current project" ) );
return;
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgsembedlayerdialog.h
Expand Up @@ -24,13 +24,16 @@ class QgsEmbedLayerDialog: public QDialog, private Ui::QgsEmbedLayerDialogBase
{
Q_OBJECT
public:
QgsEmbedLayerDialog( QWidget * parent = 0, Qt::WindowFlags f = 0 );
/**Constructor. If a project file is given, the groups/layers are displayed directly and the file selection hidden*/
QgsEmbedLayerDialog( QWidget * parent = 0, const QString& projectFile = QString(), Qt::WindowFlags f = 0 );
~QgsEmbedLayerDialog();

/**Returns name / projectfiles of groups to embed*/
QList< QPair < QString, QString > > embeddedGroups() const;
/**Returns layer id / projectfiles of single layers to embed*/
QList< QPair < QString, QString > > embeddedLayers() const;
/**Returns selected layer and group names*/
QStringList layersAndGroupNames() const;

private slots:
void on_mBrowseFileToolButton_clicked();
Expand Down
39 changes: 38 additions & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgscomposer.h"
#include "qgscontexthelp.h"
#include "qgscoordinatetransform.h"
#include "qgsembedlayerdialog.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
Expand Down Expand Up @@ -271,6 +272,14 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
mComposerListWidget->addItems( values );
}

//layer restriction for WMS
values = QgsProject::instance()->readListEntry( "WMSRestrictedLayers", "/", &ok );
mLayerRestrictionsGroupBox->setChecked( ok );
if ( ok )
{
mLayerRestrictionsListWidget->addItems( values );
}

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

Expand Down Expand Up @@ -564,6 +573,21 @@ void QgsProjectProperties::apply()
QgsProject::instance()->removeEntry( "WMSComposerList", "/" );
}

//WMS layer restrictions
if ( mLayerRestrictionsGroupBox->isChecked() )
{
QStringList layerNames;
for ( int i = 0; i < mLayerRestrictionsListWidget->count(); ++i )
{
layerNames << mLayerRestrictionsListWidget->item( i )->text();
}
QgsProject::instance()->writeEntry( "WMSRestrictedLayers", "/", layerNames );
}
else
{
QgsProject::instance()->removeEntry( "WMSRestrictedLayers", "/" );
}

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

QString maxWidthText = mMaxWidthLineEdit->text();
Expand Down Expand Up @@ -804,7 +828,20 @@ void QgsProjectProperties::on_mRemoveWMSComposerButton_clicked()

void QgsProjectProperties::on_mAddLayerRestrictionButton_clicked()
{

QgsEmbedLayerDialog d( this, QgsProject::instance()->fileName() );
d.setWindowTitle( tr( "Select restricted layers and groups" ) );
if ( d.exec() == QDialog::Accepted )
{
QStringList names = d.layersAndGroupNames();
QStringList::const_iterator nameIt = names.constBegin();
for ( ; nameIt != names.constEnd(); ++nameIt )
{
if ( mLayerRestrictionsListWidget->findItems( *nameIt, Qt::MatchExactly ).size() < 1 )
{
mLayerRestrictionsListWidget->addItem( *nameIt );
}
}
}
}

void QgsProjectProperties::on_mRemoveLayerRestrictionButton_clicked()
Expand Down

0 comments on commit 78ae218

Please sign in to comment.