Mercurial > hg > svgui
changeset 1258:0cc6ab236b0d scale-ticks
Make use of ScaleTickIntervals in linear numerical scale (not log yet)
author | Chris Cannam |
---|---|
date | Thu, 04 May 2017 10:24:23 +0100 |
parents | 14dcdc596baf |
children | 4d7e566092a7 |
files | layer/LinearNumericalScale.cpp |
diffstat | 1 files changed, 8 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/LinearNumericalScale.cpp Sun Mar 12 13:37:01 2017 +0000 +++ b/layer/LinearNumericalScale.cpp Thu May 04 10:24:23 2017 +0100 @@ -22,6 +22,8 @@ #include "LayerGeometryProvider.h" +#include "base/ScaleTickIntervals.h" + int LinearNumericalScale::getWidth(LayerGeometryProvider *, QPainter &paint) @@ -39,58 +41,33 @@ { int n = 10; - double val = minf; - double inc = (maxf - val) / n; - - const int buflen = 40; - char buffer[buflen]; + auto ticks = ScaleTickIntervals::linear({ minf, maxf, n }); int w = getWidth(v, paint) + x0; - double round = 1.0; - int dp = 0; - if (inc > 0) { - int prec = int(trunc(log10(inc))); - prec -= 1; - if (prec < 0) dp = -prec; - round = pow(10.0, prec); -#ifdef DEBUG_TIME_VALUE_LAYER - cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << endl; -#endif - } - int prevy = -1; - for (int i = 0; i < n; ++i) { + for (int i = 0; i < int(ticks.ticks.size()); ++i) { int y, ty; bool drawText = true; - double dispval = val; - if (i == n-1 && v->getPaintHeight() < paint.fontMetrics().height() * (n*2)) { if (layer->getScaleUnits() != "") drawText = false; } - dispval = int(rint(val / round) * round); -#ifdef DEBUG_TIME_VALUE_LAYER - cerr << "val = " << val << ", dispval = " << dispval << endl; -#endif - - y = layer->getYForValue(v, dispval); + double val = ticks.ticks[i].value; + QString label = QString::fromStdString(ticks.ticks[i].label); + + y = layer->getYForValue(v, val); ty = y - paint.fontMetrics().height() + paint.fontMetrics().ascent() + 2; if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) { - val += inc; continue; } - snprintf(buffer, buflen, "%.*f", dp, dispval); - - QString label = QString(buffer); - paint.drawLine(w - 5, y, w, y); if (drawText) { @@ -99,6 +76,5 @@ } prevy = y; - val += inc; } }