Skip to content

Commit

Permalink
Revert "Hidden layers"
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 7, 2020
1 parent 95fc515 commit 0c38d2f
Show file tree
Hide file tree
Showing 27 changed files with 138 additions and 831 deletions.
7 changes: 0 additions & 7 deletions python/core/auto_generated/layertree/qgslayertreemodel.sip.in
Expand Up @@ -351,13 +351,6 @@ Updates model when node's name has changed
void nodeLayerWillBeUnloaded();
void layerLegendChanged();

void layerFlagsChanged();
%Docstring
Emitted when layer flags have changed.

.. versionadded:: 3.18
%End

void layerNeedsUpdate();

void legendNodeDataChanged();
Expand Down
1 change: 0 additions & 1 deletion python/core/auto_generated/qgsmaplayer.sip.in
Expand Up @@ -84,7 +84,6 @@ This is the base class for all map layer types (vector, raster).
Identifiable,
Removable,
Searchable,
Private,
};
typedef QFlags<QgsMapLayer::LayerFlag> LayerFlags;

Expand Down
126 changes: 0 additions & 126 deletions python/gui/auto_generated/layertree/qgslayertreeview.sip.in
Expand Up @@ -10,50 +10,6 @@




class QgsLayerTreeProxyModel : QSortFilterProxyModel
{
%Docstring

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

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgslayertreeview.h"
%End
public:

QgsLayerTreeProxyModel( QgsLayerTreeModel *treeModel, QObject *parent );
%Docstring
Constructs QgsLayerTreeProxyModel with source model ``treeModel`` and a ``parent``
%End

void setFilterText( const QString &filterText = QString() );
%Docstring
Sets filter to ``filterText``.
%End

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

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

protected:

virtual bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;


};


