Skip to content

Commit

Permalink
re-add useIntersect support in QgsVectorLayer
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9097 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 20, 2008
1 parent 1543f50 commit c175c12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
3 changes: 2 additions & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -143,7 +143,8 @@ public:

void select(QList<int> fetchAttributes = QList<int>(),
QgsRect rect = QgsRect(),
bool fetchGeometry = true);
bool fetchGeometry = true,
bool useIntersect = false);

bool getNextFeature(QgsFeature& feature);

Expand Down
83 changes: 40 additions & 43 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -283,9 +283,9 @@ void QgsVectorLayer::drawLabels(QgsRenderContext& renderContext)
{
QPainter* thePainter = renderContext.painter();
if(!thePainter)
{
return;
}
{
return;
}
drawLabels(thePainter, renderContext.extent(), &(renderContext.mapToPixel()), renderContext.coordTransform(), 1.0 / renderContext.rasterScaleFactor());
}

Expand All @@ -311,7 +311,7 @@ void QgsVectorLayer::drawLabels(QPainter * p, const QgsRect& viewExtent, const Q
{
// select the records in the extent. The provider sets a spatial filter
// and sets up the selection set for retrieval
select(attributes, viewExtent, true);
select(attributes, viewExtent);

QgsFeature fet;
while( getNextFeature(fet) )
Expand Down Expand Up @@ -715,12 +715,12 @@ bool QgsVectorLayer::draw(QgsRenderContext& renderContext)
int totalFeatures = pendingFeatureCount();
int featureCount = 0;

QgsFeature fet;
QgsAttributeList attributes = mRenderer->classificationAttributes();
select(attributes, renderContext.extent(), true);

try
{
QgsFeature fet;
QgsAttributeList attributes = mRenderer->classificationAttributes();
select(attributes, renderContext.extent());

while( getNextFeature(fet) )
{

Expand Down Expand Up @@ -840,8 +840,7 @@ void QgsVectorLayer::select(QgsRect & rect, bool lock)
}

//select all the elements

select(QgsAttributeList(), rect, false);
select(QgsAttributeList(), rect, false, true);

QgsFeature f;
while( getNextFeature(f) )
Expand All @@ -859,7 +858,7 @@ void QgsVectorLayer::invertSelection()

removeSelection(FALSE); // don't emit signal

select(QgsAttributeList(), QgsRect(), true);
select(QgsAttributeList(), QgsRect(), false);

QgsFeature fet;
while ( getNextFeature(fet) )
Expand Down Expand Up @@ -1081,8 +1080,6 @@ void QgsVectorLayer::updateExtents()
QgsRect r = it->geometry()->boundingBox();
mLayerExtent.combineExtentWith(&r);
}

return;
}
else
{
Expand Down Expand Up @@ -1149,7 +1146,7 @@ void QgsVectorLayer::updateFeatureGeometry(QgsFeature &f)
}


void QgsVectorLayer::select(QgsAttributeList attributes, QgsRect rect, bool fetchGeometries)
void QgsVectorLayer::select(QgsAttributeList attributes, QgsRect rect, bool fetchGeometries, bool useIntersect)
{
if(!mDataProvider)
return;
Expand All @@ -1171,11 +1168,11 @@ void QgsVectorLayer::select(QgsAttributeList attributes, QgsRect rect, bool fetc
//look in the normal features of the provider
if( mFetchAttributes.size()>0 )
{
mDataProvider->select(mFetchAttributes, rect, fetchGeometries, true);
mDataProvider->select(mFetchAttributes, rect, fetchGeometries, useIntersect);
}
else
{
mDataProvider->select(QgsAttributeList(), rect, fetchGeometries, true);
mDataProvider->select(QgsAttributeList(), rect, fetchGeometries, useIntersect);
}
}

Expand Down Expand Up @@ -1311,29 +1308,29 @@ int QgsVectorLayer::getFeatureAtId(int featureId, QgsFeature& f, bool fetchGeome
{
if( featureId<0 )
{
// featureId<0 => in mAddedFeatures
bool found = false;

for (QgsFeatureList::iterator it=mAddedFeatures.begin(); it!=mAddedFeatures.end(); it++)
{
if( featureId!=it->featureId() )
{
found = true;
f.setAttributeMap( it->attributeMap() );
break;
}
}

if(!found)
QgsLogger::warning( QString("No attributes for the added feature %1 found").arg(f.featureId()) );
// featureId<0 => in mAddedFeatures
bool found = false;

for (QgsFeatureList::iterator it=mAddedFeatures.begin(); it!=mAddedFeatures.end(); it++)
{
if( featureId!=it->featureId() )
{
found = true;
f.setAttributeMap( it->attributeMap() );
break;
}
}

if(!found)
QgsLogger::warning( QString("No attributes for the added feature %1 found").arg(f.featureId()) );
}
else
{
// retrieve attributes from provider
QgsFeature tmp;
mDataProvider->getFeatureAtId(featureId, tmp, false, mDataProvider->allAttributesList());
updateFeatureAttributes(tmp);
f.setAttributeMap( tmp.attributeMap() );
// retrieve attributes from provider
QgsFeature tmp;
mDataProvider->getFeatureAtId(featureId, tmp, false, mDataProvider->allAttributesList());
updateFeatureAttributes(tmp);
f.setAttributeMap( tmp.attributeMap() );
}
updateFeatureAttributes(f);
}
Expand Down Expand Up @@ -1548,7 +1545,7 @@ int QgsVectorLayer::addRing(const QList<QgsPoint>& ring)
return 3; //ring not valid
}

select(QgsAttributeList(), bBox, true);
select(QgsAttributeList(), bBox, true, true);

QgsFeature f;
while( getNextFeature(f) )
Expand Down Expand Up @@ -1693,7 +1690,7 @@ int QgsVectorLayer::splitFeatures(const QList<QgsPoint>& splitLine, bool topolog
}
}

select(QgsAttributeList(), bBox, true);
select(QgsAttributeList(), bBox, true, true);

QgsFeature f;
while( getNextFeature(f) )
Expand Down Expand Up @@ -1758,7 +1755,7 @@ int QgsVectorLayer::removePolygonIntersections(QgsGeometry* geom)
QgsRect geomBBox = geom->boundingBox();

//get list of features that intersect this bounding box
select(QgsAttributeList(), geomBBox, true);
select(QgsAttributeList(), geomBBox, true, true);

QgsFeature f;
while( getNextFeature(f) )
Expand Down Expand Up @@ -1794,7 +1791,7 @@ int QgsVectorLayer::addTopologicalPoints(QgsGeometry* geom)
case QGis::WKBLineString:
{
QgsPolyline theLine = geom->asPolyline();
QgsPolyline::const_iterator line_it = theLine.constBegin();
QgsPolyline::const_iterator line_it = theLine.constBegin();
for(; line_it != theLine.constEnd(); ++line_it)
{
if(addTopologicalPoints(*line_it) != 0)
Expand Down Expand Up @@ -1836,7 +1833,7 @@ int QgsVectorLayer::addTopologicalPoints(QgsGeometry* geom)
for(int i = 0; i < thePolygon.size(); ++i)
{
currentRing = thePolygon.at(i);
QgsPolyline::const_iterator line_it = currentRing.constBegin();
QgsPolyline::const_iterator line_it = currentRing.constBegin();
for(; line_it != currentRing.constEnd(); ++line_it)
{
if(addTopologicalPoints(*line_it) != 0)
Expand All @@ -1862,7 +1859,7 @@ int QgsVectorLayer::addTopologicalPoints(QgsGeometry* geom)
for(int j = 0; j < currentPolygon.size(); ++j)
{
currentRing = currentPolygon.at(j);
QgsPolyline::const_iterator line_it = currentRing.constBegin();
QgsPolyline::const_iterator line_it = currentRing.constBegin();
for(; line_it != currentRing.constEnd(); ++line_it)
{
if(addTopologicalPoints(*line_it) != 0)
Expand Down Expand Up @@ -3057,7 +3054,7 @@ int QgsVectorLayer::snapWithContext(const QgsPoint& startPoint, double snappingT
startPoint.x()+snappingTolerance, startPoint.y()+snappingTolerance);
double sqrSnappingTolerance = snappingTolerance * snappingTolerance;

select(QgsAttributeList(), searchRect, true);
select(QgsAttributeList(), searchRect, true, true);

int n=0;
QgsFeature f;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -199,7 +199,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

void select(QgsAttributeList fetchAttributes,
QgsRect rect = QgsRect(),
bool fetchGeometry = true);
bool fetchGeometry = true,
bool useIntersect = false);

bool getNextFeature(QgsFeature& feature);

Expand Down

0 comments on commit c175c12

Please sign in to comment.