Skip to content
Permalink
Browse files

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.
  • Loading branch information
alexbruy committed May 7, 2020
1 parent e441eaa commit 8bbee9abc48f5155fe0bca4398eaa5cf3cfa1f5a
Showing with 42 additions and 10 deletions.
  1. +39 −10 src/app/layout/qgslayoutdesignerdialog.cpp
  2. +3 −0 src/app/layout/qgslayoutdesignerdialog.h
@@ -435,16 +435,30 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
resizeToolButton->setDefaultAction( mActionResizeNarrowest );
mActionsToolbar->addWidget( resizeToolButton );

QToolButton *atlasExportToolButton = new QToolButton( mAtlasToolbar );
atlasExportToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionExport.svg" ) ) );
atlasExportToolButton->setPopupMode( QToolButton::InstantPopup );
atlasExportToolButton->setAutoRaise( true );
atlasExportToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
atlasExportToolButton->addAction( mActionExportAtlasAsImage );
atlasExportToolButton->addAction( mActionExportAtlasAsSVG );
atlasExportToolButton->addAction( mActionExportAtlasAsPDF );
atlasExportToolButton->setToolTip( tr( "Export Atlas" ) );
mAtlasToolbar->insertWidget( mActionAtlasSettings, atlasExportToolButton );
QToolButton *bt = new QToolButton( mAtlasToolbar );
bt->setPopupMode( QToolButton::MenuButtonPopup );
bt->addAction( mActionExportAtlasAsImage );
bt->addAction( mActionExportAtlasAsSVG );
bt->addAction( mActionExportAtlasAsPDF );

QAction *defAtlasExportAction = mActionExportAtlasAsImage;
switch ( settings.value( QStringLiteral( "LayoutDesigner/atlasExportAction" ), 0 ).toInt() )
{
case 0:
defAtlasExportAction = mActionExportAtlasAsImage;
break;
case 1:
defAtlasExportAction = mActionExportAtlasAsSVG;
break;
case 2:
defAtlasExportAction = mActionExportAtlasAsPDF;
break;
}
bt->setDefaultAction( defAtlasExportAction );
QAction *atlasExportAction = mAtlasToolbar->insertWidget( mActionAtlasSettings, bt );
atlasExportAction->setObjectName( QStringLiteral( "AtlasExport" ) );
connect( bt, &QToolButton::triggered, this, &QgsLayoutDesignerDialog::toolButtonActionTriggered );

mAtlasPageComboBox = new QComboBox();
mAtlasPageComboBox->setEditable( true );
mAtlasPageComboBox->addItem( QString::number( 1 ) );
@@ -4787,4 +4801,19 @@ void QgsLayoutDesignerDialog::setSectionTitle( const QString &title )
mView->setSectionLabel( title );
}

void QgsLayoutDesignerDialog::toolButtonActionTriggered( QAction *action )
{
QToolButton *bt = qobject_cast<QToolButton *>( sender() );
if ( !bt )
return;

QgsSettings settings;
if ( action == mActionExportAtlasAsImage )
settings.setValue( QStringLiteral( "LayoutDesigner/atlasExportAction" ), 0 );
else if ( action == mActionExportAtlasAsSVG )
settings.setValue( QStringLiteral( "LayoutDesigner/atlasExportAction" ), 2 );
else if ( action == mActionExportAtlasAsPDF )
settings.setValue( QStringLiteral( "LayoutDesigner/atlasExportAction" ), 3 );

bt->setDefaultAction( action );
}
@@ -555,6 +555,9 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
void setLastExportPath( const QString &path ) const;

bool checkBeforeExport();

//! update default action of toolbutton
void toolButtonActionTriggered( QAction * );
};

#endif // QGSLAYOUTDESIGNERDIALOG_H

0 comments on commit 8bbee9a

Please sign in to comment.
You can’t perform that action at this time.