comparison layer/LogNumericalScale.cpp @ 946:36cddc3de023 alignment_view

Merge from default branch
author Chris Cannam
date Mon, 20 Apr 2015 09:19:52 +0100
parents b66fb15de477
children 4fe7a09be0fe
comparison
equal deleted inserted replaced
897:499b637f2a26 946:36cddc3de023
36 void 36 void
37 LogNumericalScale::paintVertical(View *v, 37 LogNumericalScale::paintVertical(View *v,
38 const VerticalScaleLayer *layer, 38 const VerticalScaleLayer *layer,
39 QPainter &paint, 39 QPainter &paint,
40 int x0, 40 int x0,
41 float minlog, 41 double minlog,
42 float maxlog) 42 double maxlog)
43 { 43 {
44 int w = getWidth(v, paint) + x0; 44 int w = getWidth(v, paint) + x0;
45 45
46 int n = 10; 46 int n = 10;
47 47
48 float val = minlog; 48 double val = minlog;
49 float inc = (maxlog - val) / n; // even increments of log scale 49 double inc = (maxlog - val) / n; // even increments of log scale
50 50
51 // smallest increment as displayed 51 // smallest increment as displayed
52 float minDispInc = LogRange::unmap(minlog + inc) - LogRange::unmap(minlog); 52 double minDispInc = LogRange::unmap(minlog + inc) - LogRange::unmap(minlog);
53 53
54 #ifdef DEBUG_TIME_VALUE_LAYER 54 #ifdef DEBUG_TIME_VALUE_LAYER
55 cerr << "min = " << minlog << ", max = " << maxlog << ", inc = " << inc << ", minDispInc = " << minDispInc << endl; 55 cerr << "min = " << minlog << ", max = " << maxlog << ", inc = " << inc << ", minDispInc = " << minDispInc << endl;
56 #endif 56 #endif
57 57
58 const int buflen = 40; 58 const int buflen = 40;
59 char buffer[buflen]; 59 char buffer[buflen];
60 60
61 float round = 1.f; 61 double round = 1.f;
62 int dp = 0; 62 int dp = 0;
63 63
64 if (minDispInc > 0) { 64 if (minDispInc > 0) {
65 int prec = trunc(log10f(minDispInc)); 65 int prec = int(trunc(log10(minDispInc)));
66 if (prec < 0) dp = -prec; 66 if (prec < 0) dp = -prec;
67 round = powf(10.f, prec); 67 round = pow(10.0, prec);
68 if (dp > 4) dp = 4; 68 if (dp > 4) dp = 4;
69 #ifdef DEBUG_TIME_VALUE_LAYER 69 #ifdef DEBUG_TIME_VALUE_LAYER
70 cerr << "round = " << round << ", prec = " << prec << ", dp = " << dp << endl; 70 cerr << "round = " << round << ", prec = " << prec << ", dp = " << dp << endl;
71 #endif 71 #endif
72 } 72 }
81 if (i == n-1 && 81 if (i == n-1 &&
82 v->height() < paint.fontMetrics().height() * (n*2)) { 82 v->height() < paint.fontMetrics().height() * (n*2)) {
83 if (layer->getScaleUnits() != "") drawText = false; 83 if (layer->getScaleUnits() != "") drawText = false;
84 } 84 }
85 85
86 float dispval = LogRange::unmap(val); 86 double dispval = LogRange::unmap(val);
87 dispval = floor(dispval / round) * round; 87 dispval = floor(dispval / round) * round;
88 88
89 #ifdef DEBUG_TIME_VALUE_LAYER 89 #ifdef DEBUG_TIME_VALUE_LAYER
90 cerr << "val = " << val << ", dispval = " << dispval << endl; 90 cerr << "val = " << val << ", dispval = " << dispval << endl;
91 #endif 91 #endif
97 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) { 97 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) {
98 val += inc; 98 val += inc;
99 continue; 99 continue;
100 } 100 }
101 101
102 int digits = trunc(log10f(dispval)); 102 int digits = int(trunc(log10(dispval)));
103 int sf = dp + (digits > 0 ? digits : 0); 103 int sf = dp + (digits > 0 ? digits : 0);
104 if (sf < 4) sf = 4; 104 if (sf < 4) sf = 4;
105 #ifdef DEBUG_TIME_VALUE_LAYER 105 #ifdef DEBUG_TIME_VALUE_LAYER
106 cerr << "sf = " << sf << endl; 106 cerr << "sf = " << sf << endl;
107 #endif 107 #endif