mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Fix pages are incorrectly loaded from templates when adding items
This commit is contained in:
parent
885f0a5602
commit
b0dea08bbe
@ -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 @@ class TestQgsLayout(unittest.TestCase):
|
||||
|
||||
p = QgsProject()
|
||||
l = QgsLayout(p)
|
||||
l.initializeDefaults()
|
||||
|
||||
# add some items
|
||||
item1 = QgsLayoutItemLabel(l)
|
||||
@ -285,11 +286,10 @@ class TestQgsLayout(unittest.TestCase):
|
||||
# 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user