Skip to content
Permalink
Browse files

Fix pages are incorrectly loaded from templates when adding items

  • Loading branch information
nyalldawson committed Dec 4, 2017
1 parent 885f0a5 commit b0dea08bbecda3dcd2ac55cb2aa19b3c7e7b32d1
Showing with 8 additions and 5 deletions.
  1. +4 −1 src/core/layout/qgslayout.cpp
  2. +4 −4 tests/src/python/test_qgslayout.py
@@ -835,10 +835,13 @@ QList< QgsLayoutItem * > QgsLayout::addItemsFromXml( const QDomElement &parentEl
}
}

const QDomNodeList layoutItemList = parentElement.elementsByTagName( QStringLiteral( "LayoutItem" ) );
const QDomNodeList layoutItemList = parentElement.childNodes();
for ( int i = 0; i < layoutItemList.size(); ++i )
{
const QDomElement currentItemElem = layoutItemList.at( i ).toElement();
if ( currentItemElem.nodeName() != QStringLiteral( "LayoutItem" ) )
continue;

const int itemType = currentItemElem.attribute( QStringLiteral( "type" ) ).toInt();
std::unique_ptr< QgsLayoutItem > item( QgsApplication::layoutItemRegistry()->createItem( itemType, this ) );
if ( !item )
@@ -222,6 +222,7 @@ def testSaveLoadTemplate(self):

p = QgsProject()
l = QgsLayout(p)
l.initializeDefaults()

# add some items
item1 = QgsLayoutItemLabel(l)
@@ -285,11 +286,10 @@ def testSaveLoadTemplate(self):
# clearing existing items
new_items3, ok = l2.loadFromTemplate(doc, QgsReadWriteContext(), True)
self.assertTrue(ok)
self.assertEqual(len(new_items3), 2)
self.assertEqual(len(new_items3), 3) # includes page
items = l2.items()
self.assertEqual(len(items), 2)
self.assertTrue([i for i in items if i.id() == 'xxyyxx'])
self.assertTrue([i for i in items if i.id() == 'zzyyzz'])
self.assertTrue([i for i in items if isinstance(i, QgsLayoutItem) and i.id() == 'xxyyxx'])
self.assertTrue([i for i in items if isinstance(i, QgsLayoutItem) and i.id() == 'zzyyzz'])
self.assertTrue(new_items3[0] in l2.items())
self.assertTrue(new_items3[1] in l2.items())
self.assertIn(new_items3[0].templateUuid(), original_uuids)

0 comments on commit b0dea08

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