+ ruler_->update();
+ cursorheader_->update();
+ viewport_->update();
+ scale_offset_changed();
+}
+
+set< shared_ptr<SignalData> > View::get_visible_data() const
+{
+ shared_lock<shared_mutex> lock(session().signals_mutex());
+ const vector< shared_ptr<Signal> > &sigs(session().signals());
+
+ // Make a set of all the visible data objects
+ set< shared_ptr<SignalData> > visible_data;
+ for (const shared_ptr<Signal> sig : sigs)
+ if (sig->enabled())
+ visible_data.insert(sig->data());
+
+ return visible_data;
+}
+
+pair<double, double> View::get_time_extents() const
+{
+ const set< shared_ptr<SignalData> > visible_data = get_visible_data();
+ if (visible_data.empty())
+ return make_pair(0.0, 0.0);
+
+ double left_time = DBL_MAX, right_time = DBL_MIN;
+ for (const shared_ptr<SignalData> d : visible_data)
+ {
+ const double start_time = d->get_start_time();
+ double samplerate = d->samplerate();
+ samplerate = (samplerate <= 0.0) ? 1.0 : samplerate;
+
+ left_time = min(left_time, start_time);
+ right_time = max(right_time, start_time +
+ d->get_max_sample_count() / samplerate);
+ }
+
+ assert(left_time < right_time);
+ return make_pair(left_time, right_time);
+}
+
+bool View::cursors_shown() const
+{
+ return show_cursors_;
+}
+
+void View::show_cursors(bool show)
+{
+ show_cursors_ = show;
+ cursorheader_->update();
+ viewport_->update();
+}
+
+void View::centre_cursors()
+{
+ const double time_width = scale_ * viewport_->width();
+ cursors_.first()->set_time(offset_ + time_width * 0.4);
+ cursors_.second()->set_time(offset_ + time_width * 0.6);
+ cursorheader_->update();
+ viewport_->update();
+}
+
+CursorPair& View::cursors()
+{
+ return cursors_;
+}
+
+const CursorPair& View::cursors() const
+{
+ return cursors_;
+}
+
+const QPoint& View::hover_point() const
+{
+ return hover_point_;
+}
+
+void View::update_viewport()
+{
+ assert(viewport_);
+ viewport_->update();
+ header_->update();
+}
+
+void View::restack_all_row_items()
+{
+ // Make a set of owners
+ unordered_set< RowItemOwner* > owners;
+ for (const auto &r : *this)
+ owners.insert(r->owner());
+
+ // Make a list that is sorted from deepest first
+ vector< RowItemOwner* > sorted_owners(owners.begin(), owners.end());
+ sort(sorted_owners.begin(), sorted_owners.end(),
+ [](const RowItemOwner* a, const RowItemOwner *b) {
+ return a->depth() > b->depth(); });
+
+ // Restack the items recursively
+ for (auto &o : sorted_owners)
+ o->restack_items();
+
+ // Animate the items to their destination
+ for (const auto &r : *this)
+ r->animate_to_layout_v_offset();
+}
+
+void View::get_scroll_layout(double &length, double &offset) const
+{
+ const pair<double, double> extents = get_time_extents();
+ length = (extents.second - extents.first) / scale_;
+ offset = offset_ / scale_;
+}
+
+void View::set_zoom(double scale, int offset)
+{
+ const double cursor_offset = offset_ + scale_ * offset;
+ const double new_scale = max(min(scale, MaxScale), MinScale);
+ const double new_offset = cursor_offset - new_scale * offset;
+ set_scale_offset(new_scale, new_offset);
+}
+
+void View::calculate_tick_spacing()
+{
+ const double SpacingIncrement = 32.0f;
+ const double MinValueSpacing = 32.0f;
+
+ double min_width = SpacingIncrement, typical_width;
+
+ QFontMetrics m(QApplication::font());
+
+ do {
+ const double min_period = scale_ * min_width;
+
+ const int order = (int)floorf(log10f(min_period));
+ const double order_decimal = pow(10.0, order);
+
+ unsigned int unit = 0;
+
+ do {
+ tick_period_ = order_decimal * ScaleUnits[unit++];
+ } while (tick_period_ < min_period &&
+ unit < countof(ScaleUnits));
+
+ 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_)).width() +
+ MinValueSpacing;
+
+ min_width += SpacingIncrement;
+
+ } while(typical_width > tick_period_ / scale_);