From 9e40e83daf6a2851f4883468a4237849f984b336 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 19 May 2013 12:24:17 +0100 Subject: [PATCH] Added a label context bar action --- pv/view/analogsignal.cpp | 1 + pv/view/header.cpp | 12 ++++++++++++ pv/view/header.h | 2 ++ pv/view/logicsignal.cpp | 1 + pv/view/signal.cpp | 41 +++++++++++++++++++++++++++++++++++++++- pv/view/signal.h | 12 ++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index fff11f12..7c906b52 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -57,6 +57,7 @@ AnalogSignal::~AnalogSignal() const list AnalogSignal::get_context_bar_actions() { list actions; + actions.push_back(&_name_action); return actions; } diff --git a/pv/view/header.cpp b/pv/view/header.cpp index d9f6666d..fd40e216 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -54,6 +54,9 @@ Header::Header(View &parent) : connect(_action_set_colour, SIGNAL(triggered()), this, SLOT(on_action_set_colour_triggered())); + connect(&_view.session(), SIGNAL(signals_changed()), + this, SLOT(on_signals_changed())); + connect(&_view, SIGNAL(signals_moved()), this, SLOT(on_signals_moved())); } @@ -256,6 +259,15 @@ void Header::on_action_set_colour_triggered() context_signal->set_colour(new_colour); } +void Header::on_signals_changed() +{ + const vector< shared_ptr > sigs(_view.session().get_signals()); + BOOST_FOREACH(shared_ptr s, sigs) { + assert(s); + connect(s.get(), SIGNAL(text_changed()), this, SLOT(update())); + } +} + void Header::on_signals_moved() { update(); diff --git a/pv/view/header.h b/pv/view/header.h index cb1d3624..22e8e4db 100644 --- a/pv/view/header.h +++ b/pv/view/header.h @@ -63,6 +63,8 @@ private: void contextMenuEvent(QContextMenuEvent *event); private slots: + void on_signals_changed(); + void on_action_set_name_triggered(); void on_action_set_colour_triggered(); diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index e071e720..e0b21309 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -67,6 +67,7 @@ LogicSignal::~LogicSignal() const list LogicSignal::get_context_bar_actions() { list actions; + actions.push_back(&_name_action); return actions; } diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index ae180e19..bb86d8cb 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -35,12 +35,42 @@ const int Signal::LabelHitPadding = 2; const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64)); +const char *const ProbeNames[] = { + "CLK", + "DATA", + "IN", + "OUT", + "RST", + "Tx", + "Rx", + "EN", + "SCLK", + "MOSI", + "MISO", + "/SS", + "SDA", + "SCL" +}; + Signal::Signal(const sr_probe *const probe) : _probe(probe), _name(probe->name), - _v_offset(0) + _v_offset(0), + _name_action(NULL), + _name_widget(), + _updating_name_widget(false) { assert(_probe); + + _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); + + connect(&_name_widget, SIGNAL(editTextChanged(const QString&)), + this, SLOT(on_text_changed(const QString&))); } QString Signal::get_name() const @@ -51,6 +81,9 @@ QString Signal::get_name() const void Signal::set_name(QString name) { _name = name; + _updating_name_widget = true; + _name_widget.setEditText(name); + _updating_name_widget = false; } QColor Signal::get_colour() const @@ -165,5 +198,11 @@ QRectF Signal::get_label_rect(int y, int right) label_size.width(), label_size.height()); } +void Signal::on_text_changed(const QString &text) +{ + _name = text; + text_changed(); +} + } // namespace view } // namespace pv diff --git a/pv/view/signal.h b/pv/view/signal.h index ece2e5a4..5732e19d 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -24,10 +24,12 @@ #include #include +#include #include #include #include #include +#include #include @@ -150,6 +152,12 @@ private: */ QRectF get_label_rect(int y, int right); +private slots: + void on_text_changed(const QString &text); + +signals: + void text_changed(); + protected: const sr_probe *const _probe; @@ -158,6 +166,10 @@ protected: int _v_offset; QSizeF _text_size; + + QWidgetAction _name_action; + QComboBox _name_widget; + bool _updating_name_widget; }; } // namespace view -- 2.30.2