X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fviews%2Ftabular_decoder%2Fmodel.cpp;h=938e6add3a6236a6e5cd3ef29fec26ed7029ebe7;hb=009fc9ae42ecccd3802f549b39c19a2ba895959d;hp=6037cf3e8171745caa67191999b6a967914edd8b;hpb=02078aa15a4747b8ab7a91d54e2e141c3acb5628;p=pulseview.git diff --git a/pv/views/tabular_decoder/model.cpp b/pv/views/tabular_decoder/model.cpp index 6037cf3e..938e6add 100644 --- a/pv/views/tabular_decoder/model.cpp +++ b/pv/views/tabular_decoder/model.cpp @@ -17,6 +17,7 @@ * along with this program; if not, see . */ +#include #include #include @@ -25,6 +26,7 @@ #include "view.hpp" #include "pv/util.hpp" +#include "pv/globalsettings.hpp" using std::make_shared; @@ -46,11 +48,9 @@ AnnotationCollectionModel::AnnotationCollectionModel(QObject* parent) : prev_last_row_(0), start_index_(0), end_index_(0), + had_highlight_before_(false), hide_hidden_(false) { - GlobalSettings::add_change_handler(this); - theme_is_dark_ = GlobalSettings::current_theme_is_dark(); - // TBD Maybe use empty columns as indentation levels to indicate stacked decoders header_data_.emplace_back(tr("Sample")); // Column #0 header_data_.emplace_back(tr("Time")); // Column #1 @@ -60,6 +60,16 @@ AnnotationCollectionModel::AnnotationCollectionModel(QObject* parent) : header_data_.emplace_back(tr("Value")); // Column #5 } +int AnnotationCollectionModel::get_hierarchy_level(const Annotation* ann) const +{ + 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); + + return level; +} + QVariant AnnotationCollectionModel::data_from_ann(const Annotation* ann, int index) const { switch (index) { @@ -93,18 +103,40 @@ QVariant AnnotationCollectionModel::data(const QModelIndex& index, int role) con if ((role == Qt::DisplayRole) || (role == Qt::ToolTipRole)) return data_from_ann(ann, index.column()); - if (role == Qt::BackgroundRole) { - int level = 0; + if (role == Qt::ForegroundRole) { + if (index.column() >= get_hierarchy_level(ann)) { + // Invert the text color if this cell is highlighted + const bool must_highlight = (highlight_sample_num_ > 0) && + ((int64_t)ann->start_sample() <= highlight_sample_num_) && + ((int64_t)ann->end_sample() >= highlight_sample_num_); + + if (must_highlight) { + if (GlobalSettings::current_theme_is_dark()) + return QApplication::palette().brush(QPalette::Window); + else + return QApplication::palette().brush(QPalette::WindowText); + } + } - const unsigned int ann_stack_level = ann->row_data()->row()->decoder()->get_stack_level(); - level = (signal_->decoder_stack().size() - 1 - ann_stack_level); + return QApplication::palette().brush(QPalette::WindowText); + } + if (role == Qt::BackgroundRole) { // 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()); + if (index.column() >= get_hierarchy_level(ann)) { + + QColor color; + const bool must_highlight = (highlight_sample_num_ > 0) && + ((int64_t)ann->start_sample() <= highlight_sample_num_) && + ((int64_t)ann->end_sample() >= highlight_sample_num_); + + if (must_highlight) + color = ann->color(); else - return QBrush(ann->bright_color()); + color = GlobalSettings::current_theme_is_dark() ? + ann->dark_color() : ann->bright_color(); + + return QBrush(color); } } @@ -330,14 +362,41 @@ void AnnotationCollectionModel::update_annotations_without_hidden() all_annotations_without_hidden_.resize(count); } -void AnnotationCollectionModel::on_setting_changed(const QString &key, const QVariant &value) +void AnnotationCollectionModel::update_highlighted_rows(QModelIndex first, + QModelIndex last, int64_t sample_num) { - (void)key; - (void)value; + bool has_highlight = false; + + highlight_sample_num_ = sample_num; + + if (!dataset_ || dataset_->empty()) + return; + + if (sample_num >= 0) { + last = last.sibling(last.row() + 1, 0); + + // Check if there are any annotations visible in the table view that + // we would need to highlight - only then do we do so + QModelIndex index = first; + do { + const Annotation* ann = + static_cast(index.internalPointer()); + assert(ann); + + if (((int64_t)ann->start_sample() <= sample_num) && + ((int64_t)ann->end_sample() >= sample_num)) { + has_highlight = true; + break; + } + + index = index.sibling(index.row() + 1, 0); + } while (index != last); + } + + if (has_highlight || had_highlight_before_) + dataChanged(first, last); - // We don't really care about the actual setting, we just update the - // flag that indicates whether we are using a bright or dark color theme - theme_is_dark_ = GlobalSettings::current_theme_is_dark(); + had_highlight_before_ = has_highlight; } void AnnotationCollectionModel::on_annotation_visibility_changed()