-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
970 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/*************************************************************************** | ||
qgscachedfeatureiterator.cpp | ||
-------------------------------------- | ||
Date : 12.2.2013 | ||
Copyright : (C) 2013 Matthias Kuhn | ||
Email : matthias dot kuhn at gmx dot 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgscachedfeatureiterator.h" | ||
#include "qgsvectorlayercache.h" | ||
#include "qgsvectordataprovider.h" | ||
|
||
QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache, QgsFeatureRequest featureRequest, QgsFeatureIds featureIds ) | ||
: QgsAbstractFeatureIterator( featureRequest ), | ||
mFeatureIds( featureIds ), | ||
mVectorLayerCache( vlCache ) | ||
{ | ||
mFeatureIdIterator = featureIds.begin(); | ||
} | ||
|
||
bool QgsCachedFeatureIterator::nextFeature( QgsFeature& f ) | ||
{ | ||
mFeatureIdIterator++; | ||
|
||
if ( mFeatureIdIterator == mFeatureIds.end() ) | ||
{ | ||
return false; | ||
} | ||
else | ||
{ | ||
f = QgsFeature( *mVectorLayerCache->mCache[*mFeatureIdIterator]->feature() ); | ||
return true; | ||
} | ||
} | ||
|
||
bool QgsCachedFeatureIterator::rewind() | ||
{ | ||
mFeatureIdIterator = mFeatureIds.begin(); | ||
return true; | ||
} | ||
|
||
bool QgsCachedFeatureIterator::close() | ||
{ | ||
// Nothing to clean... | ||
return true; | ||
} | ||
|
||
QgsCachedFeatureWriterIterator::QgsCachedFeatureWriterIterator( QgsVectorLayerCache *vlCache, QgsFeatureRequest featureRequest ) | ||
: QgsAbstractFeatureIterator( featureRequest ), | ||
mVectorLayerCache( vlCache ) | ||
{ | ||
mFeatIt = vlCache->layer()->dataProvider()->getFeatures( featureRequest ); | ||
} | ||
|
||
bool QgsCachedFeatureWriterIterator::nextFeature( QgsFeature& f ) | ||
{ | ||
if ( mFeatIt.nextFeature( f ) ) | ||
{ | ||
// As long as features can be fetched from the provider: Write them to cache | ||
mVectorLayerCache->cacheFeature( f ); | ||
mFids.insert( f.id() ); | ||
return true; | ||
} | ||
else | ||
{ | ||
// Once no more features can be fetched: Inform the cache, that | ||
// the request has been completed | ||
mVectorLayerCache->requestCompleted( mRequest, mFids ); | ||
return false; | ||
} | ||
} | ||
|
||
bool QgsCachedFeatureWriterIterator::rewind() | ||
{ | ||
mFids.clear(); | ||
return mFeatIt.rewind(); | ||
} | ||
|
||
bool QgsCachedFeatureWriterIterator::close() | ||
{ | ||
return mFeatIt.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/*************************************************************************** | ||
qgscachedfeatureiterator.h | ||
-------------------------------------- | ||
Date : 12.2.2013 | ||
Copyright : (C) 2013 Matthias Kuhn | ||
Email : matthias dot kuhn at gmx dot 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 QGSCACHEDFEATUREITERATOR_H | ||
#define QGSCACHEDFEATUREITERATOR_H | ||
|
||
#include "qgsfeature.h" | ||
#include "qgsfeatureiterator.h" | ||
|
||
class QgsVectorLayerCache; | ||
|
||
/** | ||
* @brief | ||
* Delivers features from the cache | ||
* | ||
*/ | ||
class CORE_EXPORT QgsCachedFeatureIterator : public QgsAbstractFeatureIterator | ||
{ | ||
public: | ||
/** | ||
* @brief | ||
* This constructor creates a feature iterator, that delivers only cached information, based on the | ||
* {@link QgsFeatureIds}. No request is made to the backend. | ||
* | ||
* @param vlCache The vector layer cache to use | ||
* @param featureRequest The feature request to answer | ||
* @param featureIds The feature ids to return | ||
*/ | ||
QgsCachedFeatureIterator( QgsVectorLayerCache* vlCache, QgsFeatureRequest featureRequest, QgsFeatureIds featureIds ); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @param f | ||
* @return bool | ||
*/ | ||
virtual bool nextFeature( QgsFeature& f ); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @return bool | ||
*/ | ||
virtual bool rewind(); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @return bool | ||
*/ | ||
virtual bool close(); | ||
|
||
private: | ||
QgsFeatureIds mFeatureIds; | ||
QgsVectorLayerCache* mVectorLayerCache; | ||
QgsFeatureIds::Iterator mFeatureIdIterator; | ||
}; | ||
|
||
/** | ||
* @brief | ||
* Uses another iterator as backend and writes features to the cache | ||
* | ||
*/ | ||
class CORE_EXPORT QgsCachedFeatureWriterIterator : public QgsAbstractFeatureIterator | ||
{ | ||
public: | ||
/** | ||
* @brief | ||
* This constructor creates a feature iterator, which queries the backend and caches retrieved features. | ||
* | ||
* @param vlCache The vector layer cache to use | ||
* @param featureRequest The feature request to answer | ||
*/ | ||
QgsCachedFeatureWriterIterator( QgsVectorLayerCache* vlCache, QgsFeatureRequest featureRequest ); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @param f | ||
* @return bool | ||
*/ | ||
virtual bool nextFeature( QgsFeature& f ); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @return bool | ||
*/ | ||
virtual bool rewind(); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @return bool | ||
*/ | ||
virtual bool close(); | ||
|
||
private: | ||
QgsFeatureIterator mFeatIt; | ||
QgsVectorLayerCache* mVectorLayerCache; | ||
QgsFeatureIds mFids; | ||
}; | ||
#endif // QGSCACHEDFEATUREITERATOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*************************************************************************** | ||
qgscacheindex.cpp | ||
-------------------------------------- | ||
Date : 13.2.2013 | ||
Copyright : (C) 2013 Matthias Kuhn | ||
Email : matthias dot kuhn at gmx dot 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgscacheindex.h" | ||
#include "qgsfeaturerequest.h" | ||
|
||
QgsAbstractCacheIndex::QgsAbstractCacheIndex() | ||
{ | ||
} | ||
|
||
QgsAbstractCacheIndex::~QgsAbstractCacheIndex() | ||
{ | ||
} | ||
|
||
void QgsAbstractCacheIndex::requestCompleted( QgsFeatureRequest featureRequest, QgsFeatureIds fids ) | ||
{ | ||
Q_UNUSED( featureRequest ) | ||
Q_UNUSED( fids ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*************************************************************************** | ||
qgscacheindex.h | ||
-------------------------------------- | ||
Date : 13.2.2013 | ||
Copyright : (C) 2013 Matthias Kuhn | ||
Email : matthias dot kuhn at gmx dot 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 QGSCACHEINDEX_H | ||
#define QGSCACHEINDEX_H | ||
|
||
#include "qgsfeature.h" // QgsFeatureIds | ||
|
||
class QgsFeatureRequest; | ||
|
||
/** | ||
* @brief | ||
* Abstract base class for cache indices | ||
*/ | ||
|
||
class QgsAbstractCacheIndex | ||
{ | ||
public: | ||
QgsAbstractCacheIndex(); | ||
virtual ~QgsAbstractCacheIndex(); | ||
|
||
/** | ||
* Is called, whenever a feature is removed from the cache. You should update your indexes, so | ||
* they become invalid in case this feature was required to successfuly answer a request. | ||
*/ | ||
virtual void flushFeature( const QgsFeatureId fid ) = 0; | ||
|
||
/** | ||
* Sometimes, the whole cache changes its state and its easier to just withdraw everything. | ||
* In this case, this method is issued. Be sure to clear all cache information in here. | ||
*/ | ||
virtual void flush() = 0; | ||
|
||
/** | ||
* @brief | ||
* Implement this method to update the the indices, in case you need information contained by the request | ||
* to properly index. (E.g. spatial index) | ||
* Does nothing by default | ||
* | ||
* @param featureRequest The feature request that was answered | ||
* @param fids The feature ids that have been returned | ||
*/ | ||
virtual void requestCompleted( QgsFeatureRequest featureRequest, QgsFeatureIds fids ); | ||
|
||
/** | ||
* Is called, when a feature request is issued on a cached layer. | ||
* If this cache index is able to completely answer the feature request, it will return true | ||
* and write the list of feature ids of cached features to cachedFeatures. If it is not able | ||
* it will return false and the cachedFeatures state is undefined. | ||
* | ||
* @param cachedFeatures A reference to {@link QgsFeatureIds}, where a list of ids is written to, | ||
* in case this index is able to answer the request. | ||
* @param featureRequest The feature request, for which this index is queried. | ||
* | ||
* @return True, if this index holds the information to answer the request. | ||
* | ||
*/ | ||
virtual bool getCachedIds( QgsFeatureIds& cachedFeatures, const QgsFeatureRequest& featureRequest ) = 0; | ||
}; | ||
|
||
#endif // QGSCACHEINDEX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*************************************************************************** | ||
qgscacheindexfeatureid.cpp | ||
-------------------------------------- | ||
Date : 13.2.2013 | ||
Copyright : (C) 2013 Matthias Kuhn | ||
Email : matthias dot kuhn at gmx dot 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgscacheindexfeatureid.h" | ||
|
||
QgsCacheIndexFeatureId::QgsCacheIndexFeatureId( QgsCachedVectorLayer* cachedVectorLayer ) : | ||
QgsAbstractCacheIndex(), | ||
C( cachedVectorLayer ) | ||
{ | ||
|
||
} | ||
|
Oops, something went wrong.