X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fview%2Flogicsignal.cpp;h=d9987170f06e1f18770fc6509310305196238beb;hb=18f7104f875a71bceeb152398b682737528a4ad7;hp=e214ec78426c505d621808fb38e9e5f34dc65462;hpb=b86aa8f4a22857a90bbfca6e7993b2deaf1157d4;p=pulseview.git diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index e214ec78..d9987170 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -30,6 +32,7 @@ #include "view.h" #include +#include #include #include #include @@ -48,6 +51,8 @@ using sigrok::ConfigKey; using sigrok::Device; using sigrok::Error; using sigrok::Trigger; +using sigrok::TriggerStage; +using sigrok::TriggerMatch; using sigrok::TriggerMatchType; namespace pv { @@ -94,7 +99,7 @@ LogicSignal::LogicSignal( /* Populate this channel's trigger setting with whatever we * find in the current session trigger, if anything. */ _trigger_match = nullptr; - if ((trigger = SigSession::_sr_session->trigger())) + if ((trigger = _session.session()->trigger())) for (auto stage : trigger->stages()) for (auto match : stage->matches()) if (match->channel() == _channel) @@ -133,9 +138,8 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right) assert(_data); assert(right >= left); - assert(_view); - const int y = _v_offset - _view->v_offset(); - + const int y = get_y(); + const double scale = _view->scale(); assert(scale > 0); @@ -260,24 +264,26 @@ QAction* LogicSignal::match_action(const TriggerMatchType *type) QAction *action; action = _trigger_none; - switch (type->id()) { - case SR_TRIGGER_ZERO: - action = _trigger_low; - break; - case SR_TRIGGER_ONE: - action = _trigger_high; - break; - case SR_TRIGGER_RISING: - action = _trigger_rising; - break; - case SR_TRIGGER_FALLING: - action = _trigger_falling; - break; - case SR_TRIGGER_EDGE: - action = _trigger_change; - break; - default: - assert(0); + if (type) { + switch (type->id()) { + case SR_TRIGGER_ZERO: + action = _trigger_low; + break; + case SR_TRIGGER_ONE: + action = _trigger_high; + break; + case SR_TRIGGER_RISING: + action = _trigger_rising; + break; + case SR_TRIGGER_FALLING: + action = _trigger_falling; + break; + case SR_TRIGGER_EDGE: + action = _trigger_change; + break; + default: + assert(0); + } } return action; @@ -315,6 +321,7 @@ void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form) _trigger_bar = new QToolBar(parent); init_trigger_actions(_trigger_bar); _trigger_bar->addAction(_trigger_none); + _trigger_none->setChecked(!_trigger_match); trig_types = Glib::VariantBase::cast_dynamic>>( gvar).get(); @@ -327,6 +334,35 @@ void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form) } +void LogicSignal::modify_trigger() +{ + auto trigger = _session.session()->trigger(); + auto new_trigger = _session.device_manager().context()->create_trigger("pulseview"); + + if (trigger) { + for (auto stage : trigger->stages()) { + const auto &matches = stage->matches(); + if (std::none_of(begin(matches), end(matches), + [&](shared_ptr match) { + return match->channel() != _channel; })) + continue; + + auto new_stage = new_trigger->add_stage(); + for (auto match : stage->matches()) { + if (match->channel() == _channel) + continue; + new_stage->add_match(match->channel(), match->type()); + } + } + } + + if (_trigger_match) + new_trigger->add_stage()->add_match(_channel, _trigger_match); + + _session.session()->set_trigger( + new_trigger->stages().empty() ? nullptr : new_trigger); +} + void LogicSignal::on_trigger() { QAction *action; @@ -337,6 +373,7 @@ void LogicSignal::on_trigger() action->setChecked(true); _trigger_match = action_match(action); + modify_trigger(); } } // namespace view