Skip to content
Permalink
Browse files

[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 da2c4be340b342c1e62d6188bdf88268f672d15d
Showing with 18 additions and 12 deletions.
  1. +18 −12 src/app/qgisapp.cpp
@@ -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 );
}
}

0 comments on commit da2c4be

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