Skip to content

Commit 78ae218

Browse files
author
Marco Hugentobler
committed
Load/Save restricted layers for WMS server
1 parent d96f068 commit 78ae218

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

src/app/qgsembedlayerdialog.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@
2323
#include <QMessageBox>
2424
#include <QSettings>
2525

26-
QgsEmbedLayerDialog::QgsEmbedLayerDialog( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
26+
QgsEmbedLayerDialog::QgsEmbedLayerDialog( QWidget * parent, const QString& projectFile, Qt::WindowFlags f ): QDialog( parent, f )
2727
{
2828
setupUi( this );
2929

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

33+
if ( !projectFile.isEmpty() )
34+
{
35+
mProjectFileLineEdit->setText( projectFile );
36+
mProjectFileLabel->hide();
37+
mProjectFileLineEdit->hide();
38+
mBrowseFileToolButton->hide();
39+
changeProjectFile();
40+
}
41+
3342
QObject::connect( mButtonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
3443
}
3544

@@ -72,6 +81,20 @@ QList< QPair < QString, QString > > QgsEmbedLayerDialog::embeddedLayers() const
7281
return result;
7382
}
7483

84+
QStringList QgsEmbedLayerDialog::layersAndGroupNames() const
85+
{
86+
QStringList result;
87+
88+
QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
89+
QList<QTreeWidgetItem*>::iterator itemIt = items.begin();
90+
for ( ; itemIt != items.end(); ++itemIt )
91+
{
92+
result.push_back(( *itemIt )->text( 0 ) );
93+
}
94+
95+
return result;
96+
}
97+
7598
void QgsEmbedLayerDialog::on_mBrowseFileToolButton_clicked()
7699
{
77100
//line edit might emit editingFinished signal when loosing focus
@@ -110,7 +133,7 @@ void QgsEmbedLayerDialog::changeProjectFile()
110133
}
111134

112135
//check we are not embedding from/to the same project
113-
if ( mProjectFileLineEdit->text() == QgsProject::instance()->fileName() )
136+
if ( mProjectFileLineEdit->isVisible() && mProjectFileLineEdit->text() == QgsProject::instance()->fileName() )
114137
{
115138
QMessageBox::critical( 0, tr( "Recursive embeding not possible" ), tr( "It is not possible to embed layers / groups from the current project" ) );
116139
return;

src/app/qgsembedlayerdialog.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ class QgsEmbedLayerDialog: public QDialog, private Ui::QgsEmbedLayerDialogBase
2424
{
2525
Q_OBJECT
2626
public:
27-
QgsEmbedLayerDialog( QWidget * parent = 0, Qt::WindowFlags f = 0 );
27+
/**Constructor. If a project file is given, the groups/layers are displayed directly and the file selection hidden*/
28+
QgsEmbedLayerDialog( QWidget * parent = 0, const QString& projectFile = QString(), Qt::WindowFlags f = 0 );
2829
~QgsEmbedLayerDialog();
2930

3031
/**Returns name / projectfiles of groups to embed*/
3132
QList< QPair < QString, QString > > embeddedGroups() const;
3233
/**Returns layer id / projectfiles of single layers to embed*/
3334
QList< QPair < QString, QString > > embeddedLayers() const;
35+
/**Returns selected layer and group names*/
36+
QStringList layersAndGroupNames() const;
3437

3538
private slots:
3639
void on_mBrowseFileToolButton_clicked();

src/app/qgsprojectproperties.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgscomposer.h"
2424
#include "qgscontexthelp.h"
2525
#include "qgscoordinatetransform.h"
26+
#include "qgsembedlayerdialog.h"
2627
#include "qgslogger.h"
2728
#include "qgsmapcanvas.h"
2829
#include "qgsmaplayer.h"
@@ -271,6 +272,14 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
271272
mComposerListWidget->addItems( values );
272273
}
273274

275+
//layer restriction for WMS
276+
values = QgsProject::instance()->readListEntry( "WMSRestrictedLayers", "/", &ok );
277+
mLayerRestrictionsGroupBox->setChecked( ok );
278+
if ( ok )
279+
{
280+
mLayerRestrictionsListWidget->addItems( values );
281+
}
282+
274283
bool addWktGeometry = QgsProject::instance()->readBoolEntry( "WMSAddWktGeometry", "/" );
275284
mAddWktGeometryCheckBox->setChecked( addWktGeometry );
276285

@@ -564,6 +573,21 @@ void QgsProjectProperties::apply()
564573
QgsProject::instance()->removeEntry( "WMSComposerList", "/" );
565574
}
566575

576+
//WMS layer restrictions
577+
if ( mLayerRestrictionsGroupBox->isChecked() )
578+
{
579+
QStringList layerNames;
580+
for ( int i = 0; i < mLayerRestrictionsListWidget->count(); ++i )
581+
{
582+
layerNames << mLayerRestrictionsListWidget->item( i )->text();
583+
}
584+
QgsProject::instance()->writeEntry( "WMSRestrictedLayers", "/", layerNames );
585+
}
586+
else
587+
{
588+
QgsProject::instance()->removeEntry( "WMSRestrictedLayers", "/" );
589+
}
590+
567591
QgsProject::instance()->writeEntry( "WMSAddWktGeometry", "/", mAddWktGeometryCheckBox->isChecked() );
568592

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

805829
void QgsProjectProperties::on_mAddLayerRestrictionButton_clicked()
806830
{
807-
831+
QgsEmbedLayerDialog d( this, QgsProject::instance()->fileName() );
832+
d.setWindowTitle( tr( "Select restricted layers and groups" ) );
833+
if ( d.exec() == QDialog::Accepted )
834+
{
835+
QStringList names = d.layersAndGroupNames();
836+
QStringList::const_iterator nameIt = names.constBegin();
837+
for ( ; nameIt != names.constEnd(); ++nameIt )
838+
{
839+
if ( mLayerRestrictionsListWidget->findItems( *nameIt, Qt::MatchExactly ).size() < 1 )
840+
{
841+
mLayerRestrictionsListWidget->addItem( *nameIt );
842+
}
843+
}
844+
}
808845
}
809846

810847
void QgsProjectProperties::on_mRemoveLayerRestrictionButton_clicked()

0 commit comments

Comments
 (0)