Skip to content
Permalink
Browse files

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
  • Loading branch information
nyalldawson committed May 28, 2020
1 parent 1022f3f commit 8632bf68056b7a47982adb10ec79f532dc03376a
@@ -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
@@ -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
@@ -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 );
@@ -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 );
@@ -28,6 +28,7 @@
#include "qgsrendercontext.h"

class QgsGeoPdfLayerTreeModel;
class QgsGeoPdfLayerFilteredTreeModel;

/**
* \ingroup gui
@@ -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;

};

0 comments on commit 8632bf6

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