Skip to content

Commit

Permalink
Fix pages are incorrectly loaded from templates when adding items
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 6, 2017
1 parent 885f0a5 commit b0dea08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/core/layout/qgslayout.cpp
Expand Up @@ -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 )
Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgslayout.py
Expand Up @@ -222,6 +222,7 @@ def testSaveLoadTemplate(self):

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

# add some items
item1 = QgsLayoutItemLabel(l)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b0dea08

Please sign in to comment.