Skip to content

Commit

Permalink
Applied patch from ticket #565 Do not render features or their labels…
Browse files Browse the repository at this point in the history
… if their classification value doesn't match a symbol's lower/upper range

git-svn-id: http://svn.osgeo.org/qgis/branches/Release-0_8_0@6502 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 3, 2007
1 parent 9e76700 commit b617659
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/core/qgsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ bool QgsRenderer::containsPixmap() const
}
}

bool QgsRenderer::willRenderFeature(QgsFeature *f)
{
// Normally render the feature, unless told otherwise
return true;
}
3 changes: 3 additions & 0 deletions src/core/qgsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class QgsRenderer
QgsRenderer();
/** Virtual destructor because we have virtual methods... */
virtual ~QgsRenderer() {};
/** Determines if a feature will be rendered or not
@param f a pointer to the feature to determine if rendering will happen*/
virtual bool willRenderFeature(QgsFeature *f);
/**A vector layer passes features to a renderer object to change the brush and pen of the qpainter
@param p the painter storing brush and pen
@param f a pointer to the feature to be rendered
Expand Down
42 changes: 29 additions & 13 deletions src/gui/qgsgraduatedsymbolrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,20 @@ void QgsGraduatedSymbolRenderer::removeSymbols()
mSymbols.clear();
}

void QgsGraduatedSymbolRenderer::renderFeature(QPainter * p, QgsFeature * f, QPixmap* pic,
double* scalefactor, bool selected, double widthScale)
bool QgsGraduatedSymbolRenderer::willRenderFeature(QgsFeature *f)
{
//first find out the value for the classification attribute
std::vector < QgsFeatureAttribute > vec = f->attributeMap();
double value = vec[0].fieldValue().toDouble();

std::list < QgsSymbol* >::iterator it;
//find the first render item which contains the feature
for (it = mSymbols.begin(); it != mSymbols.end(); ++it)
{
if (value >= (*it)->lowerValue().toDouble() && value <= (*it)->upperValue().toDouble())
std::list < QgsSymbol* >::iterator it = firstSymbolForFeature(f);
if (it == mSymbols.end()) //only draw features which are covered by a render item
{
break;
return false;
}
}
return true;
}

void QgsGraduatedSymbolRenderer::renderFeature(QPainter * p, QgsFeature * f, QPixmap* pic,
double* scalefactor, bool selected, double widthScale)
{
std::list < QgsSymbol* >::iterator it = firstSymbolForFeature(f);

if (it == mSymbols.end()) //only draw features which are covered by a render item
{
Expand Down Expand Up @@ -142,6 +140,24 @@ void QgsGraduatedSymbolRenderer::renderFeature(QPainter * p, QgsFeature * f, QPi
}
}

std::list < QgsSymbol* >::iterator QgsGraduatedSymbolRenderer::firstSymbolForFeature(QgsFeature *f)
{
//first find out the value for the classification attribute
std::vector < QgsFeatureAttribute > vec = f->attributeMap();
double value = vec[0].fieldValue().toDouble();

std::list < QgsSymbol* >::iterator it;
//find the first render item which contains the feature
for (it = mSymbols.begin(); it != mSymbols.end(); ++it)
{
if (value >= (*it)->lowerValue().toDouble() && value <= (*it)->upperValue().toDouble())
{
break;
}
}
return it;
}

void QgsGraduatedSymbolRenderer::readXML(const QDomNode& rnode, QgsVectorLayer& vl)
{
mVectorType = vl.vectorType();
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsgraduatedsymbolrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class QgsGraduatedSymbolRenderer: public QgsRenderer
int classificationField() const;
/**Removes all symbols*/
void removeSymbols();
/**Determines if an OGRFeature is in range of any symbol's upper and lower bounds
@param f a pointer to the feature to check*/
bool willRenderFeature(QgsFeature *f);
/**Renders an OGRFeature
\param p a painter (usually the one from the current map canvas)
\param f a pointer to a feature to render
Expand Down Expand Up @@ -75,6 +78,10 @@ class QgsGraduatedSymbolRenderer: public QgsRenderer
int mClassificationField;
/**List holding the symbols for the individual classes*/
std::list<QgsSymbol*> mSymbols;

private:
/**Helper function for finding symbol having feature value in range*/
std::list < QgsSymbol* >::iterator firstSymbolForFeature(QgsFeature *f);

};

Expand Down
30 changes: 21 additions & 9 deletions src/gui/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@ void QgsVectorLayer::drawLabels(QPainter * p, QgsRect * viewExtent, QgsMapToPixe
if(mDeletedFeatureIds.find(fet->featureId())==mDeletedFeatureIds.end())
{
bool sel=mSelectedFeatureIds.find(fet->featureId()) != mSelectedFeatureIds.end();
mLabel->renderLabel ( p, viewExtent, *mCoordinateTransform,
projectionsEnabledFlag,
theMapToPixelTransform, fet, sel, 0, scale);
if (m_renderer && m_renderer->willRenderFeature(fet))
{
mLabel->renderLabel ( p, viewExtent, *mCoordinateTransform, projectionsEnabledFlag, \
theMapToPixelTransform, fet, sel, 0, scale);
}
}
}
delete fet;
Expand All @@ -374,8 +376,11 @@ void QgsVectorLayer::drawLabels(QPainter * p, QgsRect * viewExtent, QgsMapToPixe
for(std::vector<QgsFeature*>::iterator it=mAddedFeatures.begin();it!=mAddedFeatures.end();++it)
{
bool sel=mSelectedFeatureIds.find((*it)->featureId()) != mSelectedFeatureIds.end();
mLabel->renderLabel ( p, viewExtent, *mCoordinateTransform, projectionsEnabledFlag,
if (m_renderer && m_renderer->willRenderFeature(fet))
{
mLabel->renderLabel ( p, viewExtent, *mCoordinateTransform, projectionsEnabledFlag,
theMapToPixelTransform, *it, sel, 0, scale);
}
}
}
catch (QgsCsException &e)
Expand Down Expand Up @@ -880,24 +885,31 @@ void QgsVectorLayer::draw(QPainter * p,
sel = FALSE;
}

m_renderer->renderFeature(p, fet, &marker, &markerScaleFactor, sel, widthScale );
double scale = markerScaleFactor * symbolScale;
drawFeature(p,
if (m_renderer->willRenderFeature(fet))
{
m_renderer->renderFeature(p, fet, &marker, &markerScaleFactor, sel, widthScale );
double scale = markerScaleFactor * symbolScale;
drawFeature(p,
fet,
theMapToPixelTransform,
&marker,
scale,
projectionsEnabledFlag,
drawingToEditingCanvas);
++featureCount;
delete fet;
++featureCount;
delete fet;
}
}

//also draw the not yet commited features
if(mEditable)
{
for(std::vector<QgsFeature*>::iterator it = mAddedFeatures.begin(); it != mAddedFeatures.end(); ++it)
{
if (!m_renderer->willRenderFeature(*it))
{
continue;
}
bool sel=mSelectedFeatureIds.find((*it)->featureId()) != mSelectedFeatureIds.end();
m_renderer->renderFeature(p, *it, &marker, &markerScaleFactor, sel, widthScale);
double scale = markerScaleFactor * symbolScale;
Expand Down

0 comments on commit b617659

Please sign in to comment.