Skip to content
Permalink
Browse files

Use title from template as default in layout manager

use the template name (if empty or not) as default value in the dialog. user can edit it.
if it is already existing, the user has to change it.
  • Loading branch information
signedav authored and nyalldawson committed Nov 16, 2017
1 parent 253b9d9 commit 183883182b470ca4d42b75078fe36f9600c3f0bd
Showing with 28 additions and 12 deletions.
  1. +12 −2 src/app/composer/qgscomposermanager.cpp
  2. +16 −10 src/app/layout/qgslayoutmanagerdialog.cpp
@@ -192,6 +192,10 @@ void QgsComposerManager::mAddButton_clicked()
{
QFile templateFile;
bool loadingTemplate = ( mTemplate->currentIndex() > 0 );
QDomDocument templateDoc;

QString currentTitle;

if ( loadingTemplate )
{
if ( mTemplate->currentIndex() == 1 )
@@ -213,13 +217,20 @@ void QgsComposerManager::mAddButton_clicked()
QMessageBox::warning( this, tr( "Template error" ), tr( "Error, could not read file" ) );
return;
}

if ( templateDoc.setContent( &templateFile, false ) )
{
QDomElement compositionElem = templateDoc.documentElement().firstChildElement( QStringLiteral( "Composition" ) );
if ( !compositionElem.isNull() )
currentTitle = compositionElem.attribute( "name" );
}
}

QgsComposer *newComposer = nullptr;
bool loadedOK = false;

QString title;
if ( !QgisApp::instance()->uniqueComposerTitle( this, title, true ) )
if ( !QgisApp::instance()->uniqueComposerTitle( this, title, true, currentTitle ) )
{
return;
}
@@ -237,7 +248,6 @@ void QgsComposerManager::mAddButton_clicked()

if ( loadingTemplate )
{
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile, false ) )
{
loadedOK = newComposer->loadFromTemplate( templateDoc, true );
@@ -201,6 +201,8 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
{
QFile templateFile;
bool loadingTemplate = ( mTemplate->currentIndex() > 0 );
QDomDocument templateDoc;
QString storedTitle;
if ( loadingTemplate )
{
if ( mTemplate->currentIndex() == 1 )
@@ -222,10 +224,18 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
QMessageBox::warning( this, tr( "Create layout" ), tr( "Could not read template file “%1”." ).arg( templateFile.fileName() ) );
return;
}


if ( templateDoc.setContent( &templateFile, false ) )
{
QDomElement layoutElem = templateDoc.documentElement();
if ( !layoutElem.isNull() )
storedTitle = layoutElem.attribute( "name" );
}
}

QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, storedTitle ) )
{
return;
}
@@ -238,16 +248,12 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
std::unique_ptr< QgsLayout > layout = qgis::make_unique< QgsLayout >( QgsProject::instance() );
if ( loadingTemplate )
{
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile, false ) )
bool loadedOK = false;
( void )layout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOK );
if ( !loadedOK )
{
bool loadedOK = false;
( void )layout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOK );
if ( !loadedOK )
{
QMessageBox::warning( this, tr( "Create layout" ), tr( "Invalid template file “%1”." ).arg( templateFile.fileName() ) );
layout.reset();
}
QMessageBox::warning( this, tr( "Create layout" ), tr( "Invalid template file “%1”." ).arg( templateFile.fileName() ) );
layout.reset();
}
}
else

0 comments on commit 1838831

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