QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 ***************************************************************************/
17
19
20#include "moc_qgslayermetadataresultsproxymodel.cpp"
21
23 : QSortFilterProxyModel( parent )
24{
25}
26
28{
29 mFilterExtent = extent;
30 invalidateFilter();
31}
32
34{
35 mFilterGeometryType = geometryType;
36 invalidateFilter();
37}
38
40{
41 mFilterString = filterString;
42 invalidateFilter();
43}
44
46{
47 mFilterMapLayerType = mapLayerType;
48 invalidateFilter();
49}
50
51bool QgsLayerMetadataResultsProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
52{
53 QModelIndex index0 = sourceModel()->index( sourceRow, 0, sourceParent );
54 bool result { QSortFilterProxyModel::filterAcceptsRow( sourceRow, sourceParent ) };
55
56 if ( result )
57 {
58 const QgsLayerMetadataProviderResult &metadataResult { sourceModel()->data( index0, Qt::ItemDataRole::UserRole ).value<QgsLayerMetadataProviderResult>() };
59
60 if ( !mFilterString.isEmpty() )
61 {
62 result = result && metadataResult.contains( mFilterString );
63 }
64
65 if ( result && !mFilterExtent.isEmpty() )
66 {
67 // Exclude aspatial from extent filter
68 result = result && ( metadataResult.geometryType() != Qgis::GeometryType::Unknown && metadataResult.geometryType() != Qgis::GeometryType::Null ) && mFilterExtent.intersects( metadataResult.geographicExtent().boundingBox() );
69 }
70
71 if ( result && mFilterMapLayerTypeEnabled )
72 {
73 result = result && metadataResult.layerType() == mFilterMapLayerType;
74 }
75
76 if ( result && mFilterGeometryTypeEnabled )
77 {
78 if ( mFilterGeometryType == Qgis::GeometryType::Unknown || mFilterGeometryType == Qgis::GeometryType::Null )
79 {
80 result = result && ( metadataResult.geometryType() == Qgis::GeometryType::Unknown || metadataResult.geometryType() == Qgis::GeometryType::Null );
81 }
82 else
83 {
84 result = result && metadataResult.geometryType() == mFilterGeometryType;
85 }
86 }
87 }
88
89 return result;
90}
91
93{
94 mFilterMapLayerTypeEnabled = enabled;
95 invalidateFilter();
96}
97
99{
100 mFilterGeometryTypeEnabled = enabled;
101 invalidateFilter();
102}
103
105{
106 return mFilterString;
107}
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Unknown
Unknown types.
Definition qgis.h:362
@ Null
No geometry.
Definition qgis.h:363
LayerType
Types of layers that can be added to a map.
Definition qgis.h:190
virtual QgsRectangle boundingBox() const
Returns the minimal bounding box for the geometry.
Result record of layer metadata provider search.
Qgis::GeometryType geometryType() const
Returns the layer geometry type.
const QgsPolygon & geographicExtent() const
Returns the layer extent in EPSG:4326.
Qgis::LayerType layerType() const
Returns the layer type.
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.