From: Soeren Apel Date: Sat, 18 Jan 2020 23:10:35 +0000 (+0100) Subject: DecodeTrace: Add buttons to show/hide all classes in a row X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=65bde9b3e02f7ad11f88ba4eac9d1c3ce7933437;p=pulseview.git DecodeTrace: Add buttons to show/hide all classes in a row --- diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index 9f8b7481..a91f5e03 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -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(); + 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(); + 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(); diff --git a/pv/views/trace/decodetrace.hpp b/pv/views/trace/decodetrace.hpp index 83f3a084..f8976cb7 100644 --- a/pv/views/trace/decodetrace.hpp +++ b/pv/views/trace/decodetrace.hpp @@ -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(); diff --git a/pv/widgets/flowlayout.cpp b/pv/widgets/flowlayout.cpp index 74c5036d..efd862f9 100644 --- a/pv/widgets/flowlayout.cpp +++ b/pv/widgets/flowlayout.cpp @@ -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); }