X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fviews%2Ftrace%2Fview.cpp;h=227fadfdb4197c334d084dd9a19edb37e4728181;hb=6202cf13abc361af4d1419dc56eaabc314900692;hp=15e65127b2932062b46a5734575febf9d163631c;hpb=3d6ff1cd572a55e92779420c2d1a708cdb003fe0;p=pulseview.git diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 15e65127..227fadfd 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -31,11 +31,8 @@ #include #include -#include -#include -#include - #include +#include #include #include #include @@ -84,7 +81,6 @@ using std::pair; using std::set; using std::set_difference; using std::shared_ptr; -using std::stringstream; using std::unordered_map; using std::unordered_set; using std::vector; @@ -98,8 +94,10 @@ const Timestamp View::MinScale("1e-12"); const int View::MaxScrollValue = INT_MAX / 2; -const int View::ScaleUnits[3] = {1, 2, 5}; +/* Area at the top and bottom of the view that can't be scrolled out of sight */ +const int View::ViewScrollMargin = 50; +const int View::ScaleUnits[3] = {1, 2, 5}; CustomScrollArea::CustomScrollArea(QWidget *parent) : QAbstractScrollArea(parent) @@ -205,6 +203,7 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) : connect(&lazy_event_handler_, SIGNAL(timeout()), this, SLOT(process_sticky_events())); lazy_event_handler_.setSingleShot(true); + lazy_event_handler_.setInterval(1000 / ViewBase::MaxViewAutoUpdateRate); // Set up local keyboard shortcuts zoom_in_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Plus), this, @@ -276,6 +275,8 @@ void View::reset_view_state() scale_ = 1e-3; offset_ = 0; ruler_offset_ = 0; + zero_offset_ = 0; + custom_zero_offset_set_ = false; updating_scroll_ = false; settings_restored_ = false; always_zoom_to_fit_ = false; @@ -317,7 +318,7 @@ const Session& View::session() const return session_; } -unordered_set< shared_ptr > View::signals() const +vector< shared_ptr > View::signals() const { return signals_; } @@ -344,7 +345,7 @@ void View::clear_signals() void View::add_signal(const shared_ptr signal) { ViewBase::add_signalbase(signal->base()); - signals_.insert(signal); + signals_.push_back(signal); signal->set_segment_display_mode(segment_display_mode_); signal->set_current_segment(current_segment_); @@ -432,12 +433,12 @@ 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())); - } + GlobalSettings::store_timestamp(settings, "offset", offset_); + + if (custom_zero_offset_set_) + GlobalSettings::store_timestamp(settings, "zero_offset", -zero_offset_); + else + settings.remove("zero_offset"); for (const shared_ptr& signal : signals_) { settings.beginGroup(signal->base()->internal_name()); @@ -455,20 +456,13 @@ void View::restore_settings(QSettings &settings) set_scale(settings.value("scale").toDouble()); if (settings.contains("offset")) { - util::Timestamp offset; - stringstream ss; - ss << settings.value("offset").toString().toStdString(); - - try { - boost::archive::text_iarchive ia(ss); - ia >> boost::serialization::make_nvp("offset", offset); - // This also updates ruler_offset_ - set_offset(offset); - } catch (boost::archive::archive_exception&) { - qDebug() << "Could not restore the view offset"; - } + // This also updates ruler_offset_ + set_offset(GlobalSettings::restore_timestamp(settings, "offset")); } + if (settings.contains("zero_offset")) + set_zero_position(GlobalSettings::restore_timestamp(settings, "zero_offset")); + if (settings.contains("splitter_state")) splitter_->restoreState(settings.value("splitter_state").toByteArray()); @@ -548,6 +542,7 @@ const Timestamp& View::ruler_offset() const void View::set_zero_position(const pv::util::Timestamp& position) { zero_offset_ = -position; + custom_zero_offset_set_ = true; // Force an immediate update of the offsets set_offset(offset_, true); @@ -558,6 +553,19 @@ void View::reset_zero_position() { zero_offset_ = 0; + // 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) { + vector triggers = session_.get_triggers(current_segment_); + + if (triggers.size() > 0) + zero_offset_ = triggers.front(); + } + + custom_zero_offset_set_ = false; + // Force an immediate update of the offsets set_offset(offset_, true); ruler_->update(); @@ -676,12 +684,8 @@ void View::set_current_segment(uint32_t segment_id) 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()); + if (!custom_zero_offset_set_) + reset_zero_position(); viewport_->update(); @@ -807,13 +811,13 @@ void View::set_scale_offset(double scale, const Timestamp& offset) viewport_->update(); } -set< shared_ptr > View::get_visible_data() const +vector< shared_ptr > View::get_visible_data() const { // Make a set of all the visible data objects - set< shared_ptr > visible_data; + vector< shared_ptr > visible_data; for (const shared_ptr& sig : signals_) if (sig->enabled()) - visible_data.insert(sig->data()); + visible_data.push_back(sig->data()); return visible_data; } @@ -821,8 +825,14 @@ set< shared_ptr > View::get_visible_data() const pair View::get_time_extents() const { boost::optional left_time, right_time; - const set< shared_ptr > visible_data = get_visible_data(); - for (const shared_ptr& d : visible_data) { + + vector< shared_ptr > data; + if (signals_.size() == 0) + return make_pair(0, 0); + + data.push_back(signals_.front()->data()); + + for (const shared_ptr& d : data) { const vector< shared_ptr > segments = d->segments(); for (const shared_ptr& s : segments) { double samplerate = s->samplerate(); @@ -1088,15 +1098,8 @@ void View::trigger_event(int segment_id, util::Timestamp location) 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); + if (!custom_zero_offset_set_) + reset_zero_position(); trigger_markers_.push_back(make_shared(*this, location)); } @@ -1251,9 +1254,13 @@ void View::update_scroll() const pair extents = v_extents(); // Don't change the scrollbar range if there are no traces - if (extents.first != extents.second) - vscrollbar->setRange(extents.first - areaSize.height(), - extents.second); + if (extents.first != extents.second) { + int top_margin = ViewScrollMargin; + int btm_margin = ViewScrollMargin; + + vscrollbar->setRange(extents.first - areaSize.height() + top_margin, + extents.second - btm_margin); + } if (scroll_needs_defaults_) { set_scroll_default(); @@ -1553,8 +1560,8 @@ void View::extents_changed(bool horz, bool vert) (horz ? TraceTreeItemHExtentsChanged : 0) | (vert ? TraceTreeItemVExtentsChanged : 0); - lazy_event_handler_.stop(); - lazy_event_handler_.start(); + if (!lazy_event_handler_.isActive()) + lazy_event_handler_.start(); } void View::on_signal_name_changed() @@ -1831,7 +1838,8 @@ void View::capture_state_updated(int state) set_time_unit(util::TimeUnit::Samples); trigger_markers_.clear(); - set_zero_position(0); + if (!custom_zero_offset_set_) + set_zero_position(0); scale_at_acq_start_ = scale_; offset_at_acq_start_ = offset_; @@ -1914,12 +1922,9 @@ 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 + (void)new_value; + + if (!custom_zero_offset_set_) reset_zero_position(); }