- const double minor_tick_period = tick_period / MinorTickSubdivision;
- const double first_major_division =
- floor(_view.offset() / tick_period);
- const double first_minor_division =
- ceil(_view.offset() / minor_tick_period);
- const double t0 = first_major_division * tick_period;
-
- int division = (int)round(first_minor_division -
- first_major_division * MinorTickSubdivision) - 1;
-
- const int major_tick_y1 = text_height + ValueMargin * 2;
- const int tick_y2 = height();
- const int minor_tick_y1 = (major_tick_y1 + tick_y2) / 2;
-
- double x;
-
- do {
- const double t = t0 + division * minor_tick_period;
- x = (t - _view.offset()) / _view.scale();
-
- if (division % MinorTickSubdivision == 0)
- {
- // Draw a major tick
- p.drawText(x, ValueMargin, 0, text_height,
- AlignCenter | AlignTop | TextDontClip,
- format_time(t, prefix));
- p.drawLine(QPointF(x, major_tick_y1),
- QPointF(x, tick_y2));
- }
- else
- {
- // Draw a minor tick
- p.drawLine(QPointF(x, minor_tick_y1),
- QPointF(x, tick_y2));
- }
-
- division++;
-
- } while (x < width());
+ for (const auto& tick: tick_position_cache_->major) {
+ p.drawText(tick.first, ValueMargin, 0, text_height,
+ AlignCenter | AlignTop | TextDontClip, tick.second);
+ p.drawLine(QPointF(tick.first, major_tick_y1),
+ QPointF(tick.first, ruler_height));
+ }