Skip to content
Permalink
Browse files

[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
  • Loading branch information
nyalldawson committed May 28, 2020
1 parent 601a717 commit 1022f3fed60e107a622c02d68d3e5f31f086797e
@@ -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 );
}
}
@@ -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
{
@@ -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 );

@@ -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 );
}
@@ -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 ) );
}
}
@@ -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.
@@ -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;

};

0 comments on commit 1022f3f

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