@@ -5120,6 +5120,47 @@ void QgisApp::openLayerDefinition( const QString & path )
5120
5120
}
5121
5121
}
5122
5122
5123
+ void QgisApp::openTemplate ( const QString& fileName )
5124
+ {
5125
+ QFile templateFile;
5126
+ templateFile.setFileName ( fileName );
5127
+
5128
+ if ( !templateFile.open ( QIODevice::ReadOnly ) )
5129
+ {
5130
+ messageBar ()->pushMessage ( tr ( " Load template" ), tr ( " Could not read template file" ), QgsMessageBar::WARNING );
5131
+ return ;
5132
+ }
5133
+
5134
+ QString title;
5135
+ if ( !uniqueComposerTitle ( this , title, true ) )
5136
+ {
5137
+ return ;
5138
+ }
5139
+
5140
+ QgsComposer* newComposer = createNewComposer ( title );
5141
+ if ( !newComposer )
5142
+ {
5143
+ messageBar ()->pushMessage ( tr ( " Load template" ), tr ( " Could not create composer" ), QgsMessageBar::WARNING );
5144
+ return ;
5145
+ }
5146
+
5147
+ bool loadedOk = false ;
5148
+ QDomDocument templateDoc;
5149
+ if ( templateDoc.setContent ( &templateFile, false ) )
5150
+ {
5151
+ loadedOk = newComposer->loadFromTemplate ( templateDoc, true );
5152
+ newComposer->activate ();
5153
+ }
5154
+
5155
+ if ( !loadedOk )
5156
+ {
5157
+ newComposer->close ();
5158
+ deleteComposer ( newComposer );
5159
+ newComposer = nullptr ;
5160
+ messageBar ()->pushMessage ( tr ( " Load template" ), tr ( " Could not load template file" ), QgsMessageBar::WARNING );
5161
+ }
5162
+ }
5163
+
5123
5164
// Open the project file corresponding to the
5124
5165
// path at the given index in mRecentProjectPaths
5125
5166
void QgisApp::openProject ( QAction *action )
@@ -5246,6 +5287,10 @@ void QgisApp::openFile( const QString & fileName )
5246
5287
{
5247
5288
openLayerDefinition ( fileName );
5248
5289
}
5290
+ else if ( fi.completeSuffix () == " qpt" )
5291
+ {
5292
+ openTemplate ( fileName );
5293
+ }
5249
5294
else if ( fi.completeSuffix () == " py" )
5250
5295
{
5251
5296
runScript ( fileName );
0 commit comments