From: Soeren Apel Date: Sun, 19 Jan 2020 13:14:43 +0000 (+0100) Subject: Fix #1290 by allowing the cursor to show samples X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a3c57f445a469cd9fc7ec02d529d9425a94b2256;p=pulseview.git Fix #1290 by allowing the cursor to show samples --- diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 1573a9f2..614b983c 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -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"; diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index f526285a..adb9168a 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -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; diff --git a/pv/views/trace/cursorpair.cpp b/pv/views/trace/cursorpair.cpp index bd6814c5..81688337 100644 --- a/pv/views/trace/cursorpair.cpp +++ b/pv/views/trace/cursorpair.cpp @@ -58,6 +58,8 @@ CursorPair::CursorPair(View &view) : GlobalSettings::Key_View_CursorShowFrequency).value(); show_interval_ = settings.value( GlobalSettings::Key_View_CursorShowInterval).value(); + show_samples_ = settings.value( + GlobalSettings::Key_View_CursorShowSamples).value(); 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()); }); + 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()); + }); + 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(); + + if (key == GlobalSettings::Key_View_CursorShowSamples) + show_samples_ = value.value(); } 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()); + 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; diff --git a/pv/views/trace/cursorpair.hpp b/pv/views/trace/cursorpair.hpp index 649875ee..d59d9414 100644 --- a/pv/views/trace/cursorpair.hpp +++ b/pv/views/trace/cursorpair.hpp @@ -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