##// END OF EJS Templates
Drag and drop implemented, improved plot interactions.
jeandet -
r1:a1d6d9df437f default
parent child
Show More
@@ -0,0 +1,131
1 #include "folderlistwidget.h"
2 #include <QDragEnterEvent>
3 #include <QMimeData>
4 #include <QDebug>
5 #include <QDrag>
6 #include <QApplication>
7 #include <QMap>
8 #include <QVariant>
9 #include <QDir>
10
11 FolderListWidget::FolderListWidget(QWidget *parent) : QListWidget(parent)
12 {
13 this->setSelectionMode(QAbstractItemView::ExtendedSelection);
14 this->setAcceptDrops(true);
15 this->setDragEnabled(true);
16 this->setDragDropMode(QAbstractItemView::DragDrop);
17 this->setDefaultDropAction(Qt::MoveAction);
18 this->p_mainWin=NULL;
19 this->p_path="";
20 }
21
22 FolderListWidget::~FolderListWidget()
23 {
24
25 }
26
27 bool FolderListWidget::contains(const QString &name)
28 {
29 for(int i=0;i<this->count();i++)
30 {
31 if(this->item(i)->text()==name)
32 return true;
33 }
34 return false;
35 }
36
37 bool FolderListWidget::isDraging(const QString &name)
38 {
39 for(int i=0;i<this->lastDragItems.count();i++)
40 {
41 if(lastDragItems.at(i)==name)
42 return true;
43 }
44 return false;
45 }
46
47 void FolderListWidget::setMainWindow(MainWindow *mw)
48 {
49 this->p_mainWin = mw;
50 }
51
52 void FolderListWidget::setPath(const QString &path)
53 {
54 this->p_path = path;
55 this->lastDragItems.clear();
56 }
57
58 void FolderListWidget::dragEnterEvent(QDragEnterEvent *event)
59 {
60 const QMimeData *mimeData = event->mimeData();
61 QStringList mimeFormats = mimeData->formats();
62 bool containsFile=false;
63 if(mimeFormats.count())
64 {
65 QByteArray encoded = mimeData->data("application/x-qabstractitemmodeldatalist");
66 QDataStream stream(&encoded, QIODevice::ReadOnly);
67 while (!stream.atEnd())
68 {
69 int row, col;
70 QMap<int, QVariant> roleDataMap;
71 stream >> row >> col >> roleDataMap;
72 if(this->contains(roleDataMap[0].toString()))
73 containsFile = true;
74 }
75 }
76 if(!containsFile)
77 {
78 QListWidget::dragEnterEvent(event);
79 }
80 else
81 {
82 this->lastDragItems.clear();
83 QList<QListWidgetItem*> selItems = this->selectedItems();
84 for(int i=0;i<selItems.count();i++)
85 {
86 lastDragItems.append(selItems.at(i)->text());
87 }
88 }
89
90 }
91
92 void FolderListWidget::dragMoveEvent(QDragMoveEvent *event)
93 {
94 QListWidget::dragMoveEvent(event);
95 }
96
97 void FolderListWidget::dragLeaveEvent(QDragLeaveEvent *event)
98 {
99 QListWidget::dragLeaveEvent(event);
100 this->lastDragItems.clear();
101 }
102
103 void FolderListWidget::dropEvent(QDropEvent *event)
104 {
105 QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
106 QDataStream stream(&encoded, QIODevice::ReadOnly);
107 while (!stream.atEnd())
108 {
109 int row, col;
110 QMap<int, QVariant> roleDataMap;
111 stream >> row >> col >> roleDataMap;
112 QString name=roleDataMap[0].toString();
113 QString oldPath = p_mainWin->getFilePath(name);
114 if((oldPath!="") && (p_path!=""))
115 {
116 if(QFile::rename(oldPath+"/"+name,this->p_path+"/"+name))
117 QListWidget::dropEvent(event);
118 emit askGlobalRescan();
119 }
120 }
121 }
122
123 void FolderListWidget::mousePressEvent(QMouseEvent *event)
124 {
125 QListWidget::mousePressEvent(event);
126 }
127
128 void FolderListWidget::mouseMoveEvent(QMouseEvent *event)
129 {
130 QListWidget::mouseMoveEvent(event);
131 }
@@ -0,0 +1,36
1 #ifndef FOLDERLISTWIDGET_H
2 #define FOLDERLISTWIDGET_H
3
4 #include <QWidget>
5 #include <QListWidget>
6 #include <QPoint>
7 #include <mainwindow.h>
8
9 class FolderListWidget : public QListWidget
10 {
11 Q_OBJECT
12 public:
13 explicit FolderListWidget(QWidget *parent = 0);
14 ~FolderListWidget();
15 bool contains(const QString& name);
16 bool isDraging(const QString& name);
17 void setMainWindow(MainWindow* mw);
18 void setPath(const QString& path);
19 signals:
20 void askGlobalRescan();
21 public slots:
22 protected:
23 void dragEnterEvent(QDragEnterEvent *event);
24 void dragMoveEvent(QDragMoveEvent *event);
25 void dragLeaveEvent(QDragLeaveEvent* event);
26 void dropEvent(QDropEvent *event);
27 void mousePressEvent(QMouseEvent *event);
28 void mouseMoveEvent(QMouseEvent *event);
29
30 private:
31 QStringList lastDragItems;
32 MainWindow* p_mainWin;
33 QString p_path;
34 };
35
36 #endif // FOLDERLISTWIDGET_H
@@ -23,7 +23,8 SOURCES += src/main.cpp\
23 src/themisdatafile.cpp \
23 src/themisdatafile.cpp \
24 src/filedownloader.cpp \
24 src/filedownloader.cpp \
25 src/folderview.cpp \
25 src/folderview.cpp \
26 src/toolbarcontainer.cpp
26 src/toolbarcontainer.cpp \
27 src/folderlistwidget.cpp
27
28
28 HEADERS += src/mainwindow.h \
29 HEADERS += src/mainwindow.h \
29 src/SocExplorerPlot.h \
30 src/SocExplorerPlot.h \
@@ -31,7 +32,8 HEADERS += src/mainwindow.h \
31 src/themisdatafile.h \
32 src/themisdatafile.h \
32 src/filedownloader.h \
33 src/filedownloader.h \
33 src/folderview.h \
34 src/folderview.h \
34 src/toolbarcontainer.h
35 src/toolbarcontainer.h \
36 src/folderlistwidget.h
35
37
36 FORMS += src/mainwindow.ui \
38 FORMS += src/mainwindow.ui \
37 src/folderview.ui
39 src/folderview.ui
@@ -42,6 +42,7 SocExplorerPlot::SocExplorerPlot(QWidget
42 this->mouse_hold = false;
42 this->mouse_hold = false;
43 this->m_plot->setNoAntialiasingOnDrag(true);
43 this->m_plot->setNoAntialiasingOnDrag(true);
44 this->show();
44 this->show();
45 this->m_plot->legend->setVisible(true);
45
46
46 }
47 }
47
48
@@ -385,6 +386,46 void SocExplorerPlot::keyPressEvent(QKey
385 case Qt::Key_M:
386 case Qt::Key_M:
386 this->rescaleAxis();
387 this->rescaleAxis();
387 break;
388 break;
389 case Qt::Key_Left:
390 if(!ctrl_hold)
391 {
392 move(-0.1,Qt::Horizontal);
393 }
394 else
395 {
396 zoom(2,this->width()/2,Qt::Horizontal);
397 }
398 break;
399 case Qt::Key_Right:
400 if(!ctrl_hold)
401 {
402 move(0.1,Qt::Horizontal);
403 }
404 else
405 {
406 zoom(0.5,this->width()/2,Qt::Horizontal);
407 }
408 break;
409 case Qt::Key_Up:
410 if(!ctrl_hold)
411 {
412 move(0.1,Qt::Vertical);
413 }
414 else
415 {
416 zoom(0.5,this->height()/2,Qt::Vertical);
417 }
418 break;
419 case Qt::Key_Down:
420 if(!ctrl_hold)
421 {
422 move(-0.1,Qt::Vertical);
423 }
424 else
425 {
426 zoom(2,this->height()/2,Qt::Vertical);
427 }
428 break;
388 default:
429 default:
389 QWidget::keyPressEvent(event);
430 QWidget::keyPressEvent(event);
390 break;
431 break;
@@ -418,10 +459,8 void SocExplorerPlot::wheelEvent(QWheelE
418 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
459 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
419 {
460 {
420 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
461 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
421 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(Qt::Vertical);
462 zoom(factor,event->pos().y(),Qt::Vertical);
422 axis->scaleRange(factor, axis->pixelToCoord(event->pos().y()));
423 }
463 }
424 this->m_plot->replot();
425 QWidget::wheelEvent(event);
464 QWidget::wheelEvent(event);
426 return;
465 return;
427 }
466 }
@@ -430,17 +469,12 void SocExplorerPlot::wheelEvent(QWheelE
430 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
469 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
431 {
470 {
432 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
471 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
433 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(Qt::Horizontal);
472 zoom(factor,event->pos().x(),Qt::Horizontal);
434 axis->scaleRange(factor, axis->pixelToCoord(event->pos().x()));
435 }
473 }
436 this->m_plot->replot();
437 QWidget::wheelEvent(event);
474 QWidget::wheelEvent(event);
438 return;
475 return;
439 }
476 }
440 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
477 move(wheelSteps/10,Qt::Horizontal);
441 double rg = (Haxis->range().upper - Haxis->range().lower)*(wheelSteps/10);
442 Haxis->setRange(Haxis->range().lower+(rg), Haxis->range().upper+(rg));
443 this->m_plot->replot();
444 QWidget::wheelEvent(event);
478 QWidget::wheelEvent(event);
445 }
479 }
446
480
@@ -468,6 +502,22 void SocExplorerPlot::mouseReleaseEvent(
468 QWidget::mouseReleaseEvent(event);
502 QWidget::mouseReleaseEvent(event);
469 }
503 }
470
504
505 void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation)
506 {
507 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation);
508 axis->scaleRange(factor, axis->pixelToCoord(center));
509 this->m_plot->replot();
510 }
511
512 void SocExplorerPlot::move(double factor, Qt::Orientation orientation)
513 {
514 QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation);
515 double rg = (axis->range().upper - axis->range().lower)*(factor);
516 axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg));
517 this->m_plot->replot();
518 }
519
520
471 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
521 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
472 {
522 {
473 if(mouse_hold)
523 if(mouse_hold)
@@ -70,6 +70,8 protected:
70 void mouseReleaseEvent(QMouseEvent *);
70 void mouseReleaseEvent(QMouseEvent *);
71
71
72 private:
72 private:
73 void zoom(double factor, int center, Qt::Orientation orientation);
74 void move(double factor, Qt::Orientation orientation);
73 QCustomPlot* m_plot;
75 QCustomPlot* m_plot;
74 QGridLayout* m_mainlayout;
76 QGridLayout* m_mainlayout;
75 bool ctrl_hold;
77 bool ctrl_hold;
@@ -23,26 +23,26
23 #include "ui_folderview.h"
23 #include "ui_folderview.h"
24 #include <QFileDialog>
24 #include <QFileDialog>
25 #include <QLabel>
25 #include <QLabel>
26 #include <QDebug>
26
27
27 FolderView::FolderView(QWidget *parent) :
28 p_FolderView::p_FolderView(QWidget *parent) :
28 QDockWidget(parent),
29 QWidget(parent),
29 ui(new Ui::FolderView)
30 ui(new Ui::p_FolderView)
30 {
31 {
31 ui->setupUi(this);
32 ui->setupUi(this);
32 this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
33 this->setAllowedAreas(Qt::AllDockWidgetAreas);
34 this->setWidget(this->ui->groupBox);
35 connect(this->ui->setFolderQpb,SIGNAL(clicked()),this,SLOT(openFolder()));
33 connect(this->ui->setFolderQpb,SIGNAL(clicked()),this,SLOT(openFolder()));
36 connect(this->ui->refreshQpb,SIGNAL(clicked()),this,SLOT(refreshFolder()));
34 connect(this->ui->refreshQpb,SIGNAL(clicked()),this,SLOT(refreshFolder()));
37 connect(this->ui->listWidget,SIGNAL(itemActivated(QListWidgetItem*)),this,SLOT(itemActivated(QListWidgetItem*)));
35 connect(this->ui->listWidget,SIGNAL(itemActivated(QListWidgetItem*)),this,SLOT(itemActivated(QListWidgetItem*)));
36 //this->ui->listWidget->installEventFilter(this);
37 connect(this->ui->listWidget,SIGNAL(askGlobalRescan()),this,SIGNAL(askGlobalRescan()));
38 }
38 }
39
39
40 FolderView::~FolderView()
40 p_FolderView::~p_FolderView()
41 {
41 {
42 delete ui;
42 delete ui;
43 }
43 }
44
44
45 bool FolderView::contains(const QString &fileName)
45 bool p_FolderView::contains(const QString &fileName)
46 {
46 {
47 for(int i=0;i<this->ui->listWidget->count();i++)
47 for(int i=0;i<this->ui->listWidget->count();i++)
48 {
48 {
@@ -54,16 +54,31 bool FolderView::contains(const QString
54 return false;
54 return false;
55 }
55 }
56
56
57 void FolderView::openFolder()
57 bool p_FolderView::isDraging(const QString &name)
58 {
59 return this->ui->listWidget->isDraging(name);
60 }
61
62 void p_FolderView::setMainWindow(MainWindow *mw)
58 {
63 {
59 currentFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),NULL,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
64 this->ui->listWidget->setMainWindow(mw);
65 }
66
67 QString p_FolderView::currentFolder()
68 {
69 return p_currentFolder;
70 }
71
72 void p_FolderView::openFolder()
73 {
74 p_currentFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),NULL,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
60 refreshFolder();
75 refreshFolder();
61 }
76 }
62
77
63 void FolderView::refreshFolder()
78 void p_FolderView::refreshFolder()
64 {
79 {
65 QDir dir;
80 QDir dir;
66 dir.setPath(currentFolder);
81 dir.setPath(p_currentFolder);
67 this->ui->listWidget->clear();
82 this->ui->listWidget->clear();
68 dir.setFilter(QDir::Files | QDir::NoSymLinks);
83 dir.setFilter(QDir::Files | QDir::NoSymLinks);
69 dir.setSorting(QDir::Name);
84 dir.setSorting(QDir::Name);
@@ -75,15 +90,16 void FolderView::refreshFolder()
75 this->ui->listWidget->addItem(list.at(i).fileName());
90 this->ui->listWidget->addItem(list.at(i).fileName());
76 }
91 }
77 }
92 }
78 this->ui->groupBox->setTitle(currentFolder);
93 this->ui->listWidget->setPath(p_currentFolder);
94 this->ui->groupBox->setTitle(p_currentFolder);
79 }
95 }
80
96
81 void FolderView::itemActivated(QListWidgetItem *item)
97 void p_FolderView::itemActivated(QListWidgetItem *item)
82 {
98 {
83 emit itemActivated(currentFolder+'/'+item->text());
99 emit itemActivated(p_currentFolder+'/'+item->text());
84 }
100 }
85
101
86 void FolderView::changeEvent(QEvent *e)
102 void p_FolderView::changeEvent(QEvent *e)
87 {
103 {
88 QWidget::changeEvent(e);
104 QWidget::changeEvent(e);
89 switch (e->type()) {
105 switch (e->type()) {
@@ -94,3 +110,56 void FolderView::changeEvent(QEvent *e)
94 break;
110 break;
95 }
111 }
96 }
112 }
113
114 bool p_FolderView::eventFilter(QObject *object, QEvent *event)
115 {
116 if(object == this->ui->listWidget )
117 {
118 qDebug()<<event->type();
119 if(event->type() == QEvent::Drop)
120 {
121 QDropEvent *DropEvent = static_cast<QDropEvent *>(event);
122 qDebug()<< DropEvent->mimeData();
123 }
124 }
125 return false;
126 }
127
128
129 FolderView::FolderView(MainWindow *parent)
130 :QDockWidget(parent)
131 {
132 this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
133 this->setAllowedAreas(Qt::AllDockWidgetAreas);
134 this->ui = new p_FolderView(this);
135 this->setWidget(this->ui);
136 connect(this->ui,SIGNAL(itemActivated(QString)),this,SIGNAL(itemActivated(QString)));
137 connect(this->ui,SIGNAL(askGlobalRescan()),this,SIGNAL(askGlobalRescan()));
138 this->ui->setMainWindow(parent);
139 }
140
141 bool FolderView::contains(const QString &fileName)
142 {
143 return ui->contains(fileName);
144 }
145
146 bool FolderView::isDraging(const QString &name)
147 {
148 return this->ui->isDraging(name);
149 }
150
151 QString FolderView::currentFolder()
152 {
153 return this->ui->currentFolder();
154 }
155
156 void FolderView::openFolder()
157 {
158 this->ui->openFolder();
159 }
160
161 void FolderView::refreshFolder()
162 {
163 this->ui->refreshFolder();
164 }
165
@@ -25,32 +25,61
25 #include <QWidget>
25 #include <QWidget>
26 #include <QDockWidget>
26 #include <QDockWidget>
27 #include <QListWidget>
27 #include <QListWidget>
28
28 #include <QEvent>
29 #include <QDropEvent>
30 class MainWindow;
29 namespace Ui {
31 namespace Ui {
30 class FolderView;
32 class p_FolderView;
31 }
33 }
32
34
35 class p_FolderView;
36
33 class FolderView : public QDockWidget
37 class FolderView : public QDockWidget
34 {
38 {
35 Q_OBJECT
39 Q_OBJECT
40 public:
41 FolderView (MainWindow *parent = 0);
42 ~FolderView(){}
43 bool contains(const QString& fileName);
44 bool isDraging(const QString& name);
45 QString currentFolder();
46 public slots:
47 void openFolder();
48 void refreshFolder();
49 signals:
50 void askGlobalRescan();
51 void itemActivated(const QString& item);
52 private:
53 p_FolderView* ui;
54 };
55
56
57 class p_FolderView : public QWidget
58 {
59 Q_OBJECT
36
60
37 public:
61 public:
38 explicit FolderView(QWidget *parent = 0);
62 explicit p_FolderView(QWidget *parent = 0);
39 ~FolderView();
63 ~p_FolderView();
40 bool contains(const QString& fileName);
64 bool contains(const QString& fileName);
65 bool isDraging(const QString& name);
66 void setMainWindow(MainWindow* mw);
67 QString currentFolder();
41 public slots:
68 public slots:
42 void openFolder();
69 void openFolder();
43 void refreshFolder();
70 void refreshFolder();
44 void itemActivated(QListWidgetItem * item);
71 void itemActivated(QListWidgetItem * item);
45 signals:
72 signals:
73 void askGlobalRescan();
46 void itemActivated(const QString& item);
74 void itemActivated(const QString& item);
47 protected:
75 protected:
48 void changeEvent(QEvent *e);
76 void changeEvent(QEvent *e);
77 bool eventFilter(QObject *object, QEvent *event);
49
78
50 private:
79 private:
51 Ui::FolderView *ui;
80 Ui::p_FolderView *ui;
52 QWidget* _Widget;
81 QWidget* _Widget;
53 QString currentFolder;
82 QString p_currentFolder;
54 };
83 };
55
84
56 #endif // FOLDERVIEW_H
85 #endif // FOLDERVIEW_H
@@ -1,7 +1,7
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
2 <ui version="4.0">
3 <class>FolderView</class>
3 <class>p_FolderView</class>
4 <widget class="QWidget" name="FolderView">
4 <widget class="QWidget" name="p_FolderView">
5 <property name="geometry">
5 <property name="geometry">
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
@@ -13,27 +13,27
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Test</string>
14 <string>Test</string>
15 </property>
15 </property>
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="0">
16 <widget class="QGroupBox" name="groupBox">
18 <widget class="QGroupBox" name="groupBox">
17 <property name="geometry">
18 <rect>
19 <x>9</x>
20 <y>9</y>
21 <width>282</width>
22 <height>268</height>
23 </rect>
24 </property>
25 <property name="title">
19 <property name="title">
26 <string>No Folder</string>
20 <string>No Folder</string>
27 </property>
21 </property>
28 <layout class="QGridLayout" name="gridLayout_2">
22 <layout class="QGridLayout" name="gridLayout_2">
29 <item row="0" column="0" colspan="3">
23 <item row="0" column="0" colspan="3">
30 <widget class="QListWidget" name="listWidget">
24 <widget class="FolderListWidget" name="listWidget">
25 <property name="acceptDrops">
26 <bool>true</bool>
27 </property>
31 <property name="editTriggers">
28 <property name="editTriggers">
32 <set>QAbstractItemView::NoEditTriggers</set>
29 <set>QAbstractItemView::NoEditTriggers</set>
33 </property>
30 </property>
34 <property name="dragEnabled">
31 <property name="dragEnabled">
35 <bool>true</bool>
32 <bool>true</bool>
36 </property>
33 </property>
34 <property name="dragDropOverwriteMode">
35 <bool>false</bool>
36 </property>
37 <property name="dragDropMode">
37 <property name="dragDropMode">
38 <enum>QAbstractItemView::DragDrop</enum>
38 <enum>QAbstractItemView::DragDrop</enum>
39 </property>
39 </property>
@@ -84,7 +84,16
84 </item>
84 </item>
85 </layout>
85 </layout>
86 </widget>
86 </widget>
87 </item>
88 </layout>
87 </widget>
89 </widget>
90 <customwidgets>
91 <customwidget>
92 <class>FolderListWidget</class>
93 <extends>QListWidget</extends>
94 <header>folderlistwidget.h</header>
95 </customwidget>
96 </customwidgets>
88 <resources>
97 <resources>
89 <include location="../resources/qlop.qrc"/>
98 <include location="../resources/qlop.qrc"/>
90 </resources>
99 </resources>
@@ -46,3 +46,5 int main(int argc, char *argv[])
46
46
47 return a.exec();
47 return a.exec();
48 }
48 }
49
50
@@ -55,6 +55,7 MainWindow::MainWindow(int OMP_THREADS,
55 this->progressLayout = new QVBoxLayout(this->progressWidget);
55 this->progressLayout = new QVBoxLayout(this->progressWidget);
56 this->progressWidget->setLayout(this->progressLayout);
56 this->progressWidget->setLayout(this->progressLayout);
57 this->progressWidget->setWindowModality(Qt::WindowModal);
57 this->progressWidget->setWindowModality(Qt::WindowModal);
58 progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
58 for(int i=0;i<OMP_THREADS;i++)
59 for(int i=0;i<OMP_THREADS;i++)
59 {
60 {
60 this->progress.append(new QProgressBar(this->progressWidget));
61 this->progress.append(new QProgressBar(this->progressWidget));
@@ -63,6 +64,7 MainWindow::MainWindow(int OMP_THREADS,
63 connect(&this->fileReader,SIGNAL(updateProgress(int,int)),this,SLOT(updateProgress(int,int)));
64 connect(&this->fileReader,SIGNAL(updateProgress(int,int)),this,SLOT(updateProgress(int,int)));
64 this->progressLayout->addWidget(this->progress.last());
65 this->progressLayout->addWidget(this->progress.last());
65 this->progressWidget->hide();
66 this->progressWidget->hide();
67 this->progressThreadIds[i] = -1;
66 }
68 }
67 this->progressWidget->setWindowTitle("Loading File");
69 this->progressWidget->setWindowTitle("Loading File");
68 }
70 }
@@ -72,6 +74,16 MainWindow::~MainWindow()
72 delete ui;
74 delete ui;
73 }
75 }
74
76
77 QString MainWindow::getFilePath(const QString &name)
78 {
79 for(int i=0;i<this->folderViews.count();i++)
80 {
81 if(folderViews.at(i)->isDraging(name))
82 return folderViews.at(i)->currentFolder();
83 }
84 return "";
85 }
86
75
87
76 void MainWindow::itemDoubleClicked(QListWidgetItem* item)
88 void MainWindow::itemDoubleClicked(QListWidgetItem* item)
77 {
89 {
@@ -96,7 +108,14 void MainWindow::plotFile(const QString
96
108
97 void MainWindow::dataReady(QCPDataMap *ch1, QCPDataMap *ch2, QCPDataMap *ch3)
109 void MainWindow::dataReady(QCPDataMap *ch1, QCPDataMap *ch2, QCPDataMap *ch3)
98 {
110 {
111 for(int i=0;i<OMP_THREADS;i++)
112 {
113 progressThreadIds[i]=-1;
114 }
99 this->progressWidget->hide();
115 this->progressWidget->hide();
116 this->ui->Plot->setGraphName(0,"MAG_X");
117 this->ui->Plot->setGraphName(1,"MAG_Y");
118 this->ui->Plot->setGraphName(2,"MAG_Z");
100 this->ui->Plot->setGraphData(0,ch1,false,false);
119 this->ui->Plot->setGraphData(0,ch1,false,false);
101 this->ui->Plot->setGraphData(1,ch2,false,false);
120 this->ui->Plot->setGraphData(1,ch2,false,false);
102 this->ui->Plot->setGraphData(2,ch3,false,false);
121 this->ui->Plot->setGraphData(2,ch3,false,false);
@@ -131,17 +150,36 void MainWindow::downloadData(const QDat
131
150
132 void MainWindow::updateProgress(int threadId, int percentProgress)
151 void MainWindow::updateProgress(int threadId, int percentProgress)
133 {
152 {
134 if(threadId<progress.count())
153 bool updated=false;
154 for(int i=0;i<OMP_THREADS;i++)
155 {
156 if(progressThreadIds[i]==threadId)
157 {
135 this->progress.at(threadId)->setValue(percentProgress);
158 this->progress.at(threadId)->setValue(percentProgress);
159 updated=true;
160 }
161 }
162 if(Q_UNLIKELY(updated==false))
163 {
164 for(int i=0;i<OMP_THREADS;i++)
165 {
166 if(progressThreadIds[i]==-1)
167 {
168 progressThreadIds[i] = threadId;
169 updateProgress(threadId,percentProgress);
170 }
171 }
172 }
136 }
173 }
137
174
138 void MainWindow::addFolderView()
175 void MainWindow::addFolderView()
139 {
176 {
140 this->folderViews.append(new FolderView());
177 this->folderViews.append(new FolderView(this));
141 this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last());
178 this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last());
142 this->folderViews.last()->setWindowTitle( "test");//QString("Folder View %1").arg(this->folderViews.length()));
179 this->folderViews.last()->setWindowTitle( QString("Folder View %1").arg(this->folderViews.length()));
143 this->folderViews.last()->setAllowedAreas(Qt::AllDockWidgetAreas);
180 this->folderViews.last()->setAllowedAreas(Qt::AllDockWidgetAreas);
144 connect(this->folderViews.last(),SIGNAL(itemActivated(QString)),this,SLOT(plotFile(QString)));
181 connect(this->folderViews.last(),SIGNAL(itemActivated(QString)),this,SLOT(plotFile(QString)));
182
145 }
183 }
146
184
147 void MainWindow::fileDownloadComplete()
185 void MainWindow::fileDownloadComplete()
@@ -169,6 +207,14 void MainWindow::fileDownloadComplete()
169 }
207 }
170 }
208 }
171
209
210 void MainWindow::askGlobalRescan()
211 {
212 for(int i=0;i<this->folderViews.count();i++)
213 {
214 this->folderViews.at(i)->refreshFolder();
215 }
216 }
217
172 void MainWindow::changeEvent(QEvent *e)
218 void MainWindow::changeEvent(QEvent *e)
173 {
219 {
174 QMainWindow::changeEvent(e);
220 QMainWindow::changeEvent(e);
@@ -44,7 +44,7 class MainWindow : public QMainWindow
44 public:
44 public:
45 explicit MainWindow(int OMP_THREADS,QWidget *parent = 0);
45 explicit MainWindow(int OMP_THREADS,QWidget *parent = 0);
46 ~MainWindow();
46 ~MainWindow();
47
47 QString getFilePath(const QString& name);
48 public slots:
48 public slots:
49 void itemDoubleClicked(QListWidgetItem *item);
49 void itemDoubleClicked(QListWidgetItem *item);
50 void plotFile(const QString& File);
50 void plotFile(const QString& File);
@@ -53,6 +53,7 public slots:
53 void updateProgress(int threadId,int percentProgress);
53 void updateProgress(int threadId,int percentProgress);
54 void addFolderView();
54 void addFolderView();
55 void fileDownloadComplete();
55 void fileDownloadComplete();
56 void askGlobalRescan();
56 protected:
57 protected:
57 void changeEvent(QEvent *e);
58 void changeEvent(QEvent *e);
58
59
@@ -62,6 +63,7 private:
62 QList<FileDownloader*> pendingDownloads;
63 QList<FileDownloader*> pendingDownloads;
63 ThemisDataFile fileReader;
64 ThemisDataFile fileReader;
64 QList<QProgressBar*> progress;
65 QList<QProgressBar*> progress;
66 int* progressThreadIds;
65 QWidget* progressWidget;
67 QWidget* progressWidget;
66 QVBoxLayout*progressLayout;
68 QVBoxLayout*progressLayout;
67 int OMP_THREADS;
69 int OMP_THREADS;
@@ -28,10 +28,10
28 #include <omp.h>
28 #include <omp.h>
29 #include <QTimer>
29 #include <QTimer>
30 #include <QElapsedTimer>
30 #include <QElapsedTimer>
31 #include <time.h>
31
32
32 ThemisDataFile::ThemisDataFile(QObject *parent) : QThread(parent)
33 ThemisDataFile::ThemisDataFile(QObject *parent) : QThread(parent)
33 {
34 {
34 // this->moveToThread(this);
35 }
35 }
36
36
37 ThemisDataFile::~ThemisDataFile()
37 ThemisDataFile::~ThemisDataFile()
@@ -48,29 +48,32 void ThemisDataFile::parseFile(const QSt
48 inline double __decodeVal(int ofset,unsigned char* data)
48 inline double __decodeVal(int ofset,unsigned char* data)
49 {
49 {
50 if(data[ofset]=='-')
50 if(data[ofset]=='-')
51 return -1.0 * ((10.0 * (data[ofset+1] & 0x0F))
51 return -0.001 * (double)(
52 + (1.0 * (data[ofset+2] & 0x0F))
52 (10000 * (int)(data[ofset+1] & 0x0F))
53 + (0.1 * (data[ofset+4] & 0x0F))
53 + (1000 * (int)(data[ofset+2] & 0x0F))
54 + (0.01 * (data[ofset+5] & 0x0F))
54 + (100 * (int)(data[ofset+4] & 0x0F))
55 + (0.001 * (data[ofset+6] & 0x0F))
55 + (10 * (int)(data[ofset+5] & 0x0F))
56 + ( (int)(data[ofset+6] & 0x0F))
56 );
57 );
57 else
58 else
58 {
59 {
59 if(data[ofset+1]=='-')
60 if(data[ofset+1]=='-')
60 {
61 {
61 return -1.0 * ((1.0 * (data[ofset+2] & 0x0F))
62 return -0.001 * (double)(
62 + (0.1 * (data[ofset+4] & 0x0F))
63 (1000 * (int)(data[ofset+2] & 0x0F))
63 + (0.01 * (data[ofset+5] & 0x0F))
64 + (100 * (int)(data[ofset+4] & 0x0F))
64 + (0.001 * (data[ofset+6] & 0x0F))
65 + (10 * (int)(data[ofset+5] & 0x0F))
66 + ( (int)(data[ofset+6] & 0x0F))
65 );
67 );
66 }
68 }
67 else
69 else
68 {
70 {
69 return ((10.0 * (data[ofset+1] & 0x0F))
71 return 0.001 * (double)(
70 + (1.0 * (data[ofset+2] & 0x0F))
72 (10000 * (int)(data[ofset+1] & 0x0F))
71 + (0.1 * (data[ofset+4] & 0x0F))
73 + (1000 * (int)(data[ofset+2] & 0x0F))
72 + (0.01 * (data[ofset+5] & 0x0F))
74 + (100 * (int)(data[ofset+4] & 0x0F))
73 + (0.001 * (data[ofset+6] & 0x0F))
75 + (10 * (int)(data[ofset+5] & 0x0F))
76 + ( (int)(data[ofset+6] & 0x0F))
74 );
77 );
75 }
78 }
76 }
79 }
@@ -93,7 +96,35 inline QTime __decodeTime(int ofset,unsi
93 return QTime(h,m,s,ms);
96 return QTime(h,m,s,ms);
94 }
97 }
95
98
99 double __decodeTimeFromEpochMs(int ofset,unsigned char* data)
100 {
101 struct tm t;
102 time_t t_of_day;
103 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
104 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
105 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
106 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
107 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
108 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
109 int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
110 t_of_day = mktime(&t);
111 return (t_of_day*1000.0)+ms;
112 }
96
113
114 double __decodeTimeFromEpoch(int ofset,unsigned char* data)
115 {
116 struct tm t;
117 time_t t_of_day;
118 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
119 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
120 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
121 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
122 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
123 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
124 int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
125 t_of_day = mktime(&t);
126 return t_of_day+(ms*0.001);
127 }
97 void ThemisDataFile::run()
128 void ThemisDataFile::run()
98 {
129 {
99 FILE* dataFile;
130 FILE* dataFile;
@@ -106,9 +137,6 void ThemisDataFile::run()
106 double _x=0.0;
137 double _x=0.0;
107 char* line;
138 char* line;
108 QCPData data1,data2,data3;
139 QCPData data1,data2,data3;
109 // QCPData data12,data22,data32;
110 // QCPData data13,data23,data33;
111 // QCPData data14,data24,data34;
112 if(dataFile != NULL)
140 if(dataFile != NULL)
113 {
141 {
114 fseek(dataFile, 0L, SEEK_END);
142 fseek(dataFile, 0L, SEEK_END);
@@ -138,13 +166,7 void ThemisDataFile::run()
138 #pragma omp for
166 #pragma omp for
139 for(int i=0;i<(FileSize/(58));i++)
167 for(int i=0;i<(FileSize/(58));i++)
140 {
168 {
141 line[(i*58)+23]='\0';
169 _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line);
142 line[(i*58)+56]='\0';
143 //_x= QDateTime::fromString(line+(i*58),"yyyy-MM-ddThh:mm:ss.zzz").toMSecsSinceEpoch();
144 // sscanf(line+(i*58)+24,"%lf %lf %lf",&_y1,&_y2,&_y3);
145 date.setDate(__decodeDate((i*58),(unsigned char*)line));
146 date.setTime(__decodeTime(((i*58)+11),(unsigned char*)line));
147 _x= date.toMSecsSinceEpoch();
148 data1.key=_x;
170 data1.key=_x;
149 data2.key=_x;
171 data2.key=_x;
150 data3.key=_x;
172 data3.key=_x;
General Comments 0
You need to be logged in to leave comments. Login now