]> sigrok.org Git - pulseview.git/commitdiff
Added a label context bar action
authorJoel Holdsworth <redacted>
Sun, 19 May 2013 11:24:17 +0000 (12:24 +0100)
committerJoel Holdsworth <redacted>
Sun, 19 May 2013 11:24:53 +0000 (12:24 +0100)
pv/view/analogsignal.cpp
pv/view/header.cpp
pv/view/header.h
pv/view/logicsignal.cpp
pv/view/signal.cpp
pv/view/signal.h

index fff11f12eacfc368d914a145b52940b4ea501598..7c906b52db8f6d74b79ae9f4d35e39bb661e0b9f 100644 (file)
@@ -57,6 +57,7 @@ AnalogSignal::~AnalogSignal()
 const list<QAction*> AnalogSignal::get_context_bar_actions()
 {
        list<QAction*> actions;
+       actions.push_back(&_name_action);
        return actions;
 }
 
index d9f6666d266d0d420563c3a66b7dd58c0128061c..fd40e216e196f0bd6b7a2fb09c52bf70061edcf3 100644 (file)
@@ -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<Signal> > sigs(_view.session().get_signals());
+       BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
+               assert(s);
+               connect(s.get(), SIGNAL(text_changed()), this, SLOT(update()));
+       }
+}
+
 void Header::on_signals_moved()
 {
        update();
index cb1d36246c3d76abb40b21ef89c7905f3f7062cf..22e8e4dbd2c3dbba58908d6a7a7a1208339bdfb0 100644 (file)
@@ -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();
index e071e720b33991a34f21e0ec240874c7f17a783d..e0b21309cc9841d5064a309920c187dc89251d88 100644 (file)
@@ -67,6 +67,7 @@ LogicSignal::~LogicSignal()
 const list<QAction*> LogicSignal::get_context_bar_actions()
 {
        list<QAction*> actions;
+       actions.push_back(&_name_action);
        return actions;
 }
 
index ae180e19a47a228a35f8d1151658b3f1b14973c2..bb86d8cb6d0add9c3585c8690dee22c60d06579a 100644 (file)
@@ -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
index ece2e5a446218591f066a435454004a550b267f3..5732e19d5f45e632630d382ddcc5b36ef581f8fe 100644 (file)
 #include <boost/shared_ptr.hpp>
 
 #include <QColor>
+#include <QComboBox>
 #include <QPainter>
 #include <QPen>
 #include <QRect>
 #include <QString>
+#include <QWidgetAction>
 
 #include <stdint.h>
 
@@ -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