]> sigrok.org Git - pulseview.git/blobdiff - pv/session.cpp
Rework decode channel auto-assignment
[pulseview.git] / pv / session.cpp
index 516e1acd5ad6ff1e6b52a277f97c042e28e37872..07917e582ff2846d537fecaf755dfa4e125daae7 100644 (file)
@@ -53,6 +53,7 @@
 
 #ifdef ENABLE_DECODE
 #include <libsigrokdecode/libsigrokdecode.h>
+#include "data/decodesignal.hpp"
 #endif
 
 using std::bad_alloc;
@@ -437,10 +438,10 @@ void Session::set_default_device()
 /**
  * Convert generic options to data types that are specific to InputFormat.
  *
- * @param[in] user_spec vector of tokenized words, string format
- * @param[in] fmt_opts input format's options, result of InputFormat::options()
+ * @param[in] user_spec Vector of tokenized words, string format.
+ * @param[in] fmt_opts Input format's options, result of InputFormat::options().
  *
- * @return map of options suitable for InputFormat::create_input()
+ * @return Map of options suitable for InputFormat::create_input().
  */
 map<string, Glib::VariantBase>
 Session::input_format_options(vector<string> user_spec,
@@ -664,37 +665,19 @@ bool Session::add_decoder(srd_decoder *const dec)
                // Create the decoder
                decoder_stack = make_shared<data::DecoderStack>(*this, dec);
 
-               // Make a list of all the channels
-               vector<const srd_channel*> all_channels;
-               for (const GSList *i = dec->channels; i; i = i->next)
-                       all_channels.push_back((const srd_channel*)i->data);
-               for (const GSList *i = dec->opt_channels; i; i = i->next)
-                       all_channels.push_back((const srd_channel*)i->data);
-
-               // Auto select the initial channels
-               for (const srd_channel *pdch : all_channels)
-                       for (shared_ptr<data::SignalBase> b : signalbases_) {
-                               if (b->logic_data()) {
-                                       if (QString::fromUtf8(pdch->name).toLower().
-                                               contains(b->name().toLower()))
-                                               channels[pdch] = b;
-                               }
-                       }
-
                assert(decoder_stack);
                assert(!decoder_stack->stack().empty());
                assert(decoder_stack->stack().front());
                decoder_stack->stack().front()->set_channels(channels);
 
                // Create the decode signal
-               shared_ptr<data::SignalBase> signalbase =
-                       make_shared<data::SignalBase>(nullptr, data::SignalBase::DecodeChannel);
+               shared_ptr<data::DecodeSignal> signal =
+                       make_shared<data::DecodeSignal>(decoder_stack, signalbases_);
 
-               signalbase->set_decoder_stack(decoder_stack);
-               signalbases_.insert(signalbase);
+               signalbases_.insert(signal);
 
                for (shared_ptr<views::ViewBase> view : views_)
-                       view->add_decode_signal(signalbase);
+                       view->add_decode_signal(signal);
        } catch (runtime_error e) {
                return false;
        }
@@ -707,12 +690,12 @@ bool Session::add_decoder(srd_decoder *const dec)
        return true;
 }
 
-void Session::remove_decode_signal(shared_ptr<data::SignalBase> signalbase)
+void Session::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
 {
-       signalbases_.erase(signalbase);
+       signalbases_.erase(signal);
 
        for (shared_ptr<views::ViewBase> view : views_)
-               view->remove_decode_signal(signalbase);
+               view->remove_decode_signal(signal);
 
        signals_changed();
 }