]> sigrok.org Git - pulseview.git/commitdiff
DecodeTrace: Add buttons to show/hide all classes in a row
authorSoeren Apel <redacted>
Sat, 18 Jan 2020 23:10:35 +0000 (00:10 +0100)
committerUwe Hermann <redacted>
Wed, 22 Jan 2020 21:56:04 +0000 (22:56 +0100)
pv/views/trace/decodetrace.cpp
pv/views/trace/decodetrace.hpp
pv/widgets/flowlayout.cpp

index 9f8b7481a6b07502468f9e337d8768a1b2bce6c9..a91f5e03985504a585e0f5dfe08f1c78ce47d7c2 100644 (file)
@@ -1259,29 +1259,49 @@ void DecodeTrace::initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id)
        QVBoxLayout* vlayout = new QVBoxLayout();
        r->container->setLayout(vlayout);
 
-       // Add header container with checkbox for this row
+       // Add header container
        vlayout->addWidget(r->header_container);
        vlayout->setContentsMargins(0, 0, 0, 0);
        vlayout->setSpacing(0);
+       QHBoxLayout* header_container_layout = new QHBoxLayout();
        r->header_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
        r->header_container->setMinimumSize(0, default_row_height_);
-       r->header_container->setLayout(new QVBoxLayout());
-       r->header_container->layout()->setContentsMargins(10, 2, 0, 2);
+       r->header_container->setLayout(header_container_layout);
+       r->header_container->layout()->setContentsMargins(10, 2, 10, 2);
 
        r->header_container->setAutoFillBackground(true);
        r->header_container->setPalette(header_palette);
 
+       // Add widgets inside the header container
        QCheckBox* cb = new QCheckBox();
-       r->header_container->layout()->addWidget(cb);
+       header_container_layout->addWidget(cb);
        cb->setText(tr("Show this row"));
        cb->setChecked(r->decode_row->visible());
 
-       cb->setEnabled(false);
-
        row_show_hide_mapper_.setMapping(cb, row_id);
        connect(cb, SIGNAL(stateChanged(int)),
                &row_show_hide_mapper_, SLOT(map()));
 
+       cb->setEnabled(false);
+
+       QPushButton* btn = new QPushButton();
+       header_container_layout->addWidget(btn);
+       btn->setFlat(true);
+       btn->setStyleSheet(":hover { background-color: palette(button); color: palette(button-text); border:0; }");
+       btn->setText(tr("Show All"));
+       btn->setProperty("decode_trace_row_ptr", QVariant::fromValue((void*)r));
+       connect(btn, SIGNAL(clicked(bool)), this, SLOT(on_show_all_classes()));
+
+       btn = new QPushButton();
+       header_container_layout->addWidget(btn);
+       btn->setFlat(true);
+       btn->setStyleSheet(":hover { background-color: palette(button); color: palette(button-text); border:0; }");
+       btn->setText(tr("Hide All"));
+       btn->setProperty("decode_trace_row_ptr", QVariant::fromValue((void*)r));
+       connect(btn, SIGNAL(clicked(bool)), this, SLOT(on_hide_all_classes()));
+
+       header_container_layout->addStretch(); // To left-align the header widgets
+
        // Add selector container
        vlayout->addWidget(r->selector_container);
        r->selector_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -1304,6 +1324,7 @@ void DecodeTrace::initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id)
                cb->setIcon(pixmap);
 
                r->selector_container->layout()->addWidget(cb);
+               r->selectors.push_back(cb);
 
                cb->setProperty("ann_class_ptr", QVariant::fromValue((void*)ann_class));
                cb->setProperty("decode_trace_row_ptr", QVariant::fromValue((void*)r));
@@ -1590,6 +1611,34 @@ void DecodeTrace::on_show_hide_class(QWidget* sender)
        owner_->row_item_appearance_changed(false, true);
 }
 
+void DecodeTrace::on_show_all_classes()
+{
+       void* row_ptr = QObject::sender()->property("decode_trace_row_ptr").value<void*>();
+       assert(row_ptr);
+       DecodeTraceRow* row = (DecodeTraceRow*)row_ptr;
+
+       for (QCheckBox* cb : row->selectors)
+               cb->setChecked(true);
+
+       row->has_hidden_classes = false;
+
+       owner_->row_item_appearance_changed(false, true);
+}
+
+void DecodeTrace::on_hide_all_classes()
+{
+       void* row_ptr = QObject::sender()->property("decode_trace_row_ptr").value<void*>();
+       assert(row_ptr);
+       DecodeTraceRow* row = (DecodeTraceRow*)row_ptr;
+
+       for (QCheckBox* cb : row->selectors)
+               cb->setChecked(false);
+
+       row->has_hidden_classes = true;
+
+       owner_->row_item_appearance_changed(false, true);
+}
+
 void DecodeTrace::on_row_container_resized(QWidget* sender)
 {
        sender->update();
index 83f3a0848dff117730fce20b66d5ba3ac29bc0b3..f8976cb7b2da84a22c0968715972e67affbfd3c1 100644 (file)
@@ -275,6 +275,8 @@ private Q_SLOTS:
        void on_show_hide_decoder(int index);
        void on_show_hide_row(int row_id);
        void on_show_hide_class(QWidget* sender);
+       void on_show_all_classes();
+       void on_hide_all_classes();
        void on_row_container_resized(QWidget* sender);
 
        void on_copy_annotation_to_clipboard();
index 74c5036d725cec4c661c09db341b0715e66ad6f6..efd862f97b1fb9581307fe92e920d9903b50f2dc 100644 (file)
@@ -141,7 +141,7 @@ QSize FlowLayout::minimumSize() const
                if (w > size.width())
                        size.setWidth(w);
 
-               int h = item->geometry().y() + item->geometry().width();
+               int h = item->geometry().y() + item->geometry().height();
                if (h > size.height())
                        size.setHeight(h);
        }