Skip to content
Permalink
Browse files

[composer] Simplify and consolidate loading of templates

On behalf of Faunalia, sponsored by ENEL
  • Loading branch information
nyalldawson committed Jul 19, 2016
1 parent 59dc407 commit 656e56e447c5d75476aba2259ada05bb06699f94
Showing with 28 additions and 63 deletions.
  1. +20 −45 src/app/composer/qgscomposer.cpp
  2. +6 −3 src/app/composer/qgscomposer.h
  3. +1 −12 src/app/composer/qgscomposermanager.cpp
  4. +1 −3 src/app/qgisapp.cpp
@@ -909,6 +909,21 @@ void QgsComposer::setTitle( const QString& title )
}
}

bool QgsComposer::loadFromTemplate( const QDomDocument& templateDoc, bool clearExisting )
{
// provide feedback, since composer will be hidden when loading template (much faster)
QScopedPointer< QDialog > dlg( new QgsBusyIndicatorDialog( tr( "Loading template into composer..." ), this ) );
dlg->setStyleSheet( mQgis->styleSheet() );
dlg->show();

setUpdatesEnabled( false );
bool result = mComposition->loadFromTemplate( templateDoc, nullptr, false, clearExisting );
setUpdatesEnabled( true );

dlg->close();
return result;
}

void QgsComposer::updateStatusCursorPos( QPointF cursorPosition )
{
if ( !mComposition )
@@ -3091,11 +3106,9 @@ void QgsComposer::on_mActionSaveAsTemplate_triggered()

void QgsComposer::on_mActionLoadFromTemplate_triggered()
{
loadTemplate( false );
}
if ( !mComposition )
return;

void QgsComposer::loadTemplate( const bool newComposer )
{
QSettings settings;
QString openFileDir = settings.value( "UI/lastComposerTemplateDir", QDir::homePath() ).toString();
QString openFileString = QFileDialog::getOpenFileName( nullptr, tr( "Load template" ), openFileDir, "*.qpt" );
@@ -3115,48 +3128,10 @@ void QgsComposer::loadTemplate( const bool newComposer )
return;
}

QgsComposer* c = nullptr;
QgsComposition* comp = nullptr;

if ( newComposer )
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile ) )
{
QString newTitle;
if ( !mQgis->uniqueComposerTitle( this, newTitle, true ) )
{
return;
}
c = mQgis->createNewComposer( newTitle );
if ( !c )
{
QMessageBox::warning( this, tr( "Composer error" ), tr( "Error, could not create new composer" ) );
return;
}
comp = c->composition();
}
else
{
c = this;
comp = mComposition;
}

if ( comp )
{
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile ) )
{
// provide feedback, since composer will be hidden when loading template (much faster)
QDialog* dlg = new QgsBusyIndicatorDialog( tr( "Loading template into composer..." ) );
dlg->setStyleSheet( mQgis->styleSheet() );
dlg->show();

c->setUpdatesEnabled( false );
comp->loadFromTemplate( templateDoc, nullptr, false, newComposer );
c->setUpdatesEnabled( true );

dlg->close();
delete dlg;
dlg = nullptr;
}
loadFromTemplate( templateDoc, false );
}
}

@@ -105,9 +105,12 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
const QString& title() const {return mTitle;}
void setTitle( const QString& title );

//! Load template into current or blank composer
//! @param newComposer whether to create a new composer first
void loadTemplate( const bool newComposer );
/** Loads the contents of a template document into the composer's composition.
* @param templateDoc template document to load
* @param clearExisting set to true to remove all existing composition settings and items before loading template
* @returns true if template load was successful
*/
bool loadFromTemplate( const QDomDocument& templateDoc, bool clearExisting );

protected:
//! Move event
@@ -289,19 +289,8 @@ void QgsComposerManager::on_mAddButton_clicked()
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile, false ) )
{
// provide feedback, since composer will be hidden when loading template (much faster)
// (not needed for empty composer)
QDialog* dlg = new QgsBusyIndicatorDialog( tr( "Loading template into composer..." ) );
dlg->setStyleSheet( QgisApp::instance()->styleSheet() );
dlg->show();

newComposer->hide();
loadedOK = newComposer->composition()->loadFromTemplate( templateDoc, nullptr, false );
loadedOK = newComposer->loadFromTemplate( templateDoc, true );
newComposer->activate();

dlg->close();
delete dlg;
dlg = nullptr;
}
}

@@ -6603,16 +6603,14 @@ QgsComposer* QgisApp::duplicateComposer( QgsComposer* currentComposer, QString t

// hiding composer until template is loaded is much faster, provide feedback to user
newComposer->hide();
QApplication::setOverrideCursor( Qt::BusyCursor );
if ( !newComposer->composition()->loadFromTemplate( currentDoc, nullptr, false ) )
if ( !newComposer->loadFromTemplate( currentDoc, true ) )
{
deleteComposer( newComposer );
newComposer = nullptr;
QgsDebugMsg( "Error, composer could not be duplicated" );
return newComposer;
}
newComposer->activate();
QApplication::restoreOverrideCursor();

return newComposer;
}

0 comments on commit 656e56e

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