Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / column_preferences_frame.cpp
blob42353cf1c93359d4cc280467d58ac13a9716090f
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
8 */
10 #include "config.h"
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"
26 #include <QComboBox>
27 #include <QTreeWidgetItemIterator>
28 #include <QLineEdit>
29 #include <QKeyEvent>
30 #include <QMenu>
31 #include <QAction>
33 ColumnPreferencesFrame::ColumnPreferencesFrame(QWidget *parent) :
34 QFrame(parent),
35 ui(new Ui::ColumnPreferencesFrame)
37 ui->setupUi(this);
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()
77 delete delegate_;
78 delete proxyModel_;
79 delete model_;
80 delete ui;
83 void ColumnPreferencesFrame::unstash()
85 model_->saveColumns();
86 mainApp->emitAppSignal(MainApplication::ColumnsChanged);
89 void ColumnPreferencesFrame::on_newToolButton_clicked()
91 model_->addEntry();
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*/)
125 model_->reset();