X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fviews%2Ftrace%2Fdecodetrace.cpp;h=509e77f6224b5dacbd9514d47f48b245f47a6c08;hp=a4628eab9fbfdac55c9125e765f5c6cc0976ebcd;hb=eee3eab96253315b2a3dc04ffa7051a8ec963c32;hpb=ff83d98059f06ac8f57be080ab53e7095aa4748b diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index a4628eab..509e77f6 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -54,18 +54,13 @@ extern "C" { #include using std::all_of; -using std::list; using std::make_pair; using std::max; -using std::make_pair; -using std::map; using std::min; using std::out_of_range; using std::pair; using std::shared_ptr; -using std::make_shared; using std::tie; -using std::unordered_set; using std::vector; using pv::data::decode::Annotation; @@ -92,6 +87,8 @@ const double DecodeTrace::EndCapWidth = 5; const int DecodeTrace::RowTitleMargin = 10; const int DecodeTrace::DrawPadding = 100; +const int DecodeTrace::MaxTraceUpdateRate = 1; // No more than 1 Hz + const QColor DecodeTrace::Colours[16] = { QColor(0xEF, 0x29, 0x29), QColor(0xF6, 0x6A, 0x32), @@ -149,6 +146,10 @@ DecodeTrace::DecodeTrace(pv::Session &session, connect(decode_signal_.get(), SIGNAL(new_annotations()), this, SLOT(on_new_annotations())); + connect(decode_signal_.get(), SIGNAL(decode_reset()), + this, SLOT(on_decode_reset())); + connect(decode_signal_.get(), SIGNAL(decode_finished()), + this, SLOT(on_decode_finished())); connect(decode_signal_.get(), SIGNAL(channels_updated()), this, SLOT(on_channels_updated())); @@ -156,6 +157,11 @@ DecodeTrace::DecodeTrace(pv::Session &session, this, SLOT(on_delete_decoder(int))); connect(&show_hide_mapper_, SIGNAL(mapped(int)), this, SLOT(on_show_hide_decoder(int))); + + connect(&delayed_trace_updater_, SIGNAL(timeout()), + this, SLOT(on_delayed_trace_update())); + delayed_trace_updater_.setSingleShot(true); + delayed_trace_updater_.setInterval(1000 / MaxTraceUpdateRate); } bool DecodeTrace::enabled() const @@ -244,11 +250,13 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp) // Draw the hatching draw_unresolved_period(p, annotation_height, pp.left(), pp.right()); - if ((int)visible_rows_.size() > max_visible_rows_) - owner_->extents_changed(false, true); + if ((int)visible_rows_.size() > max_visible_rows_) { + max_visible_rows_ = (int)visible_rows_.size(); - // Update the maximum row count if needed - max_visible_rows_ = max(max_visible_rows_, (int)visible_rows_.size()); + // Call order is important, otherwise the lazy event handler won't work + owner_->extents_changed(false, true); + owner_->row_item_appearance_changed(false, true); + } } void DecodeTrace::paint_fore(QPainter &p, ViewItemPaintParams &pp) @@ -304,8 +312,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form) init_state_map_.clear(); decoder_forms_.clear(); - const list< shared_ptr > &stack = - decode_signal_->decoder_stack_list(); + const vector< shared_ptr > &stack = decode_signal_->decoder_stack(); if (stack.empty()) { QLabel *const l = new QLabel( @@ -600,11 +607,11 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, int right double samples_per_pixel, pixels_offset; - const int64_t sample_count = decode_signal_->sample_count(); + const int64_t sample_count = decode_signal_->get_working_sample_count(); if (sample_count == 0) return; - const int64_t samples_decoded = decode_signal_->samples_decoded(); + const int64_t samples_decoded = decode_signal_->get_decoded_sample_count(); if (sample_count == samples_decoded) return; @@ -705,14 +712,18 @@ const QString DecodeTrace::get_annotation_at_point(const QPoint &point) QString() : annotations[0].annotations().front(); } -void DecodeTrace::hover_point_changed() +void DecodeTrace::hover_point_changed(const QPoint &hp) { assert(owner_); const View *const view = owner_->view(); assert(view); - QPoint hp = view->hover_point(); + if (hp.x() == 0) { + QToolTip::hideText(); + return; + } + QString ann = get_annotation_at_point(hp); assert(view); @@ -735,13 +746,14 @@ void DecodeTrace::hover_point_changed() // If it did, the tool tip would constantly hide and re-appear. // We also push it up by one row so that it appears above the // decode trace, not below. - hp.setX(hp.x() - (text_size.width() / 2) - padding); + QPoint p = hp; + p.setX(hp.x() - (text_size.width() / 2) - padding); - hp.setY(get_visual_y() - (row_height_ / 2) + + p.setY(get_visual_y() - (row_height_ / 2) + (hover_row * row_height_) - row_height_ - text_size.height() - padding); - QToolTip::showText(view->viewport()->mapToGlobal(hp), ann); + QToolTip::showText(view->viewport()->mapToGlobal(p), ann); } void DecodeTrace::create_decoder_form(int index, @@ -776,7 +788,7 @@ void DecodeTrace::create_decoder_form(int index, QFormLayout *const decoder_form = new QFormLayout; group->add_layout(decoder_form); - const list channels = decode_signal_->get_channels(); + const vector channels = decode_signal_->get_channels(); // Add the channels for (DecodeChannel ch : channels) { @@ -807,11 +819,9 @@ void DecodeTrace::create_decoder_form(int index, .arg(ch.name, ch.desc, required_flag), hlayout); } - shared_ptr decoder_stack = base_->decoder_stack(); - // Add the options shared_ptr binding( - new binding::Decoder(decoder_stack, dec)); + new binding::Decoder(decode_signal_, dec)); binding->add_properties_to_form(decoder_form, true); bindings_.push_back(binding); @@ -870,6 +880,27 @@ QComboBox* DecodeTrace::create_channel_selector_init_state(QWidget *parent, } void DecodeTrace::on_new_annotations() +{ + if (!delayed_trace_updater_.isActive()) + delayed_trace_updater_.start(); +} + +void DecodeTrace::on_delayed_trace_update() +{ + if (owner_) + owner_->row_item_appearance_changed(false, true); +} + +void DecodeTrace::on_decode_reset() +{ + visible_rows_.clear(); + max_visible_rows_ = 0; + + if (owner_) + owner_->row_item_appearance_changed(false, true); +} + +void DecodeTrace::on_decode_finished() { if (owner_) owner_->row_item_appearance_changed(false, true); @@ -929,6 +960,10 @@ void DecodeTrace::on_delete_decoder(int index) { decode_signal_->remove_decoder(index); + // Force re-calculation of the trace height, see paint_mid() + max_visible_rows_ = 0; + owner_->extents_changed(false, true); + // Update the popup create_popup_form(); } @@ -940,6 +975,12 @@ void DecodeTrace::on_show_hide_decoder(int index) assert(index < (int)decoder_forms_.size()); decoder_forms_[index]->set_decoder_visible(state); + if (!state) { + // Force re-calculation of the trace height, see paint_mid() + max_visible_rows_ = 0; + owner_->extents_changed(false, true); + } + if (owner_) owner_->row_item_appearance_changed(false, true); }