X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fview%2Fview.cpp;h=42b22258dd59d2b0079ef6e1246b9382832e1166;hb=ef454ad5cf454ae2da91b45219e1be2e010d8312;hp=130d2d788cfaf862cbb2c83b03fbac8e48f7e4a0;hpb=c7b03d9daa9574bd633fbac2d5976716f58027f5;p=pulseview.git diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 130d2d7..42b2225 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -61,6 +61,7 @@ using boost::shared_mutex; using pv::data::SignalData; using pv::data::Segment; using pv::util::format_time; +using pv::util::TimeUnit; using std::deque; using std::dynamic_pointer_cast; @@ -86,7 +87,7 @@ const double View::MaxScale = 1e9; const double View::MinScale = 1e-15; const int View::MaxScrollValue = INT_MAX / 2; -const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz +const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz with sticky scrolling const int View::ScaleUnits[3] = {1, 2, 5}; @@ -100,8 +101,10 @@ View::View(Session &session, QWidget *parent) : offset_(0), updating_scroll_(false), sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui() + always_zoom_to_fit_(false), tick_period_(0.0), tick_prefix_(0), + time_unit_(util::Time), show_cursors_(false), cursors_(new CursorPair(*this)), next_flag_text_('A'), @@ -238,6 +241,11 @@ double View::tick_period() const return tick_period_; } +TimeUnit View::time_unit() const +{ + return time_unit_; +} + void View::zoom(double steps) { zoom(steps, viewport_->width() / 2); @@ -248,8 +256,17 @@ void View::zoom(double steps, int offset) set_zoom(scale_ * pow(3.0/2.0, -steps), offset); } -void View::zoom_fit() +void View::zoom_fit(bool gui_state) { + // Act as one-shot when stopped, toggle along with the GUI otherwise + if (session_.get_capture_state() == Session::Stopped) { + always_zoom_to_fit_ = false; + always_zoom_to_fit_changed(false); + } else { + always_zoom_to_fit_ = gui_state; + always_zoom_to_fit_changed(gui_state); + } + const pair extents = get_time_extents(); const double delta = extents.second - extents.first; if (delta < 1e-12) @@ -295,11 +312,20 @@ void View::zoom_one_to_one() void View::set_scale_offset(double scale, double offset) { - // Disable sticky scrolling when acquisition runs and user drags the viewport + // Disable sticky scrolling / always zoom to fit when acquisition runs + // and user drags the viewport if ((scale_ == scale) && (offset_ != offset) && - sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) { - sticky_scrolling_ = false; - sticky_scrolling_changed(false); + (session_.get_capture_state() == Session::Running)) { + + if (sticky_scrolling_) { + sticky_scrolling_ = false; + sticky_scrolling_changed(false); + } + + if (always_zoom_to_fit_) { + always_zoom_to_fit_ = false; + always_zoom_to_fit_changed(false); + } } scale_ = scale; @@ -449,6 +475,10 @@ void View::get_scroll_layout(double &length, double &offset) const void View::set_zoom(double scale, int offset) { + // Reset the "always zoom to fit" feature as the user changed the zoom + always_zoom_to_fit_ = false; + always_zoom_to_fit_changed(false); + 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; @@ -481,12 +511,12 @@ void View::calculate_tick_spacing() typical_width = m.boundingRect(0, 0, INT_MAX, INT_MAX, Qt::AlignLeft | Qt::AlignTop, - format_time(offset_, tick_prefix_)).width() + + format_time(offset_, tick_prefix_, time_unit_)).width() + MinValueSpacing; min_width += SpacingIncrement; - } while(typical_width > tick_period_ / scale_); + } while (typical_width > tick_period_ / scale_); } void View::update_scroll() @@ -615,6 +645,27 @@ vector< shared_ptr > View::extract_new_traces_for_channels( return filtered_traces; } +void View::determine_time_unit() +{ + time_unit_ = util::Samples; + + shared_lock lock(session().signals_mutex()); + const unordered_set< shared_ptr > &sigs(session().signals()); + + // Check all signals but... + for (const shared_ptr signal : sigs) { + const shared_ptr data = signal->data(); + + // ...only check first segment of each + const vector< shared_ptr > segments = data->segments(); + if (!segments.empty()) + if (segments[0]->samplerate()) { + time_unit_ = util::Time; + break; + } + } +} + bool View::eventFilter(QObject *object, QEvent *event) { const QEvent::Type type = event->type(); @@ -847,10 +898,17 @@ void View::signals_changed() void View::data_updated() { - if (sticky_scrolling_) { + // Reset "always zoom to fit" when we change to the stopped state + if (always_zoom_to_fit_ && (session_.get_capture_state() == Session::Stopped)) { + always_zoom_to_fit_ = false; + always_zoom_to_fit_changed(false); + } + + if (always_zoom_to_fit_ || sticky_scrolling_) { if (!delayed_view_updater_.isActive()) delayed_view_updater_.start(); } else { + determine_time_unit(); update_scroll(); ruler_->update(); viewport_->update(); @@ -859,6 +917,9 @@ void View::data_updated() void View::perform_delayed_view_update() { + if (always_zoom_to_fit_) + zoom_fit(true); + if (sticky_scrolling_) { // Make right side of the view sticky double length = 0, offset; @@ -870,6 +931,7 @@ void View::perform_delayed_view_update() offset_ = scale_ * length; } + determine_time_unit(); update_scroll(); ruler_->update(); viewport_->update();