From: Soeren Apel Date: Sat, 15 Aug 2015 21:05:18 +0000 (+0200) Subject: View: Use max time to calculate label length, not offset_ X-Git-Tag: pulseview-0.3.0~143 X-Git-Url: http://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=1e124d4b75b7b6b6a87b93a4e175d669909c2e04 View: Use max time to calculate label length, not offset_ Using offset_ gives false results, in particular when offset_ happens to be 0. With this fix, realistic values are used for the label length calculation. --- diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 032546db..e6be30e0 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -496,6 +496,11 @@ void View::calculate_tick_spacing() const double SpacingIncrement = 32.0f; const double MinValueSpacing = 32.0f; + // Figure out the highest numeric value visible on a label + const QSize areaSize = viewport_->size(); + const double max_time = max(fabs(offset_), + fabs(offset_ + scale_ * areaSize.width())); + double min_width = SpacingIncrement; double label_width, tick_period_width; @@ -523,7 +528,7 @@ void View::calculate_tick_spacing() tick_period_width = tick_period_ / scale_; const QString label_text = - format_time(offset_, tick_prefix_, time_unit_, tick_precision_); + format_time(max_time, tick_prefix_, time_unit_, tick_precision_); label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX, Qt::AlignLeft | Qt::AlignTop, label_text).width() +