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 <QLineSeries>
|
||||
#include <iostream>
|
||||
#include <QGraphicsSceneEvent>
|
||||
|
||||
Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
|
||||
: QChart(QChart::ChartTypeCartesian, parent, wFlags)
|
||||
{
|
||||
// Seems that QGraphicsView (QChartView) does not grab gestures.
|
||||
// They can only be grabbed here in the QGraphicsWidget (QChart).
|
||||
grabGesture(Qt::PinchGesture);
|
||||
grabGesture(Qt::PanGesture);
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
setMargins(QMargins(0,0,0,0));
|
||||
setBackgroundRoundness(0);
|
||||
@ -24,9 +23,10 @@ Chart::~Chart() {
|
||||
bool Chart::sceneEvent(QEvent *event) {
|
||||
if (event->type() == QEvent::Gesture)
|
||||
return gestureEvent(static_cast<QGestureEvent *>(event));
|
||||
std::cerr << "chart: Wheel!";
|
||||
std::cerr << (event->type()) << std::endl;
|
||||
|
||||
if (event->type() == QEvent::GraphicsSceneWheel) {
|
||||
QGraphicsSceneWheelEvent *swe = static_cast<QGraphicsSceneWheelEvent*>(event);
|
||||
return myWheelEvent(swe);
|
||||
}
|
||||
return QChart::event(event);
|
||||
}
|
||||
|
||||
@ -44,10 +44,15 @@ bool Chart::gestureEvent(QGestureEvent *event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Chart::wheelEvent(QGraphicsSceneWheelEvent *event) {
|
||||
std::cerr << "chart: Wheel!";
|
||||
|
||||
QChart::wheelEvent(event);
|
||||
bool Chart::myWheelEvent(QGraphicsSceneWheelEvent *event) {
|
||||
bool in = event->delta() > 0;
|
||||
bool scale_x = event->scenePos().x() > this->geometry().right()/4;
|
||||
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) {
|
||||
|
2
chart.h
2
chart.h
@ -16,11 +16,11 @@ public:
|
||||
explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
|
||||
~Chart();
|
||||
|
||||
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
bool sceneEvent(QEvent *event);
|
||||
|
||||
private:
|
||||
bool gestureEvent(QGestureEvent *event);
|
||||
bool myWheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
|
||||
public slots:
|
||||
void XRangeChanged(qreal min, qreal max);
|
||||
|
@ -6,60 +6,39 @@ ChartView::ChartView(QChart *chart, QWidget *parent) :
|
||||
QChartView(chart, parent),
|
||||
m_isTouching(false)
|
||||
{
|
||||
setRubberBand(QChartView::RectangleRubberBand);
|
||||
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)
|
||||
{
|
||||
std::cerr << "MousePress" << std::endl;
|
||||
if (m_isTouching)
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
mouseDownPos = event->localPos();
|
||||
return;
|
||||
}
|
||||
QChartView::mousePressEvent(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;
|
||||
}
|
||||
|
||||
QChartView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void ChartView::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_isTouching)
|
||||
m_isTouching = false;
|
||||
|
||||
// Because we disabled animations when touch event was detected
|
||||
// we must put them back on.
|
||||
//chart()->setAnimationOptions(QChart::SeriesAnimations);
|
||||
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
mouseDown = false;
|
||||
QChartView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
|
@ -12,15 +12,15 @@ public:
|
||||
ChartView(QChart *chart, QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
bool viewportEvent(QEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void wheelEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
bool m_isTouching;
|
||||
bool mouseDown;
|
||||
QPointF mouseDownPos;
|
||||
};
|
||||
|
||||
#endif // CHARTVIEW_H
|
||||
|
@ -25,11 +25,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
DataLoader *loader = new DataLoader();
|
||||
loader->moveToThread(&dataQueue);
|
||||
dataQueue.start();
|
||||
file = nix::File::open("/home/grewe/zwischenlager/2017-08-17-af-invivo-1/2017-08-17-af-invivo-1.nix",
|
||||
nix::FileMode::ReadOnly);
|
||||
//file = nix::File::open("/home/grewe/zwischenlager/2017-08-17-af-invivo-1/2017-08-17-af-invivo-1.nix",
|
||||
// nix::FileMode::ReadOnly);
|
||||
|
||||
//file = nix::File::open("/Users/jan/zwischenlager/threading_test/dataservice/data/2017-08-17-af-invivo-1.nix",
|
||||
//nix::FileMode::ReadOnly);
|
||||
file = nix::File::open("/Users/jan/zwischenlager/threading_test/dataservice/data/2017-08-17-af-invivo-1.nix",
|
||||
nix::FileMode::ReadOnly);
|
||||
nix::Block b = file.getBlock(0);
|
||||
this->voltage = b.getDataArray("V-1");
|
||||
this->eod = b.getDataArray("EOD");
|
||||
|
Loading…
Reference in New Issue
Block a user