diff options
author | Roland Knall <roland.knall@br-automation.com> | 2016-10-06 17:04:45 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2016-10-07 14:31:30 +0000 |
commit | d58da8ec9098f249abd3fd0dfb3e00dee6ff47b4 (patch) | |
tree | 5e9b532e5d6b77f2c6654ca53e98a4084536a59e /ui/qt/interface_sort_filter_model.cpp | |
parent | a239472f303b1b482b5ec91e631a16d3ae3c90ce (diff) | |
download | wireshark-d58da8ec9098f249abd3fd0dfb3e00dee6ff47b4.tar.gz |
Interface View/Model: Correct column ordering
This orders the columns correctly in the sequence the developer
has intended when adding them with setColumns. Also it allows for
disabling and inverting the filtering by type, as well as query
additional roles instead of only Qt::DisplayRole from the tree model.
Change-Id: I90469e8e3f3caa50debb3c839590d42719a6fb10
Reviewed-on: https://code.wireshark.org/review/18096
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'ui/qt/interface_sort_filter_model.cpp')
-rw-r--r-- | ui/qt/interface_sort_filter_model.cpp | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/ui/qt/interface_sort_filter_model.cpp b/ui/qt/interface_sort_filter_model.cpp index 5a1823a398..b96674eea7 100644 --- a/ui/qt/interface_sort_filter_model.cpp +++ b/ui/qt/interface_sort_filter_model.cpp @@ -37,6 +37,8 @@ InterfaceSortFilterModel::InterfaceSortFilterModel(QObject *parent) : QSortFilterProxyModel(parent) { _filterHidden = true; + _filterTypes = true; + _invertTypeFilter = false; /* Adding all columns, to have a default setting */ for ( int col = 0; col < IFTREE_COL_MAX; col++ ) @@ -54,6 +56,14 @@ void InterfaceSortFilterModel::setFilterHidden(bool filter) invalidate(); } +void InterfaceSortFilterModel::setFilterByType(bool filter, bool invert) +{ + _filterTypes = filter; + _invertTypeFilter = invert; + + invalidate(); +} + void InterfaceSortFilterModel::resetPreferenceData() { displayHiddenTypes.clear(); @@ -77,6 +87,11 @@ bool InterfaceSortFilterModel::filterHidden() const return _filterHidden; } +bool InterfaceSortFilterModel::filterByType() const +{ + return _filterTypes; +} + int InterfaceSortFilterModel::interfacesHidden() { #ifdef HAVE_LIBPCAP @@ -136,10 +151,14 @@ void InterfaceSortFilterModel::setInterfaceTypeVisible(int ifType, bool visible) bool InterfaceSortFilterModel::isInterfaceTypeShown(int ifType) const { - if ( ! displayHiddenTypes.contains(ifType) ) - return true; + bool result = false; - return false; + if ( displayHiddenTypes.size() == 0 ) + result = true; + else if ( ! displayHiddenTypes.contains(ifType) ) + result = true; + + return ( ( _invertTypeFilter && ! result ) || ( ! _invertTypeFilter && result ) ); } bool InterfaceSortFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const @@ -157,12 +176,12 @@ bool InterfaceSortFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex return false; int type = ((InterfaceTreeModel *)sourceModel())->getColumnContent(idx, IFTREE_COL_TYPE).toInt(); - bool hidden = ((InterfaceTreeModel *)sourceModel())->getColumnContent(idx, IFTREE_COL_HIDDEN).toBool(); + bool hidden = ((InterfaceTreeModel *)sourceModel())->getColumnContent(idx, IFTREE_COL_HIDDEN, Qt::UserRole).toBool(); if ( hidden && _filterHidden ) return false; - if ( ! isInterfaceTypeShown(type) ) + if ( _filterTypes && ! isInterfaceTypeShown(type) ) return false; #endif @@ -196,6 +215,29 @@ int InterfaceSortFilterModel::mapSourceToColumn(InterfaceTreeColumns mdlIndex) return _columns.indexOf(mdlIndex, 0); } +QModelIndex InterfaceSortFilterModel::mapToSource(const QModelIndex &proxyIndex) const +{ + if ( ! proxyIndex.isValid() ) + return QModelIndex(); + + QModelIndex baseIndex = QSortFilterProxyModel::mapToSource(proxyIndex); + QModelIndex newIndex = sourceModel()->index(baseIndex.row(), _columns.at(proxyIndex.column())); + + return newIndex; +} + +QModelIndex InterfaceSortFilterModel::mapFromSource(const QModelIndex &sourceIndex) const +{ + if ( ! sourceIndex.isValid() ) + return QModelIndex(); + else if ( ! _columns.contains( (InterfaceTreeColumns) sourceIndex.column() ) ) + return QModelIndex(); + + QModelIndex newIndex = QSortFilterProxyModel::mapFromSource(sourceIndex); + + return index(newIndex.row(), _columns.indexOf((InterfaceTreeColumns) sourceIndex.column())); +} + /* * Editor modelines * |