Qt: Filter Dissector tables properly
Also cleanup the code a little bit Change-Id: I53097478fafa46249fa6ecb52508d9bc5b963caa Reviewed-on: https://code.wireshark.org/review/24908 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org> Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
153d588972
commit
57d54a2fc0
|
@ -9,53 +9,41 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include "dissector_tables_dialog.h"
|
||||
#include <ui/qt/dissector_tables_dialog.h>
|
||||
#include <ui_dissector_tables_dialog.h>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "wireshark_application.h"
|
||||
|
||||
DissectorTablesDialog::DissectorTablesDialog(QWidget *parent) :
|
||||
GeometryStateDialog(parent),
|
||||
ui(new Ui::DissectorTablesDialog),
|
||||
dissector_tables_model_(new DissectorTablesModel()),
|
||||
proxyModel_(new DissectorTablesProxyModel(this))
|
||||
ui(new Ui::DissectorTablesDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
if (parent) loadGeometry(parent->width() * 3 / 4, parent->height() * 3 / 4);
|
||||
|
||||
if (parent)
|
||||
loadGeometry(parent->width() * 3 / 4, parent->height() * 3 / 4);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setWindowTitle(wsApp->windowTitleString(tr("Dissector Tables")));
|
||||
|
||||
proxyModel_->setSourceModel(dissector_tables_model_);
|
||||
proxyModel_ = new DissectorTablesProxyModel(this);
|
||||
proxyModel_->setSourceModel(new DissectorTablesModel(this));
|
||||
//it's recommended to sort after list is populated
|
||||
proxyModel_->sort(DissectorTablesModel::colTableName);
|
||||
|
||||
ui->tableTree->setModel(proxyModel_);
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(fillTree()));
|
||||
//expand the "type" tables
|
||||
ui->tableTree->expandToDepth(0);
|
||||
ui->tableTree->resizeColumnToContents(DissectorTablesModel::colTableName);
|
||||
}
|
||||
|
||||
DissectorTablesDialog::~DissectorTablesDialog()
|
||||
{
|
||||
delete ui;
|
||||
delete proxyModel_;
|
||||
delete dissector_tables_model_;
|
||||
}
|
||||
|
||||
void DissectorTablesDialog::fillTree()
|
||||
{
|
||||
dissector_tables_model_->populate();
|
||||
|
||||
//it's recommended to sort after list is populated
|
||||
proxyModel_->sort(DissectorTablesModel::colTableName);
|
||||
|
||||
//expand the "type" tables
|
||||
for (int row = 0; row < proxyModel_->rowCount(); row++) {
|
||||
ui->tableTree->setExpanded(proxyModel_->index(row, DissectorTablesModel::colTableName), true);
|
||||
}
|
||||
|
||||
ui->tableTree->resizeColumnToContents(DissectorTablesModel::colTableName);
|
||||
}
|
||||
|
||||
void DissectorTablesDialog::on_search_line_edit__textChanged(const QString &search_re)
|
||||
void DissectorTablesDialog::on_txtSearchLine_textChanged(const QString &search_re)
|
||||
{
|
||||
proxyModel_->setFilter(search_re);
|
||||
}
|
||||
|
|
|
@ -10,15 +10,13 @@
|
|||
#ifndef DISSECTOR_TABLES_DIALOG_H
|
||||
#define DISSECTOR_TABLES_DIALOG_H
|
||||
|
||||
#include "geometry_state_dialog.h"
|
||||
#include <ui/qt/geometry_state_dialog.h>
|
||||
#include <ui/qt/models/dissector_tables_model.h>
|
||||
|
||||
namespace Ui {
|
||||
class DissectorTablesDialog;
|
||||
}
|
||||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
class DissectorTablesDialog : public GeometryStateDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -28,13 +26,11 @@ public:
|
|||
~DissectorTablesDialog();
|
||||
|
||||
private slots:
|
||||
void on_search_line_edit__textChanged(const QString &search_re);
|
||||
void fillTree();
|
||||
void on_txtSearchLine_textChanged(const QString &search_re);
|
||||
|
||||
private:
|
||||
Ui::DissectorTablesDialog *ui;
|
||||
|
||||
DissectorTablesModel* dissector_tables_model_;
|
||||
DissectorTablesProxyModel* proxyModel_;
|
||||
};
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="search_line_edit_"/>
|
||||
<widget class="QLineEdit" name="txtSearchLine"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
@ -48,11 +48,11 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>DissectorTablesTreeView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>widgets/dissector_tables_view.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>DissectorTablesTreeView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>widgets/dissector_tables_view.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
|
|
@ -140,6 +140,7 @@ DissectorTablesModel::DissectorTablesModel(QObject *parent) :
|
|||
QAbstractItemModel(parent),
|
||||
root_(new DissectorTablesItem(QString("ROOT"), QString("ROOT"), NULL))
|
||||
{
|
||||
populate();
|
||||
}
|
||||
|
||||
DissectorTablesModel::~DissectorTablesModel()
|
||||
|
@ -149,7 +150,7 @@ DissectorTablesModel::~DissectorTablesModel()
|
|||
|
||||
int DissectorTablesModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
DissectorTablesItem *parent_item;
|
||||
DissectorTablesItem *parent_item;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
|
||||
|
@ -405,12 +406,10 @@ bool DissectorTablesProxyModel::lessThan(const QModelIndex &left, const QModelIn
|
|||
|
||||
bool DissectorTablesProxyModel::filterAcceptItem(DissectorTablesItem& item) const
|
||||
{
|
||||
QRegExp regex(filter_, Qt::CaseInsensitive);
|
||||
|
||||
if (item.tableName().contains(regex))
|
||||
if ( filter_.isEmpty() )
|
||||
return true;
|
||||
|
||||
if (item.shortName().contains(regex))
|
||||
if (item.tableName().contains(filter_, Qt::CaseInsensitive) || item.shortName().contains(filter_, Qt::CaseInsensitive))
|
||||
return true;
|
||||
|
||||
DissectorTablesItem *child_item;
|
||||
|
@ -429,14 +428,12 @@ bool DissectorTablesProxyModel::filterAcceptsRow(int sourceRow, const QModelInde
|
|||
QModelIndex nameIdx = sourceModel()->index(sourceRow, DissectorTablesModel::colTableName, sourceParent);
|
||||
DissectorTablesItem* item = static_cast<DissectorTablesItem*>(nameIdx.internalPointer());
|
||||
if (item == NULL)
|
||||
return false;
|
||||
|
||||
if (filterAcceptItem(*item))
|
||||
return true;
|
||||
|
||||
if (!filter_.isEmpty()) {
|
||||
if (filterAcceptItem(*item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void DissectorTablesProxyModel::setFilter(const QString& filter)
|
||||
|
|
Loading…
Reference in New Issue