]> sigrok.org Git - pulseview.git/commitdiff
Initialise Trace widgets when the trace is received by the View
authorJoel Holdsworth <redacted>
Sat, 31 Aug 2013 14:56:49 +0000 (15:56 +0100)
committerJoel Holdsworth <redacted>
Tue, 3 Sep 2013 11:52:42 +0000 (12:52 +0100)
pv/view/analogsignal.cpp
pv/view/logicsignal.cpp
pv/view/logicsignal.h
pv/view/selectableitem.h
pv/view/signal.cpp
pv/view/signal.h
pv/view/timemarker.cpp
pv/view/timemarker.h
pv/view/view.cpp
pv/view/view.h

index 6b81fda77da324d8db0dec9ce6803758fad45a6a..6aeef98a57aa14f474e7b7d0fdcacbae8158a07a 100644 (file)
@@ -57,7 +57,7 @@ AnalogSignal::~AnalogSignal()
 const list<QAction*> AnalogSignal::get_context_bar_actions()
 {
        list<QAction*> actions;
-       actions.push_back(&_name_action);
+       actions.push_back(_name_action);
        return actions;
 }
 
index c8713114fbf1a8bea4e785a0e49b83958578da16..0c934cc72cb0f3de8a675332de3115deb86b9ee4 100644 (file)
@@ -58,64 +58,71 @@ LogicSignal::LogicSignal(pv::SigSession &session, const sr_probe *const probe,
        shared_ptr<data::Logic> data) :
        Signal(session, probe),
        _data(data),
-       _separator(this),
-       _icon_trigger_none(":/icons/trigger-none.svg"),
-       _trigger_none(_icon_trigger_none, tr("No trigger"), this),
-       _icon_trigger_rising(":/icons/trigger-rising.svg"),
-       _trigger_rising(_icon_trigger_rising,
-               tr("Trigger on rising edge"), this),
-       _icon_trigger_high(":/icons/trigger-high.svg"),
-       _trigger_high(_icon_trigger_high,
-               tr("Trigger on high level"), this),
-       _icon_trigger_falling(":/icons/trigger-falling.svg"),
-       _trigger_falling(_icon_trigger_falling,
-               tr("Trigger on falling edge"), this),
-       _icon_trigger_low(":/icons/trigger-low.svg"),
-       _trigger_low(_icon_trigger_low,
-               tr("Trigger on low level"), this),
-       _icon_trigger_change(":/icons/trigger-change.svg"),
-       _trigger_change(_icon_trigger_change,
-               tr("Trigger on rising or falling edge"), this)
+       _separator(NULL),
+       _trigger_none(NULL),
+       _trigger_rising(NULL),
+       _trigger_high(NULL),
+       _trigger_falling(NULL),
+       _trigger_low(NULL),
+       _trigger_change(NULL)
 {
        _colour = SignalColours[probe->index % countof(SignalColours)];
+}
+
+LogicSignal::~LogicSignal()
+{
+}
 
-       _separator.setSeparator(true);
+void LogicSignal::init_context_bar_actions(QWidget *parent)
+{
+       Signal::init_context_bar_actions(parent);
 
-       _trigger_none.setCheckable(true);
-       connect(&_trigger_none, SIGNAL(triggered()),
+       _separator = new QAction(parent);
+       _separator->setSeparator(true);
+
+       _trigger_none = new QAction(QIcon(":/icons/trigger-none.svg"),
+               tr("No trigger"), this);
+       _trigger_none->setCheckable(true);
+       connect(_trigger_none, SIGNAL(triggered()),
                this, SLOT(on_trigger_none()));
 
-       _trigger_rising.setCheckable(true);
-       connect(&_trigger_rising, SIGNAL(triggered()),
+       _trigger_rising = new QAction(QIcon(":/icons/trigger-rising.svg"),
+               tr("Trigger on rising edge"), this);
+       _trigger_rising->setCheckable(true);
+       connect(_trigger_rising, SIGNAL(triggered()),
                this, SLOT(on_trigger_rising()));
 
-       _trigger_high.setCheckable(true);
-       connect(&_trigger_high, SIGNAL(triggered()),
+       _trigger_high = new QAction(QIcon(":/icons/trigger-low.svg"),
+               tr("Trigger on high level"), this);
+       _trigger_high->setCheckable(true);
+       connect(_trigger_high, SIGNAL(triggered()),
                this, SLOT(on_trigger_high()));
 
-       _trigger_falling.setCheckable(true);
-       connect(&_trigger_falling, SIGNAL(triggered()),
+       _trigger_falling = new QAction(QIcon(":/icons/trigger-falling.svg"),
+               tr("Trigger on falling edge"), this);
+       _trigger_falling->setCheckable(true);
+       connect(_trigger_falling, SIGNAL(triggered()),
                this, SLOT(on_trigger_falling()));
 
-       _trigger_low.setCheckable(true);
-       connect(&_trigger_low, SIGNAL(triggered()),
+       _trigger_low = new QAction(QIcon(":/icons/trigger-low.svg"),
+               tr("Trigger on low level"), this);
+       _trigger_low->setCheckable(true);
+       connect(_trigger_low, SIGNAL(triggered()),
                this, SLOT(on_trigger_low()));
 
-       _trigger_change.setCheckable(true);
-       connect(&_trigger_change, SIGNAL(triggered()),
+       _trigger_change = new QAction(QIcon(":/icons/trigger-change.svg"),
+               tr("Trigger on rising or falling edge"), this);
+       _trigger_change->setCheckable(true);
+       connect(_trigger_change, SIGNAL(triggered()),
                this, SLOT(on_trigger_change()));
 }
 
-LogicSignal::~LogicSignal()
-{
-}
-
 const list<QAction*> LogicSignal::get_context_bar_actions()
 {
        GVariant *gvar;
        list<QAction*> actions;
 
-       actions.push_back(&_name_action);
+       actions.push_back(_name_action);
 
        // Add the trigger actions
        const sr_dev_inst *const sdi = _session.get_device();
@@ -125,20 +132,20 @@ const list<QAction*> LogicSignal::get_context_bar_actions()
                        g_variant_get_string(gvar, NULL);
 
                if (trig_types && trig_types[0] != '\0') {
-                       actions.push_back(&_separator);
+                       actions.push_back(_separator);
 
-                       actions.push_back(&_trigger_none);
+                       actions.push_back(_trigger_none);
 
                        add_trigger_action(trig_types, 'r',
-                               &_trigger_rising, actions);
+                               _trigger_rising, actions);
                        add_trigger_action(trig_types, '1',
-                               &_trigger_high, actions);
+                               _trigger_high, actions);
                        add_trigger_action(trig_types, 'f',
-                               &_trigger_falling, actions);
+                               _trigger_falling, actions);
                        add_trigger_action(trig_types, '0',
-                               &_trigger_low, actions);
+                               _trigger_low, actions);
                        add_trigger_action(trig_types, 'c',
-                               &_trigger_change, actions);
+                               _trigger_change, actions);
                
                        update_trigger_actions();
                }
@@ -263,12 +270,12 @@ void LogicSignal::update_trigger_actions()
 {
        const char cur_trigger = _probe->trigger ?
                _probe->trigger[0] : '\0';
-       _trigger_none.setChecked(cur_trigger == '\0');
-       _trigger_rising.setChecked(cur_trigger == 'r');
-       _trigger_high.setChecked(cur_trigger == '1');
-       _trigger_falling.setChecked(cur_trigger == 'f');
-       _trigger_low.setChecked(cur_trigger == '0');
-       _trigger_change.setChecked(cur_trigger == 'c');
+       _trigger_none->setChecked(cur_trigger == '\0');
+       _trigger_rising->setChecked(cur_trigger == 'r');
+       _trigger_high->setChecked(cur_trigger == '1');
+       _trigger_falling->setChecked(cur_trigger == 'f');
+       _trigger_low->setChecked(cur_trigger == '0');
+       _trigger_change->setChecked(cur_trigger == 'c');
 }
 
 void LogicSignal::set_trigger(char type)
index 37870be6ed23928115f1462802d51057e05e3b31..3b37c5d322ffe2b4b388f8c87cf1c82c0c88ac00 100644 (file)
@@ -52,6 +52,8 @@ public:
 
        virtual ~LogicSignal();
 
+       void init_context_bar_actions(QWidget *parent);
+
        const std::list<QAction*> get_context_bar_actions();
 
        /**
@@ -92,20 +94,14 @@ private slots:
 private:
        boost::shared_ptr<pv::data::Logic> _data;
 
-       QAction _separator;
-
-       QIcon _icon_trigger_none;
-       QAction _trigger_none;
-       QIcon _icon_trigger_rising;
-       QAction _trigger_rising;
-       QIcon _icon_trigger_high;
-       QAction _trigger_high;
-       QIcon _icon_trigger_falling;
-       QAction _trigger_falling;
-       QIcon _icon_trigger_low;
-       QAction _trigger_low;
-       QIcon _icon_trigger_change;
-       QAction _trigger_change;
+       QAction *_separator;
+
+       QAction *_trigger_none;
+       QAction *_trigger_rising;
+       QAction *_trigger_high;
+       QAction *_trigger_falling;
+       QAction *_trigger_low;
+       QAction *_trigger_change;
 };
 
 } // namespace view
index d38aca2eb534c3e65575b560d9288b591bda6479..467da0f2cbf0b7140edf87fb9e3be0b34b3c79e6 100644 (file)
@@ -52,6 +52,8 @@ public:
        void select(bool select = true);
 
 public:
+       virtual void init_context_bar_actions(QWidget *parent) = 0;
+
        virtual const std::list<QAction*> get_context_bar_actions() = 0;
 
 protected:
index 9b08336e3c64cc627f2e919a8a8b000383253017..0e1c7c729c77c4693c32a0afd38663c5ff54026f 100644 (file)
@@ -54,19 +54,25 @@ Signal::Signal(pv::SigSession &session, const sr_probe *const probe) :
        Trace(session, probe->name),
        _probe(probe),
        _name_action(NULL),
-       _name_widget(),
+       _name_widget(NULL),
        _updating_name_widget(false)
 {
        assert(_probe);
+}
+
+void Signal::init_context_bar_actions(QWidget *parent)
+{
+       _name_widget = new QComboBox(parent);
+       _name_widget->setEditable(true);
 
-       _name_action.setDefaultWidget(&_name_widget);
+       _name_action = new QWidgetAction(parent);
+       _name_action->setDefaultWidget(_name_widget);
 
-       _name_widget.setEditable(true);
        for(unsigned int i = 0; i < countof(ProbeNames); i++)
-               _name_widget.insertItem(i, ProbeNames[i]);
-       _name_widget.setEditText(probe->name);
+               _name_widget->insertItem(i, ProbeNames[i]);
+       _name_widget->setEditText(_probe->name);
 
-       connect(&_name_widget, SIGNAL(editTextChanged(const QString&)),
+       connect(_name_widget, SIGNAL(editTextChanged(const QString&)),
                this, SLOT(on_text_changed(const QString&)));
 }
 
@@ -74,7 +80,7 @@ void Signal::set_name(QString name)
 {
        Trace::set_name(name);
        _updating_name_widget = true;
-       _name_widget.setEditText(name);
+       _name_widget->setEditText(name);
        _updating_name_widget = false;
 }
 
index 81576dd4d19a9ef0a56465a8146c1f70e206ab08..ea336434f4ae5e7df9d39bfa61b610d067bd93f2 100644 (file)
@@ -50,6 +50,8 @@ protected:
        Signal(pv::SigSession &session, const sr_probe *const probe);
 
 public:
+       virtual void init_context_bar_actions(QWidget *parent);
+
        /**
         * Sets the name of the signal.
         */
@@ -77,8 +79,8 @@ private slots:
 protected:
        const sr_probe *const _probe;
 
-       QWidgetAction _name_action;
-       QComboBox _name_widget;
+       QWidgetAction *_name_action;
+       QComboBox *_name_widget;
        bool _updating_name_widget;
 };
 
index 03749689cb44aa602f5ce12e68affb55c821d5d9..5907631a671f463efa3e479bf340c9b31b4c4633 100644 (file)
@@ -33,18 +33,24 @@ TimeMarker::TimeMarker(View &view, const QColor &colour, double time) :
        _view(view),
        _colour(colour),
        _time(time),
-       _value_action(&view),
-       _value_widget(&view),
+       _value_action(NULL),
+       _value_widget(NULL),
        _updating_value_widget(false)
 {
-       _value_action.setDefaultWidget(&_value_widget);
+}
+
+void TimeMarker::init_context_bar_actions(QWidget *parent)
+{
+       _value_widget = new QDoubleSpinBox(parent);
+       _value_widget->setValue(_time);
+       _value_widget->setDecimals(6);
+       _value_widget->setSuffix("s");
+       _value_widget->setSingleStep(1e-6);
 
-       _value_widget.setValue(time);
-       _value_widget.setDecimals(6);
-       _value_widget.setSuffix("s");
-       _value_widget.setSingleStep(1e-6);
+       _value_action = new QWidgetAction(parent);
+       _value_action->setDefaultWidget(_value_widget);
 
-       connect(&_value_widget, SIGNAL(valueChanged(double)),
+       connect(_value_widget, SIGNAL(valueChanged(double)),
                this, SLOT(on_value_changed(double)));
 }
 
@@ -57,7 +63,7 @@ void TimeMarker::set_time(double time)
 {
        _time = time;
        _updating_value_widget = true;
-       _value_widget.setValue(time);
+       _value_widget->setValue(time);
        _updating_value_widget = false;
        time_changed();
 }
@@ -72,7 +78,7 @@ void TimeMarker::paint(QPainter &p, const QRect &rect)
 const list<QAction*> TimeMarker::get_context_bar_actions()
 {
        list<QAction*> actions;
-       actions.push_back(&_value_action);
+       actions.push_back(_value_action);
        return actions;
 }
 
index 63733f7a5c9a4a9040f4660db5b0ebf152c490c0..328d428f0e52ca547c48840d5a4071e247c78e14 100644 (file)
@@ -51,6 +51,8 @@ protected:
        TimeMarker(View &view, const QColor &colour, double time);
 
 public:
+       virtual void init_context_bar_actions(QWidget *parent);
+       
        /**
         * Gets the time of the marker.
         */
@@ -104,8 +106,8 @@ protected:
 
        QSizeF _text_size;
 
-       QWidgetAction _value_action;
-       QDoubleSpinBox _value_widget;
+       QWidgetAction *_value_action;
+       QDoubleSpinBox *_value_widget;
        bool _updating_value_widget;
 };
 
index ca575bec2ebc0e0258e3ee08490e1f6b5e111b8d..3619ba0694d8f4bc48c5c8a97368e9f005192a9e 100644 (file)
@@ -275,18 +275,6 @@ void View::update_scroll()
                areaSize.height());
 }
 
