b
This commit is contained in:
@@ -8,9 +8,58 @@ Scope::Scope(QWidget *parent) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
||||||
virtualscope = new VirtualScope(this);
|
chartView = new QChartView(this);
|
||||||
virtualscope->setGeometry(ui->frame->geometry());
|
series = new QLineSeries(this);
|
||||||
virtualscope->show();
|
|
||||||
|
chartView->setRenderHint(QPainter::Antialiasing);
|
||||||
|
chartView->chart()->legend()->setAlignment(Qt::AlignRight);
|
||||||
|
chartView->chart()->legend()->setMarkerShape(QLegend::MarkerShapeCircle);
|
||||||
|
chartView->chart()->legend()->setColor(Qt::yellow);
|
||||||
|
|
||||||
|
|
||||||
|
series->setName("123");
|
||||||
|
|
||||||
|
chartView->chart()->createDefaultAxes();
|
||||||
|
|
||||||
|
QPen pen(Qt::yellow);
|
||||||
|
pen.setWidth(2);
|
||||||
|
series->setPen(pen);
|
||||||
|
|
||||||
|
series->append(0, 0);
|
||||||
|
series->append(1, -4);
|
||||||
|
series->append(2, 5);
|
||||||
|
series->append(3, 6);
|
||||||
|
series->append(4, 2);
|
||||||
|
series->append(5, 9);
|
||||||
|
series->append(6, -0);
|
||||||
|
series->append(7, 4);
|
||||||
|
series->append(8, 4);
|
||||||
|
series->append(9, -5);
|
||||||
|
series->append(10, 6);
|
||||||
|
series->append(11, 2);
|
||||||
|
series->append(12, 9);
|
||||||
|
series->append(13, 0);
|
||||||
|
series->append(14, -4);
|
||||||
|
series->append(16, 4);
|
||||||
|
series->append(18, 5);
|
||||||
|
series->append(19, -6);
|
||||||
|
series->append(20, 2);
|
||||||
|
series->append(21, 9);
|
||||||
|
series->append(22, 0);
|
||||||
|
series->append(23, 4);
|
||||||
|
|
||||||
|
chartView->chart()->addSeries(series);
|
||||||
|
|
||||||
|
QValueAxis *axisX = new QValueAxis(this);
|
||||||
|
axisX->setRange(0, 1);
|
||||||
|
axisX->setTickCount(11);
|
||||||
|
axisX->setLabelFormat("%.2f");
|
||||||
|
chartView->chart()->setAxisX(axisX, series);
|
||||||
|
|
||||||
|
chartView->setGeometry(ui->frame->geometry());
|
||||||
|
|
||||||
|
QTimer::singleShot(10,this,SLOT(timeout()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Scope::~Scope()
|
Scope::~Scope()
|
||||||
@@ -18,19 +67,56 @@ Scope::~Scope()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scope::mouseReleaseEvent(QMouseEvent *e)
|
||||||
|
{
|
||||||
|
qDebug() << "Scope release" << e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scope::mousePressEvent(QMouseEvent *e)
|
||||||
|
{
|
||||||
|
qDebug() << "Scope press" << e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scope::mouseDoubleClickEvent(QMouseEvent *e)
|
||||||
|
{
|
||||||
|
qDebug() << "Scope double clicked" << e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scope::wheelEvent(QWheelEvent *e)
|
||||||
|
{
|
||||||
|
//改变是range
|
||||||
|
|
||||||
|
qDebug() << "Scope wheel" << e;
|
||||||
|
chartView->chart()->scroll(e->angleDelta().y(),0);
|
||||||
|
}
|
||||||
|
|
||||||
void Scope::resizeEvent(QResizeEvent *event)
|
void Scope::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
chartView->setGeometry(ui->frame->geometry());
|
||||||
virtualscope->setGeometry(ui->frame->geometry());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scope::timeout(void)
|
||||||
|
{
|
||||||
|
chartUpdate();
|
||||||
|
|
||||||
|
QTimer::singleShot(10,this,SLOT(timeout()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scope::chartUpdate(void)
|
||||||
|
{
|
||||||
|
//分别读取每个序列的一个数据
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//增加到新的数据 里面
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//滚动显示器
|
||||||
|
}
|
||||||
|
|
||||||
|
//void Scope::addSeries(void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,22 @@
|
|||||||
#define SCOPE_H
|
#define SCOPE_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "VirtualScope.h"
|
#include "QDebug"
|
||||||
|
|
||||||
|
#include "QTimer"
|
||||||
|
|
||||||
|
#include "QChart"
|
||||||
|
#include <QChartView>
|
||||||
|
#include <QLineSeries>
|
||||||
|
#include <QValueAxis>
|
||||||
|
|
||||||
|
using namespace QtCharts;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Scope;
|
class Scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Scope : public QWidget
|
class Scope : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -18,13 +28,22 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event);
|
void mouseReleaseEvent(QMouseEvent *e);
|
||||||
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
void mouseDoubleClickEvent(QMouseEvent *e);
|
||||||
|
void wheelEvent(QWheelEvent *e);
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void timeout(void);
|
||||||
|
void chartUpdate(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Scope *ui;
|
Ui::Scope *ui;
|
||||||
|
|
||||||
VirtualScope *virtualscope = nullptr;
|
QChartView *chartView;
|
||||||
|
QLineSeries *series;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
QT += charts
|
||||||
|
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
$$PWD/ScopeRes.qrc
|
$$PWD/ScopeRes.qrc
|
||||||
|
|
||||||
@@ -7,12 +10,10 @@ FORMS += \
|
|||||||
$$PWD/Scope.ui
|
$$PWD/Scope.ui
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/Scope.h \
|
$$PWD/Scope.h
|
||||||
$$PWD/VirtualScope.h
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/Scope.cpp \
|
$$PWD/Scope.cpp
|
||||||
$$PWD/VirtualScope.cpp
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,19 @@
|
|||||||
<property name="frameShadow">
|
<property name="frameShadow">
|
||||||
<enum>QFrame::Raised</enum>
|
<enum>QFrame::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>430</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>201</width>
|
||||||
|
<height>161</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>PushButton</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user