From: Joel Holdsworth Date: Sun, 2 Feb 2014 20:11:54 +0000 (+0000) Subject: Added show/hide decoder button X-Git-Tag: pulseview-0.2.0~90 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=dd048a7ec035447c051c7937ce04aca5be065b4e;p=pulseview.git Added show/hide decoder button --- diff --git a/icons/decoder-hidden.svg b/icons/decoder-hidden.svg new file mode 100644 index 00000000..d4622006 --- /dev/null +++ b/icons/decoder-hidden.svg @@ -0,0 +1,33 @@ + + + + + + + + + image/svg+xml + + + + + + + diff --git a/icons/decoder-shown.svg b/icons/decoder-shown.svg new file mode 100644 index 00000000..6050bdc1 --- /dev/null +++ b/icons/decoder-shown.svg @@ -0,0 +1,47 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index 592a746c..0404227e 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -33,7 +33,8 @@ namespace data { namespace decode { Decoder::Decoder(const srd_decoder *const dec) : - _decoder(dec) + _decoder(dec), + _shown(true) { } @@ -49,6 +50,16 @@ const srd_decoder* Decoder::decoder() const return _decoder; } +bool Decoder::shown() const +{ + return _shown; +} + +void Decoder::show(bool show) +{ + _shown = show; +} + const map >& Decoder::probes() const { diff --git a/pv/data/decode/decoder.h b/pv/data/decode/decoder.h index 99b21c57..f96ba2b6 100644 --- a/pv/data/decode/decoder.h +++ b/pv/data/decode/decoder.h @@ -50,6 +50,9 @@ public: const srd_decoder* decoder() const; + bool shown() const; + void show(bool show = true); + const std::map >& probes() const; void set_probes(std::map > _probes; std::map _options; diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 323f5cc2..073dcd52 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -103,7 +103,7 @@ int64_t DecoderStack::samples_decoded() const return _samples_decoded; } -std::vector DecoderStack::get_rows() const +std::vector DecoderStack::get_visible_rows() const { lock_guard lock(_mutex); @@ -112,6 +112,9 @@ std::vector DecoderStack::get_rows() const BOOST_FOREACH (const shared_ptr &dec, _stack) { assert(dec); + if (!dec->shown()) + continue; + const srd_decoder *const decc = dec->decoder(); assert(dec->decoder()); diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 80ad64cd..339c1e03 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -78,7 +78,7 @@ public: int64_t samples_decoded() const; - std::vector get_rows() const; + std::vector get_visible_rows() const; /** * Extracts sorted annotations between two period into a vector. diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index dd76b4ca..22d8f2dc 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -86,7 +86,8 @@ DecodeTrace::DecodeTrace(pv::SigSession &session, Trace(session, QString::fromUtf8( decoder_stack->stack().front()->decoder()->name)), _decoder_stack(decoder_stack), - _delete_mapper(this) + _delete_mapper(this), + _show_hide_mapper(this) { assert(_decoder_stack); @@ -96,6 +97,8 @@ DecodeTrace::DecodeTrace(pv::SigSession &session, this, SLOT(on_new_decode_data())); connect(&_delete_mapper, SIGNAL(mapped(int)), this, SLOT(on_delete_decoder(int))); + connect(&_show_hide_mapper, SIGNAL(mapped(int)), + this, SLOT(on_show_hide_decoder(int))); } bool DecodeTrace::enabled() const @@ -163,7 +166,7 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right) assert(_decoder_stack); - const vector rows(_decoder_stack->get_rows()); + const vector rows(_decoder_stack->get_visible_rows()); for (size_t i = 0; i < rows.size(); i++) { const Row &row = rows[i]; @@ -198,6 +201,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form) // Add the decoder options _bindings.clear(); _probe_selectors.clear(); + _decoder_forms.clear(); const list< shared_ptr >& stack = _decoder_stack->stack(); @@ -432,10 +436,15 @@ void DecodeTrace::create_decoder_form(int index, pv::widgets::DecoderGroupBox *const group = new pv::widgets::DecoderGroupBox( QString::fromUtf8(decoder->name)); + group->set_decoder_visible(dec->shown()); _delete_mapper.setMapping(group, index); connect(group, SIGNAL(delete_decoder()), &_delete_mapper, SLOT(map())); + _show_hide_mapper.setMapping(group, index); + connect(group, SIGNAL(show_hide_decoder()), + &_show_hide_mapper, SLOT(map())); + QFormLayout *const decoder_form = new QFormLayout; group->add_layout(decoder_form); @@ -475,6 +484,7 @@ void DecodeTrace::create_decoder_form(int index, _bindings.push_back(binding); form->addRow(group); + _decoder_forms.push_back(group); } QComboBox* DecodeTrace::create_probe_selector( @@ -592,5 +602,28 @@ void DecodeTrace::on_delete_decoder(int index) _decoder_stack->begin_decode(); } +void DecodeTrace::on_show_hide_decoder(int index) +{ + using pv::data::decode::Decoder; + + const list< shared_ptr > stack(_decoder_stack->stack()); + + // Find the decoder in the stack + list< shared_ptr >::const_iterator iter = stack.begin(); + for(int i = 0; i < index; i++, iter++) + assert(iter != stack.end()); + + shared_ptr dec = *iter; + assert(dec); + + const bool show = !dec->shown(); + dec->show(show); + + assert(index < (int)_decoder_forms.size()); + _decoder_forms[index]->set_decoder_visible(show); + + _view->update_viewport(); +} + } // namespace view } // namespace pv diff --git a/pv/view/decodetrace.h b/pv/view/decodetrace.h index 9f0e68b5..bdcb4afe 100644 --- a/pv/view/decodetrace.h +++ b/pv/view/decodetrace.h @@ -48,6 +48,10 @@ class Decoder; } } +namespace widgets { +class DecoderGroupBox; +} + namespace view { class DecodeTrace : public Trace @@ -149,6 +153,8 @@ private slots: void on_delete_decoder(int index); + void on_show_hide_decoder(int index); + private: boost::shared_ptr _decoder_stack; @@ -158,8 +164,9 @@ private: _bindings; std::list _probe_selectors; + std::vector _decoder_forms; - QSignalMapper _delete_mapper; + QSignalMapper _delete_mapper, _show_hide_mapper; }; } // namespace view diff --git a/pv/widgets/decodergroupbox.cpp b/pv/widgets/decodergroupbox.cpp index 58874d38..2cbd532e 100644 --- a/pv/widgets/decodergroupbox.cpp +++ b/pv/widgets/decodergroupbox.cpp @@ -32,7 +32,8 @@ namespace widgets { DecoderGroupBox::DecoderGroupBox(QString title, QWidget *parent) : QWidget(parent), - _layout(new QGridLayout) + _layout(new QGridLayout), + _show_hide_button(QIcon(":/icons/decoder-shown.svg"), QString(), this) { _layout->setContentsMargins(0, 0, 0, 0); setLayout(_layout); @@ -44,6 +45,12 @@ DecoderGroupBox::DecoderGroupBox(QString title, QWidget *parent) : QHBoxLayout *const toolbar = new QHBoxLayout; _layout->addLayout(toolbar, 0, 1); + _show_hide_button.setFlat(true); + _show_hide_button.setIconSize(QSize(16, 16)); + connect(&_show_hide_button, SIGNAL(clicked()), + this, SIGNAL(show_hide_decoder())); + toolbar->addWidget(&_show_hide_button); + QPushButton *const delete_button = new QPushButton( QIcon(":/icons/decoder-delete.svg"), QString(), this); delete_button->setFlat(true); @@ -59,5 +66,12 @@ void DecoderGroupBox::add_layout(QLayout *layout) _layout->addLayout(layout, 1, 0, 1, 2); } +void DecoderGroupBox::set_decoder_visible(bool visible) +{ + _show_hide_button.setIcon(QIcon(visible ? + ":/icons/decoder-shown.svg" : + ":/icons/decoder-hidden.svg")); +} + } // widgets } // pv diff --git a/pv/widgets/decodergroupbox.h b/pv/widgets/decodergroupbox.h index 7b6bc93b..63885e34 100644 --- a/pv/widgets/decodergroupbox.h +++ b/pv/widgets/decodergroupbox.h @@ -21,7 +21,7 @@ #ifndef PULSEVIEW_PV_WIDGETS_DECODERGROUPBox_H #define PULSEVIEW_PV_WIDGETS_DECODERGROUPBOX_H -#include +#include class QGridLayout; class QToolBar; @@ -38,11 +38,16 @@ public: void add_layout(QLayout *layout); + void set_decoder_visible(bool visible); + signals: void delete_decoder(); + void show_hide_decoder(); + private: QGridLayout *const _layout; + QPushButton _show_hide_button; }; } // widgets