1 /* column_preferences_frame.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include <epan/column.h>
13 #include <epan/prefs.h>
14 #include <epan/proto.h>
16 #include <ui/preference_utils.h>
18 #include <ui/qt/utils/qt_ui_utils.h>
19 #include "column_preferences_frame.h"
20 #include <ui_column_preferences_frame.h>
21 #include <ui/qt/widgets/syntax_line_edit.h>
22 #include <ui/qt/widgets/field_filter_edit.h>
23 #include <ui/qt/models/column_list_model.h>
24 #include "main_application.h"
27 #include <QTreeWidgetItemIterator>
33 ColumnPreferencesFrame::ColumnPreferencesFrame(QWidget
*parent
) :
35 ui(new Ui::ColumnPreferencesFrame
)
39 model_
= new ColumnListModel();
40 proxyModel_
= new ColumnProxyModel();
41 proxyModel_
->setSourceModel(model_
);
43 int one_em
= ui
->columnTreeView
->fontMetrics().height();
44 ui
->columnTreeView
->setColumnWidth(ColumnListModel::COL_FIELDS
, one_em
* 10);
45 ui
->columnTreeView
->setColumnWidth(ColumnListModel::COL_OCCURRENCE
, one_em
* 5);
47 ui
->columnTreeView
->setMinimumWidth(one_em
* 20);
48 ui
->columnTreeView
->setMinimumHeight(one_em
* 12);
50 ui
->columnTreeView
->setSelectionMode(QAbstractItemView::SingleSelection
);
51 ui
->columnTreeView
->setDragEnabled(true);
52 ui
->columnTreeView
->viewport()->setAcceptDrops(true);
53 ui
->columnTreeView
->setDropIndicatorShown(true);
54 ui
->columnTreeView
->setDragDropMode(QAbstractItemView::InternalMove
);
55 ui
->columnTreeView
->setContextMenuPolicy(Qt::CustomContextMenu
);
57 ui
->newToolButton
->setStockIcon("list-add");
58 ui
->deleteToolButton
->setStockIcon("list-remove");
60 ui
->columnTreeView
->setModel(proxyModel_
);
61 delegate_
= new ColumnTypeDelegate();
62 ui
->columnTreeView
->setItemDelegate(delegate_
);
63 ui
->columnTreeView
->setSortingEnabled(false);
65 ui
->columnTreeView
->resizeColumnToContents(ColumnListModel::COL_DISPLAYED
);
66 ui
->columnTreeView
->resizeColumnToContents(ColumnListModel::COL_TITLE
);
67 ui
->columnTreeView
->resizeColumnToContents(ColumnListModel::COL_TYPE
);
68 ui
->columnTreeView
->resizeColumnToContents(ColumnListModel::COL_OCCURRENCE
);
69 ui
->columnTreeView
->resizeColumnToContents(ColumnListModel::COL_DISPLAY
);
71 connect(ui
->columnTreeView
->selectionModel(), &QItemSelectionModel::selectionChanged
,
72 this, &ColumnPreferencesFrame::selectionChanged
);
75 ColumnPreferencesFrame::~ColumnPreferencesFrame()
83 void ColumnPreferencesFrame::unstash()
85 model_
->saveColumns();
86 mainApp
->emitAppSignal(MainApplication::ColumnsChanged
);
89 void ColumnPreferencesFrame::on_newToolButton_clicked()
94 void ColumnPreferencesFrame::on_deleteToolButton_clicked()
96 if (ui
->columnTreeView
->selectionModel()->selectedIndexes().count() > 0)
98 QModelIndex selIndex
= ui
->columnTreeView
->selectionModel()->selectedIndexes().at(0);
99 model_
->deleteEntry(proxyModel_
->mapToSource(selIndex
).row());
103 void ColumnPreferencesFrame::selectionChanged(const QItemSelection
&/*selected*/,
104 const QItemSelection
&/*deselected*/)
106 ui
->deleteToolButton
->setEnabled(ui
->columnTreeView
->selectionModel()->selectedIndexes().count() > 0);
109 void ColumnPreferencesFrame::on_chkShowDisplayedOnly_stateChanged(int /*state*/)
111 proxyModel_
->setShowDisplayedOnly(ui
->chkShowDisplayedOnly
->checkState() == Qt::Checked
? true : false);
114 void ColumnPreferencesFrame::on_columnTreeView_customContextMenuRequested(const QPoint
&pos
)
116 QMenu
* contextMenu
= new QMenu(this);
117 contextMenu
->setAttribute(Qt::WA_DeleteOnClose
);
118 QAction
* action
= contextMenu
->addAction(tr("Reset all changes"));
119 connect(action
, &QAction::triggered
, this, &ColumnPreferencesFrame::resetAction
);
120 contextMenu
->popup(mapToGlobal(pos
));
123 void ColumnPreferencesFrame::resetAction(bool /*checked*/)