Skip to content

Commit 1022f3f

Browse files
committedMay 28, 2020
[layouts] Allow checking all or unchecking all items in the geopdf
export options dialog at once Right click on the list shows a "Select All"/"Deselect All" option Fixes #32281
1 parent 601a717 commit 1022f3f

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed
 

‎src/gui/layout/qgsgeopdflayertreemodel.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,13 @@ bool QgsGeoPdfLayerTreeModel::setData( const QModelIndex &index, const QVariant
169169
}
170170
return false;
171171
}
172+
173+
void QgsGeoPdfLayerTreeModel::checkAll( bool checked, const QModelIndex &parent )
174+
{
175+
for ( int row = 0; row < rowCount( parent ); ++row )
176+
{
177+
const QModelIndex childIndex = index( row, LayerColumn, parent );
178+
setData( childIndex, checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
179+
checkAll( checked, childIndex );
180+
}
181+
}

‎src/gui/layout/qgsgeopdflayertreemodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class GUI_EXPORT QgsGeoPdfLayerTreeModel : public QgsLayerTreeModel
4949
QVariant data( const QModelIndex &index, int role ) const override;
5050
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
5151

52+
void checkAll( bool checked, const QModelIndex &parent = QModelIndex() );
53+
5254
private:
5355
enum Columns
5456
{

‎src/gui/layout/qgslayoutpdfexportoptionsdialog.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626

2727
#include <QCheckBox>
2828
#include <QPushButton>
29+
#include <QMenu>
2930

3031
QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *parent, Qt::WindowFlags flags )
3132
: QDialog( parent, flags )
3233
{
3334
setupUi( this );
3435

36+
mGeoPdfStructureTreeMenu = new QMenu( this );
37+
3538
mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
3639
mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), QgsRenderContext::TextFormatAlwaysText );
3740

@@ -64,12 +67,20 @@ QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *paren
6467
mThemesList->addItem( item );
6568
}
6669

67-
QgsGeoPdfLayerTreeModel *model = new QgsGeoPdfLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
68-
mGeoPdfStructureTree->setModel( model );
70+
mGeoPdfStructureModel = new QgsGeoPdfLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
71+
mGeoPdfStructureTree->setModel( mGeoPdfStructureModel );
6972
mGeoPdfStructureTree->resizeColumnToContents( 0 );
7073
mGeoPdfStructureTree->header()->show();
7174
mGeoPdfStructureTree->setSelectionMode( QAbstractItemView::NoSelection );
7275

76+
mGeoPdfStructureTree->setContextMenuPolicy( Qt::CustomContextMenu );
77+
connect( mGeoPdfStructureTree, &QTreeView::customContextMenuRequested, this, [ = ]( const QPoint & point )
78+
{
79+
const QModelIndex index = mGeoPdfStructureTree->indexAt( point );
80+
if ( index.isValid() )
81+
showContextMenuForGeoPdfStructure( point, index );
82+
} );
83+
7384
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );
7485
QgsGui::enableAutoGeometryRestore( this );
7586
}
@@ -226,3 +237,36 @@ void QgsLayoutPdfExportOptionsDialog::showHelp()
226237
{
227238
QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
228239
}
240+
241+
void QgsLayoutPdfExportOptionsDialog::showContextMenuForGeoPdfStructure( QPoint point, const QModelIndex &index )
242+
{
243+
mGeoPdfStructureTreeMenu->clear();
244+
245+
switch ( index.column() )
246+
{
247+
case 0:
248+
{
249+
QAction *selectAll = new QAction( tr( "Select All" ), mGeoPdfStructureTreeMenu );
250+
mGeoPdfStructureTreeMenu->addAction( selectAll );
251+
connect( selectAll, &QAction::triggered, this, [ = ]
252+
{
253+
mGeoPdfStructureModel->checkAll( true );
254+
} );
255+
QAction *deselectAll = new QAction( tr( "Deselect All" ), mGeoPdfStructureTreeMenu );
256+
mGeoPdfStructureTreeMenu->addAction( deselectAll );
257+
connect( deselectAll, &QAction::triggered, this, [ = ]
258+
{
259+
mGeoPdfStructureModel->checkAll( false );
260+
} );
261+
break;
262+
}
263+
264+
default:
265+
break;
266+
}
267+
268+
if ( !mGeoPdfStructureTreeMenu->actions().empty() )
269+
{
270+
mGeoPdfStructureTreeMenu->exec( mGeoPdfStructureTree->mapToGlobal( point ) );
271+
}
272+
}

‎src/gui/layout/qgslayoutpdfexportoptionsdialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include "qgsrendercontext.h"
2929

30+
class QgsGeoPdfLayerTreeModel;
31+
3032
/**
3133
* \ingroup gui
3234
* A dialog for customizing the properties of an exported PDF file from a layout.
@@ -97,10 +99,13 @@ class GUI_EXPORT QgsLayoutPdfExportOptionsDialog: public QDialog, private Ui::Qg
9799
private slots:
98100

99101
void showHelp();
102+
void showContextMenuForGeoPdfStructure( QPoint point, const QModelIndex &index );
100103

101104
private:
102105

103106
bool mGeopdfAvailable = true;
107+
QgsGeoPdfLayerTreeModel *mGeoPdfStructureModel = nullptr;
108+
QMenu *mGeoPdfStructureTreeMenu = nullptr;
104109

105110
};
106111

0 commit comments

Comments
 (0)
Please sign in to comment.