Skip to content

Commit

Permalink
Merge branch 'wms_selective_publish'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Oct 16, 2012
2 parents 5a6401c + 0478d3b commit 79be949
Show file tree
Hide file tree
Showing 10 changed files with 658 additions and 192 deletions.
4 changes: 2 additions & 2 deletions src/app/CMakeLists.txt
Expand Up @@ -28,7 +28,6 @@ SET(QGIS_APP_SRCS
qgsdecorationscalebardialog.cpp
qgsdecorationgrid.cpp
qgsdecorationgriddialog.cpp
qgsembedlayerdialog.cpp
qgsformannotationdialog.cpp
qgshtmlannotationdialog.cpp
qgsdelattrdialog.cpp
Expand Down Expand Up @@ -95,6 +94,7 @@ SET(QGIS_APP_SRCS
qgspluginmanager.cpp
qgspluginmetadata.cpp
qgspluginregistry.cpp
qgsprojectlayergroupdialog.cpp
qgsprojectproperties.cpp
qgsrastercalcdialog.cpp
qgsrasterlayerproperties.cpp
Expand Down Expand Up @@ -189,7 +189,6 @@ SET (QGIS_APP_MOC_HDRS
qgsdelattrdialog.h
qgsdiagramproperties.h
qgsdisplayangle.h
qgsembedlayerdialog.h
qgsfeatureaction.h
qgsfieldcalculator.h
qgsformannotationdialog.h
Expand Down Expand Up @@ -241,6 +240,7 @@ SET (QGIS_APP_MOC_HDRS
qgsoptions.h
qgspastetransformations.h
qgspluginmanager.h
qgsprojectlayergroupdialog.h
qgsprojectproperties.h
qgsrastercalcdialog.h
qgsrasterlayerproperties.h
Expand Down
27 changes: 15 additions & 12 deletions src/app/qgisapp.cpp
Expand Up @@ -119,7 +119,6 @@
#include "qgsdecorationnortharrow.h"
#include "qgsdecorationscalebar.h"
#include "qgsdecorationgrid.h"
#include "qgsembedlayerdialog.h"
#include "qgsencodingfiledialog.h"
#include "qgsexception.h"
#include "qgsfeature.h"
Expand Down Expand Up @@ -156,6 +155,7 @@
#include "qgspoint.h"
#include "qgshandlebadlayers.h"
#include "qgsproject.h"
#include "qgsprojectlayergroupdialog.h"
#include "qgsprojectproperties.h"
#include "qgsproviderregistry.h"
#include "qgspythonrunner.h"
Expand Down Expand Up @@ -5867,30 +5867,33 @@ void QgisApp::addMapLayer( QgsMapLayer *theMapLayer )
void QgisApp::embedLayers()
{
//dialog to select groups/layers from other project files
QgsEmbedLayerDialog d( this );
QgsProjectLayerGroupDialog d( this );
if ( d.exec() == QDialog::Accepted )
{
mMapCanvas->freeze( true );

QString projectFile = d.selectedProjectFile();

//groups
QList< QPair < QString, QString > > groups = d.embeddedGroups();
QList< QPair < QString, QString > >::const_iterator groupIt = groups.constBegin();
QStringList groups = d.selectedGroups();
QStringList::const_iterator groupIt = groups.constBegin();
for ( ; groupIt != groups.constEnd(); ++groupIt )
{
mMapLegend->addEmbeddedGroup( groupIt->first, groupIt->second );
mMapLegend->addEmbeddedGroup( *groupIt, projectFile );
}

//layers
//layer ids
QList<QDomNode> brokenNodes;
QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList;

QList< QPair < QString, QString > > layers = d.embeddedLayers();
QList< QPair < QString, QString > >::const_iterator layerIt = layers.constBegin();
for ( ; layerIt != layers.constEnd(); ++layerIt )
QStringList layerIds = d.selectedLayerIds();
QStringList::const_iterator layerIt = layerIds.constBegin();
for ( ; layerIt != layerIds.constEnd(); ++layerIt )
{
QgsProject::instance()->createEmbeddedLayer( layerIt->first, layerIt->second, brokenNodes, vectorLayerList );
QgsProject::instance()->createEmbeddedLayer( *layerIt, projectFile, brokenNodes, vectorLayerList );
}

mMapCanvas->freeze( false );
if ( groups.size() > 0 || layers.size() > 0 )
if ( groups.size() > 0 || layerIds.size() > 0 )
{
mMapCanvas->refresh();
}
Expand Down
Expand Up @@ -12,7 +12,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsembedlayerdialog.h"
#include "qgsprojectlayergroupdialog.h"
#include "qgsproject.h"
#include "qgisapp.h"
#include "qgsapplication.h"
Expand All @@ -23,56 +23,84 @@
#include <QMessageBox>
#include <QSettings>

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

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

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

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

QgsEmbedLayerDialog::~QgsEmbedLayerDialog()
QgsProjectLayerGroupDialog::~QgsProjectLayerGroupDialog()
{
QSettings settings;
settings.setValue( "/Windows/EmbedLayer/geometry", saveGeometry() );
}

QList< QPair < QString, QString > > QgsEmbedLayerDialog::embeddedGroups() const
QStringList QgsProjectLayerGroupDialog::selectedGroups() const
{
QList< QPair < QString, QString > > result;

QStringList groups;
QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
QList<QTreeWidgetItem*>::iterator itemIt = items.begin();
for ( ; itemIt != items.end(); ++itemIt )
{
if (( *itemIt )->data( 0, Qt::UserRole ).toString() == "group" )
{
result.push_back( qMakePair(( *itemIt )->text( 0 ), mProjectPath ) );
groups.push_back(( *itemIt )->text( 0 ) );
}
}

return result;
return groups;
}

QList< QPair < QString, QString > > QgsEmbedLayerDialog::embeddedLayers() const
QStringList QgsProjectLayerGroupDialog::selectedLayerIds() const
{
QList< QPair < QString, QString > > result;
QStringList layerIds;
QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
QList<QTreeWidgetItem*>::iterator itemIt = items.begin();
for ( ; itemIt != items.end(); ++itemIt )
{
if (( *itemIt )->data( 0, Qt::UserRole ).toString() == "layer" )
{
layerIds.push_back(( *itemIt )->data( 0, Qt::UserRole + 1 ).toString() );
}
}
return layerIds;
}

QStringList QgsProjectLayerGroupDialog::selectedLayerNames() const
{
QStringList layerNames;
QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
QList<QTreeWidgetItem*>::iterator itemIt = items.begin();
for ( ; itemIt != items.end(); ++itemIt )
{
if (( *itemIt )->data( 0, Qt::UserRole ).toString() == "layer" )
{
result.push_back( qMakePair(( *itemIt )->data( 0, Qt::UserRole + 1 ).toString(), mProjectPath ) );
layerNames.push_back(( *itemIt )->text( 0 ) );
}
}
return result;
return layerNames;
}

QString QgsProjectLayerGroupDialog::selectedProjectFile() const
{
return mProjectFileLineEdit->text();
}

void QgsEmbedLayerDialog::on_mBrowseFileToolButton_clicked()
void QgsProjectLayerGroupDialog::on_mBrowseFileToolButton_clicked()
{
//line edit might emit editingFinished signal when loosing focus
mProjectFileLineEdit->blockSignals( true );
Expand All @@ -90,12 +118,12 @@ void QgsEmbedLayerDialog::on_mBrowseFileToolButton_clicked()
mProjectFileLineEdit->blockSignals( false );
}

void QgsEmbedLayerDialog::on_mProjectFileLineEdit_editingFinished()
void QgsProjectLayerGroupDialog::on_mProjectFileLineEdit_editingFinished()
{
changeProjectFile();
}

void QgsEmbedLayerDialog::changeProjectFile()
void QgsProjectLayerGroupDialog::changeProjectFile()
{
QFile projectFile( mProjectFileLineEdit->text() );
if ( !projectFile.exists() )
Expand All @@ -110,7 +138,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 Expand Up @@ -155,12 +183,12 @@ void QgsEmbedLayerDialog::changeProjectFile()
mProjectPath = mProjectFileLineEdit->text();
}

void QgsEmbedLayerDialog::addLegendGroupToTreeWidget( const QDomElement& groupElem, QTreeWidgetItem* parent )
void QgsProjectLayerGroupDialog::addLegendGroupToTreeWidget( const QDomElement& groupElem, QTreeWidgetItem* parent )
{
QDomNodeList groupChildren = groupElem.childNodes();
QDomElement currentChildElem;

if ( groupElem.attribute( "embedded" ) == "1" )
if ( !mShowEmbeddedContent && groupElem.attribute( "embedded" ) == "1" )
{
return;
}
Expand Down Expand Up @@ -192,9 +220,9 @@ void QgsEmbedLayerDialog::addLegendGroupToTreeWidget( const QDomElement& groupEl
}
}

void QgsEmbedLayerDialog::addLegendLayerToTreeWidget( const QDomElement& layerElem, QTreeWidgetItem* parent )
void QgsProjectLayerGroupDialog::addLegendLayerToTreeWidget( const QDomElement& layerElem, QTreeWidgetItem* parent )
{
if ( layerElem.attribute( "embedded" ) == "1" )
if ( !mShowEmbeddedContent && layerElem.attribute( "embedded" ) == "1" )
{
return;
}
Expand All @@ -213,7 +241,7 @@ void QgsEmbedLayerDialog::addLegendLayerToTreeWidget( const QDomElement& layerEl
item->setData( 0, Qt::UserRole + 1, layerElem.firstChildElement( "filegroup" ).firstChildElement( "legendlayerfile" ).attribute( "layerid" ) );
}

void QgsEmbedLayerDialog::on_mTreeWidget_itemSelectionChanged()
void QgsProjectLayerGroupDialog::on_mTreeWidget_itemSelectionChanged()
{
mTreeWidget->blockSignals( true );
QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
Expand All @@ -226,7 +254,7 @@ void QgsEmbedLayerDialog::on_mTreeWidget_itemSelectionChanged()
mTreeWidget->blockSignals( false );
}

void QgsEmbedLayerDialog::unselectChildren( QTreeWidgetItem* item )
void QgsProjectLayerGroupDialog::unselectChildren( QTreeWidgetItem* item )
{
if ( !item )
{
Expand All @@ -242,7 +270,7 @@ void QgsEmbedLayerDialog::unselectChildren( QTreeWidgetItem* item )
}
}

void QgsEmbedLayerDialog::on_mButtonBox_accepted()
void QgsProjectLayerGroupDialog::on_mButtonBox_accepted()
{
QSettings s;
QFileInfo fi( mProjectPath );
Expand Down
@@ -1,6 +1,6 @@
/***************************************************************************
qgsembedlayerdialog.h
---------------------
qgsprojectlayergroupdialog.h
----------------------------
begin : June 2011
copyright : (C) 2011 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
Expand All @@ -12,25 +12,27 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSEMBEDLAYERSDIALOG_H
#define QGSEMBEDLAYERSDIALOG_H
#ifndef QGSPROJECTLAYERGROUPDIALOG_H
#define QGSPROJECTLAYERGROUPDIALOG_H

#include "QDialog"
#include "ui_qgsembedlayerdialogbase.h"
#include "ui_qgsprojectlayergroupdialogbase.h"

class QDomElement;

class QgsEmbedLayerDialog: public QDialog, private Ui::QgsEmbedLayerDialogBase
/**A dialog to select layers and groups from a qgs project*/
class QgsProjectLayerGroupDialog: public QDialog, private Ui::QgsProjectLayerGroupDialogBase
{
Q_OBJECT
public:
QgsEmbedLayerDialog( QWidget * parent = 0, Qt::WindowFlags f = 0 );
~QgsEmbedLayerDialog();
/**Constructor. If a project file is given, the groups/layers are displayed directly and the file selection hidden*/
QgsProjectLayerGroupDialog( QWidget * parent = 0, const QString& projectFile = QString(), Qt::WindowFlags f = 0 );
~QgsProjectLayerGroupDialog();

/**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;
QStringList selectedGroups() const;
QStringList selectedLayerIds() const;
QStringList selectedLayerNames() const;
QString selectedProjectFile() const;

private slots:
void on_mBrowseFileToolButton_clicked();
Expand All @@ -44,6 +46,7 @@ class QgsEmbedLayerDialog: public QDialog, private Ui::QgsEmbedLayerDialogBase
void addLegendLayerToTreeWidget( const QDomElement& layerElem, QTreeWidgetItem* parent = 0 );
void unselectChildren( QTreeWidgetItem* item );
QString mProjectPath;
bool mShowEmbeddedContent;
};

#endif // QGSEMBEDLAYERSDIALOG_H
#endif //QGSPROJECTLAYERGROUPDIALOG_H

0 comments on commit 79be949

Please sign in to comment.