123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #include "scope.h"
- #include "ui_scope.h"
- #include <QGraphicsScene>
- #include <QValueAxis>
- #include <QLineSeries>
- #include <QChart>
- #include <QRandomGenerator>
- #include <QVector>
- scope::scope(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::scope)
- {
- ui->setupUi(this);
- QStandardItemModel* model = treeModel->tree_set();
- ui->tree_set->setModel(model);
- ui->tree_set->expandAll();
-
- connect(ui->tree_set, &QTreeView::clicked, this, &scope::handleTreeItemClicked);
- }
- scope::~scope()
- {
- delete ui;
- }
- void scope::setTreeModel(tree_model_set* model)
- {
- treeModel = model;
- }
- void scope::handleTreeItemClicked(const QModelIndex &index) {
-
- emit treeItemClicked(index);
- }
- void scope::Chart_Init()
- {
-
- chart = new QChart();
-
- lineSeries = new QSplineSeries();
-
- lineSeries->setName("测试曲线");
-
- chart->addSeries(lineSeries);
-
- QValueAxis *axisX = new QValueAxis();
- QValueAxis *axisY = new QValueAxis();
-
- axisX->setMin(0);
- axisX->setMax(MAX_X);
- axisY->setMin(-1.5);
- axisY->setMax(MAX_Y);
-
- axisX->setTickCount(10);
- axisY->setTickCount(10);
-
- QFont font("Microsoft YaHei",8,QFont::Normal);
- axisX->setTitleFont(font);
- axisY->setTitleFont(font);
- axisX->setTitleText("X-Test");
- axisY->setTitleText("Y-Test");
-
- axisY->setGridLineVisible(false);
-
-
- chart->addAxis(axisX, Qt::AlignBottom);
- chart->addAxis(axisY, Qt::AlignLeft);
-
- lineSeries->attachAxis(axisX);
- lineSeries->attachAxis(axisY);
-
- ui->gra_scope11->setChart(chart);
- ui->gra_scope11->setRenderHint(QPainter::Antialiasing);
- }
- void scope::DrawLine(float value)
- {
-
-
-
-
-
-
-
-
-
-
- lineSeries->append(count, value);
- chart->axisX()->setRange(0, count);
- count++;
-
- }
- QVector<QPointF> scope::generateRandomData(int pointCount) {
- QVector<QPointF> data;
- for (int i = 0; i < pointCount; ++i) {
- qreal x = i;
- qreal y = QRandomGenerator::global()->bounded(0, 100);
- data.append(QPointF(x, y));
- }
- return data;
- }
- void scope::on_pushButton_clicked()
- {
- lineSeries->clear();
- chart->axisX()->setRange(0, 0);
- chart->axisY()->setRange(-1.5, 1.5);
- count=0;
- }
|