summaryrefslogtreecommitdiff
path: root/ui/qt/interface_tree_model.cpp
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2016-10-17 15:01:24 +0200
committerAnders Broman <a.broman58@gmail.com>2016-10-19 07:43:45 +0000
commit864f750be560a7a739c7453f19a8f5679cf7d6b3 (patch)
treee7d4c74c127a477c13f70ee69c82c6f06274f9a1 /ui/qt/interface_tree_model.cpp
parent5cbdbecc35f77c40142e2e5389e553931490eea0 (diff)
downloadwireshark-864f750be560a7a739c7453f19a8f5679cf7d6b3.tar.gz
ManageInterfacesDialog: Implement View/Data Model
Implement the same interface view/data model as used for the interface_tree selection in this dialog, to encapsulate all access to global_capture_devices from the dialog. Change-Id: I0e568fe236d077befa2a79765638db8bb3ed1a3f Reviewed-on: https://code.wireshark.org/review/18062 Petri-Dish: Roland Knall <rknall@gmail.com> Reviewed-by: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/interface_tree_model.cpp')
-rw-r--r--ui/qt/interface_tree_model.cpp124
1 files changed, 86 insertions, 38 deletions
diff --git a/ui/qt/interface_tree_model.cpp b/ui/qt/interface_tree_model.cpp
index 7682362f25..013062999c 100644
--- a/ui/qt/interface_tree_model.cpp
+++ b/ui/qt/interface_tree_model.cpp
@@ -115,14 +115,15 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
return QVariant();
int row = index.row();
- int col = index.column();
+ InterfaceTreeColumns col = (InterfaceTreeColumns) index.column();
- /* Data for display in cell */
- if ( role == Qt::DisplayRole )
+ if ( interfacesLoaded )
{
- if ( interfacesLoaded )
+ interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row);
+
+ /* Data for display in cell */
+ if ( role == Qt::DisplayRole )
{
- interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row);
/* Only the name is being displayed */
if ( col == IFTREE_COL_NAME )
{
@@ -138,50 +139,69 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
return QString(device.if_info.extcap);
}
#endif
- 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);
}
+ else if ( col == IFTREE_COL_INTERFACE_COMMENT )
+ {
+ QString comment = gchar_free_to_qstring(capture_dev_user_descr_find(device.name));
+ if ( comment.length() > 0 )
+ return comment;
+ else
+ return QString(device.if_info.vendor_description);
+ }
+ else
+ {
+ /* Return empty string for every other DisplayRole */
+ return QVariant();
+ }
+ }
+ else if ( role == Qt::CheckStateRole )
+ {
+ if ( col == IFTREE_COL_HIDDEN )
+ {
+ /* Hidden is a de-selection, therefore inverted logic here */
+ return device.hidden ? Qt::Unchecked : Qt::Checked;
+ }
+ }
+ /* Used by SparkLineDelegate for loading the data for the statistics line */
+ else if ( role == Qt::UserRole )
+ {
+ if ( col == IFTREE_COL_STATS )
+ {
+ if ( points.contains(device.name) )
+ return qVariantFromValue(points[device.name]);
+ }
+ else if ( col == IFTREE_COL_HIDDEN )
+ {
+ return QVariant::fromValue((bool)device.hidden);
+ }
}
-
- /* Return empty string for every other DisplayRole */
- return QVariant();
- }
- /* Used by SparkLineDelegate for loading the data for the statistics line */
- else if ( role == Qt::UserRole && col == IFTREE_COL_STATS && interfacesLoaded )
- {
- interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row);
- if ( points.contains(device.name) )
- return qVariantFromValue(points[device.name]);
- }
#ifdef HAVE_EXTCAP
- /* Displays the configuration icon for extcap interfaces */
- else if ( role == Qt::DecorationRole && interfacesLoaded )
- {
- if ( col == IFTREE_COL_EXTCAP )
+ /* Displays the configuration icon for extcap interfaces */
+ else if ( role == Qt::DecorationRole )
{
- QIcon extcap_icon(StockIcon("x-capture-options"));
- interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row);
- if ( device.if_info.type == IF_EXTCAP )
- return extcap_icon;
+ if ( col == IFTREE_COL_EXTCAP )
+ {
+ if ( device.if_info.type == IF_EXTCAP )
+ return QIcon(StockIcon("x-capture-options"));
+ }
}
- }
- else if ( role == Qt::TextAlignmentRole)
- {
- if ( col == IFTREE_COL_EXTCAP )
+ else if ( role == Qt::TextAlignmentRole )
{
- return Qt::AlignRight;
+ if ( col == IFTREE_COL_EXTCAP )
+ {
+ return Qt::AlignRight;
+ }
}
- }
#endif
- /* Displays the tooltip for each row */
- else if ( role == Qt::ToolTipRole )
- {
- return toolTipForInterface(row);
+ /* Displays the tooltip for each row */
+ else if ( role == Qt::ToolTipRole )
+ {
+ return toolTipForInterface(row);
+ }
}
#else
Q_UNUSED(index);
@@ -191,6 +211,34 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
return QVariant();
}
+QVariant InterfaceTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if ( orientation == Qt::Horizontal )
+ {
+ if ( role == Qt::DisplayRole )
+ {
+ if ( section == IFTREE_COL_HIDDEN )
+ {
+ return tr("Show");
+ }
+ else if ( section == IFTREE_COL_INTERFACE_NAME )
+ {
+ return tr("Friendly Name");
+ }
+ else if ( section == IFTREE_COL_INTERFACE_NAME )
+ {
+ return tr("Interface Name");
+ }
+ else if ( section == IFTREE_COL_INTERFACE_COMMENT )
+ {
+ return tr("Comment");
+ }
+ }
+ }
+
+ return QVariant();
+}
+
QVariant InterfaceTreeModel::getColumnContent(int idx, int col, int role)
{
return InterfaceTreeModel::data(index(idx, col), role);