]> sigrok.org Git - pulseview.git/commitdiff
Fix MetadataObjMainViewRange handling when main view is resized
authorSoeren Apel <redacted>
Sun, 24 May 2020 21:03:27 +0000 (23:03 +0200)
committerSoeren Apel <redacted>
Sun, 24 May 2020 21:04:24 +0000 (23:04 +0200)
pv/views/tabular_decoder/view.cpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 3c916f4d340689ef2230978387c6dae0ca8ddb29..14ae50a2941e8d56d8a532bd1505b566f67921b4 100644 (file)
@@ -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())
index df58967523e2e692b9b64b60df0a2564f10cc2ad..43853359540baf83859d3abd69fffde9254e9b22 100644 (file)
@@ -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>();
-                       int64_t end_sample = (offset_ * samplerate).convert_to<int64_t>() +
-                               (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<int64_t>();
+               const int64_t end_sample = (offset_ * samplerate).convert_to<int64_t>() +
+                       (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
index b4c946d6449f29ada6eec4191c5d3adc769ca691..f8506cf409ac1c73f9555a1bcfa0d72fd7cc1900 100644 (file)
@@ -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: