From 458fa7b27412db389dba376a26c5e8b3184b1814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Wed, 10 Apr 2019 19:56:18 +0200 Subject: [PATCH] Qt: Display checkboxes for extcap multicheck Multicheck was introduced to make it easy to configure USBPcap to capture only from selected devices instead of the whole Root Hub. In GTK+ interface the multicheck enabled options featured a checkbox next to the item entry. Displaying the checkboxes made it intuitive to the user that the items can be checked/unchecked. During the GTK+ to Qt transition, the checkbox idea got lost. The GTK+ interface up to its very last days did show the checkboxes. While it is possible to select the individual devices in Qt UI and actually have USBPcap to capture only on selected devices, it is really unintuitive and the user simply has to know how the multicheck is implemented to take advantage of it. This change brings the multicheck checkboxes to Qt UI. Ping-Bug: 13355 Change-Id: Ia677ff2222c46b9816b8dca4c47e93c72cee834f Reviewed-on: https://code.wireshark.org/review/32813 Petri-Dish: Anders Broman Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall Reviewed-by: Anders Broman --- ui/qt/extcap_argument_multiselect.cpp | 38 +++++++++++++-------------- ui/qt/extcap_argument_multiselect.h | 4 +-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ui/qt/extcap_argument_multiselect.cpp b/ui/qt/extcap_argument_multiselect.cpp index 511411746f..d5a6db5bcc 100644 --- a/ui/qt/extcap_argument_multiselect.cpp +++ b/ui/qt/extcap_argument_multiselect.cpp @@ -47,15 +47,18 @@ QList ExtArgMultiSelect::valueWalker(ExtcapValueList list, QStr QStandardItem * item = new QStandardItem((*iter).value()); if ( (*iter).enabled() == false ) { - item->setSelectable(false); + item->setCheckable(false); } else - item->setSelectable(true); + { + item->setCheckable(true); + } item->setData((*iter).call(), Qt::UserRole); if ((*iter).isDefault()) defaults << (*iter).call(); + item->setSelectable(false); item->setEditable(false); QList childs = valueWalker((*iter).children(), defaults); if ( childs.length() > 0 ) @@ -68,7 +71,7 @@ QList ExtArgMultiSelect::valueWalker(ExtcapValueList list, QStr return items; } -void ExtArgMultiSelect::selectItemsWalker(QStandardItem * item, QStringList defaults) +void ExtArgMultiSelect::checkItemsWalker(QStandardItem * item, QStringList defaults) { QModelIndexList results; QModelIndex index; @@ -80,7 +83,7 @@ void ExtArgMultiSelect::selectItemsWalker(QStandardItem * item, QStringList defa QStandardItem * child = item->child(row); if ( child != 0 ) { - selectItemsWalker(child, defaults); + checkItemsWalker(child, defaults); } } } @@ -89,7 +92,7 @@ void ExtArgMultiSelect::selectItemsWalker(QStandardItem * item, QStringList defa if ( defaults.contains(data) ) { - treeView->selectionModel()->select(item->index(), QItemSelectionModel::Select); + item->setCheckState(Qt::Checked); index = item->index(); while ( index.isValid() ) { @@ -128,11 +131,11 @@ QWidget * ExtArgMultiSelect::createEditor(QWidget * parent) treeView->setEditTriggers(QAbstractItemView::NoEditTriggers); for (int row = 0; row < viewModel->rowCount(); row++ ) - selectItemsWalker(((QStandardItemModel*)viewModel)->item(row), defaults); + checkItemsWalker(((QStandardItemModel*)viewModel)->item(row), defaults); - connect ( treeView->selectionModel(), - SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), - SLOT(selectionChanged(const QItemSelection &, const QItemSelection &)) ); + connect ( viewModel, + SIGNAL(itemChanged(QStandardItem *)), + SLOT(itemChanged(QStandardItem *))); return treeView; } @@ -143,13 +146,12 @@ QString ExtArgMultiSelect::value() return QString(); QStringList result; - QModelIndexList selected = treeView->selectionModel()->selectedIndexes(); - - if ( selected.size() <= 0 ) + QModelIndexList checked = viewModel->match(viewModel->index(0, 0), Qt::CheckStateRole, Qt::Checked, -1, Qt::MatchExactly | Qt::MatchRecursive); + if ( checked.size() <= 0 ) return QString(); - QModelIndexList::const_iterator iter = selected.constBegin(); - while ( iter != selected.constEnd() ) + QModelIndexList::const_iterator iter = checked.constBegin(); + while ( iter != checked.constEnd() ) { QModelIndex index = (QModelIndex)(*iter); @@ -161,7 +163,7 @@ QString ExtArgMultiSelect::value() return result.join(QString(",")); } -void ExtArgMultiSelect::selectionChanged(const QItemSelection &, const QItemSelection &) +void ExtArgMultiSelect::itemChanged(QStandardItem *) { emit valueChanged(); } @@ -176,10 +178,8 @@ bool ExtArgMultiSelect::isValid() valid = false; else { - QStringList result; - QModelIndexList selected = treeView->selectionModel()->selectedIndexes(); - - if ( selected.size() <= 0 ) + QModelIndexList checked = viewModel->match(viewModel->index(0, 0), Qt::CheckStateRole, Qt::Checked, -1, Qt::MatchExactly | Qt::MatchRecursive); + if ( checked.size() <= 0 ) valid = false; } } diff --git a/ui/qt/extcap_argument_multiselect.h b/ui/qt/extcap_argument_multiselect.h index 4ae36abb6f..d4160597a5 100644 --- a/ui/qt/extcap_argument_multiselect.h +++ b/ui/qt/extcap_argument_multiselect.h @@ -32,12 +32,12 @@ public: protected: virtual QList valueWalker(ExtcapValueList list, QStringList &defaults); - void selectItemsWalker(QStandardItem * item, QStringList defaults); + void checkItemsWalker(QStandardItem * item, QStringList defaults); virtual QWidget * createEditor(QWidget * parent); private Q_SLOTS: - void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected); + void itemChanged(QStandardItem *); private: