SocExplorerPlot.cpp
715 lines
| 20.6 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) : | ||||
r11 | QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this)) | |||
r0 | { | |||
r11 | this->m_plot = new QCustomPlotVect(this); | |||
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() | |||
{ | ||||
r11 | delete mRubberBand; | |||
r2 | } | |||
r0 | void SocExplorerPlot::show() | |||
{ | ||||
r11 | QWidget::show(); | |||
r0 | } | |||
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) | |||
{ | ||||
r11 | 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) | |||
{ | ||||
r11 | 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) | ||||
{ | ||||
r11 | 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) | ||||
{ | ||||
r11 | this->m_plot->xAxis->setRange(lower,upper); | |||
r0 | } | |||
void SocExplorerPlot::setYaxisRange(double lower, double upper) | ||||
{ | ||||
r11 | this->m_plot->yAxis->setRange(lower,upper); | |||
r0 | } | |||
void SocExplorerPlot::rescaleAxis() | ||||
{ | ||||
r11 | this->m_plot->rescaleAxes(); | |||
this->m_plot->replot(); | ||||
r0 | } | |||
void SocExplorerPlot::setLegendFont(QFont font) | ||||
{ | ||||
r11 | this->m_plot->legend->setFont(font); | |||
this->repaint(); | ||||
r0 | } | |||
void SocExplorerPlot::setLegendSelectedFont(QFont font) | ||||
{ | ||||
r11 | this->m_plot->legend->setSelectedFont(font); | |||
this->repaint(); | ||||
r0 | } | |||
void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable) | ||||
{ | ||||
r11 | this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable); | |||
r0 | } | |||
r3 | void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable) | |||
{ | ||||
r7 | // TODO deprecated | |||
r11 | // this->m_plot->graph(graphIndex)->setUseFastVectors(enable); | |||
r3 | } | |||
r0 | int SocExplorerPlot::addGraph() | |||
{ | ||||
r11 | this->m_plot->addGraph(); | |||
return this->m_plot->graphCount() -1; | ||||
r0 | } | |||
bool SocExplorerPlot::removeGraph(int graphIndex) | ||||
{ | ||||
r7 | return this->m_plot->removeGraph(graphIndex); | |||
} | ||||
int SocExplorerPlot::graphCount() | ||||
{ | ||||
return m_plot->graphCount(); | ||||
r0 | } | |||
void SocExplorerPlot::removeAllGraphs() | ||||
{ | ||||
r11 | int graphCount=this->m_plot->graphCount(); | |||
for(int i=0;i<graphCount;i++) | ||||
r0 | { | |||
r11 | this->m_plot->removeGraph(0); | |||
r0 | } | |||
} | ||||
void SocExplorerPlot::setGraphName(int graphIndex,QString name) | ||||
{ | ||||
r11 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r11 | 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) | ||||
{ | ||||
r11 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double)) | |||
r0 | { | |||
r11 | QVector<double> _x(x.count()), _y(y.count()); | |||
for(int i=0;i<x.count();i++) | ||||
r0 | { | |||
r11 | /*_x[i] = x.at(i).value<double>(); | |||
r0 | _y[i] = y.at(i).value<double>();*/ | |||
r11 | _x[i] = x.at(i).toDouble(); | |||
_y[i] = y.at(i).toDouble(); | ||||
r0 | } | |||
r11 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |||
r0 | } | |||
r11 | else | |||
r1 | { | |||
r11 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime)) | |||
r0 | { | |||
r11 | QVector<double> _x(x.count()), _y(y.count()); | |||
for(int i=0;i<x.count();i++) | ||||
r0 | { | |||
r11 | /*_x[i] = x.at(i).value<double>(); | |||
r0 | _y[i] = y.at(i).value<double>();*/ | |||
r11 | _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); | |||
_y[i] = y.at(i).toDouble(); | ||||
r0 | } | |||
r11 | 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 | } | |||
r11 | this->m_plot->replot(); | |||
r0 | } | |||
void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot) | ||||
{ | ||||
r11 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) | |||
r1 | { | |||
r11 | this->m_plot->graph(graphIndex)->setData(data,copy); | |||
r1 | } | |||
r11 | if(replot) | |||
this->m_plot->replot(); | ||||
r0 | } | |||
r3 | void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot) | |||
{ | ||||
r11 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) | |||
r3 | { | |||
r11 | ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data); | |||
r3 | } | |||
r11 | if(replot) | |||
this->m_plot->replot(); | ||||
r3 | } | |||
r0 | void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) | |||
{ | ||||
r11 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) | |||
r0 | { | |||
r11 | QVector<double> _x(x.count()), _y(y.count()); | |||
for(int i=0;i<x.count();i++) | ||||
r0 | { | |||
r11 | /*_x[i] = x.at(i).value<double>(); | |||
r0 | _y[i] = y.at(i).value<double>();*/ | |||
r11 | _x[i] = x.at(i).toDouble(); | |||
_y[i] = y.at(i).toDouble(); | ||||
r0 | } | |||
r11 | this->m_plot->graph(graphIndex)->addData(_x,_y); | |||
r0 | } | |||
r11 | this->m_plot->replot(); | |||
r0 | } | |||
void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y) | ||||
{ | ||||
r11 | if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double)) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble()); | |||
r0 | } | |||
r11 | this->m_plot->replot(); | |||
r0 | } | |||
void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen) | ||||
{ | ||||
r11 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setPen(pen); | |||
r0 | } | |||
} | ||||
QPen SocExplorerPlot::getGraphPen(int graphIndex) | ||||
{ | ||||
r11 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r11 | return this->m_plot->graph(graphIndex)->pen(); | |||
r0 | } | |||
r11 | return this->m_plot->graph()->pen(); | |||
r0 | } | |||
void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle) | ||||
{ | ||||
r11 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r11 | if(!lineStyle.compare("none")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); | |||
return; | ||||
r0 | } | |||
r11 | if(!lineStyle.compare("line")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); | |||
return; | ||||
r0 | } | |||
r11 | if(!lineStyle.compare("stepleft")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); | |||
return; | ||||
r0 | } | |||
r11 | if(!lineStyle.compare("stepright")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); | |||
return; | ||||
r0 | } | |||
r11 | if(!lineStyle.compare("stepcenter")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); | |||
return; | ||||
r0 | } | |||
r11 | if(!lineStyle.compare("impulse")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); | |||
return; | ||||
r0 | } | |||
} | ||||
} | ||||
void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle) | ||||
{ | ||||
r11 | if(graphIndex<this->m_plot->graphCount()) | |||
r0 | { | |||
r11 | if(!scatterStyle.compare("none")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("dot")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("cross")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("plus")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("circle")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("disc")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("square")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("diamond")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("star")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("triangle")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("invertedtriangle")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("crosssquare")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("plussquare")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("crosscircle")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("pluscircle")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); | |||
return; | ||||
r0 | } | |||
r11 | if(!scatterStyle.compare("peace")) | |||
r0 | { | |||
r11 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); | |||
return; | ||||
r0 | } | |||
r1 | } | |||
r0 | } | |||
void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type) | ||||
{ | ||||
r11 | this->m_plot->xAxis->setTickLabelType(type); | |||
r0 | } | |||
void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format) | ||||
{ | ||||
r11 | this->m_plot->xAxis->setDateTimeFormat(format); | |||
r0 | } | |||
void SocExplorerPlot::keyPressEvent(QKeyEvent * event) | ||||
{ | ||||
r11 | switch(event->key()) | |||
r0 | { | |||
case Qt::Key_Control: | ||||
r11 | this->ctrl_hold = true; | |||
setCursor(Qt::CrossCursor); | ||||
break; | ||||
r0 | case Qt::Key_Shift: | |||
r11 | this->shift_hold = true; | |||
break; | ||||
r0 | case Qt::Key_M: | |||
r11 | this->rescaleAxis(); | |||
break; | ||||
r1 | case Qt::Key_Left: | |||
r11 | if(!ctrl_hold) | |||
r1 | { | |||
r11 | move(-0.1,Qt::Horizontal); | |||
r1 | } | |||
r11 | else | |||
r1 | { | |||
r11 | zoom(2,this->width()/2,Qt::Horizontal); | |||
r1 | } | |||
r11 | break; | |||
r1 | case Qt::Key_Right: | |||
r11 | if(!ctrl_hold) | |||
r1 | { | |||
r11 | move(0.1,Qt::Horizontal); | |||
r1 | } | |||
r11 | else | |||
r1 | { | |||
r11 | zoom(0.5,this->width()/2,Qt::Horizontal); | |||
r1 | } | |||
r11 | break; | |||
r1 | case Qt::Key_Up: | |||
r11 | if(!ctrl_hold) | |||
r1 | { | |||
r11 | move(0.1,Qt::Vertical); | |||
r1 | } | |||
r11 | else | |||
r1 | { | |||
r11 | zoom(0.5,this->height()/2,Qt::Vertical); | |||
r1 | } | |||
r11 | break; | |||
r1 | case Qt::Key_Down: | |||
r11 | if(!ctrl_hold) | |||
r1 | { | |||
r11 | move(-0.1,Qt::Vertical); | |||
r1 | } | |||
r11 | else | |||
r1 | { | |||
r11 | zoom(2,this->height()/2,Qt::Vertical); | |||
r1 | } | |||
r11 | break; | |||
r0 | default: | |||
r11 | QWidget::keyPressEvent(event); | |||
break; | ||||
r0 | } | |||
} | ||||
void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) | ||||
{ | ||||
r11 | switch(event->key()) | |||
r0 | { | |||
case Qt::Key_Control: | ||||
r11 | event->accept(); | |||
this->ctrl_hold = false; | ||||
break; | ||||
r0 | case Qt::Key_Shift: | |||
r11 | event->accept(); | |||
this->shift_hold = false; | ||||
break; | ||||
r0 | default: | |||
r11 | QWidget::keyReleaseEvent(event); | |||
break; | ||||
r0 | } | |||
r11 | setCursor(Qt::ArrowCursor); | |||
r0 | } | |||
void SocExplorerPlot::wheelEvent(QWheelEvent * event) | ||||
{ | ||||
r11 | double factor; | |||
double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually | ||||
if(ctrl_hold) | ||||
r0 | { | |||
r11 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) | |||
r0 | { | |||
r11 | setCursor(Qt::SizeVerCursor); | |||
factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); | ||||
zoom(factor,event->pos().y(),Qt::Vertical); | ||||
r0 | } | |||
r11 | QWidget::wheelEvent(event); | |||
return; | ||||
r0 | } | |||
r11 | if(shift_hold) | |||
r1 | { | |||
r11 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) | |||
r1 | { | |||
r11 | setCursor(Qt::SizeHorCursor); | |||
factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); | ||||
zoom(factor,event->pos().x(),Qt::Horizontal); | ||||
r1 | } | |||
r11 | QWidget::wheelEvent(event); | |||
return; | ||||
r1 | } | |||
r11 | move(wheelSteps,Qt::Horizontal); | |||
QWidget::wheelEvent(event); | ||||
r0 | } | |||
void SocExplorerPlot::mousePressEvent(QMouseEvent *event) | ||||
{ | ||||
r11 | if(event->button()==Qt::LeftButton) | |||
r0 | { | |||
r11 | if(ctrl_hold) | |||
r2 | { | |||
r11 | setCursor(Qt::CrossCursor); | |||
mOrigin = event->pos(); | ||||
mRubberBand->setGeometry(QRect(mOrigin, QSize())); | ||||
mRubberBand->show(); | ||||
r2 | } | |||
r11 | else | |||
r2 | { | |||
r11 | 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(); | ||||
r2 | } | |||
r0 | } | |||
r11 | QWidget::mousePressEvent(event); | |||
r0 | } | |||
void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event) | ||||
{ | ||||
r11 | if(event->button()==Qt::LeftButton) | |||
r0 | { | |||
r11 | this->mouse_hold = false; | |||
r0 | } | |||
r11 | if (mRubberBand->isVisible()) | |||
r2 | { | |||
r11 | 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); | ||||
r2 | ||||
r11 | this->m_plot->xAxis->setRange(x1, x2); | |||
this->m_plot->yAxis->setRange(y1, y2); | ||||
r2 | ||||
r11 | mRubberBand->hide(); | |||
this->m_plot->replot(); | ||||
r2 | } | |||
r11 | setCursor(Qt::ArrowCursor); | |||
QWidget::mouseReleaseEvent(event); | ||||
r1 | } | |||
void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation) | ||||
{ | ||||
r11 | 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) | |||
{ | ||||
r11 | 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)); | ||||
double rg =0.0; | ||||
DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); | ||||
DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); | ||||
if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) | ||||
{ | ||||
rg = (axis->range().upper - axis->range().lower)*(factor/10); | ||||
axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | ||||
} | ||||
else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) | ||||
{ | ||||
// rg = (axis->range().upper / axis->range().lower)*(factor/100); | ||||
int start,stop; | ||||
double diff; | ||||
if(factor>0.0) | ||||
{ | ||||
stop =this->width()*factor/10; | ||||
start = 2*this->width()*factor/10; | ||||
} | ||||
if(factor<0.0) | ||||
{ | ||||
factor*=-1.0; | ||||
start =this->width()*factor/10; | ||||
stop = 2*this->width()*factor/10; | ||||
} | ||||
diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop); | ||||
axis->setRange(this->m_plot->axisRect()->rangeDragAxis(orientation)->range().lower*diff, this->m_plot->axisRect()->rangeDragAxis(orientation)->range().upper*diff); | ||||
} | ||||
this->m_plot->replot(); | ||||
r1 | } | |||
r0 | void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event) | |||
{ | ||||
r11 | if(mouse_hold) | |||
r0 | { | |||
r11 | QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |||
QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical); | ||||
// double diff = rangeDragHorzAxis->pixelToCoord(mDragStart.x()) / rangeDragHorzAxis->pixelToCoord(event->pos().x()); | ||||
// rangeDragHorzAxis->setRange(mDragStartHorzRange.lower*diff, mDragStartHorzRange.upper*diff); | ||||
double diff=0; | ||||
if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) | ||||
{ | ||||
diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x()); | ||||
Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff); | ||||
} | ||||
else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) | ||||
{ | ||||
diff = Haxis->pixelToCoord(mDragStart.x()) / Haxis->pixelToCoord(event->pos().x()); | ||||
Haxis->setRange(DragStartHorzRange.lower*diff, DragStartHorzRange.upper*diff); | ||||
} | ||||
if(this->m_plot->yAxis->scaleType() == QCPAxis::stLinear) | ||||
{ | ||||
diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y()); | ||||
Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff); | ||||
} | ||||
else if(this->m_plot->yAxis->scaleType() == QCPAxis::stLogarithmic) | ||||
{ | ||||
diff = Vaxis->pixelToCoord(mDragStart.y()) / Vaxis->pixelToCoord(event->pos().y()); | ||||
Vaxis->setRange(DragStartVertRange.lower*diff, DragStartVertRange.upper*diff); | ||||
} | ||||
this->m_plot->replot(); | ||||
r0 | } | |||
r11 | if (mRubberBand->isVisible()) | |||
r2 | { | |||
r11 | mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); | |||
r2 | } | |||
r11 | QWidget::mouseMoveEvent(event); | |||
r0 | } | |||