Package: qgis / 2.4.0-1

0001-BUGFIX-Issue-11109-Write-relative-path-in-project-XM.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
From 86e350c3dfdff439ef06a0fcb9d6395793fb9ffa Mon Sep 17 00:00:00 2001
From: Michael Douchin <mdouchin@3liz.com>
Date: Thu, 28 Aug 2014 18:24:05 +0200
Subject: [BUGFIX] Issue #11109 - Write relative path in project XML for
 embedded groups and layers when needed
Origin: https://github.com/qgis/QGIS/commit/86e350c3dfdff439ef06a0fcb9d6395793fb9ffa
Bug: http://hub.qgis.org/issues/11109


--- a/src/app/qgisapp.cpp
+++ b/src/app/qgisapp.cpp
@@ -9663,6 +9663,7 @@ void QgisApp::writeProject( QDomDocument
 
   QgsLayerTreeNode* clonedRoot = QgsProject::instance()->layerTreeRoot()->clone();
   QgsLayerTreeUtils::removeChildrenOfEmbeddedGroups( QgsLayerTree::toGroup( clonedRoot ) );
+  QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( clonedRoot ) ); // convert absolute paths to relative paths if required
   QDomElement oldLegendElem = QgsLayerTreeUtils::writeOldLegend( doc, QgsLayerTree::toGroup( clonedRoot ),
                               mLayerTreeCanvasBridge->hasCustomLayerOrder(), mLayerTreeCanvasBridge->customLayerOrder() );
   delete clonedRoot;
--- a/src/core/layertree/qgslayertreeutils.cpp
+++ b/src/core/layertree/qgslayertreeutils.cpp
@@ -19,8 +19,11 @@
 
 #include "qgsvectorlayer.h"
 
+#include "qgsproject.h"
+
 #include <QDomElement>
 
+
 static void _readOldLegendGroup( const QDomElement& groupElem, QgsLayerTreeGroup* parent );
 static void _readOldLegendLayer( const QDomElement& layerElem, QgsLayerTreeGroup* parent );
 
@@ -314,3 +317,22 @@ void QgsLayerTreeUtils::removeChildrenOf
     }
   }
 }
+
+
+void QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group )
+{
+  foreach ( QgsLayerTreeNode* node, group->children() )
+  {
+    if ( !node->customProperty( "embedded_project" ).toString().isEmpty() )
+    {
+      // may change from absolute path to relative path
+      QString newPath = QgsProject::instance()->writePath( node->customProperty( "embedded_project" ).toString() );
+      node->setCustomProperty( "embedded_project", newPath );
+    }
+
+    if ( QgsLayerTree::isGroup( node ) )
+    {
+        updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( node ) );
+    }
+  }
+}
--- a/src/core/layertree/qgslayertreeutils.h
+++ b/src/core/layertree/qgslayertreeutils.h
@@ -58,6 +58,9 @@ class CORE_EXPORT QgsLayerTreeUtils
     //! Remove subtree of embedded groups. Useful when saving layer tree
     static void removeChildrenOfEmbeddedGroups( QgsLayerTreeGroup* group );
 
+    //! @note not available in python bindings
+    static void updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group );
+
 };
 
 #endif // QGSLAYERTREEUTILS_H
--- a/src/core/qgsproject.cpp
+++ b/src/core/qgsproject.cpp
@@ -1003,24 +1003,6 @@ void QgsProject::loadEmbeddedNodes( QgsL
   }
 }
 
-void QgsProject::updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group )
-{
-  foreach ( QgsLayerTreeNode* node, group->children() )
-  {
-    if ( QgsLayerTree::isGroup( node ) )
-    {
-      if ( !node->customProperty( "embedded_project" ).toString().isEmpty() )
-      {
-        // may change from absolute path to relative path
-        QString newPath = writePath( node->customProperty( "embedded_project" ).toString() );
-        node->setCustomProperty( "embedded_project", newPath );
-      }
-      else
-        updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( node ) );
-    }
-  }
-}
-
 
 bool QgsProject::read( QDomNode & layerNode )
 {
@@ -1102,7 +1084,7 @@ bool QgsProject::write()
   // write layer tree - make sure it is without embedded subgroups
   QgsLayerTreeNode* clonedRoot = mRootGroup->clone();
   QgsLayerTreeUtils::removeChildrenOfEmbeddedGroups( QgsLayerTree::toGroup( clonedRoot ) );
-  updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( clonedRoot ) ); // convert absolute paths to relative paths if required
+  QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( clonedRoot ) ); // convert absolute paths to relative paths if required
   clonedRoot->writeXML( qgisNode );
   delete clonedRoot;
 
@@ -1716,6 +1698,7 @@ bool QgsProject::createEmbeddedLayer( co
 
   //does project store pathes absolute or relative?
   bool useAbsolutePathes = true;
+
   QDomElement propertiesElem = projectDocument.documentElement().firstChildElement( "properties" );
   if ( !propertiesElem.isNull() )
   {
--- a/src/core/qgsproject.h
+++ b/src/core/qgsproject.h
@@ -361,9 +361,6 @@ class CORE_EXPORT QgsProject : public QO
     //! @note not available in python bindings
     void loadEmbeddedNodes( QgsLayerTreeGroup* group );
 
-    //! @note not available in python bindings
-    void updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group );
-
   signals:
     //! emitted when project is being read
     void readProject( const QDomDocument & );