]> sigrok.org Git - pulseview.git/commitdiff
Added show/hide decoder button
authorJoel Holdsworth <redacted>
Sun, 2 Feb 2014 20:11:54 +0000 (20:11 +0000)
committerUwe Hermann <redacted>
Sun, 2 Feb 2014 20:57:26 +0000 (21:57 +0100)
icons/decoder-hidden.svg [new file with mode: 0644]
icons/decoder-shown.svg [new file with mode: 0644]
pv/data/decode/decoder.cpp
pv/data/decode/decoder.h
pv/data/decoderstack.cpp
pv/data/decoderstack.h
pv/view/decodetrace.cpp
pv/view/decodetrace.h
pv/widgets/decodergroupbox.cpp
pv/widgets/decodergroupbox.h

diff --git a/icons/decoder-hidden.svg b/icons/decoder-hidden.svg
new file mode 100644 (file)
index 0000000..d462200
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   version="1.1"
+   width="22"
+   height="22"
+   id="svg2989">
+  <defs
+     id="defs2991" />
+  <metadata
+     id="metadata2994">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <path
+     d="m 19.426489,11.070664 a 11,11 0 0 1 -16.8529782,-1e-6"
+     transform="matrix(1.1867339,0,0,1.1867339,-2.0540724,-2.1379314)"
+     id="path3053"
+     style="fill:none;stroke:#000000;stroke-width:1.26397336" />
+</svg>
diff --git a/icons/decoder-shown.svg b/icons/decoder-shown.svg
new file mode 100644 (file)
index 0000000..6050bdc
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   version="1.1"
+   width="22"
+   height="22"
+   id="svg2989">
+  <defs
+     id="defs2991" />
+  <metadata
+     id="metadata2994">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <path
+     d="M 13.390812,-9.3707772 A 5.87888,5.87888 0 0 1 14.476134,0.74106762"
+     transform="matrix(0.89442417,0,0,0.89442417,1.1613345,14.644558)"
+     id="path2989"
+     style="fill:none;stroke:#000000;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
+  <path
+     d="m 12,-4 a 1,1 0 1 1 -2,0 1,1 0 1 1 2,0 z"
+     transform="matrix(1.3065319,0,0,1.3065319,-3.3718505,16.219638)"
+     id="path2995"
+     style="fill:#000000;stroke:none" />
+  <path
+     d="M 10.875,6.34375 C 7.9493854,6.36765 5.0099958,7.3787791 2.59375,9.40625 2.0116039,9.8947285 1.4884785,10.417854 1,11 1.4884785,11.582146 2.0116039,12.105271 2.59375,12.59375 8.1165975,17.227969 16.365781,16.522848 21,11 18.393252,7.8933983 14.636505,6.3130214 10.875,6.34375 z"
+     id="path3053"
+     style="fill:none;stroke:#000000;stroke-width:1.5" />
+  <path
+     d="M 7.5357022,0.74972325 A 5.87888,5.87888 0 0 1 8.1948438,-9.1664619"
+     transform="matrix(0.89442417,0,0,0.89442417,1.1613345,14.644558)"
+     id="path3057"
+     style="fill:none;stroke:#000000;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
+</svg>
index 592a746c7f612cc71dd34a914c2ab91ec1f8e8f7..0404227eeaef48a92da5581e93f29d16e7e42bf7 100644 (file)
@@ -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<const srd_probe*, shared_ptr<view::LogicSignal> >&
 Decoder::probes() const
 {
index 99b21c574e43b682e18893e13bb111a9b2b9e9d0..f96ba2b6e18e66a3b80e00469fdf2cf05db19c17 100644 (file)
@@ -50,6 +50,9 @@ public:
 
        const srd_decoder* decoder() const;
 
+       bool shown() const;
+       void show(bool show = true);
+
        const std::map<const srd_probe*,
                boost::shared_ptr<view::LogicSignal> >& probes() const;
        void set_probes(std::map<const srd_probe*,
@@ -64,6 +67,9 @@ public:
 
 private:
        const srd_decoder *const _decoder;
+
+       bool _shown;
+
        std::map<const srd_probe*, boost::shared_ptr<pv::view::LogicSignal> >
                _probes;
        std::map<std::string, GVariant*> _options;
index 323f5cc2cd4b45397cf18e1cd59560dc0ef17f33..073dcd523ec44146fb067cadd9957d5c523f2d76 100644 (file)
@@ -103,7 +103,7 @@ int64_t DecoderStack::samples_decoded() const
        return _samples_decoded;
 }
 
-std::vector<Row> DecoderStack::get_rows() const
+std::vector<Row> DecoderStack::get_visible_rows() const
 {
        lock_guard<mutex> lock(_mutex);
 
@@ -112,6 +112,9 @@ std::vector<Row> DecoderStack::get_rows() const
        BOOST_FOREACH (const shared_ptr<decode::Decoder> &dec, _stack)
        {
                assert(dec);
+               if (!dec->shown())
+                       continue;
+
                const srd_decoder *const decc = dec->decoder();
                assert(dec->decoder());
 
index 80ad64cdfebf90398213d801ef184f128cc7d4bd..339c1e0386daf3cd1b9421b67613956564444428 100644 (file)
@@ -78,7 +78,7 @@ public:
 
        int64_t samples_decoded() const;
 
-       std::vector<decode::Row> get_rows() const;
+       std::vector<decode::Row> get_visible_rows() const;
 
        /**
         * Extracts sorted annotations between two period into a vector.
index dd76b4ca4a78e491dbac1b5784aba4d624d56739..22d8f2dce06ceff5b0c46e8a185550ce52fc81ba 100644 (file)
@@ -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<Row> rows(_decoder_stack->get_rows());
+       const vector<Row> 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<Decoder> >& 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<Decoder> > stack(_decoder_stack->stack());
+
+       // Find the decoder in the stack
+       list< shared_ptr<Decoder> >::const_iterator iter = stack.begin();
+       for(int i = 0; i < index; i++, iter++)
+               assert(iter != stack.end());
+
+       shared_ptr<Decoder> 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
index 9f0e68b5deee5cd8fc0229f9182c2d526d4d11b4..bdcb4afe3ff1c350cd1002787ce942377e59e850 100644 (file)
@@ -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<pv::data::DecoderStack> _decoder_stack;
 
@@ -158,8 +164,9 @@ private:
                _bindings;
 
        std::list<ProbeSelector> _probe_selectors;
+       std::vector<pv::widgets::DecoderGroupBox*> _decoder_forms;
 
-       QSignalMapper _delete_mapper;
+       QSignalMapper _delete_mapper, _show_hide_mapper;
 };
 
 } // namespace view
index 58874d38722d0723e46a53e271616c21541f55f2..2cbd532ef08f5a323b2d86e09b4b51fef3e74a8c 100644 (file)
@@ -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
index 7b6bc93bdd46b41836490fe58065d89ac4bbdce5..63885e3429525b060e1f794765c214c71f54ac06 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef PULSEVIEW_PV_WIDGETS_DECODERGROUPBox_H
 #define PULSEVIEW_PV_WIDGETS_DECODERGROUPBOX_H
 
-#include <QWidget>
+#include <QPushButton>
 
 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