Skip to content
Permalink
Browse files

Hidden layers -> Private layers

  • Loading branch information
elpaso committed Nov 5, 2020
1 parent 61bd8a8 commit 26a9cdf5fd0be74421d8df6e414fdd225dd1619e
@@ -80,7 +80,7 @@ This is the base class for all map layer types (vector, raster).
Identifiable,
Removable,
Searchable,
Hidden,
Private,
};
typedef QFlags<QgsMapLayer::LayerFlag> LayerFlags;

@@ -16,7 +16,7 @@ class QgsLayerTreeProxyModel : QSortFilterProxyModel
%Docstring

The QgsLayerTreeProxyModel class is a proxy model for QgsLayerTreeModel, supports
hidden layers and text filtering.
private layers and text filtering.

.. versionadded:: 3.18
%End
@@ -36,14 +36,14 @@ Constructs QgsLayerTreeProxyModel with source model ``treeModel`` and a ``parent
Sets filter to ``filterText``.
%End

bool showHidden() const;
bool showPrivateLayers() const;
%Docstring
Returns if hidden layers are shown.
Returns if private layers are shown.
%End

void setShowHidden( bool showHidden );
void setShowPrivateLayers( bool showPrivate );
%Docstring
Determines if hidden layers are shown.
Determines if private layers are shown.
%End

protected:
@@ -333,16 +333,16 @@ Set the message bar to display messages from the layer tree
.. versionadded:: 3.14
%End

void setShowHidden( bool showHidden );
void setShowPrivateLayers( bool showPrivate );
%Docstring
Set the show hidden layers to ``showHidden``
Set the show private layers to ``showPrivate``

.. versionadded:: 3.18
%End

bool showHidden( );
bool showPrivateLayers( );
%Docstring
Returns the show hidden status
Returns the show private layers status

.. versionadded:: 3.18
%End
@@ -4774,10 +4774,10 @@ void QgisApp::initLayerTreeView()
connect( mFilterLegendByMapContentAction, &QAction::toggled, this, &QgisApp::updateFilterLegend );
filterLegendMenu->addAction( mFilterLegendByMapContentAction );

mFilterLegendToggleHiddenLayersAction = new QAction( tr( "Show Hidden Layers" ), this );
mFilterLegendToggleHiddenLayersAction->setCheckable( true );
connect( mFilterLegendToggleHiddenLayersAction, &QAction::toggled, this, [ = ]( bool showHidden ) { layerTreeView()->setShowHidden( showHidden ); } );
filterLegendMenu->addAction( mFilterLegendToggleHiddenLayersAction );
mFilterLegendToggleShowPrivateLayersAction = new QAction( tr( "Show Private Layers" ), this );
mFilterLegendToggleShowPrivateLayersAction->setCheckable( true );
connect( mFilterLegendToggleShowPrivateLayersAction, &QAction::toggled, this, [ = ]( bool showPrivateLayers ) { layerTreeView()->setShowPrivateLayers( showPrivateLayers ); } );
filterLegendMenu->addAction( mFilterLegendToggleShowPrivateLayersAction );

