-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add UI for configuring layer-by-layer export attributes and…
… layer groups to GeoPDF export Allows users to set on a layer-by-layer basis whether layers should be identifiable and include vector features in a GeoPDF export, and optionally whether to group multiple layers together into a single logical, switchable entry in the GeoPDF layer tree.
- Loading branch information
1 parent
2ca3029
commit 7c22da0
Showing
5 changed files
with
241 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/*************************************************************************** | ||
qgsgeopdflayertreemodel.cpp | ||
--------------------- | ||
begin : August 2019 | ||
copyright : (C) 2019 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <QComboBox> | ||
#include <QDoubleSpinBox> | ||
|
||
#include "qgsgeopdflayertreemodel.h" | ||
#include "qgslayertree.h" | ||
#include "qgsproject.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsapplication.h" | ||
|
||
QgsGeoPdfLayerTreeModel::QgsGeoPdfLayerTreeModel( QgsLayerTree *rootNode, QObject *parent ) | ||
: QgsLayerTreeModel( rootNode, parent ) | ||
{ | ||
setFlags( nullptr ); // ideally we'd just show embedded legend nodes - but the api doesn't exist for this | ||
} | ||
|
||
int QgsGeoPdfLayerTreeModel::columnCount( const QModelIndex &parent ) const | ||
{ | ||
Q_UNUSED( parent ) | ||
return 2; | ||
} | ||
|
||
Qt::ItemFlags QgsGeoPdfLayerTreeModel::flags( const QModelIndex &idx ) const | ||
{ | ||
if ( idx.column() == LayerColumn ) | ||
{ | ||
return QgsLayerTreeModel::flags( idx ) | Qt::ItemIsUserCheckable; | ||
} | ||
|
||
QgsVectorLayer *vl = vectorLayer( idx ); | ||
if ( !vl ) | ||
{ | ||
return Qt::NoItemFlags; | ||
} | ||
else | ||
{ | ||
const QModelIndex layerIndex = sibling( idx.row(), LayerColumn, idx ); | ||
if ( data( layerIndex, Qt::CheckStateRole ) == Qt::Checked ) | ||
{ | ||
return Qt::ItemIsEnabled | Qt::ItemIsEditable; | ||
} | ||
} | ||
return Qt::NoItemFlags; | ||
} | ||
|
||
QgsVectorLayer *QgsGeoPdfLayerTreeModel::vectorLayer( const QModelIndex &idx ) const | ||
{ | ||
QgsLayerTreeNode *node = index2node( index( idx.row(), LayerColumn, idx.parent() ) ); | ||
if ( !node || !QgsLayerTree::isLayer( node ) ) | ||
return nullptr; | ||
|
||
return qobject_cast<QgsVectorLayer *>( QgsLayerTree::toLayer( node )->layer() ); | ||
} | ||
|
||
QVariant QgsGeoPdfLayerTreeModel::headerData( int section, Qt::Orientation orientation, int role ) const | ||
{ | ||
if ( orientation == Qt::Horizontal ) | ||
{ | ||
if ( role == Qt::DisplayRole ) | ||
{ | ||
switch ( section ) | ||
{ | ||
case 0: | ||
return tr( "Layer" ); | ||
case 1: | ||
return tr( "PDF Group" ); | ||
default: | ||
return QVariant(); | ||
} | ||
} | ||
} | ||
return QgsLayerTreeModel::headerData( section, orientation, role ); | ||
} | ||
|
||
QVariant QgsGeoPdfLayerTreeModel::data( const QModelIndex &idx, int role ) const | ||
{ | ||
switch ( idx.column() ) | ||
{ | ||
case LayerColumn: | ||
{ | ||
if ( role == Qt::CheckStateRole ) | ||
{ | ||
QgsLayerTreeNode *node = index2node( index( idx.row(), LayerColumn, idx.parent() ) ); | ||
QgsVectorLayer *vl = vectorLayer( idx ); | ||
if ( vl ) | ||
{ | ||
const QVariant v = vl->customProperty( QStringLiteral( "geopdf/includeFeatures" ) ); | ||
if ( v.isValid() ) | ||
{ | ||
return v.toBool() ? Qt::Checked : Qt::Unchecked; | ||
} | ||
else | ||
{ | ||
// otherwise, we default to the layer's visibility | ||
return node->itemVisibilityChecked() ? Qt::Checked : Qt::Unchecked; | ||
} | ||
} | ||
return QVariant(); | ||
} | ||
return QgsLayerTreeModel::data( idx, role ); | ||
} | ||
case GroupColumn: | ||
{ | ||
switch ( role ) | ||
{ | ||
case Qt::DisplayRole: | ||
{ | ||
if ( QgsVectorLayer *vl = vectorLayer( idx ) ) | ||
{ | ||
return vl->customProperty( QStringLiteral( "geopdf/groupName" ) ).toString(); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
return QVariant(); | ||
} | ||
} | ||
|
||
return QVariant(); | ||
} | ||
|
||
bool QgsGeoPdfLayerTreeModel::setData( const QModelIndex &index, const QVariant &value, int role ) | ||
{ | ||
switch ( index.column() ) | ||
{ | ||
case LayerColumn: | ||
{ | ||
if ( role == Qt::CheckStateRole ) | ||
{ | ||
if ( QgsVectorLayer *vl = vectorLayer( index ) ) | ||
{ | ||
vl->setCustomProperty( QStringLiteral( "geopdf/includeFeatures" ), value.toInt() == Qt::Checked ); | ||
emit dataChanged( index, index ); | ||
return true; | ||
} | ||
} | ||
break; | ||
} | ||
|
||
case GroupColumn: | ||
{ | ||
if ( role == Qt::EditRole ) | ||
{ | ||
if ( QgsVectorLayer *vl = vectorLayer( index ) ) | ||
{ | ||
vl->setCustomProperty( QStringLiteral( "geopdf/groupName" ), value.toString() ); | ||
emit dataChanged( index, index ); | ||
return true; | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*************************************************************************** | ||
qgsgeopdflayertreemodel.h | ||
--------------------- | ||
begin : August 2019 | ||
copyright : (C) 2019 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSGEOPDFLAYERTREEMODEL_H | ||
#define QGSGEOPDFLAYERTREEMODEL_H | ||
|
||
#include <QSortFilterProxyModel> | ||
#include <QItemDelegate> | ||
|
||
#include "qgslayertreemodel.h" | ||
#include "qgis_app.h" | ||
|
||
class QgsMapCanvas; | ||
class QgsProject; | ||
|
||
|
||
class APP_EXPORT QgsGeoPdfLayerTreeModel : public QgsLayerTreeModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsGeoPdfLayerTreeModel( QgsLayerTree *rootNode, QObject *parent = nullptr ); | ||
|
||
int columnCount( const QModelIndex &parent ) const override; | ||
QVariant headerData( int section, Qt::Orientation orientation, int role ) const override; | ||
Qt::ItemFlags flags( const QModelIndex &idx ) const override; | ||
QVariant data( const QModelIndex &index, int role ) const override; | ||
bool setData( const QModelIndex &index, const QVariant &value, int role ) override; | ||
|
||
private: | ||
enum Columns | ||
{ | ||
LayerColumn = 0, | ||
GroupColumn | ||
}; | ||
|
||
QgsVectorLayer *vectorLayer( const QModelIndex &idx ) const; | ||
}; | ||
|
||
#endif // QGSGEOPDFLAYERTREEMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters