QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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() != QgsWkbTypes::UnknownGeometry && metadataResult.geometryType() != QgsWkbTypes::NullGeometry ) && 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 == QgsWkbTypes::UnknownGeometry || mFilterGeometryType == QgsWkbTypes::NullGeometry )
75 {
76 result = result && ( metadataResult.geometryType() == QgsWkbTypes::UnknownGeometry || metadataResult.geometryType() == QgsWkbTypes::NullGeometry );
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
Result record of layer metadata provider search.
void setFilterGeometryType(const QgsWkbTypes::GeometryType geometryType)
Sets the geometry type filter to geometryType.
QgsLayerMetadataResultsProxyModel(QObject *parent=nullptr)
Constructs a QgsLayerMetadataResultsProxyModel with an optional parent.
void setFilterString(const QString &filterString)
Sets the text filter to filterString.
void setFilterExtent(const QgsRectangle &extent)
Sets the extent filter to extent.
void setFilterMapLayerType(const QgsMapLayerType mapLayerType)
Sets the map layer type filter to mapLayerType.
void setFilterMapLayerTypeEnabled(bool enabled)
Sets the map layer type filter status to enabled.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
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.
Definition: qgsrectangle.h:42
bool intersects(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle intersects with other rectangle.
Definition: qgsrectangle.h:349
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:469
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:47