QGIS API Documentation
2.8.2-Wien
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
src
core
qgsfeaturerequest.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsfeaturerequest.cpp
3
---------------------
4
begin : Mai 2012
5
copyright : (C) 2012 by Martin Dobias
6
email : wonder dot sk at gmail dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
#include "
qgsfeaturerequest.h
"
16
17
#include "
qgsfield.h
"
18
#include "
qgsgeometry.h
"
19
20
#include <QStringList>
21
22
//constants
23
const
QString
QgsFeatureRequest::AllAttributes
= QString(
"#!allattributes!#"
);
24
25
QgsFeatureRequest::QgsFeatureRequest
()
26
: mFilter( FilterNone )
27
, mFilterFid( -1 )
28
, mFilterExpression( 0 )
29
, mFlags( 0 )
30
{
31
}
32
33
QgsFeatureRequest::QgsFeatureRequest
(
QgsFeatureId
fid )
34
: mFilter( FilterFid )
35
, mFilterFid( fid )
36
, mFilterExpression( 0 )
37
, mFlags( 0 )
38
{
39
}
40
41
QgsFeatureRequest::QgsFeatureRequest
(
const
QgsRectangle
& rect )
42
: mFilter( FilterRect )
43
, mFilterRect( rect )
44
, mFilterFid( -1 )
45
, mFilterExpression( 0 )
46
, mFlags( 0 )
47
{
48
}
49
50
QgsFeatureRequest::QgsFeatureRequest
(
const
QgsExpression
& expr )
51
: mFilter( FilterExpression )
52
, mFilterFid( -1 )
53
, mFilterExpression( new
QgsExpression
( expr.expression() ) )
54
, mFlags( 0 )
55
{
56
}
57
58
QgsFeatureRequest::QgsFeatureRequest
(
const
QgsFeatureRequest
&rh )
59
{
60
operator=
( rh );
61
}
62
63
QgsFeatureRequest
&
QgsFeatureRequest::operator=
(
const
QgsFeatureRequest
& rh )
64
{
65
mFlags
= rh.
mFlags
;
66
mFilter
= rh.
mFilter
;
67
mFilterRect
= rh.
mFilterRect
;
68
mFilterFid
= rh.
mFilterFid
;
69
mFilterFids
= rh.
mFilterFids
;
70
if
( rh.
mFilterExpression
)
71
{
72
mFilterExpression
=
new
QgsExpression
( rh.
mFilterExpression
->
expression
() );
73
}
74
else
75
{
76
mFilterExpression
= 0;
77
}
78
mAttrs
= rh.
mAttrs
;
79
mSimplifyMethod
= rh.
mSimplifyMethod
;
80
return
*
this
;
81
}
82
83
QgsFeatureRequest::~QgsFeatureRequest
()
84
{
85
delete
mFilterExpression
;
86
}
87
88
QgsFeatureRequest
&
QgsFeatureRequest::setFilterRect
(
const
QgsRectangle
& rect )
89
{
90
mFilter
=
FilterRect
;
91
mFilterRect
= rect;
92
return
*
this
;
93
}
94
95
QgsFeatureRequest
&
QgsFeatureRequest::setFilterFid
(
QgsFeatureId
fid )
96
{
97
mFilter
=
FilterFid
;
98
mFilterFid
= fid;
99
return
*
this
;
100
}
101
102
QgsFeatureRequest
&
QgsFeatureRequest::setFilterFids
(
QgsFeatureIds
fids )
103
{
104
mFilter
=
FilterFids
;
105
mFilterFids
= fids;
106
return
*
this
;
107
}
108
109
QgsFeatureRequest
&
QgsFeatureRequest::setFilterExpression
(
const
QString& expression )
110
{
111
mFilter
=
FilterExpression
;
112
delete
mFilterExpression
;
113
mFilterExpression
=
new
QgsExpression
( expression );
114
return
*
this
;
115
}
116
117
QgsFeatureRequest
&
QgsFeatureRequest::setFlags
( QgsFeatureRequest::Flags flags )
118
{
119
mFlags
=
flags
;
120
return
*
this
;
121
}
122
123
QgsFeatureRequest
&
QgsFeatureRequest::setSubsetOfAttributes
(
const
QgsAttributeList
& attrs )
124
{
125
mFlags
|=
SubsetOfAttributes
;
126
mAttrs
= attrs;
127
return
*
this
;
128
}
129
130
QgsFeatureRequest
&
QgsFeatureRequest::setSubsetOfAttributes
(
const
QStringList& attrNames,
const
QgsFields
& fields )
131
{
132
if
( attrNames.contains(
QgsFeatureRequest::AllAttributes
) )
133
{
134
//attribute string list contains the all attributes flag, so we must fetch all attributes
135
return
*
this
;
136
}
137
138
mFlags
|=
SubsetOfAttributes
;
139
mAttrs
.clear();
140
141
foreach
(
const
QString& attrName, attrNames )
142
{
143
int
attrNum = fields.
fieldNameIndex
( attrName );
144
if
( attrNum != -1 && !
mAttrs
.contains( attrNum ) )
145
mAttrs
.append( attrNum );
146
}
147
148
return
*
this
;
149
}
150
151
QgsFeatureRequest
&
QgsFeatureRequest::setSimplifyMethod
(
const
QgsSimplifyMethod
& simplifyMethod )
152
{
153
mSimplifyMethod
=
simplifyMethod
;
154
return
*
this
;
155
}
156
157
bool
QgsFeatureRequest::acceptFeature
(
const
QgsFeature
& feature )
158
{
159
switch
(
mFilter
)
160
{
161
case
QgsFeatureRequest::FilterNone
:
162
return
true
;
163
break
;
164
165
case
QgsFeatureRequest::FilterRect
:
166
if
( feature.
geometry
() && feature.
geometry
()->
intersects
(
mFilterRect
) )
167
return
true
;
168
else
169
return
false
;
170
break
;
171
172
case
QgsFeatureRequest::FilterFid
:
173
if
( feature.
id
() ==
mFilterFid
)
174
return
true
;
175
else
176
return
false
;
177
break
;
178
179
case
QgsFeatureRequest::FilterExpression
:
180
if
(
mFilterExpression
->
evaluate
( feature ).toBool() )
181
return
true
;
182
else
183
return
false
;
184
break
;
185
186
case
QgsFeatureRequest::FilterFids
:
187
if
(
mFilterFids
.contains( feature.
id
() ) )
188
return
true
;
189
else
190
return
false
;
191
break
;
192
}
193
194
return
true
;
195
}
196
197
#include "
qgsfeatureiterator.h
"
198
#include "
qgslogger.h
"
199
200
QgsAbstractFeatureSource::~QgsAbstractFeatureSource
()
201
{
202
while
( !
mActiveIterators
.empty() )
203
{
204
QgsAbstractFeatureIterator
*it = *
mActiveIterators
.begin();
205
QgsDebugMsg
(
"closing active iterator"
);
206
it->
close
();
207
}
208
}
209
210
void
QgsAbstractFeatureSource::iteratorOpened
(
QgsAbstractFeatureIterator
* it )
211
{
212
mActiveIterators
.insert( it );
213
}
214
215
void
QgsAbstractFeatureSource::iteratorClosed
(
QgsAbstractFeatureIterator
* it )
216
{
217
mActiveIterators
.remove( it );
218
}
219
220
Generated on Sun May 10 2015 16:33:24 for QGIS API Documentation by
1.8.1.2