Skip to content

Commit

Permalink
Qt: fix tracer and selection of packet in IO Graph
Browse files Browse the repository at this point in the history
Do not assume first graph in the list, pick the first visible graph.
This (1) fixes the tracer which would otherwise show a marker at an
non-obvious position that is not located on the graph and (2) fixes the
GoToPacket action when clicking on the graph.

Bug: 13537
Change-Id: I49d750102ad25c8539aa2e44fe1583cd535dd471
Reviewed-on: https://code.wireshark.org/review/20768
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
  • Loading branch information
Lekensteyn committed Apr 5, 2017
1 parent 48a614d commit a5f9b4e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
40 changes: 31 additions & 9 deletions ui/qt/io_graph_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,32 @@ void IOGraphDialog::toggleTracerStyle(bool force_default)
ui->ioPlot->replot();
}

// Returns the IOGraph which is most likely to be used by the user. This is the
// currently selected, visible graph or the first visible graph otherwise.
IOGraph *IOGraphDialog::currentActiveGraph() const
{
QTreeWidgetItem *selectedItem = ui->graphTreeWidget->currentItem();
if (selectedItem && selectedItem->checkState(name_col_) != Qt::Checked) {
selectedItem = NULL;
}

if (!selectedItem) {
for (int i = 0; i < ui->graphTreeWidget->topLevelItemCount(); i++) {
QTreeWidgetItem *item = ui->graphTreeWidget->topLevelItem(i);
if (item && item->checkState(name_col_) == Qt::Checked) {
selectedItem = item;
break;
}
}
}

if (selectedItem) {
return VariantPointer<IOGraph>::asPtr(selectedItem->data(name_col_, Qt::UserRole));
} else {
return NULL;
}
}

// Scan through our graphs and gather information.
// QCPItemTracers can only be associated with QCPGraphs. Find the first one
// and associate it with our tracer. Set bar stacking order while we're here.
Expand All @@ -718,15 +744,15 @@ void IOGraphDialog::getGraphInfo()
start_time_ = 0.0;

tracer_->setGraph(NULL);
IOGraph *selectedGraph = currentActiveGraph();
for (int i = 0; i < ui->graphTreeWidget->topLevelItemCount(); i++) {
QTreeWidgetItem *item = ui->graphTreeWidget->topLevelItem(i);
IOGraph *iog = NULL;
if (item) {
iog = VariantPointer<IOGraph>::asPtr(item->data(name_col_, Qt::UserRole));
if (item && item->checkState(name_col_) == Qt::Checked) {
IOGraph *iog = VariantPointer<IOGraph>::asPtr(item->data(name_col_, Qt::UserRole));
QCPGraph *graph = iog->graph();
QCPBars *bars = iog->bars();
int style = item->data(style_col_, Qt::UserRole).toInt();
if (graph && !base_graph_) {
if (graph && (!base_graph_ || iog == selectedGraph)) {
base_graph_ = graph;
} else if (bars && style == IOGraph::psStackedBar && iog->visible()) {
bars->moveBelow(NULL); // Remove from existing stack
Expand Down Expand Up @@ -885,11 +911,7 @@ void IOGraphDialog::mouseMoved(QMouseEvent *event)
if (event && tracer_->graph()) {
tracer_->setGraphKey(iop->xAxis->pixelToCoord(event->pos().x()));
ts = tracer_->position->key();

QTreeWidgetItem *ti = ui->graphTreeWidget->topLevelItem(0);
IOGraph *iog = NULL;
if (ti) {
iog = VariantPointer<IOGraph>::asPtr(ti->data(name_col_, Qt::UserRole));
if (IOGraph *iog = currentActiveGraph()) {
interval_packet = iog->packetFromTime(ts);
}
}
Expand Down
1 change: 1 addition & 0 deletions ui/qt/io_graph_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public slots:
void loadProfileGraphs();
void makeCsv(QTextStream &stream) const;
bool saveCsv(const QString &file_name) const;
IOGraph *currentActiveGraph() const;

private slots:
void updateWidgets();
Expand Down

0 comments on commit a5f9b4e

Please sign in to comment.