Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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)
  • Loading branch information
nyalldawson committed May 3, 2018
1 parent 0c6a59e commit da2c4be
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/app/qgisapp.cpp
Expand Up @@ -5816,30 +5816,36 @@ void QgisApp::openTemplate( const QString &fileName )
return;
}

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

QgsLayoutDesignerDialog *designer = createNewPrintLayout( title );
if ( !designer )
QString title;
QDomElement layoutElem = templateDoc.documentElement();
if ( !layoutElem.isNull() )
title = layoutElem.attribute( QStringLiteral( "name" ) );

if ( !uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout, title ) )
{
messageBar()->pushMessage( tr( "Load template" ), tr( "Could not create print layout" ), Qgis::Warning );
return;
}

//create new layout object
std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( QgsProject::instance() );
bool loadedOk = false;
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile, false ) )
layout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOk );
if ( loadedOk )
{
designer->currentLayout()->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOk );
designer->activate();
}
layout->setName( title );

if ( !loadedOk )
openLayoutDesignerDialog( layout.get() );
QgsProject::instance()->layoutManager()->addLayout( layout.release() );
}
else
{
designer->close();
messageBar()->pushMessage( tr( "Load template" ), tr( "Could not load template file" ), Qgis::Warning );
}
}
Expand Down

0 comments on commit da2c4be

Please sign in to comment.