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
  • Loading branch information
nyalldawson committed May 28, 2020
1 parent 1022f3f commit 8632bf6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/gui/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/gui/layout/qgsgeopdflayertreemodel.h
Expand Up @@ -61,4 +61,19 @@ class GUI_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/gui/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/gui/layout/qgslayoutpdfexportoptionsdialog.h
Expand Up @@ -28,6 +28,7 @@
#include "qgsrendercontext.h"

class QgsGeoPdfLayerTreeModel;
class QgsGeoPdfLayerFilteredTreeModel;

/**
* \ingroup gui
Expand Down Expand Up @@ -105,6 +106,7 @@ class GUI_EXPORT QgsLayoutPdfExportOptionsDialog: public QDialog, private Ui::Qg

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

};
Expand Down

0 comments on commit 8632bf6

Please sign in to comment.