QGIS API Documentation
2.2.0-Valmiera
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
QgsFeatureRequest::QgsFeatureRequest
()
23
: mFilter( FilterNone )
24
, mFilterExpression( 0 )
25
, mFlags( 0 )
26
{
27
}
28
29
QgsFeatureRequest::QgsFeatureRequest
(
QgsFeatureId
fid )
30
: mFilter( FilterFid )
31
, mFilterFid( fid )
32
, mFilterExpression( 0 )
33
, mFlags( 0 )
34
{
35
}
36
37
QgsFeatureRequest::QgsFeatureRequest
(
const
QgsRectangle
& rect )
38
: mFilter( FilterRect )
39
, mFilterRect( rect )
40
, mFilterExpression( 0 )
41
, mFlags( 0 )
42
{
43
}
44
45
QgsFeatureRequest::QgsFeatureRequest
(
const
QgsExpression
& expr )
46
: mFilter( FilterExpression )
47
, mFilterExpression( new
QgsExpression
( expr.expression() ) )
48
, mFlags( 0 )
49
{
50
}
51
52
QgsFeatureRequest::QgsFeatureRequest
(
const
QgsFeatureRequest
&rh )
53
{
54
operator=
( rh );
55
}
56
57
QgsFeatureRequest
&
QgsFeatureRequest::operator=
(
const
QgsFeatureRequest
& rh )
58
{
59
mFlags
= rh.
mFlags
;
60
mFilter
= rh.
mFilter
;
61
mFilterRect
= rh.
mFilterRect
;
62
mFilterFid
= rh.
mFilterFid
;
63
mFilterFids
= rh.
mFilterFids
;
64
if
( rh.
mFilterExpression
)
65
{
66
mFilterExpression
=
new
QgsExpression
( rh.
mFilterExpression
->
expression
() );
67
}
68
else
69
{
70
mFilterExpression
= 0;
71
}
72
mAttrs
= rh.
mAttrs
;
73
mSimplifyMethod
= rh.
mSimplifyMethod
;
74
return
*
this
;
75
}
76
77
QgsFeatureRequest::~QgsFeatureRequest
()
78
{
79
delete
mFilterExpression
;
80
}
81
82
QgsFeatureRequest
&
QgsFeatureRequest::setFilterRect
(
const
QgsRectangle
& rect )
83
{
84
mFilter
=
FilterRect
;
85
mFilterRect
= rect;
86
return
*
this
;
87
}
88
89
QgsFeatureRequest
&
QgsFeatureRequest::setFilterFid
(
QgsFeatureId
fid )
90
{
91
mFilter
=
FilterFid
;
92
mFilterFid
= fid;
93
return
*
this
;
94
}
95
96
QgsFeatureRequest
&
QgsFeatureRequest::setFilterFids
(
QgsFeatureIds
fids )
97
{
98
mFilter
=
FilterFids
;
99
mFilterFids
= fids;
100
return
*
this
;
101
}
102
103
QgsFeatureRequest
&
QgsFeatureRequest::setFilterExpression
(
const
QString& expression )
104
{
105
mFilter
=
FilterExpression
;
106
delete
mFilterExpression
;
107
mFilterExpression
=
new
QgsExpression
( expression );
108
return
*
this
;
109
}
110
111
QgsFeatureRequest
&
QgsFeatureRequest::setFlags
( QgsFeatureRequest::Flags flags )
112
{
113
mFlags
=
flags
;
114
return
*
this
;
115
}
116
117
QgsFeatureRequest
&
QgsFeatureRequest::setSubsetOfAttributes
(
const
QgsAttributeList
& attrs )
118
{
119
mFlags
|=
SubsetOfAttributes
;
120
mAttrs
= attrs;
121
return
*
this
;
122
}
123
124
QgsFeatureRequest
&
QgsFeatureRequest::setSubsetOfAttributes
(
const
QStringList& attrNames,
const
QgsFields
& fields )
125
{
126
mFlags
|=
SubsetOfAttributes
;
127
mAttrs
.clear();
128
129
for
(
int
idx = 0; idx < fields.
count
(); ++idx )
130
{
131
if
( attrNames.contains( fields[idx].name() ) )
132
mAttrs
.append( idx );
133
}
134
135
return
*
this
;
136
}
137
138
QgsFeatureRequest
&
QgsFeatureRequest::setSimplifyMethod
(
const
QgsSimplifyMethod
& simplifyMethod )
139
{
140
mSimplifyMethod
=
simplifyMethod
;
141
return
*
this
;
142
}
143
144
bool
QgsFeatureRequest::acceptFeature
(
const
QgsFeature
& feature )
145
{
146
switch
(
mFilter
)
147
{
148
case
QgsFeatureRequest::FilterNone
:
149
return
true
;
150
break
;
151
152
case
QgsFeatureRequest::FilterRect
:
153
if
( feature.
geometry
() && feature.
geometry
()->
intersects
(
mFilterRect
) )
154
return
true
;
155
else
156
return
false
;
157
break
;
158
159
case
QgsFeatureRequest::FilterFid
:
160
if
( feature.
id
() ==
mFilterFid
)
161
return
true
;
162
else
163
return
false
;
164
break
;
165
166
case
QgsFeatureRequest::FilterExpression
:
167
if
(
mFilterExpression
->
evaluate
( feature ).toBool() )
168
return
true
;
169
else
170
return
false
;
171
break
;
172
173
case
QgsFeatureRequest::FilterFids
:
174
if
(
mFilterFids
.contains( feature.
id
() ) )
175
return
true
;
176
else
177
return
false
;
178
break
;
179
}
180
181
return
true
;
182
}
Generated on Sun Feb 23 2014 14:27:19 for QGIS API Documentation by
1.8.1.2