diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp index 0c19078fc3..cbaeaee169 100644 --- a/ui/qt/io_graph_dialog.cpp +++ b/ui/qt/io_graph_dialog.cpp @@ -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::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. @@ -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::asPtr(item->data(name_col_, Qt::UserRole)); + if (item && item->checkState(name_col_) == Qt::Checked) { + IOGraph *iog = VariantPointer::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 @@ -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::asPtr(ti->data(name_col_, Qt::UserRole)); + if (IOGraph *iog = currentActiveGraph()) { interval_packet = iog->packetFromTime(ts); } } diff --git a/ui/qt/io_graph_dialog.h b/ui/qt/io_graph_dialog.h index 55e32f9838..d76c6cc638 100644 --- a/ui/qt/io_graph_dialog.h +++ b/ui/qt/io_graph_dialog.h @@ -208,6 +208,7 @@ private: void loadProfileGraphs(); void makeCsv(QTextStream &stream) const; bool saveCsv(const QString &file_name) const; + IOGraph *currentActiveGraph() const; private slots: void updateWidgets();