From: Soeren Apel Date: Thu, 23 Apr 2020 19:43:49 +0000 (+0200) Subject: TabularDecView-related bug fixes X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=85125b0f34be424fdf8a8a5133f2494722077d7d;p=pulseview.git TabularDecView-related bug fixes --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index eb6488e7..811aff65 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -358,7 +358,7 @@ void DecodeSignal::set_initial_pin_state(const uint16_t channel_id, const int in begin_decode(); } -double DecodeSignal::samplerate() const +double DecodeSignal::get_samplerate() const { double result = 0; diff --git a/pv/data/decodesignal.hpp b/pv/data/decodesignal.hpp index f961b7c3..3adcbb93 100644 --- a/pv/data/decodesignal.hpp +++ b/pv/data/decodesignal.hpp @@ -124,7 +124,7 @@ public: void set_initial_pin_state(const uint16_t channel_id, const int init_state); - double samplerate() const; + virtual double get_samplerate() const; const pv::util::Timestamp start_time() const; /** diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index c3e0d3d6..6decf26e 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -195,7 +195,7 @@ public: /** * Returns the sample rate for this signal. */ - double get_samplerate() const; + virtual double get_samplerate() const; /** * Queries the kind of conversion performed on this channel. diff --git a/pv/views/tabular_decoder/model.cpp b/pv/views/tabular_decoder/model.cpp index bd9e174c..0c89cef3 100644 --- a/pv/views/tabular_decoder/model.cpp +++ b/pv/views/tabular_decoder/model.cpp @@ -24,8 +24,15 @@ #include "view.hpp" +#include "pv/util.hpp" + using std::make_shared; +using pv::util::Timestamp; +using pv::util::format_time_si; +using pv::util::format_time_minutes; +using pv::util::SIPrefix; + namespace pv { namespace views { namespace tabular_decoder { @@ -49,6 +56,28 @@ AnnotationCollectionModel::AnnotationCollectionModel(QObject* parent) : header_data_.emplace_back(tr("Value")); // Column #5 } +QVariant AnnotationCollectionModel::data_from_ann(const Annotation* ann, int index) const +{ + switch (index) { + case 0: return QVariant((qulonglong)ann->start_sample()); // Column #0, Start Sample + case 1: { // Column #1, Start Time + Timestamp t = ann->start_sample() / signal_->get_samplerate(); + QString unit = signal_->get_samplerate() ? tr("s") : tr("sa"); + QString s; + if ((t < 60) || (signal_->get_samplerate() == 0)) // i.e. if unit is sa + s = format_time_si(t, SIPrefix::unspecified, 3, unit, false); + else + s = format_time_minutes(t, 3, false); + return QVariant(s); + } + case 2: return QVariant(ann->row()->decoder()->name()); // Column #2, Decoder + case 3: return QVariant(ann->row()->description()); // Column #3, Ann Row + case 4: return QVariant(ann->ann_class_description()); // Column #4, Ann Class + case 5: return QVariant(ann->longest_annotation()); // Column #5, Value + default: return QVariant(); + } +} + QVariant AnnotationCollectionModel::data(const QModelIndex& index, int role) const { if (!index.isValid() || !signal_) @@ -57,17 +86,8 @@ QVariant AnnotationCollectionModel::data(const QModelIndex& index, int role) con const Annotation* ann = static_cast(index.internalPointer()); - if (role == Qt::DisplayRole) { - switch (index.column()) { - case 0: return QVariant((qulonglong)ann->start_sample()); // Column #0, Start Sample - case 1: return QVariant(0/*(qulonglong)ann->start_sample()*/); // Column #1, Start Time - case 2: return QVariant(ann->row()->decoder()->name()); // Column #2, Decoder - case 3: return QVariant(ann->row()->description()); // Column #3, Ann Row - case 4: return QVariant(ann->ann_class_description()); // Column #4, Ann Class - case 5: return QVariant(ann->longest_annotation()); // Column #5, Value - default: return QVariant(); - } - } + if ((role == Qt::DisplayRole) || (role == Qt::ToolTipRole)) + return data_from_ann(ann, index.column()); if (role == Qt::BackgroundRole) { int level = 0; diff --git a/pv/views/tabular_decoder/view.cpp b/pv/views/tabular_decoder/view.cpp index 99da2c35..b5024d92 100644 --- a/pv/views/tabular_decoder/view.cpp +++ b/pv/views/tabular_decoder/view.cpp @@ -231,9 +231,6 @@ void View::reset_data() void View::update_data() { - if (!signal_) - return; - if (updating_data_) { if (!delayed_view_updater_.isActive()) delayed_view_updater_.start(); @@ -291,7 +288,7 @@ void View::save_data() const void View::on_selected_decoder_changed(int index) { if (signal_) { - disconnect(signal_, SIGNAL(signal_color_changed())); + disconnect(signal_, SIGNAL(color_changed(QColor))); disconnect(signal_, SIGNAL(new_annotations())); disconnect(signal_, SIGNAL(decode_reset())); } @@ -375,8 +372,7 @@ void View::on_decoder_stacked(void* decoder) if (index == -1) { // Add the decoder to the list - QString title = QString("%1 (%2)").arg(signal->name(), d->name()); - decoder_selector_->addItem(title, QVariant::fromValue((void*)d)); + decoder_selector_->addItem(signal->name(), QVariant::fromValue((void*)d)); } } diff --git a/pv/views/tabular_decoder/view.hpp b/pv/views/tabular_decoder/view.hpp index a7215f7b..484b81be 100644 --- a/pv/views/tabular_decoder/view.hpp +++ b/pv/views/tabular_decoder/view.hpp @@ -43,6 +43,7 @@ class AnnotationCollectionModel : public QAbstractTableModel, public GlobalSetti public: AnnotationCollectionModel(QObject* parent = nullptr); + QVariant data_from_ann(const Annotation* ann, int index) const; QVariant data(const QModelIndex& index, int role) const override; Qt::ItemFlags flags(const QModelIndex& index) const override; diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index 53998b2e..e9b046c2 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -971,7 +971,7 @@ pair DecodeTrace::get_pixels_offset_samples_per_pixel() const const double pixels_offset = ((view->offset() - decode_signal_->start_time()) / scale).convert_to(); - double samplerate = decode_signal_->samplerate(); + double samplerate = decode_signal_->get_samplerate(); // Show sample rate as 1Hz when it is unknown if (samplerate == 0.0)