From e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 22:34:10 +0200 Subject: Adding upstream version 4.2.2. Signed-off-by: Daniel Baumann --- ui/qt/column_preferences_frame.cpp | 128 +++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 ui/qt/column_preferences_frame.cpp (limited to 'ui/qt/column_preferences_frame.cpp') diff --git a/ui/qt/column_preferences_frame.cpp b/ui/qt/column_preferences_frame.cpp new file mode 100644 index 00000000..961e2737 --- /dev/null +++ b/ui/qt/column_preferences_frame.cpp @@ -0,0 +1,128 @@ +/* column_preferences_frame.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "config.h" + +#include + +#include +#include +#include + +#include + +#include +#include "column_preferences_frame.h" +#include +#include +#include +#include +#include "main_application.h" + +#include +#include +#include +#include +#include +#include + +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(); +} -- cgit v1.2.3