Skip to content
Permalink
Browse files
And the same for graduated symbol renderer in svn head
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6507 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 3, 2007
1 parent 709fc8b commit 7734eb4e460db3f7487a6445408d347704e61ab2
Showing with 64 additions and 39 deletions.
  1. +60 −39 src/core/renderer/qgsgraduatedsymbolrenderer.cpp
  2. +4 −0 src/core/renderer/qgsgraduatedsymbolrenderer.h
@@ -86,11 +86,68 @@ void QgsGraduatedSymbolRenderer::removeSymbols()
mSymbols.clear();
}

bool QgsGraduatedSymbolRenderer::willRenderFeature(QgsFeature *f)
{
return (symbolForFeature(f) != 0);
}

void QgsGraduatedSymbolRenderer::renderFeature(QPainter * p, QgsFeature & f, QImage* img,
double* scalefactor, bool selected, double widthScale)
{
QgsSymbol* theSymbol = symbolForFeature(&f);
if(!theSymbol)
{
if ( img && mVectorType == QGis::Point )
{
img->fill(0);
}
else if ( mVectorType != QGis::Point )
{
p->setPen(Qt::NoPen);
p->setBrush(Qt::NoBrush);
}
return;
}

//set the qpen and qpainter to the right values
// Point
if ( img && mVectorType == QGis::Point )
{
*img = theSymbol->getPointSymbolAsImage( widthScale, selected, mSelectionColor );
if ( scalefactor )
{
*scalefactor = 1;
}
}

// Line, polygon
if ( mVectorType != QGis::Point )
{
if( !selected )
{
QPen pen=theSymbol->pen();
pen.setWidthF ( widthScale * pen.width() );
p->setPen(pen);
p->setBrush(theSymbol->brush());
}
else
{
QPen pen=theSymbol->pen();
pen.setColor(mSelectionColor);
pen.setWidthF ( widthScale * pen.width() );
QBrush brush=theSymbol->brush();
brush.setColor(mSelectionColor);
p->setPen(pen);
p->setBrush(brush);
}
}
}


QgsSymbol* QgsGraduatedSymbolRenderer::symbolForFeature(const QgsFeature* f)
{
//first find out the value for the classification attribute
const QgsAttributeMap& attrs = f.attributeMap();
const QgsAttributeMap& attrs = f->attributeMap();
double value = attrs[mClassificationField].fieldValue().toDouble();

std::list < QgsSymbol* >::iterator it;
@@ -104,46 +161,10 @@ void QgsGraduatedSymbolRenderer::renderFeature(QPainter * p, QgsFeature & f, QIm
}

if (it == mSymbols.end()) //only draw features which are covered by a render item
{
QgsDebugMsg("Warning, value is contained in no class");
p->setPen(QPen(Qt::NoPen));
p->setBrush(QBrush(Qt::NoBrush));
return;
}
else
{
//set the qpen and qpainter to the right values
// Point
if ( img && mVectorType == QGis::Point )
{
*img = (*it)->getPointSymbolAsImage( widthScale,
selected, mSelectionColor );

if ( scalefactor ) *scalefactor = 1;
}

// Line, polygon
if ( mVectorType != QGis::Point )
{
if( !selected )
{
QPen pen=(*it)->pen();
pen.setWidthF ( widthScale * pen.width() );
p->setPen(pen);
p->setBrush((*it)->brush());
}
else
{
QPen pen=(*it)->pen();
pen.setColor(mSelectionColor);
pen.setWidthF ( widthScale * pen.width() );
QBrush brush=(*it)->brush();
brush.setColor(mSelectionColor);
p->setPen(pen);
p->setBrush(brush);
}
return 0;
}
}
return (*it);
}

void QgsGraduatedSymbolRenderer::readXML(const QDomNode& rnode, QgsVectorLayer& vl)
@@ -40,6 +40,9 @@ class CORE_EXPORT QgsGraduatedSymbolRenderer: public QgsRenderer
int classificationField() const;
/**Removes all symbols*/
void removeSymbols();
/** Determines if a feature will be rendered or not
@param f a pointer to the feature to determine if rendering will happen*/
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
@@ -70,6 +73,7 @@ class CORE_EXPORT QgsGraduatedSymbolRenderer: public QgsRenderer
int mClassificationField;
/**List holding the symbols for the individual classes*/
std::list<QgsSymbol*> mSymbols;
QgsSymbol* symbolForFeature(const QgsFeature* f);

};

0 comments on commit 7734eb4

Please sign in to comment.