X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fviews%2Ftrace%2Fview.cpp;h=35b6807dfc75c11ba825831c1552ee17fe490f5a;hp=156b3eef30276515ebbb59880cffbf3e9a37ccf1;hb=451dc5f33fbc4f559881acdf338c476a976fcbf2;hpb=89914a8657612761ff962ee973721a4872cda8d7 diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 156b3eef..35b6807d 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -79,6 +79,7 @@ using std::make_pair; using std::make_shared; using std::min; using std::pair; +using std::placeholders::_1; using std::set; using std::set_difference; using std::shared_ptr; @@ -129,6 +130,7 @@ View::View(Session &session, bool is_main_view, QWidget *parent) : segment_selectable_(false), scale_(1e-3), offset_(0), + ruler_offset_(0), updating_scroll_(false), settings_restored_(false), header_was_shrunk_(false), @@ -197,6 +199,9 @@ View::View(Session &session, bool is_main_view, QWidget *parent) : GlobalSettings settings; coloured_bg_ = settings.value(GlobalSettings::Key_View_ColouredBG).toBool(); + GlobalSettings::register_change_handler(GlobalSettings::Key_View_TriggerIsZeroTime, + bind(&View::on_settingViewTriggerIsZeroTime_changed, this, _1)); + connect(scrollarea_->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(h_scroll_value_changed(int))); connect(scrollarea_->verticalScrollBar(), SIGNAL(valueChanged(int)), @@ -326,10 +331,18 @@ void View::save_settings(QSettings &settings) const settings.setValue("splitter_state", splitter_->saveState()); settings.setValue("segment_display_mode", segment_display_mode_); - stringstream ss; - boost::archive::text_oarchive oa(ss); - oa << boost::serialization::make_nvp("offset", offset_); - settings.setValue("offset", QString::fromStdString(ss.str())); + { + stringstream ss; + boost::archive::text_oarchive oa(ss); + oa << boost::serialization::make_nvp("ruler_shift", ruler_shift_); + settings.setValue("ruler_shift", QString::fromStdString(ss.str())); + } + { + stringstream ss; + boost::archive::text_oarchive oa(ss); + oa << boost::serialization::make_nvp("offset", offset_); + settings.setValue("offset", QString::fromStdString(ss.str())); + } for (shared_ptr signal : signals_) { settings.beginGroup(signal->base()->internal_name()); @@ -346,6 +359,17 @@ void View::restore_settings(QSettings &settings) if (settings.contains("scale")) set_scale(settings.value("scale").toDouble()); + if (settings.contains("ruler_shift")) { + util::Timestamp shift; + stringstream ss; + ss << settings.value("ruler_shift").toString().toStdString(); + + boost::archive::text_iarchive ia(ss); + ia >> boost::serialization::make_nvp("ruler_shift", shift); + + ruler_shift_ = shift; + } + if (settings.contains("offset")) { util::Timestamp offset; stringstream ss; @@ -354,6 +378,7 @@ void View::restore_settings(QSettings &settings) boost::archive::text_iarchive ia(ss); ia >> boost::serialization::make_nvp("offset", offset); + // This also updates ruler_offset_ set_offset(offset); } @@ -411,17 +436,41 @@ void View::set_scale(double scale) } } +void View::set_offset(const pv::util::Timestamp& offset, bool force_update) +{ + if ((offset_ != offset) || force_update) { + offset_ = offset; + ruler_offset_ = offset_ + ruler_shift_; + offset_changed(); + } +} + const Timestamp& View::offset() const { return offset_; } -void View::set_offset(const pv::util::Timestamp& offset) +const Timestamp& View::ruler_offset() const { - if (offset_ != offset) { - offset_ = offset; - offset_changed(); - } + return ruler_offset_; +} + +void View::set_zero_position(pv::util::Timestamp& position) +{ + ruler_shift_ = -position; + + // Force an immediate update of the offsets + set_offset(offset_, true); + ruler_->update(); +} + +void View::reset_zero_position() +{ + ruler_shift_ = 0; + + // Force an immediate update of the offsets + set_offset(offset_, true); + ruler_->update(); } int View::owner_visual_v_offset() const @@ -477,6 +526,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) { @@ -507,6 +561,19 @@ void View::set_current_segment(uint32_t segment_id) for (shared_ptr dt : decode_traces_) dt->set_current_segment(current_segment_); + vector triggers = session_.get_triggers(current_segment_); + + trigger_markers_.clear(); + for (util::Timestamp timestamp : triggers) + trigger_markers_.push_back(make_shared(*this, timestamp)); + + // When enabled, the first trigger for this segment is used as the zero position + GlobalSettings settings; + bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool(); + + if (trigger_is_zero_time && (triggers.size() > 0)) + set_zero_position(triggers.front()); + viewport_->update(); segment_changed(segment_id); @@ -524,6 +591,8 @@ Trace::SegmentDisplayMode View::segment_display_mode() const void View::set_segment_display_mode(Trace::SegmentDisplayMode mode) { + trigger_markers_.clear(); + segment_display_mode_ = mode; for (shared_ptr signal : signals_) @@ -792,8 +861,22 @@ void View::restack_all_trace_tree_items() i->animate_to_layout_v_offset(); } -void View::trigger_event(util::Timestamp location) +void View::trigger_event(int segment_id, util::Timestamp location) { + // TODO This doesn't work if we're showing multiple segments at once + if ((uint32_t)segment_id != current_segment_) + return; + + // Set zero location if the Key_View_TriggerIsZeroTime setting is set and + // if this is the first trigger for this segment. + GlobalSettings settings; + bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool(); + + size_t trigger_count = session_.get_triggers(current_segment_).size(); + + if (trigger_is_zero_time && trigger_count == 1) + set_zero_position(location); + trigger_markers_.push_back(make_shared(*this, location)); } @@ -858,6 +941,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); @@ -1509,6 +1593,17 @@ void View::on_segment_changed(int segment) } } +void View::on_settingViewTriggerIsZeroTime_changed(const QVariant new_value) +{ + if (new_value.toBool()) { + // The first trigger for this segment is used as the zero position + vector triggers = session_.get_triggers(current_segment_); + if (triggers.size() > 0) + set_zero_position(triggers.front()); + } else + reset_zero_position(); +} + void View::perform_delayed_view_update() { if (always_zoom_to_fit_) {