mLegendExpressionFilterButton = new QgsLegendFilterButton( this );
mLegendExpressionFilterButton->setToolTip( tr( "Filter legend by expression" ) );
@@ -11599,7 +11599,7 @@ void QgisApp::removeLayer()
if ( QgsLayerTree::isLayer( c ) )
{
const auto treeLayer { QgsLayerTree::toLayer( c ) };
if ( treeLayer->layer() && treeLayer->layer()->flags().testFlag( QgsMapLayer::LayerFlag::Hidden ) )
if ( treeLayer->layer() && treeLayer->layer()->flags().testFlag( QgsMapLayer::LayerFlag::Private ) )
{
hiddenLayerNames.push_back( treeLayer->layer()->name( ) );
}
@@ -2579,7 +2579,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QToolButton *mFilterLegendToolButton = nullptr;
QAction *mFilterLegendByMapContentAction = nullptr;
QAction *mFilterLegendToggleHiddenLayersAction = nullptr;
QAction *mFilterLegendToggleShowPrivateLayersAction = nullptr;
QAction *mActionStyleDock = nullptr;

QgsLegendFilterButton *mLegendExpressionFilterButton = nullptr;
@@ -32,7 +32,7 @@ QgsLayerCapabilitiesModel::QgsLayerCapabilitiesModel( QgsProject *project, QObje
mSearchableLayers.insert( it.value(), it.value()->type() == QgsMapLayerType::VectorLayer && it.value()->flags().testFlag( QgsMapLayer::Searchable ) );
mIdentifiableLayers.insert( it.value(), it.value()->flags().testFlag( QgsMapLayer::Identifiable ) );
mRemovableLayers.insert( it.value(), it.value()->flags().testFlag( QgsMapLayer::Removable ) );
mHiddenLayers.insert( it.value(), it.value()->flags().testFlag( QgsMapLayer::Hidden ) );
mPrivateLayers.insert( it.value(), it.value()->flags().testFlag( QgsMapLayer::Private ) );
}
}

@@ -77,9 +77,9 @@ bool QgsLayerCapabilitiesModel::removable( QgsMapLayer *layer ) const
return mRemovableLayers.value( layer, true );
}

bool QgsLayerCapabilitiesModel::hidden( QgsMapLayer *layer ) const
bool QgsLayerCapabilitiesModel::privateLayer( QgsMapLayer *layer ) const
{
return mHiddenLayers.value( layer, true );
return mPrivateLayers.value( layer, true );
}

bool QgsLayerCapabilitiesModel::readOnly( QgsMapLayer *layer ) const
@@ -116,8 +116,8 @@ QVariant QgsLayerCapabilitiesModel::headerData( int section, Qt::Orientation ori
return tr( "Searchable" );
case RequiredColumn:
return tr( "Required" );
case HiddenColumn:
return tr( "Hidden" );
case PrivateColumn:
return tr( "Private" );
default:
return QVariant();
}
@@ -133,7 +133,7 @@ QVariant QgsLayerCapabilitiesModel::headerData( int section, Qt::Orientation ori
return QVariant();
case RequiredColumn:
return tr( "Layers which are protected from inadvertent removal from the project." );
case HiddenColumn:
case PrivateColumn:
return tr( "Layers which are not shown in the legend." );
default:
return QVariant();
@@ -195,7 +195,7 @@ Qt::ItemFlags QgsLayerCapabilitiesModel::flags( const QModelIndex &idx ) const
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
}
case HiddenColumn:
case PrivateColumn:
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
}
@@ -295,8 +295,8 @@ QVariant QgsLayerCapabilitiesModel::data( const QModelIndex &idx, int role ) con
case RequiredColumn:
return !mRemovableLayers.value( layer, true ) ? trueValue : falseValue;

case HiddenColumn:
return mHiddenLayers.value( layer, false ) ? trueValue : falseValue;
case PrivateColumn:
return mPrivateLayers.value( layer, false ) ? trueValue : falseValue;
}
}
}
@@ -368,12 +368,12 @@ bool QgsLayerCapabilitiesModel::setData( const QModelIndex &index, const QVarian
}
break;
}
case HiddenColumn:
case PrivateColumn:
{
const bool hidden = value == Qt::Checked;
if ( hidden != mHiddenLayers.value( layer, false ) )
const bool isPrivate = value == Qt::Checked;
if ( isPrivate != mPrivateLayers.value( layer, false ) )
{
mHiddenLayers.insert( layer, hidden );
mPrivateLayers.insert( layer, isPrivate );
emit dataChanged( index, index );
return true;
}
@@ -40,7 +40,7 @@ class APP_EXPORT QgsLayerCapabilitiesModel : public QSortFilterProxyModel
ReadOnlyColumn,
SearchableColumn,
RequiredColumn,
HiddenColumn,
PrivateColumn,
};

