aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2019-04-10 19:56:18 +0200
committerAnders Broman <a.broman58@gmail.com>2019-04-13 20:56:39 +0000
commit458fa7b27412db389dba376a26c5e8b3184b1814 (patch)
treece7a38ec03b7de421b2208d923d562b26228b43e
parent65b5f50859d6f2bf7c5c8bec575ac7b2675fc896 (diff)
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 <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--ui/qt/extcap_argument_multiselect.cpp38
-rw-r--r--ui/qt/extcap_argument_multiselect.h4
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<QStandardItem *> 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<QStandardItem *> childs = valueWalker((*iter).children(), defaults);
if ( childs.length() > 0 )
@@ -68,7 +71,7 @@ QList<QStandardItem *> 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<QStandardItem *> 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: