Skip to content

Commit 819084d

Browse files
committedJun 1, 2011
Wire in dialog to select embedded groups and layers
1 parent 097881f commit 819084d

File tree

9 files changed

+400
-116
lines changed

9 files changed

+400
-116
lines changed
 

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ SET(QGIS_APP_SRCS
2020
qgscustomprojectiondialog.cpp
2121
qgsdbfilterproxymodel.cpp
2222
qgsdbtablemodel.cpp
23+
qgsembedlayerdialog.cpp
2324
qgsformannotationdialog.cpp
2425
qgsdelattrdialog.cpp
2526
qgsdisplayangle.cpp
@@ -152,6 +153,7 @@ SET (QGIS_APP_MOC_HDRS
152153
qgsdbtablemodel.h
153154
qgsdelattrdialog.h
154155
qgsdisplayangle.h
156+
qgsembedlayerdialog.h
155157
qgsfeatureaction.h
156158
qgsfieldcalculator.h
157159
qgsformannotationdialog.h

‎src/app/legend/qgslegend.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -611,27 +611,27 @@ Qt::CheckState QgsLegend::layerCheckState( QgsMapLayer * layer )
611611
return ll ? ll->checkState( 0 ) : Qt::Unchecked;
612612
}
613613

614-
void QgsLegend::addEmbeddedGroup( const QString& groupName, const QString& projectFilePath, QgsLegendItem* parent )
614+
QgsLegendGroup* QgsLegend::addEmbeddedGroup( const QString& groupName, const QString& projectFilePath, QgsLegendItem* parent )
615615
{
616616
mEmbeddedGroups.insert( groupName, projectFilePath );
617617

618618
//open project file, get layer ids in group, add the layers
619619
QFile projectFile( projectFilePath );
620620
if( !projectFile.open( QIODevice::ReadOnly ) )
621621
{
622-
return;
622+
return 0;
623623
}
624624

625625
QDomDocument projectDocument;
626626
if( !projectDocument.setContent( &projectFile ) )
627627
{
628-
return;
628+
return 0;
629629
}
630630

631631
QDomElement legendElem = projectDocument.documentElement().firstChildElement("legend");
632632
if( legendElem.isNull() )
633633
{
634-
return;
634+
return 0;
635635
}
636636

637637
QList<QDomNode> brokenNodes;
@@ -667,8 +667,8 @@ void QgsLegend::addEmbeddedGroup( const QString& groupName, const QString& proje
667667
if( tagName == "legendlayer" )
668668
{
669669
QString layerId = childElem.firstChildElement("filegroup").firstChildElement("legendlayerfile").attribute("layerid");
670-
QgsProject::instance()->createEmbeddedLayer( layerId, projectFilePath, brokenNodes, vectorLayerList );
671-
if( currentItem() )
670+
QgsProject::instance()->createEmbeddedLayer( layerId, projectFilePath, brokenNodes, vectorLayerList, false );
671+
if( currentItem() && currentItem() != group )
672672
{
673673
insertItem( currentItem(), group );
674674
}
@@ -678,8 +678,10 @@ void QgsLegend::addEmbeddedGroup( const QString& groupName, const QString& proje
678678
addEmbeddedGroup( childElem.attribute("name"), projectFilePath, group );
679679
}
680680
}
681+
return group;
681682
}
682683
}
684+
return 0;
683685
}
684686

685687
int QgsLegend::getItemPos( QTreeWidgetItem* item )
@@ -1003,14 +1005,22 @@ bool QgsLegend::writeXML( QList<QTreeWidgetItem *> items, QDomNode &node, QDomDo
10031005
legendgroupnode.setAttribute( "checked", "Qt::PartiallyChecked" );
10041006
}
10051007

1006-
QList<QTreeWidgetItem *> children;
1007-
for ( int i = 0; i < currentItem->childCount(); i++ )
1008+
QHash< QString, QString >::const_iterator embedIt = mEmbeddedGroups.find( item->text( 0 ) );
1009+
if( embedIt != mEmbeddedGroups.constEnd() )
10081010
{
1009-
children << currentItem->child( i );
1011+
legendgroupnode.setAttribute("embedded", 1);
1012+
legendgroupnode.setAttribute("project", embedIt.value() );
10101013
}
1014+
else
1015+
{
1016+
QList<QTreeWidgetItem *> children;
1017+
for ( int i = 0; i < currentItem->childCount(); i++ )
1018+
{
1019+
children << currentItem->child( i );
1020+
}
10111021

1012-
writeXML( children, legendgroupnode, document );
1013-
1022+
writeXML( children, legendgroupnode, document );
1023+
}
10141024
node.appendChild( legendgroupnode );
10151025
}
10161026
else if ( item->type() == QgsLegendItem::LEGEND_LAYER )
@@ -1109,11 +1119,18 @@ bool QgsLegend::readXML( QgsLegendGroup *parent, const QDomNode &node )
11091119
//test every possibility of element...
11101120
if ( childelem.tagName() == "legendgroup" )
11111121
{
1112-
QgsLegendGroup *theGroup;
1113-
if ( parent )
1114-
theGroup = new QgsLegendGroup( parent, name );
1122+
QgsLegendGroup* theGroup = 0;
1123+
if( childelem.attribute("embedded") == "1" )
1124+
{
1125+
theGroup = addEmbeddedGroup( name, childelem.attribute( "project" ) );
1126+
}
11151127
else
1116-
theGroup = new QgsLegendGroup( this, name );
1128+
{
1129+
if ( parent )
1130+
theGroup = new QgsLegendGroup( parent, name );
1131+
else
1132+
theGroup = new QgsLegendGroup( this, name );
1133+
}
11171134

11181135
//set the checkbox of the legend group to the right state
11191136
blockSignals( true );

‎src/app/legend/qgslegend.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ class QgsLegend : public QTreeWidget
193193
/**Returns a layers check state*/
194194
Qt::CheckState layerCheckState( QgsMapLayer * layer );
195195

196-
void addEmbeddedGroup( const QString& groupName, const QString& projectFilePath, QgsLegendItem* parent = 0 );
196+
/**Add group from other project file. Returns a pointer to the new group in case of success or 0 in case of error*/
197+
QgsLegendGroup* addEmbeddedGroup( const QString& groupName, const QString& projectFilePath, QgsLegendItem* parent = 0 );
197198

198199
public slots:
199200

@@ -369,7 +370,8 @@ class QgsLegend : public QTreeWidget
369370
// The action when the mouse is released
370371
enum { BEFORE, INSERT, AFTER } mDropAction;
371372

372-
// Groups defined in other project files
373+
/** Groups defined in other project files.
374+
Key: group name, value: absolute path to project file*/
373375
QHash< QString, QString > mEmbeddedGroups;
374376

375377
/** Hide the line that indicates insertion position */

‎src/app/qgisapp.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
#include "qgscustomization.h"
114114
#include "qgscustomprojectiondialog.h"
115115
#include "qgsdatasourceuri.h"
116+
#include "qgsembedlayerdialog.h"
116117
#include "qgsencodingfiledialog.h"
117118
#include "qgsexception.h"
118119
#include "qgsfeature.h"
@@ -5061,9 +5062,32 @@ void QgisApp::embedLayers()
50615062
QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList;
50625063
QgsProject::instance()->createEmbeddedLayer( id, filepath, brokenNodes, vectorLayerList );*/
50635064

5064-
QString filepath="/home/marco/geodaten/projekte/rasters.qgs";
5065+
/*QString filepath="/home/marco/geodaten/projekte/rasters.qgs";
50655066
QString groupname="Karten";
5066-
mMapLegend->addEmbeddedGroup( groupname, filepath );
5067+
mMapLegend->addEmbeddedGroup( groupname, filepath );*/
5068+
5069+
QgsEmbedLayerDialog d;
5070+
if( d.exec() == QDialog::Accepted )
5071+
{
5072+
//groups
5073+
QList< QPair < QString, QString > > groups = d.embeddedGroups();
5074+
QList< QPair < QString, QString > >::const_iterator groupIt = groups.constBegin();
5075+
for(; groupIt != groups.constEnd(); ++groupIt )
5076+
{
5077+
mMapLegend->addEmbeddedGroup( groupIt->first, groupIt->second );
5078+
}
5079+
5080+
//layers
5081+
QList<QDomNode> brokenNodes;
5082+
QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList;
5083+
5084+
QList< QPair < QString, QString > > layers = d.embeddedLayers();
5085+
QList< QPair < QString, QString > >::const_iterator layerIt = layers.constBegin();
5086+
for(; layerIt != layers.constEnd(); ++layerIt )
5087+
{
5088+
QgsProject::instance()->createEmbeddedLayer( layerIt->first, layerIt->second, brokenNodes, vectorLayerList );
5089+
}
5090+
}
50675091
}
50685092

50695093
void QgisApp::setExtent( QgsRectangle theRect )

‎src/app/qgsembedlayerdialog.cpp

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#include "qgsembedlayerdialog.h"
2+
#include <QDomDocument>
3+
#include <QFileDialog>
4+
5+
QgsEmbedLayerDialog::QgsEmbedLayerDialog( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
6+
{
7+
setupUi( this );
8+
}
9+
10+
QgsEmbedLayerDialog::~QgsEmbedLayerDialog()
11+
{
12+
}
13+
14+
QList< QPair < QString, QString > > QgsEmbedLayerDialog::embeddedGroups() const
15+
{
16+
QList< QPair < QString, QString > > result;
17+
18+
QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
19+
QList<QTreeWidgetItem*>::iterator itemIt = items.begin();
20+
for(; itemIt != items.end(); ++itemIt )
21+
{
22+
if( (*itemIt)->data(0, Qt::UserRole).toString() == "group" )
23+
{
24+
result.push_back( qMakePair( (*itemIt)->text( 0 ), mProjectFileLineEdit->text() ) );
25+
}
26+
}
27+
28+
return result;
29+
}
30+
31+
QList< QPair < QString, QString > > QgsEmbedLayerDialog::embeddedLayers() const
32+
{
33+
QList< QPair < QString, QString > > result;
34+
35+
QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
36+
QList<QTreeWidgetItem*>::iterator itemIt = items.begin();
37+
for(; itemIt != items.end(); ++itemIt )
38+
{
39+
if( (*itemIt)->data(0, Qt::UserRole).toString() == "layer" )
40+
{
41+
result.push_back( qMakePair( (*itemIt)->data(0, Qt::UserRole + 1).toString(), mProjectFileLineEdit->text() ) );
42+
}
43+
}
44+
return result;
45+
}
46+
47+
void QgsEmbedLayerDialog::on_mBrowseFileToolButton_clicked()
48+
{
49+
QString projectFile = QFileDialog::getOpenFileName( 0, tr("Select project file"), "",tr("QGIS project files (*.qgs)") );
50+
if( !projectFile.isEmpty() )
51+
{
52+
mProjectFileLineEdit->setText( projectFile );
53+
}
54+
changeProjectFile();
55+
}
56+
57+
void QgsEmbedLayerDialog::on_mProjectFileLineEdit_editingFinished()
58+
{
59+
changeProjectFile();
60+
}
61+
62+
void QgsEmbedLayerDialog::changeProjectFile()
63+
{
64+
mTreeWidget->clear();
65+
QFile projectFile( mProjectFileLineEdit->text() );
66+
if( !projectFile.exists() )
67+
{
68+
return;
69+
}
70+
71+
//parse project file and fill tree
72+
if( !projectFile.open( QIODevice::ReadOnly ) )
73+
{
74+
return;
75+
}
76+
77+
QDomDocument projectDom;
78+
if( !projectDom.setContent( &projectFile ) )
79+
{
80+
return;
81+
}
82+
83+
QDomElement legendElem = projectDom.documentElement().firstChildElement("legend");
84+
if( legendElem.isNull() )
85+
{
86+
return;
87+
}
88+
89+
QDomNodeList legendChildren = legendElem.childNodes();
90+
QDomElement currentChildElem;
91+
92+
for( int i = 0; i < legendChildren.size(); ++i )
93+
{
94+
currentChildElem = legendChildren.at( i ).toElement();
95+
if( currentChildElem.tagName() == "legendlayer" )
96+
{
97+
addLegendLayerToTreeWidget( currentChildElem );
98+
}
99+
else if( currentChildElem.tagName() == "legendgroup" )
100+
{
101+
addLegendGroupToTreeWidget( currentChildElem );
102+
}
103+
}
104+
}
105+
106+
void QgsEmbedLayerDialog::addLegendGroupToTreeWidget( const QDomElement& groupElem, QTreeWidgetItem* parent )
107+
{
108+
QDomNodeList groupChildren = groupElem.childNodes();
109+
QDomElement currentChildElem;
110+
111+
QTreeWidgetItem* groupItem = 0;
112+
if( !parent )
113+
{
114+
groupItem = new QTreeWidgetItem( mTreeWidget );
115+
}
116+
else
117+
{
118+
groupItem = new QTreeWidgetItem( parent );
119+
}
120+
groupItem->setText( 0, groupElem.attribute("name") );
121+
groupItem->setData( 0, Qt::UserRole, "group" );
122+
123+
for( int i = 0; i < groupChildren.size(); ++i )
124+
{
125+
currentChildElem = groupChildren.at( i ).toElement();
126+
if( currentChildElem.tagName() == "legendlayer" )
127+
{
128+
addLegendLayerToTreeWidget( currentChildElem, groupItem );
129+
}
130+
else if( currentChildElem.tagName() == "legendgroup" )
131+
{
132+
addLegendGroupToTreeWidget( currentChildElem, groupItem );
133+
}
134+
}
135+
}
136+
137+
void QgsEmbedLayerDialog::addLegendLayerToTreeWidget( const QDomElement& layerElem, QTreeWidgetItem* parent )
138+
{
139+
QTreeWidgetItem* item = 0;
140+
if( parent )
141+
{
142+
item = new QTreeWidgetItem( parent );
143+
}
144+
else
145+
{
146+
item = new QTreeWidgetItem( mTreeWidget );
147+
}
148+
item->setText( 0, layerElem.attribute("name") );
149+
item->setData( 0, Qt::UserRole, "layer" );
150+
item->setData( 0, Qt::UserRole + 1, layerElem.firstChildElement("filegroup").firstChildElement("legendlayerfile").attribute("layerid") );
151+
}
152+
153+
void QgsEmbedLayerDialog::on_mTreeWidget_itemSelectionChanged()
154+
{
155+
mTreeWidget->blockSignals( true );
156+
QList<QTreeWidgetItem*> items = mTreeWidget->selectedItems();
157+
QList<QTreeWidgetItem*>::iterator itemIt = items.begin();
158+
for(; itemIt != items.end(); ++itemIt )
159+
{
160+
//deselect children recursively
161+
unselectChildren( *itemIt );
162+
}
163+
mTreeWidget->blockSignals( false );
164+
}
165+
166+
void QgsEmbedLayerDialog::unselectChildren( QTreeWidgetItem* item )
167+
{
168+
if( !item )
169+
{
170+
return;
171+
}
172+
173+
QTreeWidgetItem* currentChild = 0;
174+
for( int i = 0; i < item->childCount(); ++i )
175+
{
176+
currentChild = item->child( i );
177+
currentChild->setSelected( false );
178+
unselectChildren( currentChild );
179+
}
180+
}
181+
182+

‎src/app/qgsembedlayerdialog.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef QGSEMBEDLAYERSDIALOG_H
2+
#define QGSEMBEDLAYERSDIALOG_H
3+
4+
#include "QDialog"
5+
#include "ui_qgsembedlayerdialogbase.h"
6+
7+
class QDomElement;
8+
9+
class QgsEmbedLayerDialog: public QDialog, private Ui::QgsEmbedLayerDialogBase
10+
{
11+
Q_OBJECT
12+
public:
13+
QgsEmbedLayerDialog( QWidget * parent = 0, Qt::WindowFlags f = 0 );
14+
~QgsEmbedLayerDialog();
15+
16+
/**Returns name / projectfiles of groups to embed*/
17+
QList< QPair < QString, QString > > embeddedGroups() const;
18+
/**Returns layer id / projectfiles of single layers to embed*/
19+
QList< QPair < QString, QString > > embeddedLayers() const;
20+
21+
private slots:
22+
void on_mBrowseFileToolButton_clicked();
23+
void on_mProjectFileLineEdit_editingFinished();
24+
void on_mTreeWidget_itemSelectionChanged();
25+
26+
private:
27+
void changeProjectFile();
28+
void addLegendGroupToTreeWidget( const QDomElement& groupElem, QTreeWidgetItem* parent = 0 );
29+
void addLegendLayerToTreeWidget( const QDomElement& layerElem, QTreeWidgetItem* parent = 0 );
30+
void unselectChildren( QTreeWidgetItem* item );
31+
};
32+
33+
#endif // QGSEMBEDLAYERSDIALOG_H

‎src/core/qgsproject.cpp

Lines changed: 16 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -692,55 +692,6 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
692692
}
693693
else
694694
{
695-
#if 0
696-
QString type = element.attribute( "type" );
697-
QgsDebugMsg( "Layer type is " + type );
698-
QgsMapLayer *mapLayer = NULL;
699-
700-
if ( type == "vector" )
701-
{
702-
mapLayer = new QgsVectorLayer;
703-
}
704-
else if ( type == "raster" )
705-
{
706-
mapLayer = new QgsRasterLayer;
707-
}
708-
else if ( type == "plugin" )
709-
{
710-
QString typeName = element.attribute( "name" );
711-
mapLayer = QgsPluginLayerRegistry::instance()->createLayer( typeName );
712-
}
713-
714-
Q_CHECK_PTR( mapLayer );
715-
716-
if ( !mapLayer )
717-
{
718-
QgsDebugMsg( "Unable to create layer" );
719-
720-
return qMakePair( false, brokenNodes );
721-
}
722-
723-
// have the layer restore state that is stored in Dom node
724-
if ( mapLayer->readXML( node ) && mapLayer->isValid() )
725-
{
726-
mapLayer = QgsMapLayerRegistry::instance()->addMapLayer( mapLayer );
727-
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
728-
if ( vLayer && vLayer->vectorJoins().size() > 0 )
729-
{
730-
vLayerList.push_back( qMakePair( vLayer, element ) );
731-
}
732-
}
733-
else
734-
{
735-
delete mapLayer;
736-
737-
QgsDebugMsg( "Unable to load " + type + " layer" );
738-
739-
returnStatus = false; // flag that we had problems loading layers
740-
741-
brokenNodes.push_back( node );
742-
}
743-
#endif //0
744695
if( !addLayer( element, brokenNodes, vLayerList ) )
745696
{
746697
returnStatus = false;
@@ -1092,17 +1043,22 @@ bool QgsProject::write()
10921043
if ( ml )
10931044
{
10941045
QString externalProjectFile = layerIsEmbedded( ml->id() );
1095-
if( externalProjectFile.isEmpty() )
1046+
QHash< QString, QPair< QString, bool> >::const_iterator emIt = mEmbeddedLayers.find( ml->id() );
1047+
if( emIt == mEmbeddedLayers.constEnd() )
10961048
{
10971049
ml->writeXML( projectLayersNode, *doc );
10981050
}
10991051
else //layer defined in an external project file
11001052
{
1101-
QDomElement mapLayerElem = doc->createElement("maplayer");
1102-
mapLayerElem.setAttribute("embedded", 1 );
1103-
mapLayerElem.setAttribute("project", writePath( externalProjectFile ) );
1104-
mapLayerElem.setAttribute("id", ml->id() );
1105-
projectLayersNode.appendChild( mapLayerElem );
1053+
//only save embedded layer if not managed by a legend group
1054+
if( emIt.value().second )
1055+
{
1056+
QDomElement mapLayerElem = doc->createElement("maplayer");
1057+
mapLayerElem.setAttribute("embedded", 1 );
1058+
mapLayerElem.setAttribute("project", writePath( emIt.value().first ) );
1059+
mapLayerElem.setAttribute("id", ml->id() );
1060+
projectLayersNode.appendChild( mapLayerElem );
1061+
}
11061062
}
11071063
}
11081064
li++;
@@ -1612,15 +1568,16 @@ void QgsProject::setBadLayerHandler( QgsProjectBadLayerHandler* handler )
16121568

16131569
QString QgsProject::layerIsEmbedded( const QString& id ) const
16141570
{
1615-
QHash< QString, QString >::const_iterator it = mEmbeddedLayers.find( id );
1571+
QHash< QString, QPair< QString, bool > >::const_iterator it = mEmbeddedLayers.find( id );
16161572
if( it == mEmbeddedLayers.constEnd() )
16171573
{
16181574
return QString();
16191575
}
1620-
return it.value();
1576+
return it.value().first;
16211577
};
16221578

1623-
bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList )
1579+
bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
1580+
QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag )
16241581
{
16251582
QFile projectFile( projectFilePath );
16261583
if( !projectFile.open( QIODevice::ReadOnly ) )
@@ -1648,7 +1605,7 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
16481605
QString id = mapLayerElem.firstChildElement("id").text();
16491606
if( id == layerId )
16501607
{
1651-
mEmbeddedLayers.insert( layerId, projectFilePath );
1608+
mEmbeddedLayers.insert( layerId, qMakePair( projectFilePath, saveFlag ) );
16521609
if( addLayer( mapLayerElem, brokenNodes, vectorLayerList ) )
16531610
{
16541611
return true;
@@ -1658,41 +1615,6 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
16581615
mEmbeddedLayers.remove( layerId );
16591616
return false;
16601617
}
1661-
#if 0
1662-
QString type = mapLayerElem.attribute("type");
1663-
QgsMapLayer* layer = 0;
1664-
if( type == "vector" )
1665-
{
1666-
layer = new QgsVectorLayer();
1667-
}
1668-
else if( type == "raster" )
1669-
{
1670-
layer = new QgsRasterLayer();
1671-
}
1672-
else if( type == "plugin" )
1673-
{
1674-
QString typeName = mapLayerElem.attribute( "name" );
1675-
layer = QgsPluginLayerRegistry::instance()->createLayer( typeName );
1676-
}
1677-
else
1678-
{
1679-
return 0;
1680-
}
1681-
1682-
// have the layer restore state that is stored in Dom node
1683-
if ( layer->readXML( mapLayerElem ) )
1684-
{
1685-
QgsMapLayerRegistry::instance()->addMapLayer( layer );
1686-
QgsProject::instance()->addEmbeddedLayer( layerId, projectFilePath );
1687-
}
1688-
else
1689-
{
1690-
delete layer;
1691-
QgsDebugMsg( "unable to load " + type + " layer" );
1692-
return 0;
1693-
}
1694-
return layer;
1695-
#endif //0
16961618
}
16971619
}
16981620

