Skip to content

Commit

Permalink
[layouts] Allow checking all or unchecking all items in the geopdf
Browse files Browse the repository at this point in the history
export options dialog at once

Right click on the list shows a "Select All"/"Deselect All" option

Fixes #32281
  • Loading branch information
nyalldawson committed May 28, 2020
1 parent 601a717 commit 1022f3f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/gui/layout/qgsgeopdflayertreemodel.cpp
Expand Up @@ -169,3 +169,13 @@ bool QgsGeoPdfLayerTreeModel::setData( const QModelIndex &index, const QVariant
}
return false;
}

void QgsGeoPdfLayerTreeModel::checkAll( bool checked, const QModelIndex &parent )
{
for ( int row = 0; row < rowCount( parent ); ++row )
{
const QModelIndex childIndex = index( row, LayerColumn, parent );
setData( childIndex, checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
checkAll( checked, childIndex );
}
}
2 changes: 2 additions & 0 deletions src/gui/layout/qgsgeopdflayertreemodel.h
Expand Up @@ -49,6 +49,8 @@ class GUI_EXPORT QgsGeoPdfLayerTreeModel : public QgsLayerTreeModel
QVariant data( const QModelIndex &index, int role ) const override;
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;

void checkAll( bool checked, const QModelIndex &parent = QModelIndex() );

private:
enum Columns
{
Expand Down
48 changes: 46 additions & 2 deletions src/gui/layout/qgslayoutpdfexportoptionsdialog.cpp
Expand Up @@ -26,12 +26,15 @@

#include <QCheckBox>
#include <QPushButton>
#include <QMenu>

QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *parent, Qt::WindowFlags flags )
: QDialog( parent, flags )
{
setupUi( this );

mGeoPdfStructureTreeMenu = new QMenu( this );

mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), QgsRenderContext::TextFormatAlwaysText );

Expand Down Expand Up @@ -64,12 +67,20 @@ QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *paren
mThemesList->addItem( item );
}

QgsGeoPdfLayerTreeModel *model = new QgsGeoPdfLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
mGeoPdfStructureTree->setModel( model );
mGeoPdfStructureModel = new QgsGeoPdfLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
mGeoPdfStructureTree->setModel( mGeoPdfStructureModel );
mGeoPdfStructureTree->resizeColumnToContents( 0 );
mGeoPdfStructureTree->header()->show();
mGeoPdfStructureTree->setSelectionMode( QAbstractItemView::NoSelection );

mGeoPdfStructureTree->setContextMenuPolicy( Qt::CustomContextMenu );
connect( mGeoPdfStructureTree, &QTreeView::customContextMenuRequested, this, [ = ]( const QPoint & point )
{
const QModelIndex index = mGeoPdfStructureTree->indexAt( point );
if ( index.isValid() )
showContextMenuForGeoPdfStructure( point, index );
} );

connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );
QgsGui::enableAutoGeometryRestore( this );
}
Expand Down Expand Up @@ -226,3 +237,36 @@ void QgsLayoutPdfExportOptionsDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
}

void QgsLayoutPdfExportOptionsDialog::showContextMenuForGeoPdfStructure( QPoint point, const QModelIndex &index )
{
mGeoPdfStructureTreeMenu->clear();

switch ( index.column() )
{
case 0:
{
QAction *selectAll = new QAction( tr( "Select All" ), mGeoPdfStructureTreeMenu );
mGeoPdfStructureTreeMenu->addAction( selectAll );
connect( selectAll, &QAction::triggered, this, [ = ]
{
mGeoPdfStructureModel->checkAll( true );
} );
QAction *deselectAll = new QAction( tr( "Deselect All" ), mGeoPdfStructureTreeMenu );
mGeoPdfStructureTreeMenu->addAction( deselectAll );
connect( deselectAll, &QAction::triggered, this, [ = ]
{
mGeoPdfStructureModel->checkAll( false );
} );
break;
}

default:
break;
}

if ( !mGeoPdfStructureTreeMenu->actions().empty() )
{
mGeoPdfStructureTreeMenu->exec( mGeoPdfStructureTree->mapToGlobal( point ) );
}
}
5 changes: 5 additions & 0 deletions src/gui/layout/qgslayoutpdfexportoptionsdialog.h
Expand Up @@ -27,6 +27,8 @@

#include "qgsrendercontext.h"

class QgsGeoPdfLayerTreeModel;

/**
* \ingroup gui
* A dialog for customizing the properties of an exported PDF file from a layout.
Expand Down Expand Up @@ -97,10 +99,13 @@ class GUI_EXPORT QgsLayoutPdfExportOptionsDialog: public QDialog, private Ui::Qg
private slots:

void showHelp();
void showContextMenuForGeoPdfStructure( QPoint point, const QModelIndex &index );

private:

bool mGeopdfAvailable = true;
QgsGeoPdfLayerTreeModel *mGeoPdfStructureModel = nullptr;
QMenu *mGeoPdfStructureTreeMenu = nullptr;

};

Expand Down

0 comments on commit 1022f3f

Please sign in to comment.