]> sigrok.org Git - pulseview.git/commitdiff
Renamed DecodeSignal to DecodeTrace
authorJoel Holdsworth <redacted>
Sat, 26 Oct 2013 11:54:58 +0000 (12:54 +0100)
committerJoel Holdsworth <redacted>
Tue, 19 Nov 2013 19:32:10 +0000 (19:32 +0000)
CMakeLists.txt
pv/sigsession.cpp
pv/sigsession.h
pv/view/decodesignal.cpp [deleted file]
pv/view/decodesignal.h [deleted file]
pv/view/decodetrace.cpp [new file with mode: 0644]
pv/view/decodetrace.h [new file with mode: 0644]
pv/view/view.cpp
test/CMakeLists.txt
test/data/decoder.cpp

index 03d856b7bf923407622b250ca792afef9a5bacd6..ca89c107374f0aac953bc342d7c82bc942e5e085 100644 (file)
@@ -129,7 +129,7 @@ set(pulseview_SOURCES
        pv/view/analogsignal.cpp
        pv/view/cursor.cpp
        pv/view/cursorpair.cpp
-       pv/view/decodesignal.cpp
+       pv/view/decodetrace.cpp
        pv/view/header.cpp
        pv/view/marginwidget.cpp
        pv/view/logicsignal.cpp
@@ -166,7 +166,7 @@ set(pulseview_HEADERS
        pv/prop/string.h
        pv/toolbars/samplingbar.h
        pv/view/cursor.h
-       pv/view/decodesignal.h
+       pv/view/decodetrace.h
        pv/view/header.h
        pv/view/logicsignal.h
        pv/view/marginwidget.h
index aeb6d22072f55f6bc49c04dd389295fd852b5c6a..24a059ea8a35f03340461aac434047231087ec05 100644 (file)
@@ -31,7 +31,7 @@
 #include "data/logicsnapshot.h"
 
 #include "view/analogsignal.h"
-#include "view/decodesignal.h"
+#include "view/decodetrace.h"
 #include "view/logicsignal.h"
 
 #include <assert.h>
@@ -227,8 +227,8 @@ bool SigSession::add_decoder(srd_decoder *const dec)
                decoder->set_probes(probes);
 
                // Create the decode signal
-               shared_ptr<view::DecodeSignal> d(
-                       new view::DecodeSignal(*this, decoder,
+               shared_ptr<view::DecodeTrace> d(
+                       new view::DecodeTrace(*this, decoder,
                                _decode_traces.size()));
                _decode_traces.push_back(d);
        }
@@ -242,15 +242,15 @@ bool SigSession::add_decoder(srd_decoder *const dec)
        return true;
 }
 
-vector< shared_ptr<view::DecodeSignal> > SigSession::get_decode_signals() const
+vector< shared_ptr<view::DecodeTrace> > SigSession::get_decode_signals() const
 {
        lock_guard<mutex> lock(_signals_mutex);
        return _decode_traces;
 }
 
-void SigSession::remove_decode_signal(view::DecodeSignal *signal)
+void SigSession::remove_decode_signal(view::DecodeTrace *signal)
 {
-       for (vector< shared_ptr<view::DecodeSignal> >::iterator i =
+       for (vector< shared_ptr<view::DecodeTrace> >::iterator i =
                _decode_traces.begin();
                i != _decode_traces.end();
                i++)
index 801c0a57c60c67066ef04d3d61a9b6a6eb5889d8..980fef947192e2ecb06202400b7d4dc6650ab08c 100644 (file)
@@ -49,7 +49,7 @@ class LogicSnapshot;
 }
 
 namespace view {
-class DecodeSignal;
+class DecodeTrace;
 class LogicSignal;
 class Signal;
 }
@@ -96,10 +96,10 @@ public:
 
        bool add_decoder(srd_decoder *const dec);
 
-       std::vector< boost::shared_ptr<view::DecodeSignal> >
+       std::vector< boost::shared_ptr<view::DecodeTrace> >
                get_decode_signals() const;
 
-       void remove_decode_signal(view::DecodeSignal *signal);
+       void remove_decode_signal(view::DecodeTrace *signal);
 
 private:
        void set_capture_state(capture_state state);
@@ -159,7 +159,7 @@ private:
         */
        struct sr_dev_inst *_sdi;
 
-       std::vector< boost::shared_ptr<view::DecodeSignal> > _decode_traces;
+       std::vector< boost::shared_ptr<view::DecodeTrace> > _decode_traces;
 
        mutable boost::mutex _sampling_mutex;
        capture_state _capture_state;
diff --git a/pv/view/decodesignal.cpp b/pv/view/decodesignal.cpp
deleted file mode 100644 (file)
index 9f81ab4..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
- */
-
-extern "C" {
-#include <libsigrokdecode/libsigrokdecode.h>
-}
-
-#include <extdef.h>
-
-#include <boost/foreach.hpp>
-
-#include <QAction>
-#include <QComboBox>
-#include <QFormLayout>
-#include <QLabel>
-#include <QMenu>
-
-#include "decodesignal.h"
-
-#include <pv/sigsession.h>
-#include <pv/data/decoder.h>
-#include <pv/view/logicsignal.h>
-#include <pv/view/view.h>
-#include <pv/view/decode/annotation.h>
-
-using namespace boost;
-using namespace std;
-
-namespace pv {
-namespace view {
-
-const QColor DecodeSignal::DecodeColours[4] = {
-       QColor(0xEF, 0x29, 0x29),       // Red
-       QColor(0xFC, 0xE9, 0x4F),       // Yellow
-       QColor(0x8A, 0xE2, 0x34),       // Green
-       QColor(0x72, 0x9F, 0xCF)        // Blue
-};
-
-const QColor DecodeSignal::ErrorBgColour = QColor(0xEF, 0x29, 0x29);
-
-DecodeSignal::DecodeSignal(pv::SigSession &session,
-       boost::shared_ptr<pv::data::Decoder> decoder, int index) :
-       Trace(session, QString(decoder->decoder()->name)),
-       _decoder(decoder),
-       _binding(decoder)
-{
-       assert(_decoder);
-
-       _colour = DecodeColours[index % countof(DecodeColours)];
-
-       connect(_decoder.get(), SIGNAL(new_decode_data()),
-               this, SLOT(on_new_decode_data()));
-}
-
-bool DecodeSignal::enabled() const
-{
-       return true;
-}
-
-const boost::shared_ptr<pv::data::Decoder>& DecodeSignal::decoder() const
-{
-       return _decoder;
-}
-
-void DecodeSignal::set_view(pv::view::View *view)
-{
-       assert(view);
-       Trace::set_view(view);
-}
-
-void DecodeSignal::paint_back(QPainter &p, int left, int right)
-{
-       paint_axis(p, get_y(), left, right);
-}
-
-void DecodeSignal::paint_mid(QPainter &p, int left, int right)
-{
-       using namespace pv::view::decode;
-
-       assert(_decoder);
-       const QString err = _decoder->error_message();
-       if (!err.isEmpty()) {
-               draw_error(p, err, left, right);
-               return;
-       }
-
-       assert(_view);
-       const int y = get_y();
-
-       const double scale = _view->scale();
-       assert(scale > 0);
-
-       double samplerate = _decoder->get_samplerate();
-
-       // Show sample rate as 1Hz when it is unknown
-       if (samplerate == 0.0)
-               samplerate = 1.0;
-
-       const double pixels_offset = (_view->offset() -
-               _decoder->get_start_time()) / scale;
-       const double samples_per_pixel = samplerate * scale;
-
-       assert(_decoder);
-       vector< shared_ptr<Annotation> > annotations(_decoder->annotations());
-       BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
-               assert(a);
-               a->paint(p, get_text_colour(), _text_size.height(),
-                       left, right, samples_per_pixel, pixels_offset, y);
-       }
-}
-
-void DecodeSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
-{
-       const GSList *probe;
-
-       assert(form);
-       assert(parent);
-       assert(_decoder);
-
-       const srd_decoder *const decoder = _decoder->decoder();
-
-       assert(decoder);
-
-       Trace::populate_popup_form(parent, form);
-
-       form->addRow(new QLabel(tr("<h3>Probes</h3>"), parent));
-
-       _probe_selector_map.clear();
-
-       // Add the mandatory probes
-       for(probe = decoder->probes; probe; probe = probe->next) {
-               const struct srd_probe *const p =
-                       (struct srd_probe *)probe->data;
-               QComboBox *const combo = create_probe_selector(parent, p);
-               connect(combo, SIGNAL(currentIndexChanged(int)),
-                       this, SLOT(on_probe_selected(int)));
-               form->addRow(tr("<b>%1</b> (%2) *")
-                       .arg(p->name).arg(p->desc), combo);
-
-               _probe_selector_map[p] = combo;
-       }
-
-       // Add the optional probes
-       for(probe = decoder->opt_probes; probe; probe = probe->next) {
-               const struct srd_probe *const p =
-                       (struct srd_probe *)probe->data;
-               QComboBox *const combo = create_probe_selector(parent, p);
-               connect(combo, SIGNAL(currentIndexChanged(int)),
-                       this, SLOT(on_probe_selected(int)));
-               form->addRow(tr("<b>%1</b> (%2)")
-                       .arg(p->name).arg(p->desc), combo);
-
-               _probe_selector_map[p] = combo;
-       }
-
-       form->addRow(new QLabel(
-               tr("<i>* Required Probes</i>"), parent));
-
-       // Add the options
-       if (!_binding.properties().empty()) {
-               form->addRow(new QLabel(tr("<h3>Options</h3>"),
-                       parent));
-               _binding.add_properties_to_form(form, true);
-       }
-}
-
-QMenu* DecodeSignal::create_context_menu(QWidget *parent)
-{
-       QMenu *const menu = Trace::create_context_menu(parent);
-
-       menu->addSeparator();
-
-       QAction *const del = new QAction(tr("Delete"), this);
-       del->setShortcuts(QKeySequence::Delete);
-       connect(del, SIGNAL(triggered()), this, SLOT(on_delete()));
-       menu->addAction(del);
-
-       return menu;
-}
-
-void DecodeSignal::draw_error(QPainter &p, const QString &message,
-       int left, int right)
-{
-       const int y = get_y();
-
-       p.setPen(ErrorBgColour.darker());
-       p.setBrush(ErrorBgColour);
-
-       const QRectF bounding_rect =
-               QRectF(left, INT_MIN / 2 + y, right - left, INT_MAX);
-       const QRectF text_rect = p.boundingRect(bounding_rect,
-               Qt::AlignCenter, message);
-       const float r = text_rect.height() / 4;
-
-       p.drawRoundedRect(text_rect.adjusted(-r, -r, r, r), r, r,
-               Qt::AbsoluteSize);
-
-       p.setPen(get_text_colour());
-       p.drawText(text_rect, message);
-}
-
-QComboBox* DecodeSignal::create_probe_selector(
-       QWidget *parent, const srd_probe *const probe)
-{
-       const vector< shared_ptr<Signal> > sigs = _session.get_signals();
-
-       assert(_decoder);
-       const map<const srd_probe*,
-               shared_ptr<LogicSignal> >::const_iterator probe_iter =
-               _decoder->probes().find(probe);
-
-       QComboBox *selector = new QComboBox(parent);
-
-       selector->addItem("-", qVariantFromValue((void*)NULL));
-
-       if (probe_iter == _decoder->probes().end())
-               selector->setCurrentIndex(0);
-
-       for(size_t i = 0; i < sigs.size(); i++) {
-               const shared_ptr<view::Signal> s(sigs[i]);
-               assert(s);
-
-               if (dynamic_pointer_cast<LogicSignal>(s) && s->enabled())
-               {
-                       selector->addItem(s->get_name(),
-                               qVariantFromValue((void*)s.get()));
-                       if ((*probe_iter).second == s)
-                               selector->setCurrentIndex(i + 1);
-               }
-       }
-
-       return selector;
-}
-
-void DecodeSignal::commit_probes()
-{
-       assert(_decoder);
-
-       map<const srd_probe*, shared_ptr<LogicSignal> > probe_map;
-       const vector< shared_ptr<Signal> > sigs = _session.get_signals();
-
-       for(map<const srd_probe*, QComboBox*>::const_iterator i =
-               _probe_selector_map.begin();
-               i != _probe_selector_map.end(); i++)
-       {
-               const QComboBox *const combo = (*i).second;
-               const LogicSignal *const selection =
-                       (LogicSignal*)combo->itemData(combo->currentIndex()).
-                       value<void*>();
-
-               BOOST_FOREACH(shared_ptr<Signal> s, sigs)
-                       if(s.get() == selection) {
-                               probe_map[(*i).first] =
-                                       dynamic_pointer_cast<LogicSignal>(s);
-                               break;
-                       }
-       }
-
-       _decoder->set_probes(probe_map);
-}
-
-void DecodeSignal::on_new_decode_data()
-{
-       if (_view)
-               _view->update_viewport();
-}
-
-void DecodeSignal::delete_pressed()
-{
-       on_delete();
-}
-
-void DecodeSignal::on_delete()
-{
-       _session.remove_decode_signal(this);
-}
-
-void DecodeSignal::on_probe_selected(int)
-{
-       commit_probes();
-}
-
-} // namespace view
-} // namespace pv
diff --git a/pv/view/decodesignal.h b/pv/view/decodesignal.h
deleted file mode 100644 (file)
index 7977c1c..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
- */
-
-#ifndef PULSEVIEW_PV_VIEW_DECODESIGNAL_H
-#define PULSEVIEW_PV_VIEW_DECODESIGNAL_H
-
-#include "trace.h"
-
-#include <map>
-
-#include <boost/shared_ptr.hpp>
-
-#include <pv/prop/binding/decoderoptions.h>
-
-struct srd_probe;
-
-class QComboBox;
-
-namespace pv {
-
-namespace data {
-class Decoder;
-}
-
-namespace view {
-
-class DecodeSignal : public Trace
-{
-       Q_OBJECT
-
-private:
-       static const QColor DecodeColours[4];
-       static const QColor ErrorBgColour;
-
-public:
-       DecodeSignal(pv::SigSession &session,
-               boost::shared_ptr<pv::data::Decoder> decoder, int index);
-
-       bool enabled() const;
-
-       const boost::shared_ptr<pv::data::Decoder>& decoder() const;
-
-       void set_view(pv::view::View *view);
-
-       /**
-        * Paints the background layer of the trace with a QPainter
-        * @param p the QPainter to paint into.
-        * @param left the x-coordinate of the left edge of the signal.
-        * @param right the x-coordinate of the right edge of the signal.
-        **/
-       void paint_back(QPainter &p, int left, int right);
-
-       /**
-        * Paints the mid-layer of the trace with a QPainter
-        * @param p the QPainter to paint into.
-        * @param left the x-coordinate of the left edge of the signal
-        * @param right the x-coordinate of the right edge of the signal
-        **/
-       void paint_mid(QPainter &p, int left, int right);
-
-       void populate_popup_form(QWidget *parent, QFormLayout *form);
-
-       QMenu* create_context_menu(QWidget *parent);
-
-       void delete_pressed();
-
-private:
-       void draw_error(QPainter &p, const QString &message,
-               int left, int right);
-
-       QComboBox* create_probe_selector(
-               QWidget *parent, const srd_probe *const probe);
-
-       void commit_probes();
-
-private slots:
-       void on_new_decode_data();
-
-       void on_delete();
-
-       void on_probe_selected(int);
-
-private:
-       boost::shared_ptr<pv::data::Decoder> _decoder;
-
-       uint64_t _decode_start, _decode_end;
-
-       pv::prop::binding::DecoderOptions _binding;
-
-       std::map<const srd_probe*, QComboBox*> _probe_selector_map;
-};
-
-} // namespace view
-} // namespace pv
-
-#endif // PULSEVIEW_PV_VIEW_DECODESIGNAL_H
diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp
new file mode 100644 (file)
index 0000000..2844367
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+extern "C" {
+#include <libsigrokdecode/libsigrokdecode.h>
+}
+
+#include <extdef.h>
+
+#include <boost/foreach.hpp>
+
+#include <QAction>
+#include <QComboBox>
+#include <QFormLayout>
+#include <QLabel>
+#include <QMenu>
+
+#include "decodetrace.h"
+
+#include <pv/sigsession.h>
+#include <pv/data/decoder.h>
+#include <pv/view/logicsignal.h>
+#include <pv/view/view.h>
+#include <pv/view/decode/annotation.h>
+
+using namespace boost;
+using namespace std;
+
+namespace pv {
+namespace view {
+
+const QColor DecodeTrace::DecodeColours[4] = {
+       QColor(0xEF, 0x29, 0x29),       // Red
+       QColor(0xFC, 0xE9, 0x4F),       // Yellow
+       QColor(0x8A, 0xE2, 0x34),       // Green
+       QColor(0x72, 0x9F, 0xCF)        // Blue
+};
+
+const QColor DecodeTrace::ErrorBgColour = QColor(0xEF, 0x29, 0x29);
+
+DecodeTrace::DecodeTrace(pv::SigSession &session,
+       boost::shared_ptr<pv::data::Decoder> decoder, int index) :
+       Trace(session, QString(decoder->decoder()->name)),
+       _decoder(decoder),
+       _binding(decoder)
+{
+       assert(_decoder);
+
+       _colour = DecodeColours[index % countof(DecodeColours)];
+
+       connect(_decoder.get(), SIGNAL(new_decode_data()),
+               this, SLOT(on_new_decode_data()));
+}
+
+bool DecodeTrace::enabled() const
+{
+       return true;
+}
+
+const boost::shared_ptr<pv::data::Decoder>& DecodeTrace::decoder() const
+{
+       return _decoder;
+}
+
+void DecodeTrace::set_view(pv::view::View *view)
+{
+       assert(view);
+       Trace::set_view(view);
+}
+
+void DecodeTrace::paint_back(QPainter &p, int left, int right)
+{
+       paint_axis(p, get_y(), left, right);
+}
+
+void DecodeTrace::paint_mid(QPainter &p, int left, int right)
+{
+       using namespace pv::view::decode;
+
+       assert(_decoder);
+       const QString err = _decoder->error_message();
+       if (!err.isEmpty()) {
+               draw_error(p, err, left, right);
+               return;
+       }
+
+       assert(_view);
+       const int y = get_y();
+
+       const double scale = _view->scale();
+       assert(scale > 0);
+
+       double samplerate = _decoder->get_samplerate();
+
+       // Show sample rate as 1Hz when it is unknown
+       if (samplerate == 0.0)
+               samplerate = 1.0;
+
+       const double pixels_offset = (_view->offset() -
+               _decoder->get_start_time()) / scale;
+       const double samples_per_pixel = samplerate * scale;
+
+       assert(_decoder);
+       vector< shared_ptr<Annotation> > annotations(_decoder->annotations());
+       BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
+               assert(a);
+               a->paint(p, get_text_colour(), _text_size.height(),
+                       left, right, samples_per_pixel, pixels_offset, y);
+       }
+}
+
+void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
+{
+       const GSList *probe;
+
+       assert(form);
+       assert(parent);
+       assert(_decoder);
+
+       const srd_decoder *const decoder = _decoder->decoder();
+
+       assert(decoder);
+
+       Trace::populate_popup_form(parent, form);
+
+       form->addRow(new QLabel(tr("<h3>Probes</h3>"), parent));
+
+       _probe_selector_map.clear();
+
+       // Add the mandatory probes
+       for(probe = decoder->probes; probe; probe = probe->next) {
+               const struct srd_probe *const p =
+                       (struct srd_probe *)probe->data;
+               QComboBox *const combo = create_probe_selector(parent, p);
+               connect(combo, SIGNAL(currentIndexChanged(int)),
+                       this, SLOT(on_probe_selected(int)));
+               form->addRow(tr("<b>%1</b> (%2) *")
+                       .arg(p->name).arg(p->desc), combo);
+
+               _probe_selector_map[p] = combo;
+       }
+
+       // Add the optional probes
+       for(probe = decoder->opt_probes; probe; probe = probe->next) {
+               const struct srd_probe *const p =
+                       (struct srd_probe *)probe->data;
+               QComboBox *const combo = create_probe_selector(parent, p);
+               connect(combo, SIGNAL(currentIndexChanged(int)),
+                       this, SLOT(on_probe_selected(int)));
+               form->addRow(tr("<b>%1</b> (%2)")
+                       .arg(p->name).arg(p->desc), combo);
+
+               _probe_selector_map[p] = combo;
+       }
+
+       form->addRow(new QLabel(
+               tr("<i>* Required Probes</i>"), parent));
+
+       // Add the options
+       if (!_binding.properties().empty()) {
+               form->addRow(new QLabel(tr("<h3>Options</h3>"),
+                       parent));
+               _binding.add_properties_to_form(form, true);
+       }
+}
+
+QMenu* DecodeTrace::create_context_menu(QWidget *parent)
+{
+       QMenu *const menu = Trace::create_context_menu(parent);
+
+       menu->addSeparator();
+
+       QAction *const del = new QAction(tr("Delete"), this);
+       del->setShortcuts(QKeySequence::Delete);
+       connect(del, SIGNAL(triggered()), this, SLOT(on_delete()));
+       menu->addAction(del);
+
+       return menu;
+}
+
+void DecodeTrace::draw_error(QPainter &p, const QString &message,
+       int left, int right)
+{
+       const int y = get_y();
+
+       p.setPen(ErrorBgColour.darker());
+       p.setBrush(ErrorBgColour);
+
+       const QRectF bounding_rect =
+               QRectF(left, INT_MIN / 2 + y, right - left, INT_MAX);
+       const QRectF text_rect = p.boundingRect(bounding_rect,
+               Qt::AlignCenter, message);
+       const float r = text_rect.height() / 4;
+
+       p.drawRoundedRect(text_rect.adjusted(-r, -r, r, r), r, r,
+               Qt::AbsoluteSize);
+
+       p.setPen(get_text_colour());
+       p.drawText(text_rect, message);
+}
+
+QComboBox* DecodeTrace::create_probe_selector(
+       QWidget *parent, const srd_probe *const probe)
+{
+       const vector< shared_ptr<Signal> > sigs = _session.get_signals();
+
+       assert(_decoder);
+       const map<const srd_probe*,
+               shared_ptr<LogicSignal> >::const_iterator probe_iter =
+               _decoder->probes().find(probe);
+
+       QComboBox *selector = new QComboBox(parent);
+
+       selector->addItem("-", qVariantFromValue((void*)NULL));
+
+       if (probe_iter == _decoder->probes().end())
+               selector->setCurrentIndex(0);
+
+       for(size_t i = 0; i < sigs.size(); i++) {
+               const shared_ptr<view::Signal> s(sigs[i]);
+               assert(s);
+
+               if (dynamic_pointer_cast<LogicSignal>(s) && s->enabled())
+               {
+                       selector->addItem(s->get_name(),
+                               qVariantFromValue((void*)s.get()));
+                       if ((*probe_iter).second == s)
+                               selector->setCurrentIndex(i + 1);
+               }
+       }
+
+       return selector;
+}
+
+void DecodeTrace::commit_probes()
+{
+       assert(_decoder);
+
+       map<const srd_probe*, shared_ptr<LogicSignal> > probe_map;
+       const vector< shared_ptr<Signal> > sigs = _session.get_signals();
+
+       for(map<const srd_probe*, QComboBox*>::const_iterator i =
+               _probe_selector_map.begin();
+               i != _probe_selector_map.end(); i++)
+       {
+               const QComboBox *const combo = (*i).second;
+               const LogicSignal *const selection =
+                       (LogicSignal*)combo->itemData(combo->currentIndex()).
+                       value<void*>();
+
+               BOOST_FOREACH(shared_ptr<Signal> s, sigs)
+                       if(s.get() == selection) {
+                               probe_map[(*i).first] =
+                                       dynamic_pointer_cast<LogicSignal>(s);
+                               break;
+                       }
+       }
+
+       _decoder->set_probes(probe_map);
+}
+
+void DecodeTrace::on_new_decode_data()
+{
+       if (_view)
+               _view->update_viewport();
+}
+
+void DecodeTrace::delete_pressed()
+{
+       on_delete();
+}
+
+void DecodeTrace::on_delete()
+{
+       _session.remove_decode_signal(this);
+}
+
+void DecodeTrace::on_probe_selected(int)
+{
+       commit_probes();
+}
+
+} // namespace view
+} // namespace pv
diff --git a/pv/view/decodetrace.h b/pv/view/decodetrace.h
new file mode 100644 (file)
index 0000000..6f7182f
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_PV_VIEW_DECODETRACE_H
+#define PULSEVIEW_PV_VIEW_DECODETRACE_H
+
+#include "trace.h"
+
+#include <map>
+
+#include <boost/shared_ptr.hpp>
+
+#include <pv/prop/binding/decoderoptions.h>
+
+struct srd_probe;
+
+class QComboBox;
+
+namespace pv {
+
+namespace data {
+class Decoder;
+}
+
+namespace view {
+
+class DecodeTrace : public Trace
+{
+       Q_OBJECT
+
+private:
+       static const QColor DecodeColours[4];
+       static const QColor ErrorBgColour;
+
+public:
+       DecodeTrace(pv::SigSession &session,
+               boost::shared_ptr<pv::data::Decoder> decoder, int index);
+
+       bool enabled() const;
+
+       const boost::shared_ptr<pv::data::Decoder>& decoder() const;
+
+       void set_view(pv::view::View *view);
+
+       /**
+        * Paints the background layer of the trace with a QPainter
+        * @param p the QPainter to paint into.
+        * @param left the x-coordinate of the left edge of the signal.
+        * @param right the x-coordinate of the right edge of the signal.
+        **/
+       void paint_back(QPainter &p, int left, int right);
+
+       /**
+        * Paints the mid-layer of the trace with a QPainter
+        * @param p the QPainter to paint into.
+        * @param left the x-coordinate of the left edge of the signal
+        * @param right the x-coordinate of the right edge of the signal
+        **/
+       void paint_mid(QPainter &p, int left, int right);
+
+       void populate_popup_form(QWidget *parent, QFormLayout *form);
+
+       QMenu* create_context_menu(QWidget *parent);
+
+       void delete_pressed();
+
+private:
+       void draw_error(QPainter &p, const QString &message,
+               int left, int right);
+
+       QComboBox* create_probe_selector(
+               QWidget *parent, const srd_probe *const probe);
+
+       void commit_probes();
+
+private slots:
+       void on_new_decode_data();
+
+       void on_delete();
+
+       void on_probe_selected(int);
+
+private:
+       boost::shared_ptr<pv::data::Decoder> _decoder;
+
+       uint64_t _decode_start, _decode_end;
+
+       pv::prop::binding::DecoderOptions _binding;
+
+       std::map<const srd_probe*, QComboBox*> _probe_selector_map;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PULSEVIEW_PV_VIEW_DECODETRACE_H
index 42a2f79f0b22e96b45340c67aef0eabaa0c8957d..4cfb39783319a258732b28e14a34b5f884d3b17f 100644 (file)
@@ -30,7 +30,7 @@
 #include <QMouseEvent>
 #include <QScrollBar>
 
-#include "decodesignal.h"
+#include "decodetrace.h"
 #include "header.h"
 #include "ruler.h"
 #include "signal.h"
@@ -168,7 +168,7 @@ vector< shared_ptr<Trace> > View::get_traces() const
 {
        const vector< shared_ptr<Signal> > sigs(
                session().get_signals());
-       const vector< shared_ptr<DecodeSignal> > decode_sigs(
+       const vector< shared_ptr<DecodeTrace> > decode_sigs(
                session().get_decode_signals());
        vector< shared_ptr<Trace> > traces(
                sigs.size() + decode_sigs.size());
index e55e20dea9cfc53dcc909d72657dd13e06fc001b..6e578b704dfe4fa595f7b1ce95117b79064818a2 100644 (file)
@@ -54,7 +54,7 @@ set(pulseview_TEST_SOURCES
        ${PROJECT_SOURCE_DIR}/pv/view/analogsignal.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/cursor.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/cursorpair.cpp
-       ${PROJECT_SOURCE_DIR}/pv/view/decodesignal.cpp
+       ${PROJECT_SOURCE_DIR}/pv/view/decodetrace.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/header.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/logicsignal.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/marginwidget.cpp
@@ -85,7 +85,7 @@ set(pulseview_TEST_HEADERS
        ${PROJECT_SOURCE_DIR}/pv/prop/property.h
        ${PROJECT_SOURCE_DIR}/pv/prop/string.h
        ${PROJECT_SOURCE_DIR}/pv/view/cursor.h
-       ${PROJECT_SOURCE_DIR}/pv/view/decodesignal.h
+       ${PROJECT_SOURCE_DIR}/pv/view/decodetrace.h
        ${PROJECT_SOURCE_DIR}/pv/view/header.h
        ${PROJECT_SOURCE_DIR}/pv/view/logicsignal.h
        ${PROJECT_SOURCE_DIR}/pv/view/marginwidget.h
index 0a54a8669dae376e28c51a391a972768cd230832..6a48fb04709637f636db6989d8045170e5253d40 100644 (file)
@@ -26,7 +26,7 @@
 #include "../../pv/data/decoder.h"
 #include "../../pv/devicemanager.h"
 #include "../../pv/sigsession.h"
-#include "../../pv/view/decodesignal.h"
+#include "../../pv/view/decodetrace.h"
 
 using namespace boost;
 using namespace std;
@@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(TwoDecoder)
                ss.add_decoder(dec);
 
                // Check the signals were created
-               const vector< shared_ptr<view::DecodeSignal> > sigs =
+               const vector< shared_ptr<view::DecodeTrace> > sigs =
                        ss.get_decode_signals();
 
                shared_ptr<data::Decoder> dec0 = sigs[0]->decoder();