p.setRenderHint(QPainter::Antialiasing);
const double tick_period = view_.tick_period();
- const unsigned int prefix = view_.tick_prefix();
// Draw the tick marks
p.setPen(palette().color(foregroundRole()));
// Draw a major tick
p.drawText(x, ValueMargin, 0, text_height,
AlignCenter | AlignTop | TextDontClip,
- util::format_time(t, prefix, view_.time_unit()));
+ util::format_time(t, view_.tick_prefix(), view_.time_unit(),
+ view_.tick_precision()));
p.drawLine(QPointF(x, major_tick_y1),
QPointF(x, ruler_height));
}
always_zoom_to_fit_(false),
tick_period_(0.0),
tick_prefix_(0),
+ tick_precision_(0),
time_unit_(util::Time),
show_cursors_(false),
cursors_(new CursorPair(*this)),
return tick_prefix_;
}
+unsigned int View::tick_precision() const
+{
+ return tick_precision_;
+}
+
double View::tick_period() const
{
return tick_period_;
const double SpacingIncrement = 32.0f;
const double MinValueSpacing = 32.0f;
- double min_width = SpacingIncrement, typical_width;
+ double min_width = SpacingIncrement;
+ double label_width, tick_period_width;
QFontMetrics m(QApplication::font());
tick_prefix_ = (order - pv::util::FirstSIPrefixPower) / 3;
- typical_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
- Qt::AlignLeft | Qt::AlignTop,
- format_time(offset_, tick_prefix_, time_unit_)).width() +
+ // Precision is the number of fractional digits required, not
+ // taking the prefix into account (and it must never be negative)
+ tick_precision_ = std::max((int)ceil(log10f(1 / tick_period_)), 0);
+
+ tick_period_width = tick_period_ / scale_;
+
+ const QString label_text =
+ format_time(offset_, tick_prefix_, time_unit_, tick_precision_);
+
+ label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
+ Qt::AlignLeft | Qt::AlignTop, label_text).width() +
MinValueSpacing;
min_width += SpacingIncrement;
- } while (typical_width > tick_period_ / scale_);
+ } while (tick_period_width < label_width);
}
void View::update_scroll()
*/
unsigned int tick_prefix() const;
+ /**
+ * Returns the number of fractional digits shown for the time markings.
+ */
+ unsigned int tick_precision() const;
+
/**
* Returns period of the graticule time markings.
*/
double tick_period_;
unsigned int tick_prefix_;
+ unsigned int tick_precision_;
util::TimeUnit time_unit_;
bool show_cursors_;