Skip to content

Commit 2b87168

Browse files
author
mhugent
committedOct 25, 2007
apply patch #782 from perrygeo that moves code for determination of color into its own function
git-svn-id: http://svn.osgeo.org/qgis/trunk@7300 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 44493e2 commit 2b87168

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed
 

‎src/app/qgsgraduatedsymboldialog.cpp

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -275,32 +275,19 @@ void QgsGraduatedSymbolDialog::adjustClassification()
275275
QPen pen;
276276
QBrush brush;
277277

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+
304291
pen.setWidth(1);
305292
brush.setStyle(Qt::SolidPattern);
306293
symbol->setPen(pen);
@@ -520,4 +507,26 @@ int QgsGraduatedSymbolDialog::calculateQuantiles(std::list<double>& result, cons
520507
}
521508

522509

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+
}

‎src/app/qgsgraduatedsymboldialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class QgsGraduatedSymbolDialog: public QDialog, private Ui::QgsGraduatedSymbolDi
6767
@param numQuantiles the number of quantiles, e.g. 4 calculates the quantiles for 25%, 50%, 75%, 100%
6868
@return 0 in case of success*/
6969
int calculateQuantiles(std::list<double>& result, const std::vector<double>& values, int numQuantiles) const;
70+
/**Gets the color value along a specified ramp**/
71+
QColor getColorFromRamp(QString ramp, int step, int totalSteps);
7072

7173
protected slots:
7274
/**Removes a class from the classification*/

0 commit comments

Comments
 (0)
Please sign in to comment.