‎src/core/qgsproject.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ class CORE_EXPORT QgsProject : public QObject
283283
@return the layer or 0 in case of error
284284
@note: added in version 1.8*/
285285
//static QgsMapLayer* createEmbeddedLayer( const QString& layerId, const QString& projectFilePath );
286-
bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList );
286+
bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
287+
QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );
287288

288289
protected:
289290

@@ -333,9 +334,10 @@ class CORE_EXPORT QgsProject : public QObject
333334

334335
QgsProjectBadLayerHandler* mBadLayerHandler;
335336

336-
/**Embeded layers which are defined in other projects. Key: layer id, value: project file path.
337+
/**Embeded layers which are defined in other projects. Key: layer id,
338+
value: pair< project file path, save layer yes / no (e.g. if the layer is part of an embedded group, loading/saving is done by the legend)
337339
If the project file path is empty, QgsProject is going to ignore the layer for saving (e.g. because it is part and managed by an embedded group)*/
338-
QHash< QString, QString > mEmbeddedLayers;
340+
QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
339341

340342
}; // QgsProject
341343

‎src/ui/qgsembedlayerdialogbase.ui

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsEmbedLayerDialogBase</class>
4+
<widget class="QDialog" name="QgsEmbedLayerDialogBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Select layers and groups to embed</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="0" column="0">
18+
<layout class="QHBoxLayout" name="horizontalLayout">
19+
<item>
20+
<widget class="QLabel" name="mProjectFileLabel">
21+
<property name="text">
22+
<string>Project file</string>
23+
</property>
24+
</widget>
25+
</item>
26+
<item>
27+
<widget class="QLineEdit" name="mProjectFileLineEdit"/>
28+
</item>
29+
<item>
30+
<widget class="QToolButton" name="mBrowseFileToolButton">
31+
<property name="text">
32+
<string>...</string>
33+
</property>
34+
</widget>
35+
</item>
36+
</layout>
37+
</item>
38+
<item row="1" column="0">
39+
<widget class="QTreeWidget" name="mTreeWidget">
40+
<property name="selectionMode">
41+
<enum>QAbstractItemView::ExtendedSelection</enum>
42+
</property>
43+
<attribute name="headerVisible">
44+
<bool>false</bool>
45+
</attribute>
46+
<column>
47+
<property name="text">
48+
<string notr="true">1</string>
49+
</property>
50+
</column>
51+
</widget>
52+
</item>
53+
<item row="2" column="0">
54+
<widget class="QDialogButtonBox" name="buttonBox">
55+
<property name="orientation">
56+
<enum>Qt::Horizontal</enum>
57+
</property>
58+
<property name="standardButtons">
59+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
60+
</property>
61+
</widget>
62+
</item>
63+
</layout>
64+
</widget>
65+
<resources/>
66+
<connections>
67+
<connection>
68+
<sender>buttonBox</sender>
69+
<signal>accepted()</signal>
70+
<receiver>QgsEmbedLayerDialogBase</receiver>
71+
<slot>accept()</slot>
72+
<hints>
73+
<hint type="sourcelabel">
74+
<x>248</x>
75+
<y>254</y>
76+
</hint>
77+
<hint type="destinationlabel">
78+
<x>157</x>
79+
<y>274</y>
80+
</hint>
81+
</hints>
82+
</connection>
83+
<connection>
84+
<sender>buttonBox</sender>
85+
<signal>rejected()</signal>
86+
<receiver>QgsEmbedLayerDialogBase</receiver>
87+
<slot>reject()</slot>
88+
<hints>
89+
<hint type="sourcelabel">
90+
<x>316</x>
91+
<y>260</y>
92+
</hint>
93+
<hint type="destinationlabel">
94+
<x>286</x>
95+
<y>274</y>
96+
</hint>
97+
</hints>
98+
</connection>
99+
</connections>
100+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.