aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/stats_tree_dialog.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2015-06-08 11:33:16 -0700
committerGerald Combs <gerald@wireshark.org>2015-06-08 19:51:34 +0000
commit2d863b9782f19e0821cacfbf6c7ab17fa1183317 (patch)
treea402d791b8411dc33135b5e78b296b2158b2fcfb /ui/qt/stats_tree_dialog.cpp
parent2533889f3c0116d64f374eab5677876c5366d134 (diff)
Add TapParameterDialog.
Split StatsTreeDialog into StatsTreeDialog and TapParameterDialog (its base class). This more closely matches the GTK+ UI and paves the way for more statistics dialogs. Change-Id: I2630385534e829d99724673ade372fcb33200d07 Reviewed-on: https://code.wireshark.org/review/8842 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/stats_tree_dialog.cpp')
-rw-r--r--ui/qt/stats_tree_dialog.cpp200
1 files changed, 43 insertions, 157 deletions
diff --git a/ui/qt/stats_tree_dialog.cpp b/ui/qt/stats_tree_dialog.cpp
index 8d5dd34fa2..2152058bd3 100644
--- a/ui/qt/stats_tree_dialog.cpp
+++ b/ui/qt/stats_tree_dialog.cpp
@@ -20,37 +20,20 @@
*/
#include "stats_tree_dialog.h"
-#include "ui_stats_tree_dialog.h"
#include "file.h"
#include "epan/stats_tree_priv.h"
-#include "ui/last_open_dir.h"
-#include "ui/utf8_entities.h"
+#include "qt_ui_utils.h"
-#include "wsutil/file_util.h"
-
-#include "wireshark_application.h"
-
-#include <QClipboard>
+#include <QHeaderView>
#include <QMessageBox>
#include <QTreeWidget>
#include <QTreeWidgetItemIterator>
-#include <QFileDialog>
-
-// The GTK+ counterpart uses tap_param_dlg, which we don't use. If we
-// need tap parameters we should probably create a TapParameterDialog
-// class based on WiresharkDialog and subclass it here.
-
-// To do:
-// - Add help
-// - Update to match bug 9452 / r53657
const int item_col_ = 0;
-const int expand_all_threshold_ = 100; // Arbitrary
-
Q_DECLARE_METATYPE(stat_node *)
class StatsTreeWidgetItem : public QTreeWidgetItem
@@ -67,19 +50,18 @@ public:
result = stats_tree_sort_compare(thisnode, othernode, treeWidget()->sortColumn(),
order==Qt::DescendingOrder);
if (order==Qt::DescendingOrder) {
- result= -result;
+ result = -result;
}
return result < 0;
}
};
+
StatsTreeDialog::StatsTreeDialog(QWidget &parent, CaptureFile &cf, const char *cfg_abbr) :
- WiresharkDialog(parent, cf),
- ui(new Ui::StatsTreeDialog),
+ TapParameterDialog(parent, cf),
st_(NULL),
st_cfg_(NULL)
{
- ui->setupUi(this);
st_cfg_ = stats_tree_get_cfg_by_abbr(cfg_abbr);
memset(&cfg_pr_, 0, sizeof(struct _tree_cfg_pres));
@@ -88,19 +70,6 @@ StatsTreeDialog::StatsTreeDialog(QWidget &parent, CaptureFile &cf, const char *c
tr("Unable to find configuration for %1.").arg(cfg_abbr));
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
}
-
- ui->statsTreeWidget->addAction(ui->actionCopyToClipboard);
- ui->statsTreeWidget->addAction(ui->actionSaveAs);
- ui->statsTreeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
-
- QPushButton *button;
- button = ui->buttonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
- connect(button, SIGNAL(clicked()), this, SLOT(on_actionCopyToClipboard_triggered()));
-
- button = ui->buttonBox->addButton(tr("Save as..."), QDialogButtonBox::ActionRole);
- connect(button, SIGNAL(clicked()), this, SLOT(on_actionSaveAs_triggered()));
-
- fillTree();
}
StatsTreeDialog::~StatsTreeDialog()
@@ -108,7 +77,31 @@ StatsTreeDialog::~StatsTreeDialog()
if (st_) {
stats_tree_free(st_);
}
- delete ui;
+}
+
+// Adds a node to the QTreeWidget
+// Note: We're passing QTreeWidgetItem pointers as st_node_pres pointers
+void StatsTreeDialog::setupNode(stat_node* node)
+{
+ if (!node || !node->st || !node->st->cfg || !node->st->cfg->pr
+ || !node->st->cfg->pr->st_dlg) return;
+ StatsTreeDialog *st_dlg = node->st->cfg->pr->st_dlg;
+
+ QTreeWidgetItem *ti = new StatsTreeWidgetItem(), *parent = NULL;
+
+ ti->setText(item_col_, node->name);
+ ti->setData(item_col_, Qt::UserRole, qVariantFromValue(node));
+ node->pr = (st_node_pres *) ti;
+ if (node->parent && node->parent->pr) {
+ parent = (QTreeWidgetItem *) node->parent->pr;
+ parent->setExpanded(true);
+ }
+ if (parent) {
+ parent->addChild(ti);
+ } else {
+ st_dlg->statsTreeWidget()->addTopLevelItem(ti);
+ }
+ st_dlg->statsTreeWidget()->resizeColumnToContents(item_col_);
}
void StatsTreeDialog::fillTree()
@@ -130,20 +123,20 @@ void StatsTreeDialog::fillTree()
if (st_) {
stats_tree_free(st_);
}
- st_ = stats_tree_new(st_cfg_, NULL, ui->displayFilterLineEdit->text().toUtf8().constData());
+ st_ = stats_tree_new(st_cfg_, NULL, displayFilter());
// Add number of columns for this stats_tree
QStringList headerLabels;
for (int count = 0; count<st_->num_columns; count++) {
headerLabels.push_back(stats_tree_get_column_name(count));
}
- ui->statsTreeWidget->setColumnCount(headerLabels.count());
- ui->statsTreeWidget->setHeaderLabels(headerLabels);
+ statsTreeWidget()->setColumnCount(headerLabels.count());
+ statsTreeWidget()->setHeaderLabels(headerLabels);
resize(st_->num_columns*80+80, height());
for (int count = 0; count<st_->num_columns; count++) {
headerLabels.push_back(stats_tree_get_column_name(count));
}
- ui->statsTreeWidget->setSortingEnabled(false);
+ statsTreeWidget()->setSortingEnabled(false);
error_string = register_tap_listener(st_cfg_->tapname,
st_,
@@ -162,7 +155,7 @@ void StatsTreeDialog::fillTree()
cf_retap_packets(cap_file_.capFile());
drawTreeItems(st_);
- ui->statsTreeWidget->setSortingEnabled(true);
+ statsTreeWidget()->setSortingEnabled(true);
remove_tap_listener(st_);
st_cfg_->pr = NULL;
@@ -173,41 +166,16 @@ void StatsTreeDialog::resetTap(void *st_ptr)
stats_tree *st = (stats_tree *) st_ptr;
if (!st || !st->cfg || !st->cfg->pr || !st->cfg->pr->st_dlg) return;
- st->cfg->pr->st_dlg->ui->statsTreeWidget->clear();
+ st->cfg->pr->st_dlg->statsTreeWidget()->clear();
st->cfg->init(st);
}
-// Adds a node to the QTreeWidget
-// Note: We're passing QTreeWidgetItem pointers as st_node_pres pointers
-void StatsTreeDialog::setupNode(stat_node* node)
-{
- if (!node || !node->st || !node->st->cfg || !node->st->cfg->pr
- || !node->st->cfg->pr->st_dlg) return;
- StatsTreeDialog *st_dlg = node->st->cfg->pr->st_dlg;
-
- QTreeWidgetItem *ti = new StatsTreeWidgetItem(), *parent = NULL;
-
- ti->setText(item_col_, node->name);
- ti->setData(item_col_, Qt::UserRole, qVariantFromValue(node));
- node->pr = (st_node_pres *) ti;
- if (node->parent && node->parent->pr) {
- parent = (QTreeWidgetItem *) node->parent->pr;
- parent->setExpanded(true);
- }
- if (parent) {
- parent->addChild(ti);
- } else {
- st_dlg->ui->statsTreeWidget->addTopLevelItem(ti);
- }
- st_dlg->ui->statsTreeWidget->resizeColumnToContents(item_col_);
-}
-
void StatsTreeDialog::drawTreeItems(void *st_ptr)
{
stats_tree *st = (stats_tree *) st_ptr;
if (!st || !st->cfg || !st->cfg->pr || !st->cfg->pr->st_dlg) return;
- StatsTreeDialog *st_dlg = st->cfg->pr->st_dlg;
- QTreeWidgetItemIterator iter(st_dlg->ui->statsTreeWidget);
+ TapParameterDialog *st_dlg = st->cfg->pr->st_dlg;
+ QTreeWidgetItemIterator iter(st_dlg->statsTreeWidget());
int node_count = 0;
while (*iter) {
@@ -225,101 +193,19 @@ void StatsTreeDialog::drawTreeItems(void *st_ptr)
node_count++;
++iter;
}
- if (node_count < expand_all_threshold_) {
- st_dlg->ui->statsTreeWidget->expandAll();
- }
- for (int count = 0; count<st->num_columns; count++) {
- st_dlg->ui->statsTreeWidget->resizeColumnToContents(count);
- }
+ st_dlg->drawTreeItems();
}
-void StatsTreeDialog::updateWidgets()
+QByteArray StatsTreeDialog::getTreeAsString(st_format_type format)
{
- if (file_closed_) {
- ui->displayFilterLineEdit->setEnabled(false);
- ui->applyFilterButton->setEnabled(false);
- }
-}
-
-void StatsTreeDialog::on_applyFilterButton_clicked()
-{
- fillTree();
-}
-
-void StatsTreeDialog::on_actionCopyToClipboard_triggered()
-{
- GString* s= stats_tree_format_as_str(st_ ,ST_FORMAT_PLAIN, ui->statsTreeWidget->sortColumn(),
- ui->statsTreeWidget->header()->sortIndicatorOrder()==Qt::DescendingOrder);
- wsApp->clipboard()->setText(s->str);
- g_string_free(s,TRUE);
-}
-
-void StatsTreeDialog::on_actionSaveAs_triggered()
-{
- QString selectedFilter;
- st_format_type file_type;
- const char *file_ext;
- FILE *f;
GString *str_tree;
- bool success= false;
- int last_errno;
-
- QFileDialog SaveAsDialog(this, wsApp->windowTitleString(tr("Save Statistics As" UTF8_HORIZONTAL_ELLIPSIS)),
- get_last_open_dir());
- SaveAsDialog.setNameFilter(tr("Plain text file (*.txt);;"
- "Comma separated values (*.csv);;"
- "XML document (*.xml);;"
- "YAML document (*.yaml)"));
- SaveAsDialog.selectNameFilter(tr("Plain text file (*.txt)"));
- SaveAsDialog.setAcceptMode(QFileDialog::AcceptSave);
- if (!SaveAsDialog.exec()) {
- return;
- }
- selectedFilter= SaveAsDialog.selectedNameFilter();
- if (selectedFilter.contains("*.yaml", Qt::CaseInsensitive)) {
- file_type= ST_FORMAT_YAML;
- file_ext = ".yaml";
- }
- else if (selectedFilter.contains("*.xml", Qt::CaseInsensitive)) {
- file_type= ST_FORMAT_XML;
- file_ext = ".xml";
- }
- else if (selectedFilter.contains("*.csv", Qt::CaseInsensitive)) {
- file_type= ST_FORMAT_CSV;
- file_ext = ".csv";
- }
- else {
- file_type= ST_FORMAT_PLAIN;
- file_ext = ".txt";
- }
-
- // Get selected filename and add extension of necessary
- QString file_name = SaveAsDialog.selectedFiles()[0];
- if (!file_name.endsWith(file_ext, Qt::CaseInsensitive)) {
- file_name.append(file_ext);
- }
// produce output in selected format using current sort information
- str_tree=stats_tree_format_as_str(st_ ,file_type, ui->statsTreeWidget->sortColumn(),
- ui->statsTreeWidget->header()->sortIndicatorOrder()==Qt::DescendingOrder);
-
- // actually save the file
- f= ws_fopen (file_name.toUtf8().constData(),"w");
- last_errno= errno;
- if (f) {
- if (fputs(str_tree->str, f)!=EOF) {
- success= true;
- }
- last_errno= errno;
- fclose(f);
- }
- if (!success) {
- QMessageBox::warning(this, tr("Error saving file %1").arg(file_name),
- g_strerror (last_errno));
- }
+ str_tree = stats_tree_format_as_str(st_, format, statsTreeWidget()->sortColumn(),
+ statsTreeWidget()->header()->sortIndicatorOrder()==Qt::DescendingOrder);
- g_string_free(str_tree, TRUE);
+ return gstring_free_to_qbytearray(str_tree);
}
extern "C" {