From: Joel Holdsworth Date: Sat, 30 Nov 2013 17:12:09 +0000 (+0000) Subject: Added decoder stack item deletion X-Git-Tag: pulseview-0.2.0~208 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=613d097c5af2d12ffd68e2dfab309b518edca1a6;p=pulseview.git Added decoder stack item deletion --- diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 2817d292..bc26f9fc 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -71,6 +71,22 @@ void DecoderStack::push(boost::shared_ptr 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 >::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 > DecoderStack::annotations() const { diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 8b9d29b2..fe03df0a 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -74,6 +74,7 @@ public: const std::list< boost::shared_ptr >& stack() const; void push(boost::shared_ptr decoder); + void remove(int index); const std::vector< boost::shared_ptr > annotations() const; diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 3e78e6ed..bad849c0 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -62,7 +62,8 @@ const QColor DecodeTrace::ErrorBgColour = QColor(0xEF, 0x29, 0x29); DecodeTrace::DecodeTrace(pv::SigSession &session, boost::shared_ptr 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 dec, - _decoder_stack->stack()) - create_decoder_form(dec, parent, form); + const list< shared_ptr >& stack = _decoder_stack->stack(); + list< shared_ptr >::const_iterator iter = stack.begin(); + for (int i = 0; i < (int)stack.size(); i++, iter++) { + shared_ptr dec(*iter); + create_decoder_form(i, dec, parent, form); + } form->addRow(new QLabel( tr("* Required Probes"), 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 &dec, - QWidget *parent, QFormLayout *form) +void DecodeTrace::create_decoder_form(int index, + shared_ptr &dec, QWidget *parent, + QFormLayout *form) { const GSList *probe; @@ -210,6 +219,10 @@ void DecodeTrace::create_decoder_form(shared_ptr &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 diff --git a/pv/view/decodetrace.h b/pv/view/decodetrace.h index 2b964c19..ccf4a0f7 100644 --- a/pv/view/decodetrace.h +++ b/pv/view/decodetrace.h @@ -26,6 +26,8 @@ #include #include +#include + #include #include @@ -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 &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 _decoder_stack; @@ -131,6 +135,8 @@ private: _bindings; std::list _probe_selectors; + + QSignalMapper _delete_mapper; }; } // namespace view