Skip to content

Commit 7734eb4

Browse files
author
mhugent
committed
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
1 parent 709fc8b commit 7734eb4

File tree

2 files changed

+64
-39
lines changed

2 files changed

+64
-39
lines changed

src/core/renderer/qgsgraduatedsymbolrenderer.cpp

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,68 @@ void QgsGraduatedSymbolRenderer::removeSymbols()
8686
mSymbols.clear();
8787
}
8888

89+
bool QgsGraduatedSymbolRenderer::willRenderFeature(QgsFeature *f)
90+
{
91+
return (symbolForFeature(f) != 0);
92+
}
93+
8994
void QgsGraduatedSymbolRenderer::renderFeature(QPainter * p, QgsFeature & f, QImage* img,
9095
double* scalefactor, bool selected, double widthScale)
96+
{
97+
QgsSymbol* theSymbol = symbolForFeature(&f);
98+
if(!theSymbol)
99+
{
100+
if ( img && mVectorType == QGis::Point )
101+
{
102+
img->fill(0);
103+
}
104+
else if ( mVectorType != QGis::Point )
105+
{
106+
p->setPen(Qt::NoPen);
107+
p->setBrush(Qt::NoBrush);
108+
}
109+
return;
110+
}
111+
112+
//set the qpen and qpainter to the right values
113+
// Point
114+
if ( img && mVectorType == QGis::Point )
115+
{
116+
*img = theSymbol->getPointSymbolAsImage( widthScale, selected, mSelectionColor );
117+
if ( scalefactor )
118+
{
119+
*scalefactor = 1;
120+
}
121+
}
122+
123+
// Line, polygon
124+
if ( mVectorType != QGis::Point )
125+
{
126+
if( !selected )
127+
{
128+
QPen pen=theSymbol->pen();
129+
pen.setWidthF ( widthScale * pen.width() );
130+
p->setPen(pen);
131+
p->setBrush(theSymbol->brush());
132+
}
133+
else
134+
{
135+
QPen pen=theSymbol->pen();
136+
pen.setColor(mSelectionColor);
137+
pen.setWidthF ( widthScale * pen.width() );
138+
QBrush brush=theSymbol->brush();
139+
brush.setColor(mSelectionColor);
140+
p->setPen(pen);
141+
p->setBrush(brush);
142+
}
143+
}
144+
}
145+
146+
147+
QgsSymbol* QgsGraduatedSymbolRenderer::symbolForFeature(const QgsFeature* f)
91148
{
92149
//first find out the value for the classification attribute
93-
const QgsAttributeMap& attrs = f.attributeMap();
150+
const QgsAttributeMap& attrs = f->attributeMap();
94151
double value = attrs[mClassificationField].fieldValue().toDouble();
95152

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

106163
if (it == mSymbols.end()) //only draw features which are covered by a render item
107-
{
108-
QgsDebugMsg("Warning, value is contained in no class");
109-
p->setPen(QPen(Qt::NoPen));
110-
p->setBrush(QBrush(Qt::NoBrush));
111-
return;
112-
}
113-
else
114-
{
115-
//set the qpen and qpainter to the right values
116-
// Point
117-
if ( img && mVectorType == QGis::Point )
118164
{
119-
*img = (*it)->getPointSymbolAsImage( widthScale,
120-
selected, mSelectionColor );
121-
122-
if ( scalefactor ) *scalefactor = 1;
123-
}
124-
125-
// Line, polygon
126-
if ( mVectorType != QGis::Point )
127-
{
128-
if( !selected )
129-
{
130-
QPen pen=(*it)->pen();
131-
pen.setWidthF ( widthScale * pen.width() );
132-
p->setPen(pen);
133-
p->setBrush((*it)->brush());
134-
}
135-
else
136-
{
137-
QPen pen=(*it)->pen();
138-
pen.setColor(mSelectionColor);
139-
pen.setWidthF ( widthScale * pen.width() );
140-
QBrush brush=(*it)->brush();
141-
brush.setColor(mSelectionColor);
142-
p->setPen(pen);
143-
p->setBrush(brush);
144-
}
165+
return 0;
145166
}
146-
}
167+
return (*it);
147168
}
148169

149170
void QgsGraduatedSymbolRenderer::readXML(const QDomNode& rnode, QgsVectorLayer& vl)

src/core/renderer/qgsgraduatedsymbolrenderer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class CORE_EXPORT QgsGraduatedSymbolRenderer: public QgsRenderer
4040
int classificationField() const;
4141
/**Removes all symbols*/
4242
void removeSymbols();
43+
/** Determines if a feature will be rendered or not
44+
@param f a pointer to the feature to determine if rendering will happen*/
45+
bool willRenderFeature(QgsFeature *f);
4346
/**Renders an OGRFeature
4447
\param p a painter (usually the one from the current map canvas)
4548
\param f a pointer to a feature to render
@@ -70,6 +73,7 @@ class CORE_EXPORT QgsGraduatedSymbolRenderer: public QgsRenderer
7073
int mClassificationField;
7174
/**List holding the symbols for the individual classes*/
7275
std::list<QgsSymbol*> mSymbols;
76+
QgsSymbol* symbolForFeature(const QgsFeature* f);
7377

7478
};
7579

0 commit comments

Comments
 (0)