]> sigrok.org Git - pulseview.git/commitdiff
Added decoder stack item deletion
authorJoel Holdsworth <redacted>
Sat, 30 Nov 2013 17:12:09 +0000 (17:12 +0000)
committerJoel Holdsworth <redacted>
Sat, 30 Nov 2013 18:14:05 +0000 (18:14 +0000)
pv/data/decoderstack.cpp
pv/data/decoderstack.h
pv/view/decodetrace.cpp
pv/view/decodetrace.h

index 2817d29205cc8ee825c72ff049e5775ab6b638cb..bc26f9fccf1a93a2acaa38bea1a86621bca53687 100644 (file)
@@ -71,6 +71,22 @@ void DecoderStack::push(boost::shared_ptr<decode::Decoder> decoder)
        _stack.push_back(decoder);
 }
 
+void DecoderStack::remove(int index)
+{
+       using pv::data::decode::Decoder;
+
+       assert(index >= 0);
+       assert(index < (int)_stack.size());
+
+       // Find the decoder in the stack
+       list< shared_ptr<Decoder> >::iterator iter = _stack.begin();
+       for(int i = 0; i < index; i++, iter++)
+               assert(iter != _stack.end());
+
+       // Delete the element
+       _stack.erase(iter);
+}
+
 const vector< shared_ptr<view::decode::Annotation> >
        DecoderStack::annotations() const
 {
index 8b9d29b2bf89e487c31bf12e030b98678d618e2c..fe03df0aca3011f4f0d1d2c3a116621b6068e23c 100644 (file)
@@ -74,6 +74,7 @@ public:
 
        const std::list< boost::shared_ptr<decode::Decoder> >& stack() const;
        void push(boost::shared_ptr<decode::Decoder> decoder);
+       void remove(int index);
 
        const std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
                annotations() const;
index 3e78e6ed2a669811e85e890ef31ad7c50f999bf5..bad849c04665b2c53680836f610fdd329bc8ccd8 100644 (file)
@@ -62,7 +62,8 @@ const QColor DecodeTrace::ErrorBgColour = QColor(0xEF, 0x29, 0x29);
 DecodeTrace::DecodeTrace(pv::SigSession &session,
        boost::shared_ptr<pv::data::DecoderStack> decoder_stack, int index) :
        Trace(session, QString(decoder_stack->stack().front()->decoder()->name)),
-       _decoder_stack(decoder_stack)
+       _decoder_stack(decoder_stack),
+       _delete_mapper(this)
 {
        assert(_decoder_stack);
 
@@ -70,6 +71,8 @@ DecodeTrace::DecodeTrace(pv::SigSession &session,
 
        connect(_decoder_stack.get(), SIGNAL(new_decode_data()),
                this, SLOT(on_new_decode_data()));
+       connect(&_delete_mapper, SIGNAL(mapped(int)),
+               this, SLOT(on_delete_decoder(int)));
 }
 
 bool DecodeTrace::enabled() const
@@ -131,6 +134,8 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
 
 void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
 {
+       using pv::data::decode::Decoder;
+
        assert(form);
        assert(parent);
        assert(_decoder_stack);
@@ -142,9 +147,12 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
        _bindings.clear();
        _probe_selectors.clear();
 
-       BOOST_FOREACH(shared_ptr<data::decode::Decoder> dec,
-               _decoder_stack->stack())
-               create_decoder_form(dec, parent, form);
+       const list< shared_ptr<Decoder> >& stack = _decoder_stack->stack();
+       list< shared_ptr<Decoder> >::const_iterator iter = stack.begin();
+       for (int i = 0; i < (int)stack.size(); i++, iter++) {
+               shared_ptr<Decoder> dec(*iter);
+               create_decoder_form(i, dec, parent, form);
+       }
 
        form->addRow(new QLabel(
                tr("<i>* Required Probes</i>"), parent));
@@ -199,8 +207,9 @@ void DecodeTrace::draw_error(QPainter &p, const QString &message,
        p.drawText(text_rect, message);
 }
 
-void DecodeTrace::create_decoder_form(shared_ptr<data::decode::Decoder> &dec,
-       QWidget *parent, QFormLayout *form)
+void DecodeTrace::create_decoder_form(int index,
+       shared_ptr<data::decode::Decoder> &dec, QWidget *parent,
+       QFormLayout *form)
 {
        const GSList *probe;
 
@@ -210,6 +219,10 @@ void DecodeTrace::create_decoder_form(shared_ptr<data::decode::Decoder> &dec,
 
        pv::widgets::DecoderGroupBox *const group =
                new pv::widgets::DecoderGroupBox(decoder->name);
+
+       _delete_mapper.setMapping(group, index);
+       connect(group, SIGNAL(delete_decoder()), &_delete_mapper, SLOT(map()));
+
        QFormLayout *const decoder_form = new QFormLayout;
        group->add_layout(decoder_form);
 
@@ -356,5 +369,15 @@ void DecodeTrace::on_stack_decoder(srd_decoder *decoder)
        create_popup_form();
 }
 
+void DecodeTrace::on_delete_decoder(int index)
+{
+       _decoder_stack->remove(index);
+
+       // Update the popup
+       create_popup_form();    
+
+       _decoder_stack->begin_decode();
+}
+
 } // namespace view
 } // namespace pv
index 2b964c196ad99fe51392639f4e47be046dc8f717..ccf4a0f7bbe4d64d9c421b3eb25c446fc0e67934 100644 (file)
@@ -26,6 +26,8 @@
 #include <list>
 #include <map>
 
+#include <QSignalMapper>
+
 #include <boost/shared_ptr.hpp>
 
 #include <pv/prop/binding/decoderoptions.h>
@@ -100,7 +102,7 @@ private:
        void draw_error(QPainter &p, const QString &message,
                int left, int right);
 
-       void create_decoder_form(
+       void create_decoder_form(int index,
                boost::shared_ptr<pv::data::decode::Decoder> &dec,
                QWidget *parent, QFormLayout *form);
 
@@ -122,6 +124,8 @@ private slots:
 
        void on_stack_decoder(srd_decoder *decoder);
 
+       void on_delete_decoder(int index);
+
 private:
        boost::shared_ptr<pv::data::DecoderStack> _decoder_stack;
 
@@ -131,6 +135,8 @@ private:
                _bindings;
 
        std::list<ProbeSelector> _probe_selectors;
+
+       QSignalMapper _delete_mapper;
 };
 
 } // namespace view