@@ -93,62 +93,78 @@ int QgsUniqueValueRenderer::classificationField()
93
93
{
94
94
return mClassificationField ;
95
95
}
96
+
97
+ bool QgsUniqueValueRenderer::willRenderFeature (QgsFeature *f)
98
+ {
99
+ return (symbolForFeature (f) != 0 );
100
+ }
96
101
97
102
void QgsUniqueValueRenderer::renderFeature (QPainter* p, QgsFeature& f,QImage* img,
98
103
double * scalefactor, bool selected, double widthScale)
99
104
{
100
- const QgsAttributeMap& attrs = f.attributeMap ();
101
- QString value = attrs[mClassificationField ].fieldValue ();
105
+ QgsSymbol* symbol = symbolForFeature (&f);
106
+ if (!symbol) // no matching symbol
107
+ {
108
+ if ( img && mVectorType == QGis::Point )
109
+ {
110
+ img->fill (0 );
111
+ }
112
+ else if ( mVectorType != QGis::Point )
113
+ {
114
+ p->setPen (Qt::NoPen);
115
+ p->setBrush (Qt::NoBrush);
116
+ }
117
+ return ;
118
+ }
102
119
103
- std::map<QString,QgsSymbol*>::iterator it= mSymbols . find (value);
104
- if (it!= mSymbols . end ())
120
+ // Point
121
+ if ( img && mVectorType == QGis:: Point )
105
122
{
106
- QgsSymbol* symbol = it->second ;
107
-
108
- // Point
109
- if ( img && mVectorType == QGis::Point ) {
110
- *img = symbol->getPointSymbolAsImage ( widthScale,
111
- selected, mSelectionColor );
112
-
113
- if ( scalefactor ) *scalefactor = 1 ;
114
- }
115
-
116
- // Line, polygon
117
- else if ( mVectorType != QGis::Point )
123
+ *img = symbol->getPointSymbolAsImage ( widthScale, selected, mSelectionColor );
124
+ if ( scalefactor )
118
125
{
119
- if ( !selected )
120
- {
121
- QPen pen=symbol->pen ();
122
- pen.setWidthF ( widthScale * pen.width () );
123
- p->setPen (pen);
124
- p->setBrush (symbol->brush ());
125
- }
126
- else
127
- {
128
- QPen pen=symbol->pen ();
129
- pen.setWidthF ( widthScale * pen.width () );
130
- pen.setColor (mSelectionColor );
131
- QBrush brush=symbol->brush ();
126
+ *scalefactor = 1 ;
127
+ }
128
+ }
129
+
130
+ // Line, polygon
131
+ else if ( mVectorType != QGis::Point )
132
+ {
133
+ if ( !selected )
134
+ {
135
+ QPen pen=symbol->pen ();
136
+ pen.setWidthF ( widthScale * pen.width () );
137
+ p->setPen (pen);
138
+ p->setBrush (symbol->brush ());
139
+ }
140
+ else
141
+ {
142
+ QPen pen=symbol->pen ();
143
+ pen.setWidthF ( widthScale * pen.width () );
144
+ pen.setColor (mSelectionColor );
145
+ QBrush brush=symbol->brush ();
132
146
brush.setColor (mSelectionColor );
133
147
p->setPen (pen);
134
148
p->setBrush (brush);
135
- }
136
149
}
137
150
}
138
- else
151
+ }
152
+
153
+ QgsSymbol* QgsUniqueValueRenderer::symbolForFeature (const QgsFeature* f)
154
+ {
155
+ // first find out the value
156
+ const QgsAttributeMap& attrs = f->attributeMap ();
157
+ QString value = attrs[mClassificationField ].fieldValue ();
158
+
159
+ std::map<QString,QgsSymbol*>::iterator it=mSymbols .find (value);
160
+ if (it == mSymbols .end ())
139
161
{
140
- // no matching symbol found. In this case, set Qt::NoPen, Qt::NoBrush or transparent image
141
- if ( img && mVectorType == QGis::Point )
142
- {
143
- img->fill (0 );
144
- }
145
- else if ( mVectorType != QGis::Point )
146
- {
147
- p->setPen (Qt::NoPen);
148
- p->setBrush (Qt::NoBrush);
149
- }
162
+ return 0 ;
163
+ }
164
+ else
165
+ {
166
+ return it->second ;
150
167
}
151
-
152
168
}
153
169
154
170
void QgsUniqueValueRenderer::readXML (const QDomNode& rnode, QgsVectorLayer& vl)
0 commit comments