diff --git a/src/common/SocExplorerPlot.cpp b/src/common/SocExplorerPlot.cpp --- a/src/common/SocExplorerPlot.cpp +++ b/src/common/SocExplorerPlot.cpp @@ -3,199 +3,222 @@ SocExplorerPlot::SocExplorerPlot(QWidget *parent) : - QWidget(parent) + QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this)) { - this->m_plot = new QCustomPlot(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 = new QCustomPlot(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(); +} +SocExplorerPlot::~SocExplorerPlot() +{ + delete mRubberBand; } void SocExplorerPlot::show() { - QWidget::show(); + QWidget::show(); +} + +void SocExplorerPlot::replot() +{ + this->m_plot->replot(); } void SocExplorerPlot::setTitle(QString title) { - Q_UNUSED(title) - //this->m_plot->setTitle(title); -/*! + Q_UNUSED(title) + //this->m_plot->setTitle(title); + /*! @todo Function borcken fixe this! */ - this->repaint(); + this->repaint(); } void SocExplorerPlot::setXaxisLabel(QString label) { - this->m_plot->xAxis->setLabel(label); - this->repaint(); + this->m_plot->xAxis->setLabel(label); + this->repaint(); } void SocExplorerPlot::setYaxisLabel(QString label) { - this->m_plot->yAxis->setLabel(label); - this->repaint(); + this->m_plot->yAxis->setLabel(label); + this->repaint(); } void SocExplorerPlot::setXaxisRange(double lower, double upper) { - this->m_plot->xAxis->setRange(lower,upper); + this->m_plot->xAxis->setRange(lower,upper); } void SocExplorerPlot::setYaxisRange(double lower, double upper) { - this->m_plot->yAxis->setRange(lower,upper); + this->m_plot->yAxis->setRange(lower,upper); } void SocExplorerPlot::rescaleAxis() { - this->m_plot->rescaleAxes(); - this->m_plot->replot(); + this->m_plot->rescaleAxes(); + this->m_plot->replot(); } void SocExplorerPlot::setLegendFont(QFont font) { - this->m_plot->legend->setFont(font); - this->repaint(); + this->m_plot->legend->setFont(font); + this->repaint(); } void SocExplorerPlot::setLegendSelectedFont(QFont font) { - this->m_plot->legend->setSelectedFont(font); - this->repaint(); + this->m_plot->legend->setSelectedFont(font); + this->repaint(); } void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable) { - this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable); + this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable); } int SocExplorerPlot::addGraph() { - this->m_plot->addGraph(); - return this->m_plot->graphCount() -1; + this->m_plot->addGraph(); + return this->m_plot->graphCount() -1; +} + +bool SocExplorerPlot::removeGraph(int graphIndex) +{ + return this->m_plot->removeGraph(graphIndex); +} + +void SocExplorerPlot::removeAllGraphs() +{ + int graphCount=this->m_plot->graphCount(); + for(int i=0;im_plot->removeGraph(0); + } } void SocExplorerPlot::setGraphName(int graphIndex,QString name) { - if(graphIndexm_plot->graphCount()) + if(graphIndexm_plot->graphCount()) { - this->m_plot->graph(graphIndex)->setName(name); + this->m_plot->graph(graphIndex)->setName(name); } } void SocExplorerPlot::setGraphData(int graphIndex, QList x, QList y) { - if((graphIndexm_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) + if((graphIndexm_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) { - QVector _x(x.count()), _y(y.count()); - for(int i=0;i _x(x.count()), _y(y.count()); + for(int i=0;i(); + /*_x[i] = x.at(i).value(); _y[i] = y.at(i).value();*/ - _x[i] = x.at(i).toDouble(); - _y[i] = y.at(i).toDouble(); + _x[i] = x.at(i).toDouble(); + _y[i] = y.at(i).toDouble(); } - this->m_plot->graph(graphIndex)->setData(_x,_y); + this->m_plot->graph(graphIndex)->setData(_x,_y); } - this->m_plot->replot(); + this->m_plot->replot(); } void SocExplorerPlot::addGraphData(int graphIndex, QList x, QList y) { - if((graphIndexm_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) + if((graphIndexm_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) { - QVector _x(x.count()), _y(y.count()); - for(int i=0;i _x(x.count()), _y(y.count()); + for(int i=0;i(); + /*_x[i] = x.at(i).value(); _y[i] = y.at(i).value();*/ - _x[i] = x.at(i).toDouble(); - _y[i] = y.at(i).toDouble(); + _x[i] = x.at(i).toDouble(); + _y[i] = y.at(i).toDouble(); } - this->m_plot->graph(graphIndex)->addData(_x,_y); + this->m_plot->graph(graphIndex)->addData(_x,_y); } - this->m_plot->replot(); + this->m_plot->replot(); } void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y) { - if(graphIndexm_plot->graphCount())// && (x.at(0).type()==QVariant::Double)) + if(graphIndexm_plot->graphCount())// && (x.at(0).type()==QVariant::Double)) { - this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble()); + this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble()); } - this->m_plot->replot(); + this->m_plot->replot(); } void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen) { - if(graphIndexm_plot->graphCount()) + if(graphIndexm_plot->graphCount()) { - this->m_plot->graph(graphIndex)->setPen(pen); + this->m_plot->graph(graphIndex)->setPen(pen); } } QPen SocExplorerPlot::getGraphPen(int graphIndex) { - if(graphIndexm_plot->graphCount()) + if(graphIndexm_plot->graphCount()) { - return this->m_plot->graph(graphIndex)->pen(); + return this->m_plot->graph(graphIndex)->pen(); } - return this->m_plot->graph()->pen(); + return this->m_plot->graph()->pen(); } void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle) { - if(graphIndexm_plot->graphCount()) + if(graphIndexm_plot->graphCount()) { - if(!lineStyle.compare("none")) + if(!lineStyle.compare("none")) { - this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); - return; + this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); + return; } - if(!lineStyle.compare("line")) + if(!lineStyle.compare("line")) { - this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); - return; + this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); + return; } - if(!lineStyle.compare("stepleft")) + if(!lineStyle.compare("stepleft")) { - this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); - return; + this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); + return; } - if(!lineStyle.compare("stepright")) + if(!lineStyle.compare("stepright")) { - this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); - return; + this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); + return; } - if(!lineStyle.compare("stepcenter")) + if(!lineStyle.compare("stepcenter")) { - this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); - return; + this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); + return; } - if(!lineStyle.compare("impulse")) + if(!lineStyle.compare("impulse")) { - this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); - return; + this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); + return; } @@ -204,166 +227,213 @@ void SocExplorerPlot::setGraphLineStyle( void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle) { - if(graphIndexm_plot->graphCount()) + if(graphIndexm_plot->graphCount()) { - if(!scatterStyle.compare("none")) + if(!scatterStyle.compare("none")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); + return; } - if(!scatterStyle.compare("dot")) + if(!scatterStyle.compare("dot")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); + return; } - if(!scatterStyle.compare("cross")) + if(!scatterStyle.compare("cross")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); + return; } - if(!scatterStyle.compare("plus")) + if(!scatterStyle.compare("plus")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); + return; } - if(!scatterStyle.compare("circle")) + if(!scatterStyle.compare("circle")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); + return; } - if(!scatterStyle.compare("disc")) + if(!scatterStyle.compare("disc")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); + return; } - if(!scatterStyle.compare("square")) + if(!scatterStyle.compare("square")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); + return; } - if(!scatterStyle.compare("diamond")) + if(!scatterStyle.compare("diamond")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); + return; } - if(!scatterStyle.compare("star")) + if(!scatterStyle.compare("star")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); + return; } - if(!scatterStyle.compare("triangle")) + if(!scatterStyle.compare("triangle")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); + return; } - if(!scatterStyle.compare("invertedtriangle")) + if(!scatterStyle.compare("invertedtriangle")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); + return; } - if(!scatterStyle.compare("crosssquare")) + if(!scatterStyle.compare("crosssquare")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); + return; } - if(!scatterStyle.compare("plussquare")) + if(!scatterStyle.compare("plussquare")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); + return; } - if(!scatterStyle.compare("crosscircle")) + if(!scatterStyle.compare("crosscircle")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); + return; } - if(!scatterStyle.compare("pluscircle")) + if(!scatterStyle.compare("pluscircle")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); + return; } - if(!scatterStyle.compare("peace")) + if(!scatterStyle.compare("peace")) { - this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); - return; + this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); + return; } } } +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) { - switch(event->key()) + switch(event->key()) { case Qt::Key_Control: - this->ctrl_hold = true; - break; + this->ctrl_hold = true; + setCursor(Qt::CrossCursor); + break; case Qt::Key_Shift: - this->shift_hold = true; - break; + this->shift_hold = true; + break; case Qt::Key_M: - this->rescaleAxis(); - break; + this->rescaleAxis(); + break; + case Qt::Key_Left: + if(!ctrl_hold) + { + move(-0.1,Qt::Horizontal); + } + else + { + zoom(2,this->width()/2,Qt::Horizontal); + } + break; + case Qt::Key_Right: + if(!ctrl_hold) + { + move(0.1,Qt::Horizontal); + } + else + { + zoom(0.5,this->width()/2,Qt::Horizontal); + } + break; + case Qt::Key_Up: + if(!ctrl_hold) + { + move(0.1,Qt::Vertical); + } + else + { + zoom(0.5,this->height()/2,Qt::Vertical); + } + break; + case Qt::Key_Down: + if(!ctrl_hold) + { + move(-0.1,Qt::Vertical); + } + else + { + zoom(2,this->height()/2,Qt::Vertical); + } + break; default: - QWidget::keyPressEvent(event); - break; + QWidget::keyPressEvent(event); + break; } } void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) { - switch(event->key()) + switch(event->key()) { case Qt::Key_Control: - event->accept(); - this->ctrl_hold = false; - break; + event->accept(); + this->ctrl_hold = false; + break; case Qt::Key_Shift: - event->accept(); - this->shift_hold = false; - break; + event->accept(); + this->shift_hold = false; + break; default: - QWidget::keyReleaseEvent(event); - break; + QWidget::keyReleaseEvent(event); + break; } + setCursor(Qt::ArrowCursor); } void SocExplorerPlot::wheelEvent(QWheelEvent * event) { - double factor; - double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - if(ctrl_hold) - { - if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) - { - factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); - QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(Qt::Vertical); - axis->scaleRange(factor, axis->pixelToCoord(event->pos().y())); - } - this->m_plot->replot(); - QWidget::wheelEvent(event); - return; - } - if(shift_hold) + double factor; + double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + if(ctrl_hold) { - if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) + if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) { - factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); - QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(Qt::Horizontal); - axis->scaleRange(factor, axis->pixelToCoord(event->pos().x())); + setCursor(Qt::SizeVerCursor); + factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); + zoom(factor,event->pos().y(),Qt::Vertical); } - this->m_plot->replot(); - QWidget::wheelEvent(event); - return; + QWidget::wheelEvent(event); + return; } - QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); - double rg = (Haxis->range().upper - Haxis->range().lower)*(wheelSteps/10); - Haxis->setRange(Haxis->range().lower+(rg), Haxis->range().upper+(rg)); - this->m_plot->replot(); - QWidget::wheelEvent(event); + if(shift_hold) + { + if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) + { + setCursor(Qt::SizeHorCursor); + 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); } @@ -371,38 +441,86 @@ void SocExplorerPlot::wheelEvent(QWheelE void SocExplorerPlot::mousePressEvent(QMouseEvent *event) { - if(event->button()==Qt::LeftButton) + if(event->button()==Qt::LeftButton) { - 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(); + 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(); + } } - QWidget::mousePressEvent(event); + QWidget::mousePressEvent(event); } void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event) { - if(event->button()==Qt::LeftButton) + if(event->button()==Qt::LeftButton) + { + this->mouse_hold = false; + } + if (mRubberBand->isVisible()) { - this->mouse_hold = false; + 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(); } - QWidget::mouseReleaseEvent(event); + setCursor(Qt::ArrowCursor); + 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(); } +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(); +} + + void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event) { - if(mouse_hold) + if(mouse_hold) { - 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(); + 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(); } - QWidget::mouseMoveEvent(event); + if (mRubberBand->isVisible()) + { + mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); + } + QWidget::mouseMoveEvent(event); } diff --git a/src/common/SocExplorerPlot.h b/src/common/SocExplorerPlot.h --- a/src/common/SocExplorerPlot.h +++ b/src/common/SocExplorerPlot.h @@ -4,53 +4,67 @@ #include #include #include +#include +#include class SocExplorerPlot : public QWidget { - Q_OBJECT + Q_OBJECT public: - explicit SocExplorerPlot(QWidget *parent = 0); - void setTitle(QString title); - void setXaxisLabel(QString label); - void setXaxisRange(double lower, double upper); - void setYaxisLabel(QString label); - void setYaxisRange(double lower, double upper); - void rescaleAxis(); - void setLegendFont(QFont font); - void setLegendSelectedFont(QFont font); - void setAdaptativeSampling(int graphIndex,bool enable); - int addGraph(); - void setGraphName(int graphIndex,QString name); - void setGraphData(int graphIndex, QList x, QList y); - void addGraphData(int graphIndex, QList x, QList y); - void addGraphData(int graphIndex, QVariant x, QVariant y); - void setGraphPen(int graphIndex,QPen pen); - QPen getGraphPen(int graphIndex); - void setGraphLineStyle(int graphIndex,QString lineStyle); - void setGraphScatterStyle(int graphIndex,QString scatterStyle); - void show(); + explicit SocExplorerPlot(QWidget *parent = 0); + ~SocExplorerPlot(); + void setTitle(QString title); + void setXaxisLabel(QString label); + void setXaxisRange(double lower, double upper); + void setYaxisLabel(QString label); + void setYaxisRange(double lower, double upper); + void rescaleAxis(); + void setLegendFont(QFont font); + void setLegendSelectedFont(QFont font); + void setAdaptativeSampling(int graphIndex,bool enable); + int addGraph(); + bool removeGraph(int graphIndex); + void removeAllGraphs(); + void setGraphName(int graphIndex,QString name); + void setGraphData(int graphIndex, QList x, QList y); + void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true); + void addGraphData(int graphIndex, QList x, QList y); + void addGraphData(int graphIndex, QVariant x, QVariant y); + void setGraphPen(int graphIndex,QPen pen); + QPen getGraphPen(int graphIndex); + void setGraphLineStyle(int graphIndex,QString lineStyle); + void setGraphScatterStyle(int graphIndex,QString scatterStyle); + void setXaxisTickLabelType(QCPAxis::LabelType type); + void setXaxisDateTimeFormat(const QString &format); + void show(); + void replot(); signals: - + public slots: protected: - void keyPressEvent(QKeyEvent *); - void keyReleaseEvent(QKeyEvent *); - void wheelEvent(QWheelEvent *); - void mousePressEvent(QMouseEvent *); - void mouseMoveEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); + void keyPressEvent(QKeyEvent *); + void keyReleaseEvent(QKeyEvent *); + void wheelEvent(QWheelEvent *); + void mousePressEvent(QMouseEvent *); + void mouseMoveEvent(QMouseEvent *); + void mouseReleaseEvent(QMouseEvent *); private: - QCustomPlot* m_plot; - QGridLayout* m_mainlayout; - bool ctrl_hold; - bool shift_hold; - bool mouse_hold; - QCPRange DragStartHorzRange; - QCPRange DragStartVertRange; - QPoint mDragStart; + void zoom(double factor, int center, Qt::Orientation orientation); + void move(double factor, Qt::Orientation orientation); + QCustomPlot* m_plot; + QGridLayout* m_mainlayout; + bool ctrl_hold; + bool shift_hold; + bool mouse_hold; + QCPRange DragStartHorzRange; + QCPRange DragStartVertRange; + QPoint mDragStart; + bool mZoomMode; + QRubberBand * mRubberBand; + QPoint mOrigin; }; #endif // SOCEXPLORERPLOT_H