QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
20QgsLayerMetadataResultsProxyModel::QgsLayerMetadataResultsProxyModel( QObject *parent ) : QSortFilterProxyModel( parent )
21{
22}
23
25{
26 mFilterExtent = extent;
27 invalidateFilter();
28}
29
31{
32 mFilterGeometryType = geometryType;
33 invalidateFilter();
34}
35
36void QgsLayerMetadataResultsProxyModel::setFilterString( const QString &filterString )
37{
38 mFilterString = filterString;
39 invalidateFilter();
40}
41
43{
44 mFilterMapLayerType = mapLayerType;
45 invalidateFilter();
46}
47
48bool QgsLayerMetadataResultsProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
49{
50 QModelIndex index0 = sourceModel()->index( sourceRow, 0, sourceParent );
51 bool result { QSortFilterProxyModel::filterAcceptsRow( sourceRow, sourceParent ) };
52
53 if ( result )
54 {
55 const QgsLayerMetadataProviderResult &metadataResult { sourceModel()->data( index0, Qt::ItemDataRole::UserRole ).value<QgsLayerMetadataProviderResult>( ) };
56
57 if ( ! mFilterString.isEmpty() )
58 {
59 result = result && metadataResult.contains( mFilterString );
60 }
61
62 if ( result && ! mFilterExtent.isEmpty() )
63 {
64 // Exclude aspatial from extent filter
65 result = result && ( metadataResult.geometryType() != Qgis::GeometryType::Unknown && metadataResult.geometryType() != Qgis::GeometryType::Null ) && mFilterExtent.intersects( metadataResult.geographicExtent().boundingBox() );
66 }
67
68 if ( result && mFilterMapLayerTypeEnabled )
69 {
70 result = result && metadataResult.layerType() == mFilterMapLayerType;
71 }
72
73 if ( result && mFilterGeometryTypeEnabled )
74 {
75 if ( mFilterGeometryType == Qgis::GeometryType::Unknown || mFilterGeometryType == Qgis::GeometryType::Null )
76 {
77 result = result && ( metadataResult.geometryType() == Qgis::GeometryType::Unknown || metadataResult.geometryType() == Qgis::GeometryType::Null );
78 }
79 else
80 {
81 result = result && metadataResult.geometryType() == mFilterGeometryType;
82 }
83 }
84 }
85
86 return result;
87}
88
90{
91 mFilterMapLayerTypeEnabled = enabled;
92 invalidateFilter();
93}
94
96{
97 mFilterGeometryTypeEnabled = enabled;
98 invalidateFilter();
99}
100
102{
103 return mFilterString;
104}
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.
bool isEmpty() const
Returns true if the rectangle has no area.