pan and scrol works
This commit is contained in:
parent
e65decc86a
commit
af09e38132
23
chart.cpp
23
chart.cpp
@ -4,14 +4,13 @@
|
|||||||
#include <QtWidgets/QGraphicsView>
|
#include <QtWidgets/QGraphicsView>
|
||||||
#include <QLineSeries>
|
#include <QLineSeries>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QGraphicsSceneEvent>
|
||||||
|
|
||||||
Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
|
Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
|
||||||
: QChart(QChart::ChartTypeCartesian, parent, wFlags)
|
: QChart(QChart::ChartTypeCartesian, parent, wFlags)
|
||||||
{
|
{
|
||||||
// Seems that QGraphicsView (QChartView) does not grab gestures.
|
// Seems that QGraphicsView (QChartView) does not grab gestures.
|
||||||
// They can only be grabbed here in the QGraphicsWidget (QChart).
|
// They can only be grabbed here in the QGraphicsWidget (QChart).
|
||||||
grabGesture(Qt::PinchGesture);
|
|
||||||
grabGesture(Qt::PanGesture);
|
|
||||||
setContentsMargins(0, 0, 0, 0);
|
setContentsMargins(0, 0, 0, 0);
|
||||||
setMargins(QMargins(0,0,0,0));
|
setMargins(QMargins(0,0,0,0));
|
||||||
setBackgroundRoundness(0);
|
setBackgroundRoundness(0);
|
||||||
@ -24,9 +23,10 @@ Chart::~Chart() {
|
|||||||
bool Chart::sceneEvent(QEvent *event) {
|
bool Chart::sceneEvent(QEvent *event) {
|
||||||
if (event->type() == QEvent::Gesture)
|
if (event->type() == QEvent::Gesture)
|
||||||
return gestureEvent(static_cast<QGestureEvent *>(event));
|
return gestureEvent(static_cast<QGestureEvent *>(event));
|
||||||
std::cerr << "chart: Wheel!";
|
if (event->type() == QEvent::GraphicsSceneWheel) {
|
||||||
std::cerr << (event->type()) << std::endl;
|
QGraphicsSceneWheelEvent *swe = static_cast<QGraphicsSceneWheelEvent*>(event);
|
||||||
|
return myWheelEvent(swe);
|
||||||
|
}
|
||||||
return QChart::event(event);
|
return QChart::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,10 +44,15 @@ bool Chart::gestureEvent(QGestureEvent *event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chart::wheelEvent(QGraphicsSceneWheelEvent *event) {
|
bool Chart::myWheelEvent(QGraphicsSceneWheelEvent *event) {
|
||||||
std::cerr << "chart: Wheel!";
|
bool in = event->delta() > 0;
|
||||||
|
bool scale_x = event->scenePos().x() > this->geometry().right()/4;
|
||||||
QChart::wheelEvent(event);
|
QRectF view = plotArea();
|
||||||
|
qreal zoom = 0.1;
|
||||||
|
qreal dwidth = view.width() * (scale_x ? (in ? -1.0 : 1.0) * zoom/2 : 0.0);
|
||||||
|
qreal dheight = view.height() * (scale_x ? 0.0 : (in ? -1.0 : 1.0) * zoom/2);
|
||||||
|
view.adjust(dwidth/2, dheight/2, -1.0 * dwidth/2, -1.0 * dheight/2);
|
||||||
|
this->zoomIn(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chart::XRangeChanged(qreal min, qreal max) {
|
void Chart::XRangeChanged(qreal min, qreal max) {
|
||||||
|
2
chart.h
2
chart.h
@ -16,11 +16,11 @@ public:
|
|||||||
explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
|
explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
|
||||||
~Chart();
|
~Chart();
|
||||||
|
|
||||||
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
|
||||||
bool sceneEvent(QEvent *event);
|
bool sceneEvent(QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool gestureEvent(QGestureEvent *event);
|
bool gestureEvent(QGestureEvent *event);
|
||||||
|
bool myWheelEvent(QGraphicsSceneWheelEvent *event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void XRangeChanged(qreal min, qreal max);
|
void XRangeChanged(qreal min, qreal max);
|
||||||
|
@ -6,60 +6,39 @@ ChartView::ChartView(QChart *chart, QWidget *parent) :
|
|||||||
QChartView(chart, parent),
|
QChartView(chart, parent),
|
||||||
m_isTouching(false)
|
m_isTouching(false)
|
||||||
{
|
{
|
||||||
setRubberBand(QChartView::RectangleRubberBand);
|
|
||||||
setContentsMargins(0,0,0,0);
|
setContentsMargins(0,0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ChartView::viewportEvent(QEvent *event)
|
|
||||||
{
|
|
||||||
if (event->type() == QEvent::TouchBegin) {
|
|
||||||
// By default touch events are converted to mouse events. So
|
|
||||||
// after this event we will get a mouse event also but we want
|
|
||||||
// to handle touch events as gestures only. So we need this safeguard
|
|
||||||
// to block mouse events that are actually generated from touch.
|
|
||||||
m_isTouching = true;
|
|
||||||
|
|
||||||
// Turn off animations when handling gestures they
|
|
||||||
// will only slow us down.
|
|
||||||
chart()->setAnimationOptions(QChart::NoAnimation);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QChartView::viewportEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChartView::wheelEvent(QMouseEvent *event) {
|
|
||||||
std::cerr << "Mouse event" << std::endl;
|
|
||||||
std::cerr << event->type();
|
|
||||||
//QChartView::whwheelEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChartView::mousePressEvent(QMouseEvent *event)
|
void ChartView::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
std::cerr << "MousePress" << std::endl;
|
if (event->buttons() & Qt::LeftButton) {
|
||||||
if (m_isTouching)
|
mouseDownPos = event->localPos();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
QChartView::mousePressEvent(event);
|
QChartView::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ChartView::mouseMoveEvent(QMouseEvent *event)
|
void ChartView::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (m_isTouching)
|
if (event->buttons() & Qt::LeftButton) {
|
||||||
|
QPointF diff = mouseDownPos - event->localPos();
|
||||||
|
qreal dx = event->localPos().x() - mouseDownPos.x();
|
||||||
|
qreal dy = event->localPos().y() - mouseDownPos.y();
|
||||||
|
mouseDownPos = event->localPos();
|
||||||
|
chart()->scroll(-1.0*dx,dy);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QChartView::mouseMoveEvent(event);
|
QChartView::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ChartView::mouseReleaseEvent(QMouseEvent *event)
|
void ChartView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (m_isTouching)
|
if (event->buttons() & Qt::LeftButton)
|
||||||
m_isTouching = false;
|
mouseDown = false;
|
||||||
|
|
||||||
// Because we disabled animations when touch event was detected
|
|
||||||
// we must put them back on.
|
|
||||||
//chart()->setAnimationOptions(QChart::SeriesAnimations);
|
|
||||||
|
|
||||||
QChartView::mouseReleaseEvent(event);
|
QChartView::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,15 +12,15 @@ public:
|
|||||||
ChartView(QChart *chart, QWidget *parent = 0);
|
ChartView(QChart *chart, QWidget *parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool viewportEvent(QEvent *event);
|
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
void wheelEvent(QMouseEvent *event);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isTouching;
|
bool m_isTouching;
|
||||||
|
bool mouseDown;
|
||||||
|
QPointF mouseDownPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHARTVIEW_H
|
#endif // CHARTVIEW_H
|
||||||
|
@ -25,11 +25,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
DataLoader *loader = new DataLoader();
|
DataLoader *loader = new DataLoader();
|
||||||
loader->moveToThread(&dataQueue);
|
loader->moveToThread(&dataQueue);
|
||||||
dataQueue.start();
|
dataQueue.start();
|
||||||
file = nix::File::open("/home/grewe/zwischenlager/2017-08-17-af-invivo-1/2017-08-17-af-invivo-1.nix",
|
//file = nix::File::open("/home/grewe/zwischenlager/2017-08-17-af-invivo-1/2017-08-17-af-invivo-1.nix",
|
||||||
nix::FileMode::ReadOnly);
|
// nix::FileMode::ReadOnly);
|
||||||
|
|
||||||
//file = nix::File::open("/Users/jan/zwischenlager/threading_test/dataservice/data/2017-08-17-af-invivo-1.nix",
|
file = nix::File::open("/Users/jan/zwischenlager/threading_test/dataservice/data/2017-08-17-af-invivo-1.nix",
|
||||||
//nix::FileMode::ReadOnly);
|
nix::FileMode::ReadOnly);
|
||||||
nix::Block b = file.getBlock(0);
|
nix::Block b = file.getBlock(0);
|
||||||
this->voltage = b.getDataArray("V-1");
|
this->voltage = b.getDataArray("V-1");
|
||||||
this->eod = b.getDataArray("EOD");
|
this->eod = b.getDataArray("EOD");
|
||||||
|
Loading…
Reference in New Issue
Block a user