Skip to content

Commit b8880d4

Browse files
committedJan 24, 2018
[layouts] Handle duplicated composer names when upgrading 2.x
projects Somehow 2.x projects could end up with compositions with duplicate names. This is strictly forbidden in 3.x, so we autogenerate a new unique name if we encounter any duplicate composer names when upgrading a 2.x project. Fixes #17924
1 parent c1f0657 commit b8880d4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎src/core/layout/qgslayoutmanager.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,31 @@ bool QgsLayoutManager::readXml( const QDomElement &element, const QDomDocument &
158158
{
159159
if ( l->name().isEmpty() )
160160
l->setName( legacyTitle );
161+
162+
// some 2.x projects could end in a state where they had duplicated layout names. This is strictly forbidden in 3.x
163+
// so check for duplicate name in layouts already added
164+
int id = 2;
165+
bool isDuplicateName = false;
166+
QString originalName = l->name();
167+
do
168+
{
169+
isDuplicateName = false;
170+
for ( QgsMasterLayoutInterface *layout : qgis::as_const( mLayouts ) )
171+
{
172+
if ( l->name() == layout->name() )
173+
{
174+
isDuplicateName = true;
175+
break;
176+
}
177+
}
178+
if ( isDuplicateName )
179+
{
180+
l->setName( QStringLiteral( "%1 %2" ).arg( originalName ).arg( id ) );
181+
id++;
182+
}
183+
}
184+
while ( isDuplicateName );
185+
161186
bool added = addLayout( l.release() );
162187
result = added && result;
163188
}

0 commit comments

Comments
 (0)
Please sign in to comment.