Skip to content
Permalink
Browse files

Load/Save restricted layers for WMS server

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Oct 16, 2012
1 parent d96f068 commit 78ae21841c037aac13d486d1499e7d0ed92ed9d0
Showing with 67 additions and 4 deletions.
  1. +25 −2 src/app/qgsembedlayerdialog.cpp
  2. +4 −1 src/app/qgsembedlayerdialog.h
  3. +38 −1 src/app/qgsprojectproperties.cpp
@@ -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() ) );
}

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

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

0 comments on commit 78ae218

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