-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsfeaturefiltermodel_p.h
130 lines (103 loc) · 3.61 KB
/
qgsfeaturefiltermodel_p.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
qgsfeaturefiltermodel_p - QgsFieldExpressionValuesGatherer
---------------------
begin : 10.3.2017
copyright : (C) 2017 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSFEATUREFILTERMODEL_P_H
#define QGSFEATUREFILTERMODEL_P_H
#include <QThread>
#include "qgsvectorlayer.h"
#include "qgsfeaturefiltermodel.h"
#include "qgslogger.h"
#include "qgsvectorlayerfeatureiterator.h"
#define SIP_NO_FILE
// just internal guff - definitely not for exposing to public API!
///@cond PRIVATE
/**
* \class QgsFieldExpressionValuesGatherer
* Gathers features with substring matching on an expression.
*
* \since QGIS 3.0
*/
class QgsFieldExpressionValuesGatherer: public QThread
{
Q_OBJECT
public:
QgsFieldExpressionValuesGatherer( QgsVectorLayer *layer, const QString &displayExpression, const QString &identifierField, const QgsFeatureRequest &request = QgsFeatureRequest() )
: mSource( new QgsVectorLayerFeatureSource( layer ) )
, mDisplayExpression( displayExpression )
, mRequest( request )
, mWasCanceled( false )
, mIdentifierField( identifierField )
{
}
~QgsFieldExpressionValuesGatherer()
{
}
virtual void run() override
{
mWasCanceled = false;
mIterator = mSource->getFeatures( mRequest );
mDisplayExpression.prepare( &mExpressionContext );
QgsFeature feat;
int attribute = mSource->fields().indexOf( mIdentifierField );
while ( mIterator.nextFeature( feat ) )
{
mExpressionContext.setFeature( feat );
mEntries.append( QgsFeatureFilterModel::Entry( feat.attribute( attribute ), mDisplayExpression.evaluate( &mExpressionContext ).toString() ) );
if ( mWasCanceled )
return;
}
emit collectedValues();
}
//! Informs the gatherer to immediately stop collecting values
void stop()
{
mWasCanceled = true;
}
//! Returns true if collection was canceled before completion
bool wasCanceled() const { return mWasCanceled; }
QVector<QgsFeatureFilterModel::Entry> entries() const
{
return mEntries;
}
QgsFeatureRequest request() const
{
return mRequest;
}
/**
* Internal data, use for whatever you want.
*/
QVariant data() const;
/**
* Internal data, use for whatever you want.
*/
void setData( const QVariant &data );
signals:
/**
* Emitted when values have been collected
* @param values list of unique matching string values
*/
void collectedValues();
private:
std::unique_ptr<QgsVectorLayerFeatureSource> mSource;
QgsExpression mDisplayExpression;
QgsExpressionContext mExpressionContext;
QgsFeatureRequest mRequest;
QgsFeatureIterator mIterator;
bool mWasCanceled;
QVector<QgsFeatureFilterModel::Entry> mEntries;
QString mIdentifierField;
QVariant mData;
};
///@endcond
#endif // QGSFEATUREFILTERMODEL_P_H