224 |
224 |
mVectorLayer->setRenderer(renderer);
|
225 |
225 |
}
|
226 |
226 |
|
|
227 |
QColor QgsGraduatedSymbolDialog::getColorFromRamp(QString ramp, int step, int totalSteps)
|
|
228 |
{
|
|
229 |
QColor color;
|
|
230 |
|
|
231 |
/* To do:
|
|
232 |
Grab the ramp by name from a file or ramp registry
|
|
233 |
and apply determine the color for the given step.
|
|
234 |
Ideally there would be two types of ramps:
|
|
235 |
- discrete colors: the number of steps would have to match totalSteps
|
|
236 |
- continuous colors: (eg grass or gmt ramps) would need to code a method
|
|
237 |
for determining an RGB color for any point along the continuum
|
|
238 |
Color ramps should be plugin-able; should be defined in a simple text file format
|
|
239 |
and read from a directory where users can add their own ramps.
|
|
240 |
*/
|
|
241 |
|
|
242 |
if (step == 0)
|
|
243 |
{
|
|
244 |
color = QColor(0,255,0);
|
|
245 |
}
|
|
246 |
else
|
|
247 |
{
|
|
248 |
color = QColor(0,255-((255/totalSteps)*step+1),((255/totalSteps)*step+1));
|
|
249 |
}
|
|
250 |
|
|
251 |
return color;
|
|
252 |
}
|
|
253 |
|
227 |
254 |
void QgsGraduatedSymbolDialog::adjustClassification()
|
228 |
255 |
{
|
229 |
256 |
mClassListWidget->clear();
|
... | ... | |
275 |
302 |
QPen pen;
|
276 |
303 |
QBrush brush;
|
277 |
304 |
|
|
305 |
|
278 |
306 |
//apply a nice color range from red to green as default
|
279 |
|
//todo: make other color ranges available
|
280 |
|
if (i == 0)
|
281 |
|
{
|
282 |
|
if (m_type == QGis::Line)
|
283 |
|
{
|
284 |
|
pen.setColor(QColor(255, 0, 0));
|
285 |
|
}
|
286 |
|
else //point or polygon
|
287 |
|
{
|
288 |
|
brush.setColor(QColor(255, 0, 0));
|
289 |
|
pen.setColor(Qt::black);
|
290 |
|
}
|
291 |
|
}
|
292 |
|
else
|
293 |
|
{
|
294 |
|
if (m_type == QGis::Line)
|
295 |
|
{
|
296 |
|
pen.setColor(QColor(255 - (255 / numberofclassesspinbox->value() * (i+1)), 255 / numberofclassesspinbox->value() * (i+1), 0));
|
297 |
|
}
|
298 |
|
else //point or polygon
|
299 |
|
{
|
300 |
|
brush.setColor(QColor(255 - (255 / numberofclassesspinbox->value() * (i+1)), 255 / numberofclassesspinbox->value() * (i+1), 0));
|
301 |
|
pen.setColor(Qt::black);
|
302 |
|
}
|
303 |
|
}
|
|
307 |
// todo: These color ramps should come from a dropdown list
|
|
308 |
QString ramp;
|
|
309 |
ramp = "red_to_green";
|
|
310 |
|
|
311 |
if (m_type == QGis::Line)
|
|
312 |
{
|
|
313 |
pen.setColor(getColorFromRamp(ramp,i, numberofclassesspinbox->value()));
|
|
314 |
}
|
|
315 |
else //point or polygon
|
|
316 |
{
|
|
317 |
brush.setColor(getColorFromRamp(ramp,i, numberofclassesspinbox->value()));
|
|
318 |
pen.setColor(Qt::black);
|
|
319 |
}
|
|
320 |
|
304 |
321 |
pen.setWidth(1);
|
305 |
322 |
brush.setStyle(Qt::SolidPattern);
|
306 |
323 |
symbol->setPen(pen);
|