]> sigrok.org Git - pulseview.git/commitdiff
Fix #977 properly by checking whether a row actually has annotations
authorSoeren Apel <redacted>
Fri, 20 Dec 2019 20:05:54 +0000 (21:05 +0100)
committerSoeren Apel <redacted>
Fri, 20 Dec 2019 22:52:01 +0000 (23:52 +0100)
pv/data/decode/rowdata.cpp
pv/data/decode/rowdata.hpp
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/views/trace/decodetrace.cpp

index 2a26169eb6cc0f14adb5a107726c40ee891838b6..d3d14f9bd56fb7d2b3c275f5185775ca12dceab8 100644 (file)
@@ -32,6 +32,11 @@ uint64_t RowData::get_max_sample() const
        return annotations_.back().end_sample();
 }
 
+uint64_t RowData::get_annotation_count() const
+{
+       return annotations_.size();
+}
+
 void RowData::get_annotation_subset(
        vector<pv::data::decode::Annotation> &dest,
        uint64_t start_sample, uint64_t end_sample) const
index 0589ec894eb444fad4f2d0d759c98a1eabc13fc7..3c967ff70b1e8998d60903c39bcc35e2e8fcc2ce 100644 (file)
@@ -42,6 +42,8 @@ public:
 public:
        uint64_t get_max_sample() const;
 
+       uint64_t get_annotation_count() const;
+
        /**
         * Extracts annotations between the given sample range into a vector.
         * Note: The annotations are unsorted and only annotations that fully
index a6d4a9d603b23e0820a9a6a869658020e7787079..3071a5c1d1c3628d6a96933dcec6e6f24b021c14 100644 (file)
@@ -454,7 +454,7 @@ int64_t DecodeSignal::get_decoded_sample_count(uint32_t segment_id,
        return result;
 }
 
-vector<Row> DecodeSignal::get_rows(bool visible_only) const
+vector<Row> DecodeSignal::get_rows() const
 {
        lock_guard<mutex> lock(output_mutex_);
 
@@ -462,9 +462,6 @@ vector<Row> DecodeSignal::get_rows(bool visible_only) const
 
        for (const shared_ptr<decode::Decoder>& dec : stack_) {
                assert(dec);
-               if (visible_only && !dec->shown())
-                       continue;
-
                const srd_decoder *const decc = dec->decoder();
                assert(dec->decoder());
 
@@ -485,6 +482,23 @@ vector<Row> DecodeSignal::get_rows(bool visible_only) const
        return rows;
 }
 
+uint64_t DecodeSignal::get_annotation_count(const decode::Row &row,
+       uint32_t segment_id) const
+{
+       if (segment_id >= segments_.size())
+               return 0;
+
+       const DecodeSegment *segment = &(segments_.at(segment_id));
+       const map<const decode::Row, decode::RowData> *rows =
+               &(segment->annotation_rows);
+
+       const auto iter = rows->find(row);
+       if (iter != rows->end())
+               return (*iter).second.get_annotation_count();
+
+       return 0;
+}
+
 void DecodeSignal::get_annotation_subset(
        vector<pv::data::decode::Annotation> &dest,
        const decode::Row &row, uint32_t segment_id, uint64_t start_sample,
@@ -510,7 +524,7 @@ void DecodeSignal::get_annotation_subset(
 {
        // Note: We put all vectors and lists on the heap, not the stack
 
-       const vector<Row> rows = get_rows(true);
+       const vector<Row> rows = get_rows();
 
        // Use forward_lists for faster merging
        forward_list<Annotation> *all_ann_list = new forward_list<Annotation>();
index 74ffbd1ff470c64cd88678ef429ccfc739997883..9a112e9ba6342183b50a9c8c0678f492593ff27c 100644 (file)
@@ -139,7 +139,9 @@ public:
        int64_t get_decoded_sample_count(uint32_t segment_id,
                bool include_processing) const;
 
-       vector<decode::Row> get_rows(bool visible_only) const;
+       vector<decode::Row> get_rows() const;
+
+       uint64_t get_annotation_count(const decode::Row &row, uint32_t segment_id) const;
 
        /**
         * Extracts annotations from a single row into a vector.
index e14b4ecbf433469467c5b820eabf534aac04e1c7..50156ddf7f865bb0d0f58fda546423ebf4b2a522 100644 (file)
@@ -192,7 +192,7 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
        sample_range.second = min((int64_t)sample_range.second,
                decode_signal_->get_decoded_sample_count(current_segment_, false));
 
-       const vector<Row> rows = decode_signal_->get_rows(!always_show_all_rows_);
+       const vector<Row> rows = decode_signal_->get_rows();
 
        visible_rows_.clear();
        for (const Row& row : rows) {
@@ -212,7 +212,13 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
                vector<Annotation> annotations;
                decode_signal_->get_annotation_subset(annotations, row,
                        current_segment_, sample_range.first, sample_range.second);
-               if (always_show_all_rows_ || !annotations.empty()) {
+
+               // Show row if there are visible annotations or when user wants to see
+               // all rows that have annotations somewhere and this one is one of them
+               bool row_visible = !annotations.empty() ||
+                       (always_show_all_rows_ && (decode_signal_->get_annotation_count(row, current_segment_) > 0));
+
+               if (row_visible) {
                        draw_annotations(annotations, p, annotation_height, pp, y,
                                get_row_color(row.index()), row_title_width);
                        y += row_height_;