From: Cenkron Date: Wed, 10 Jan 2018 15:10:58 +0000 (-0600) Subject: Change the number of minor ticks to be either 4 or 5 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4a07615736968fc8d635c8d187b8a5d6b8a0e2eb;p=pulseview.git Change the number of minor ticks to be either 4 or 5 Depends on the current tick interval size, in the sense of the 1, 2, 5 sequence. It was originally always 4. --- diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index fe08cb06..0c2b6592 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -37,7 +37,6 @@ namespace views { namespace trace { const float Ruler::RulerHeight = 2.5f; // x Text Height -const int Ruler::MinorTickSubdivision = 4; const float Ruler::HoverArrowSize = 0.5f; // x Text Height @@ -143,6 +142,7 @@ void Ruler::paintEvent(QPaintEvent*) view_.ruler_offset(), view_.scale(), width(), + view_.minor_tick_count(), ffunc); } @@ -194,17 +194,18 @@ Ruler::TickPositions Ruler::calculate_tick_positions( const pv::util::Timestamp& offset, const double scale, const int width, + const unsigned int minor_tick_count, function format_function) { TickPositions tp; - const pv::util::Timestamp minor_period = major_period / MinorTickSubdivision; + const pv::util::Timestamp minor_period = major_period / minor_tick_count; const pv::util::Timestamp first_major_division = floor(offset / major_period); const pv::util::Timestamp first_minor_division = ceil(offset / minor_period); const pv::util::Timestamp t0 = first_major_division * major_period; int division = (round(first_minor_division - - first_major_division * MinorTickSubdivision)).convert_to() - 1; + first_major_division * minor_tick_count)).convert_to() - 1; double x; @@ -212,9 +213,9 @@ Ruler::TickPositions Ruler::calculate_tick_positions( pv::util::Timestamp t = t0 + division * minor_period; x = ((t - offset) / scale).convert_to(); - if (division % MinorTickSubdivision == 0) { + if (division % minor_tick_count == 0) { // Recalculate 't' without using 'minor_period' which is a fraction - t = t0 + division / MinorTickSubdivision * major_period; + t = t0 + division / minor_tick_count * major_period; tp.major.emplace_back(x, format_function(t)); } else { tp.minor.emplace_back(x); diff --git a/pv/views/trace/ruler.hpp b/pv/views/trace/ruler.hpp index 0c614c6c..448204b2 100644 --- a/pv/views/trace/ruler.hpp +++ b/pv/views/trace/ruler.hpp @@ -63,8 +63,6 @@ private: /// Height of the ruler in multipes of the text height static const float RulerHeight; - static const int MinorTickSubdivision; - /// Height of the hover arrow in multiples of the text height static const float HoverArrowSize; @@ -170,6 +168,7 @@ private: const pv::util::Timestamp& offset, const double scale, const int width, + const unsigned int minor_tick_count, function format_function); protected: diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 292933e7..9cd90be8 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -506,6 +506,11 @@ const pv::util::Timestamp& View::tick_period() const return tick_period_; } +unsigned int View::minor_tick_count() const +{ + return minor_tick_count_; +} + void View::set_tick_period(const pv::util::Timestamp& tick_period) { if (tick_period_ != tick_period) { @@ -896,6 +901,7 @@ void View::calculate_tick_spacing() (ScaleUnits[unit++] + tp_margin); } while (tp_with_margin < min_period && unit < countof(ScaleUnits)); + minor_tick_count_ = (unit == 2) ? (4) : (5); tick_period = order_decimal * ScaleUnits[unit - 1]; tick_prefix = static_cast( (order - pv::util::exponent(pv::util::SIPrefix::yocto)) / 3); diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 28c94e52..45149897 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -187,6 +187,11 @@ public: */ const pv::util::Timestamp& tick_period() const; + /** + * Returns number of minor division ticks per time marking. + */ + unsigned int minor_tick_count() const; + /** * Returns the unit of time currently used. */ @@ -479,6 +484,7 @@ private: pv::util::Timestamp tick_period_; pv::util::SIPrefix tick_prefix_; + unsigned int minor_tick_count_; unsigned int tick_precision_; util::TimeUnit time_unit_;