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

(cherry picked from commit cbfc112)
(cherry picked from commit 4ac5b98)
  • Loading branch information
nyalldawson committed Jun 19, 2020
1 parent 1283ea3 commit ea990fb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/app/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/app/layout/qgsgeopdflayertreemodel.h
Expand Up @@ -38,6 +38,8 @@ class APP_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/app/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/app/layout/qgslayoutpdfexportoptionsdialog.h
Expand Up @@ -23,6 +23,8 @@

#include "qgsrendercontext.h"

class QgsGeoPdfLayerTreeModel;

/**
* A dialog for customizing the properties of an exported PDF file from a layout.
*/
Expand Down Expand Up @@ -67,10 +69,13 @@ class QgsLayoutPdfExportOptionsDialog: public QDialog, private Ui::QgsPdfExportO
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 ea990fb

Please sign in to comment.