Skip to content
Permalink
Browse files

[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
  • Loading branch information
nyalldawson committed Jan 24, 2018
1 parent c1f0657 commit b8880d46cd967f8e1574df08b0c96c848b9d23e4
Showing with 25 additions and 0 deletions.
  1. +25 −0 src/core/layout/qgslayoutmanager.cpp
@@ -158,6 +158,31 @@ bool QgsLayoutManager::readXml( const QDomElement &element, const QDomDocument &
{
if ( l->name().isEmpty() )
l->setName( legacyTitle );

// some 2.x projects could end in a state where they had duplicated layout names. This is strictly forbidden in 3.x
// so check for duplicate name in layouts already added
int id = 2;
bool isDuplicateName = false;
QString originalName = l->name();
do
{
isDuplicateName = false;
for ( QgsMasterLayoutInterface *layout : qgis::as_const( mLayouts ) )
{
if ( l->name() == layout->name() )
{
isDuplicateName = true;
break;
}
}
if ( isDuplicateName )
{
l->setName( QStringLiteral( "%1 %2" ).arg( originalName ).arg( id ) );
id++;
}
}
while ( isDuplicateName );

bool added = addLayout( l.release() );
result = added && result;
}

0 comments on commit b8880d4

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