From: Soeren Apel Date: Sun, 24 May 2020 21:03:27 +0000 (+0200) Subject: Fix MetadataObjMainViewRange handling when main view is resized X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5a5d3b1de81417f64b58e80cc359dcfde0d3a10c;p=pulseview.git Fix MetadataObjMainViewRange handling when main view is resized --- diff --git a/pv/views/tabular_decoder/view.cpp b/pv/views/tabular_decoder/view.cpp index 3c916f4d..14ae50a2 100644 --- a/pv/views/tabular_decoder/view.cpp +++ b/pv/views/tabular_decoder/view.cpp @@ -529,7 +529,8 @@ void View::on_new_annotations() { if (view_mode_selector_->currentIndex() == ViewModeLatest) { update_data(); - table_view_->scrollTo(model_->index(model_->rowCount() - 1, 0), + table_view_->scrollTo( + filter_proxy_model_->index(filter_proxy_model_->rowCount() - 1, 0), QAbstractItemView::PositionAtBottom); } else { if (!delayed_view_updater_.isActive()) diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index df589675..43853359 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -578,6 +578,9 @@ void View::set_scale(double scale) { if (scale_ != scale) { scale_ = scale; + + update_view_range_metaobject(); + scale_changed(); } } @@ -588,20 +591,7 @@ void View::set_offset(const pv::util::Timestamp& offset, bool force_update) offset_ = offset; ruler_offset_ = offset_ + zero_offset_; - const int w = viewport_->width(); - if (w > 0) { - const double samplerate = session_.get_samplerate(); - // Note: sample_num = time * samplerate - // Note: samples_per_pixel = samplerate * scale - int64_t start_sample = (offset_ * samplerate).convert_to(); - int64_t end_sample = (offset_ * samplerate).convert_to() + - (w * session_.get_samplerate() * scale_); - - MetadataObject* md_obj = - session_.metadata_obj_manager()->find_object_by_type(MetadataObjMainViewRange); - md_obj->set_value(MetadataValueStartSample, QVariant((qlonglong)start_sample)); - md_obj->set_value(MetadataValueEndSample, QVariant((qlonglong)end_sample)); - } + update_view_range_metaobject(); offset_changed(); } @@ -1427,6 +1417,8 @@ void View::resize_header_to_fit() void View::update_layout() { update_scroll(); + + update_view_range_metaobject(); } TraceTreeItemOwner* View::find_prevalent_trace_group( @@ -1604,6 +1596,31 @@ void View::resizeEvent(QResizeEvent* event) update_layout(); } +void View::update_view_range_metaobject() const +{ + const int w = viewport_->width(); + if (w > 0) { + const double samplerate = session_.get_samplerate(); + // Note: sample_num = time * samplerate + // Note: samples_per_pixel = samplerate * scale + const int64_t start_sample = (offset_ * samplerate).convert_to(); + const int64_t end_sample = (offset_ * samplerate).convert_to() + + (w * session_.get_samplerate() * scale_); + + MetadataObject* md_obj = + session_.metadata_obj_manager()->find_object_by_type(MetadataObjMainViewRange); + + const int64_t old_start_sample = md_obj->value(MetadataValueStartSample).toLongLong(); + const int64_t old_end_sample = md_obj->value(MetadataValueEndSample).toLongLong(); + + if (start_sample != old_start_sample) + md_obj->set_value(MetadataValueStartSample, QVariant((qlonglong)start_sample)); + + if (end_sample != old_end_sample) + md_obj->set_value(MetadataValueEndSample, QVariant((qlonglong)end_sample)); + } +} + void View::update_hover_point() { // Determine signal that the mouse cursor is hovering over diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index b4c946d6..f8506cf4 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -393,9 +393,7 @@ private: void adjust_top_margin(); void update_scroll(); - void reset_scroll(); - void set_scroll_default(); void determine_if_header_was_shrunk(); @@ -422,6 +420,7 @@ private: void resizeEvent(QResizeEvent *event); + void update_view_range_metaobject() const; void update_hover_point(); public: