From: Soeren Apel Date: Wed, 22 Mar 2017 21:45:41 +0000 (+0100) Subject: Introduce PV-internal channel types X-Git-Tag: pulseview-0.4.0~141 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=472a80c58cfdbd37cb00b5ba2ef4bcd923f9b54b;p=pulseview.git Introduce PV-internal channel types --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 06b3e1d8..ccdc1da7 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -30,15 +30,15 @@ using std::dynamic_pointer_cast; using std::shared_ptr; using sigrok::Channel; -using sigrok::ChannelType; namespace pv { namespace data { const int SignalBase::ColourBGAlpha = 8*256/100; -SignalBase::SignalBase(shared_ptr channel) : - channel_(channel) +SignalBase::SignalBase(shared_ptr channel, ChannelType channel_type) : + channel_(channel), + channel_type_(channel_type) { if (channel_) internal_name_ = QString::fromStdString(channel_->name()); @@ -82,9 +82,9 @@ void SignalBase::set_enabled(bool value) } } -const ChannelType *SignalBase::type() const +SignalBase::ChannelType SignalBase::type() const { - return (channel_) ? channel_->type() : nullptr; + return channel_type_; } unsigned int SignalBase::index() const @@ -119,7 +119,7 @@ void SignalBase::set_data(shared_ptr data) shared_ptr SignalBase::analog_data() const { - if (type() == ChannelType::ANALOG) + if (channel_type_ == AnalogChannel) return dynamic_pointer_cast(data_); else return shared_ptr(); @@ -127,7 +127,7 @@ shared_ptr SignalBase::analog_data() const shared_ptr SignalBase::logic_data() const { - if (type() == ChannelType::LOGIC) + if (channel_type_ == LogicChannel) return dynamic_pointer_cast(data_); else return shared_ptr(); diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 8b60c366..4889d16a 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -32,7 +32,6 @@ using std::shared_ptr; namespace sigrok { class Channel; -class ChannelType; } namespace pv { @@ -47,11 +46,20 @@ class SignalBase : public QObject { Q_OBJECT +public: + enum ChannelType { + AnalogChannel = 1, + LogicChannel, + DecodeChannel, + A2LChannel, // Analog converted to logic, joint representation + MathChannel + }; + private: static const int ColourBGAlpha; public: - SignalBase(shared_ptr channel); + SignalBase(shared_ptr channel, ChannelType channel_type); virtual ~SignalBase() {} public: @@ -74,7 +82,7 @@ public: /** * Gets the type of this channel. */ - const sigrok::ChannelType *type() const; + ChannelType type() const; /** * Gets the index number of this channel. @@ -147,6 +155,7 @@ Q_SIGNALS: private: shared_ptr channel_; + ChannelType channel_type_; shared_ptr data_; #ifdef ENABLE_DECODE diff --git a/pv/session.cpp b/pv/session.cpp index e84f7804..2712af12 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -89,7 +89,6 @@ using std::vector; using sigrok::Analog; using sigrok::Channel; -using sigrok::ChannelType; using sigrok::ConfigKey; using sigrok::DatafeedCallbackFunction; using sigrok::Error; @@ -638,7 +637,7 @@ bool Session::add_decoder(srd_decoder *const dec) // Auto select the initial channels for (const srd_channel *pdch : all_channels) for (shared_ptr b : signalbases_) { - if (b->type() == ChannelType::LOGIC) { + if (b->type() == data::SignalBase::LogicChannel) { if (QString::fromUtf8(pdch->name).toLower(). contains(b->name().toLower())) channels[pdch] = b; @@ -652,7 +651,7 @@ bool Session::add_decoder(srd_decoder *const dec) // Create the decode signal shared_ptr signalbase = - make_shared(nullptr); + make_shared(nullptr, data::SignalBase::DecodeChannel); signalbase->set_decoder_stack(decoder_stack); signalbases_.insert(signalbase); @@ -730,7 +729,7 @@ void Session::update_signals() unsigned int logic_channel_count = count_if( channels.begin(), channels.end(), [] (shared_ptr channel) { - return channel->type() == ChannelType::LOGIC; }); + return channel->type() == sigrok::ChannelType::LOGIC; }); // Create data containers for the logic data segments { @@ -780,7 +779,8 @@ void Session::update_signals() switch(channel->type()->id()) { case SR_CHANNEL_LOGIC: if (!signalbase) { - signalbase = make_shared(channel); + signalbase = make_shared(channel, + data::SignalBase::LogicChannel); signalbases_.insert(signalbase); all_signal_data_.insert(logic_data_); @@ -796,7 +796,8 @@ void Session::update_signals() case SR_CHANNEL_ANALOG: { if (!signalbase) { - signalbase = make_shared(channel); + signalbase = make_shared(channel, + data::SignalBase::AnalogChannel); signalbases_.insert(signalbase); shared_ptr data(new data::Analog()); diff --git a/pv/storesession.cpp b/pv/storesession.cpp index c2135ab3..3c5d899f 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -60,7 +60,6 @@ using std::vector; using Glib::VariantBase; -using sigrok::ChannelType; using sigrok::ConfigKey; using sigrok::Error; using sigrok::OutputFormat; @@ -115,7 +114,7 @@ bool StoreSession::start() if (!signal->enabled()) continue; - if (signal->type() == ChannelType::LOGIC) { + if (signal->type() == data::SignalBase::LogicChannel) { // All logic channels share the same data segments shared_ptr ldata = signal->logic_data(); @@ -131,7 +130,7 @@ bool StoreSession::start() any_segment = lsegment; } - if (signal->type() == ChannelType::ANALOG) { + if (signal->type() == data::SignalBase::AnalogChannel) { // Each analog channel has its own segments shared_ptr adata = signal->analog_data(); diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index c650ee14..5944fd64 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -877,7 +877,7 @@ QComboBox* DecodeTrace::create_channel_selector( for (const shared_ptr &b : sig_list) { assert(b); - if (b->type() == sigrok::ChannelType::LOGIC && b->enabled()) { + if (b->type() == data::SignalBase::LogicChannel && b->enabled()) { selector->addItem(b->name(), qVariantFromValue((void*)b.get()));