Skip to content

Commit

Permalink
Only show vector layers in GeoPDF export vector attributes tree view
Browse files Browse the repository at this point in the history
This option only makes sense for vector layers, so filter out rasters
and other layer types

(cherry picked from commit 47e5651)
(cherry picked from commit b62dfd2)
  • Loading branch information
nyalldawson committed Jun 19, 2020
1 parent ea990fb commit 14e17b9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/app/layout/qgsgeopdflayertreemodel.cpp
Expand Up @@ -179,3 +179,24 @@ void QgsGeoPdfLayerTreeModel::checkAll( bool checked, const QModelIndex &parent
checkAll( checked, childIndex );
}
}

///@cond PRIVATE
QgsGeoPdfLayerFilteredTreeModel::QgsGeoPdfLayerFilteredTreeModel( QgsGeoPdfLayerTreeModel *sourceModel, QObject *parent )
: QSortFilterProxyModel( parent )
, mLayerTreeModel( sourceModel )
{
setSourceModel( sourceModel );
}

bool QgsGeoPdfLayerFilteredTreeModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
{
if ( QgsLayerTreeNode *node = mLayerTreeModel->index2node( sourceModel()->index( source_row, 0, source_parent ) ) )
{
// filter out non-vector layers
if ( QgsLayerTree::isLayer( node ) && QgsLayerTree::toLayer( node ) && QgsLayerTree::toLayer( node )->layer() && QgsLayerTree::toLayer( node )->layer()->type() != QgsMapLayerType::VectorLayer )
return false;
}
return true;
}

///@endcond
15 changes: 15 additions & 0 deletions src/app/layout/qgsgeopdflayertreemodel.h
Expand Up @@ -50,4 +50,19 @@ class APP_EXPORT QgsGeoPdfLayerTreeModel : public QgsLayerTreeModel
QgsVectorLayer *vectorLayer( const QModelIndex &idx ) const;
};


///@cond PRIVATE
class GUI_EXPORT QgsGeoPdfLayerFilteredTreeModel : public QSortFilterProxyModel
{
public:

QgsGeoPdfLayerFilteredTreeModel( QgsGeoPdfLayerTreeModel *sourceModel, QObject *parent = nullptr );

bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;

private:
QgsGeoPdfLayerTreeModel *mLayerTreeModel = nullptr;
};
///@endcond

#endif // QGSGEOPDFLAYERTREEMODEL_H
5 changes: 3 additions & 2 deletions src/app/layout/qgslayoutpdfexportoptionsdialog.cpp
Expand Up @@ -68,7 +68,8 @@ QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *paren
}

mGeoPdfStructureModel = new QgsGeoPdfLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
mGeoPdfStructureTree->setModel( mGeoPdfStructureModel );
mGeoPdfStructureProxyModel = new QgsGeoPdfLayerFilteredTreeModel( mGeoPdfStructureModel, this );
mGeoPdfStructureTree->setModel( mGeoPdfStructureProxyModel );
mGeoPdfStructureTree->resizeColumnToContents( 0 );
mGeoPdfStructureTree->header()->show();
mGeoPdfStructureTree->setSelectionMode( QAbstractItemView::NoSelection );
Expand All @@ -78,7 +79,7 @@ QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *paren
{
const QModelIndex index = mGeoPdfStructureTree->indexAt( point );
if ( index.isValid() )
showContextMenuForGeoPdfStructure( point, index );
showContextMenuForGeoPdfStructure( point, mGeoPdfStructureProxyModel->mapToSource( index ) );
} );

connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout/qgslayoutpdfexportoptionsdialog.h
Expand Up @@ -24,6 +24,7 @@
#include "qgsrendercontext.h"

class QgsGeoPdfLayerTreeModel;
class QgsGeoPdfLayerFilteredTreeModel;

/**
* A dialog for customizing the properties of an exported PDF file from a layout.
Expand Down Expand Up @@ -75,6 +76,7 @@ class QgsLayoutPdfExportOptionsDialog: public QDialog, private Ui::QgsPdfExportO

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

};
Expand Down

0 comments on commit 14e17b9

Please sign in to comment.