From: Soeren Apel Date: Thu, 23 Apr 2020 11:54:29 +0000 (+0200) Subject: TabularDecView: Visually indent annotations by PD stack level X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d656b01007629b239b51ab34e5a0219ef4f2595a;p=pulseview.git TabularDecView: Visually indent annotations by PD stack level --- diff --git a/pv/data/decode/annotation.cpp b/pv/data/decode/annotation.cpp index fe0350d0..27a44fe4 100644 --- a/pv/data/decode/annotation.cpp +++ b/pv/data/decode/annotation.cpp @@ -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_; diff --git a/pv/data/decode/annotation.hpp b/pv/data/decode/annotation.hpp index fa514908..57ca4695 100644 --- a/pv/data/decode/annotation.hpp +++ b/pv/data/decode/annotation.hpp @@ -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; diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 1de4a329..eb6488e7 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -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 diff --git a/pv/views/tabular_decoder/model.cpp b/pv/views/tabular_decoder/model.cpp index 66fabf5a..b502395c 100644 --- a/pv/views/tabular_decoder/model.cpp +++ b/pv/views/tabular_decoder/model.cpp @@ -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; diff --git a/pv/views/tabular_decoder/view.hpp b/pv/views/tabular_decoder/view.hpp index a6bd9ea3..461cc7cd 100644 --- a/pv/views/tabular_decoder/view.hpp +++ b/pv/views/tabular_decoder/view.hpp @@ -63,6 +63,7 @@ public: private: vector header_data_; const deque* all_annotations_; + data::DecodeSignal* signal_; uint32_t prev_segment_; uint64_t prev_last_row_; bool theme_is_dark_;