blob: 961e2737a52f4df6b353e2191c865ee3b29f30a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* column_preferences_frame.cpp
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <glib.h>
#include <epan/column.h>
#include <epan/prefs.h>
#include <epan/proto.h>
#include <ui/preference_utils.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include "column_preferences_frame.h"
#include <ui_column_preferences_frame.h>
#include <ui/qt/widgets/syntax_line_edit.h>
#include <ui/qt/widgets/field_filter_edit.h>
#include <ui/qt/models/column_list_model.h>
#include "main_application.h"
#include <QComboBox>
#include <QTreeWidgetItemIterator>
#include <QLineEdit>
#include <QKeyEvent>
#include <QMenu>
#include <QAction>
ColumnPreferencesFrame::ColumnPreferencesFrame(QWidget *parent) :
QFrame(parent),
ui(new Ui::ColumnPreferencesFrame)
{
ui->setupUi(this);
model_ = new ColumnListModel();
proxyModel_ = new ColumnProxyModel();
proxyModel_->setSourceModel(model_);
int one_em = ui->columnTreeView->fontMetrics().height();
ui->columnTreeView->setColumnWidth(ColumnListModel::COL_FIELDS, one_em * 10);
ui->columnTreeView->setColumnWidth(ColumnListModel::COL_OCCURRENCE, one_em * 5);
ui->columnTreeView->setMinimumWidth(one_em * 20);
ui->columnTreeView->setMinimumHeight(one_em * 12);
ui->columnTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->columnTreeView->setDragEnabled(true);
ui->columnTreeView->viewport()->setAcceptDrops(true);
ui->columnTreeView->setDropIndicatorShown(true);
ui->columnTreeView->setDragDropMode(QAbstractItemView::InternalMove);
ui->columnTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
ui->newToolButton->setStockIcon("list-add");
ui->deleteToolButton->setStockIcon("list-remove");
ui->columnTreeView->setModel(proxyModel_);
delegate_ = new ColumnTypeDelegate();
ui->columnTreeView->setItemDelegate(delegate_);
ui->columnTreeView->setSortingEnabled(false);
ui->columnTreeView->resizeColumnToContents(ColumnListModel::COL_DISPLAYED);
ui->columnTreeView->resizeColumnToContents(ColumnListModel::COL_TITLE);
ui->columnTreeView->resizeColumnToContents(ColumnListModel::COL_TYPE);
ui->columnTreeView->resizeColumnToContents(ColumnListModel::COL_OCCURRENCE);
ui->columnTreeView->resizeColumnToContents(ColumnListModel::COL_RESOLVED);
connect(ui->columnTreeView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &ColumnPreferencesFrame::selectionChanged);
}
ColumnPreferencesFrame::~ColumnPreferencesFrame()
{
delete delegate_;
delete proxyModel_;
delete model_;
delete ui;
}
void ColumnPreferencesFrame::unstash()
{
model_->saveColumns();
mainApp->emitAppSignal(MainApplication::ColumnsChanged);
}
void ColumnPreferencesFrame::on_newToolButton_clicked()
{
model_->addEntry();
}
void ColumnPreferencesFrame::on_deleteToolButton_clicked()
{
if (ui->columnTreeView->selectionModel()->selectedIndexes().count() > 0)
{
QModelIndex selIndex = ui->columnTreeView->selectionModel()->selectedIndexes().at(0);
model_->deleteEntry(proxyModel_->mapToSource(selIndex).row());
}
}
void ColumnPreferencesFrame::selectionChanged(const QItemSelection &/*selected*/,
const QItemSelection &/*deselected*/)
{
ui->deleteToolButton->setEnabled(ui->columnTreeView->selectionModel()->selectedIndexes().count() > 0);
}
void ColumnPreferencesFrame::on_chkShowDisplayedOnly_stateChanged(int /*state*/)
{
proxyModel_->setShowDisplayedOnly(ui->chkShowDisplayedOnly->checkState() == Qt::Checked ? true : false);
}
void ColumnPreferencesFrame::on_columnTreeView_customContextMenuRequested(const QPoint &pos)
{
QMenu * contextMenu = new QMenu(this);
contextMenu->setAttribute(Qt::WA_DeleteOnClose);
QAction * action = contextMenu->addAction(tr("Reset all changes"));
connect(action, &QAction::triggered, this, &ColumnPreferencesFrame::resetAction);
contextMenu->popup(mapToGlobal(pos));
}
void ColumnPreferencesFrame::resetAction(bool /*checked*/)
{
model_->reset();
}
|