1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-03 11:24:10 +01:00

Added zoom functionality to scopes. There is a minor bias error when zooming with the legends activated.

This is due principally to the fact that retreiving the Qt coordinate in the frame
references to a slightly different system from Qwt invTranformation when the
legend is active.
This commit is contained in:
Laura Sebesta 2012-05-25 00:48:58 +03:00
parent 534559680b
commit 423e287494

View File

@ -51,6 +51,7 @@
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton> #include <QtGui/QPushButton>
#include <QMutexLocker> #include <QMutexLocker>
#include <QWheelEvent>
//using namespace Core; //using namespace Core;
@ -65,8 +66,8 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
replotTimer = new QTimer(this); replotTimer = new QTimer(this);
connect(replotTimer, SIGNAL(timeout()), this, SLOT(replotNewData())); connect(replotTimer, SIGNAL(timeout()), this, SLOT(replotNewData()));
// Listen to telemetry connection/disconnection events, no point // Listen to telemetry connection/disconnection events, no point in
// running the scopes if we are not connected and not replaying logs // running the scopes if we are not connected and not replaying logs.
// Also listen to disconnect actions from the user // Also listen to disconnect actions from the user
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(stopPlotting())); connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(stopPlotting()));
@ -124,12 +125,17 @@ void ScopeGadgetWidget::mouseReleaseEvent(QMouseEvent *e)
void ScopeGadgetWidget::mouseDoubleClickEvent(QMouseEvent *e) void ScopeGadgetWidget::mouseDoubleClickEvent(QMouseEvent *e)
{ {
//On double-click, toggle legend
mutex.lock(); mutex.lock();
if (legend()) if (legend())
deleteLegend(); deleteLegend();
else else
addLegend(); addLegend();
mutex.unlock(); mutex.unlock();
//On double-click, reset plot zoom
setAxisAutoScale(QwtPlot::yLeft, true);
update(); update();
QwtPlot::mouseDoubleClickEvent(e); QwtPlot::mouseDoubleClickEvent(e);
@ -142,6 +148,33 @@ void ScopeGadgetWidget::mouseMoveEvent(QMouseEvent *e)
void ScopeGadgetWidget::wheelEvent(QWheelEvent *e) void ScopeGadgetWidget::wheelEvent(QWheelEvent *e)
{ {
//Change zoom on scroll wheel event
QwtInterval yInterval=axisInterval(QwtPlot::yLeft);
if (yInterval.minValue() != yInterval.maxValue()) //Make sure that the two values are never the same. Sometimes axisInterval returns (0,0)
{
//Determine what y value to zoom about. NOTE, this approach has a bug that the in that
//the value returned by Qt includes the legend, whereas the value transformed by Qwt
//does *not*. Thus, when zooming with a legend, there will always be a small bias error.
//In practice, this seems not to be a UI problem.
QPoint mouse_pos=e->pos(); //Get the mouse coordinate in the frame
double zoomLine=invTransform(QwtPlot::yLeft, mouse_pos.y()); //Transform the y mouse coordinate into a frame value.
double zoomScale=1.1; //THIS IS AN ARBITRARY CONSTANT, AND PERHAPS SHOULD BE IN A DEFINE INSTEAD OF BURIED HERE
mutex.lock(); //DOES THIS mutex.lock NEED TO BE HERE? I DON'T KNOW, I JUST COPIED IT FROM THE ABOVE CODE
// Set the scale
if (e->delta()<0){
setAxisScale(QwtPlot::yLeft,
(yInterval.minValue()-zoomLine)*zoomScale+zoomLine,
(yInterval.maxValue()-zoomLine)*zoomScale+zoomLine );
}
else{
setAxisScale(QwtPlot::yLeft,
(yInterval.minValue()-zoomLine)/zoomScale+zoomLine,
(yInterval.maxValue()-zoomLine)/zoomScale+zoomLine );
}
mutex.unlock();
}
QwtPlot::wheelEvent(e); QwtPlot::wheelEvent(e);
} }
@ -412,7 +445,7 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField
//Keep the curve details for later //Keep the curve details for later
m_curvesData.insert(curveNameScaled, plotData); m_curvesData.insert(curveNameScaled, plotData);
//Link to the signal of new data only if this UAVObject has not been to connected yet //Link to the new signal data only if this UAVObject has not been connected yet
if (!m_connectedUAVObjects.contains(obj->getName())) { if (!m_connectedUAVObjects.contains(obj->getName())) {
m_connectedUAVObjects.append(obj->getName()); m_connectedUAVObjects.append(obj->getName());
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(uavObjectReceived(UAVObject*))); connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(uavObjectReceived(UAVObject*)));
@ -470,6 +503,7 @@ void ScopeGadgetWidget::replotNewData()
replot(); replot();
} }
/*
void ScopeGadgetWidget::setupExamplePlot() void ScopeGadgetWidget::setupExamplePlot()
{ {
preparePlot(SequentialPlot); preparePlot(SequentialPlot);
@ -514,6 +548,7 @@ void ScopeGadgetWidget::setupExamplePlot()
replot(); replot();
mutex.unlock(); mutex.unlock();
} }
*/
void ScopeGadgetWidget::clearCurvePlots() void ScopeGadgetWidget::clearCurvePlots()
{ {