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
qgscachedfeatureiterator.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgscachedfeatureiterator.cpp
3
--------------------------------------
4
Date : 12.2.2013
5
Copyright : (C) 2013 Matthias Kuhn
6
Email : matthias dot kuhn at gmx dot ch
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
16
#include "
qgscachedfeatureiterator.h
"
17
#include "
qgsvectorlayercache.h
"
18
19
QgsCachedFeatureIterator::QgsCachedFeatureIterator
(
QgsVectorLayerCache
*vlCache,
QgsFeatureRequest
featureRequest,
QgsFeatureIds
featureIds )
20
:
QgsAbstractFeatureIterator
( featureRequest )
21
, mFeatureIds( featureIds )
22
, mVectorLayerCache( vlCache )
23
{
24
mFeatureIdIterator
= featureIds.constBegin();
25
26
if
(
mFeatureIdIterator
== featureIds.constEnd() )
27
close
();
28
}
29
30
QgsCachedFeatureIterator::QgsCachedFeatureIterator
(
QgsVectorLayerCache
*vlCache,
QgsFeatureRequest
featureRequest )
31
:
QgsAbstractFeatureIterator
( featureRequest )
32
, mVectorLayerCache( vlCache )
33
{
34
switch
( featureRequest.
filterType
() )
35
{
36
case
QgsFeatureRequest::FilterFids
:
37
mFeatureIds
= featureRequest.
filterFids
();
38
break
;
39
40
case
QgsFeatureRequest::FilterFid
:
41
mFeatureIds
=
QgsFeatureIds
() << featureRequest.
filterFid
();
42
break
;
43
44
default
:
45
mFeatureIds
=
mVectorLayerCache
->
mCache
.keys().toSet();
46
break
;
47
}
48
49
mFeatureIdIterator
=
mFeatureIds
.constBegin();
50
51
if
(
mFeatureIdIterator
==
mFeatureIds
.constEnd() )
52
close
();
53
}
54
55
bool
QgsCachedFeatureIterator::fetchFeature
(
QgsFeature
& f )
56
{
57
if
(
mClosed
)
58
return
false
;
59
60
while
(
mFeatureIdIterator
!=
mFeatureIds
.constEnd() )
61
{
62
f =
QgsFeature
( *
mVectorLayerCache
->
mCache
[*
mFeatureIdIterator
]->feature() );
63
++
mFeatureIdIterator
;
64
if
(
mRequest
.
acceptFeature
( f ) )
65
return
true
;
66
}
67
close
();
68
return
false
;
69
}
70
71
bool
QgsCachedFeatureIterator::rewind
()
72
{
73
mFeatureIdIterator
=
mFeatureIds
.constBegin();
74
return
true
;
75
}
76
77
bool
QgsCachedFeatureIterator::close
()
78
{
79
mClosed
=
true
;
80
mFeatureIds
.clear();
81
return
true
;
82
}
83
84
QgsCachedFeatureWriterIterator::QgsCachedFeatureWriterIterator
(
QgsVectorLayerCache
*vlCache,
QgsFeatureRequest
featureRequest )
85
:
QgsAbstractFeatureIterator
( featureRequest )
86
, mVectorLayerCache( vlCache )
87
{
88
mFeatIt
= vlCache->
layer
()->
getFeatures
( featureRequest );
89
}
90
91
bool
QgsCachedFeatureWriterIterator::fetchFeature
(
QgsFeature
& f )
92
{
93
if
(
mFeatIt
.
nextFeature
( f ) )
94
{
95
// As long as features can be fetched from the provider: Write them to cache
96
mVectorLayerCache
->
cacheFeature
( f );
97
mFids
.insert( f.
id
() );
98
return
true
;
99
}
100
else
101
{
102
// Once no more features can be fetched: Inform the cache, that
103
// the request has been completed
104
mVectorLayerCache
->
requestCompleted
(
mRequest
,
mFids
);
105
return
false
;
106
}
107
}
108
109
bool
QgsCachedFeatureWriterIterator::rewind
()
110
{
111
mFids
.clear();
112
return
mFeatIt
.
rewind
();
113
}
114
115
bool
QgsCachedFeatureWriterIterator::close
()
116
{
117
mClosed
=
true
;
118
return
mFeatIt
.
close
();
119
}
Generated on Sun Feb 23 2014 14:27:18 for QGIS API Documentation by
1.8.1.2