Skip to content

Commit

Permalink
Redirect default layout template button to configured folder
Browse files Browse the repository at this point in the history
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
  • Loading branch information
m-kuhn committed Jun 4, 2019
1 parent 86e3a8d commit e7d4453
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/app/layout/qgslayoutmanagerdialog.cpp
Expand Up @@ -101,6 +101,8 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
addTemplates( defaultTemplateMap );
addTemplates( otherTemplates() );

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

toggleButtons();
}

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

void QgsLayoutManagerDialog::activate()
{
updateTemplateButtonEnabledState();
raise();
setWindowState( windowState() & ~Qt::WindowMinimized );
activateWindow();
Expand Down Expand Up @@ -284,7 +287,14 @@ void QgsLayoutManagerDialog::mTemplate_currentIndexChanged( int indx )

void QgsLayoutManagerDialog::mTemplatesDefaultDirBtn_pressed()
{
openLocalDirectory( mDefaultTemplatesDir );
if ( QDir( mDefaultTemplatesDir ).exists() )
openLocalDirectory( mDefaultTemplatesDir );
else
{
const QStringList paths = QgsApplication::layoutTemplatePaths();
if ( !paths.empty() )
openLocalDirectory( paths.at( 0 ) );
}
}

void QgsLayoutManagerDialog::mTemplatesUserDirBtn_pressed()
Expand Down Expand Up @@ -330,6 +340,11 @@ void QgsLayoutManagerDialog::openLocalDirectory( const QString &localDirPath )
}
}

void QgsLayoutManagerDialog::updateTemplateButtonEnabledState()
{
mTemplatesDefaultDirBtn->setEnabled( QDir( mDefaultTemplatesDir ).exists() || !QgsApplication::layoutTemplatePaths().empty() );
}

#ifdef Q_OS_MAC
void QgsLayoutManagerDialog::showEvent( QShowEvent *event )
{
Expand Down
6 changes: 4 additions & 2 deletions src/app/layout/qgslayoutmanagerdialog.h
Expand Up @@ -85,18 +85,20 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase

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

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

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

void updateTemplateButtonEnabledState();

QString mDefaultTemplatesDir;
QString mUserTemplatesDir;
QPushButton *mCreateReportButton = nullptr;
Expand Down

0 comments on commit e7d4453

Please sign in to comment.