QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgslayermetadataresultsproxymodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayermetadataresultsproxymodel.cpp - QgsLayerMetadataResultsProxyModel
3
4 ---------------------
5 begin : 1.9.2022
6 copyright : (C) 2022 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
18
19QgsLayerMetadataResultsProxyModel::QgsLayerMetadataResultsProxyModel( QObject *parent ) : QSortFilterProxyModel( parent )
20{
21}
22
24{
25 mFilterExtent = extent;
26 invalidateFilter();
27}
28
30{
31 mFilterGeometryType = geometryType;
32 invalidateFilter();
33}
34
35void QgsLayerMetadataResultsProxyModel::setFilterString( const QString &filterString )
36{
37 mFilterString = filterString;
38 invalidateFilter();
39}
40
42{
43 mFilterMapLayerType = mapLayerType;
44 invalidateFilter();
45}
46
47bool QgsLayerMetadataResultsProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
48{
49 QModelIndex index0 = sourceModel()->index( sourceRow, 0, sourceParent );
50 bool result { QSortFilterProxyModel::filterAcceptsRow( sourceRow, sourceParent ) };
51
52 if ( result )
53 {
54 const QgsLayerMetadataProviderResult &metadataResult { sourceModel()->data( index0, Qt::ItemDataRole::UserRole ).value<QgsLayerMetadataProviderResult>( ) };
55
56 if ( ! mFilterString.isEmpty() )
57 {
58 result = result && metadataResult.contains( mFilterString );
59 }
60
61 if ( result && ! mFilterExtent.isEmpty() )
62 {
63 // Exclude aspatial from extent filter
64 result = result && ( metadataResult.geometryType() != Qgis::GeometryType::Unknown && metadataResult.geometryType() != Qgis::GeometryType::Null ) && mFilterExtent.intersects( metadataResult.geographicExtent().boundingBox() );
65 }
66
67 if ( result && mFilterMapLayerTypeEnabled )
68 {
69 result = result && metadataResult.layerType() == mFilterMapLayerType;
70 }
71
72 if ( result && mFilterGeometryTypeEnabled )
73 {
74 if ( mFilterGeometryType == Qgis::GeometryType::Unknown || mFilterGeometryType == Qgis::GeometryType::Null )
75 {
76 result = result && ( metadataResult.geometryType() == Qgis::GeometryType::Unknown || metadataResult.geometryType() == Qgis::GeometryType::Null );
77 }
78 else
79 {
80 result = result && metadataResult.geometryType() == mFilterGeometryType;
81 }
82 }
83 }
84
85 return result;
86}
87
89{
90 mFilterMapLayerTypeEnabled = enabled;
91 invalidateFilter();
92}
93
95{
96 mFilterGeometryTypeEnabled = enabled;
97 invalidateFilter();
98}
99
101{
102 return mFilterString;
103}
104
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:255
@ Unknown
Unknown types.
@ Null
No geometry.
LayerType
Types of layers that can be added to a map.
Definition qgis.h:114
Result record of layer metadata provider search.
QgsLayerMetadataResultsProxyModel(QObject *parent=nullptr)
Constructs a QgsLayerMetadataResultsProxyModel with an optional parent.
void setFilterGeometryType(Qgis::GeometryType geometryType)
Sets the geometry type filter to geometryType.
void setFilterString(const QString &filterString)
Sets the text filter to filterString.
void setFilterExtent(const QgsRectangle &extent)
Sets the extent filter to extent.
void setFilterMapLayerTypeEnabled(bool enabled)
Sets the map layer type filter status to enabled.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
void setFilterMapLayerType(const Qgis::LayerType mapLayerType)
Sets the map layer type filter to mapLayerType.
void setFilterGeometryTypeEnabled(bool enabled)
Sets the geometry type filter status to enabled.
const QString filterString() const
Returns the filter string.
bool contains(const QString &searchString) const
Returns true if the metadata identifier, title, abstract, keywords or categories contain searchString...
A rectangle specified with double values.
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
bool isEmpty() const
Returns true if the rectangle has no area.