Skip to content

Commit da2c4be

Browse files
committedMay 3, 2018
[layouts] Fix handling of layout name when dropping qpt file to app
- Fix entered name is ignored and replaced by stored name - Default to name stored in qpt as initial name for layout Fixes #18790 (cherry-picked from b63733e)
1 parent 0c6a59e commit da2c4be

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5816,30 +5816,36 @@ void QgisApp::openTemplate( const QString &fileName )
58165816
return;
58175817
}
58185818

5819-
QString title;
5820-
if ( !uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout ) )
5819+
QDomDocument templateDoc;
5820+
if ( !templateDoc.setContent( &templateFile, false ) )
58215821
{
5822+
messageBar()->pushMessage( tr( "Load template" ), tr( "Could not load template file" ), Qgis::Warning );
58225823
return;
58235824
}
58245825

5825-
QgsLayoutDesignerDialog *designer = createNewPrintLayout( title );
5826-
if ( !designer )
5826+
QString title;
5827+
QDomElement layoutElem = templateDoc.documentElement();
5828+
if ( !layoutElem.isNull() )
5829+
title = layoutElem.attribute( QStringLiteral( "name" ) );
5830+
5831+
if ( !uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout, title ) )
58275832
{
5828-
messageBar()->pushMessage( tr( "Load template" ), tr( "Could not create print layout" ), Qgis::Warning );
58295833
return;
58305834
}
58315835

5836+
//create new layout object
5837+
std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( QgsProject::instance() );
58325838
bool loadedOk = false;
5833-
QDomDocument templateDoc;
5834-
if ( templateDoc.setContent( &templateFile, false ) )
5839+
layout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOk );
5840+
if ( loadedOk )
58355841
{
5836-
designer->currentLayout()->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOk );
5837-
designer->activate();
5838-
}
5842+
layout->setName( title );
58395843

5840-
if ( !loadedOk )
5844+
openLayoutDesignerDialog( layout.get() );
5845+
QgsProject::instance()->layoutManager()->addLayout( layout.release() );
5846+
}
5847+
else
58415848
{
5842-
designer->close();
58435849
messageBar()->pushMessage( tr( "Load template" ), tr( "Could not load template file" ), Qgis::Warning );
58445850
}
58455851
}

0 commit comments

Comments
 (0)
Please sign in to comment.