From: Joel Holdsworth Date: Sat, 31 Aug 2013 14:56:49 +0000 (+0100) Subject: Initialise Trace widgets when the trace is received by the View X-Git-Tag: pulseview-0.2.0~324 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ef8311a4296a2dc85c82b063de61efa4eb7a8404;p=pulseview.git Initialise Trace widgets when the trace is received by the View --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 6b81fda7..6aeef98a 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -57,7 +57,7 @@ AnalogSignal::~AnalogSignal() const list AnalogSignal::get_context_bar_actions() { list actions; - actions.push_back(&_name_action); + actions.push_back(_name_action); return actions; } diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index c8713114..0c934cc7 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -58,64 +58,71 @@ LogicSignal::LogicSignal(pv::SigSession &session, const sr_probe *const probe, shared_ptr 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 LogicSignal::get_context_bar_actions() { GVariant *gvar; list 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 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) diff --git a/pv/view/logicsignal.h b/pv/view/logicsignal.h index 37870be6..3b37c5d3 100644 --- a/pv/view/logicsignal.h +++ b/pv/view/logicsignal.h @@ -52,6 +52,8 @@ public: virtual ~LogicSignal(); + void init_context_bar_actions(QWidget *parent); + const std::list get_context_bar_actions(); /** @@ -92,20 +94,14 @@ private slots: private: boost::shared_ptr _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 diff --git a/pv/view/selectableitem.h b/pv/view/selectableitem.h index d38aca2e..467da0f2 100644 --- a/pv/view/selectableitem.h +++ b/pv/view/selectableitem.h @@ -52,6 +52,8 @@ public: void select(bool select = true); public: + virtual void init_context_bar_actions(QWidget *parent) = 0; + virtual const std::list get_context_bar_actions() = 0; protected: diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 9b08336e..0e1c7c72 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -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; } diff --git a/pv/view/signal.h b/pv/view/signal.h index 81576dd4..ea336434 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -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; }; diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 03749689..5907631a 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -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 TimeMarker::get_context_bar_actions() { list actions; - actions.push_back(&_value_action); + actions.push_back(_value_action); return actions; } diff --git a/pv/view/timemarker.h b/pv/view/timemarker.h index 63733f7a..328d428f 100644 --- a/pv/view/timemarker.h +++ b/pv/view/timemarker.h @@ -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; }; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index ca575bec..3619ba06 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -275,18 +275,6 @@ void View::update_scroll() areaSize.height()); } -void View::reset_signal_layout() -{ - int offset = SignalMargin + SignalHeight; - const vector< shared_ptr > sigs(_session.get_signals()); - BOOST_FOREACH(shared_ptr 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 > sigs(_session.get_signals()); + BOOST_FOREACH(shared_ptr s, sigs) { + s->init_context_bar_actions(NULL); + s->set_v_offset(offset); + offset += SignalHeight + 2 * SignalMargin; + } + + normalize_layout(); } void View::data_updated() diff --git a/pv/view/view.h b/pv/view/view.h index 99c12473..f378e911 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -131,8 +131,6 @@ private: void update_scroll(); - void reset_signal_layout(); - private: bool eventFilter(QObject *object, QEvent *event);