try to catch wheel event
This commit is contained in:
parent
1dd49f23f8
commit
e65decc86a
12
chart.cpp
12
chart.cpp
@ -12,6 +12,9 @@ Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
|
||||
// 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);
|
||||
}
|
||||
|
||||
Chart::~Chart() {
|
||||
@ -21,6 +24,9 @@ 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;
|
||||
|
||||
return QChart::event(event);
|
||||
}
|
||||
|
||||
@ -38,6 +44,12 @@ bool Chart::gestureEvent(QGestureEvent *event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Chart::wheelEvent(QGraphicsSceneWheelEvent *event) {
|
||||
std::cerr << "chart: Wheel!";
|
||||
|
||||
QChart::wheelEvent(event);
|
||||
}
|
||||
|
||||
void Chart::XRangeChanged(qreal min, qreal max) {
|
||||
std::cerr << "XRangeChanged" << min << "\t"<< max << std::endl;
|
||||
if (series().at(0)->type() == QtCharts::QAbstractSeries::SeriesTypeLine) {
|
||||
|
2
chart.h
2
chart.h
@ -16,7 +16,7 @@ public:
|
||||
explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
|
||||
~Chart();
|
||||
|
||||
protected:
|
||||
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
bool sceneEvent(QEvent *event);
|
||||
|
||||
private:
|
||||
|
@ -1,12 +1,13 @@
|
||||
#include "chartview.h"
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <iostream>
|
||||
ChartView::ChartView(QChart *chart, QWidget *parent) :
|
||||
QChartView(chart, parent),
|
||||
m_isTouching(false)
|
||||
{
|
||||
setRubberBand(QChartView::RectangleRubberBand);
|
||||
setContentsMargins(0,0,0,0);
|
||||
}
|
||||
|
||||
|
||||
@ -23,12 +24,19 @@ bool ChartView::viewportEvent(QEvent *event)
|
||||
// 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)
|
||||
return;
|
||||
QChartView::mousePressEvent(event);
|
||||
|
@ -17,6 +17,7 @@ protected:
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void wheelEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
bool m_isTouching;
|
||||
|
@ -13,8 +13,9 @@ MultiChartView::MultiChartView(DataQueue *queue, QWidget *parent) :
|
||||
xRangeMin = 0.0;
|
||||
connect(dataQueue, SIGNAL(resultReady(QString)), this, SLOT(dataReady(QString)));
|
||||
//connect(&dataQueue, SIGNAL(finished()), &dataQueue, SLOT(deleteLater()));
|
||||
|
||||
|
||||
labelFont = QFont("Sans", 10);
|
||||
tickLabelFont = QFont("Sans", 7);
|
||||
setContentsMargins(QMargins(0,0,0,0));
|
||||
}
|
||||
|
||||
MultiChartView::~MultiChartView()
|
||||
@ -35,8 +36,6 @@ void MultiChartView::addArray(const nix::DataArray &array) {
|
||||
while (dataQueue->isRunning()){
|
||||
// uncool!!!
|
||||
}
|
||||
|
||||
|
||||
this->arrayMap.insert(std::pair<std::string, nix::DataArray>(array.id(), array));
|
||||
ArrayInfo ai(array);
|
||||
this->infoMap.insert(std::pair<std::string, ArrayInfo*>(ai.arrayid, &ai));
|
||||
@ -61,10 +60,30 @@ void MultiChartView::addArray(const nix::DataArray &array) {
|
||||
|
||||
Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
||||
Chart *chart = new Chart();
|
||||
chart->setTitle(QString::fromStdString(arrayMap.at(info.arrayid).name()));
|
||||
//chart->setTitle(QString::fromStdString(info.name));
|
||||
chart->setToolTip(QString::fromStdString(info.name));
|
||||
chart->legend()->hide();
|
||||
chart->createDefaultAxes();
|
||||
|
||||
QValueAxis *axisY = new QValueAxis;
|
||||
axisY->setTickCount(10);
|
||||
axisY->applyNiceNumbers();
|
||||
axisY->setTitleText(QString::fromStdString(info.ylabel));
|
||||
axisY->setTitleFont(labelFont);
|
||||
axisY->setLabelsFont(tickLabelFont);
|
||||
chart->setAxisY(axisY);
|
||||
|
||||
QValueAxis *axisX = new QValueAxis;
|
||||
axisX->setRange(info.xoffset, info.xmax);
|
||||
axisX->setTickCount(10);
|
||||
axisX->setLabelFormat("%.4f");
|
||||
axisX->setTitleFont(labelFont);
|
||||
axisX->setTitleText(QString::fromStdString(info.xlabel));
|
||||
axisX->setLabelsFont(tickLabelFont);
|
||||
axisX->applyNiceNumbers();
|
||||
chart->setAxisX(axisX);
|
||||
connect(axisX, SIGNAL(rangeChanged(qreal,qreal)), chart, SLOT(XRangeChanged(qreal,qreal)));
|
||||
|
||||
this->chartMap.insert(std::pair<std::string, Chart*>(info.arrayid, chart));
|
||||
return chart;
|
||||
}
|
||||
@ -73,6 +92,7 @@ ChartView* MultiChartView::createChartView(Chart *chart, const ArrayInfo &info)
|
||||
ChartView *view = new ChartView(chart);
|
||||
view->setLineWidth(1);
|
||||
view->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
/*
|
||||
QMargins margins = voltageChart->margins();
|
||||
int marg1 = margins.left();
|
||||
@ -110,21 +130,15 @@ void MultiChartView::dataConverted(QLineSeries *series, QString entityId, double
|
||||
series->setUseOpenGL(true);
|
||||
chart->addSeries(series);
|
||||
|
||||
QValueAxis *axisY = new QValueAxis;
|
||||
double range = ymax - ymin;
|
||||
axisY->setRange(ymin - 0.2 * range, ymax + 0.2 * range);
|
||||
axisY->setTickCount(10);
|
||||
axisY->applyNiceNumbers();
|
||||
axisY->setTitleText("Test");
|
||||
chart->setAxisY(axisY, series);
|
||||
|
||||
QValueAxis *axisX = new QValueAxis;
|
||||
axisX->setRange(series->at(0).x(), series->at(series->count()-1).x());
|
||||
axisX->setTickCount(10);
|
||||
axisX->setLabelFormat("%.4f");
|
||||
axisX->applyNiceNumbers();
|
||||
chart->setAxisX(axisX, series);
|
||||
connect(axisX, SIGNAL(rangeChanged(qreal,qreal)), chart, SLOT(XRangeChanged(qreal,qreal)));
|
||||
if (chart->axisX()->type() == QAbstractAxis::AxisTypeValue) {
|
||||
QValueAxis *axisX = static_cast<QValueAxis*>(chart->axisX());
|
||||
axisX->setRange(series->at(0).x(), series->at(series->count()-1).x());
|
||||
}
|
||||
if (chart->axisY()->type() == QAbstractAxis::AxisTypeValue) {
|
||||
QValueAxis *axisY = static_cast<QValueAxis*>(chart->axisY());
|
||||
double range = ymax - ymin;
|
||||
axisY->setRange(ymin - 0.2 * range, ymax + 0.2 * range);
|
||||
}
|
||||
|
||||
QPen pen = series->pen();
|
||||
pen.setWidth(1);
|
||||
|
@ -20,26 +20,38 @@ struct ArrayInfo {
|
||||
xDim = guessBestXdim(array);
|
||||
nix::Dimension d = array.getDimension(xDim);
|
||||
dimType = d.dimensionType();
|
||||
|
||||
xlabel = "";
|
||||
if (dimType == nix::DimensionType::Sample) {
|
||||
nix::SampledDimension sd = d.asSampledDimension();
|
||||
xoffset = sd.offset() ? *sd.offset() : 0.0;
|
||||
sampleinterval = sd.samplingInterval();
|
||||
xmax = dataExtent[xDim - 1] * sampleinterval + xoffset;
|
||||
xlabel = sd.label() ? *sd.label() : "";
|
||||
xlabel += sd.unit() ? " [" + *sd.unit() + "]" : "";
|
||||
|
||||
} else if (dimType == nix::DimensionType::Range) {
|
||||
nix::RangeDimension rd = d.asRangeDimension();
|
||||
tics = rd.ticks();
|
||||
xoffset = tics.front();
|
||||
xmax = tics.back();
|
||||
sampleinterval = 0.0;
|
||||
xlabel = rd.label() ? *rd.label() : "";
|
||||
xlabel += rd.unit() ? " [" + *rd.unit() + "]" : "";
|
||||
} else { // SetDimension
|
||||
xoffset = 0.0;
|
||||
xmax = dataExtent[xDim - 1];
|
||||
sampleinterval = 1.0;
|
||||
}
|
||||
name = array.name();
|
||||
ylabel = array.label() ? *array.label() : "";
|
||||
ylabel += array.unit() ? " [" + *array.unit() + "]" : "";
|
||||
|
||||
}
|
||||
|
||||
std::string arrayid;
|
||||
std::string name;
|
||||
std::string ylabel;
|
||||
std::string xlabel;
|
||||
int xDim;
|
||||
nix::DimensionType dimType;
|
||||
double xoffset, xmax, sampleinterval;
|
||||
@ -101,6 +113,7 @@ private:
|
||||
std::map<std::string, Chart*> chartMap;
|
||||
std::map<std::string, ChartView*> viewMap;
|
||||
std::map<std::string, ArrayInfo*> infoMap;
|
||||
QFont labelFont, tickLabelFont;
|
||||
|
||||
Chart* createChart(const ArrayInfo &info);
|
||||
ChartView* createChartView(Chart *chart, const ArrayInfo &info);
|
||||
|
@ -13,9 +13,34 @@
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="vBox"/>
|
||||
<layout class="QVBoxLayout" name="vBox">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QScrollBar" name="scrollBar">
|
||||
|
Loading…
Reference in New Issue
Block a user