QgsLayerCapabilitiesModel( QgsProject *project, QObject *parent = nullptr );
@@ -49,7 +49,7 @@ class APP_EXPORT QgsLayerCapabilitiesModel : public QSortFilterProxyModel
void setLayerTreeModel( QgsLayerTreeModel *layerTreeModel );
bool identifiable( QgsMapLayer *layer ) const;
bool removable( QgsMapLayer *layer ) const;
bool hidden( QgsMapLayer *layer ) const;
bool privateLayer( QgsMapLayer *layer ) const;
bool readOnly( QgsMapLayer *layer ) const;
bool searchable( QgsMapLayer *layer ) const;
QgsMapLayer *mapLayer( const QModelIndex &idx ) const;
@@ -81,7 +81,7 @@ class APP_EXPORT QgsLayerCapabilitiesModel : public QSortFilterProxyModel
QHash<QgsMapLayer *, bool> mSearchableLayers;
QHash<QgsMapLayer *, bool> mIdentifiableLayers;
QHash<QgsMapLayer *, bool> mRemovableLayers;
QHash<QgsMapLayer *, bool> mHiddenLayers;
QHash<QgsMapLayer *, bool> mPrivateLayers;

QgsLayerTreeModel *mLayerTreeModel = nullptr;
};
@@ -1190,10 +1190,10 @@ void QgsProjectProperties::apply()
else
flags &= ~QgsMapLayer::Searchable;

if ( mLayerCapabilitiesModel->hidden( layer ) )
flags |= QgsMapLayer::Hidden;
if ( mLayerCapabilitiesModel->privateLayer( layer ) )
flags |= QgsMapLayer::Private;
else
flags &= ~QgsMapLayer::Hidden;
flags &= ~QgsMapLayer::Private;

layer->setFlags( flags );

@@ -148,7 +148,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
Identifiable = 1 << 0, //!< If the layer is identifiable using the identify map tool and as a WMS layer.
Removable = 1 << 1, //!< If the layer can be removed from the project. The layer will not be removable from the legend menu entry but can still be removed with an API call.
Searchable = 1 << 2, //!< Only for vector-layer, determines if the layer is used in the 'search all layers' locator.
Hidden = 1 << 3, //!< Determines if the layer is visible in the layer legend tree.
Private = 1 << 3, //!< Determines if the layer is meant to be exposed to the GUI, i.e. visible in the layer legend tree.
};
Q_ENUM( LayerFlag )
Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
@@ -95,7 +95,7 @@ void QgsLayerTreeView::setModel( QAbstractItemModel *model )
);

mProxyModel = new QgsLayerTreeProxyModel( treeModel, this );
mProxyModel->setShowHidden( mShowHidden );
mProxyModel->setShowPrivateLayers( mShowPrivateLayers );
QTreeView::setModel( mProxyModel );

connect( treeModel->rootGroup(), &QgsLayerTreeNode::expandedChanged, this, &QgsLayerTreeView::onExpandedChanged );
@@ -546,15 +546,15 @@ void QgsLayerTreeView::setMessageBar( QgsMessageBar *messageBar )
);
}

void QgsLayerTreeView::setShowHidden( bool showHidden )
void QgsLayerTreeView::setShowPrivateLayers( bool showPrivate )
{
mShowHidden = showHidden;
mProxyModel->setShowHidden( showHidden );
mShowPrivateLayers = showPrivate;
mProxyModel->setShowPrivateLayers( showPrivate );
}

bool QgsLayerTreeView::showHidden()
bool QgsLayerTreeView::showPrivateLayers()
{
return mShowHidden;
return mShowPrivateLayers;
}

void QgsLayerTreeView::mouseReleaseEvent( QMouseEvent *event )
@@ -715,21 +715,21 @@ bool QgsLayerTreeProxyModel::nodeShown( QgsLayerTreeNode *node ) const
return true;
if ( !mFilterText.isEmpty() && !layer->name().contains( mFilterText, Qt::CaseInsensitive ) )
return false;
if ( ! mShowHidden && layer->flags().testFlag( QgsMapLayer::LayerFlag::Hidden ) )
if ( ! mShowPrivateLayers && layer->flags().testFlag( QgsMapLayer::LayerFlag::Private ) )
{
return false;
}
return true;
}
}

