Skip to content

Commit e7d4453

Browse files
committedJun 4, 2019
Redirect default layout template button to configured folder
The "Default templates" button in the layout manager now 1. checks if there is a composer_templates folder in the app dir 2. if not, redirects to the first configured composer templates folder 3. if no composer templates folder is configured, it's deactivated Fix #30064
1 parent 86e3a8d commit e7d4453

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed
 

‎src/app/layout/qgslayoutmanagerdialog.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
101101
addTemplates( defaultTemplateMap );
102102
addTemplates( otherTemplates() );
103103

104+
mTemplatesDefaultDirBtn->setToolTip( tr( "Use <i>Settings --> Options --> Layouts --> Layout Paths</i> to configure the folders in which QGIS will search for print layout templates." ) );
105+
104106
toggleButtons();
105107
}
106108

@@ -148,6 +150,7 @@ void QgsLayoutManagerDialog::addTemplates( const QMap<QString, QString> &templat
148150

149151
void QgsLayoutManagerDialog::activate()
150152
{
153+
updateTemplateButtonEnabledState();
151154
raise();
152155
setWindowState( windowState() & ~Qt::WindowMinimized );
153156
activateWindow();
@@ -284,7 +287,14 @@ void QgsLayoutManagerDialog::mTemplate_currentIndexChanged( int indx )
284287

285288
void QgsLayoutManagerDialog::mTemplatesDefaultDirBtn_pressed()
286289
{
287-
openLocalDirectory( mDefaultTemplatesDir );
290+
if ( QDir( mDefaultTemplatesDir ).exists() )
291+
openLocalDirectory( mDefaultTemplatesDir );
292+
else
293+
{
294+
const QStringList paths = QgsApplication::layoutTemplatePaths();
295+
if ( !paths.empty() )
296+
openLocalDirectory( paths.at( 0 ) );
297+
}
288298
}
289299

290300
void QgsLayoutManagerDialog::mTemplatesUserDirBtn_pressed()
@@ -330,6 +340,11 @@ void QgsLayoutManagerDialog::openLocalDirectory( const QString &localDirPath )
330340
}
331341
}
332342

343+
void QgsLayoutManagerDialog::updateTemplateButtonEnabledState()
344+
{
345+
mTemplatesDefaultDirBtn->setEnabled( QDir( mDefaultTemplatesDir ).exists() || !QgsApplication::layoutTemplatePaths().empty() );
346+
}
347+
333348
#ifdef Q_OS_MAC
334349
void QgsLayoutManagerDialog::showEvent( QShowEvent *event )
335350
{

‎src/app/layout/qgslayoutmanagerdialog.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,20 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
8585

8686
/**
8787
* Returns the default templates (key: template name, value: absolute path to template file)
88-
* \param fromUser whether to return user templates from ~/.qgis/composer_templates
88+
* \param fromUser whether to return user templates from [profile folder]/composer_templates
8989
*/
9090
QMap<QString, QString> defaultTemplates( bool fromUser = false ) const;
9191
QMap<QString, QString> otherTemplates() const;
9292

9393
QMap<QString, QString> templatesFromPath( const QString &path ) const;
9494

9595
/**
96-
* Open local directory with user's system, creating it if not present
96+
* Opens local directory with user's system and tries to create it if not present
9797
*/
9898
void openLocalDirectory( const QString &localDirPath );
9999

100+
void updateTemplateButtonEnabledState();
101+
100102
QString mDefaultTemplatesDir;
101103
QString mUserTemplatesDir;
102104
QPushButton *mCreateReportButton = nullptr;

0 commit comments

Comments
 (0)
Please sign in to comment.