Skip to content
Permalink
Browse files
Applied patch from ticket #565 Do not render features or their labels…
… 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 b617659dcd7710b5f5ece5709822fdb033a4d230
Showing with 65 additions and 22 deletions.
  1. +5 −0 src/core/qgsrenderer.cpp
  2. +3 −0 src/core/qgsrenderer.h
  3. +29 −13 src/gui/qgsgraduatedsymbolrenderer.cpp
  4. +7 −0 src/gui/qgsgraduatedsymbolrenderer.h
  5. +21 −9 src/gui/qgsvectorlayer.cpp
@@ -72,3 +72,8 @@ bool QgsRenderer::containsPixmap() const
}
}

bool QgsRenderer::willRenderFeature(QgsFeature *f)
{
// Normally render the feature, unless told otherwise
return true;
}
@@ -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
@@ -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
{
@@ -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();
@@ -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
@@ -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);

};

@@ -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;
@@ -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)
@@ -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;

0 comments on commit b617659

Please sign in to comment.