+ trigger_none_ = new QAction(*get_icon(":/icons/trigger-none.svg"),
+ tr("No trigger"), parent);
+ trigger_none_->setCheckable(true);
+ connect(trigger_none_, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ trigger_rising_ = new QAction(*get_icon(":/icons/trigger-rising.svg"),
+ tr("Trigger on rising edge"), parent);
+ trigger_rising_->setCheckable(true);
+ connect(trigger_rising_, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ trigger_high_ = new QAction(*get_icon(":/icons/trigger-high.svg"),
+ tr("Trigger on high level"), parent);
+ trigger_high_->setCheckable(true);
+ connect(trigger_high_, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ trigger_falling_ = new QAction(*get_icon(":/icons/trigger-falling.svg"),
+ tr("Trigger on falling edge"), parent);
+ trigger_falling_->setCheckable(true);
+ connect(trigger_falling_, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ trigger_low_ = new QAction(*get_icon(":/icons/trigger-low.svg"),
+ tr("Trigger on low level"), parent);
+ trigger_low_->setCheckable(true);
+ connect(trigger_low_, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ trigger_change_ = new QAction(*get_icon(":/icons/trigger-change.svg"),
+ tr("Trigger on rising or falling edge"), parent);
+ trigger_change_->setCheckable(true);
+ connect(trigger_change_, SIGNAL(triggered()), this, SLOT(on_trigger()));
+}
+
+const vector<int32_t> LogicSignal::get_trigger_types() const
+{
+ try {
+ const Glib::VariantContainerBase gvar =
+ device_->config_list(ConfigKey::TRIGGER_MATCH);
+ return Glib::VariantBase::cast_dynamic<
+ Glib::Variant<vector<int32_t>>>(gvar).get();
+ } catch (Error e) {
+ return vector<int32_t>();
+ }
+}
+
+QAction* LogicSignal::action_from_trigger_type(const TriggerMatchType *type)
+{
+ QAction *action;
+
+ action = trigger_none_;
+ 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;
+}
+
+const TriggerMatchType *LogicSignal::trigger_type_from_action(QAction *action)
+{
+ if (action == trigger_low_)
+ return TriggerMatchType::ZERO;
+ else if (action == trigger_high_)
+ return TriggerMatchType::ONE;
+ else if (action == trigger_rising_)
+ return TriggerMatchType::RISING;
+ else if (action == trigger_falling_)
+ return TriggerMatchType::FALLING;
+ else if (action == trigger_change_)
+ return TriggerMatchType::EDGE;
+ else
+ return nullptr;
+}
+
+void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
+{
+ Signal::populate_popup_form(parent, form);
+
+ trigger_bar_ = new QToolBar(parent);
+ init_trigger_actions(trigger_bar_);
+ trigger_bar_->addAction(trigger_none_);
+ trigger_none_->setChecked(!trigger_match_);
+
+ const vector<int32_t> trig_types = get_trigger_types();
+ for (auto type_id : trig_types) {
+ const TriggerMatchType *const type =
+ TriggerMatchType::get(type_id);
+ QAction *const action = action_from_trigger_type(type);
+ trigger_bar_->addAction(action);
+ action->setChecked(trigger_match_ == type);
+ }
+ form->addRow(tr("Trigger"), trigger_bar_);
+
+}
+
+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<TriggerMatch> 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);
+
+ if (owner_)
+ owner_->row_item_appearance_changed(false, true);
+}
+
+const QIcon* LogicSignal::get_icon(const char *path)
+{
+ const QIcon *icon = icon_cache_.take(path);
+ if (!icon) {
+ icon = new QIcon(path);
+ icon_cache_.insert(path, icon);
+ }
+
+ return icon;
+}
+
+const QPixmap* LogicSignal::get_pixmap(const char *path)
+{
+ const QPixmap *pixmap = pixmap_cache_.take(path);
+ if (!pixmap) {
+ pixmap = new QPixmap(path);
+ pixmap_cache_.insert(path, pixmap);
+ }
+
+ return pixmap;
+}
+
+void LogicSignal::on_trigger()
+{
+ QAction *action;
+
+ action_from_trigger_type(trigger_match_)->setChecked(false);
+
+ action = (QAction *)sender();
+ action->setChecked(true);
+ trigger_match_ = trigger_type_from_action(action);
+
+ modify_trigger();