]> sigrok.org Git - pulseview.git/blobdiff - pv/view/logicsignal.cpp
icons: Added trigger markers
[pulseview.git] / pv / view / logicsignal.cpp
index 1b873e24fd797cb9addb787a6043144b9300e568..c58b85d9857a2a622c6e7cf51b3674be7b77a48a 100644 (file)
 #include <QFormLayout>
 #include <QToolBar>
 
-#include "logicsignal.h"
-#include "view.h"
+#include "logicsignal.hpp"
+#include "view.hpp"
 
-#include <pv/sigsession.h>
-#include <pv/devicemanager.h>
-#include <pv/data/logic.h>
-#include <pv/data/logicsnapshot.h>
-#include <pv/view/view.h>
+#include <pv/sigsession.hpp>
+#include <pv/devicemanager.hpp>
+#include <pv/data/logic.hpp>
+#include <pv/data/logicsnapshot.hpp>
+#include <pv/view/view.hpp>
 
 #include <libsigrok/libsigrok.hpp>
 
@@ -82,7 +82,7 @@ const QColor LogicSignal::SignalColours[10] = {
 };
 
 LogicSignal::LogicSignal(
-       pv::SigSession &session,
+       pv::Session &session,
        shared_ptr<Device> device,
        shared_ptr<Channel> channel,
        shared_ptr<data::Logic> data) :
@@ -272,7 +272,19 @@ void LogicSignal::init_trigger_actions(QWidget *parent)
        connect(trigger_change_, SIGNAL(triggered()), this, SLOT(on_trigger()));
 }
 
-QAction* LogicSignal::match_action(const TriggerMatchType *type)
+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;
 
@@ -302,7 +314,7 @@ QAction* LogicSignal::match_action(const TriggerMatchType *type)
        return action;
 }
 
-const TriggerMatchType *LogicSignal::action_match(QAction *action)
+const TriggerMatchType *LogicSignal::trigger_type_from_action(QAction *action)
 {
        if (action == trigger_low_)
                return TriggerMatchType::ZERO;
@@ -320,28 +332,20 @@ const TriggerMatchType *LogicSignal::action_match(QAction *action)
 
 void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
 {
-       Glib::VariantContainerBase gvar;
-       vector<int32_t> trig_types;
-
        Signal::populate_popup_form(parent, form);
 
-       try {
-               gvar = device_->config_list(ConfigKey::TRIGGER_MATCH);
-       } catch (Error e) {
-               return;
-       }
-
        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<Glib::Variant<vector<int32_t>>>(
-                       gvar).get();
+
+       const vector<int32_t> trig_types = get_trigger_types();
        for (auto type_id : trig_types) {
-               auto type = TriggerMatchType::get(type_id);
-               trigger_bar_->addAction(match_action(type));
-               match_action(type)->setChecked(trigger_match_ == type);
+               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_);
 
@@ -380,11 +384,11 @@ void LogicSignal::on_trigger()
 {
        QAction *action;
 
-       match_action(trigger_match_)->setChecked(false);
+       action_from_trigger_type(trigger_match_)->setChecked(false);
 
        action = (QAction *)sender();
        action->setChecked(true);
-       trigger_match_ = action_match(action);
+       trigger_match_ = trigger_type_from_action(action);
 
        modify_trigger();
 }