Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more flexible/understandable api for setting layer tree legend fi…
…lters And update existing broken tests which are incorrectly showing symbols which should not be visible in the legend
- Loading branch information
1 parent
efee735
commit 1742934
Showing
18 changed files
with
593 additions
and
152 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
130 changes: 130 additions & 0 deletions
130
python/core/auto_generated/layertree/qgslayertreefiltersettings.sip.in
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,130 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/layertree/qgslayertreefiltersettings.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
class QgsLayerTreeFilterSettings | ||
{ | ||
%Docstring(signature="appended") | ||
Contains settings relating to filtering the contents of :py:class:`QgsLayerTreeModel` and views. | ||
|
||
.. versionadded:: 3.32 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslayertreefiltersettings.h" | ||
%End | ||
public: | ||
|
||
explicit QgsLayerTreeFilterSettings( const QgsMapSettings &settings ); | ||
%Docstring | ||
Constructor for QgsLayerTreeFilterSettings, using the specified map ``settings``. | ||
%End | ||
|
||
~QgsLayerTreeFilterSettings(); | ||
|
||
QgsLayerTreeFilterSettings( const QgsLayerTreeFilterSettings &other ); | ||
%Docstring | ||
Copy constructor. | ||
%End | ||
|
||
|
||
void setMapSettings( const QgsMapSettings &settings ); | ||
%Docstring | ||
Sets the map ``settings`` used to filter the legend content. | ||
|
||
.. seealso:: :py:func:`mapSettings` | ||
%End | ||
|
||
QgsMapSettings &mapSettings(); | ||
%Docstring | ||
Returns the map settings used to filter the legend content. | ||
|
||
.. seealso:: :py:func:`setMapSettings` | ||
%End | ||
|
||
QMap<QString, QString> layerFilterExpressions() const; | ||
%Docstring | ||
Returns the map of layer IDs to legend filter expression. | ||
|
||
.. seealso:: :py:func:`layerFilterExpression` | ||
|
||
.. seealso:: :py:func:`setLayerFilterExpressions` | ||
%End | ||
|
||
void setLayerFilterExpressions( const QMap<QString, QString> &expressions ); | ||
%Docstring | ||
Sets the map of layer IDs to legend filter expression. | ||
|
||
.. seealso:: :py:func:`layerFilterExpressions` | ||
%End | ||
|
||
QString layerFilterExpression( const QString &layerId ) const; | ||
%Docstring | ||
Returns the filter expression to use for the layer with the specified | ||
``layerId``, or an empty string if no expression is set for the layer. | ||
|
||
.. seealso:: :py:func:`layerFilterExpressions` | ||
|
||
.. seealso:: :py:func:`setLayerFilterExpressions` | ||
%End | ||
|
||
QgsGeometry filterPolygon() const; | ||
%Docstring | ||
Returns the optional filter polygon, used when testing for symbols to show in | ||
the legend. | ||
|
||
The CRS of the polygon will match the destination CRS of :py:func:`~QgsLayerTreeFilterSettings.mapSettings`. | ||
|
||
If not set then the filter visibility extent will use the extent of :py:func:`~QgsLayerTreeFilterSettings.mapSettings`. | ||
|
||
.. seealso:: :py:func:`setFilterPolygon` | ||
%End | ||
|
||
void setFilterPolygon( const QgsGeometry &polygon ); | ||
%Docstring | ||
Sets the optional filter ``polygon``, used when testing for symbols to show in | ||
the legend. | ||
|
||
The CRS of the polygon must match the destination CRS of :py:func:`~QgsLayerTreeFilterSettings.mapSettings`. | ||
|
||
If not set then the filter visibility extent will use the extent of :py:func:`~QgsLayerTreeFilterSettings.mapSettings`. | ||
|
||
.. seealso:: :py:func:`filterPolygon` | ||
%End | ||
|
||
Qgis::LayerTreeFilterFlags flags() const; | ||
%Docstring | ||
Returns the filter flags. | ||
|
||
.. seealso:: :py:func:`setFlags` | ||
%End | ||
|
||
void setFlags( Qgis::LayerTreeFilterFlags flags ); | ||
%Docstring | ||
Sets the filter ``flags``. | ||
|
||
.. seealso:: :py:func:`flags` | ||
%End | ||
|
||
QList<QgsMapLayer *> layers() const; | ||
%Docstring | ||
Returns the layers which should be shown in the legend. | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/layertree/qgslayertreefiltersettings.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
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
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
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,91 @@ | ||
/*************************************************************************** | ||
qgslayertreefiltersettings.cpp | ||
-------------------------------------- | ||
Date : March 2023 | ||
Copyright : (C) 2023 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 "qgslayertreefiltersettings.h" | ||
#include "qgsmapsettings.h" | ||
|
||
QgsLayerTreeFilterSettings::QgsLayerTreeFilterSettings( const QgsMapSettings &settings ) | ||
: mMapSettings( std::make_unique<QgsMapSettings>( settings ) ) | ||
{} | ||
|
||
QgsLayerTreeFilterSettings::~QgsLayerTreeFilterSettings() = default; | ||
|
||
QgsLayerTreeFilterSettings::QgsLayerTreeFilterSettings( const QgsLayerTreeFilterSettings &other ) | ||
: mLayerFilterExpressions( other.mLayerFilterExpressions ) | ||
, mMapSettings( other.mMapSettings ? new QgsMapSettings( *other.mMapSettings ) : nullptr ) | ||
, mFilterPolygon( other.mFilterPolygon ) | ||
, mFlags( other.mFlags ) | ||
{ | ||
|
||
} | ||
|
||
QgsLayerTreeFilterSettings &QgsLayerTreeFilterSettings::operator=( const QgsLayerTreeFilterSettings &other ) | ||
{ | ||
mLayerFilterExpressions = other.mLayerFilterExpressions; | ||
mMapSettings.reset( other.mMapSettings ? new QgsMapSettings( *other.mMapSettings ) : nullptr ); | ||
mFilterPolygon = other.mFilterPolygon; | ||
mFlags = other.mFlags; | ||
return *this; | ||
} | ||
|
||
void QgsLayerTreeFilterSettings::setMapSettings( const QgsMapSettings &settings ) | ||
{ | ||
mMapSettings.reset( new QgsMapSettings( settings ) ); | ||
} | ||
|
||
QgsMapSettings &QgsLayerTreeFilterSettings::mapSettings() | ||
{ | ||
return *mMapSettings.get(); | ||
} | ||
|
||
QMap<QString, QString> QgsLayerTreeFilterSettings::layerFilterExpressions() const | ||
{ | ||
return mLayerFilterExpressions; | ||
} | ||
|
||
void QgsLayerTreeFilterSettings::setLayerFilterExpressions( const QMap<QString, QString> &expressions ) | ||
{ | ||
mLayerFilterExpressions = expressions; | ||
} | ||
|
||
QString QgsLayerTreeFilterSettings::layerFilterExpression( const QString &layerId ) const | ||
{ | ||
return mLayerFilterExpressions.value( layerId ); | ||
} | ||
|
||
QgsGeometry QgsLayerTreeFilterSettings::filterPolygon() const | ||
{ | ||
return mFilterPolygon; | ||
} | ||
|
||
void QgsLayerTreeFilterSettings::setFilterPolygon( const QgsGeometry &newFilterPolygon ) | ||
{ | ||
mFilterPolygon = newFilterPolygon; | ||
} | ||
|
||
Qgis::LayerTreeFilterFlags QgsLayerTreeFilterSettings::flags() const | ||
{ | ||
return mFlags; | ||
} | ||
|
||
void QgsLayerTreeFilterSettings::setFlags( Qgis::LayerTreeFilterFlags flags ) | ||
{ | ||
mFlags = flags; | ||
} | ||
|
||
QList<QgsMapLayer *> QgsLayerTreeFilterSettings::layers() const | ||
{ | ||
return mMapSettings->layers( true ); | ||
} |
Oops, something went wrong.