# HG changeset patch # User Alexis Jeandet # Date 2015-01-30 19:45:26 # Node ID a262e3a4f8e7d5c75e7e6690e6ef6b4f8edf2672 # Parent a1d6d9df437f5f8a2f40274e7f1f065ef23a5deb added zoom box. diff --git a/QLop.pro b/QLop.pro --- a/QLop.pro +++ b/QLop.pro @@ -13,8 +13,8 @@ TEMPLATE = app INCLUDEPATH += src/QCustomPlot src -QMAKE_CXXFLAGS += -fopenmp -QMAKE_LFLAGS += -fopenmp +QMAKE_CXXFLAGS += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx +QMAKE_LFLAGS += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx SOURCES += src/main.cpp\ src/mainwindow.cpp \ diff --git a/src/SocExplorerPlot.cpp b/src/SocExplorerPlot.cpp --- a/src/SocExplorerPlot.cpp +++ b/src/SocExplorerPlot.cpp @@ -24,7 +24,7 @@ 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 | @@ -46,6 +46,11 @@ SocExplorerPlot::SocExplorerPlot(QWidget } +SocExplorerPlot::~SocExplorerPlot() +{ + delete mRubberBand; +} + void SocExplorerPlot::show() { QWidget::show(); @@ -379,6 +384,7 @@ void SocExplorerPlot::keyPressEvent(QKey { case Qt::Key_Control: this->ctrl_hold = true; + setCursor(Qt::CrossCursor); break; case Qt::Key_Shift: this->shift_hold = true; @@ -389,7 +395,7 @@ void SocExplorerPlot::keyPressEvent(QKey case Qt::Key_Left: if(!ctrl_hold) { - move(-0.1,Qt::Horizontal); + move(-0.1,Qt::Horizontal); } else { @@ -399,7 +405,7 @@ void SocExplorerPlot::keyPressEvent(QKey case Qt::Key_Right: if(!ctrl_hold) { - move(0.1,Qt::Horizontal); + move(0.1,Qt::Horizontal); } else { @@ -409,7 +415,7 @@ void SocExplorerPlot::keyPressEvent(QKey case Qt::Key_Up: if(!ctrl_hold) { - move(0.1,Qt::Vertical); + move(0.1,Qt::Vertical); } else { @@ -419,7 +425,7 @@ void SocExplorerPlot::keyPressEvent(QKey case Qt::Key_Down: if(!ctrl_hold) { - move(-0.1,Qt::Vertical); + move(-0.1,Qt::Vertical); } else { @@ -448,6 +454,7 @@ void SocExplorerPlot::keyReleaseEvent(QK QWidget::keyReleaseEvent(event); break; } + setCursor(Qt::ArrowCursor); } void SocExplorerPlot::wheelEvent(QWheelEvent * event) @@ -458,6 +465,7 @@ void SocExplorerPlot::wheelEvent(QWheelE { if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) { + setCursor(Qt::SizeVerCursor); factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); zoom(factor,event->pos().y(),Qt::Vertical); } @@ -468,6 +476,7 @@ void SocExplorerPlot::wheelEvent(QWheelE { 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); } @@ -485,10 +494,21 @@ void SocExplorerPlot::mousePressEvent(QM { 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); } @@ -499,6 +519,23 @@ void SocExplorerPlot::mouseReleaseEvent( { this->mouse_hold = false; } + 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); QWidget::mouseReleaseEvent(event); } @@ -530,6 +567,10 @@ void SocExplorerPlot::mouseMoveEvent(QMo Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff); this->m_plot->replot(); } + if (mRubberBand->isVisible()) + { + mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); + } QWidget::mouseMoveEvent(event); } diff --git a/src/SocExplorerPlot.h b/src/SocExplorerPlot.h --- a/src/SocExplorerPlot.h +++ b/src/SocExplorerPlot.h @@ -25,12 +25,15 @@ #include #include #include +#include +#include class SocExplorerPlot : public QWidget { Q_OBJECT public: explicit SocExplorerPlot(QWidget *parent = 0); + ~SocExplorerPlot(); void setTitle(QString title); void setXaxisLabel(QString label); void setXaxisRange(double lower, double upper); @@ -80,6 +83,9 @@ private: QCPRange DragStartHorzRange; QCPRange DragStartVertRange; QPoint mDragStart; + bool mZoomMode; + QRubberBand * mRubberBand; + QPoint mOrigin; }; #endif // SOCEXPLORERPLOT_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -103,6 +103,7 @@ void MainWindow::plotFile(const QString } this->progressWidget->show(); fileReader.parseFile(File); + this->ui->Plot->setTitle(File); } } @@ -155,8 +156,11 @@ void MainWindow::updateProgress(int thre { if(progressThreadIds[i]==threadId) { - this->progress.at(threadId)->setValue(percentProgress); - updated=true; + if(threadIdprogress.count()) + { + this->progress.at(threadId)->setValue(percentProgress); + updated=true; + } } } if(Q_UNLIKELY(updated==false)) diff --git a/src/themisdatafile.cpp b/src/themisdatafile.cpp --- a/src/themisdatafile.cpp +++ b/src/themisdatafile.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include ThemisDataFile::ThemisDataFile(QObject *parent) : QThread(parent) { @@ -121,9 +121,9 @@ double __decodeTimeFromEpoch(int ofset,u 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)); + double 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); + return (double)t_of_day+((double)ms*(double)0.001); } void ThemisDataFile::run() { @@ -144,7 +144,6 @@ void ThemisDataFile::run() int lineCnt = FileSize/58; int curLine=0; int lastLineUpdate=0; - int threadIndex,numThreads=omp_get_num_threads(); char* fileContent=(char*)malloc(FileSize); if(Q_UNLIKELY(fileContent==NULL))return; fseek(dataFile, 0L, SEEK_SET); @@ -154,45 +153,31 @@ void ThemisDataFile::run() if(fread(fileContent,1,FileSize,dataFile)) { line = fileContent; - if(FileSize > 10000000) - { - lineCnt/=numThreads; - } QDateTime date; timr.start(); -#pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt) - { - threadIndex = omp_get_thread_num(); -#pragma omp for - for(int i=0;i<(FileSize/(58));i++) - { - _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line); - data1.key=_x; - data2.key=_x; - data3.key=_x; - data1.value=__decodeVal(((i*58)+27),(unsigned char*)line); - data2.value=__decodeVal(((i*58)+38),(unsigned char*)line); - data3.value=__decodeVal(((i*58)+49),(unsigned char*)line); -#pragma omp critical + for(int i=0;i<(FileSize/(58));i++) + { +// _x= i; + _x= __decodeTimeFromEpoch((i*58),(unsigned char*)line); + data1.key=_x; + data2.key=_x; + data3.key=_x; + data1.value=__decodeVal(((i*58)+27),(unsigned char*)line); + data2.value=__decodeVal(((i*58)+38),(unsigned char*)line); + data3.value=__decodeVal(((i*58)+49),(unsigned char*)line); + ch1->insertMulti(_x,data1); + ch2->insertMulti(_x,data2); + ch3->insertMulti(_x,data3); + curLine++; + if(lastLineUpdate++>8000) { - ch1->insertMulti(_x,data1); - ch2->insertMulti(_x,data2); - ch3->insertMulti(_x,data3); + lastLineUpdate=0; + int test=(curLine *100/ (lineCnt)); + emit updateProgress(0,test); } - curLine++; - if(lastLineUpdate++>8000) - { - lastLineUpdate=0; - int test=(curLine *100/ (lineCnt)); - emit updateProgress(threadIndex,test); - } - } -#pragma omp barrier - } + } free(fileContent); - } - qDebug()<