]> sigrok.org Git - pulseview.git/commitdiff
Make sure PD row colors remain constant by adding a row index
authorSoeren Apel <redacted>
Mon, 16 Jul 2018 16:27:54 +0000 (18:27 +0200)
committerUwe Hermann <redacted>
Sat, 21 Jul 2018 16:57:21 +0000 (18:57 +0200)
Without this change, PD row colors depend on the visible rows,
not a constant ID. This means that rows that collapse change the
colors of all rows coming after them.

pv/data/decode/row.cpp
pv/data/decode/row.hpp
pv/data/decodesignal.cpp
pv/views/trace/decodetrace.cpp

index 1266b8436e1e09934b92418b62e5a6ebc42e7728..5b1b25ee8ec56043f736b2d82938d9d1ea1ef0fd 100644 (file)
@@ -31,7 +31,8 @@ Row::Row() :
 {
 }
 
-Row::Row(const srd_decoder *decoder, const srd_decoder_annotation_row *row) :
+Row::Row(int index, const srd_decoder *decoder, const srd_decoder_annotation_row *row) :
+       index_(index),
        decoder_(decoder),
        row_(row)
 {
@@ -60,6 +61,11 @@ const QString Row::title() const
        return QString();
 }
 
+int Row::index() const
+{
+       return index_;
+}
+
 bool Row::operator<(const Row &other) const
 {
        return (decoder_ < other.decoder_) ||
index 5ddd10d3318fb2b0c9e0d399fa8b83915164d45f..2411d4f61afaa2344660429fc2b76348f034a269 100644 (file)
@@ -36,17 +36,19 @@ class Row
 public:
        Row();
 
-       Row(const srd_decoder *decoder,
+       Row(int index, const srd_decoder *decoder,
                const srd_decoder_annotation_row *row = nullptr);
 
        const srd_decoder* decoder() const;
        const srd_decoder_annotation_row* row() const;
 
        const QString title() const;
+       int index() const;
 
        bool operator<(const Row &other) const;
 
 private:
+       int index_;
        const srd_decoder *decoder_;
        const srd_decoder_annotation_row *row_;
 };
index 65436002c760681a8b1b8117f15c74932479f4a2..9da7de6766c418e759ea1f02d88ba8ab8614c551 100644 (file)
@@ -209,6 +209,7 @@ void DecodeSignal::begin_decode()
                }
 
        // Map out all the annotation classes
+       int row_index = 0;
        for (const shared_ptr<decode::Decoder> &dec : stack_) {
                assert(dec);
                const srd_decoder *const decc = dec->decoder();
@@ -219,7 +220,7 @@ void DecodeSignal::begin_decode()
                                (srd_decoder_annotation_row *)l->data;
                        assert(ann_row);
 
-                       const Row row(decc, ann_row);
+                       const Row row(row_index++, decc, ann_row);
 
                        for (const GSList *ll = ann_row->ann_classes;
                                ll; ll = ll->next)
@@ -432,16 +433,17 @@ vector<Row> DecodeSignal::visible_rows() const
                const srd_decoder *const decc = dec->decoder();
                assert(dec->decoder());
 
+               int row_index = 0;
                // Add a row for the decoder if it doesn't have a row list
                if (!decc->annotation_rows)
-                       rows.emplace_back(decc);
+                       rows.emplace_back(row_index++, decc);
 
                // Add the decoder rows
                for (const GSList *l = decc->annotation_rows; l; l = l->next) {
                        const srd_decoder_annotation_row *const ann_row =
                                (srd_decoder_annotation_row *)l->data;
                        assert(ann_row);
-                       rows.emplace_back(decc, ann_row);
+                       rows.emplace_back(row_index++, decc, ann_row);
                }
        }
 
@@ -1159,9 +1161,10 @@ void DecodeSignal::create_decode_segment()
                const srd_decoder *const decc = dec->decoder();
                assert(dec->decoder());
 
+               int row_index = 0;
                // Add a row for the decoder if it doesn't have a row list
                if (!decc->annotation_rows)
-                       (segments_.back().annotation_rows)[Row(decc)] =
+                       (segments_.back().annotation_rows)[Row(row_index++, decc)] =
                                decode::RowData();
 
                // Add the decoder rows
@@ -1170,7 +1173,7 @@ void DecodeSignal::create_decode_segment()
                                (srd_decoder_annotation_row *)l->data;
                        assert(ann_row);
 
-                       const Row row(decc, ann_row);
+                       const Row row(row_index++, decc, ann_row);
 
                        // Add a new empty row data object
                        (segments_.back().annotation_rows)[row] =
@@ -1211,7 +1214,7 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa
                row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find((*r).second);
        else {
                // Failing that, use the decoder as a key
-               row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find(Row(decc));
+               row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find(Row(0, decc));
        }
 
        if (row_iter == ds->segments_.at(ds->current_segment_id_).annotation_rows.end()) {
index 211d46e448a531d3313c205745ff4aaf015a1133..208185ac63a7e26ccb0da39ac11bae73b501aed6 100644 (file)
@@ -196,8 +196,7 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
                        current_segment_, sample_range.first, sample_range.second);
                if (!annotations.empty()) {
                        draw_annotations(annotations, p, annotation_height, pp, y,
-                               get_row_color(visible_rows_.size()), row_title_width);
-
+                               get_row_color(row.index()), row_title_width);
                        y += row_height_;
                        visible_rows_.push_back(row);
                }