Skip to content
Permalink
Browse files

[FEATURE] Drag qpt to QGIS to create new composer from template

  • Loading branch information
nyalldawson committed Oct 17, 2016
1 parent 8194de9 commit 17e318bd954f749ccb88f19c200534219254803b
Showing with 49 additions and 0 deletions.
  1. +45 −0 src/app/qgisapp.cpp
  2. +4 −0 src/app/qgisapp.h
@@ -5120,6 +5120,47 @@ void QgisApp::openLayerDefinition( const QString & path )
}
}

void QgisApp::openTemplate( const QString& fileName )
{
QFile templateFile;
templateFile.setFileName( fileName );

if ( !templateFile.open( QIODevice::ReadOnly ) )
{
messageBar()->pushMessage( tr( "Load template" ), tr( "Could not read template file" ), QgsMessageBar::WARNING );
return;
}

QString title;
if ( !uniqueComposerTitle( this, title, true ) )
{
return;
}

QgsComposer* newComposer = createNewComposer( title );
if ( !newComposer )
{
messageBar()->pushMessage( tr( "Load template" ), tr( "Could not create composer" ), QgsMessageBar::WARNING );
return;
}

bool loadedOk = false;
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile, false ) )
{
loadedOk = newComposer->loadFromTemplate( templateDoc, true );
newComposer->activate();
}

if ( !loadedOk )
{
newComposer->close();
deleteComposer( newComposer );
newComposer = nullptr;
messageBar()->pushMessage( tr( "Load template" ), tr( "Could not load template file" ), QgsMessageBar::WARNING );
}
}

// Open the project file corresponding to the
// path at the given index in mRecentProjectPaths
void QgisApp::openProject( QAction *action )
@@ -5246,6 +5287,10 @@ void QgisApp::openFile( const QString & fileName )
{
openLayerDefinition( fileName );
}
else if ( fi.completeSuffix() == "qpt" )
{
openTemplate( fileName );
}
else if ( fi.completeSuffix() == "py" )
{
runScript( fileName );
@@ -203,6 +203,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void openProject( const QString & fileName );

void openLayerDefinition( const QString & filename );

//! Open a composer template file and create a new composition
void openTemplate( const QString& fileName );

/** Opens a qgis project file
@returns false if unable to open the project
*/

0 comments on commit 17e318b

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