comparison layer/LinearNumericalScale.cpp @ 944:78c152e4db95

Merge from branch tonioni
author Chris Cannam
date Mon, 20 Apr 2015 09:12:17 +0100
parents b66fb15de477
children 4fe7a09be0fe
comparison
equal deleted inserted replaced
896:78e041e45ff0 944:78c152e4db95
32 void 32 void
33 LinearNumericalScale::paintVertical(View *v, 33 LinearNumericalScale::paintVertical(View *v,
34 const VerticalScaleLayer *layer, 34 const VerticalScaleLayer *layer,
35 QPainter &paint, 35 QPainter &paint,
36 int x0, 36 int x0,
37 float minf, 37 double minf,
38 float maxf) 38 double maxf)
39 { 39 {
40 int n = 10; 40 int n = 10;
41 41
42 float val = minf; 42 double val = minf;
43 float inc = (maxf - val) / n; 43 double inc = (maxf - val) / n;
44 44
45 const int buflen = 40; 45 const int buflen = 40;
46 char buffer[buflen]; 46 char buffer[buflen];
47 47
48 int w = getWidth(v, paint) + x0; 48 int w = getWidth(v, paint) + x0;
49 49
50 float round = 1.f; 50 double round = 1.0;
51 int dp = 0; 51 int dp = 0;
52 if (inc > 0) { 52 if (inc > 0) {
53 int prec = trunc(log10f(inc)); 53 int prec = int(trunc(log10(inc)));
54 prec -= 1; 54 prec -= 1;
55 if (prec < 0) dp = -prec; 55 if (prec < 0) dp = -prec;
56 round = powf(10.f, prec); 56 round = pow(10.0, prec);
57 #ifdef DEBUG_TIME_VALUE_LAYER 57 #ifdef DEBUG_TIME_VALUE_LAYER
58 cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << endl; 58 cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << endl;
59 #endif 59 #endif
60 } 60 }
61 61
64 for (int i = 0; i < n; ++i) { 64 for (int i = 0; i < n; ++i) {
65 65
66 int y, ty; 66 int y, ty;
67 bool drawText = true; 67 bool drawText = true;
68 68
69 float dispval = val; 69 double dispval = val;
70 70
71 if (i == n-1 && 71 if (i == n-1 &&
72 v->height() < paint.fontMetrics().height() * (n*2)) { 72 v->height() < paint.fontMetrics().height() * (n*2)) {
73 if (layer->getScaleUnits() != "") drawText = false; 73 if (layer->getScaleUnits() != "") drawText = false;
74 } 74 }
75 dispval = lrintf(val / round) * round; 75 dispval = int(rint(val / round) * round);
76 76
77 #ifdef DEBUG_TIME_VALUE_LAYER 77 #ifdef DEBUG_TIME_VALUE_LAYER
78 cerr << "val = " << val << ", dispval = " << dispval << endl; 78 cerr << "val = " << val << ", dispval = " << dispval << endl;
79 #endif 79 #endif
80 80