@@ -201,6 +201,8 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
201
201
{
202
202
QFile templateFile;
203
203
bool loadingTemplate = ( mTemplate ->currentIndex () > 0 );
204
+ QDomDocument templateDoc;
205
+ QString storedTitle;
204
206
if ( loadingTemplate )
205
207
{
206
208
if ( mTemplate ->currentIndex () == 1 )
@@ -222,10 +224,18 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
222
224
QMessageBox::warning ( this , tr ( " Create layout" ), tr ( " Could not read template file “%1”." ).arg ( templateFile.fileName () ) );
223
225
return ;
224
226
}
227
+
228
+
229
+ if ( templateDoc.setContent ( &templateFile, false ) )
230
+ {
231
+ QDomElement layoutElem = templateDoc.documentElement ();
232
+ if ( !layoutElem.isNull () )
233
+ storedTitle = layoutElem.attribute ( " name" );
234
+ }
225
235
}
226
236
227
237
QString title;
228
- if ( !QgisApp::instance ()->uniqueLayoutTitle ( this , title, true ) )
238
+ if ( !QgisApp::instance ()->uniqueLayoutTitle ( this , title, true , storedTitle ) )
229
239
{
230
240
return ;
231
241
}
@@ -238,16 +248,12 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
238
248
std::unique_ptr< QgsLayout > layout = qgis::make_unique< QgsLayout >( QgsProject::instance () );
239
249
if ( loadingTemplate )
240
250
{
241
- QDomDocument templateDoc;
242
- if ( templateDoc.setContent ( &templateFile, false ) )
251
+ bool loadedOK = false ;
252
+ ( void )layout->loadFromTemplate ( templateDoc, QgsReadWriteContext (), true , &loadedOK );
253
+ if ( !loadedOK )
243
254
{
244
- bool loadedOK = false ;
245
- ( void )layout->loadFromTemplate ( templateDoc, QgsReadWriteContext (), true , &loadedOK );
246
- if ( !loadedOK )
247
- {
248
- QMessageBox::warning ( this , tr ( " Create layout" ), tr ( " Invalid template file “%1”." ).arg ( templateFile.fileName () ) );
249
- layout.reset ();
250
- }
255
+ QMessageBox::warning ( this , tr ( " Create layout" ), tr ( " Invalid template file “%1”." ).arg ( templateFile.fileName () ) );
256
+ layout.reset ();
251
257
}
252
258
}
253
259
else
0 commit comments