void viewGVpropertieslayout::contextMenuRequest(QPoint pos) { // first get a pointer to the current plot! QCustomPlot * currPlot = (QCustomPlot *) currentSubWindow->widget(); QMenu *menu = new QMenu(this); menu->setAttribute(Qt::WA_DeleteOnClose); if (currPlot->legend->selectTest(pos, false) >= 0) // context menu on legend requested { /*menu->addAction("Move to top left", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignLeft)); menu->addAction("Move to top center", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignHCenter)); menu->addAction("Move to top right", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignRight)); menu->addAction("Move to bottom right", this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignRight)); menu->addAction("Move to bottom left", this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignLeft));*/ } else if (currPlot->xAxis->selectTest(pos, false) >= 0 || \ currPlot->xAxis2->selectTest(pos, false) >= 0) { // enable / disable zoom if (currPlot->axisRect()->rangeZoom() & Qt::Horizontal) menu->addAction("Disable zoom on axis", this, SLOT(toggleHorizontalZoom())); else menu->addAction("Enable zoom on axis", this, SLOT(toggleHorizontalZoom())); // enable / diable drag if (currPlot->axisRect()->rangeDrag() & Qt::Horizontal) menu->addAction("Disable drag on axis", this, SLOT(toggleHorizontalDrag())); else menu->addAction("Enable drag on axis", this, SLOT(toggleHorizontalDrag())); } else if (currPlot->yAxis->selectTest(pos, false) >= 0 || \ currPlot->yAxis2->selectTest(pos, false) >= 0) { // enable / disable zoom if (currPlot->axisRect()->rangeZoom() & Qt::Vertical) menu->addAction("Disable zoom on axis", this, SLOT(toggleVerticalZoom())); else menu->addAction("Enable zoom on axis", this, SLOT(toggleVerticalZoom())); // enable / diable drag if (currPlot->axisRect()->rangeDrag() & Qt::Vertical) menu->addAction("Disable drag on axis", this, SLOT(toggleVerticalDrag())); else menu->addAction("Enable drag on axis", this, SLOT(toggleVerticalDrag())); } else { if (currPlot->graphCount() > 0) menu->addAction("Scale axes to fit", this, SLOT(rescaleAxes())); if (currPlot->selectedGraphs().size() > 0) menu->addAction("Remove selected graph", this, SLOT(removeSelectedGraph())); if (currPlot->graphCount() > 0) menu->addAction("Remove all graphs", this, SLOT(removeAllGraphs())); } menu->popup(currPlot->mapToGlobal(pos)); }
void CurrencyPane::UpdateGraph(const QMap<double, double> map) { QCustomPlot* customPlot = ui->plotWidget; if (map.size() < 2) { customPlot->hide(); return; } if (customPlot->isHidden()) { customPlot->show(); } //customPlot->setBackground(Qt::transparent); double lastDate = map.lastKey(); double weekAgo = QDateTime(QDate::currentDate()).addDays(-7).toTime_t(); double highestVal = 0; if (!map.isEmpty()) { highestVal = from(map.values().toVector().toStdVector()).max(); } if (customPlot->graphCount() > 0) { customPlot->removeGraph(0); } customPlot->addGraph(); customPlot->graph()->setName("Net Worth"); QPen pen; pen.setColor(QColor(0, 0, 255, 200)); customPlot->graph()->setLineStyle(QCPGraph::lsLine); customPlot->graph()->setPen(pen); customPlot->graph()->setBrush(QBrush(QColor(255/4.0,160,50,150))); customPlot->graph()->setData(map.keys().toVector(), map.values().toVector()); // configure bottom axis to show date and time instead of number: customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime); customPlot->xAxis->setDateTimeFormat("ddd"); // set a more compact font size for bottom and left axis tick labels: customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8)); customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8)); // set axis labels: customPlot->xAxis->setLabel("Date"); customPlot->yAxis->setLabel("Total Worth in Chaos"); // make top and right axes visible but without ticks and labels: customPlot->xAxis2->setVisible(true); customPlot->yAxis2->setVisible(true); customPlot->xAxis2->setTicks(false); customPlot->yAxis2->setTicks(false); customPlot->xAxis2->setTickLabels(false); customPlot->yAxis2->setTickLabels(false); // set axis ranges to show all data: customPlot->xAxis->setRange(weekAgo, lastDate); customPlot->yAxis->setRange(0, highestVal); // show legend: customPlot->legend->setVisible(true); }
void viewGVpropertieslayout::refreshLog(logData * log) { if (log->setupFromXML()) { // find graphs from this log // get a list of the MDI windows QList<QMdiSubWindow *> subWins = viewGV->mdiarea->subWindowList(); // loop and extract the plot for (int i = 0; i < subWins.size(); ++i) { QCustomPlot * currPlot = (QCustomPlot *) subWins[i]->widget(); // loop through graphs in the plot for (int j = 0; j < currPlot->graphCount(); ++j) { // if the graph is from this log if (currPlot->graph(j)->property("source").toString() == log->logFileXMLname) { // extract remaining graph data QString type = currPlot->graph(j)->property("type").toString(); if (type == "linePlot") { // get index int index = currPlot->graph(j)->property("index").toInt(); log->plotLine(currPlot, index, j); } else if (type == "rasterPlot") { // get indices QList < QVariant > indices = currPlot->graph(j)->property("indices").toList(); log->plotRaster(currPlot, indices, j); } } } } } else return; }
// Fill in graph data based upon what was read into the rlc_graph struct. void LteRlcGraphDialog::fillGraph() { QCustomPlot *sp = ui->rlcPlot; // We should always have 4 graphs, but cover case if no channel was chosen. if (sp->graphCount() < 1) { return; } tracer_->setGraph(NULL); base_graph_->setLineStyle(QCPGraph::lsNone); // dot reseg_graph_->setLineStyle(QCPGraph::lsNone); // dot acks_graph_->setLineStyle(QCPGraph::lsStepLeft); // to get step effect... nacks_graph_->setLineStyle(QCPGraph::lsNone); // dot, but bigger. // Will show all graphs with data we find. for (int i = 0; i < sp->graphCount(); i++) { sp->graph(i)->clearData(); sp->graph(i)->setVisible(true); } // N.B. ssDisc is really too slow. TODO: work out how to turn off aliasing, or experiment // with ssCustom. Other styles tried didn't look right. // GTK version was speeded up noticibly by turning down aliasing level... base_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_)); reseg_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_)); acks_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_)); // NACKs are shown bigger than others. nacks_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_*2)); // Map timestamps -> segments in first pass. time_stamp_map_.clear(); for (struct rlc_segment *seg = graph_.segments; seg != NULL; seg = seg->next) { if (!compareHeaders(seg)) { continue; } double ts = seg->rel_secs + seg->rel_usecs / 1000000.0; time_stamp_map_.insertMulti(ts, seg); } // Now sequence numbers. QVector<double> seq_time, seq, reseg_seq_time, reseg_seq, acks_time, acks, nacks_time, nacks; for (struct rlc_segment *seg = graph_.segments; seg != NULL; seg = seg->next) { double ts = seg->rel_secs + seg->rel_usecs / 1000000.0; if (compareHeaders(seg)) { if (!seg->isControlPDU) { // Data if (seg->isResegmented) { reseg_seq_time.append(ts); reseg_seq.append(seg->SN); } else { seq_time.append(ts); seq.append(seg->SN); } } else { // Status (ACKs/NACKs) acks_time.append(ts); acks.append(seg->ACKNo-1); for (int n=0; n < seg->noOfNACKs; n++) { nacks_time.append(ts); nacks.append(seg->NACKs[n]); } } } } // Add the data from the graphs. base_graph_->setData(seq_time, seq); reseg_graph_->setData(reseg_seq_time, reseg_seq); acks_graph_->setData(acks_time, acks); nacks_graph_->setData(nacks_time, nacks); sp->setEnabled(true); // Auto-size... mouseMoved(NULL); resetAxes(); tracer_->setGraph(base_graph_); // XXX QCustomPlot doesn't seem to draw any sort of focus indicator. sp->setFocus(); }
void TCPStreamDialog::fillGraph() { QCustomPlot *sp = ui->streamPlot; if (sp->graphCount() < 1) return; base_graph_->setLineStyle(QCPGraph::lsNone); tracer_->setGraph(NULL); // base_graph_ is always visible. for (int i = 0; i < sp->graphCount(); i++) { sp->graph(i)->clearData(); sp->graph(i)->setVisible(i == 0 ? true : false); } base_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_)); sp->xAxis->setLabel(time_s_label_); sp->xAxis->setNumberFormat("gb"); sp->xAxis->setNumberPrecision(6); sp->yAxis->setNumberFormat("f"); sp->yAxis->setNumberPrecision(0); sp->yAxis2->setVisible(false); sp->yAxis2->setLabel(QString()); if (!cap_file_) { QString dlg_title = QString(tr("No Capture Data")); setWindowTitle(dlg_title); title_->setText(dlg_title); sp->setEnabled(false); sp->yAxis->setLabel(QString()); sp->replot(); return; } ts_offset_ = 0; seq_offset_ = 0; bool first = true; guint64 bytes_fwd = 0; guint64 bytes_rev = 0; int pkts_fwd = 0; int pkts_rev = 0; time_stamp_map_.clear(); for (struct segment *seg = graph_.segments; seg != NULL; seg = seg->next) { if (!compareHeaders(seg)) { bytes_rev += seg->th_seglen; pkts_rev++; continue; } bytes_fwd += seg->th_seglen; pkts_fwd++; double ts = seg->rel_secs + seg->rel_usecs / 1000000.0; if (first) { if (ts_origin_conn_) ts_offset_ = ts; if (seq_origin_zero_) seq_offset_ = seg->th_seq; first = false; } time_stamp_map_.insertMulti(ts - ts_offset_, seg); } switch (graph_.type) { case GRAPH_TSEQ_STEVENS: fillStevens(); break; case GRAPH_TSEQ_TCPTRACE: fillTcptrace(); break; case GRAPH_THROUGHPUT: fillThroughput(); break; case GRAPH_RTT: fillRoundTripTime(); break; case GRAPH_WSCALE: fillWindowScale(); break; default: break; } sp->setEnabled(true); stream_desc_ = tr("%1 %2 pkts, %3 %4 %5 pkts, %6 ") .arg(UTF8_RIGHTWARDS_ARROW) .arg(gchar_free_to_qstring(format_size(pkts_fwd, format_size_unit_none|format_size_prefix_si))) .arg(gchar_free_to_qstring(format_size(bytes_fwd, format_size_unit_bytes|format_size_prefix_si))) .arg(UTF8_LEFTWARDS_ARROW) .arg(gchar_free_to_qstring(format_size(pkts_rev, format_size_unit_none|format_size_prefix_si))) .arg(gchar_free_to_qstring(format_size(bytes_rev, format_size_unit_bytes|format_size_prefix_si))); mouseMoved(NULL); resetAxes(); tracer_->setGraph(base_graph_); // XXX QCustomPlot doesn't seem to draw any sort of focus indicator. sp->setFocus(); }