From: Soeren Apel Date: Fri, 29 Nov 2019 21:37:28 +0000 (+0100) Subject: DecoderOutput: Add selector box and fix signal handling X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=bdbc561f1ac395449f1b3afa7d2d0538dd1aa400;p=pulseview.git DecoderOutput: Add selector box and fix signal handling --- diff --git a/pv/session.cpp b/pv/session.cpp index 79c32947..dc16dd97 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -664,9 +664,8 @@ void Session::stop_capture() void Session::register_view(shared_ptr view) { - if (views_.empty()) { + if (views_.empty()) main_view_ = view; - } views_.push_back(view); @@ -674,35 +673,29 @@ void Session::register_view(shared_ptr view) update_signals(); // Add all other signals - unordered_set< shared_ptr > view_signalbases = - view->signalbases(); - - views::trace::View *trace_view = - qobject_cast(view.get()); - - if (trace_view) { - for (const shared_ptr& signalbase : signalbases_) { - const int sb_exists = count_if( - view_signalbases.cbegin(), view_signalbases.cend(), - [&](const shared_ptr &sb) { - return sb == signalbase; - }); - // Add the signal to the view as it doesn't have it yet - if (!sb_exists) - switch (signalbase->type()) { - case data::SignalBase::AnalogChannel: - case data::SignalBase::LogicChannel: - case data::SignalBase::DecodeChannel: + unordered_set< shared_ptr > view_signalbases = view->signalbases(); + + for (const shared_ptr& signalbase : signalbases_) { + const int sb_exists = count_if( + view_signalbases.cbegin(), view_signalbases.cend(), + [&](const shared_ptr &sb) { + return sb == signalbase; + }); + + // Add the signal to the view if it doesn't have it yet + if (!sb_exists) + switch (signalbase->type()) { + case data::SignalBase::AnalogChannel: + case data::SignalBase::LogicChannel: + case data::SignalBase::MathChannel: + view->add_signalbase(signalbase); + break; + case data::SignalBase::DecodeChannel: #ifdef ENABLE_DECODE - trace_view->add_decode_signal( - dynamic_pointer_cast(signalbase)); + view->add_decode_signal(dynamic_pointer_cast(signalbase)); #endif - break; - case data::SignalBase::MathChannel: - // TBD - break; - } - } + break; + } } signals_changed(); diff --git a/pv/views/decoder_output/view.cpp b/pv/views/decoder_output/view.cpp index 8da1e84a..d4077476 100644 --- a/pv/views/decoder_output/view.cpp +++ b/pv/views/decoder_output/view.cpp @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -28,6 +29,7 @@ #include "pv/session.hpp" #include "pv/util.hpp" +using pv::data::SignalBase; using pv::util::TimeUnit; using pv::util::Timestamp; @@ -38,17 +40,22 @@ namespace views { namespace decoder_output { View::View(Session &session, bool is_main_view, QMainWindow *parent) : - ViewBase(session, is_main_view, parent) + ViewBase(session, is_main_view, parent), // Note: Place defaults in View::reset_view_state(), not here + signal_selector_(new QComboBox()) { QVBoxLayout *root_layout = new QVBoxLayout(this); root_layout->setContentsMargins(0, 0, 0, 0); - QToolBar* tool_bar = new QToolBar(); - tool_bar->setContextMenuPolicy(Qt::PreventContextMenu); + // Create toolbar + QToolBar* toolbar = new QToolBar(); + toolbar->setContextMenuPolicy(Qt::PreventContextMenu); + parent->addToolBar(toolbar); - parent->addToolBar(tool_bar); + // Populate toolbar + toolbar->addWidget(new QLabel(tr("Decoder:"))); + toolbar->addWidget(signal_selector_); reset_view_state(); } @@ -74,17 +81,23 @@ void View::clear_signals() void View::clear_decode_signals() { + signal_selector_->clear(); } void View::add_decode_signal(shared_ptr signal) { connect(signal.get(), SIGNAL(name_changed(const QString&)), - this, SLOT(on_signal_name_changed())); + this, SLOT(on_signal_name_changed(const QString&))); + + signal_selector_->addItem(signal->name(), qVariantFromValue(signal.get())); } void View::remove_decode_signal(shared_ptr signal) { - (void)signal; + int index = signal_selector_->findData(qVariantFromValue(signal.get())); + + if (index != -1) + signal_selector_->removeItem(index); } void View::save_settings(QSettings &settings) const @@ -99,8 +112,14 @@ void View::restore_settings(QSettings &settings) (void)settings; } -void View::on_signal_name_changed() +void View::on_signal_name_changed(const QString &name) { + SignalBase *sb = qobject_cast(QObject::sender()); + assert(sb); + + int index = signal_selector_->findData(qVariantFromValue(sb)); + if (index != -1) + signal_selector_->setItemText(index, name); } } // namespace decoder_output diff --git a/pv/views/decoder_output/view.hpp b/pv/views/decoder_output/view.hpp index 79dfe234..4f772c82 100644 --- a/pv/views/decoder_output/view.hpp +++ b/pv/views/decoder_output/view.hpp @@ -20,6 +20,8 @@ #ifndef PULSEVIEW_PV_VIEWS_DECODEROUTPUT_VIEW_HPP #define PULSEVIEW_PV_VIEWS_DECODEROUTPUT_VIEW_HPP +#include + #include namespace pv { @@ -57,8 +59,10 @@ public: virtual void restore_settings(QSettings &settings); private Q_SLOTS: - void on_signal_name_changed(); + void on_signal_name_changed(const QString &name); +private: + QComboBox *signal_selector_; }; } // namespace decoder_output