]> sigrok.org Git - pulseview.git/commitdiff
Fix #1290 by allowing the cursor to show samples
authorSoeren Apel <redacted>
Sun, 19 Jan 2020 13:14:43 +0000 (14:14 +0100)
committerUwe Hermann <redacted>
Wed, 22 Jan 2020 21:56:04 +0000 (22:56 +0100)
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/views/trace/cursorpair.cpp
pv/views/trace/cursorpair.hpp

index 1573a9f2ba165b23c2582de93aa0aba05ef794c1..614b983c40a45418fb6b986c367fd2fad2227ee9 100644 (file)
@@ -64,6 +64,7 @@ const QString GlobalSettings::Key_View_SnapDistance = "View_SnapDistance";
 const QString GlobalSettings::Key_View_CursorFillColor = "View_CursorFillColor";
 const QString GlobalSettings::Key_View_CursorShowFrequency = "View_CursorShowFrequency";
 const QString GlobalSettings::Key_View_CursorShowInterval = "View_CursorShowInterval";
+const QString GlobalSettings::Key_View_CursorShowSamples = "View_CursorShowSamples";
 const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable";
 const QString GlobalSettings::Key_Dec_ExportFormat = "Dec_ExportFormat";
 const QString GlobalSettings::Key_Dec_AlwaysShowAllRows = "Dec_AlwaysShowAllRows";
index f526285a13d322f364d34d069459e839a7eb4780..adb9168a1fbc3be027db6f7ee16df0930b501de4 100644 (file)
@@ -72,6 +72,7 @@ public:
        static const QString Key_View_CursorFillColor;
        static const QString Key_View_CursorShowInterval;
        static const QString Key_View_CursorShowFrequency;
+       static const QString Key_View_CursorShowSamples;
        static const QString Key_Dec_InitialStateConfigurable;
        static const QString Key_Dec_ExportFormat;
        static const QString Key_Dec_AlwaysShowAllRows;
index bd6814c5c8f1a86258d2dcda6eb4d4af5b922450..81688337f94e238c8eaaf0310a54d5ced35a1ee4 100644 (file)
@@ -58,6 +58,8 @@ CursorPair::CursorPair(View &view) :
                GlobalSettings::Key_View_CursorShowFrequency).value<bool>();
        show_interval_ = settings.value(
                GlobalSettings::Key_View_CursorShowInterval).value<bool>();
+       show_samples_ = settings.value(
+               GlobalSettings::Key_View_CursorShowSamples).value<bool>();
 
        connect(&view_, SIGNAL(hover_point_changed(const QWidget*, QPoint)),
                this, SLOT(on_hover_point_changed(const QWidget*, QPoint)));
@@ -145,6 +147,17 @@ QMenu *CursorPair::create_header_context_menu(QWidget *parent)
                        !settings.value(GlobalSettings::Key_View_CursorShowFrequency).value<bool>());
                });
 
+       QAction *displaySamplesAction = new QAction(tr("Display samples"));
+       displaySamplesAction->setCheckable(true);
+       displaySamplesAction->setChecked(show_samples_);
+       menu->addAction(displaySamplesAction);
+
+       connect(displaySamplesAction, &QAction::toggled, [=]{
+               GlobalSettings settings;
+               settings.setValue(GlobalSettings::Key_View_CursorShowSamples,
+                       !settings.value(GlobalSettings::Key_View_CursorShowSamples).value<bool>());
+               });
+
        return menu;
 }
 
@@ -283,6 +296,9 @@ void CursorPair::on_setting_changed(const QString &key, const QVariant &value)
 
        if (key == GlobalSettings::Key_View_CursorShowInterval)
                show_interval_ = value.value<bool>();
+
+       if (key == GlobalSettings::Key_View_CursorShowSamples)
+               show_samples_ = value.value<bool>();
 }
 
 void CursorPair::on_hover_point_changed(const QWidget* widget, const QPoint& hp)
@@ -329,6 +345,15 @@ QString CursorPair::format_string_sub(int time_precision, int freq_precision, bo
                                s = QString("%1").arg(time);
                        items++;
                }
+
+               if (show_samples_) {
+                       const QString samples = QString::number(
+                               (diff * view_.session().get_samplerate()).convert_to<uint64_t>());
+                       if (items > 0)
+                               s = QString("%1 / %2").arg(s, samples);
+                       else
+                               s = QString("%1").arg(samples);
+               }
        } else
                // In this case, we return the number of samples, really
                s = time;
index 649875ee4f1e98ae5dde96bd24aaa011c505f8b3..d59d9414d6ae5488896131ccf9c667716bd0737f 100644 (file)
@@ -128,7 +128,7 @@ private:
        QSizeF text_size_;
        QRectF label_area_;
        bool label_incomplete_;
-       bool show_interval_, show_frequency_;
+       bool show_interval_, show_frequency_, show_samples_;
 };
 
 } // namespace trace