void SequenceDialog::diagramClicked(QMouseEvent *event) { QCustomPlot *sp = ui->sequencePlot; if (event->button() == Qt::RightButton) { // XXX We should find some way to get sequenceDiagram to handle a // contextMenuEvent instead. ctx_menu_.exec(event->globalPos()); } else if (sp->axisRect()->rect().contains(event->pos())) { sp->setCursor(QCursor(Qt::ClosedHandCursor)); } on_actionGoToPacket_triggered(); }
void LteRlcGraphDialog::zoomAxes(bool in) { QCustomPlot *rp = ui->rlcPlot; double h_factor = rp->axisRect()->rangeZoomFactor(Qt::Horizontal); double v_factor = rp->axisRect()->rangeZoomFactor(Qt::Vertical); if (!in) { h_factor = pow(h_factor, -1); v_factor = pow(v_factor, -1); } if (in) { // Don't want to zoom in *too* far on y axis. if (rp->yAxis->range().size() < 10) { return; } } else { // Don't want to zoom out *too* far on y axis. if (rp->yAxis->range().size() > (65536+10)) { return; } } rp->xAxis->scaleRange(h_factor, rp->xAxis->range().center()); rp->yAxis->scaleRange(v_factor, rp->yAxis->range().center()); rp->replot(QCustomPlot::rpQueued); }
void viewGVpropertieslayout::toggleVerticalDrag() { // first get a pointer to the current plot! QCustomPlot * currPlot = (QCustomPlot *) currentSubWindow->widget(); if (currPlot->axisRect()->rangeDrag() & Qt::Vertical) currPlot->axisRect()->setRangeDrag(currPlot->axisRect()->rangeDrag() & ~Qt::Vertical); else currPlot->axisRect()->setRangeDrag(currPlot->axisRect()->rangeDrag() | Qt::Vertical); }
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 Record::createWaveFormPic(Ffmpeg_t *ffmpeg, QString recortPath) { std::pair<std::vector<double>, std::vector<double> > dataWaveForm = ffmpeg->getSamplesForWaveformPlotting(recortPath + "/" + m_Name); QCustomPlot Plotter; Plotter.setBackground(QBrush(Qt::transparent) ); Plotter.xAxis->setVisible(false); Plotter.yAxis->setVisible(false); Plotter.axisRect()->setAutoMargins(QCP::msNone); Plotter.axisRect()->setMargins(QMargins(0, 5, 0, 5)); QCPGraph *Waveform = Plotter.addGraph(); Waveform->setPen(QPen(Qt::green) ); if (!Waveform) { qDebug("addGraph failed\n"); } QVector<double> Amplitudes(QVector<double>::fromStdVector(dataWaveForm.first) ); QVector<double> Time; double CurrentTime = 0; auto TimeSlotCount = Amplitudes.size(); for (int64_t i = 1; i < TimeSlotCount; i++) { Time.append(CurrentTime); CurrentTime += 0.5; } Waveform->setData(Time, Amplitudes); Plotter.xAxis->setRange(0, Time.back() ); Plotter.yAxis->setRange(SHRT_MIN, SHRT_MAX); QByteArray ByteArray; QBuffer Buffer(&ByteArray); Buffer.open(QBuffer::WriteOnly); uint32_t time = m_EndTime - m_StartTime; for (int i = 1; i < 10000; i*=10) { Plotter.toPixmap(time/(i), this->height()).save(&Buffer, "PNG", 0); //Plotter.saveJpg(recortPath + "/plot" + QString::number(m_Id) + QString::number(i) + ".jpg", time/(i), this->height()); QPixmap Pixmap; Pixmap.loadFromData(ByteArray, "PNG"); v_PixWaves.append(Pixmap); ByteArray.clear(); Buffer.reset(); } Buffer.close(); qDebug() << m_WavePic->margin(); // místo 2 podle toho jaký zoom m_WavePic->setPixmap(v_PixWaves[2]); }
void SequenceDialog::resetAxes(bool keep_lower) { if (!info_->sainfo()) return; QCustomPlot *sp = ui->sequencePlot; // Allow space for labels on the top and port numbers on the left. double top_pos = min_top_, left_pos = min_left_; if (keep_lower) { top_pos = sp->yAxis->range().lower; left_pos = sp->xAxis2->range().lower; } double range_span = sp->viewport().width() / sequence_w_; sp->xAxis2->setRange(left_pos, range_span + left_pos); range_span = sp->axisRect()->height() / (one_em_ * 1.5); sp->yAxis->setRange(top_pos, range_span + top_pos); double rmin = sp->xAxis2->range().size() / 2; ui->horizontalScrollBar->setRange((rmin - 0.5) * 100, (info_->sainfo()->num_nodes - 0.5 - rmin) * 100); xAxisChanged(sp->xAxis2->range()); ui->horizontalScrollBar->setValue(ui->horizontalScrollBar->minimum()); // Shouldn't be needed. rmin = (sp->yAxis->range().size() / 2); ui->verticalScrollBar->setRange((rmin - 1.0) * 100, (num_items_ - 0.5 - rmin) * 100); yAxisChanged(sp->yAxis->range()); // It would be exceedingly handy if we could do one or both of the // following: // - Position an axis label above its axis inline with the tick labels. // - Anchor a QCPItemText to one of the corners of a QCPAxis. // Neither of those appear to be possible, so we first call replot in // order to lay out our X axes, place our labels, the call replot again. sp->replot(QCustomPlot::rpQueued); QRect axis_rect = sp->axisRect()->rect(); key_text_->position->setCoords(axis_rect.left() - sp->yAxis->padding() - sp->yAxis->tickLabelPadding() - sp->yAxis->offset(), axis_rect.top() / 2); comment_text_->position->setCoords(axis_rect.right() + sp->yAxis2->padding() + sp->yAxis2->tickLabelPadding() + sp->yAxis2->offset(), axis_rect.top() / 2); sp->replot(QCustomPlot::rpHint); }
void TCPStreamDialog::zoomAxes(bool in) { QCustomPlot *sp = ui->streamPlot; double h_factor = sp->axisRect()->rangeZoomFactor(Qt::Horizontal); double v_factor = sp->axisRect()->rangeZoomFactor(Qt::Vertical); if (!in) { h_factor = pow(h_factor, -1); v_factor = pow(v_factor, -1); } sp->xAxis->scaleRange(h_factor, sp->xAxis->range().center()); sp->yAxis->scaleRange(v_factor, sp->yAxis->range().center()); sp->replot(); }
void SequenceDialog::mouseMoved(QMouseEvent *event) { QCustomPlot *sp = ui->sequencePlot; Qt::CursorShape shape = Qt::ArrowCursor; if (event) { if (event->buttons().testFlag(Qt::LeftButton)) { shape = Qt::ClosedHandCursor; } else { if (sp->axisRect()->rect().contains(event->pos())) { shape = Qt::OpenHandCursor; } } } sp->setCursor(QCursor(shape)); packet_num_ = 0; QString hint; if (event) { seq_analysis_item_t *sai = seq_diagram_->itemForPosY(event->pos().y()); if (sai) { packet_num_ = sai->fd->num; hint = QString("Packet %1: %2").arg(packet_num_).arg(sai->comment); } } if (hint.isEmpty()) { hint += tr("%Ln node(s)", "", seq_analysis_.num_nodes) + QString(", ") + tr("%Ln item(s)", "", num_items_); } hint.prepend("<small><i>"); hint.append("</i></small>"); ui->hintLabel->setText(hint); }
void LteRlcGraphDialog::zoomXAxis(bool in) { QCustomPlot *rp = ui->rlcPlot; double h_factor = rp->axisRect()->rangeZoomFactor(Qt::Horizontal); if (!in) { h_factor = pow(h_factor, -1); } rp->xAxis->scaleRange(h_factor, rp->xAxis->range().center()); rp->replot(QCustomPlot::rpQueued); }
void TCPStreamDialog::graphClicked(QMouseEvent *event) { QCustomPlot *sp = ui->streamPlot; if (event->button() == Qt::RightButton) { // XXX We should find some way to get streamPlot to handle a // contextMenuEvent instead. ctx_menu_.exec(event->globalPos()); } else if (mouse_drags_) { if (sp->axisRect()->rect().contains(event->pos())) { sp->setCursor(QCursor(Qt::ClosedHandCursor)); } on_actionGoToPacket_triggered(); } else { if (!rubber_band_) { rubber_band_ = new QRubberBand(QRubberBand::Rectangle, sp); } rb_origin_ = event->pos(); rubber_band_->setGeometry(QRect(rb_origin_, QSize())); rubber_band_->show(); } }
QRectF LteRlcGraphDialog::getZoomRanges(QRect zoom_rect) { QRectF zoom_ranges = QRectF(); if (zoom_rect.width() < min_zoom_pixels_ && zoom_rect.height() < min_zoom_pixels_) { return zoom_ranges; } QCustomPlot *rp = ui->rlcPlot; QRect zr = zoom_rect.normalized(); QRect ar = rp->axisRect()->rect(); if (ar.intersects(zr)) { QRect zsr = ar.intersected(zr); zoom_ranges.setX(rp->xAxis->range().lower + rp->xAxis->range().size() * (zsr.left() - ar.left()) / ar.width()); zoom_ranges.setWidth(rp->xAxis->range().size() * zsr.width() / ar.width()); // QRects grow down zoom_ranges.setY(rp->yAxis->range().lower + rp->yAxis->range().size() * (ar.bottom() - zsr.bottom()) / ar.height()); zoom_ranges.setHeight(rp->yAxis->range().size() * zsr.height() / ar.height()); } return zoom_ranges; }
QCustomPlot* Plots::createChart(QVector<double> x, QVector<double> y, QString chartName) { QCustomPlot* customPlot = new QCustomPlot(); // create and configure plottables: QCPBars *bars1 = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(bars1); bars1->setWidth(0.3); bars1->setData(x, y); bars1->setPen(QPen(Qt::red)); bars1->setBrush(QColor(10, 140, 70, 160)); // set title of plot: customPlot->plotLayout()->insertRow(0); customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, chartName)); // set a fixed tick-step to one tick per year value: customPlot->xAxis->setAutoTickStep(false); customPlot->xAxis->setTickStep(1); customPlot->xAxis->setSubTickCount(3); // set a fixed tick-step to one tick per колво value: customPlot->yAxis->setAutoTickStep(false); customPlot->yAxis->setTickStep(10); customPlot->yAxis->setSubTickCount(3); // labels customPlot->xAxis->setLabel("Год"); customPlot->yAxis->setLabel("% человек"); customPlot->yAxis->setLabelColor(Qt::white); customPlot->xAxis->setLabelColor(Qt::white); // move bars above graphs and grid below bars: customPlot->addLayer("abovemain", customPlot->layer("main"), QCustomPlot::limAbove); customPlot->addLayer("belowmain", customPlot->layer("main"), QCustomPlot::limBelow); bars1->setLayer("abovemain"); customPlot->xAxis->grid()->setLayer("belowmain"); customPlot->yAxis->grid()->setLayer("belowmain"); // set some pens, brushes and backgrounds: customPlot->xAxis->setBasePen(QPen(Qt::white, 1)); customPlot->yAxis->setBasePen(QPen(Qt::white, 1)); customPlot->xAxis->setTickPen(QPen(Qt::white, 1)); customPlot->yAxis->setTickPen(QPen(Qt::white, 1)); customPlot->xAxis->setSubTickPen(QPen(Qt::white, 1)); customPlot->yAxis->setSubTickPen(QPen(Qt::white, 1)); customPlot->xAxis->setTickLabelColor(Qt::white); customPlot->yAxis->setTickLabelColor(Qt::white); customPlot->xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine)); customPlot->yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine)); customPlot->xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine)); customPlot->yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine)); customPlot->xAxis->grid()->setSubGridVisible(true); customPlot->yAxis->grid()->setSubGridVisible(true); customPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen); customPlot->yAxis->grid()->setZeroLinePen(Qt::NoPen); customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); QLinearGradient plotGradient; plotGradient.setStart(0, 0); plotGradient.setFinalStop(0, 350); plotGradient.setColorAt(0, QColor(80, 80, 80)); plotGradient.setColorAt(1, QColor(50, 50, 50)); customPlot->setBackground(plotGradient); QLinearGradient axisRectGradient; axisRectGradient.setStart(0, 0); axisRectGradient.setFinalStop(0, 350); axisRectGradient.setColorAt(0, QColor(80, 80, 80)); axisRectGradient.setColorAt(1, QColor(30, 30, 30)); customPlot->axisRect()->setBackground(axisRectGradient); customPlot->rescaleAxes(); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); return customPlot; }
SequenceDialog::SequenceDialog(QWidget &parent, CaptureFile &cf, seq_analysis_info_t *sainfo) : WiresharkDialog(parent, cf), ui(new Ui::SequenceDialog), sainfo_(sainfo), num_items_(0), packet_num_(0), node_label_w_(20) { ui->setupUi(this); QCustomPlot *sp = ui->sequencePlot; setWindowSubtitle(sainfo ? tr("Call Flow") : tr("Flow")); if (!sainfo_) { sainfo_ = sequence_analysis_info_new(); sainfo_->type = SEQ_ANALYSIS_ANY; sainfo_->all_packets = TRUE; } else { num_items_ = sequence_analysis_get_nodes(sainfo_); } seq_diagram_ = new SequenceDiagram(sp->yAxis, sp->xAxis2, sp->yAxis2); sp->addPlottable(seq_diagram_); sp->axisRect()->setRangeDragAxes(sp->xAxis2, sp->yAxis); sp->xAxis->setVisible(false); sp->xAxis->setPadding(0); sp->xAxis->setLabelPadding(0); sp->xAxis->setTickLabelPadding(0); sp->xAxis2->setVisible(true); sp->yAxis2->setVisible(true); one_em_ = QFontMetrics(sp->yAxis->labelFont()).height(); ui->horizontalScrollBar->setSingleStep(100 / one_em_); ui->verticalScrollBar->setSingleStep(100 / one_em_); sp->setInteractions(QCP::iRangeDrag); ui->gridLayout->setSpacing(0); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), sp->yAxis2, SLOT(setRange(QCPRange))); ctx_menu_.addAction(ui->actionReset); ctx_menu_.addSeparator(); ctx_menu_.addAction(ui->actionMoveRight10); ctx_menu_.addAction(ui->actionMoveLeft10); ctx_menu_.addAction(ui->actionMoveUp10); ctx_menu_.addAction(ui->actionMoveDown10); ctx_menu_.addAction(ui->actionMoveRight1); ctx_menu_.addAction(ui->actionMoveLeft1); ctx_menu_.addAction(ui->actionMoveUp1); ctx_menu_.addAction(ui->actionMoveDown1); ctx_menu_.addSeparator(); ctx_menu_.addAction(ui->actionGoToPacket); ui->showComboBox->blockSignals(true); ui->showComboBox->setCurrentIndex(0); ui->showComboBox->blockSignals(false); ui->addressComboBox->blockSignals(true); ui->addressComboBox->setCurrentIndex(0); ui->addressComboBox->blockSignals(false); QComboBox *fcb = ui->flowComboBox; fcb->addItem(ui->actionFlowAny->text(), SEQ_ANALYSIS_ANY); fcb->addItem(ui->actionFlowTcp->text(), SEQ_ANALYSIS_TCP); ui->flowComboBox->blockSignals(true); ui->flowComboBox->setCurrentIndex(sainfo_->type); if (sainfo_->type == SEQ_ANALYSIS_VOIP) { ui->controlFrame->hide(); } else { ui->flowComboBox->blockSignals(false); } QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save); save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS)); // XXX Use recent settings instead resize(parent.width(), parent.height() * 4 / 5); connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(hScrollBarChanged(int))); connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vScrollBarChanged(int))); connect(sp->xAxis2, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange))); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChanged(QCPRange))); connect(sp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(diagramClicked(QMouseEvent*))); connect(sp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*))); connect(sp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*))); connect(this, SIGNAL(goToPacket(int)), seq_diagram_, SLOT(setSelectedPacket(int))); disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); fillDiagram(); }
// Setting mouseTracking on our streamPlot may not be as reliable // as we need. If it's not we might want to poll the mouse position // using a QTimer instead. void TCPStreamDialog::mouseMoved(QMouseEvent *event) { QCustomPlot *sp = ui->streamPlot; Qt::CursorShape shape = Qt::ArrowCursor; if (event) { if (event->buttons().testFlag(Qt::LeftButton)) { if (mouse_drags_) { shape = Qt::ClosedHandCursor; } else { shape = Qt::CrossCursor; } } else { if (sp->axisRect()->rect().contains(event->pos())) { if (mouse_drags_) { shape = Qt::OpenHandCursor; } else { shape = Qt::CrossCursor; } } } } sp->setCursor(QCursor(shape)); QString hint = "<small><i>"; if (mouse_drags_) { double tr_key = tracer_->position->key(); struct segment *packet_seg = NULL; packet_num_ = 0; // XXX If we have multiple packets with the same timestamp tr_key // may not return the packet we want. It might be possible to fudge // unique keys using nextafter(). if (event && tracer_->graph() && tracer_->position->axisRect()->rect().contains(event->pos())) { switch (graph_.type) { case GRAPH_TSEQ_STEVENS: case GRAPH_TSEQ_TCPTRACE: case GRAPH_THROUGHPUT: case GRAPH_WSCALE: packet_seg = time_stamp_map_.value(tr_key, NULL); break; case GRAPH_RTT: packet_seg = sequence_num_map_.value(tr_key, NULL); default: break; } } if (!packet_seg) { tracer_->setVisible(false); hint += "Hover over the graph for details. " + stream_desc_ + "</i></small>"; ui->hintLabel->setText(hint); ui->streamPlot->replot(); return; } tracer_->setVisible(true); packet_num_ = packet_seg->num; hint += tr("%1 %2 (%3s len %4 seq %5 ack %6 win %7)") .arg(cap_file_ ? tr("Click to select packet") : tr("Packet")) .arg(packet_num_) .arg(QString::number(packet_seg->rel_secs + packet_seg->rel_usecs / 1000000.0, 'g', 4)) .arg(packet_seg->th_seglen) .arg(packet_seg->th_seq) .arg(packet_seg->th_ack) .arg(packet_seg->th_win); tracer_->setGraphKey(ui->streamPlot->xAxis->pixelToCoord(event->pos().x())); sp->replot(); } else { if (rubber_band_ && rubber_band_->isVisible() && event) { rubber_band_->setGeometry(QRect(rb_origin_, event->pos()).normalized()); QRectF zoom_ranges = getZoomRanges(QRect(rb_origin_, event->pos())); if (zoom_ranges.width() > 0.0 && zoom_ranges.height() > 0.0) { hint += tr("Release to zoom, x = %1 to %2, y = %3 to %4") .arg(zoom_ranges.x()) .arg(zoom_ranges.x() + zoom_ranges.width()) .arg(zoom_ranges.y()) .arg(zoom_ranges.y() + zoom_ranges.height()); } else { hint += tr("Unable to select range."); } } else { hint += tr("Click to select a portion of the graph."); } } hint += " " + stream_desc_ + "</i></small>"; ui->hintLabel->setText(hint); }
SequenceDialog::SequenceDialog(QWidget *parent, capture_file *cf, SequenceType type) : QDialog(parent), ui(new Ui::SequenceDialog), cap_file_(cf), num_items_(0), packet_num_(0), node_label_w_(20) { ui->setupUi(this); QCustomPlot *sp = ui->sequencePlot; seq_diagram_ = new SequenceDiagram(sp->yAxis, sp->xAxis2, sp->yAxis2); sp->addPlottable(seq_diagram_); sp->axisRect()->setRangeDragAxes(sp->xAxis2, sp->yAxis); sp->xAxis->setVisible(false); sp->xAxis->setPadding(0); sp->xAxis->setLabelPadding(0); sp->xAxis->setTickLabelPadding(0); sp->xAxis2->setVisible(true); sp->yAxis2->setVisible(true); one_em_ = QFontMetrics(sp->yAxis->labelFont()).height(); ui->horizontalScrollBar->setSingleStep(100 / one_em_); ui->verticalScrollBar->setSingleStep(100 / one_em_); sp->setInteractions(QCP::iRangeDrag); ui->gridLayout->setSpacing(0); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), sp->yAxis2, SLOT(setRange(QCPRange))); ctx_menu_.addAction(ui->actionReset); ctx_menu_.addSeparator(); ctx_menu_.addAction(ui->actionMoveRight10); ctx_menu_.addAction(ui->actionMoveLeft10); ctx_menu_.addAction(ui->actionMoveUp10); ctx_menu_.addAction(ui->actionMoveDown10); ctx_menu_.addAction(ui->actionMoveRight1); ctx_menu_.addAction(ui->actionMoveLeft1); ctx_menu_.addAction(ui->actionMoveUp1); ctx_menu_.addAction(ui->actionMoveDown1); ctx_menu_.addSeparator(); ctx_menu_.addAction(ui->actionGoToPacket); memset (&seq_analysis_, 0, sizeof(seq_analysis_)); ui->showComboBox->blockSignals(true); ui->showComboBox->setCurrentIndex(0); ui->showComboBox->blockSignals(false); ui->addressComboBox->blockSignals(true); ui->addressComboBox->setCurrentIndex(0); ui->addressComboBox->blockSignals(false); QComboBox *fcb = ui->flowComboBox; fcb->addItem(ui->actionFlowAny->text(), SEQ_ANALYSIS_ANY); fcb->addItem(ui->actionFlowTcp->text(), SEQ_ANALYSIS_TCP); ui->flowComboBox->blockSignals(true); switch (type) { case any: seq_analysis_.type = SEQ_ANALYSIS_ANY; ui->flowComboBox->setCurrentIndex(SEQ_ANALYSIS_ANY); break; case tcp: seq_analysis_.type = SEQ_ANALYSIS_TCP; ui->flowComboBox->setCurrentIndex(SEQ_ANALYSIS_TCP); break; case voip: seq_analysis_.type = SEQ_ANALYSIS_VOIP; ui->flowComboBox->hide(); ui->flowLabel->hide(); break; } ui->flowComboBox->blockSignals(false); seq_analysis_.all_packets = TRUE; QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save); save_bt->setText(tr("Save As...")); // XXX Use recent settings instead if (parent) { resize(parent->width(), parent->height() * 4 / 5); } connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(hScrollBarChanged(int))); connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vScrollBarChanged(int))); connect(sp->xAxis2, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange))); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChanged(QCPRange))); connect(sp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(diagramClicked(QMouseEvent*))); connect(sp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*))); connect(sp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*))); connect(this, SIGNAL(goToPacket(int)), seq_diagram_, SLOT(setSelectedPacket(int))); disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); fillDiagram(); }
void chartcreate::repaintplot() { QCustomPlot * customPlot = ui->chart_preview; // create empty bar chart objects: QCPBars *regen = new QCPBars(customPlot->xAxis, customPlot->yAxis); QCPBars *nuclear = new QCPBars(customPlot->xAxis, customPlot->yAxis); QCPBars *fossil = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(regen); customPlot->addPlottable(nuclear); customPlot->addPlottable(fossil); // set names and colors: QPen pen; pen.setWidthF(1.2); fossil->setName("Danone"); pen.setColor(QColor(255, 131, 0)); fossil->setPen(pen); fossil->setBrush(QColor(255, 131, 0, 50)); nuclear->setName("AuBonLait"); pen.setColor(QColor(1, 92, 191)); nuclear->setPen(pen); nuclear->setBrush(QColor(1, 92, 191, 50)); regen->setName("Yoplait"); pen.setColor(QColor(150, 222, 0)); regen->setPen(pen); regen->setBrush(QColor(150, 222, 0, 70)); // stack bars ontop of each other: nuclear->moveAbove(fossil); regen->moveAbove(nuclear); // prepare x axis with country labels: QVector<double> ticks; QVector<QString> labels; ticks << 1 << 2 ; labels << "Homme" << "Femme" ; customPlot->xAxis->setAutoTicks(false); customPlot->xAxis->setAutoTickLabels(false); customPlot->xAxis->setTickVector(ticks); customPlot->xAxis->setTickVectorLabels(labels); customPlot->xAxis->setTickLabelRotation(60); customPlot->xAxis->setSubTickCount(0); customPlot->xAxis->setTickLength(0, 4); customPlot->xAxis->grid()->setVisible(true); customPlot->xAxis->setRange(0, 8); // prepare y axis: customPlot->yAxis->setRange(0, 12.1); customPlot->yAxis->setPadding(5); // a bit more space to the left border customPlot->yAxis->setLabel("Marque de Yaourt Connu"); customPlot->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); customPlot->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); customPlot->yAxis->grid()->setSubGridPen(gridPen); // Add data: QVector<double> fossilData, nuclearData, regenData; fossilData << 0.86*10.5 << 0.83*5.5; nuclearData << 0.08*10.5 << 0.12*5.5; regenData << 0.06*10.5 << 0.05*5.5; fossil->setData(ticks, fossilData); nuclear->setData(ticks, nuclearData); regen->setData(ticks, regenData); // setup legend: customPlot->legend->setVisible(true); customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter); customPlot->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); customPlot->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(10); customPlot->legend->setFont(legendFont); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); }
LBMUIMFlowDialog::LBMUIMFlowDialog(QWidget * parent, capture_file * cfile) : QDialog(parent), m_ui(new Ui::LBMUIMFlowDialog), m_capture_file(cfile), m_num_items(0), m_packet_num(0), m_node_label_width(20) { m_ui->setupUi(this); QCustomPlot * sp = m_ui->sequencePlot; m_sequence_diagram = new SequenceDiagram(sp->yAxis, sp->xAxis2, sp->yAxis2); sp->addPlottable(m_sequence_diagram); sp->axisRect()->setRangeDragAxes(sp->xAxis2, sp->yAxis); sp->xAxis->setVisible(false); sp->xAxis->setPadding(0); sp->xAxis->setLabelPadding(0); sp->xAxis->setTickLabelPadding(0); sp->xAxis2->setVisible(true); sp->yAxis2->setVisible(true); m_one_em = QFontMetrics(sp->yAxis->labelFont()).height(); m_ui->horizontalScrollBar->setSingleStep(100 / m_one_em); m_ui->verticalScrollBar->setSingleStep(100 / m_one_em); sp->setInteractions(QCP::iRangeDrag); m_ui->gridLayout->setSpacing(0); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), sp->yAxis2, SLOT(setRange(QCPRange))); m_context_menu.addAction(m_ui->actionReset); m_context_menu.addSeparator(); m_context_menu.addAction(m_ui->actionMoveRight10); m_context_menu.addAction(m_ui->actionMoveLeft10); m_context_menu.addAction(m_ui->actionMoveUp10); m_context_menu.addAction(m_ui->actionMoveDown10); m_context_menu.addAction(m_ui->actionMoveRight1); m_context_menu.addAction(m_ui->actionMoveLeft1); m_context_menu.addAction(m_ui->actionMoveUp1); m_context_menu.addAction(m_ui->actionMoveDown1); m_context_menu.addSeparator(); m_context_menu.addAction(m_ui->actionGoToPacket); memset(&m_sequence_analysis, 0, sizeof(m_sequence_analysis)); m_ui->showComboBox->blockSignals(true); m_ui->showComboBox->setCurrentIndex(0); m_ui->showComboBox->blockSignals(false); m_sequence_analysis.all_packets = TRUE; m_sequence_analysis.any_addr = TRUE; QPushButton * save_bt = m_ui->buttonBox->button(QDialogButtonBox::Save); save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS)); // XXX Use recent settings instead if (parent) { resize(parent->width(), parent->height() * 4 / 5); } connect(m_ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(hScrollBarChanged(int))); connect(m_ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vScrollBarChanged(int))); connect(sp->xAxis2, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange))); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChanged(QCPRange))); connect(sp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(diagramClicked(QMouseEvent*))); connect(sp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*))); connect(sp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*))); connect(this, SIGNAL(goToPacket(int)), m_sequence_diagram, SLOT(setSelectedPacket(int))); disconnect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); fillDiagram(); }
void ChartPage::setupChart() { this->buildingChart=true; QCustomPlot *customPlot = ui->chartBlock; customPlot->setInteraction(QCP::iRangeDrag, true); customPlot->setInteraction(QCP::iSelectPlottables, true); customPlot->setInteraction(QCP::iSelectItems, true); customPlot->setInteraction(QCP::iRangeZoom, true); customPlot->legend->setVisible(true); customPlot->legend->setFont(QFont("Helvetica",9)); // set locale to english, so we get english decimal separator: customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // create graph and assign data to it: customPlot->addGraph(); customPlot->graph(0)->setName("Difficulty"); // customPlot->graph(0)->setData(x, y); // give the axes some labels: customPlot->xAxis->setLabel("Date"); customPlot->yAxis->setLabel("Difficulty"); customPlot->legend->setSelectableParts(QCPLegend::spItems); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables); customPlot->axisRect()->setupFullAxesBox(); customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime); customPlot->xAxis->setDateTimeFormat("dd/MM/yyyy"); customPlot->xAxis->setAutoTickCount(5); //customPlot->yAxis->setAutoTickCount(5); // set axes ranges, so we see all data: customPlot->yAxis->setRange(-0.1, 3); ClientModel *model = this->clientModel; // generate some data: QVector<double> x(1000), y(1000); //, y1(50000); int maxBlocks; maxBlocks = model->getNumBlocks(); if (maxBlocks > 1000) { maxBlocks=1000; } int i = 0; if (maxBlocks > 0) { for (i = 0; i < maxBlocks; i++) { CBlock blk = model->getBlock(i); CBlockIndex* cIndex = model->getBlockIndex(i); x[i]=blk.GetBlockTime(); y[i]=model->getDiff(cIndex); } customPlot->graph(0)->setData(x, y); customPlot->xAxis->setRange(x[i-1]-(60*60*24), x[i-1]); this->lastBlockHeight = i; } customPlot->replot(); this->buildingChart=false; }
void LteRlcGraphDialog::mouseMoved(QMouseEvent *event) { QCustomPlot *rp = ui->rlcPlot; Qt::CursorShape shape = Qt::ArrowCursor; // Set the cursor shape. if (event) { if (event->buttons().testFlag(Qt::LeftButton)) { if (mouse_drags_) { shape = Qt::ClosedHandCursor; } else { shape = Qt::CrossCursor; } } else if (rp->axisRect()->rect().contains(event->pos())) { if (mouse_drags_) { shape = Qt::OpenHandCursor; } else { shape = Qt::CrossCursor; } } rp->setCursor(QCursor(shape)); } // Trying to let 'hint' grow efficiently. Still pretty slow for a dense graph... QString hint; hint.reserve(128); hint = "<small><i>"; if (mouse_drags_) { double tr_key = tracer_->position->key(); struct rlc_segment *packet_seg = NULL; packet_num_ = 0; // XXX If we have multiple packets with the same timestamp tr_key // may not return the packet we want. It might be possible to fudge // unique keys using nextafter(). if (event && tracer_->graph() && tracer_->position->axisRect()->rect().contains(event->pos())) { packet_seg = time_stamp_map_.value(tr_key, NULL); } if (!packet_seg) { tracer_->setVisible(false); hint += "Hover over the graph for details. </i></small>"; ui->hintLabel->setText(hint); ui->rlcPlot->replot(QCustomPlot::rpQueued); return; } tracer_->setVisible(true); packet_num_ = packet_seg->num; hint += tr("%1 %2 (%3s seq %4 len %5)") .arg(cap_file_.capFile() ? tr("Click to select packet") : tr("Packet")) .arg(packet_num_) .arg(QString::number(packet_seg->rel_secs + packet_seg->rel_usecs / 1000000.0, 'g', 4)) .arg(packet_seg->SN) .arg(packet_seg->pduLength); tracer_->setGraphKey(ui->rlcPlot->xAxis->pixelToCoord(event->pos().x())); // Redrawing the whole graph is making the update *very* slow! // TODO: Is there a way just to draw the parts that may have changed? // In the GTK version, we displayed the stored pixbuf and draw temporary items on top... rp->replot(QCustomPlot::rpQueued); } else { if (event && rubber_band_ && rubber_band_->isVisible()) { rubber_band_->setGeometry(QRect(rb_origin_, event->pos()).normalized()); QRectF zoom_ranges = getZoomRanges(QRect(rb_origin_, event->pos())); if (zoom_ranges.width() > 0.0 && zoom_ranges.height() > 0.0) { hint += tr("Release to zoom, x = %1 to %2, y = %3 to %4") .arg(zoom_ranges.x()) .arg(zoom_ranges.x() + zoom_ranges.width()) .arg(zoom_ranges.y()) .arg(zoom_ranges.y() + zoom_ranges.height()); } else { hint += tr("Unable to select range."); } } else { hint += tr("Click to select a portion of the graph."); } } hint.append("</i></small>"); ui->hintLabel->setText(hint); }