Compare commits
No commits in common. "166cc4357c8ccd6c2855012734d092342b63e640" and "1579e3832280752fcd2225503baa86b98bb665c6" have entirely different histories.
166cc4357c
...
1579e38322
11
scope.cpp
11
scope.cpp
|
@ -3,9 +3,11 @@
|
||||||
#include <QValueAxis>
|
#include <QValueAxis>
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QChartView>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
|
|
||||||
Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow *parent) : QMainWindow(parent){
|
Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow *parent) : QMainWindow(parent){
|
||||||
this->digi = digi;
|
this->digi = digi;
|
||||||
this->nDigi = nDigi;
|
this->nDigi = nDigi;
|
||||||
|
@ -17,11 +19,11 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
|
||||||
|
|
||||||
allowChange = false;
|
allowChange = false;
|
||||||
|
|
||||||
plot = new Trace();
|
plot = new QChart();
|
||||||
for( int i = 0; i < 6; i++) {
|
for( int i = 0; i < 6; i++) {
|
||||||
dataTrace[i] = new QLineSeries();
|
dataTrace[i] = new QLineSeries();
|
||||||
dataTrace[i]->setName("Trace " + QString::number(i));
|
dataTrace[i]->setName("Trace " + QString::number(i));
|
||||||
for(int j = 0; j < 100; j ++) dataTrace[i]->append(40*j, QRandomGenerator::global()->bounded(8000) + 8000);
|
for(int j = 0; j < 100; j ++) dataTrace[i]->append(j, QRandomGenerator::global()->bounded(8000) + 8000);
|
||||||
plot->addSeries(dataTrace[i]);
|
plot->addSeries(dataTrace[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +34,6 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
|
||||||
dataTrace[4]->setPen(QPen(Qt::darkGreen, 1));
|
dataTrace[4]->setPen(QPen(Qt::darkGreen, 1));
|
||||||
dataTrace[5]->setPen(QPen(Qt::darkBlue, 1));
|
dataTrace[5]->setPen(QPen(Qt::darkBlue, 1));
|
||||||
|
|
||||||
plot->setAnimationOptions(QChart::SeriesAnimations);
|
|
||||||
plot->createDefaultAxes(); /// this must be after addSeries();
|
plot->createDefaultAxes(); /// this must be after addSeries();
|
||||||
/// this must be after createDefaultAxes();
|
/// this must be after createDefaultAxes();
|
||||||
QValueAxis * yaxis = qobject_cast<QValueAxis*> (plot->axes(Qt::Vertical).first());
|
QValueAxis * yaxis = qobject_cast<QValueAxis*> (plot->axes(Qt::Vertical).first());
|
||||||
|
@ -319,10 +320,12 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
|
||||||
|
|
||||||
//------------ plot view
|
//------------ plot view
|
||||||
rowID ++;
|
rowID ++;
|
||||||
TraceView * plotView = new TraceView(plot);
|
QChartView * plotView = new QChartView(plot);
|
||||||
plotView->setRenderHints(QPainter::Antialiasing);
|
plotView->setRenderHints(QPainter::Antialiasing);
|
||||||
layout->addWidget(plotView, rowID, 0, 1, 6);
|
layout->addWidget(plotView, rowID, 0, 1, 6);
|
||||||
|
|
||||||
|
//TODO zoom and pan, see Zoom Line example
|
||||||
|
|
||||||
//------------ close button
|
//------------ close button
|
||||||
rowID ++;
|
rowID ++;
|
||||||
bnScopeStart = new QPushButton("Start", this);
|
bnScopeStart = new QPushButton("Start", this);
|
||||||
|
|
83
scope.h
83
scope.h
|
@ -4,99 +4,16 @@
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QChart>
|
#include <QChart>
|
||||||
#include <QChartView>
|
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLineSeries>
|
#include <QLineSeries>
|
||||||
#include <QRubberBand>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QGestureEvent>
|
|
||||||
|
|
||||||
#include "ClassDigitizer2Gen.h"
|
#include "ClassDigitizer2Gen.h"
|
||||||
#include "manyThread.h"
|
#include "manyThread.h"
|
||||||
|
|
||||||
class Trace : public QChart{
|
|
||||||
public:
|
|
||||||
explicit Trace(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {})
|
|
||||||
: QChart(QChart::ChartTypeCartesian, parent, wFlags){
|
|
||||||
grabGesture(Qt::PanGesture);
|
|
||||||
grabGesture(Qt::PinchGesture);
|
|
||||||
}
|
|
||||||
~Trace(){}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool sceneEvent(QEvent *event){
|
|
||||||
if (event->type() == QEvent::Gesture) return gestureEvent(static_cast<QGestureEvent *>(event));
|
|
||||||
return QChart::event(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool gestureEvent(QGestureEvent *event){
|
|
||||||
if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
|
|
||||||
QPanGesture *pan = static_cast<QPanGesture *>(gesture);
|
|
||||||
QChart::scroll(-(pan->delta().x()), pan->delta().y());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
|
|
||||||
QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
|
|
||||||
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) QChart::zoom(pinch->scaleFactor());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class TraceView : public QChartView{
|
|
||||||
public:
|
|
||||||
TraceView(QChart * chart, QWidget * parent = nullptr): QChartView(chart, parent){
|
|
||||||
m_isTouching = false;
|
|
||||||
this->setRubberBand(QChartView::RectangleRubberBand);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool viewportEvent(QEvent *event){
|
|
||||||
if (event->type() == QEvent::TouchBegin) {
|
|
||||||
m_isTouching = true;
|
|
||||||
chart()->setAnimationOptions(QChart::NoAnimation);
|
|
||||||
}
|
|
||||||
return QChartView::viewportEvent(event);
|
|
||||||
}
|
|
||||||
void mousePressEvent(QMouseEvent *event){
|
|
||||||
if (m_isTouching) return;
|
|
||||||
QChartView::mousePressEvent(event);
|
|
||||||
}
|
|
||||||
void mouseMoveEvent(QMouseEvent *event){
|
|
||||||
if (m_isTouching) return;
|
|
||||||
QChartView::mouseMoveEvent(event);
|
|
||||||
}
|
|
||||||
void mouseReleaseEvent(QMouseEvent *event){
|
|
||||||
if (m_isTouching) m_isTouching = false;
|
|
||||||
chart()->setAnimationOptions(QChart::SeriesAnimations);
|
|
||||||
QChartView::mouseReleaseEvent(event);
|
|
||||||
}
|
|
||||||
void keyPressEvent(QKeyEvent *event){
|
|
||||||
switch (event->key()) {
|
|
||||||
case Qt::Key_Plus: chart()->zoomIn(); break;
|
|
||||||
case Qt::Key_Minus: chart()->zoomOut(); break;
|
|
||||||
case Qt::Key_Left: chart()->scroll(-10, 0); break;
|
|
||||||
case Qt::Key_Right: chart()->scroll(10, 0); break;
|
|
||||||
case Qt::Key_Up: chart()->scroll(0, 10); break;
|
|
||||||
case Qt::Key_Down: chart()->scroll(0, -10); break;
|
|
||||||
case Qt::Key_R : chart()->axes(Qt::Vertical).first()->setRange(-16384, 65536); break;
|
|
||||||
default: QGraphicsView::keyPressEvent(event); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_isTouching;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Scope : public QMainWindow{
|
class Scope : public QMainWindow{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user