Skip to content

Commit 8632bf6

Browse files
committedMay 28, 2020
Only show vector layers in GeoPDF export vector attributes tree view
This option only makes sense for vector layers, so filter out rasters and other layer types
1 parent 1022f3f commit 8632bf6

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed
 

‎src/gui/layout/qgsgeopdflayertreemodel.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,24 @@ void QgsGeoPdfLayerTreeModel::checkAll( bool checked, const QModelIndex &parent
179179
checkAll( checked, childIndex );
180180
}
181181
}
182+
183+
///@cond PRIVATE
184+
QgsGeoPdfLayerFilteredTreeModel::QgsGeoPdfLayerFilteredTreeModel( QgsGeoPdfLayerTreeModel *sourceModel, QObject *parent )
185+
: QSortFilterProxyModel( parent )
186+
, mLayerTreeModel( sourceModel )
187+
{
188+
setSourceModel( sourceModel );
189+
}
190+
191+
bool QgsGeoPdfLayerFilteredTreeModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
192+
{
193+
if ( QgsLayerTreeNode *node = mLayerTreeModel->index2node( sourceModel()->index( source_row, 0, source_parent ) ) )
194+
{
195+
// filter out non-vector layers
196+
if ( QgsLayerTree::isLayer( node ) && QgsLayerTree::toLayer( node ) && QgsLayerTree::toLayer( node )->layer() && QgsLayerTree::toLayer( node )->layer()->type() != QgsMapLayerType::VectorLayer )
197+
return false;
198+
}
199+
return true;
200+
}
201+
202+
///@endcond

‎src/gui/layout/qgsgeopdflayertreemodel.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,19 @@ class GUI_EXPORT QgsGeoPdfLayerTreeModel : public QgsLayerTreeModel
6161
QgsVectorLayer *vectorLayer( const QModelIndex &idx ) const;
6262
};
6363

64+
65+
///@cond PRIVATE
66+
class GUI_EXPORT QgsGeoPdfLayerFilteredTreeModel : public QSortFilterProxyModel
67+
{
68+
public:
69+
70+
QgsGeoPdfLayerFilteredTreeModel( QgsGeoPdfLayerTreeModel *sourceModel, QObject *parent = nullptr );
71+
72+
bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
73+
74+
private:
75+
QgsGeoPdfLayerTreeModel *mLayerTreeModel = nullptr;
76+
};
77+
///@endcond
78+
6479
#endif // QGSGEOPDFLAYERTREEMODEL_H

‎src/gui/layout/qgslayoutpdfexportoptionsdialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *paren
6868
}
6969

7070
mGeoPdfStructureModel = new QgsGeoPdfLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
71-
mGeoPdfStructureTree->setModel( mGeoPdfStructureModel );
71+
mGeoPdfStructureProxyModel = new QgsGeoPdfLayerFilteredTreeModel( mGeoPdfStructureModel, this );
72+
mGeoPdfStructureTree->setModel( mGeoPdfStructureProxyModel );
7273
mGeoPdfStructureTree->resizeColumnToContents( 0 );
7374
mGeoPdfStructureTree->header()->show();
7475
mGeoPdfStructureTree->setSelectionMode( QAbstractItemView::NoSelection );
@@ -78,7 +79,7 @@ QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *paren
7879
{
7980
const QModelIndex index = mGeoPdfStructureTree->indexAt( point );
8081
if ( index.isValid() )
81-
showContextMenuForGeoPdfStructure( point, index );
82+
showContextMenuForGeoPdfStructure( point, mGeoPdfStructureProxyModel->mapToSource( index ) );
8283
} );
8384

8485
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );

‎src/gui/layout/qgslayoutpdfexportoptionsdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsrendercontext.h"
2929

3030
class QgsGeoPdfLayerTreeModel;
31+
class QgsGeoPdfLayerFilteredTreeModel;
3132

3233
/**
3334
* \ingroup gui
@@ -105,6 +106,7 @@ class GUI_EXPORT QgsLayoutPdfExportOptionsDialog: public QDialog, private Ui::Qg
105106

106107
bool mGeopdfAvailable = true;
107108
QgsGeoPdfLayerTreeModel *mGeoPdfStructureModel = nullptr;
109+
QgsGeoPdfLayerFilteredTreeModel *mGeoPdfStructureProxyModel = nullptr;
108110
QMenu *mGeoPdfStructureTreeMenu = nullptr;
109111

110112
};

0 commit comments

Comments
 (0)
Please sign in to comment.