-void View::reset_signal_layout()
-{
-       int offset = SignalMargin + SignalHeight;
-       const vector< shared_ptr<Signal> > sigs(_session.get_signals());
-       BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
-               s->set_v_offset(offset);
-               offset += SignalHeight + 2 * SignalMargin;
-       }
-
-       normalize_layout();
-}
-
 bool View::eventFilter(QObject *object, QEvent *event)
 {
        const QEvent::Type type = event->type();
@@ -364,7 +352,15 @@ void View::v_scroll_value_changed(int value)
 
 void View::signals_changed()
 {
-       reset_signal_layout();
+       int offset = SignalMargin + SignalHeight;
+       const vector< shared_ptr<Signal> > sigs(_session.get_signals());
+       BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
+               s->init_context_bar_actions(NULL);
+               s->set_v_offset(offset);
+               offset += SignalHeight + 2 * SignalMargin;
+       }
+
+       normalize_layout();
 }
 
 void View::data_updated()
index 99c124733bfe094b69f7f48c3f46dbe77ff4659c..f378e9116c24a6ccb0b3376cf2fe7d77ac18b7ba 100644 (file)
@@ -131,8 +131,6 @@ private:
        
        void update_scroll();
 
-       void reset_signal_layout();
-
 private:
        bool eventFilter(QObject *object, QEvent *event);