class QgsLayerTreeView : QTreeView
{
%Docstring
Expand Down Expand Up @@ -99,74 +55,6 @@ Overridden :py:func:`~QgsLayerTreeView.setModel` from base class. Only QgsLayerT
QgsLayerTreeModel *layerTreeModel() const;
%Docstring
Gets access to the model casted to :py:class:`QgsLayerTreeModel`
%End

QgsLayerTreeProxyModel *proxyModel() const;
%Docstring
Returns the proxy model used by the view.

This can be used to set filters controlling which layers are shown in the view.

.. versionadded:: 3.18
%End

QgsLayerTreeNode *index2node( const QModelIndex &index ) const;
%Docstring
Returns layer tree node for given proxy model tree ``index``. Returns root node for invalid index.
Returns ``None`` if index does not refer to a layer tree node (e.g. it is a legend node)

Unlike :py:func:`QgsLayerTreeModel.index2Node()`, calling this method correctly accounts
for mapping the view indexes through the view's proxy model to the source model.

.. versionadded:: 3.18
%End

QModelIndex node2index( QgsLayerTreeNode *node ) const;
%Docstring
Returns proxy model index for a given node. If the node does not belong to the layer tree, the result is undefined

Unlike :py:func:`QgsLayerTreeModel.node2index()`, calling this method correctly accounts
for mapping the view indexes through the view's proxy model to the source model.

.. versionadded:: 3.18
%End


QModelIndex node2sourceIndex( QgsLayerTreeNode *node ) const;
%Docstring
Returns source model index for a given node. If the node does not belong to the layer tree, the result is undefined

.. versionadded:: 3.18
%End


QgsLayerTreeModelLegendNode *index2legendNode( const QModelIndex &index ) const;
%Docstring
Returns legend node for given proxy model tree ``index``. Returns ``None`` for invalid index

Unlike :py:func:`QgsLayerTreeModel.index2legendNode()`, calling this method correctly accounts
for mapping the view indexes through the view's proxy model to the source model.

.. versionadded:: 3.18
%End

QModelIndex legendNode2index( QgsLayerTreeModelLegendNode *legendNode );
%Docstring
Returns proxy model index for a given legend node. If the legend node does not belong to the layer tree, the result is undefined.
If the legend node is belongs to the tree but it is filtered out, invalid model index is returned.

Unlike :py:func:`QgsLayerTreeModel.legendNode2index()`, calling this method correctly accounts
for mapping the view indexes through the view's proxy model to the source model.

.. versionadded:: 3.18
%End

QModelIndex legendNode2sourceIndex( QgsLayerTreeModelLegendNode *legendNode );
%Docstring
Returns index for a given legend node. If the legend node does not belong to the layer tree, the result is undefined.
If the legend node is belongs to the tree but it is filtered out, invalid model index is returned.

.. versionadded:: 3.18
%End

QgsLayerTreeViewDefaultActions *defaultActions();
Expand Down Expand Up @@ -331,20 +219,6 @@ Set width of contextual menu mark, at right of layer node items.
Set the message bar to display messages from the layer tree

.. versionadded:: 3.14
%End

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

.. versionadded:: 3.18
%End

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

.. versionadded:: 3.18
%End

signals:
Expand Down
74 changes: 14 additions & 60 deletions src/app/qgisapp.cpp
Expand Up @@ -4776,23 +4776,12 @@ void QgisApp::initLayerTreeView()
btnVisibilityPresets->setPopupMode( QToolButton::InstantPopup );
btnVisibilityPresets->setMenu( QgsMapThemes::instance()->menu() );

// filter legend actions
mFilterLegendToolButton = new QToolButton( this );
mFilterLegendToolButton->setAutoRaise( true );
mFilterLegendToolButton->setToolTip( tr( "Filter Legend by Map Content" ) );
mFilterLegendToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFilter2.svg" ) ) );
mFilterLegendToolButton->setPopupMode( QToolButton::InstantPopup );
QMenu *filterLegendMenu = new QMenu( this );
mFilterLegendToolButton->setMenu( filterLegendMenu );
mFilterLegendByMapContentAction = new QAction( tr( "Filter Legend by Map Content" ), this );
mFilterLegendByMapContentAction->setCheckable( true );
connect( mFilterLegendByMapContentAction, &QAction::toggled, this, &QgisApp::updateFilterLegend );
filterLegendMenu->addAction( mFilterLegendByMapContentAction );

mFilterLegendToggleShowPrivateLayersAction = new QAction( tr( "Show Private Layers" ), this );
mFilterLegendToggleShowPrivateLayersAction->setCheckable( true );
connect( mFilterLegendToggleShowPrivateLayersAction, &QAction::toggled, this, [ = ]( bool showPrivateLayers ) { layerTreeView()->setShowPrivateLayers( showPrivateLayers ); } );
filterLegendMenu->addAction( mFilterLegendToggleShowPrivateLayersAction );
// filter legend action
mActionFilterLegend = new QAction( tr( "Filter Legend by Map Content" ), this );
mActionFilterLegend->setCheckable( true );
mActionFilterLegend->setToolTip( tr( "Filter Legend by Map Content" ) );
mActionFilterLegend->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFilter2.svg" ) ) );
connect( mActionFilterLegend, &QAction::toggled, this, &QgisApp::updateFilterLegend );

mLegendExpressionFilterButton = new QgsLegendFilterButton( this );
mLegendExpressionFilterButton->setToolTip( tr( "Filter legend by expression" ) );
Expand Down Expand Up @@ -4820,7 +4809,7 @@ void QgisApp::initLayerTreeView()
toolbar->addAction( mActionStyleDock );
toolbar->addAction( actionAddGroup );
toolbar->addWidget( btnVisibilityPresets );
toolbar->addWidget( mFilterLegendToolButton );
toolbar->addAction( mActionFilterLegend );
toolbar->addWidget( mLegendExpressionFilterButton );
toolbar->addAction( actionExpandAll );
toolbar->addAction( actionCollapseAll );
Expand Down Expand Up @@ -4931,7 +4920,7 @@ void QgisApp::autoSelectAddedLayer( QList<QgsMapLayer *> layers )
if ( !nodeLayer )
return;

QModelIndex index = mLayerTreeView->node2index( nodeLayer );
QModelIndex index = mLayerTreeView->layerTreeModel()->node2index( nodeLayer );
mLayerTreeView->setCurrentIndex( index );
}
}
Expand Down Expand Up @@ -7136,7 +7125,7 @@ bool QgisApp::addProject( const QString &projectFile )
mMapCanvas->updateScale();
QgsDebugMsgLevel( QStringLiteral( "Scale restored..." ), 3 );

mFilterLegendByMapContentAction->setChecked( QgsProject::instance()->readBoolEntry( QStringLiteral( "Legend" ), QStringLiteral( "filterByMap" ) ) );
mActionFilterLegend->setChecked( QgsProject::instance()->readBoolEntry( QStringLiteral( "Legend" ), QStringLiteral( "filterByMap" ) ) );

