void MainWindow::on_listView_clicked(const QModelIndex &index) { //QModelIndex a = ui->listView->selectedIndexes().back(); QVariant selected = dataModel->compNameList->data(index,Qt::DisplayRole); dataModel->dataViewComp = selected.toString(); QVector<double> dataViewPrice = dataModel->priceBuff.value(selected.toString()); QVector<double> xval; QVector<double> baseVal; if(dataViewPrice.empty()) return; double min = dataViewPrice[0]; for(auto &i : dataViewPrice) min = std::fmin(min,i); for(int i = 0; i<dataViewPrice.size(); i++){ xval<<i; baseVal<<min; } QCustomPlot* p = ui->qcpDataView;; p->clearGraphs(); QCPGraph* timeline = new QCPGraph(p->xAxis,p->yAxis); timeline->addData(xval,dataViewPrice); QCPGraph* base = new QCPGraph(p->xAxis,p->yAxis); base->setData(xval,baseVal); p->addPlottable(timeline); p->addPlottable(base); timeline->setChannelFillGraph(base); timeline->setPen(QPen(QColor(0,0,0,0))); timeline->setBrush(QColor(0,0,255,100)); //QVector<double> ticks; QVector<QString> labels; int L = this->dataModel->dateBuff.values()[0].size()-1; int len = 6; float step = (float)L/(float)len; for(int i = 0; i<= len; i++){ labels<<this->dataModel->dateBuff.values()[0][i*step].toString("MM/yy"); } p->xAxis->setTickVectorLabels(labels); p->xAxis->setAutoTicks(true); p->xAxis->setAutoTickLabels(false); p->xAxis->setTickLabelRotation(-60); //p->xAxis->setSubTickCount(0); //p->xAxis->setTickLength(0, len-1); p->xAxis->grid()->setVisible(true); //p->xAxis->setRange(0, len-2); //p->xAxis->setTickVector(ticks); p->rescaleAxes(); p->replot(); }
void Window::plotHistogram(QVector<double> key, QVector<double> nonEq, QVector<double> eqValue, QVector<double> lutValue) { QCustomPlot *histogramPlot = ui->histogramPlot; histogramPlot->clearGraphs(); // Non Equalized QCPBars *nonEqHistBars = new QCPBars(histogramPlot->xAxis, histogramPlot->yAxis); histogramPlot->addPlottable(nonEqHistBars); nonEqHistBars->setWidth(1); nonEqHistBars->setData(key, nonEq); nonEqHistBars->setPen(Qt::NoPen); nonEqHistBars->setBrush(QColor(10, 140, 70, 160)); // // Equalized // QCPBars *eqHistBars = new QCPBars(histogramPlot->xAxis, histogramPlot->yAxis); // histogramPlot->addPlottable(eqHistBars); // eqHistBars->setWidth(1); // eqHistBars->setData(key, eqValue); // eqHistBars->setPen(Qt::NoPen); // eqHistBars->setBrush(QColor(10, 100, 50, 70)); //// eqHistBars->moveAbove(eqHistBars); // // LUT // QCPGraph *lut = histogramPlot->addGraph(); // lut->setData(key, lutValue); // lut->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(Qt::black, 1.5), QBrush(Qt::white), 9)); // lut->setLineStyle(QCPGraph::lsStepCenter); // lut->setPen(QPen(QColor(120, 120, 120), 2)); histogramPlot->replot(); histogramPlot->rescaleAxes(); }
bool BarGraph::update(const GRT::VectorDouble &sample ) { if( !initialized ) return false; this->data = sample; //If the plot is hidden then there is no point in updating the graph if( this->isHidden() ) { return true; } QCustomPlot *plot = ui->graph; QVector<double> keyData; QVector<double> valueData; QVector<double> tickVector; QVector<QString> tickLabels; const unsigned int K = (unsigned int)data.size(); plot->clearPlottables(); QCPBars *bar = new QCPBars(plot->xAxis,plot->yAxis); plot->addPlottable( bar ); //Add the data to the graph for(unsigned int k=0; k<K; k++) { keyData << k+1; valueData << data[k]; } bar->setData(keyData, valueData); //Add the tick labels for(unsigned int k=0; k<K; k++) { tickVector << double(k+1); tickLabels << QString::fromStdString( GRT::Util::intToString( k+1 ) ); } plot->xAxis->setAutoTicks(false); plot->xAxis->setAutoTickLabels(false); plot->xAxis->setTickVector( tickVector ); plot->xAxis->setTickVectorLabels( tickLabels ); plot->xAxis->setLabel("Features"); plot->yAxis->setLabel("Values"); plot->rescaleAxes(); plot->replot(); return true; }
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(); }
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); }
SequenceDialog::SequenceDialog(QWidget &parent, CaptureFile &cf, SequenceInfo *info) : WiresharkDialog(parent, cf), ui(new Ui::SequenceDialog), info_(info), num_items_(0), packet_num_(0), sequence_w_(1) { ui->setupUi(this); loadGeometry(parent.width(), parent.height() * 4 / 5); QCustomPlot *sp = ui->sequencePlot; setWindowSubtitle(info_ ? tr("Call Flow") : tr("Flow")); if (!info_) { info_ = new SequenceInfo(sequence_analysis_info_new()); info_->sainfo()->type = SEQ_ANALYSIS_ANY; info_->sainfo()->all_packets = TRUE; } else { info_->ref(); num_items_ = sequence_analysis_get_nodes(info_->sainfo()); } seq_diagram_ = new SequenceDiagram(sp->yAxis, sp->xAxis2, sp->yAxis2); sp->addPlottable(seq_diagram_); // When dragging is enabled it's easy to drag past the lower and upper // bounds of each axis. Disable it for now. //sp->axisRect()->setRangeDragAxes(sp->xAxis2, sp->yAxis); //sp->setInteractions(QCP::iRangeDrag); sp->xAxis->setVisible(false); sp->xAxis->setPadding(0); sp->xAxis->setLabelPadding(0); sp->xAxis->setTickLabelPadding(0); QPen base_pen(ColorUtils::alphaBlend(palette().text(), palette().base(), 0.25)); base_pen.setWidthF(0.5); sp->xAxis2->setBasePen(base_pen); sp->yAxis->setBasePen(base_pen); sp->yAxis2->setBasePen(base_pen); sp->xAxis2->setVisible(true); sp->yAxis2->setVisible(true); key_text_ = new QCPItemText(sp); key_text_->setText(tr("Time")); sp->addItem(key_text_); key_text_->setPositionAlignment(Qt::AlignRight | Qt::AlignVCenter); key_text_->position->setType(QCPItemPosition::ptAbsolute); key_text_->setClipToAxisRect(false); comment_text_ = new QCPItemText(sp); comment_text_->setText(tr("Comment")); sp->addItem(comment_text_); comment_text_->setPositionAlignment(Qt::AlignLeft | Qt::AlignVCenter); comment_text_->position->setType(QCPItemPosition::ptAbsolute); comment_text_->setClipToAxisRect(false); one_em_ = QFontMetrics(sp->yAxis->labelFont()).height(); ui->horizontalScrollBar->setSingleStep(100 / one_em_); ui->verticalScrollBar->setSingleStep(100 / one_em_); 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); ctx_menu_.addAction(ui->actionGoToNextPacket); ctx_menu_.addAction(ui->actionGoToPreviousPacket); ui->showComboBox->setCurrentIndex(0); ui->addressComboBox->setCurrentIndex(0); QComboBox *fcb = ui->flowComboBox; fcb->addItem(ui->actionFlowAny->text(), SEQ_ANALYSIS_ANY); fcb->addItem(ui->actionFlowTcp->text(), SEQ_ANALYSIS_TCP); ui->flowComboBox->setCurrentIndex(info_->sainfo()->type); if (info_->sainfo()->type == SEQ_ANALYSIS_VOIP) { ui->flowComboBox->blockSignals(true); ui->controlFrame->hide(); } QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save); save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS)); ProgressFrame::addToButtonBox(ui->buttonBox, &parent); 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(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheeled(QWheelEvent*))); connect(this, SIGNAL(goToPacket(int)), seq_diagram_, SLOT(setSelectedPacket(int))); disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); }
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 YarrGui::detachPlot(){ if(ui->plotTree->currentItem() == nullptr){ std::cerr << "Please select plot to detach...\n"; return; } if(ui->plotTree->currentItem()->childCount() > 0){ std::cerr << "Please select plot to detach...\n"; return; } PlotDialog * myPDiag = new PlotDialog(); QCustomPlot * plotWidget = dynamic_cast<QCustomPlot*>(ui->scanPlots_tabWidget->currentWidget()); if(plotWidget == nullptr){ std::cerr << "Severe cast error. Aborting...\n"; return; } QCustomPlot * transferPlot = dynamic_cast<QCustomPlot*>(myPDiag->childAt(10, 10)); if(transferPlot == nullptr){ std::cerr << "Severe cast error. Aborting...\n"; return; } QCPPlotTitle * widgetPT = dynamic_cast<QCPPlotTitle*>(plotWidget->plotLayout()->element(0, 0)); if(widgetPT == nullptr){ std::cerr << "Severe cast error. Aborting... \n"; return; } if(dynamic_cast<QCPColorMap*>(plotWidget->plottable(0)) != nullptr){ QCPColorMap * widgetCMap = dynamic_cast<QCPColorMap*>(plotWidget->plottable(0)); QCPColorScale * widgetCScale = dynamic_cast<QCPColorScale*>(plotWidget->plotLayout()->element(1, 1)); if(widgetCScale == nullptr) { std::cerr << "Severe cast error. Aborting... \n"; return; } transferPlot->plotLayout()->insertRow(0); transferPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(transferPlot, widgetPT->text())); QCPColorMap * transferCMap = new QCPColorMap(transferPlot->xAxis, transferPlot->yAxis); transferPlot->addPlottable(transferCMap); transferCMap->data()->setSize(80, 336); transferCMap->setData(widgetCMap->data(), true); QCPColorScale * transferCScale = new QCPColorScale(transferPlot); transferPlot->plotLayout()->addElement(1, 1, transferCScale); transferCScale->setType(QCPAxis::atRight); transferCMap->setColorScale(transferCScale); transferCMap->keyAxis()->setLabel(widgetCMap->keyAxis()->label()); transferCMap->valueAxis()->setLabel(widgetCMap->valueAxis()->label()); transferCScale->axis()->setLabel(widgetCScale->axis()->label()); transferCMap->setGradient(QCPColorGradient::gpPolar); transferCMap->rescaleDataRange(); }else if(dynamic_cast<QCPBars*>(plotWidget->plottable(0)) != nullptr){ QCPBars * widgetBars = dynamic_cast<QCPBars*>(plotWidget->plottable(0)); QCPBars * transferBars = new QCPBars(transferPlot->xAxis, transferPlot->yAxis); transferBars->setData(widgetBars->data(), true); transferBars->rescaleAxes(); transferPlot->plotLayout()->insertRow(0); transferPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(transferPlot, widgetPT->text())); transferBars->keyAxis()->setLabel(widgetBars->keyAxis()->label()); transferBars->valueAxis()->setLabel(widgetBars->valueAxis()->label()); }else{ std::cerr << "Severe cast error. Aborting... \n"; //DEBUG return; } transferPlot->rescaleAxes(); transferPlot->replot(); myPDiag->setModal(false); myPDiag->show(); removePlot(); return; }
void YarrGui::doScan(QString qn){ std::ofstream *tmpOfCout = new std::ofstream("deleteMeCout.txt"); std::streambuf *coutBuf = std::cout.rdbuf(tmpOfCout->rdbuf()); std::ofstream *tmpOfCerr = new std::ofstream("deleteMeCerr.txt"); std::streambuf *cerrBuf = std::cerr.rdbuf(tmpOfCerr->rdbuf()); int N = ui->feTree->topLevelItemCount(); int M = scanVec.size(); for(int j = 0; j < N; j++){ scanDone = false; processorDone = false; if(!(ui->feTree->topLevelItem(j)->child(4)->checkState(1))){continue;} //Is the Scan checkbox checked? Fei4 * fe = dynamic_cast<Fei4*>(bk->feList.at(j)); ScanBase * s = nullptr; if(qn == "NS") {s = new Fei4NoiseScan(bk);} if(qn == "DS") {s = new Fei4DigitalScan(bk);} if(qn == "AS") {s = new Fei4AnalogScan(bk);} if(qn == "TS") {s = new Fei4ThresholdScan(bk);} if(qn == "ToTS") {s = new Fei4TotScan(bk);} if(qn == "GTT") {s = new Fei4GlobalThresholdTune(bk);} if(qn == "GPT") {s = new Fei4GlobalPreampTune(bk);} if(qn == "PTT") {s = new Fei4PixelThresholdTune(bk);} if(qn == "PPT") {s = new Fei4PixelPreampTune(bk);} if(qn == "CS") {s = &cs;} if(s == nullptr){ std::cerr << "Invalid scan QString parameter passed or scan object construction failed. Returning...\n"; return; } QTreeWidgetItem * plotTreeItem = nullptr; //Plot tree item for current FE for(int k = 0; k < ui->plotTree->topLevelItemCount(); k++){ //Is the current FE already in the tree? ... if(ui->plotTree->topLevelItem(k)->text(0) == ui->feTree->topLevelItem(j)->text(0)){ plotTreeItem = ui->plotTree->topLevelItem(k); break; } } if(plotTreeItem == nullptr){ //... if not: create a branch for it plotTreeItem = new QTreeWidgetItem(ui->plotTree); plotTreeItem->setText(0, ui->feTree->topLevelItem(j)->text(0)); } QTreeWidgetItem * plotTreeItemDS = new QTreeWidgetItem(); //plot tree item for current scan plotTreeItemDS->setText(0, qn); plotTreeItem->addChild(plotTreeItemDS); fe->histogrammer = new Fei4Histogrammer(); fe->histogrammer->connect(fe->clipDataFei4, fe->clipHisto); fe->ana = new Fei4Analysis(bk, fe->getRxChannel()); fe->ana->connect(s, fe->clipHisto, fe->clipResult); if (qn=="CS"){ CustomScan * tmp; tmp = dynamic_cast<CustomScan*>(s); if(tmp->bA.at(OCC_MAP) == true) {fe->histogrammer->addHistogrammer(new OccupancyMap());} if(tmp->bA.at(TOT_MAP) == true) {fe->histogrammer->addHistogrammer(new TotMap());} if(tmp->bA.at(TOT_2_MAP) == true) {fe->histogrammer->addHistogrammer(new Tot2Map());} if(tmp->bA.at(OCC_ANA) == true) {fe->ana->addAlgorithm(new OccupancyAnalysis());} if(tmp->bA.at(NOISE_ANA) == true) {fe->ana->addAlgorithm(new NoiseAnalysis());} if(tmp->bA.at(TOT_ANA) == true) {fe->ana->addAlgorithm(new TotAnalysis());} if(tmp->bA.at(S_CU_FIT) == true) {fe->ana->addAlgorithm(new ScurveFitter());} if(tmp->bA.at(PIX_THR) == true) {fe->ana->addAlgorithm(new OccPixelThresholdTune);} }else{ fe->histogrammer->addHistogrammer(new OccupancyMap()); if (qn == "ToTS" || qn == "GPT" || qn == "PPT"){ fe->histogrammer->addHistogrammer(new TotMap()); fe->histogrammer->addHistogrammer(new Tot2Map()); } if(qn == "NS") {fe->ana->addAlgorithm(new NoiseAnalysis());} if(qn == "DS") {fe->ana->addAlgorithm(new OccupancyAnalysis());} if(qn == "AS") {fe->ana->addAlgorithm(new OccupancyAnalysis());} if(qn == "TS") {fe->ana->addAlgorithm(new ScurveFitter());} if(qn == "ToTS") {fe->ana->addAlgorithm(new TotAnalysis());} if(qn == "GTT") {fe->ana->addAlgorithm(new OccGlobalThresholdTune());} if(qn == "GPT") {fe->ana->addAlgorithm(new TotAnalysis());} if(qn == "PTT") {fe->ana->addAlgorithm(new OccPixelThresholdTune());} if(qn == "PPT") {fe->ana->addAlgorithm(new TotAnalysis());} } s->init(); ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //1 s->preScan(); ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //2 unsigned int numThreads = std::thread::hardware_concurrency(); //std::cout << "-> Starting " << numThreads << " processor Threads:" << std::endl; std::vector<std::thread> procThreads; for (unsigned i=0; i<numThreads; i++){ procThreads.push_back(std::thread(process, bk, &scanDone)); //std::cout << " -> Processor thread #" << i << " started!" << std::endl; } std::vector<std::thread> anaThreads; //std::cout << "-> Starting histogrammer and analysis threads:" << std::endl; if (fe->isActive()){ anaThreads.push_back(std::thread(analysis, fe->histogrammer, fe->ana, &processorDone)); //std::cout << " -> Analysis thread of Fe " << fe->getRxChannel() << std::endl; } s->run(); ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //3 s->postScan(); ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //4 scanDone = true; for (unsigned i=0; i<numThreads; i++){ procThreads[i].join(); } ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //5 processorDone = true; for(unsigned i=0; i<anaThreads.size(); i++){ anaThreads[i].join(); } ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //6 if(qn != "CS") { delete s; } // fe->toFileBinary(); // fe->ana->plot("Scan_GUI"); //DEBUG begin [plotting] //clear raw data while(fe->clipDataFei4->size() != 0){ fe->clipDataFei4->popData(); } //clear raw data while(fe->clipHisto->size() != 0){ fe->clipHisto->popData(); } while(fe->clipResult->size() != 0){ HistogramBase * showMe = fe->clipResult->popData(); //Add tab to plot tab widget QCustomPlot * tabScanPlot = new QCustomPlot(ui->scanPlots_tabWidget); // X QWidget * addToTabWidget = dynamic_cast<QWidget*>(tabScanPlot); QString newTabName = qn + ' ' + ui->feTree->topLevelItem(j)->text(0); ui->scanPlots_tabWidget->addTab(addToTabWidget, newTabName); //Add plot to scan tree QTreeWidgetItem * plotTreeItemP = new QTreeWidgetItem(plotTreeItemDS); // X plotTreeItemP->setText(0, "Plot " + QString::number(plotTreeItemDS->childCount()) + " (" + QString::fromStdString(showMe->getName()) + ")"); plotTreeItemDS->addChild(plotTreeItemP); if(dynamic_cast<Histo2d*>(showMe) != nullptr){ Histo2d * myHist2d = dynamic_cast<Histo2d*>(showMe); //Create plot QCPColorMap * colorMap = new QCPColorMap(tabScanPlot->xAxis, tabScanPlot->yAxis); QCPColorScale * colorScale = new QCPColorScale(tabScanPlot); tabScanPlot->addPlottable(colorMap); tabScanPlot->plotLayout()->insertRow(0); tabScanPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(tabScanPlot, QString::fromStdString(myHist2d->getName()))); colorMap->setName(QString::fromStdString(myHist2d->getName())); colorMap->data()->setSize(80, 336); colorMap->data()->setRange(QCPRange(0, 80), QCPRange(0, 336)); colorMap->keyAxis()->setLabel(QString::fromStdString(myHist2d->getXaxisTitle())); colorMap->valueAxis()->setLabel(QString::fromStdString(myHist2d->getYaxisTitle())); for(int xCoord = 0; xCoord<80; xCoord++){ for(int yCoord = 0; yCoord<336; yCoord++){ double colVal = myHist2d->getBin(yCoord + 336*xCoord); //TODO make better colorMap->data()->setCell(xCoord, yCoord, colVal); } } tabScanPlot->plotLayout()->addElement(1, 1, colorScale); colorScale->setType(QCPAxis::atRight); colorMap->setColorScale(colorScale); colorScale->axis()->setLabel(QString::fromStdString(myHist2d->getZaxisTitle())); colorMap->setGradient(QCPColorGradient::gpPolar); colorMap->rescaleDataRange(); }else if(dynamic_cast<Histo1d*>(showMe) != nullptr){ Histo1d * myHist1d = dynamic_cast<Histo1d*>(showMe); QCPBars * myBars = new QCPBars(tabScanPlot->xAxis, tabScanPlot->yAxis); tabScanPlot->addPlottable(myBars); myBars->setName(QString::fromStdString(myHist1d->getName())); for(unsigned int i = 0; i < myHist1d->size(); i++) { myBars->addData((double)(i+1), myHist1d->getBin(i)); } myBars->rescaleAxes(); tabScanPlot->plotLayout()->insertRow(0); tabScanPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(tabScanPlot, QString::fromStdString(myHist1d->getName()))); myBars->keyAxis()->setLabel(QString::fromStdString(myHist1d->getXaxisTitle())); myBars->valueAxis()->setLabel(QString::fromStdString(myHist1d->getYaxisTitle())); }else{ std::cerr << "Correct plot type not found or severe cast error\n"; //DEBUG return; } tabScanPlot->rescaleAxes(); tabScanPlot->replot(); } ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //7 delete fe->histogrammer; fe->histogrammer = nullptr; delete fe->ana; fe->ana = nullptr; } std::cout.rdbuf(coutBuf); std::cerr.rdbuf(cerrBuf); tmpOfCout->close(); tmpOfCerr->close(); std::ifstream tmpInCout("deleteMeCout.txt"); std::ifstream tmpInCerr("deleteMeCerr.txt"); std::cout << tmpInCout.rdbuf(); std::cerr << tmpInCerr.rdbuf(); tmpInCout.close(); tmpInCerr.close(); return; }