20 #include <QFontMetrics> 21 #include <QDataStream> 38 return QString(
"%1").arg(
m_makeOpposite ? -value : value, 0,
'f', decimalPlaces);
44 return QString(
"%1").arg(
m_makeOpposite ? -value : value, 0,
'f', decimalPlaces);
48 double actual = value *
m_scale;
49 double orig = fabs(actual);
53 tmp =
floor(actual / 86400.0);
54 str = QString(
"%1.").arg(tmp, 0,
'f', 0);
55 actual -= tmp * 86400.0;
61 tmp =
floor(actual / 3600.0);
62 str += QString(
"%1:").arg(tmp, 2,
'f', 0, QChar(
'0'));
63 actual -= tmp * 3600.0;
69 tmp =
floor(actual / 60.0);
70 str += QString(
"%1:").arg(tmp, 2,
'f', 0, QChar(
'0'));
77 str += QString(
"%1").arg(tmp, 2,
'f', decimalPlaces, QChar(
'0'));
85 QFontMetricsF fontMetrics(
m_font);
90 QString str(
"012345679.,-");
94 for(i = 0; i < str.length(); i++) {
95 size = fontMetrics.width(QString(str[i]));
105 double median, range, freqBase;
109 freqBase = (median == 0 ? range : median);
119 if(freqBase < 1000.0) {
121 }
else if(freqBase < 1000000.0) {
124 }
else if(freqBase < 1000000000.0) {
127 }
else if(freqBase < 1000000000000.0){
137 if(median < 1024.0) {
139 }
else if(median < 1048576.0) {
142 }
else if(median < 1073741824.0) {
145 }
else if(median < 1099511627776.0) {
148 }
else if(median < 1125899906842624.0) {
179 if (median < 0.001) {
182 }
else if (median < 1.0) {
185 }
else if (median < 1000.0) {
197 }
else if (median < 1e-6) {
200 }
else if (median < 1e-3) {
203 }
else if (median < 1.0) {
224 sign = (distance > 0.0) ? 1.0 : -1.0;
225 log10x = log10(fabs(distance));
226 exponent =
floor(log10x);
227 base = pow(10.0, log10x - exponent);
228 decimalPlaces = (int)(-exponent);
278 }
else if(base <= 2.0) {
280 }
else if(base <= 2.5) {
282 if(decimalPlaces >= 0)
284 }
else if(base <= 5.0) {
290 if(retDecimalPlaces != 0) {
291 if(decimalPlaces < 0)
293 *retDecimalPlaces = decimalPlaces;
296 return sign * base * pow(10.0, exponent);
315 return tickLen + decimalPlaces + 1;
321 QFontMetricsF fontMetrics(
m_font);
328 tick.
textSize = fontMetrics.boundingRect(tick.
text).width();
330 tick.
textPos = tick.
pos - fontMetrics.ascent() / 2;
331 else tick.
textPos = tick.
pos - fontMetrics.boundingRect(tick.
text).width() / 2;
336 tick.
textSize = fontMetrics.boundingRect(tick.
text).width();
338 tick.
textPos = tick.
pos - fontMetrics.ascent() / 2;
339 else tick.
textPos = tick.
pos - fontMetrics.boundingRect(tick.
text).width() / 2;
346 double rangeMinScaled;
347 double rangeMaxScaled;
348 int maxNumMajorTicks;
359 QFontMetricsF fontMetrics(
m_font);
376 maxNumMajorTicks = (int)(
m_size / (fontMetrics.lineSpacing() * 1.3f));
383 if(majorTickSize != 0.0) {
384 maxNumMajorTicks = (int)(
m_size / majorTickSize);
386 maxNumMajorTicks = 20;
394 if(numMajorTicks == 0) {
399 if(maxNumMajorTicks > 0)
416 if(rangeMinScaled == rangeMaxScaled)
423 lastEndPos = -100000000;
426 for(i = 0;
true; i++) {
431 if(value2 < rangeMinScaled)
433 if(value2 > rangeMaxScaled)
436 if((pos >= 0) && (pos <
m_size)) {
458 if(step % (skip + 1) != 0) {
467 tick.
textSize = fontMetrics.boundingRect(tick.
text).width();
469 tick.
textPos = pos - fontMetrics.ascent() / 2;
470 endPos = tick.
textPos + fontMetrics.ascent();
472 tick.
textPos = pos - fontMetrics.boundingRect(tick.
text).width() / 2;
476 if(lastEndPos >= tick.
textPos) {
497 if(numMajorTicks < 2)
570 tmpRangeMin = rangeMin;
571 tmpRangeMax = rangeMax;
Qt::Orientation m_orientation
double minorTickValue(int tick)
float getPosFromValue(double value)
QString formatTick(double value, int decimalPlaces)
Fixed< IntType, IntBits > floor(Fixed< IntType, IntBits > const &x)
double majorTickValue(int tick)
float getValueFromPos(double pos)
double m_majorTickValueDistance
void setFont(const QFont &font)
double m_firstMajorTickValue
const TickList & getTickList()
void setRange(Unit::Physical physicalUnit, float rangeMin, float rangeMax)
Unit::Physical m_physicalUnit
double calcMajorTickUnits(double distance, int *retDecimalPlaces)
int calcTickTextSize(double distance)
void setOrientation(Qt::Orientation orientation)
T max(const T &x, const T &y)