From 17e4998a47c72246063de98828599c4fa079a94e Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sun, 24 Apr 2016 14:18:44 -0700 Subject: Qt: Speed up the Display Filter Expression dialog appearance. Copy over and adapt SupportedProtocolsDialog::fillTree, which fills in the protocol tree after the dialog is shown processes display events while the tree is being built. Change-Id: I25082fd94c511db6a94aaed1c463ba1c1e64855c Reviewed-on: https://code.wireshark.org/review/15079 Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs --- ui/qt/display_filter_expression_dialog.cpp | 92 +++++++++++++++++++----------- ui/qt/display_filter_expression_dialog.h | 1 + ui/qt/supported_protocols_dialog.cpp | 1 + 3 files changed, 60 insertions(+), 34 deletions(-) diff --git a/ui/qt/display_filter_expression_dialog.cpp b/ui/qt/display_filter_expression_dialog.cpp index 5bac97aec3..d252cc5998 100644 --- a/ui/qt/display_filter_expression_dialog.cpp +++ b/ui/qt/display_filter_expression_dialog.cpp @@ -81,37 +81,6 @@ DisplayFilterExpressionDialog::DisplayFilterExpressionDialog(QWidget *parent) : ui->enumListWidget->setToolTip(ui->enumLabel->toolTip()); ui->rangeLineEdit->setToolTip(ui->rangeLabel->toolTip()); - // Field tree - ui->fieldTreeWidget->setUpdatesEnabled(false); - void *proto_cookie; - for (int proto_id = proto_get_first_protocol(&proto_cookie); proto_id != -1; proto_id = proto_get_next_protocol(&proto_cookie)) { - protocol_t *protocol = find_protocol_by_id(proto_id); - if (!proto_is_protocol_enabled(protocol)) continue; - - QTreeWidgetItem *proto_ti = new QTreeWidgetItem(proto_type_); - QString label = QString("%1 " UTF8_MIDDLE_DOT " %3") - .arg(proto_get_protocol_short_name(protocol)) - .arg(proto_get_protocol_long_name(protocol)); - proto_ti->setText(0, label); - proto_ti->setData(0, Qt::UserRole, qVariantFromValue(proto_id)); - - QList fti_list; - void *field_cookie; - for (header_field_info *hfinfo = proto_get_first_protocol_field(proto_id, &field_cookie); hfinfo; hfinfo = proto_get_next_protocol_field(proto_id, &field_cookie)) { - if (hfinfo->same_name_prev_id != -1) continue; // Ignore duplicate names. - - QTreeWidgetItem *field_ti = new QTreeWidgetItem(field_type_); - label = QString("%1 " UTF8_MIDDLE_DOT " %3").arg(hfinfo->abbrev).arg(hfinfo->name); - field_ti->setText(0, label); - field_ti->setData(0, Qt::UserRole, qVariantFromValue(hfinfo)); - fti_list << field_ti; - } - proto_ti->addChildren(fti_list); - ui->fieldTreeWidget->addTopLevelItem(proto_ti); - } - ui->fieldTreeWidget->sortByColumn(0, Qt::AscendingOrder); - ui->fieldTreeWidget->setUpdatesEnabled(true); - // Relation list new QListWidgetItem("is present", ui->relationListWidget, present_op_); new QListWidgetItem("==", ui->relationListWidget, eq_op_); @@ -130,9 +99,8 @@ DisplayFilterExpressionDialog::DisplayFilterExpressionDialog(QWidget *parent) : // Trigger updateWidgets ui->fieldTreeWidget->selectionModel()->clear(); -// if (ui->fieldTreeWidget->topLevelItemCount() > 0) { -// ui->fieldTreeWidget->topLevelItem(0)->setSelected(true); -// } + + QTimer::singleShot(0, this, SLOT(fillTree())); } DisplayFilterExpressionDialog::~DisplayFilterExpressionDialog() @@ -140,6 +108,60 @@ DisplayFilterExpressionDialog::~DisplayFilterExpressionDialog() delete ui; } +// Nearly identical to SupportedProtocolsDialog::fillTree. +void DisplayFilterExpressionDialog::fillTree() +{ + void *proto_cookie; + QList proto_list; + + for (int proto_id = proto_get_first_protocol(&proto_cookie); proto_id != -1; + proto_id = proto_get_next_protocol(&proto_cookie)) { + protocol_t *protocol = find_protocol_by_id(proto_id); + if (!proto_is_protocol_enabled(protocol)) continue; + + QTreeWidgetItem *proto_ti = new QTreeWidgetItem(proto_type_); + QString label = QString("%1 " UTF8_MIDDLE_DOT " %3") + .arg(proto_get_protocol_short_name(protocol)) + .arg(proto_get_protocol_long_name(protocol)); + proto_ti->setText(0, label); + proto_ti->setData(0, Qt::UserRole, qVariantFromValue(proto_id)); + proto_list << proto_ti; + } + + wsApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 1); + + ui->fieldTreeWidget->invisibleRootItem()->addChildren(proto_list); + ui->fieldTreeWidget->sortByColumn(0, Qt::AscendingOrder); + + int field_count = 0; + foreach (QTreeWidgetItem *proto_ti, proto_list) { + void *field_cookie; + int proto_id = proto_ti->data(0, Qt::UserRole).toInt(); + + QList field_list; + for (header_field_info *hfinfo = proto_get_first_protocol_field(proto_id, &field_cookie); hfinfo != NULL; + hfinfo = proto_get_next_protocol_field(proto_id, &field_cookie)) { + if (hfinfo->same_name_prev_id != -1) continue; // Ignore duplicate names. + + QTreeWidgetItem *field_ti = new QTreeWidgetItem(field_type_); + QString label = QString("%1 " UTF8_MIDDLE_DOT " %3").arg(hfinfo->abbrev).arg(hfinfo->name); + field_ti->setText(0, label); + field_ti->setData(0, Qt::UserRole, qVariantFromValue(hfinfo)); + field_list << field_ti; + + field_count++; + if (field_count % 10000 == 0) { + wsApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 1); + } + } + std::sort(field_list.begin(), field_list.end()); + proto_ti->addChildren(field_list); + } + + wsApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 1); + ui->fieldTreeWidget->sortByColumn(0, Qt::AscendingOrder); +} + void DisplayFilterExpressionDialog::updateWidgets() { bool rel_enable = field_ != NULL; @@ -394,6 +416,7 @@ void DisplayFilterExpressionDialog::on_enumListWidget_itemSelectionChanged() void DisplayFilterExpressionDialog::on_searchLineEdit_textChanged(const QString &search_re) { + ui->fieldTreeWidget->setUpdatesEnabled(false); QTreeWidgetItemIterator it(ui->fieldTreeWidget); QRegExp regex(search_re, Qt::CaseInsensitive); while (*it) { @@ -407,6 +430,7 @@ void DisplayFilterExpressionDialog::on_searchLineEdit_textChanged(const QString (*it)->setHidden(hidden); ++it; } + ui->fieldTreeWidget->setUpdatesEnabled(true); } void DisplayFilterExpressionDialog::on_buttonBox_accepted() diff --git a/ui/qt/display_filter_expression_dialog.h b/ui/qt/display_filter_expression_dialog.h index eae5bc7e1e..8c1a0ee083 100644 --- a/ui/qt/display_filter_expression_dialog.h +++ b/ui/qt/display_filter_expression_dialog.h @@ -49,6 +49,7 @@ signals: void insertDisplayFilter(const QString &filter); private slots: + void fillTree(); void updateWidgets(); void on_fieldTreeWidget_itemSelectionChanged(); diff --git a/ui/qt/supported_protocols_dialog.cpp b/ui/qt/supported_protocols_dialog.cpp index 1bd1dc8d60..b170104e96 100644 --- a/ui/qt/supported_protocols_dialog.cpp +++ b/ui/qt/supported_protocols_dialog.cpp @@ -80,6 +80,7 @@ void SupportedProtocolsDialog::updateStatistics() wsApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 1); } +// Nearly identical to DisplayFilterExpressionDialog::fillTree. void SupportedProtocolsDialog::fillTree() { void *proto_cookie; -- cgit v1.2.3