mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
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
This commit is contained in:
parent
898c6a19e8
commit
ae3b39bd1e
@ -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();
|
||||
}
|
||||
|
||||
@ -148,6 +150,7 @@ void QgsLayoutManagerDialog::addTemplates( const QMap<QString, QString> &templat
|
||||
|
||||
void QgsLayoutManagerDialog::activate()
|
||||
{
|
||||
updateTemplateButtonEnabledState();
|
||||
raise();
|
||||
setWindowState( windowState() & ~Qt::WindowMinimized );
|
||||
activateWindow();
|
||||
@ -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();
|
||||
@ -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()
|
||||
@ -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 )
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ 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;
|
||||
@ -56,10 +56,12 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user