// Select the first layer
if ( mLayerTreeView->layerTreeModel()->rootGroup()->findLayers().count() > 0 )
Expand Down Expand Up @@ -7780,10 +7769,10 @@ void QgisApp::toggleFilterLegendByExpression( bool checked )
void QgisApp::updateFilterLegend()
{
bool hasExpressions = mLegendExpressionFilterButton->isChecked() && QgsLayerTreeUtils::hasLegendFilterExpression( *mLayerTreeView->layerTreeModel()->rootGroup() );
if ( mFilterLegendByMapContentAction->isChecked() || hasExpressions )
if ( mActionFilterLegend->isChecked() || hasExpressions )
{
layerTreeView()->layerTreeModel()->setLegendFilter( &mMapCanvas->mapSettings(),
/* useExtent */ mFilterLegendByMapContentAction->isChecked(),
/* useExtent */ mActionFilterLegend->isChecked(),
/* polygon */ QgsGeometry(),
hasExpressions );
}
Expand Down Expand Up @@ -11687,43 +11676,8 @@ void QgisApp::removeLayer()
}

bool shiftHeld = QApplication::queryKeyboardModifiers().testFlag( Qt::ShiftModifier );

// Check if there are any hidden layer elements and display a confirmation dialog
QStringList hiddenLayerNames;
auto harvest = [ &hiddenLayerNames ]( const QgsLayerTreeNode * parent )
{
const auto cChildren { parent->children() };
for ( const auto &c : cChildren )
{
if ( QgsLayerTree::isLayer( c ) )
{
const auto treeLayer { QgsLayerTree::toLayer( c ) };
if ( treeLayer->layer() && treeLayer->layer()->flags().testFlag( QgsMapLayer::LayerFlag::Private ) )
{
hiddenLayerNames.push_back( treeLayer->layer()->name( ) );
}
}
}
};

for ( const auto &n : qgis::as_const( selectedNodes ) )
{
harvest( n );
}

QString message { tr( "Remove %n legend entries?", "number of legend items to remove", selectedNodes.count() ) };
if ( ! hiddenLayerNames.isEmpty() )
{
if ( hiddenLayerNames.count( ) > 10 )
{
const int layerCount { hiddenLayerNames.count( ) };
hiddenLayerNames = hiddenLayerNames.mid( 0, 10 );
hiddenLayerNames.push_back( tr( "(%n more hidden layers)", "number of hidden layers not shown", layerCount - 10 ) );
}
message.append( tr( "The following hidden layers will be removed:\n%1" ).arg( hiddenLayerNames.join( '\n' ) ) );
}

if ( !shiftHeld && promptConfirmation && QMessageBox::warning( this, tr( "Remove layers and groups" ), message, QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
//display a warning
if ( !shiftHeld && promptConfirmation && QMessageBox::warning( this, tr( "Remove layers and groups" ), tr( "Remove %n legend entries?", "number of legend items to remove", selectedNodes.count() ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}
Expand Down Expand Up @@ -13514,7 +13468,7 @@ void QgisApp::closeProject()

mLegendExpressionFilterButton->setExpressionText( QString() );
mLegendExpressionFilterButton->setChecked( false );
mFilterLegendByMapContentAction->setChecked( false );
mActionFilterLegend->setChecked( false );

closeAdditionalMapCanvases();
closeAdditional3DMapCanvases();
Expand Down
4 changes: 1 addition & 3 deletions src/app/qgisapp.h
Expand Up @@ -2622,9 +2622,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! A class that facilitates tracing of features
QgsMapCanvasTracer *mTracer = nullptr;

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

QgsLegendFilterButton *mLegendExpressionFilterButton = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -75,7 +75,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()

// TODO: update drawing order
}
else if ( QgsLayerTreeNode *node = mView->index2node( idx ) )
else if ( QgsLayerTreeNode *node = mView->layerTreeModel()->index2node( idx ) )
{
// layer or group selected
if ( QgsLayerTree::isGroup( node ) )
Expand Down Expand Up @@ -616,7 +616,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
menu->addAction( tr( "&Properties…" ), QgisApp::instance(), &QgisApp::layerProperties );
}
}
else if ( QgsLayerTreeModelLegendNode *node = mView->index2legendNode( idx ) )
else if ( QgsLayerTreeModelLegendNode *node = mView->layerTreeModel()->index2legendNode( idx ) )
{
if ( QgsSymbolLegendNode *symbolNode = qobject_cast< QgsSymbolLegendNode * >( node ) )
{
Expand Down

0 comments on commit 0c38d2f

Please sign in to comment.