Skip to content

Commit 8bbee9a

Browse files
committedMay 7, 2020
turn "Export atlas" button in the Layout Designer into drop-down button
menu (fix #25899) So this button works ins the same way as menu buttons with popup in the QGIS main window, namely remember last used tool and allow either to click on the button itself to perform export in desired format or click on the dropdown button to choose different action.
1 parent e441eaa commit 8bbee9a

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed
 

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,30 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
435435
resizeToolButton->setDefaultAction( mActionResizeNarrowest );
436436
mActionsToolbar->addWidget( resizeToolButton );
437437

438-
QToolButton *atlasExportToolButton = new QToolButton( mAtlasToolbar );
439-
atlasExportToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionExport.svg" ) ) );
440-
atlasExportToolButton->setPopupMode( QToolButton::InstantPopup );
441-
atlasExportToolButton->setAutoRaise( true );
442-
atlasExportToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
443-
atlasExportToolButton->addAction( mActionExportAtlasAsImage );
444-
atlasExportToolButton->addAction( mActionExportAtlasAsSVG );
445-
atlasExportToolButton->addAction( mActionExportAtlasAsPDF );
446-
atlasExportToolButton->setToolTip( tr( "Export Atlas" ) );
447-
mAtlasToolbar->insertWidget( mActionAtlasSettings, atlasExportToolButton );
438+
QToolButton *bt = new QToolButton( mAtlasToolbar );
439+
bt->setPopupMode( QToolButton::MenuButtonPopup );
440+
bt->addAction( mActionExportAtlasAsImage );
441+
bt->addAction( mActionExportAtlasAsSVG );
442+
bt->addAction( mActionExportAtlasAsPDF );
443+
444+
QAction *defAtlasExportAction = mActionExportAtlasAsImage;
445+
switch ( settings.value( QStringLiteral( "LayoutDesigner/atlasExportAction" ), 0 ).toInt() )
446+
{
447+
case 0:
448+
defAtlasExportAction = mActionExportAtlasAsImage;
449+
break;
450+
case 1:
451+
defAtlasExportAction = mActionExportAtlasAsSVG;
452+
break;
453+
case 2:
454+
defAtlasExportAction = mActionExportAtlasAsPDF;
455+
break;
456+
}
457+
bt->setDefaultAction( defAtlasExportAction );
458+
QAction *atlasExportAction = mAtlasToolbar->insertWidget( mActionAtlasSettings, bt );
459+
atlasExportAction->setObjectName( QStringLiteral( "AtlasExport" ) );
460+
connect( bt, &QToolButton::triggered, this, &QgsLayoutDesignerDialog::toolButtonActionTriggered );
461+
448462
mAtlasPageComboBox = new QComboBox();
449463
mAtlasPageComboBox->setEditable( true );
450464
mAtlasPageComboBox->addItem( QString::number( 1 ) );
@@ -4787,4 +4801,19 @@ void QgsLayoutDesignerDialog::setSectionTitle( const QString &title )
47874801
mView->setSectionLabel( title );
47884802
}
47894803

4804+
void QgsLayoutDesignerDialog::toolButtonActionTriggered( QAction *action )
4805+
{
4806+
QToolButton *bt = qobject_cast<QToolButton *>( sender() );
4807+
if ( !bt )
4808+
return;
4809+
4810+
QgsSettings settings;
4811+
if ( action == mActionExportAtlasAsImage )
4812+
settings.setValue( QStringLiteral( "LayoutDesigner/atlasExportAction" ), 0 );
4813+
else if ( action == mActionExportAtlasAsSVG )
4814+
settings.setValue( QStringLiteral( "LayoutDesigner/atlasExportAction" ), 2 );
4815+
else if ( action == mActionExportAtlasAsPDF )
4816+
settings.setValue( QStringLiteral( "LayoutDesigner/atlasExportAction" ), 3 );
47904817

4818+
bt->setDefaultAction( action );
4819+
}

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
555555
void setLastExportPath( const QString &path ) const;
556556

557557
bool checkBeforeExport();
558+
559+
//! update default action of toolbutton
560+
void toolButtonActionTriggered( QAction * );
558561
};
559562

560563
#endif // QGSLAYOUTDESIGNERDIALOG_H

0 commit comments

Comments
 (0)
Please sign in to comment.