TabularDecView-related bug fixes
authorSoeren Apel <soeren@apelpie.net>
Thu, 23 Apr 2020 19:43:49 +0000 (21:43 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Sun, 3 May 2020 15:20:55 +0000 (17:20 +0200)
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/data/signalbase.hpp
pv/views/tabular_decoder/model.cpp
pv/views/tabular_decoder/view.cpp
pv/views/tabular_decoder/view.hpp
pv/views/trace/decodetrace.cpp

index eb6488e7570a4bfeb85e7fbfd1c695da56e6110d..811aff65589529887d8b57b7924c6df05b5024f2 100644 (file)
@@ -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;
 
index f961b7c3a740b6bb9bc8a010147da64ce9e814db..3adcbb93102c5b05b65b58340de491857fdefaf9 100644 (file)
@@ -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;
 
        /**
index c3e0d3d64ef56d02b289451c7cb3d54ca89c44f9..6decf26e6a96c3af654743f0724b0ec1c2ee7408 100644 (file)
@@ -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.
index bd9e174c26ba482237c7bdc750e002c1f52880c7..0c89cef314f3a8547dfdad3659a90fc1c21676cc 100644 (file)
 
 #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<const Annotation*>(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;
index 99da2c35d53ad60f75dc7ec1a309affee27bf73f..b5024d92b531fc3fb3524e8e86fc087cf7ad5c38 100644 (file)
@@ -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));
        }
 }
 
index a7215f7b85008ad4cf5f0bb9e52bbae68dda7308..484b81be799775a3619b7fe969175ad470a878ed 100644 (file)
@@ -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;
 
index 53998b2ea7a0dc30f0728fdc9d895dd557425127..e9b046c2d86bb088389f53682b6d8f6732248ffe 100644 (file)
@@ -971,7 +971,7 @@ pair<double, double> DecodeTrace::get_pixels_offset_samples_per_pixel() const
        const double pixels_offset =
                ((view->offset() - decode_signal_->start_time()) / scale).convert_to<double>();
 
-       double samplerate = decode_signal_->samplerate();
+       double samplerate = decode_signal_->get_samplerate();
 
        // Show sample rate as 1Hz when it is unknown
        if (samplerate == 0.0)