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 898c6a1 commit ae3b39b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/app/layout/qgslayoutmanagerdialog.cpp
Original file line number Diff line number Diff line change
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 All @@ -163,9 +166,8 @@ QMap<QString, QString> QgsLayoutManagerDialog::defaultTemplates( bool fromUser )
QMap<QString, QString> QgsLayoutManagerDialog::otherTemplates() const
{
QMap<QString, QString> templateMap;
QStringList paths = QgsApplication::layoutTemplatePaths();
const auto constPaths = paths;
for ( const QString &path : constPaths )
const QStringList paths = QgsApplication::layoutTemplatePaths();
for ( const QString &path : paths )
{
QMap<QString, QString> templates = templatesFromPath( path );
QMap<QString, QString>::const_iterator templateIt = templates.constBegin();
Expand Down Expand Up @@ -285,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 @@ -331,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
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,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 ae3b39b

Please sign in to comment.