@@ -275,32 +275,19 @@ void QgsGraduatedSymbolDialog::adjustClassification()
275
275
QPen pen;
276
276
QBrush brush;
277
277
278
- // 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
- }
278
+ // todo: These color ramps should come from a dropdown list
279
+ QString ramp;
280
+ ramp = " red_to_green" ;
281
+ if (m_type == QGis::Line)
282
+ {
283
+ pen.setColor (getColorFromRamp (ramp,i, numberofclassesspinbox->value ()));
284
+ }
285
+ else // point or polygon
286
+ {
287
+ brush.setColor (getColorFromRamp (ramp,i, numberofclassesspinbox->value ()));
288
+ pen.setColor (Qt::black);
289
+ }
290
+
304
291
pen.setWidth (1 );
305
292
brush.setStyle (Qt::SolidPattern);
306
293
symbol->setPen (pen);
@@ -520,4 +507,26 @@ int QgsGraduatedSymbolDialog::calculateQuantiles(std::list<double>& result, cons
520
507
}
521
508
522
509
523
-
510
+ QColor QgsGraduatedSymbolDialog::getColorFromRamp (QString ramp, int step, int totalSteps)
511
+ {
512
+ QColor color;
513
+ /* To do:
514
+ Grab the ramp by name from a file or ramp registry
515
+ and apply determine the color for the given step.
516
+ Ideally there would be two types of ramps:
517
+ - discrete colors: the number of steps would have to match totalSteps
518
+ - continuous colors: (eg grass or gmt ramps) would need to code a method
519
+ for determining an RGB color for any point along the continuum
520
+ Color ramps should be plugin-able; should be defined in a simple text file format
521
+ and read from a directory where users can add their own ramps.
522
+ */
523
+ if (step == 0 )
524
+ {
525
+ color = QColor (0 ,255 ,0 );
526
+ }
527
+ else
528
+ {
529
+ color = QColor (0 ,255 -((255 /totalSteps)*step+1 ),((255 /totalSteps)*step+1 ));
530
+ }
531
+ return color;
532
+ }
0 commit comments