diff options
author | Roland Knall <roland.knall@br-automation.com> | 2016-10-03 16:31:36 +0200 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2016-10-03 17:06:03 +0000 |
commit | a50bed094bdb03ce68b65c6a69696ce446f9dd3d (patch) | |
tree | e401234babf57832582a86a815a98ea1e74ae5db /ui/qt/interface_tree_model.cpp | |
parent | 542c3c6f3a87ba147dd85f2909270cc2ad320e93 (diff) | |
download | wireshark-a50bed094bdb03ce68b65c6a69696ce446f9dd3d.tar.gz |
Interface List: Allow column filtering in model
This change allows for the definition of columns to be shown
to the enduser if instanting the proxy model. The tree model
will allways transport ALL data, and it is the job of the proxy
model to determine which data is actually shown.
Additionally, this removes the final definitions of the global
interface array from interface_frame as well as sort_filter, so
that knowledge about the inner workings of the interface list
is contained to interface_tree_model
Change-Id: Ib34b150066ee344ad0d18bec1d90826eb0fa28b2
Reviewed-on: https://code.wireshark.org/review/18039
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/interface_tree_model.cpp')
-rw-r--r-- | ui/qt/interface_tree_model.cpp | 125 |
1 files changed, 124 insertions, 1 deletions
diff --git a/ui/qt/interface_tree_model.cpp b/ui/qt/interface_tree_model.cpp index 94e94113d8..ab1ee1d612 100644 --- a/ui/qt/interface_tree_model.cpp +++ b/ui/qt/interface_tree_model.cpp @@ -71,6 +71,23 @@ InterfaceTreeModel::~InterfaceTreeModel(void) #endif // HAVE_LIBPCAP } +QString InterfaceTreeModel::interfaceError() +{ + QString errorText; + if ( rowCount() == 0 ) + { + errorText = tr("No Interfaces found!"); + } +#ifdef HAVE_LIBPCAP + else if ( global_capture_opts.ifaces_err != 0 ) + { + errorText = tr(global_capture_opts.ifaces_err_info); + } +#endif + + return errorText; +} + int InterfaceTreeModel::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); @@ -115,7 +132,22 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const { return QString(device.display_name); } - + else if ( col == IFTREE_COL_INTERFACE_NAME ) + { + return QString(device.name); + } + else if ( col == IFTREE_COL_EXTCAP_PATH ) + { + return QString(device.if_info.extcap); + } + else if ( col == IFTREE_COL_HIDDEN ) + { + return QVariant::fromValue((bool)device.hidden); + } + else if ( col == IFTREE_COL_TYPE ) + { + return QVariant::fromValue((int)device.if_info.type); + } } /* Return empty string for every other DisplayRole */ @@ -160,6 +192,11 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const return QVariant(); } +QVariant InterfaceTreeModel::getColumnContent(int idx, int col) +{ + return InterfaceTreeModel::data(index(idx, col), Qt::DisplayRole); +} + /** * The interface list has changed. global_capture_opts.all_ifaces may have been reloaded * or changed with current data. beginResetModel() and endResetModel() will signalize the @@ -300,3 +337,89 @@ void InterfaceTreeModel::getPoints(int idx, PointList *pts) Q_UNUSED(pts); #endif } + +QItemSelection InterfaceTreeModel::selectedDevices() +{ + QItemSelection mySelection; + + for( int idx = 0; idx < rowCount(); idx++ ) + { + interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); + + if ( device.selected ) + { + QModelIndex selectIndex = index(idx, 0); + /* Proxy model has masked out the interface */ + if ( !selectIndex.isValid() ) + continue; + + mySelection.merge( + QItemSelection( selectIndex, index(selectIndex.row(), columnCount() - 1) ), + QItemSelectionModel::SelectCurrent + ); + } + } + + return mySelection; +} + +bool InterfaceTreeModel::updateSelectedDevices(QItemSelection sourceSelection) +{ + bool selectionHasChanged = false; + QList<int> selectedIndices; + + foreach(QItemSelectionRange selection, sourceSelection) + { + foreach(QModelIndex index, selection.indexes()) + { + if ( ! selectedIndices.contains(index.row()) ) + { + selectedIndices.append(index.row()); + } + } + } + + global_capture_opts.num_selected = 0; + + for ( unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++ ) + { + interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); + if ( !device.locked ) + { + if ( selectedIndices.contains(idx) ) + { + if (! device.selected ) + selectionHasChanged = true; + device.selected = TRUE; + global_capture_opts.num_selected++; + } else { + if ( device.selected ) + selectionHasChanged = true; + device.selected = FALSE; + } + device.locked = TRUE; + global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, idx); + g_array_insert_val(global_capture_opts.all_ifaces, idx, device); + + device.locked = FALSE; + global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, idx); + g_array_insert_val(global_capture_opts.all_ifaces, idx, device); + } + } + + return selectionHasChanged; +} + + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ |