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

(cherry picked from commit 47e5651)
(cherry picked from commit b62dfd2)
  • Loading branch information
nyalldawson committed Jun 19, 2020
1 parent ea990fb commit 14e17b986dcc180928ecabc795e16dbfa4f876ea
@@ -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
@@ -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
@@ -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 );
@@ -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.
@@ -75,6 +76,7 @@ class QgsLayoutPdfExportOptionsDialog: public QDialog, private Ui::QgsPdfExportO

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

};

0 comments on commit 14e17b9

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