]> sigrok.org Git - pulseview.git/commitdiff
TabularDecView: Visually indent annotations by PD stack level
authorSoeren Apel <redacted>
Thu, 23 Apr 2020 11:54:29 +0000 (13:54 +0200)
committerUwe Hermann <redacted>
Sun, 3 May 2020 15:20:55 +0000 (17:20 +0200)
pv/data/decode/annotation.cpp
pv/data/decode/annotation.hpp
pv/data/decodesignal.cpp
pv/views/tabular_decoder/model.cpp
pv/views/tabular_decoder/view.hpp

index fe0350d03b1643a4aedba1623a27ba23981c83b0..27a44fe4808208b09240d575910ff4f72b68cc42 100644 (file)
@@ -86,6 +86,11 @@ uint64_t Annotation::end_sample() const
        return end_sample_;
 }
 
+uint64_t Annotation::length() const
+{
+       return end_sample_ - start_sample_;
+}
+
 Annotation::Class Annotation::ann_class_id() const
 {
        return ann_class_id_;
index fa5149086c230fcfb790f07d2a3c38cc229ecd0c..57ca46950384d16632cab87b0596b0fba9baab43 100644 (file)
@@ -53,6 +53,7 @@ public:
 
        uint64_t start_sample() const;
        uint64_t end_sample() const;
+       uint64_t length() const;
 
        Class ann_class_id() const;
        const QString ann_class_name() const;
index 1de4a3297ef92f53562372d0d29d356b3f86d417..eb6488e7570a4bfeb85e7fbfd1c695da56e6110d 100644 (file)
@@ -1478,7 +1478,7 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa
                                it--;
                                ann_has_earlier_start = (pdata->start_sample < (*it)->start_sample());
                                ann_has_same_start = (pdata->start_sample == (*it)->start_sample());
-                               ann_is_longer = (new_ann_len > ((*it)->end_sample() - (*it)->start_sample()));
+                               ann_is_longer = (new_ann_len > (*it)->length());
                        } while ((ann_has_earlier_start || (ann_has_same_start && ann_is_longer)) && (it != all_annotations.begin()));
 
                        // Allow inserting at the front
index 66fabf5ac1534817781ebe07a453bbdbc2bedaad..b502395c3dd907a8d0d2c2f89b07458cc3547d6c 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "pv/views/tabular_decoder/view.hpp"
 
+#include "view.hpp"
+
 using std::make_shared;
 
 namespace pv {
@@ -31,6 +33,7 @@ namespace tabular_decoder {
 AnnotationCollectionModel::AnnotationCollectionModel(QObject* parent) :
        QAbstractTableModel(parent),
        all_annotations_(nullptr),
+       signal_(nullptr),
        prev_segment_(0),
        prev_last_row_(0)
 {
@@ -48,7 +51,7 @@ AnnotationCollectionModel::AnnotationCollectionModel(QObject* parent) :
 
 QVariant AnnotationCollectionModel::data(const QModelIndex& index, int role) const
 {
-       if (!index.isValid())
+       if (!index.isValid() || !signal_)
                return QVariant();
 
        const Annotation* ann =
@@ -67,10 +70,18 @@ QVariant AnnotationCollectionModel::data(const QModelIndex& index, int role) con
        }
 
        if (role == Qt::BackgroundRole) {
-               if (theme_is_dark_)
-                       return QBrush(ann->dark_color());
-               else
-                       return QBrush(ann->bright_color());
+               int level = 0;
+
+               const unsigned int ann_stack_level = ann->row_data()->row()->decoder()->get_stack_level();
+               level = (signal_->decoder_stack().size() - 1 - ann_stack_level);
+
+               // Only use custom cell background color if column index reached the hierarchy level
+               if (index.column() >= level) {
+                       if (theme_is_dark_)
+                               return QBrush(ann->dark_color());
+                       else
+                               return QBrush(ann->bright_color());
+               }
        }
 
        return QVariant();
@@ -135,12 +146,14 @@ void AnnotationCollectionModel::set_signal_and_segment(data::DecodeSignal* signa
 {
        if (!signal) {
                all_annotations_ = nullptr;
+               signal_ = nullptr;
                dataChanged(QModelIndex(), QModelIndex());
                layoutChanged();
                return;
        }
 
        all_annotations_ = signal->get_all_annotations_by_segment(current_segment);
+       signal_ = signal;
 
        if (!all_annotations_ || all_annotations_->empty()) {
                prev_segment_ = current_segment;
index a6bd9ea3c613d353b33afd1a93061a2008fbd57d..461cc7cd2c460092e0aa436ea6851e6652311c34 100644 (file)
@@ -63,6 +63,7 @@ public:
 private:
        vector<QVariant> header_data_;
        const deque<const Annotation*>* all_annotations_;
+       data::DecodeSignal* signal_;
        uint32_t prev_segment_;
        uint64_t prev_last_row_;
        bool theme_is_dark_;