bool QgsLayerTreeProxyModel::showHidden() const
bool QgsLayerTreeProxyModel::showPrivateLayers() const
{
return mShowHidden;
return mShowPrivateLayers;
}

void QgsLayerTreeProxyModel::setShowHidden( bool showHidden )
void QgsLayerTreeProxyModel::setShowPrivateLayers( bool showPrivate )
{
mShowHidden = showHidden;
mShowPrivateLayers = showPrivate;
invalidateFilter();
}
@@ -39,7 +39,7 @@ class QgsLayerTreeFilterProxyModel;
* \ingroup gui
*
* The QgsLayerTreeProxyModel class is a proxy model for QgsLayerTreeModel, supports
* hidden layers and text filtering.
* private layers and text filtering.
*
* \since QGIS 3.18
*/
@@ -60,14 +60,14 @@ class GUI_EXPORT QgsLayerTreeProxyModel : public QSortFilterProxyModel
void setFilterText( const QString &filterText = QString() );

/**
* Returns if hidden layers are shown.
* Returns if private layers are shown.
*/
bool showHidden() const;
bool showPrivateLayers() const;

/**
* Determines if hidden layers are shown.
* Determines if private layers are shown.
*/
void setShowHidden( bool showHidden );
void setShowPrivateLayers( bool showPrivate );

protected:

@@ -79,7 +79,7 @@ class GUI_EXPORT QgsLayerTreeProxyModel : public QSortFilterProxyModel

QgsLayerTreeModel *mLayerTreeModel = nullptr;
QString mFilterText;
bool mShowHidden = false;
bool mShowPrivateLayers = false;
};


@@ -334,16 +334,16 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
void setMessageBar( QgsMessageBar *messageBar );

/**
* Set the show hidden layers to \a showHidden
* Set the show private layers to \a showPrivate
* \since QGIS 3.18
*/
void setShowHidden( bool showHidden );
void setShowPrivateLayers( bool showPrivate );

/**
* Returns the show hidden status
* Returns the show private layers status
* \since QGIS 3.18
*/
bool showHidden( );
bool showPrivateLayers( );

signals:
//! Emitted when a current layer is changed
@@ -401,7 +401,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView

QgsMessageBar *mMessageBar = nullptr;

bool mShowHidden = false;
bool mShowPrivateLayers = false;

// friend so it can access viewOptions() method and mLastReleaseMousePos without making them public
friend class QgsLayerTreeViewItemDelegate;
@@ -437,7 +437,7 @@ def testSetLayerVisible(self):
self.layer2).itemVisibilityChecked())

def testProxyModel(self):
"""Test proxy model filtering and hidden layers"""
"""Test proxy model filtering and private layers"""

view = QgsLayerTreeView()
view.setModel(self.model)
@@ -461,7 +461,7 @@ def testProxyModel(self):

self.assertEqual(proxy_items, ['layer1', 'layer2', 'layer3'])

self.layer3.setFlags(self.layer.Hidden)
self.layer3.setFlags(self.layer.Private)
self.assertEqual(tree_model.rowCount(), 3)
self.assertEqual(proxy_model.rowCount(), 2)

@@ -471,7 +471,7 @@ def testProxyModel(self):

self.assertEqual(proxy_items, ['layer1', 'layer2'])

view.setShowHidden(True)
view.setShowPrivateLayers(True)

self.assertEqual(proxy_model.rowCount(), 3)

@@ -481,7 +481,7 @@ def testProxyModel(self):

self.assertEqual(proxy_items, ['layer1', 'layer2', 'layer3'])

view.setShowHidden(False)
view.setShowPrivateLayers(False)

self.assertEqual(proxy_model.rowCount(), 2)

@@ -511,7 +511,7 @@ def testProxyModelCurrentIndex(self):
proxy_tester = QAbstractItemModelTester(view.model())

view.setCurrentLayer(self.layer3)
self.layer3.setFlags(self.layer.Hidden)
self.layer3.setFlags(self.layer.Private)

def testNode2IndexMethods(self):
"""Test node2index and node2sourceIndex"""

0 comments on commit 26a9cdf

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