SocExplorerPlot.cpp
669 lines
| 18.0 KiB
| text/x-c
|
CppLexer
/ src / SocExplorerPlot.cpp
r0 | /*------------------------------------------------------------------------------ | |||
-- This file is a part of the QLop Software | ||||
-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 2 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@member.fsf.org | ||||
----------------------------------------------------------------------------*/ | ||||
#include "SocExplorerPlot.h" | ||||
r5 | #include <QSvgGenerator> | |||
#include <qcpdocumentobject.h> | ||||
#include <QPdfWriter> | ||||
#include <QPrinter> | ||||
r0 | ||||
SocExplorerPlot::SocExplorerPlot(QWidget *parent) : | ||||
r2 | QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this)) | |||
r0 | { | |||
r7 | this->m_plot = new QCustomPlotVect(this); | |||
r1 | this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | | |||
QCP::iSelectLegend | QCP::iSelectPlottables); | ||||
this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical); | ||||
this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); | ||||
this->m_mainlayout = new QGridLayout(this); | ||||
this->setLayout(this->m_mainlayout); | ||||
this->m_mainlayout->addWidget(this->m_plot); | ||||
this->setMinimumSize(400,300); | ||||
this->setFocusPolicy(Qt::WheelFocus); | ||||
this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); | ||||
this->ctrl_hold = false; | ||||
this->shift_hold = false; | ||||
this->mouse_hold = false; | ||||
this->m_plot->setNoAntialiasingOnDrag(true); | ||||
this->show(); | ||||
this->m_plot->legend->setVisible(true); | ||||
r0 | } | |||
r2 | SocExplorerPlot::~SocExplorerPlot() | |||
{ | ||||
delete mRubberBand; | ||||
} | ||||
r0 | void SocExplorerPlot::show() | |||
{ | ||||
QWidget::show(); | ||||
} | ||||
void SocExplorerPlot::replot() | ||||
{ | ||||
r5 | this->m_plot->replot(); | |||
} | ||||
void SocExplorerPlot::exportToSVG(const QString &fileName) | ||||
{ | ||||
QSvgGenerator printer; | ||||
printer.setFileName(fileName); | ||||
QCPPainter qcpPainter; | ||||
qcpPainter.begin(&printer); | ||||
m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height()); | ||||
qcpPainter.end(); | ||||
} | ||||
void SocExplorerPlot::exportToPDF(const QString &fileName) | ||||
{ | ||||
r6 | QPrinter printer(QPrinter::HighResolution); | |||
printer.setOutputFormat(QPrinter::PdfFormat); | ||||
printer.setOrientation(QPrinter::Landscape); | ||||
printer.setOutputFileName(fileName); | ||||
printer.setFullPage(true); | ||||
QCPPainter qcpPainter; | ||||
qcpPainter.begin(&printer); | ||||
m_plot->toPainter(&qcpPainter, printer.width(), printer.height()); | ||||
qcpPainter.end(); | ||||
r0 | } | |||
r7 | void SocExplorerPlot::addAction(SocExplorerPlotActions *action) | |||
{ | ||||
this->m_actions.append(action); | ||||
QWidget::addAction((QAction*)action); | ||||
} | ||||
QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex) | ||||
{ | ||||
r8 | QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData(); | |||
return visibleData; | ||||
r7 | } | |||
r0 | void SocExplorerPlot::setTitle(QString title) | |||
{ | ||||
r1 | Q_UNUSED(title) | |||
//this->m_plot->setTitle(title); | ||||
/*! | ||||
r0 | @todo Function borcken fixe this! | |||
*/ | ||||
r10 | this->m_Title = title; | |||
r6 | emit titleChanged(title); | |||
this->repaint(); | ||||
r0 | } | |||
r10 | const QString &SocExplorerPlot::title() | |||
{ | ||||
return m_Title; | ||||
} | ||||
r0 | void SocExplorerPlot::setXaxisLabel(QString label) | |||
{ | ||||
r1 | this->m_plot->xAxis->setLabel(label); | |||
r9 | this->repaint(); | |||
} | ||||
void SocExplorerPlot::setXaxisLog() | ||||
{ | ||||
this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic); | ||||
r0 | } | |||
void SocExplorerPlot::setYaxisLabel(QString label) | ||||
{ | ||||
r1 | this->m_plot->yAxis->setLabel(label); | |||
r9 | this->repaint(); | |||
} | ||||
void SocExplorerPlot::setYaxisLog() | ||||
{ | ||||
this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic); | ||||
r0 | } | |||
void SocExplorerPlot::setXaxisRange(double lower, double upper) | ||||
{ | ||||
r1 | this->m_plot->xAxis->setRange(lower,upper); | |||
r0 | } | |||
void SocExplorerPlot::setYaxisRange(double lower, double upper) | ||||
{ | ||||
r1 | this->m_plot->yAxis->setRange(lower,upper); | |||
r0 | } | |||
void SocExplorerPlot::rescaleAxis() | ||||
{ | ||||
r1 | this->m_plot->rescaleAxes(); | |||
this->m_plot->replot(); | ||||
r0 | } | |||
void SocExplorerPlot::setLegendFont(QFont font) | ||||
{ | ||||
r1 | this->m_plot->legend->setFont(font); | |||
this->repaint(); | ||||
r0 | } | |||
void SocExplorerPlot::setLegendSelectedFont(QFont font) | ||||
{ | ||||
r1 | this->m_plot->legend->setSelectedFont(font); | |||
this->repaint(); | ||||
r0 | } | |||
void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable) | ||||
{ | ||||
r1 | this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable); | |||
r0 | } | |||
r3 | void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable) | |||
{ | ||||
r7 | // TODO deprecated | |||
// this->m_plot->graph(graphIndex)->setUseFastVectors(enable); | ||||
r3 | } | |||
r0 | int SocExplorerPlot::addGraph() | |||
{ | ||||
r1 | this->m_plot->addGraph(); | |||
r0 | return this->m_plot->graphCount() -1; | |||
} | ||||
bool SocExplorerPlot::removeGraph(int graphIndex) | ||||
{ | ||||
r7 | return this->m_plot->removeGraph(graphIndex); | |||
} | ||||
int SocExplorerPlot::graphCount() | ||||
{ | ||||
return m_plot->graphCount(); | ||||
r0 | } | |||
void SocExplorerPlot::removeAllGraphs() | ||||
{ | ||||
int graphCount=this->m_plot->graphCount(); | ||||
for(int i=0;i<graphCount;i++) | ||||
{ | ||||
this->m_plot->removeGraph(0); | ||||
} | ||||
} | ||||
void SocExplorerPlot::setGraphName(int graphIndex,QString name) | ||||
{ | ||||
r1 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setName(name); | |||
r10 | } | |||
} | ||||
const QString &SocExplorerPlot::graphName(int graphIndex) | ||||
{ | ||||
if(graphIndex<this->m_plot->graphCount()) | ||||
{ | ||||
return this->m_plot->graph(graphIndex)->name(); | ||||
r0 | } | |||
r10 | return ""; | |||
r0 | } | |||
void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) | ||||
{ | ||||
r1 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double)) | |||
r0 | { | |||
r1 | QVector<double> _x(x.count()), _y(y.count()); | |||
for(int i=0;i<x.count();i++) | ||||
r0 | { | |||
r1 | /*_x[i] = x.at(i).value<double>(); | |||
r0 | _y[i] = y.at(i).value<double>();*/ | |||
r1 | _x[i] = x.at(i).toDouble(); | |||
_y[i] = y.at(i).toDouble(); | ||||
r0 | } | |||
r1 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |||
r0 | } | |||
r1 | else | |||
{ | ||||
if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime)) | ||||
r0 | { | |||
r1 | QVector<double> _x(x.count()), _y(y.count()); | |||
for(int i=0;i<x.count();i++) | ||||
r0 | { | |||
r1 | /*_x[i] = x.at(i).value<double>(); | |||
r0 | _y[i] = y.at(i).value<double>();*/ | |||
r1 | _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); | |||
_y[i] = y.at(i).toDouble(); | ||||
r0 | } | |||
r1 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |||
this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); | ||||
this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz"); | ||||
r0 | ||||
} | ||||
r1 | } | |||
this->m_plot->replot(); | ||||
r0 | } | |||
void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot) | ||||
{ | ||||
if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) | ||||
r1 | { | |||
r0 | this->m_plot->graph(graphIndex)->setData(data,copy); | |||
r1 | } | |||
r0 | if(replot) | |||
this->m_plot->replot(); | ||||
} | ||||
r3 | void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot) | |||
{ | ||||
if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) | ||||
{ | ||||
r7 | ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data); | |||
r3 | } | |||
if(replot) | ||||
this->m_plot->replot(); | ||||
} | ||||
r0 | void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) | |||
{ | ||||
r1 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) | |||
r0 | { | |||
r1 | QVector<double> _x(x.count()), _y(y.count()); | |||
for(int i=0;i<x.count();i++) | ||||
r0 | { | |||
r1 | /*_x[i] = x.at(i).value<double>(); | |||
r0 | _y[i] = y.at(i).value<double>();*/ | |||
r1 | _x[i] = x.at(i).toDouble(); | |||
_y[i] = y.at(i).toDouble(); | ||||
r0 | } | |||
r1 | this->m_plot->graph(graphIndex)->addData(_x,_y); | |||
r0 | } | |||
r1 | this->m_plot->replot(); | |||
r0 | } | |||
void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y) | ||||
{ | ||||
r1 | if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double)) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble()); | |||
r0 | } | |||
r1 | this->m_plot->replot(); | |||
r0 | } | |||
void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen) | ||||
{ | ||||
r1 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setPen(pen); | |||
r0 | } | |||
} | ||||
QPen SocExplorerPlot::getGraphPen(int graphIndex) | ||||
{ | ||||
r1 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r1 | return this->m_plot->graph(graphIndex)->pen(); | |||
r0 | } | |||
r1 | return this->m_plot->graph()->pen(); | |||
r0 | } | |||
void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle) | ||||
{ | ||||
r1 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r1 | if(!lineStyle.compare("none")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); | |||
return; | ||||
r0 | } | |||
r1 | if(!lineStyle.compare("line")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); | |||
return; | ||||
r0 | } | |||
r1 | if(!lineStyle.compare("stepleft")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); | |||
return; | ||||
r0 | } | |||
r1 | if(!lineStyle.compare("stepright")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); | |||
return; | ||||
r0 | } | |||
r1 | if(!lineStyle.compare("stepcenter")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); | |||
return; | ||||
r0 | } | |||
r1 | if(!lineStyle.compare("impulse")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); | |||
return; | ||||
r0 | } | |||
} | ||||
} | ||||
void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle) | ||||
{ | ||||
r1 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r1 | if(!scatterStyle.compare("none")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("dot")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("cross")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("plus")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("circle")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("disc")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("square")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("diamond")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("star")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("triangle")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("invertedtriangle")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("crosssquare")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("plussquare")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("crosscircle")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("pluscircle")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); | |||
return; | ||||
r0 | } | |||
r1 | if(!scatterStyle.compare("peace")) | |||
r0 | { | |||
r1 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); | |||
return; | ||||
r0 | } | |||
r1 | } | |||
r0 | } | |||
void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type) | ||||
{ | ||||
this->m_plot->xAxis->setTickLabelType(type); | ||||
} | ||||
void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format) | ||||
{ | ||||
this->m_plot->xAxis->setDateTimeFormat(format); | ||||
} | ||||
void SocExplorerPlot::keyPressEvent(QKeyEvent * event) | ||||
{ | ||||
r1 | switch(event->key()) | |||
r0 | { | |||
case Qt::Key_Control: | ||||
r1 | this->ctrl_hold = true; | |||
r2 | setCursor(Qt::CrossCursor); | |||
r1 | break; | |||
r0 | case Qt::Key_Shift: | |||
r1 | this->shift_hold = true; | |||
break; | ||||
r0 | case Qt::Key_M: | |||
r1 | this->rescaleAxis(); | |||
break; | ||||
case Qt::Key_Left: | ||||
if(!ctrl_hold) | ||||
{ | ||||
r2 | move(-0.1,Qt::Horizontal); | |||
r1 | } | |||
else | ||||
{ | ||||
zoom(2,this->width()/2,Qt::Horizontal); | ||||
} | ||||
break; | ||||
case Qt::Key_Right: | ||||
if(!ctrl_hold) | ||||
{ | ||||
r2 | move(0.1,Qt::Horizontal); | |||
r1 | } | |||
else | ||||
{ | ||||
zoom(0.5,this->width()/2,Qt::Horizontal); | ||||
} | ||||
break; | ||||
case Qt::Key_Up: | ||||
if(!ctrl_hold) | ||||
{ | ||||
r2 | move(0.1,Qt::Vertical); | |||
r1 | } | |||
else | ||||
{ | ||||
zoom(0.5,this->height()/2,Qt::Vertical); | ||||
} | ||||
break; | ||||
case Qt::Key_Down: | ||||
if(!ctrl_hold) | ||||
{ | ||||
r2 | move(-0.1,Qt::Vertical); | |||
r1 | } | |||
else | ||||
{ | ||||
zoom(2,this->height()/2,Qt::Vertical); | ||||
} | ||||
break; | ||||
r0 | default: | |||
r1 | QWidget::keyPressEvent(event); | |||
break; | ||||
r0 | } | |||
} | ||||
void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) | ||||
{ | ||||
r1 | switch(event->key()) | |||
r0 | { | |||
case Qt::Key_Control: | ||||
r1 | event->accept(); | |||
this->ctrl_hold = false; | ||||
break; | ||||
r0 | case Qt::Key_Shift: | |||
r1 | event->accept(); | |||
this->shift_hold = false; | ||||
break; | ||||
r0 | default: | |||
r1 | QWidget::keyReleaseEvent(event); | |||
break; | ||||
r0 | } | |||
r2 | setCursor(Qt::ArrowCursor); | |||
r0 | } | |||
void SocExplorerPlot::wheelEvent(QWheelEvent * event) | ||||
{ | ||||
r1 | double factor; | |||
double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually | ||||
if(ctrl_hold) | ||||
r0 | { | |||
r1 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) | |||
r0 | { | |||
r2 | setCursor(Qt::SizeVerCursor); | |||
r1 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); | |||
zoom(factor,event->pos().y(),Qt::Vertical); | ||||
r0 | } | |||
r1 | QWidget::wheelEvent(event); | |||
return; | ||||
r0 | } | |||
r1 | if(shift_hold) | |||
{ | ||||
if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) | ||||
{ | ||||
r2 | setCursor(Qt::SizeHorCursor); | |||
r1 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); | |||
zoom(factor,event->pos().x(),Qt::Horizontal); | ||||
} | ||||
QWidget::wheelEvent(event); | ||||
return; | ||||
} | ||||
move(wheelSteps/10,Qt::Horizontal); | ||||
QWidget::wheelEvent(event); | ||||
r0 | } | |||
void SocExplorerPlot::mousePressEvent(QMouseEvent *event) | ||||
{ | ||||
r1 | if(event->button()==Qt::LeftButton) | |||
r0 | { | |||
r2 | if(ctrl_hold) | |||
{ | ||||
setCursor(Qt::CrossCursor); | ||||
mOrigin = event->pos(); | ||||
mRubberBand->setGeometry(QRect(mOrigin, QSize())); | ||||
mRubberBand->show(); | ||||
} | ||||
else | ||||
{ | ||||
setCursor(Qt::ClosedHandCursor); | ||||
mDragStart = event->pos(); | ||||
this->mouse_hold = true; | ||||
DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); | ||||
DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); | ||||
} | ||||
r0 | } | |||
r1 | QWidget::mousePressEvent(event); | |||
r0 | } | |||
void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event) | ||||
{ | ||||
r1 | if(event->button()==Qt::LeftButton) | |||
r0 | { | |||
r1 | this->mouse_hold = false; | |||
r0 | } | |||
r2 | if (mRubberBand->isVisible()) | |||
{ | ||||
const QRect & zoomRect = mRubberBand->geometry(); | ||||
int xp1, yp1, xp2, yp2; | ||||
zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2); | ||||
double x1 = this->m_plot->xAxis->pixelToCoord(xp1); | ||||
double x2 = this->m_plot->xAxis->pixelToCoord(xp2); | ||||
double y1 = this->m_plot->yAxis->pixelToCoord(yp1); | ||||
double y2 = this->m_plot->yAxis->pixelToCoord(yp2); | ||||
this->m_plot->xAxis->setRange(x1, x2); | ||||
this->m_plot->yAxis->setRange(y1, y2); | ||||
mRubberBand->hide(); | ||||
this->m_plot->replot(); | ||||
} | ||||
setCursor(Qt::ArrowCursor); | ||||
r1 | QWidget::mouseReleaseEvent(event); | |||
} | ||||
void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation) | ||||
{ | ||||
QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation); | ||||
axis->scaleRange(factor, axis->pixelToCoord(center)); | ||||
this->m_plot->replot(); | ||||
r0 | } | |||
r1 | void SocExplorerPlot::move(double factor, Qt::Orientation orientation) | |||
{ | ||||
QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation); | ||||
double rg = (axis->range().upper - axis->range().lower)*(factor); | ||||
axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | ||||
this->m_plot->replot(); | ||||
} | ||||
r0 | void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event) | |||
{ | ||||
r1 | if(mouse_hold) | |||
r0 | { | |||
r1 | QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |||
QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical); | ||||
double diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x()); | ||||
Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff); | ||||
diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y()); | ||||
Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff); | ||||
this->m_plot->replot(); | ||||
r0 | } | |||
r2 | if (mRubberBand->isVisible()) | |||
{ | ||||
mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); | ||||
} | ||||
r1 | QWidget::mouseMoveEvent(event); | |||
r0 | } | |||