void MainWindow::genLineEnding() { resetPlot(); QMetaEnum endingStyleEnum = QCPLineEnding::staticMetaObject.enumerator(QCPLineEnding::staticMetaObject.indexOfEnumerator("EndingStyle")); double offset = -0.2; double step = 1.4/((double)endingStyleEnum.keyCount()-1); for (int i=0; i<endingStyleEnum.keyCount(); ++i) { QCPLineEnding ending(static_cast<QCPLineEnding::EndingStyle>(endingStyleEnum.value(i))); QString endingName(endingStyleEnum.key(i)); if (ending.style() == QCPLineEnding::esSkewedBar) ending.setInverted(true); QCPItemLine *line = new QCPItemLine(customPlot); line->setPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::FlatCap)); customPlot->addItem(line); line->start->setCoords(offset+i*step-0.1, -0.2); line->end->setCoords(offset+i*step, 0.5); line->setHead(ending); QCPItemText *text = new QCPItemText(customPlot); customPlot->addItem(text); text->position->setParentAnchor(line->end); text->position->setCoords(8, -15-(i%2)*15); text->setFont(QFont(font().family(), 8)); text->setText(endingName); } customPlot->savePng(dir.filePath("QCPLineEnding.png"), 500, 100); }
void MainWindow::genItemLine() { resetPlot(); QCPItemLine *line = new QCPItemLine(customPlot); customPlot->addItem(line); line->start->setCoords(-0.1, 0.8); line->end->setCoords(1.1, 0.2); line->setHead(QCPLineEnding::esSpikeArrow); labelItemAnchors(line); customPlot->savePng(dir.filePath("QCPItemLine.png"), 230, 160); }
void AP2DataPlot2D::navModeChanged(int uasid, int mode, const QString& text) { Q_UNUSED(mode); if (m_uas->getUASID() != uasid) { return; } if (m_logLoaded) { //If a log is currently loaded, we don't care about incoming data. return; } qint64 msec_current = QDateTime::currentMSecsSinceEpoch(); m_currentIndex = msec_current; qint64 newmsec = (msec_current - m_startIndex) + m_timeDiff; if (m_graphCount > 0 && ui.autoScrollCheckBox->isChecked()) { double diff = (newmsec / 1000.0) - m_wideAxisRect->axis(QCPAxis::atBottom,0)->range().upper; m_wideAxisRect->axis(QCPAxis::atBottom,0)->setRangeLower(m_wideAxisRect->axis(QCPAxis::atBottom,0)->range().lower + diff); m_wideAxisRect->axis(QCPAxis::atBottom,0)->setRangeUpper((newmsec / 1000.0)); } if (!m_graphClassMap.contains("MODE")) { QCPAxis *axis = m_wideAxisRect->addAxis(QCPAxis::atLeft); axis->setLabel("MODE"); if (m_graphCount > 0) { connect(m_wideAxisRect->axis(QCPAxis::atLeft,0),SIGNAL(rangeChanged(QCPRange)),axis,SLOT(setRange(QCPRange))); } QColor color = QColor::fromRgb(rand()%255,rand()%255,rand()%255); axis->setLabelColor(color); axis->setTickLabelColor(color); axis->setTickLabelColor(color); // add an extra axis on the left and color its numbers QCPGraph *mainGraph1 = m_plot->addGraph(m_wideAxisRect->axis(QCPAxis::atBottom), m_wideAxisRect->axis(QCPAxis::atLeft,m_graphCount++)); m_graphNameList.append("MODE"); mainGraph1->setPen(QPen(color, 2)); Graph graph; graph.axis = axis; graph.groupName = ""; graph.graph= mainGraph1; graph.isInGroup = false; graph.isManualRange = false; m_graphClassMap["MODE"] = graph; mainGraph1->rescaleValueAxis(); if (m_graphCount == 1) { mainGraph1->rescaleKeyAxis(); } } QCPAxis *xAxis = m_wideAxisRect->axis(QCPAxis::atBottom); QCPItemText *itemtext = new QCPItemText(m_plot); itemtext->setText(text); itemtext->position->setAxes(xAxis,m_graphClassMap["MODE"].axis); itemtext->position->setCoords((newmsec / 1000.0),2.0); m_plot->addItem(itemtext); m_graphClassMap["MODE"].itemList.append(itemtext); m_graphClassMap["MODE"].modeMap[newmsec / 1000.0] = text; QCPItemLine *itemline = new QCPItemLine(m_plot); m_graphClassMap["MODE"].itemList.append(itemline); itemline->start->setParentAnchor(itemtext->bottom); itemline->start->setAxes(xAxis, m_graphClassMap["MODE"].axis); itemline->start->setCoords(0.0, 0.0); itemline->end->setAxes(xAxis, m_graphClassMap["MODE"].axis); itemline->end->setCoords((newmsec / 1000.0), 0.0); itemline->setTail(QCPLineEnding::esDisc); itemline->setHead(QCPLineEnding::esSpikeArrow); m_plot->addItem(itemline); }