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::genMarginGroup() { resetPlot(); customPlot->plotLayout()->clear(); customPlot->plotLayout()->addElement(0, 0, new QCPAxisRect(customPlot)); customPlot->plotLayout()->addElement(0, 1, new QCPAxisRect(customPlot)); customPlot->plotLayout()->addElement(1, 0, new QCPAxisRect(customPlot)); customPlot->plotLayout()->addElement(1, 1, new QCPAxisRect(customPlot)); foreach (QCPAxisRect *r, customPlot->axisRects()) r->axis(QCPAxis::atBottom)->setTickLabels(false); QCPMarginGroup *marginGroup = new QCPMarginGroup(customPlot); customPlot->axisRect(0)->setMarginGroup(QCP::msLeft, marginGroup); customPlot->axisRect(2)->setMarginGroup(QCP::msLeft, marginGroup); customPlot->axisRect(0)->axis(QCPAxis::atLeft)->setRange(0, 1300); customPlot->axisRect(1)->axis(QCPAxis::atLeft)->setRange(0, 1300); customPlot->axisRect(0)->axis(QCPAxis::atLeft)->setLabel("y"); customPlot->axisRect(1)->axis(QCPAxis::atLeft)->setLabel("y"); customPlot->plotLayout()->setAutoMargins(QCP::msLeft|QCP::msRight|QCP::msBottom); customPlot->plotLayout()->setMargins(QMargins(0, 25, 0, 0)); QFont textFont; textFont.setBold(true); QCPItemText *leftCaption = new QCPItemText(customPlot); customPlot->addItem(leftCaption); leftCaption->position->setType(QCPItemPosition::ptViewportRatio); leftCaption->setClipToAxisRect(false); leftCaption->position->setCoords(0.25, 0); leftCaption->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter); leftCaption->setText("left sides in margin group"); leftCaption->setFont(textFont); QCPItemText *rightCaption = new QCPItemText(customPlot); customPlot->addItem(rightCaption); rightCaption->position->setType(QCPItemPosition::ptViewportRatio); rightCaption->position->setCoords(0.75, 0); rightCaption->setClipToAxisRect(false); rightCaption->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter); rightCaption->setText("no margin group"); rightCaption->setFont(textFont); QCPItemLine *splitter = new QCPItemLine(customPlot); splitter->start->setType(QCPItemPosition::ptViewportRatio); splitter->start->setCoords(0.5, 0); splitter->end->setType(QCPItemPosition::ptViewportRatio); splitter->end->setCoords(0.5, 1); splitter->setClipToAxisRect(false); splitter->setPen(QPen(Qt::gray, 0, Qt::DashLine)); customPlot->savePng(dir.filePath("QCPMarginGroup.png"), 400, 400); }
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 MainWindow::genAxisRectSpacingOverview() { resetPlot(); customPlot->xAxis->setRange(-0.4, 1.4); customPlot->yAxis->setRange(100, 900); customPlot->xAxis->setVisible(true); customPlot->yAxis->setVisible(true); customPlot->axisRect()->setupFullAxesBox(); customPlot->xAxis->setTickLabels(false); customPlot->axisRect()->setAutoMargins(QCP::msNone); customPlot->axisRect()->setMargins(QMargins(200, 50, 20, 165)); customPlot->axisRect()->setBackground(QColor(245, 245, 245)); customPlot->yAxis->setLabel("Axis Label"); customPlot->yAxis->setOffset(30); customPlot->yAxis->setTickLabelPadding(30); customPlot->yAxis->setLabelPadding(30); customPlot->yAxis->setTickLengthOut(5); customPlot->yAxis->setSubTickLengthOut(2); addBracket(QPointF(200-95-27-17, 30), QPointF(1, 30), "Padding (if auto margins enabled)", QPointF(-25, -5), false, Qt::AlignLeft|Qt::AlignBottom); addBracket(QPointF(1, 370), QPointF(200, 370), "Margin", QPointF(0, 5), false, Qt::AlignHCenter|Qt::AlignTop); addBracket(QPointF(200-30, 240), QPointF(200, 240), "Axis offset", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter); addBracket(QPointF(200-35, 250), QPointF(200-30, 250), "Tick length out", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter); addBracket(QPointF(200-65, 240), QPointF(200-35, 240), "Tick label padding", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter); addBracket(QPointF(200-95-25, 240), QPointF(200-65-25, 240), "Label padding", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter); QCPItemLine *leftBorder = new QCPItemLine(customPlot); customPlot->addItem(leftBorder); leftBorder->setClipToAxisRect(false); leftBorder->start->setType(QCPItemPosition::ptViewportRatio); leftBorder->end->setType(QCPItemPosition::ptViewportRatio); leftBorder->start->setCoords(0, 0); leftBorder->end->setCoords(0, 1); leftBorder->setPen(QPen(Qt::gray, 0, Qt::DashLine)); QCPItemText *axisRectLabel = new QCPItemText(customPlot); customPlot->addItem(axisRectLabel); axisRectLabel->position->setType(QCPItemPosition::ptAxisRectRatio); axisRectLabel->position->setCoords(0.5, 0.5); axisRectLabel->setFont(QFont(QFont().family(), 16)); axisRectLabel->setText("QCPAxisRect"); axisRectLabel->setColor(QColor(0, 0, 0, 60)); customPlot->savePng(dir.filePath("AxisRectSpacingOverview.png"), 400, 400); }
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); }
void MainWindow::displayTemperature(QCustomPlot *customPlot) { QPen pen; int temp; // give the axes some labels: customPlot->xAxis->setLabel("Samples"); customPlot->yAxis->setLabel("Temperature (°C)"); // set axes ranges, so we see all data: customPlot->xAxis->setRange(0, SAMPLE_STORE_SIZE); customPlot->yAxis->setRange(0, CUSTOMPLOT_YAXIS_RANGE); customPlot->legend->setVisible(true); pen.setWidth(1); currentTempsensorIndex = 0; for (uint zone = 0; zone < thermaldInterface.getZoneCount(); zone++) { zoneInformationType *zone_info = thermaldInterface.getZone(zone); if (!zone_info) continue; pen.setColor(colors[zone % colors.count()]); int sensor_cnt_per_zone = thermaldInterface.getSensorCountForZone(zone); if (sensor_cnt_per_zone <= 0) break; pen.setStyle(Qt::SolidLine); for (int cnt = 0; cnt < sensor_cnt_per_zone; cnt++) { QString sensor_type; QString sensor_name; sensorZoneInformationType sensor_info; if (thermaldInterface.getSensorTypeForZone(zone, cnt, sensor_type) < 0) continue; sensor_name.append(zone_info->name); sensor_name.append(":"); sensor_name.append(sensor_type); ui->customPlot->addGraph(); ui->customPlot->graph(currentTempsensorIndex)->setName(sensor_name); ui->customPlot->graph(currentTempsensorIndex)->setPen(pen); current_sample_index[currentTempsensorIndex] = 0; sensor_info.index = thermaldInterface.getSensorIndex(sensor_type); sensor_info.display_name = sensor_name; sensor_info.sensor_name = sensor_type; sensor_info.zone = zone; sensor_types.append(sensor_info); currentTempsensorIndex++; } pen.setStyle(Qt::DashLine); // Draw a dashed horz line for each min valid trip temperature QVector<QCPItemLine *> these_trips; uint trip_count = thermaldInterface.getTripCountForZone(zone); if (trip_count > 0) { for (uint trip = 0; trip < trip_count; trip++){ QCPItemLine *line = new QCPItemLine(customPlot); customPlot->addItem(line); temp = thermaldInterface.getTripTempForZone(zone, trip); line->start->setCoords(0, temp); line->end->setCoords(SAMPLE_STORE_SIZE - 1, temp); line->setPen(pen); if (temp == thermaldInterface.getLowestValidTripTempForZone(zone)) { line->setVisible(true); thermaldInterface.setTripVisibility(zone, trip, true); } else { line->setVisible(false); thermaldInterface.setTripVisibility(zone, trip, false); } these_trips.append(line); } trips.append(these_trips); } } // Now display sensors which are not part of any zone. Users can use this and assign to some zone for (uint i = 0; i < thermaldInterface.getSensorCount(); ++i) { sensorInformationType info; QString name; bool found = false; name = thermaldInterface.getSensorName(i); if (!name.isEmpty()){ // search if this is already registered as part of a zone sensor for (int j = 0; j < sensor_types.count(); ++j) { sensorZoneInformationType sensor_info = sensor_types[j]; if (name == sensor_info.sensor_name) { found = true; break; } } if (!found) { sensorZoneInformationType sensor_info; QString sensor_name; sensor_name.append("UKWN:"); sensor_name.append(name); ui->customPlot->addGraph(); ui->customPlot->graph(currentTempsensorIndex)->setName(sensor_name); ui->customPlot->graph(currentTempsensorIndex)->setPen(pen); current_sample_index[currentTempsensorIndex] = 0; sensor_info.index = thermaldInterface.getSensorIndex(name); sensor_info.display_name = sensor_name; sensor_info.sensor_name = name; sensor_info.zone = -1; sensor_types.append(sensor_info); currentTempsensorIndex++; } } } sensor_visibility = new bool[sensor_types.count()]; sensor_temp = new QLabel[sensor_types.count()]; connect(&tempUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTemperatureDataSlot())); tempUpdateTimer.start(temp_poll_interval); }