Files
newspark110/dmplot/ui/plotwidget.cpp
Chenwenxuan edac2715f0 init
2024-03-06 14:54:30 +08:00

126 lines
1.8 KiB
C++

#include "plotwidget.h"
#include "ui_plotwidget.h"
#include <QDebug>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
# include <QDesktopWidget>
#endif
#include <QScreen>
#include <QMessageBox>
#include <QMetaEnum>
PlotWidget::PlotWidget(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::PlotWidget)
{
ui->setupUi(this);
setGeometry(400, 250, 542, 390);
setupItemDemo(ui->customPlot);
statusBar()->clearMessage();
ui->customPlot->replot();
}
void PlotWidget::setupItemDemo(QCustomPlot *customPlot)
{
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
QCPGraph *graph = customPlot->addGraph();
graph->setData(x, y);
graph->setPen(QPen(Qt::blue));
graph->rescaleKeyAxis();
customPlot->yAxis->setRange(-1.45, 1.65);
customPlot->xAxis->setRange(1,500);
customPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen);
}
void PlotWidget::appentDataDisplaySlot(double yValue)
{
double secs = QCPAxisTickerDateTime::dateTimeToKey(QDateTime::currentDateTime());
if(0!=xNum)
{
y.append(yValue);
x.insert(0,xNum);
xNum--;
}
else
{
y.remove(0);
y.append(yValue);
}
ui->customPlot->graph()->setData(x,y);
ui->customPlot->replot();
// calculate frames per second:
// double key = secs;
// static double lastFpsKey;
// static int frameCount;
// ++frameCount;
// if (key-lastFpsKey > 2) // average fps over 2 seconds
// {
// ui->statusBar->showMessage(
// QString("%1 FPS, Total Data points: %2")
// .arg(frameCount/(key-lastFpsKey), 0, 'f', 0)
// .arg(ui->customPlot->graph(0)->data()->size())
// , 0);
// lastFpsKey = key;
// frameCount = 0;
// }
}
PlotWidget::~PlotWidget()
{
delete ui;
}
void PlotWidget::setPlotDataCount(int value)
{
n = value;
}