QGIS API Documentation 3.41.0-Master (d5b93354e9c)
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#include "moc_qgslayermetadataresultsproxymodel.cpp"
19
21 : QSortFilterProxyModel( parent )
22{
23}
24
26{
27 mFilterExtent = extent;
28 invalidateFilter();
29}
30
32{
33 mFilterGeometryType = geometryType;
34 invalidateFilter();
35}
36
37void QgsLayerMetadataResultsProxyModel::setFilterString( const QString &filterString )
38{
39 mFilterString = filterString;
40 invalidateFilter();
41}
42
44{
45 mFilterMapLayerType = mapLayerType;
46 invalidateFilter();
47}
48
49bool QgsLayerMetadataResultsProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
50{
51 QModelIndex index0 = sourceModel()->index( sourceRow, 0, sourceParent );
52 bool result { QSortFilterProxyModel::filterAcceptsRow( sourceRow, sourceParent ) };
53
54 if ( result )
55 {
56 const QgsLayerMetadataProviderResult &metadataResult { sourceModel()->data( index0, Qt::ItemDataRole::UserRole ).value<QgsLayerMetadataProviderResult>() };
57
58 if ( !mFilterString.isEmpty() )
59 {
60 result = result && metadataResult.contains( mFilterString );
61 }
62
63 if ( result && !mFilterExtent.isEmpty() )
64 {
65 // Exclude aspatial from extent filter
66 result = result && ( metadataResult.geometryType() != Qgis::GeometryType::Unknown && metadataResult.geometryType() != Qgis::GeometryType::Null ) && mFilterExtent.intersects( metadataResult.geographicExtent().boundingBox() );
67 }
68
69 if ( result && mFilterMapLayerTypeEnabled )
70 {
71 result = result && metadataResult.layerType() == mFilterMapLayerType;
72 }
73
74 if ( result && mFilterGeometryTypeEnabled )
75 {
76 if ( mFilterGeometryType == Qgis::GeometryType::Unknown || mFilterGeometryType == Qgis::GeometryType::Null )
77 {
78 result = result && ( metadataResult.geometryType() == Qgis::GeometryType::Unknown || metadataResult.geometryType() == Qgis::GeometryType::Null );
79 }
80 else
81 {
82 result = result && metadataResult.geometryType() == mFilterGeometryType;
83 }
84 }
85 }
86
87 return result;
88}
89
91{
92 mFilterMapLayerTypeEnabled = enabled;
93 invalidateFilter();
94}
95
97{
98 mFilterGeometryTypeEnabled = enabled;
99 invalidateFilter();
100}
101
103{
104 return mFilterString;
105}
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Unknown
Unknown types.
@ Null
No geometry.
LayerType
Types of layers that can be added to a map.
Definition qgis.h:169
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.