From: jaseg Date: Thu, 23 Jan 2020 08:28:52 +0000 (+0100) Subject: Rework channel selection popup X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5fbf231e831ed4ff39599c4336f60eaa2f568442;p=pulseview.git Rework channel selection popup Change the channel selection popup to make select-multiple more intuitive. * Show select all/none buttons per group * Show select all/none buttons per row of 8 channels https://github.com/sigrokproject/pulseview/pull/18 --- diff --git a/pv/popups/channels.cpp b/pv/popups/channels.cpp index acd7079b..b7fcad45 100644 --- a/pv/popups/channels.cpp +++ b/pv/popups/channels.cpp @@ -42,6 +42,7 @@ using std::out_of_range; using std::shared_ptr; using std::unordered_set; using std::vector; +using std::weak_ptr; using pv::data::SignalBase; using pv::data::Logic; @@ -227,49 +228,96 @@ void Channels::populate_group(shared_ptr group, if (group) binding = make_shared(group); + QHBoxLayout* group_layout = new QHBoxLayout(); + layout_.addRow(group_layout); + // Create a title if the group is going to have any content if ((!sigs.empty() || (binding && !binding->properties().empty())) && group) { QLabel *label = new QLabel( QString("

%1

").arg(group->name().c_str())); - layout_.addRow(label); + group_layout->addWidget(label); group_label_map_[group] = label; } // Create the channel group grid - QGridLayout *const channel_grid = create_channel_group_grid(sigs); - layout_.addRow(channel_grid); - - // Create the channel group options - if (binding) { - binding->add_properties_to_form(&layout_, true); - group_bindings_.push_back(binding); - } -} - -QGridLayout* Channels::create_channel_group_grid( - const vector< shared_ptr > sigs) -{ int row = 0, col = 0; QGridLayout *const grid = new QGridLayout(); + vector group_checkboxes, this_row; for (const shared_ptr& sig : sigs) { assert(sig); QCheckBox *const checkbox = new QCheckBox(sig->display_name()); check_box_mapper_.setMapping(checkbox, checkbox); - connect(checkbox, SIGNAL(toggled(bool)), - &check_box_mapper_, SLOT(map())); + connect(checkbox, SIGNAL(toggled(bool)), &check_box_mapper_, SLOT(map())); grid->addWidget(checkbox, row, col); + group_checkboxes.push_back(checkbox); + this_row.push_back(checkbox); + check_box_signal_map_[checkbox] = sig; - if (++col >= 8) + weak_ptr weak_sig(sig); + connect(checkbox, &QCheckBox::toggled, + [weak_sig](bool state) { + auto sig = weak_sig.lock(); + assert(sig); + sig->set_enabled(state); + }); + + if ((++col >= 8 || &sig == &sigs.back())) { + // Show buttons if there's more than one row + if (sigs.size() > 8) { + QPushButton *row_enable_button = new QPushButton(tr("All"), this); + grid->addWidget(row_enable_button, row, 8); + connect(row_enable_button, &QPushButton::clicked, + [this_row]() { + for (QCheckBox *box : this_row) + box->setChecked(true); + }); + + QPushButton *row_disable_button = new QPushButton(tr("None"), this); + connect(row_disable_button, &QPushButton::clicked, + [this_row]() { + for (QCheckBox *box : this_row) + box->setChecked(false); + }); + grid->addWidget(row_disable_button, row, 9); + } + + this_row.clear(); col = 0, row++; + } + } + layout_.addRow(grid); + + if (sigs.size() > 1) { + // Create enable all/none buttons + QPushButton *btn_enable_all, *btn_disable_all; + + btn_enable_all = new QPushButton(tr("All")); + btn_disable_all = new QPushButton(tr("None")); + group_layout->addWidget(btn_enable_all); + group_layout->addWidget(btn_disable_all); + + connect(btn_enable_all, &QPushButton::clicked, [group_checkboxes](){ + for (QCheckBox *box: group_checkboxes) + box->setChecked(true); + }); + + connect(btn_disable_all, &QPushButton::clicked, [group_checkboxes](){ + for (QCheckBox *box: group_checkboxes) + box->setChecked(false); + }); } - return grid; + // Create the channel group options + if (binding) { + binding->add_properties_to_form(&layout_, true); + group_bindings_.push_back(binding); + } } void Channels::showEvent(QShowEvent *event) diff --git a/pv/popups/channels.hpp b/pv/popups/channels.hpp index 54d24340..972549a8 100644 --- a/pv/popups/channels.hpp +++ b/pv/popups/channels.hpp @@ -79,9 +79,6 @@ private: void populate_group(shared_ptr group, const vector< shared_ptr > sigs); - QGridLayout* create_channel_group_grid( - const vector< shared_ptr > sigs); - void showEvent(QShowEvent *event); private Q_SLOTS: