mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -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 )
|
for ( int i = 0; i < layoutItemList.size(); ++i )
|
||||||
{
|
{
|
||||||
const QDomElement currentItemElem = layoutItemList.at( i ).toElement();
|
const QDomElement currentItemElem = layoutItemList.at( i ).toElement();
|
||||||
|
if ( currentItemElem.nodeName() != QStringLiteral( "LayoutItem" ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
const int itemType = currentItemElem.attribute( QStringLiteral( "type" ) ).toInt();
|
const int itemType = currentItemElem.attribute( QStringLiteral( "type" ) ).toInt();
|
||||||
std::unique_ptr< QgsLayoutItem > item( QgsApplication::layoutItemRegistry()->createItem( itemType, this ) );
|
std::unique_ptr< QgsLayoutItem > item( QgsApplication::layoutItemRegistry()->createItem( itemType, this ) );
|
||||||
if ( !item )
|
if ( !item )
|
||||||
|
@ -222,6 +222,7 @@ class TestQgsLayout(unittest.TestCase):
|
|||||||
|
|
||||||
p = QgsProject()
|
p = QgsProject()
|
||||||
l = QgsLayout(p)
|
l = QgsLayout(p)
|
||||||
|
l.initializeDefaults()
|
||||||
|
|
||||||
# add some items
|
# add some items
|
||||||
item1 = QgsLayoutItemLabel(l)
|
item1 = QgsLayoutItemLabel(l)
|
||||||
@ -285,11 +286,10 @@ class TestQgsLayout(unittest.TestCase):
|
|||||||
# clearing existing items
|
# clearing existing items
|
||||||
new_items3, ok = l2.loadFromTemplate(doc, QgsReadWriteContext(), True)
|
new_items3, ok = l2.loadFromTemplate(doc, QgsReadWriteContext(), True)
|
||||||
self.assertTrue(ok)
|
self.assertTrue(ok)
|
||||||
self.assertEqual(len(new_items3), 2)
|
self.assertEqual(len(new_items3), 3) # includes page
|
||||||
items = l2.items()
|
items = l2.items()
|
||||||
self.assertEqual(len(items), 2)
|
self.assertTrue([i for i in items if isinstance(i, QgsLayoutItem) and i.id() == 'xxyyxx'])
|
||||||
self.assertTrue([i for i in items if i.id() == 'xxyyxx'])
|
self.assertTrue([i for i in items if isinstance(i, QgsLayoutItem) and i.id() == 'zzyyzz'])
|
||||||
self.assertTrue([i for i in items if i.id() == 'zzyyzz'])
|
|
||||||
self.assertTrue(new_items3[0] in l2.items())
|
self.assertTrue(new_items3[0] in l2.items())
|
||||||
self.assertTrue(new_items3[1] in l2.items())
|
self.assertTrue(new_items3[1] in l2.items())
|
||||||
self.assertIn(new_items3[0].templateUuid(), original_uuids)
|
self.assertIn(new_items3[0].templateUuid(), original_uuids)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user