# HG changeset patch # User Alexis Jeandet # Date 2015-01-30 08:53:39 # Node ID a1d6d9df437f5f8a2f40274e7f1f065ef23a5deb # Parent b2e86551a87bfb4010779ceae6ae582c00d14c36 Drag and drop implemented, improved plot interactions. diff --git a/QLop.pro b/QLop.pro --- a/QLop.pro +++ b/QLop.pro @@ -23,7 +23,8 @@ SOURCES += src/main.cpp\ src/themisdatafile.cpp \ src/filedownloader.cpp \ src/folderview.cpp \ - src/toolbarcontainer.cpp + src/toolbarcontainer.cpp \ + src/folderlistwidget.cpp HEADERS += src/mainwindow.h \ src/SocExplorerPlot.h \ @@ -31,7 +32,8 @@ HEADERS += src/mainwindow.h \ src/themisdatafile.h \ src/filedownloader.h \ src/folderview.h \ - src/toolbarcontainer.h + src/toolbarcontainer.h \ + src/folderlistwidget.h FORMS += src/mainwindow.ui \ src/folderview.ui diff --git a/src/SocExplorerPlot.cpp b/src/SocExplorerPlot.cpp --- a/src/SocExplorerPlot.cpp +++ b/src/SocExplorerPlot.cpp @@ -24,24 +24,25 @@ SocExplorerPlot::SocExplorerPlot(QWidget *parent) : - QWidget(parent) + QWidget(parent) { - 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(); + this->m_plot->legend->setVisible(true); } @@ -57,63 +58,63 @@ void SocExplorerPlot::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(); + this->m_plot->addGraph(); return this->m_plot->graphCount() -1; } @@ -134,136 +135,136 @@ void SocExplorerPlot::removeAllGraphs() 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); } - else - { - if((graphIndexm_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime)) + else + { + if((graphIndexm_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime)) { - 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).toDateTime().toMSecsSinceEpoch(); - _y[i] = y.at(i).toDouble(); + _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); + _y[i] = y.at(i).toDouble(); } - this->m_plot->graph(graphIndex)->setData(_x,_y); - this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); - this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz"); + this->m_plot->graph(graphIndex)->setData(_x,_y); + this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); + this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz"); } - } - this->m_plot->replot(); + } + this->m_plot->replot(); } void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot) { if((graphIndexm_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) - { + { this->m_plot->graph(graphIndex)->setData(data,copy); - } + } if(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; } @@ -272,90 +273,90 @@ 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) @@ -374,74 +375,107 @@ void SocExplorerPlot::setXaxisDateTimeFo void SocExplorerPlot::keyPressEvent(QKeyEvent * event) { - switch(event->key()) + switch(event->key()) { case Qt::Key_Control: - this->ctrl_hold = true; - break; + this->ctrl_hold = true; + 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; } } 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())); + 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)) + { + 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); } @@ -449,38 +483,54 @@ 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(); + 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; + this->mouse_hold = false; } - QWidget::mouseReleaseEvent(event); + 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); + QWidget::mouseMoveEvent(event); } diff --git a/src/SocExplorerPlot.h b/src/SocExplorerPlot.h --- a/src/SocExplorerPlot.h +++ b/src/SocExplorerPlot.h @@ -70,6 +70,8 @@ protected: void mouseReleaseEvent(QMouseEvent *); private: + 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; diff --git a/src/folderlistwidget.cpp b/src/folderlistwidget.cpp new file mode 100644 --- /dev/null +++ b/src/folderlistwidget.cpp @@ -0,0 +1,131 @@ +#include "folderlistwidget.h" +#include +#include +#include +#include +#include +#include +#include +#include + +FolderListWidget::FolderListWidget(QWidget *parent) : QListWidget(parent) +{ + this->setSelectionMode(QAbstractItemView::ExtendedSelection); + this->setAcceptDrops(true); + this->setDragEnabled(true); + this->setDragDropMode(QAbstractItemView::DragDrop); + this->setDefaultDropAction(Qt::MoveAction); + this->p_mainWin=NULL; + this->p_path=""; +} + +FolderListWidget::~FolderListWidget() +{ + +} + +bool FolderListWidget::contains(const QString &name) +{ + for(int i=0;icount();i++) + { + if(this->item(i)->text()==name) + return true; + } + return false; +} + +bool FolderListWidget::isDraging(const QString &name) +{ + for(int i=0;ilastDragItems.count();i++) + { + if(lastDragItems.at(i)==name) + return true; + } + return false; +} + +void FolderListWidget::setMainWindow(MainWindow *mw) +{ + this->p_mainWin = mw; +} + +void FolderListWidget::setPath(const QString &path) +{ + this->p_path = path; + this->lastDragItems.clear(); +} + +void FolderListWidget::dragEnterEvent(QDragEnterEvent *event) +{ + const QMimeData *mimeData = event->mimeData(); + QStringList mimeFormats = mimeData->formats(); + bool containsFile=false; + if(mimeFormats.count()) + { + QByteArray encoded = mimeData->data("application/x-qabstractitemmodeldatalist"); + QDataStream stream(&encoded, QIODevice::ReadOnly); + while (!stream.atEnd()) + { + int row, col; + QMap roleDataMap; + stream >> row >> col >> roleDataMap; + if(this->contains(roleDataMap[0].toString())) + containsFile = true; + } + } + if(!containsFile) + { + QListWidget::dragEnterEvent(event); + } + else + { + this->lastDragItems.clear(); + QList selItems = this->selectedItems(); + for(int i=0;itext()); + } + } + +} + +void FolderListWidget::dragMoveEvent(QDragMoveEvent *event) +{ + QListWidget::dragMoveEvent(event); +} + +void FolderListWidget::dragLeaveEvent(QDragLeaveEvent *event) +{ + QListWidget::dragLeaveEvent(event); + this->lastDragItems.clear(); +} + +void FolderListWidget::dropEvent(QDropEvent *event) +{ + QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist"); + QDataStream stream(&encoded, QIODevice::ReadOnly); + while (!stream.atEnd()) + { + int row, col; + QMap roleDataMap; + stream >> row >> col >> roleDataMap; + QString name=roleDataMap[0].toString(); + QString oldPath = p_mainWin->getFilePath(name); + if((oldPath!="") && (p_path!="")) + { + if(QFile::rename(oldPath+"/"+name,this->p_path+"/"+name)) + QListWidget::dropEvent(event); + emit askGlobalRescan(); + } + } +} + +void FolderListWidget::mousePressEvent(QMouseEvent *event) +{ + QListWidget::mousePressEvent(event); +} + +void FolderListWidget::mouseMoveEvent(QMouseEvent *event) +{ + QListWidget::mouseMoveEvent(event); +} diff --git a/src/folderlistwidget.h b/src/folderlistwidget.h new file mode 100644 --- /dev/null +++ b/src/folderlistwidget.h @@ -0,0 +1,36 @@ +#ifndef FOLDERLISTWIDGET_H +#define FOLDERLISTWIDGET_H + +#include +#include +#include +#include + +class FolderListWidget : public QListWidget +{ + Q_OBJECT +public: + explicit FolderListWidget(QWidget *parent = 0); + ~FolderListWidget(); + bool contains(const QString& name); + bool isDraging(const QString& name); + void setMainWindow(MainWindow* mw); + void setPath(const QString& path); +signals: + void askGlobalRescan(); +public slots: +protected: + void dragEnterEvent(QDragEnterEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dragLeaveEvent(QDragLeaveEvent* event); + void dropEvent(QDropEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + +private: + QStringList lastDragItems; + MainWindow* p_mainWin; + QString p_path; +}; + +#endif // FOLDERLISTWIDGET_H diff --git a/src/folderview.cpp b/src/folderview.cpp --- a/src/folderview.cpp +++ b/src/folderview.cpp @@ -23,26 +23,26 @@ #include "ui_folderview.h" #include #include +#include -FolderView::FolderView(QWidget *parent) : - QDockWidget(parent), - ui(new Ui::FolderView) +p_FolderView::p_FolderView(QWidget *parent) : + QWidget(parent), + ui(new Ui::p_FolderView) { ui->setupUi(this); - this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); - this->setAllowedAreas(Qt::AllDockWidgetAreas); - this->setWidget(this->ui->groupBox); connect(this->ui->setFolderQpb,SIGNAL(clicked()),this,SLOT(openFolder())); connect(this->ui->refreshQpb,SIGNAL(clicked()),this,SLOT(refreshFolder())); connect(this->ui->listWidget,SIGNAL(itemActivated(QListWidgetItem*)),this,SLOT(itemActivated(QListWidgetItem*))); + //this->ui->listWidget->installEventFilter(this); + connect(this->ui->listWidget,SIGNAL(askGlobalRescan()),this,SIGNAL(askGlobalRescan())); } -FolderView::~FolderView() +p_FolderView::~p_FolderView() { delete ui; } -bool FolderView::contains(const QString &fileName) +bool p_FolderView::contains(const QString &fileName) { for(int i=0;iui->listWidget->count();i++) { @@ -54,16 +54,31 @@ bool FolderView::contains(const QString return false; } -void FolderView::openFolder() +bool p_FolderView::isDraging(const QString &name) +{ + return this->ui->listWidget->isDraging(name); +} + +void p_FolderView::setMainWindow(MainWindow *mw) { - currentFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),NULL,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + this->ui->listWidget->setMainWindow(mw); +} + +QString p_FolderView::currentFolder() +{ + return p_currentFolder; +} + +void p_FolderView::openFolder() +{ + p_currentFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),NULL,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); refreshFolder(); } -void FolderView::refreshFolder() +void p_FolderView::refreshFolder() { QDir dir; - dir.setPath(currentFolder); + dir.setPath(p_currentFolder); this->ui->listWidget->clear(); dir.setFilter(QDir::Files | QDir::NoSymLinks); dir.setSorting(QDir::Name); @@ -75,15 +90,16 @@ void FolderView::refreshFolder() this->ui->listWidget->addItem(list.at(i).fileName()); } } - this->ui->groupBox->setTitle(currentFolder); + this->ui->listWidget->setPath(p_currentFolder); + this->ui->groupBox->setTitle(p_currentFolder); } -void FolderView::itemActivated(QListWidgetItem *item) +void p_FolderView::itemActivated(QListWidgetItem *item) { - emit itemActivated(currentFolder+'/'+item->text()); + emit itemActivated(p_currentFolder+'/'+item->text()); } -void FolderView::changeEvent(QEvent *e) +void p_FolderView::changeEvent(QEvent *e) { QWidget::changeEvent(e); switch (e->type()) { @@ -94,3 +110,56 @@ void FolderView::changeEvent(QEvent *e) break; } } + +bool p_FolderView::eventFilter(QObject *object, QEvent *event) +{ + if(object == this->ui->listWidget ) + { + qDebug()<type(); + if(event->type() == QEvent::Drop) + { + QDropEvent *DropEvent = static_cast(event); + qDebug()<< DropEvent->mimeData(); + } + } + return false; +} + + +FolderView::FolderView(MainWindow *parent) + :QDockWidget(parent) +{ + this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); + this->setAllowedAreas(Qt::AllDockWidgetAreas); + this->ui = new p_FolderView(this); + this->setWidget(this->ui); + connect(this->ui,SIGNAL(itemActivated(QString)),this,SIGNAL(itemActivated(QString))); + connect(this->ui,SIGNAL(askGlobalRescan()),this,SIGNAL(askGlobalRescan())); + this->ui->setMainWindow(parent); +} + +bool FolderView::contains(const QString &fileName) +{ + return ui->contains(fileName); +} + +bool FolderView::isDraging(const QString &name) +{ + return this->ui->isDraging(name); +} + +QString FolderView::currentFolder() +{ + return this->ui->currentFolder(); +} + +void FolderView::openFolder() +{ + this->ui->openFolder(); +} + +void FolderView::refreshFolder() +{ + this->ui->refreshFolder(); +} + diff --git a/src/folderview.h b/src/folderview.h --- a/src/folderview.h +++ b/src/folderview.h @@ -25,32 +25,61 @@ #include #include #include - +#include +#include + class MainWindow; namespace Ui { - class FolderView; + class p_FolderView; } +class p_FolderView; + class FolderView : public QDockWidget { Q_OBJECT +public: + FolderView (MainWindow *parent = 0); + ~FolderView(){} + bool contains(const QString& fileName); + bool isDraging(const QString& name); + QString currentFolder(); +public slots: + void openFolder(); + void refreshFolder(); +signals: + void askGlobalRescan(); + void itemActivated(const QString& item); +private: + p_FolderView* ui; +}; + + +class p_FolderView : public QWidget +{ + Q_OBJECT public: - explicit FolderView(QWidget *parent = 0); - ~FolderView(); + explicit p_FolderView(QWidget *parent = 0); + ~p_FolderView(); bool contains(const QString& fileName); + bool isDraging(const QString& name); + void setMainWindow(MainWindow* mw); + QString currentFolder(); public slots: void openFolder(); void refreshFolder(); void itemActivated(QListWidgetItem * item); signals: + void askGlobalRescan(); void itemActivated(const QString& item); protected: void changeEvent(QEvent *e); + bool eventFilter(QObject *object, QEvent *event); private: - Ui::FolderView *ui; + Ui::p_FolderView *ui; QWidget* _Widget; - QString currentFolder; + QString p_currentFolder; }; #endif // FOLDERVIEW_H diff --git a/src/folderview.ui b/src/folderview.ui --- a/src/folderview.ui +++ b/src/folderview.ui @@ -1,7 +1,7 @@ - FolderView - + p_FolderView + 0 @@ -13,78 +13,87 @@ Test - - - - 9 - 9 - 282 - 268 - - - - No Folder - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - QAbstractItemView::DragDrop - - - Qt::MoveAction - - - - - - - Set Folder - - - - - - - - - - - - - - :/img/Gnome-view-refresh.svg:/img/Gnome-view-refresh.svg - - - - 24 - 24 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + + + + No Folder + + + + + + true + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + QAbstractItemView::DragDrop + + + Qt::MoveAction + + + + + + + Set Folder + + + + + + + + + + + + + + :/img/Gnome-view-refresh.svg:/img/Gnome-view-refresh.svg + + + + 24 + 24 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + FolderListWidget + QListWidget +
folderlistwidget.h
+
+
diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -46,3 +46,5 @@ int main(int argc, char *argv[]) return a.exec(); } + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -55,6 +55,7 @@ MainWindow::MainWindow(int OMP_THREADS, this->progressLayout = new QVBoxLayout(this->progressWidget); this->progressWidget->setLayout(this->progressLayout); this->progressWidget->setWindowModality(Qt::WindowModal); + progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); for(int i=0;iprogress.append(new QProgressBar(this->progressWidget)); @@ -63,6 +64,7 @@ MainWindow::MainWindow(int OMP_THREADS, connect(&this->fileReader,SIGNAL(updateProgress(int,int)),this,SLOT(updateProgress(int,int))); this->progressLayout->addWidget(this->progress.last()); this->progressWidget->hide(); + this->progressThreadIds[i] = -1; } this->progressWidget->setWindowTitle("Loading File"); } @@ -72,6 +74,16 @@ MainWindow::~MainWindow() delete ui; } +QString MainWindow::getFilePath(const QString &name) +{ + for(int i=0;ifolderViews.count();i++) + { + if(folderViews.at(i)->isDraging(name)) + return folderViews.at(i)->currentFolder(); + } + return ""; +} + void MainWindow::itemDoubleClicked(QListWidgetItem* item) { @@ -96,7 +108,14 @@ void MainWindow::plotFile(const QString void MainWindow::dataReady(QCPDataMap *ch1, QCPDataMap *ch2, QCPDataMap *ch3) { + for(int i=0;iprogressWidget->hide(); + this->ui->Plot->setGraphName(0,"MAG_X"); + this->ui->Plot->setGraphName(1,"MAG_Y"); + this->ui->Plot->setGraphName(2,"MAG_Z"); this->ui->Plot->setGraphData(0,ch1,false,false); this->ui->Plot->setGraphData(1,ch2,false,false); this->ui->Plot->setGraphData(2,ch3,false,false); @@ -131,17 +150,36 @@ void MainWindow::downloadData(const QDat void MainWindow::updateProgress(int threadId, int percentProgress) { - if(threadIdprogress.at(threadId)->setValue(percentProgress); + bool updated=false; + for(int i=0;iprogress.at(threadId)->setValue(percentProgress); + updated=true; + } + } + if(Q_UNLIKELY(updated==false)) + { + for(int i=0;ifolderViews.append(new FolderView()); + this->folderViews.append(new FolderView(this)); this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last()); - this->folderViews.last()->setWindowTitle( "test");//QString("Folder View %1").arg(this->folderViews.length())); + this->folderViews.last()->setWindowTitle( QString("Folder View %1").arg(this->folderViews.length())); this->folderViews.last()->setAllowedAreas(Qt::AllDockWidgetAreas); connect(this->folderViews.last(),SIGNAL(itemActivated(QString)),this,SLOT(plotFile(QString))); + } void MainWindow::fileDownloadComplete() @@ -169,6 +207,14 @@ void MainWindow::fileDownloadComplete() } } +void MainWindow::askGlobalRescan() +{ + for(int i=0;ifolderViews.count();i++) + { + this->folderViews.at(i)->refreshFolder(); + } +} + void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -44,7 +44,7 @@ class MainWindow : public QMainWindow public: explicit MainWindow(int OMP_THREADS,QWidget *parent = 0); ~MainWindow(); - + QString getFilePath(const QString& name); public slots: void itemDoubleClicked(QListWidgetItem *item); void plotFile(const QString& File); @@ -53,6 +53,7 @@ public slots: void updateProgress(int threadId,int percentProgress); void addFolderView(); void fileDownloadComplete(); + void askGlobalRescan(); protected: void changeEvent(QEvent *e); @@ -62,6 +63,7 @@ private: QList pendingDownloads; ThemisDataFile fileReader; QList progress; + int* progressThreadIds; QWidget* progressWidget; QVBoxLayout*progressLayout; int OMP_THREADS; diff --git a/src/themisdatafile.cpp b/src/themisdatafile.cpp --- a/src/themisdatafile.cpp +++ b/src/themisdatafile.cpp @@ -28,10 +28,10 @@ #include #include #include +#include ThemisDataFile::ThemisDataFile(QObject *parent) : QThread(parent) { - // this->moveToThread(this); } ThemisDataFile::~ThemisDataFile() @@ -48,29 +48,32 @@ void ThemisDataFile::parseFile(const QSt inline double __decodeVal(int ofset,unsigned char* data) { if(data[ofset]=='-') - return -1.0 * ((10.0 * (data[ofset+1] & 0x0F)) - + (1.0 * (data[ofset+2] & 0x0F)) - + (0.1 * (data[ofset+4] & 0x0F)) - + (0.01 * (data[ofset+5] & 0x0F)) - + (0.001 * (data[ofset+6] & 0x0F)) + return -0.001 * (double)( + (10000 * (int)(data[ofset+1] & 0x0F)) + + (1000 * (int)(data[ofset+2] & 0x0F)) + + (100 * (int)(data[ofset+4] & 0x0F)) + + (10 * (int)(data[ofset+5] & 0x0F)) + + ( (int)(data[ofset+6] & 0x0F)) ); else { if(data[ofset+1]=='-') { - return -1.0 * ((1.0 * (data[ofset+2] & 0x0F)) - + (0.1 * (data[ofset+4] & 0x0F)) - + (0.01 * (data[ofset+5] & 0x0F)) - + (0.001 * (data[ofset+6] & 0x0F)) + return -0.001 * (double)( + (1000 * (int)(data[ofset+2] & 0x0F)) + + (100 * (int)(data[ofset+4] & 0x0F)) + + (10 * (int)(data[ofset+5] & 0x0F)) + + ( (int)(data[ofset+6] & 0x0F)) ); } else { - return ((10.0 * (data[ofset+1] & 0x0F)) - + (1.0 * (data[ofset+2] & 0x0F)) - + (0.1 * (data[ofset+4] & 0x0F)) - + (0.01 * (data[ofset+5] & 0x0F)) - + (0.001 * (data[ofset+6] & 0x0F)) + return 0.001 * (double)( + (10000 * (int)(data[ofset+1] & 0x0F)) + + (1000 * (int)(data[ofset+2] & 0x0F)) + + (100 * (int)(data[ofset+4] & 0x0F)) + + (10 * (int)(data[ofset+5] & 0x0F)) + + ( (int)(data[ofset+6] & 0x0F)) ); } } @@ -93,7 +96,35 @@ inline QTime __decodeTime(int ofset,unsi return QTime(h,m,s,ms); } +double __decodeTimeFromEpochMs(int ofset,unsigned char* data) +{ + struct tm t; + time_t t_of_day; + t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; + t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); + t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); + t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); + t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); + t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); + int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); + t_of_day = mktime(&t); + return (t_of_day*1000.0)+ms; +} +double __decodeTimeFromEpoch(int ofset,unsigned char* data) +{ + struct tm t; + time_t t_of_day; + t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; + t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); + t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); + t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); + t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); + t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); + int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); + t_of_day = mktime(&t); + return t_of_day+(ms*0.001); +} void ThemisDataFile::run() { FILE* dataFile; @@ -106,9 +137,6 @@ void ThemisDataFile::run() double _x=0.0; char* line; QCPData data1,data2,data3; - // QCPData data12,data22,data32; - // QCPData data13,data23,data33; - // QCPData data14,data24,data34; if(dataFile != NULL) { fseek(dataFile, 0L, SEEK_END); @@ -138,13 +166,7 @@ void ThemisDataFile::run() #pragma omp for for(int i=0;i<(FileSize/(58));i++) { - line[(i*58)+23]='\0'; - line[(i*58)+56]='\0'; - //_x= QDateTime::fromString(line+(i*58),"yyyy-MM-ddThh:mm:ss.zzz").toMSecsSinceEpoch(); - // sscanf(line+(i*58)+24,"%lf %lf %lf",&_y1,&_y2,&_y3); - date.setDate(__decodeDate((i*58),(unsigned char*)line)); - date.setTime(__decodeTime(((i*58)+11),(unsigned char*)line)); - _x= date.toMSecsSinceEpoch(); + _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line); data1.key=_x; data2.key=_x; data3.key=_x;