]> sigrok.org Git - pulseview.git/commitdiff
DecoderOutput: Add selector box and fix signal handling
authorSoeren Apel <redacted>
Fri, 29 Nov 2019 21:37:28 +0000 (22:37 +0100)
committerSoeren Apel <redacted>
Fri, 29 Nov 2019 21:37:28 +0000 (22:37 +0100)
pv/session.cpp
pv/views/decoder_output/view.cpp
pv/views/decoder_output/view.hpp

index 79c32947e1f619b43895516d0fb1b0820bdc349e..dc16dd97f9b616e4d7f6911e665ddf248a20815d 100644 (file)
@@ -664,9 +664,8 @@ void Session::stop_capture()
 
 void Session::register_view(shared_ptr<views::ViewBase> view)
 {
-       if (views_.empty()) {
+       if (views_.empty())
                main_view_ = view;
-       }
 
        views_.push_back(view);
 
@@ -674,35 +673,29 @@ void Session::register_view(shared_ptr<views::ViewBase> view)
        update_signals();
 
        // Add all other signals
-       unordered_set< shared_ptr<data::SignalBase> > view_signalbases =
-               view->signalbases();
-
-       views::trace::View *trace_view =
-               qobject_cast<views::trace::View*>(view.get());
-
-       if (trace_view) {
-               for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) {
-                       const int sb_exists = count_if(
-                               view_signalbases.cbegin(), view_signalbases.cend(),
-                               [&](const shared_ptr<data::SignalBase> &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<data::SignalBase> > view_signalbases = view->signalbases();
+
+       for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) {
+               const int sb_exists = count_if(
+                       view_signalbases.cbegin(), view_signalbases.cend(),
+                       [&](const shared_ptr<data::SignalBase> &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<data::DecodeSignal>(signalbase));
+                               view->add_decode_signal(dynamic_pointer_cast<data::DecodeSignal>(signalbase));
 #endif
-                                       break;
-                               case data::SignalBase::MathChannel:
-                                       // TBD
-                                       break;
-                               }
-               }
+                               break;
+                       }
        }
 
        signals_changed();
index 8da1e84ae73499c506cff31e3bbf63e5d7c69e39..d407747605e8f03a8ec9948bb5ac0a8d7af7b545 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <libsigrokdecode/libsigrokdecode.h>
 
+#include <QLabel>
 #include <QMenu>
 #include <QToolBar>
 #include <QVBoxLayout>
@@ -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<data::DecodeSignal> 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<data::DecodeSignal> 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<SignalBase*>(QObject::sender());
+       assert(sb);
+
+       int index = signal_selector_->findData(qVariantFromValue(sb));
+       if (index != -1)
+               signal_selector_->setItemText(index, name);
 }
 
 } // namespace decoder_output
index 79dfe234aac4751827d233352a8528328cf1761f..4f772c822d01c99d30cb2cd17742a68345b7b5a6 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef PULSEVIEW_PV_VIEWS_DECODEROUTPUT_VIEW_HPP
 #define PULSEVIEW_PV_VIEWS_DECODEROUTPUT_VIEW_HPP
 
+#include <QComboBox>
+
 #include <pv/views/viewbase.hpp>
 
 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