@@ -1,110 +1,110 | |||||
1 | #------------------------------------------------- |
|
1 | #------------------------------------------------- | |
2 | # |
|
2 | # | |
3 | # Project created by QtCreator 2015-01-07T02:41:29 |
|
3 | # Project created by QtCreator 2015-01-07T02:41:29 | |
4 | # |
|
4 | # | |
5 | #------------------------------------------------- |
|
5 | #------------------------------------------------- | |
6 |
|
6 | |||
7 | QT += core gui network xml svg |
|
7 | QT += core gui network xml svg | |
8 | CONFIG += pythonqt |
|
8 | CONFIG += pythonqt | |
9 |
|
9 | |||
10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport |
|
10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport | |
11 |
|
11 | |||
12 | DESTDIR =./bin |
|
12 | DESTDIR =./bin | |
13 |
|
13 | |||
14 | TARGET = QLop |
|
14 | TARGET = QLop | |
15 | TEMPLATE = app |
|
15 | TEMPLATE = app | |
16 |
|
16 | |||
17 | LIBS+=-lfftw3 |
|
17 | LIBS+=-lfftw3_threads -lfftw3 | |
18 |
|
18 | |||
19 | INCLUDEPATH += src/QCustomPlot \ |
|
19 | INCLUDEPATH += src/QCustomPlot \ | |
20 | src src/Cassini \ |
|
20 | src src/Cassini \ | |
21 | src/Core src/Core/Widgets \ |
|
21 | src/Core src/Core/Widgets \ | |
22 | src/Core/Widgets/PyWdgt |
|
22 | src/Core/Widgets/PyWdgt | |
23 |
|
23 | |||
24 | QMAKE_CXXFLAGS_RELEASE += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx |
|
24 | QMAKE_CXXFLAGS_RELEASE += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx | |
25 | QMAKE_LFLAGS_RELEASE += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx |
|
25 | QMAKE_LFLAGS_RELEASE += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx | |
26 |
|
26 | |||
27 | QMAKE_CXXFLAGS_DEBUG += -O0 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx |
|
27 | QMAKE_CXXFLAGS_DEBUG += -O0 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx | |
28 | QMAKE_LFLAGS_DEBUG += -O0 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx |
|
28 | QMAKE_LFLAGS_DEBUG += -O0 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | SOURCES += src/main.cpp\ |
|
31 | SOURCES += src/main.cpp\ | |
32 | src/mainwindow.cpp \ |
|
32 | src/mainwindow.cpp \ | |
33 | src/SocExplorerPlot.cpp \ |
|
33 | src/SocExplorerPlot.cpp \ | |
34 | src/QCustomPlot/qcustomplot.cpp \ |
|
34 | src/QCustomPlot/qcustomplot.cpp \ | |
35 | src/toolbarcontainer.cpp \ |
|
35 | src/toolbarcontainer.cpp \ | |
36 | src/Core/abstractfileloader.cpp \ |
|
36 | src/Core/abstractfileloader.cpp \ | |
37 | src/Core/filedownloader.cpp \ |
|
37 | src/Core/filedownloader.cpp \ | |
38 | src/Core/filedownloadertask.cpp \ |
|
38 | src/Core/filedownloadertask.cpp \ | |
39 | src/Core/Widgets/downloadhistory.cpp \ |
|
39 | src/Core/Widgets/downloadhistory.cpp \ | |
40 | src/Core/Widgets/downloadhistoryelement.cpp \ |
|
40 | src/Core/Widgets/downloadhistoryelement.cpp \ | |
41 | src/Core/qlopservice.cpp \ |
|
41 | src/Core/qlopservice.cpp \ | |
42 | src/Cassini/expxmldownloader.cpp \ |
|
42 | src/Cassini/expxmldownloader.cpp \ | |
43 | src/Cassini/cassinidatadownloader.cpp \ |
|
43 | src/Cassini/cassinidatadownloader.cpp \ | |
44 | src/Cassini/cassinidatafile.cpp \ |
|
44 | src/Cassini/cassinidatafile.cpp \ | |
45 | src/Cassini/cassiniindexfile.cpp \ |
|
45 | src/Cassini/cassiniindexfile.cpp \ | |
46 | src/Cassini/cassiniindexfileviewer.cpp \ |
|
46 | src/Cassini/cassiniindexfileviewer.cpp \ | |
47 | src/Cassini/cassinitools.cpp \ |
|
47 | src/Cassini/cassinitools.cpp \ | |
48 | src/Cassini/cassinitoolsgui.cpp \ |
|
48 | src/Cassini/cassinitoolsgui.cpp \ | |
49 | src/Core/Widgets/qlopplots.cpp \ |
|
49 | src/Core/Widgets/qlopplots.cpp \ | |
50 | src/Core/qlopdata.cpp \ |
|
50 | src/Core/qlopdata.cpp \ | |
51 | src/Core/Widgets/PyWdgt/pythonconsole.cpp \ |
|
51 | src/Core/Widgets/PyWdgt/pythonconsole.cpp \ | |
52 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.cpp \ |
|
52 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.cpp \ | |
53 | src/QCustomPlot/qcpdocumentobject.cpp \ |
|
53 | src/QCustomPlot/qcpdocumentobject.cpp \ | |
54 | src/Core/Widgets/filebrowser.cpp \ |
|
54 | src/Core/Widgets/filebrowser.cpp \ | |
55 | src/Core/Widgets/filesystemmodel.cpp \ |
|
55 | src/Core/Widgets/filesystemmodel.cpp \ | |
56 | src/Core/Widgets/qcustomplotvect.cpp |
|
56 | src/Core/Widgets/qcustomplotvect.cpp | |
57 |
|
57 | |||
58 | HEADERS += src/mainwindow.h \ |
|
58 | HEADERS += src/mainwindow.h \ | |
59 | src/SocExplorerPlot.h \ |
|
59 | src/SocExplorerPlot.h \ | |
60 | src/QCustomPlot/qcustomplot.h \ |
|
60 | src/QCustomPlot/qcustomplot.h \ | |
61 | src/toolbarcontainer.h \ |
|
61 | src/toolbarcontainer.h \ | |
62 | src/Core/abstractfileloader.h \ |
|
62 | src/Core/abstractfileloader.h \ | |
63 | src/Core/filedownloader.h \ |
|
63 | src/Core/filedownloader.h \ | |
64 | src/Core/filedownloadertask.h \ |
|
64 | src/Core/filedownloadertask.h \ | |
65 | src/Core/Widgets/downloadhistory.h \ |
|
65 | src/Core/Widgets/downloadhistory.h \ | |
66 | src/Core/Widgets/downloadhistoryelement.h \ |
|
66 | src/Core/Widgets/downloadhistoryelement.h \ | |
67 | src/Core/qlopservice.h \ |
|
67 | src/Core/qlopservice.h \ | |
68 | src/Cassini/expxmldownloader.h \ |
|
68 | src/Cassini/expxmldownloader.h \ | |
69 | src/Cassini/cassinidatadownloader.h \ |
|
69 | src/Cassini/cassinidatadownloader.h \ | |
70 | src/Cassini/cassinidatafile.h \ |
|
70 | src/Cassini/cassinidatafile.h \ | |
71 | src/Cassini/cassiniindexfile.h \ |
|
71 | src/Cassini/cassiniindexfile.h \ | |
72 | src/Cassini/cassiniindexfileviewer.h \ |
|
72 | src/Cassini/cassiniindexfileviewer.h \ | |
73 | src/Cassini/cassinitools.h \ |
|
73 | src/Cassini/cassinitools.h \ | |
74 | src/Cassini/cassinitoolsgui.h \ |
|
74 | src/Cassini/cassinitoolsgui.h \ | |
75 | src/Core/Widgets/qlopplots.h \ |
|
75 | src/Core/Widgets/qlopplots.h \ | |
76 | src/Core/qlopdata.h \ |
|
76 | src/Core/qlopdata.h \ | |
77 | src/Core/Widgets/PyWdgt/pythonconsole.h \ |
|
77 | src/Core/Widgets/PyWdgt/pythonconsole.h \ | |
78 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.h \ |
|
78 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.h \ | |
79 | src/Core/qlop.h \ |
|
79 | src/Core/qlop.h \ | |
80 | src/Core/pyqlop.h \ |
|
80 | src/Core/pyqlop.h \ | |
81 | src/QCustomPlot/qcpdocumentobject.h \ |
|
81 | src/QCustomPlot/qcpdocumentobject.h \ | |
82 | src/Core/Widgets/filebrowser.h \ |
|
82 | src/Core/Widgets/filebrowser.h \ | |
83 | src/Core/Widgets/filesystemmodel.h \ |
|
83 | src/Core/Widgets/filesystemmodel.h \ | |
84 | src/Core/Widgets/qcustomplotvect.h |
|
84 | src/Core/Widgets/qcustomplotvect.h | |
85 |
|
85 | |||
86 | FORMS += src/mainwindow.ui \ |
|
86 | FORMS += src/mainwindow.ui \ | |
87 | src/Core/Widgets/downloadhistory.ui \ |
|
87 | src/Core/Widgets/downloadhistory.ui \ | |
88 | src/Core/Widgets/downloadhistoryelement.ui \ |
|
88 | src/Core/Widgets/downloadhistoryelement.ui \ | |
89 | src/Cassini/cassinidatadownloader.ui \ |
|
89 | src/Cassini/cassinidatadownloader.ui \ | |
90 | src/Cassini/cassiniindexfileviewer.ui \ |
|
90 | src/Cassini/cassiniindexfileviewer.ui \ | |
91 | src/Cassini/cassinitoolsgui.ui \ |
|
91 | src/Cassini/cassinitoolsgui.ui \ | |
92 | src/Core/Widgets/filebrowser.ui |
|
92 | src/Core/Widgets/filebrowser.ui | |
93 |
|
93 | |||
94 | RESOURCES += \ |
|
94 | RESOURCES += \ | |
95 | resources/qlop.qrc |
|
95 | resources/qlop.qrc | |
96 |
|
96 | |||
97 | include(src/Core/Widgets/NicePyConsole/NicePyConsole.pri) |
|
97 | include(src/Core/Widgets/NicePyConsole/NicePyConsole.pri) | |
98 | include(src/Core/pythonQtOut/generated_cpp/PyQLop/PyQLop.pri) |
|
98 | include(src/Core/pythonQtOut/generated_cpp/PyQLop/PyQLop.pri) | |
99 |
|
99 | |||
100 | win32 { |
|
100 | win32 { | |
101 | DEFINES += WIN32 |
|
101 | DEFINES += WIN32 | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | unix { |
|
104 | unix { | |
105 | DEFINES += UNIX |
|
105 | DEFINES += UNIX | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | DISTFILES += \ |
|
108 | DISTFILES += \ | |
109 | src/Core/pythongenerator.sh \ |
|
109 | src/Core/pythongenerator.sh \ | |
110 | src/Core/pythonQtgeneratorCfg.txt |
|
110 | src/Core/pythonQtgeneratorCfg.txt |
@@ -1,69 +1,91 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "cassinidatadownloader.h" |
|
23 | #include "cassinidatadownloader.h" | |
2 | #include "ui_cassinidatadownloader.h" |
|
24 | #include "ui_cassinidatadownloader.h" | |
3 | #include <filedownloader.h> |
|
25 | #include <filedownloader.h> | |
4 | #include <QDir> |
|
26 | #include <QDir> | |
5 | #include <QFileDialog> |
|
27 | #include <QFileDialog> | |
6 | #include <QFile> |
|
28 | #include <QFile> | |
7 |
|
29 | |||
8 | CassiniDataDownloader::CassiniDataDownloader(QWidget *parent) : |
|
30 | CassiniDataDownloader::CassiniDataDownloader(QWidget *parent) : | |
9 | QWidget(parent), |
|
31 | QWidget(parent), | |
10 | ui(new Ui::CassiniDataDownloader) |
|
32 | ui(new Ui::CassiniDataDownloader) | |
11 | { |
|
33 | { | |
12 | ui->setupUi(this); |
|
34 | ui->setupUi(this); | |
13 | m_xmlLoader = new ExpXmlDownLoader(); |
|
35 | m_xmlLoader = new ExpXmlDownLoader(); | |
14 | connect(this->ui->calendar,SIGNAL(activated(QDate)),this,SLOT(downloadData(QDate))); |
|
36 | connect(this->ui->calendar,SIGNAL(activated(QDate)),this,SLOT(downloadData(QDate))); | |
15 | connect(this->ui->LoadXmlFileQpb,SIGNAL(clicked()),this,SLOT(loadXmlFile())); |
|
37 | connect(this->ui->LoadXmlFileQpb,SIGNAL(clicked()),this,SLOT(loadXmlFile())); | |
16 | } |
|
38 | } | |
17 |
|
39 | |||
18 | CassiniDataDownloader::~CassiniDataDownloader() |
|
40 | CassiniDataDownloader::~CassiniDataDownloader() | |
19 | { |
|
41 | { | |
20 | delete ui; |
|
42 | delete ui; | |
21 | delete m_xmlLoader; |
|
43 | delete m_xmlLoader; | |
22 | } |
|
44 | } | |
23 |
|
45 | |||
24 | void CassiniDataDownloader::changeEvent(QEvent *e) |
|
46 | void CassiniDataDownloader::changeEvent(QEvent *e) | |
25 | { |
|
47 | { | |
26 | QWidget::changeEvent(e); |
|
48 | QWidget::changeEvent(e); | |
27 | switch (e->type()) { |
|
49 | switch (e->type()) { | |
28 | case QEvent::LanguageChange: |
|
50 | case QEvent::LanguageChange: | |
29 | ui->retranslateUi(this); |
|
51 | ui->retranslateUi(this); | |
30 | break; |
|
52 | break; | |
31 | default: |
|
53 | default: | |
32 | break; |
|
54 | break; | |
33 | } |
|
55 | } | |
34 | } |
|
56 | } | |
35 |
|
57 | |||
36 | void CassiniDataDownloader::downloadData(const QDate &date) |
|
58 | void CassiniDataDownloader::downloadData(const QDate &date) | |
37 | { |
|
59 | { | |
38 | QDate tmpDate; |
|
60 | QDate tmpDate; | |
39 | QStringList months=QStringList()<< "JAN" << "FEB" << "MAR" << "APR" << "MAY" << "JUN" << "JUI" << "AUG" << "SEP" << "OCT" << "NOV" << "DEC"; |
|
61 | QStringList months=QStringList()<< "JAN" << "FEB" << "MAR" << "APR" << "MAY" << "JUN" << "JUI" << "AUG" << "SEP" << "OCT" << "NOV" << "DEC"; | |
40 | tmpDate.setDate(date.year(),date.month(),1); |
|
62 | tmpDate.setDate(date.year(),date.month(),1); | |
41 | int firstDayOfMonth=tmpDate.dayOfYear(); |
|
63 | int firstDayOfMonth=tmpDate.dayOfYear(); | |
42 | tmpDate.setDate(tmpDate.year(),tmpDate.month(),tmpDate.daysInMonth()); |
|
64 | tmpDate.setDate(tmpDate.year(),tmpDate.month(),tmpDate.daysInMonth()); | |
43 | int lastDayOfMonth=tmpDate.dayOfYear(); |
|
65 | int lastDayOfMonth=tmpDate.dayOfYear(); | |
44 | QString link="http://ppi.pds.nasa.gov/ditdos/download?id=pds://PPI/CO-E_SW_J_S-MAG-3-RDR-FULL-RES-V1.0/DATA/" \ |
|
66 | QString link="http://ppi.pds.nasa.gov/ditdos/download?id=pds://PPI/CO-E_SW_J_S-MAG-3-RDR-FULL-RES-V1.0/DATA/" \ | |
45 | + QString("%1").arg(date.year()) +"/" + QString("%1_%2_").arg(firstDayOfMonth,3).arg(lastDayOfMonth,3).replace(' ','0') \ |
|
67 | + QString("%1").arg(date.year()) +"/" + QString("%1_%2_").arg(firstDayOfMonth,3).arg(lastDayOfMonth,3).replace(' ','0') \ | |
46 | + months.at(date.month()-1) + "/" ; |
|
68 | + months.at(date.month()-1) + "/" ; | |
47 | qDebug()<<link; |
|
69 | qDebug()<<link; | |
48 | QString dataFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.TAB"; |
|
70 | QString dataFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.TAB"; | |
49 | QString headerFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.LBL"; |
|
71 | QString headerFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.LBL"; | |
50 | // "_FGM_KRTP.TAB" |
|
72 | // "_FGM_KRTP.TAB" | |
51 | FileDownloader::downloadFile(link+dataFileName,QDir::homePath() +"/Téléchargements/"+dataFileName); |
|
73 | FileDownloader::downloadFile(link+dataFileName,QDir::homePath() +"/Téléchargements/"+dataFileName); | |
52 | FileDownloader::downloadFile(link+headerFileName,QDir::homePath() +"/Téléchargements/"+headerFileName); |
|
74 | FileDownloader::downloadFile(link+headerFileName,QDir::homePath() +"/Téléchargements/"+headerFileName); | |
53 | } |
|
75 | } | |
54 |
|
76 | |||
55 | void CassiniDataDownloader::loadXmlFile() |
|
77 | void CassiniDataDownloader::loadXmlFile() | |
56 | { |
|
78 | { | |
57 | QString file=QFileDialog::getOpenFileName(); |
|
79 | QString file=QFileDialog::getOpenFileName(); | |
58 | if(QFile::exists(file)) |
|
80 | if(QFile::exists(file)) | |
59 | { |
|
81 | { | |
60 | if(m_xmlLoader->parseXml(file)) |
|
82 | if(m_xmlLoader->parseXml(file)) | |
61 | { |
|
83 | { | |
62 | QList<QDate> daysToDl = m_xmlLoader->daysToDownload(); |
|
84 | QList<QDate> daysToDl = m_xmlLoader->daysToDownload(); | |
63 | for(int i=0;i<daysToDl.count();i++) |
|
85 | for(int i=0;i<daysToDl.count();i++) | |
64 | { |
|
86 | { | |
65 | downloadData(daysToDl.at(i)); |
|
87 | downloadData(daysToDl.at(i)); | |
66 | } |
|
88 | } | |
67 | } |
|
89 | } | |
68 | } |
|
90 | } | |
69 | } |
|
91 | } |
@@ -1,30 +1,52 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef CASSINIDATADOWNLOADER_H |
|
23 | #ifndef CASSINIDATADOWNLOADER_H | |
2 | #define CASSINIDATADOWNLOADER_H |
|
24 | #define CASSINIDATADOWNLOADER_H | |
3 |
|
25 | |||
4 | #include <QWidget> |
|
26 | #include <QWidget> | |
5 | #include <QDate> |
|
27 | #include <QDate> | |
6 | #include <expxmldownloader.h> |
|
28 | #include <expxmldownloader.h> | |
7 |
|
29 | |||
8 | namespace Ui { |
|
30 | namespace Ui { | |
9 | class CassiniDataDownloader; |
|
31 | class CassiniDataDownloader; | |
10 | } |
|
32 | } | |
11 |
|
33 | |||
12 | class CassiniDataDownloader : public QWidget |
|
34 | class CassiniDataDownloader : public QWidget | |
13 | { |
|
35 | { | |
14 | Q_OBJECT |
|
36 | Q_OBJECT | |
15 |
|
37 | |||
16 | public: |
|
38 | public: | |
17 | explicit CassiniDataDownloader(QWidget *parent = 0); |
|
39 | explicit CassiniDataDownloader(QWidget *parent = 0); | |
18 | ~CassiniDataDownloader(); |
|
40 | ~CassiniDataDownloader(); | |
19 |
|
41 | |||
20 | protected: |
|
42 | protected: | |
21 | void changeEvent(QEvent *e); |
|
43 | void changeEvent(QEvent *e); | |
22 | private slots: |
|
44 | private slots: | |
23 | void downloadData(const QDate & date ); |
|
45 | void downloadData(const QDate & date ); | |
24 | void loadXmlFile(); |
|
46 | void loadXmlFile(); | |
25 | private: |
|
47 | private: | |
26 | Ui::CassiniDataDownloader *ui; |
|
48 | Ui::CassiniDataDownloader *ui; | |
27 | ExpXmlDownLoader* m_xmlLoader; |
|
49 | ExpXmlDownLoader* m_xmlLoader; | |
28 | }; |
|
50 | }; | |
29 |
|
51 | |||
30 | #endif // CASSINIDATADOWNLOADER_H |
|
52 | #endif // CASSINIDATADOWNLOADER_H |
@@ -1,306 +1,306 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "cassinidatafile.h" |
|
22 | #include "cassinidatafile.h" | |
23 | #include <QFile> |
|
23 | #include <QFile> | |
24 | #include <stdio.h> |
|
24 | #include <stdio.h> | |
25 | #include <QDateTime> |
|
25 | #include <QDateTime> | |
26 | #include <QVector> |
|
26 | #include <QVector> | |
27 | #include <QProgressDialog> |
|
27 | #include <QProgressDialog> | |
28 | #include <omp.h> |
|
28 | #include <omp.h> | |
29 | #include <QTimer> |
|
29 | #include <QTimer> | |
30 | #include <QElapsedTimer> |
|
30 | #include <QElapsedTimer> | |
31 | #include <sys/time.h> |
|
31 | #include <sys/time.h> | |
32 |
|
32 | |||
33 | CassiniDataFile::CassiniDataFile(QObject *parent) : AbstractFileLoader(parent) |
|
33 | CassiniDataFile::CassiniDataFile(QObject *parent) : AbstractFileLoader(parent) | |
34 | { |
|
34 | { | |
35 |
|
35 | |||
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | CassiniDataFile::~CassiniDataFile() |
|
38 | CassiniDataFile::~CassiniDataFile() | |
39 | { |
|
39 | { | |
40 |
|
40 | |||
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void CassiniDataFile::parseFile(const QString &fileName) |
|
43 | void CassiniDataFile::parseFile(const QString &fileName) | |
44 | { |
|
44 | { | |
45 | this->fileName = fileName; |
|
45 | this->fileName = fileName; | |
46 | m_Write = false; |
|
46 | m_Write = false; | |
47 | this->start(); |
|
47 | this->start(); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void CassiniDataFile::saveFile(const QString &fileName, QLopDataList data) |
|
50 | void CassiniDataFile::saveFile(const QString &fileName, QLopDataList data) | |
51 | { |
|
51 | { | |
52 | this->fileName = fileName; |
|
52 | this->fileName = fileName; | |
53 | m_Write = true; |
|
53 | m_Write = true; | |
54 | m_data = data; |
|
54 | m_data = data; | |
55 | this->start(); |
|
55 | this->start(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | inline double __decodeVal(int ofset,unsigned char* data) |
|
58 | inline double __decodeVal(int ofset,unsigned char* data) | |
59 | { |
|
59 | { | |
60 | if(data[ofset]=='-') |
|
60 | if(data[ofset]=='-') | |
61 | return -0.001 * (double)( |
|
61 | return -0.001 * (double)( | |
62 | (10000 * (int)(data[ofset+1] & 0x0F)) |
|
62 | (10000 * (int)(data[ofset+1] & 0x0F)) | |
63 | + (1000 * (int)(data[ofset+2] & 0x0F)) |
|
63 | + (1000 * (int)(data[ofset+2] & 0x0F)) | |
64 | + (100 * (int)(data[ofset+4] & 0x0F)) |
|
64 | + (100 * (int)(data[ofset+4] & 0x0F)) | |
65 | + (10 * (int)(data[ofset+5] & 0x0F)) |
|
65 | + (10 * (int)(data[ofset+5] & 0x0F)) | |
66 | + ( (int)(data[ofset+6] & 0x0F)) |
|
66 | + ( (int)(data[ofset+6] & 0x0F)) | |
67 | ); |
|
67 | ); | |
68 | else |
|
68 | else | |
69 | { |
|
69 | { | |
70 | if(data[ofset+1]=='-') |
|
70 | if(data[ofset+1]=='-') | |
71 | { |
|
71 | { | |
72 | return -0.001 * (double)( |
|
72 | return -0.001 * (double)( | |
73 | (1000 * (int)(data[ofset+2] & 0x0F)) |
|
73 | (1000 * (int)(data[ofset+2] & 0x0F)) | |
74 | + (100 * (int)(data[ofset+4] & 0x0F)) |
|
74 | + (100 * (int)(data[ofset+4] & 0x0F)) | |
75 | + (10 * (int)(data[ofset+5] & 0x0F)) |
|
75 | + (10 * (int)(data[ofset+5] & 0x0F)) | |
76 | + ( (int)(data[ofset+6] & 0x0F)) |
|
76 | + ( (int)(data[ofset+6] & 0x0F)) | |
77 | ); |
|
77 | ); | |
78 | } |
|
78 | } | |
79 | else |
|
79 | else | |
80 | { |
|
80 | { | |
81 | return 0.001 * (double)( |
|
81 | return 0.001 * (double)( | |
82 | (10000 * (int)(data[ofset+1] & 0x0F)) |
|
82 | (10000 * (int)(data[ofset+1] & 0x0F)) | |
83 | + (1000 * (int)(data[ofset+2] & 0x0F)) |
|
83 | + (1000 * (int)(data[ofset+2] & 0x0F)) | |
84 | + (100 * (int)(data[ofset+4] & 0x0F)) |
|
84 | + (100 * (int)(data[ofset+4] & 0x0F)) | |
85 | + (10 * (int)(data[ofset+5] & 0x0F)) |
|
85 | + (10 * (int)(data[ofset+5] & 0x0F)) | |
86 | + ( (int)(data[ofset+6] & 0x0F)) |
|
86 | + ( (int)(data[ofset+6] & 0x0F)) | |
87 | ); |
|
87 | ); | |
88 | } |
|
88 | } | |
89 | } |
|
89 | } | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | inline QDate __decodeDate(int ofset,unsigned char* data) |
|
92 | inline QDate __decodeDate(int ofset,unsigned char* data) | |
93 | { |
|
93 | { | |
94 | int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F)); |
|
94 | int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F)); | |
95 | int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F)); |
|
95 | int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F)); | |
96 | int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F)); |
|
96 | int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F)); | |
97 | return QDate(y,m,d); |
|
97 | return QDate(y,m,d); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | inline QTime __decodeTime(int ofset,unsigned char* data) |
|
100 | inline QTime __decodeTime(int ofset,unsigned char* data) | |
101 | { |
|
101 | { | |
102 | int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F)); |
|
102 | int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F)); | |
103 | int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F)); |
|
103 | int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F)); | |
104 | int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F)); |
|
104 | int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F)); | |
105 | int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F)); |
|
105 | int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F)); | |
106 | return QTime(h,m,s,ms); |
|
106 | return QTime(h,m,s,ms); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | double __decodeTimeFromEpochMs(int ofset,unsigned char* data) |
|
109 | double __decodeTimeFromEpochMs(int ofset,unsigned char* data) | |
110 | { |
|
110 | { | |
111 | struct tm t; |
|
111 | struct tm t; | |
112 | time_t t_of_day; |
|
112 | time_t t_of_day; | |
113 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; |
|
113 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; | |
114 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); |
|
114 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); | |
115 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); |
|
115 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); | |
116 | t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); |
|
116 | t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); | |
117 | t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); |
|
117 | t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); | |
118 | t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); |
|
118 | t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); | |
119 | int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); |
|
119 | int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); | |
120 | t_of_day = mktime(&t); |
|
120 | t_of_day = mktime(&t); | |
121 | return (t_of_day*1000.0)+ms; |
|
121 | return (t_of_day*1000.0)+ms; | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | double __decodeTimeFromEpoch(int ofset,unsigned char* data) |
|
124 | double __decodeTimeFromEpoch(int ofset,unsigned char* data) | |
125 | { |
|
125 | { | |
126 | struct tm t; |
|
126 | struct tm t; | |
127 | time_t t_of_day; |
|
127 | time_t t_of_day; | |
128 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; |
|
128 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; | |
129 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); |
|
129 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); | |
130 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); |
|
130 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); | |
131 | t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); |
|
131 | t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); | |
132 | t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); |
|
132 | t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); | |
133 | t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); |
|
133 | t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); | |
134 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); |
|
134 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); | |
135 | t_of_day = mktime(&t); |
|
135 | t_of_day = mktime(&t); | |
136 | return (double)t_of_day+((double)ms*(double)0.001); |
|
136 | return (double)t_of_day+((double)ms*(double)0.001); | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | double __decodeTimeHMSmS(int ofset,unsigned char* data) |
|
139 | double __decodeTimeHMSmS(int ofset,unsigned char* data) | |
140 | { |
|
140 | { | |
141 | int h,m,s; |
|
141 | int h,m,s; | |
142 | h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); |
|
142 | h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); | |
143 | m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); |
|
143 | m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); | |
144 | s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); |
|
144 | s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); | |
145 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); |
|
145 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); | |
146 | return (double)((h*3600)+(m*60)+s) + (ms*0.001); |
|
146 | return (double)((h*3600)+(m*60)+s) + (ms*0.001); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | double __decodeTimeDHMSmS(int ofset,unsigned char* data) |
|
149 | double __decodeTimeDHMSmS(int ofset,unsigned char* data) | |
150 | { |
|
150 | { | |
151 | int d,h,m,s; |
|
151 | int d,h,m,s; | |
152 | d=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); |
|
152 | d=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); | |
153 | h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); |
|
153 | h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); | |
154 | m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); |
|
154 | m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); | |
155 | s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); |
|
155 | s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); | |
156 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); |
|
156 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); | |
157 | return (double)((d*3600*24)+(h*3600)+(m*60)+s) + (ms*0.001); |
|
157 | return (double)((d*3600*24)+(h*3600)+(m*60)+s) + (ms*0.001); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | double __decodeTimeFromEpochDayOnly(int ofset,unsigned char* data) |
|
160 | double __decodeTimeFromEpochDayOnly(int ofset,unsigned char* data) | |
161 | { |
|
161 | { | |
162 | struct tm t; |
|
162 | struct tm t; | |
163 | time_t t_of_day; |
|
163 | time_t t_of_day; | |
164 | // t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; |
|
164 | // t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; | |
165 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)); |
|
165 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)); | |
166 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); |
|
166 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); | |
167 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); |
|
167 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); | |
168 | t.tm_hour=0; |
|
168 | t.tm_hour=0; | |
169 | t.tm_min=0; |
|
169 | t.tm_min=0; | |
170 | t.tm_sec=0; |
|
170 | t.tm_sec=0; | |
171 | // t_of_day = mktime(&t); |
|
171 | // t_of_day = mktime(&t); | |
172 | // return (double)t_of_day; |
|
172 | // return (double)t_of_day; | |
173 | QDateTime date(QDate(t.tm_year,t.tm_mon,1),QTime(0,0)); |
|
173 | QDateTime date(QDate(t.tm_year,t.tm_mon,1),QTime(0,0)); | |
174 | // date.setDate(); |
|
174 | // date.setDate(); | |
175 | return (double)((date.toMSecsSinceEpoch()/1000.0)-(24*3600)); |
|
175 | return (double)((date.toMSecsSinceEpoch()/1000.0)-(24*3600)); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | void CassiniDataFile::run() |
|
178 | void CassiniDataFile::run() | |
179 | { |
|
179 | { | |
180 | if(!m_Write) |
|
180 | if(!m_Write) | |
181 | { |
|
181 | { | |
182 | readFile(); |
|
182 | readFile(); | |
183 | } |
|
183 | } | |
184 | else |
|
184 | else | |
185 | { |
|
185 | { | |
186 | writeFile(); |
|
186 | writeFile(); | |
187 | } |
|
187 | } | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void CassiniDataFile::readFile() |
|
190 | void CassiniDataFile::readFile() | |
191 | { |
|
191 | { | |
192 | FILE* dataFile; |
|
192 | FILE* dataFile; | |
193 | dataFile = fopen(fileName.toStdString().c_str(),"r"); |
|
193 | dataFile = fopen(fileName.toStdString().c_str(),"r"); | |
194 |
|
194 | |||
195 | if(dataFile != NULL) |
|
195 | if(dataFile != NULL) | |
196 | { |
|
196 | { | |
197 | fseek(dataFile, 0L, SEEK_END); |
|
197 | fseek(dataFile, 0L, SEEK_END); | |
198 | int FileSize=ftell(dataFile); |
|
198 | int FileSize=ftell(dataFile); | |
199 | int lineCnt = FileSize/58; |
|
199 | int lineCnt = FileSize/58; | |
200 | int curLine=0; |
|
200 | int curLine=0; | |
201 | int lastLineUpdate=0; |
|
201 | int lastLineUpdate=0; | |
202 | QVector<QCPData> *ch1=new QVector<QCPData>(lineCnt); |
|
202 | QVector<QCPData> *ch1=new QVector<QCPData>(lineCnt); | |
203 | QVector<QCPData> *ch2=new QVector<QCPData>(lineCnt); |
|
203 | QVector<QCPData> *ch2=new QVector<QCPData>(lineCnt); | |
204 | QVector<QCPData> *ch3=new QVector<QCPData>(lineCnt); |
|
204 | QVector<QCPData> *ch3=new QVector<QCPData>(lineCnt); | |
205 | QLopDataList data; |
|
205 | QLopDataList data; | |
206 | QLopData* ch1V=new QLopData(); |
|
206 | QLopData* ch1V=new QLopData(); | |
207 | QLopData* ch2V=new QLopData(); |
|
207 | QLopData* ch2V=new QLopData(); | |
208 | QLopData* ch3V=new QLopData(); |
|
208 | QLopData* ch3V=new QLopData(); | |
209 | ch1V->data=ch1; |
|
209 | ch1V->data=ch1; | |
210 | ch2V->data=ch2; |
|
210 | ch2V->data=ch2; | |
211 | ch3V->data=ch3; |
|
211 | ch3V->data=ch3; | |
212 | ch1V->name="r"; |
|
212 | ch1V->name="r"; | |
213 | ch2V->name="theta"; |
|
213 | ch2V->name="theta"; | |
214 | ch3V->name="phi"; |
|
214 | ch3V->name="phi"; | |
215 | ch1V->unit="nT"; |
|
215 | ch1V->unit="nT"; | |
216 | ch2V->unit="nT"; |
|
216 | ch2V->unit="nT"; | |
217 | ch3V->unit="nT"; |
|
217 | ch3V->unit="nT"; | |
218 | data.append(ch1V); |
|
218 | data.append(ch1V); | |
219 | data.append(ch2V); |
|
219 | data.append(ch2V); | |
220 | data.append(ch3V); |
|
220 | data.append(ch3V); | |
221 | QElapsedTimer timr; |
|
221 | QElapsedTimer timr; | |
222 |
|
222 | |||
223 | double _x=0.0,day=0.0; |
|
223 | double _x=0.0,day=0.0; | |
224 | char* line; |
|
224 | char* line; | |
225 | QCPData data1,data2,data3; |
|
225 | QCPData data1,data2,data3; | |
226 | char* fileContent=(char*)malloc(FileSize); |
|
226 | char* fileContent=(char*)malloc(FileSize); | |
227 | if(Q_UNLIKELY(fileContent==NULL))return; |
|
227 | if(Q_UNLIKELY(fileContent==NULL))return; | |
228 | int threadIndex,numThreads=omp_get_num_threads(); |
|
228 | int threadIndex,numThreads=omp_get_num_threads(); | |
229 | int updateTriger=(lineCnt/100)/numThreads; |
|
229 | int updateTriger=(lineCnt/100)/numThreads; | |
230 | fseek(dataFile, 0L, SEEK_SET); |
|
230 | fseek(dataFile, 0L, SEEK_SET); | |
231 | char* svglocale=NULL; |
|
231 | char* svglocale=NULL; | |
232 | setlocale(LC_NUMERIC,svglocale); |
|
232 | setlocale(LC_NUMERIC,svglocale); | |
233 | setlocale(LC_NUMERIC, "en_US"); |
|
233 | setlocale(LC_NUMERIC, "en_US"); | |
234 | if(fread(fileContent,1,FileSize,dataFile)) |
|
234 | if(fread(fileContent,1,FileSize,dataFile)) | |
235 | { |
|
235 | { | |
236 | line = fileContent; |
|
236 | line = fileContent; | |
237 | QDateTime date; |
|
237 | QDateTime date; | |
238 | timr.start(); |
|
238 | timr.start(); | |
239 | day=__decodeTimeFromEpochDayOnly(0,(unsigned char*)line); |
|
239 | day=__decodeTimeFromEpochDayOnly(0,(unsigned char*)line); | |
240 | //#pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt) |
|
240 | //#pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt) | |
241 | // { |
|
241 | // { | |
242 | #pragma omp parallel for if ((FileSize > 1024*1024*10)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate,curLine) shared(ch1,ch2,ch3,lineCnt,updateTriger) |
|
242 | #pragma omp parallel for if ((FileSize > 1024*1024*10)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate,curLine) shared(ch1,ch2,ch3,lineCnt,updateTriger) | |
243 | for(int i=0;i<lineCnt;i++) |
|
243 | for(int i=0;i<lineCnt;i++) | |
244 | { |
|
244 | { | |
245 | // _x= i; |
|
245 | // _x= i; | |
246 | _x= day + __decodeTimeDHMSmS((i*58),(unsigned char*)line); |
|
246 | _x= day + __decodeTimeDHMSmS((i*58),(unsigned char*)line); | |
247 | // _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line); |
|
247 | // _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line); | |
248 | data1.key=_x; |
|
248 | data1.key=_x; | |
249 | data2.key=_x; |
|
249 | data2.key=_x; | |
250 | data3.key=_x; |
|
250 | data3.key=_x; | |
251 | data1.value=__decodeVal(((i*58)+27),(unsigned char*)line); |
|
251 | data1.value=__decodeVal(((i*58)+27),(unsigned char*)line); | |
252 | data2.value=__decodeVal(((i*58)+38),(unsigned char*)line); |
|
252 | data2.value=__decodeVal(((i*58)+38),(unsigned char*)line); | |
253 | data3.value=__decodeVal(((i*58)+49),(unsigned char*)line); |
|
253 | data3.value=__decodeVal(((i*58)+49),(unsigned char*)line); | |
254 | (*ch1)[i]=data1; |
|
254 | (*ch1)[i]=data1; | |
255 | (*ch2)[i]=data2; |
|
255 | (*ch2)[i]=data2; | |
256 | (*ch3)[i]=data3; |
|
256 | (*ch3)[i]=data3; | |
257 | curLine++; |
|
257 | curLine++; | |
258 | if(Q_UNLIKELY(lastLineUpdate++>updateTriger)) |
|
258 | if(Q_UNLIKELY(lastLineUpdate++>updateTriger)) | |
259 | { |
|
259 | { | |
260 | lastLineUpdate=0; |
|
260 | lastLineUpdate=0; | |
261 | int test=((curLine*numThreads *100)/ (lineCnt)); |
|
261 | int test=((curLine*numThreads *100)/ (lineCnt)); | |
262 | emit updateProgress(omp_get_thread_num(),test); |
|
262 | emit updateProgress(omp_get_thread_num(),test); | |
263 | } |
|
263 | } | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 | //#pragma omp barrier |
|
266 | //#pragma omp barrier | |
267 | free(fileContent); |
|
267 | free(fileContent); | |
268 | // } |
|
268 | // } | |
269 | qDebug()<< lineCnt <<" Points loade in "<< timr.elapsed()<<"ms"; |
|
269 | qDebug()<< lineCnt <<" Points loaded in "<< timr.elapsed()<<"ms"; | |
270 | setlocale(LC_NUMERIC,svglocale); |
|
270 | setlocale(LC_NUMERIC,svglocale); | |
271 | emit dataReady(data); |
|
271 | emit dataReady(data); | |
272 | } |
|
272 | } | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | void CassiniDataFile::writeFile() |
|
275 | void CassiniDataFile::writeFile() | |
276 | { |
|
276 | { | |
277 | QFile dataFile(fileName); |
|
277 | QFile dataFile(fileName); | |
278 | dataFile.open(QIODevice::WriteOnly); |
|
278 | dataFile.open(QIODevice::WriteOnly); | |
279 | QTextStream out(&dataFile); |
|
279 | QTextStream out(&dataFile); | |
280 | if(dataFile.isOpen()) |
|
280 | if(dataFile.isOpen()) | |
281 | { |
|
281 | { | |
282 | if(m_data.count()==3) |
|
282 | if(m_data.count()==3) | |
283 | { |
|
283 | { | |
284 | QLopData* ch1V=m_data.at(0); |
|
284 | QLopData* ch1V=m_data.at(0); | |
285 | QLopData* ch2V=m_data.at(1); |
|
285 | QLopData* ch2V=m_data.at(1); | |
286 | QLopData* ch3V=m_data.at(2); |
|
286 | QLopData* ch3V=m_data.at(2); | |
287 | if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) |
|
287 | if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) | |
288 | { |
|
288 | { | |
289 | for(int i=0;i<ch1V->data->count();i++) |
|
289 | for(int i=0;i<ch1V->data->count();i++) | |
290 | { |
|
290 | { | |
291 | double key = ch1V->data->at(i).key; |
|
291 | double key = ch1V->data->at(i).key; | |
292 | QDateTime date = QDateTime::fromMSecsSinceEpoch(key*1000); |
|
292 | QDateTime date = QDateTime::fromMSecsSinceEpoch(key*1000); | |
293 | out << date.toString(Qt::ISODate)+QString(".%1").arg(date.time().msec(),3); |
|
293 | out << date.toString(Qt::ISODate)+QString(".%1").arg(date.time().msec(),3); | |
294 | out << QString("%1%2%3").arg(ch1V->data->at(i).value, 11, 'f', 3).arg(ch2V->data->at(i).value, 11, 'f', 3).arg(ch3V->data->at(i).value, 11, 'f', 3); |
|
294 | out << QString("%1%2%3").arg(ch1V->data->at(i).value, 11, 'f', 3).arg(ch2V->data->at(i).value, 11, 'f', 3).arg(ch3V->data->at(i).value, 11, 'f', 3); | |
295 | out << "\r\n"; |
|
295 | out << "\r\n"; | |
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 | dataFile.flush(); |
|
298 | dataFile.flush(); | |
299 | m_data.clear(); |
|
299 | m_data.clear(); | |
300 | delete ch1V; |
|
300 | delete ch1V; | |
301 | delete ch2V; |
|
301 | delete ch2V; | |
302 | delete ch3V; |
|
302 | delete ch3V; | |
303 | } |
|
303 | } | |
304 | } |
|
304 | } | |
305 | } |
|
305 | } | |
306 |
|
306 |
@@ -1,48 +1,70 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "cassiniindexfile.h" |
|
23 | #include "cassiniindexfile.h" | |
2 |
|
24 | |||
3 | #include <QFile> |
|
25 | #include <QFile> | |
4 | #include <stdio.h> |
|
26 | #include <stdio.h> | |
5 | #include <QStringList> |
|
27 | #include <QStringList> | |
6 |
|
28 | |||
7 | CassiniIndexFile::CassiniIndexFile() |
|
29 | CassiniIndexFile::CassiniIndexFile() | |
8 | { |
|
30 | { | |
9 |
|
31 | |||
10 | } |
|
32 | } | |
11 |
|
33 | |||
12 | CassiniIndexFile::~CassiniIndexFile() |
|
34 | CassiniIndexFile::~CassiniIndexFile() | |
13 | { |
|
35 | { | |
14 |
|
36 | |||
15 | } |
|
37 | } | |
16 |
|
38 | |||
17 | QList<CassiniIndexLine> CassiniIndexFile::loadFile(const QString &file) |
|
39 | QList<CassiniIndexLine> CassiniIndexFile::loadFile(const QString &file) | |
18 | { |
|
40 | { | |
19 | QFile dataFile(file); |
|
41 | QFile dataFile(file); | |
20 | dataFile.open(QIODevice::ReadOnly); |
|
42 | dataFile.open(QIODevice::ReadOnly); | |
21 | QList<CassiniIndexLine> lines; |
|
43 | QList<CassiniIndexLine> lines; | |
22 | if(dataFile.isOpen()) |
|
44 | if(dataFile.isOpen()) | |
23 | { |
|
45 | { | |
24 | QString line; |
|
46 | QString line; | |
25 | QStringList cels; |
|
47 | QStringList cels; | |
26 | CassiniIndexLine indexLine; |
|
48 | CassiniIndexLine indexLine; | |
27 | line=dataFile.readLine(); |
|
49 | line=dataFile.readLine(); | |
28 | while(!dataFile.atEnd()) |
|
50 | while(!dataFile.atEnd()) | |
29 | { |
|
51 | { | |
30 | line=dataFile.readLine(); |
|
52 | line=dataFile.readLine(); | |
31 | cels= line.split(','); |
|
53 | cels= line.split(','); | |
32 | for(int i=0;i<8;i++) |
|
54 | for(int i=0;i<8;i++) | |
33 | { |
|
55 | { | |
34 | indexLine.cels[i]=""; |
|
56 | indexLine.cels[i]=""; | |
35 | } |
|
57 | } | |
36 | if(cels.count()<=8) |
|
58 | if(cels.count()<=8) | |
37 | { |
|
59 | { | |
38 | for(int i=0;i<cels.count();i++) |
|
60 | for(int i=0;i<cels.count();i++) | |
39 | { |
|
61 | { | |
40 | indexLine.cels[i]=cels.at(i); |
|
62 | indexLine.cels[i]=cels.at(i); | |
41 | } |
|
63 | } | |
42 | lines.append(indexLine); |
|
64 | lines.append(indexLine); | |
43 | } |
|
65 | } | |
44 | } |
|
66 | } | |
45 | } |
|
67 | } | |
46 | return lines; |
|
68 | return lines; | |
47 | } |
|
69 | } | |
48 |
|
70 |
@@ -1,34 +1,56 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef CASSINIINDEXFILE_H |
|
23 | #ifndef CASSINIINDEXFILE_H | |
2 | #define CASSINIINDEXFILE_H |
|
24 | #define CASSINIINDEXFILE_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 |
|
27 | |||
6 |
|
28 | |||
7 | #define DATA_SET_ID 0 |
|
29 | #define DATA_SET_ID 0 | |
8 | #define FILE_SPECIFICATION_NAME 1 |
|
30 | #define FILE_SPECIFICATION_NAME 1 | |
9 | #define PRODUCT_ID 2 |
|
31 | #define PRODUCT_ID 2 | |
10 | #define VOLUME_ID 3 |
|
32 | #define VOLUME_ID 3 | |
11 | #define PRODUCT_CREATION_TIME 4 |
|
33 | #define PRODUCT_CREATION_TIME 4 | |
12 | #define TARGET_NAME 5 |
|
34 | #define TARGET_NAME 5 | |
13 | #define START_TIME 6 |
|
35 | #define START_TIME 6 | |
14 | #define STOP_TIME 7 |
|
36 | #define STOP_TIME 7 | |
15 |
|
37 | |||
16 |
|
38 | |||
17 | typedef struct CassiniIndexLine |
|
39 | typedef struct CassiniIndexLine | |
18 | { |
|
40 | { | |
19 | QString cels[8]; |
|
41 | QString cels[8]; | |
20 | }CassiniIndexLine; |
|
42 | }CassiniIndexLine; | |
21 |
|
43 | |||
22 | class CassiniIndexFile:QObject |
|
44 | class CassiniIndexFile:QObject | |
23 | { |
|
45 | { | |
24 | Q_OBJECT |
|
46 | Q_OBJECT | |
25 | public: |
|
47 | public: | |
26 | CassiniIndexFile(); |
|
48 | CassiniIndexFile(); | |
27 | ~CassiniIndexFile(); |
|
49 | ~CassiniIndexFile(); | |
28 | QList<CassiniIndexLine> loadFile(const QString& file); |
|
50 | QList<CassiniIndexLine> loadFile(const QString& file); | |
29 | signals: |
|
51 | signals: | |
30 | public slots: |
|
52 | public slots: | |
31 | private: |
|
53 | private: | |
32 | }; |
|
54 | }; | |
33 |
|
55 | |||
34 | #endif // CASSINIINDEXFILE_H |
|
56 | #endif // CASSINIINDEXFILE_H |
@@ -1,69 +1,91 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "cassiniindexfileviewer.h" |
|
23 | #include "cassiniindexfileviewer.h" | |
2 | #include "ui_cassiniindexfileviewer.h" |
|
24 | #include "ui_cassiniindexfileviewer.h" | |
3 | #include <QFileDialog> |
|
25 | #include <QFileDialog> | |
4 |
|
26 | |||
5 | CassiniIndexFileViewer::CassiniIndexFileViewer(QWidget *parent) : |
|
27 | CassiniIndexFileViewer::CassiniIndexFileViewer(QWidget *parent) : | |
6 | QWidget(parent), |
|
28 | QWidget(parent), | |
7 | ui(new Ui::CassiniIndexFileViewer) |
|
29 | ui(new Ui::CassiniIndexFileViewer) | |
8 | { |
|
30 | { | |
9 | ui->setupUi(this); |
|
31 | ui->setupUi(this); | |
10 | this->indexFile = new CassiniIndexFile(); |
|
32 | this->indexFile = new CassiniIndexFile(); | |
11 | connect(this->ui->loadFileQpb,SIGNAL(clicked()),this,SLOT(loadFile())); |
|
33 | connect(this->ui->loadFileQpb,SIGNAL(clicked()),this,SLOT(loadFile())); | |
12 | connect(this->ui->FilteerInput,SIGNAL(textChanged(QString)),this,SLOT(filterCol(QString))); |
|
34 | connect(this->ui->FilteerInput,SIGNAL(textChanged(QString)),this,SLOT(filterCol(QString))); | |
13 | } |
|
35 | } | |
14 |
|
36 | |||
15 | CassiniIndexFileViewer::~CassiniIndexFileViewer() |
|
37 | CassiniIndexFileViewer::~CassiniIndexFileViewer() | |
16 | { |
|
38 | { | |
17 | delete this->indexFile; |
|
39 | delete this->indexFile; | |
18 | delete ui; |
|
40 | delete ui; | |
19 | } |
|
41 | } | |
20 |
|
42 | |||
21 | void CassiniIndexFileViewer::filterCol(const QString &pattern) |
|
43 | void CassiniIndexFileViewer::filterCol(const QString &pattern) | |
22 | { |
|
44 | { | |
23 | Qt::MatchFlags flag = Qt::MatchContains | Qt::MatchStartsWith | Qt::MatchEndsWith | Qt::MatchRegExp | Qt::MatchWildcard | Qt::MatchWrap |Qt::MatchRecursive; |
|
45 | Qt::MatchFlags flag = Qt::MatchContains | Qt::MatchStartsWith | Qt::MatchEndsWith | Qt::MatchRegExp | Qt::MatchWildcard | Qt::MatchWrap |Qt::MatchRecursive; | |
24 | if(this->ui->FilterCaseSensitive->isChecked()) |
|
46 | if(this->ui->FilterCaseSensitive->isChecked()) | |
25 | flag |= Qt::MatchCaseSensitive; |
|
47 | flag |= Qt::MatchCaseSensitive; | |
26 | if(pattern.isEmpty()) |
|
48 | if(pattern.isEmpty()) | |
27 | { |
|
49 | { | |
28 | for(int i=0;i<this->ui->IndexView->rowCount();i++) |
|
50 | for(int i=0;i<this->ui->IndexView->rowCount();i++) | |
29 | this->ui->IndexView->setRowHidden(i,false); |
|
51 | this->ui->IndexView->setRowHidden(i,false); | |
30 | } |
|
52 | } | |
31 | else |
|
53 | else | |
32 | { |
|
54 | { | |
33 | for(int i=0;i<this->ui->IndexView->rowCount();i++) |
|
55 | for(int i=0;i<this->ui->IndexView->rowCount();i++) | |
34 | this->ui->IndexView->setRowHidden(i,true); |
|
56 | this->ui->IndexView->setRowHidden(i,true); | |
35 | QList<QTableWidgetItem*> items = this->ui->IndexView->findItems(pattern,flag); |
|
57 | QList<QTableWidgetItem*> items = this->ui->IndexView->findItems(pattern,flag); | |
36 | for(int i=0;i<items.count();i++) |
|
58 | for(int i=0;i<items.count();i++) | |
37 | this->ui->IndexView->setRowHidden(items.at(i)->row(),false); |
|
59 | this->ui->IndexView->setRowHidden(items.at(i)->row(),false); | |
38 | } |
|
60 | } | |
39 | } |
|
61 | } | |
40 |
|
62 | |||
41 | void CassiniIndexFileViewer::loadFile() |
|
63 | void CassiniIndexFileViewer::loadFile() | |
42 | { |
|
64 | { | |
43 | QList<CassiniIndexLine> lines=this->indexFile->loadFile(QFileDialog::getOpenFileName()); |
|
65 | QList<CassiniIndexLine> lines=this->indexFile->loadFile(QFileDialog::getOpenFileName()); | |
44 | this->ui->IndexView->clear(); |
|
66 | this->ui->IndexView->clear(); | |
45 | this->ui->IndexView->setRowCount(lines.count()); |
|
67 | this->ui->IndexView->setRowCount(lines.count()); | |
46 | this->ui->IndexView->setHorizontalHeaderLabels(QStringList()<<"Dataset ID"<<"File specification name"<<"Product ID"<<"Volume ID"<<"Product Creation Time"<<"Taget name"<<"Start time"<<"Stop time"); |
|
68 | this->ui->IndexView->setHorizontalHeaderLabels(QStringList()<<"Dataset ID"<<"File specification name"<<"Product ID"<<"Volume ID"<<"Product Creation Time"<<"Taget name"<<"Start time"<<"Stop time"); | |
47 | for(int i=0;i<lines.count();i++) |
|
69 | for(int i=0;i<lines.count();i++) | |
48 | { |
|
70 | { | |
49 | for(int j=0;j<8;j++) |
|
71 | for(int j=0;j<8;j++) | |
50 | { |
|
72 | { | |
51 | QString cel=QString(lines.at(i).cels[j]).remove('\n').remove('\r'); |
|
73 | QString cel=QString(lines.at(i).cels[j]).remove('\n').remove('\r'); | |
52 | QTableWidgetItem *newItem = new QTableWidgetItem(cel); |
|
74 | QTableWidgetItem *newItem = new QTableWidgetItem(cel); | |
53 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); |
|
75 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); | |
54 | this->ui->IndexView->setItem(i, j, newItem); |
|
76 | this->ui->IndexView->setItem(i, j, newItem); | |
55 | } |
|
77 | } | |
56 | } |
|
78 | } | |
57 | } |
|
79 | } | |
58 |
|
80 | |||
59 | void CassiniIndexFileViewer::changeEvent(QEvent *e) |
|
81 | void CassiniIndexFileViewer::changeEvent(QEvent *e) | |
60 | { |
|
82 | { | |
61 | QWidget::changeEvent(e); |
|
83 | QWidget::changeEvent(e); | |
62 | switch (e->type()) { |
|
84 | switch (e->type()) { | |
63 | case QEvent::LanguageChange: |
|
85 | case QEvent::LanguageChange: | |
64 | ui->retranslateUi(this); |
|
86 | ui->retranslateUi(this); | |
65 | break; |
|
87 | break; | |
66 | default: |
|
88 | default: | |
67 | break; |
|
89 | break; | |
68 | } |
|
90 | } | |
69 | } |
|
91 | } |
@@ -1,30 +1,52 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef CASSINIINDEXFILEVIEWER_H |
|
23 | #ifndef CASSINIINDEXFILEVIEWER_H | |
2 | #define CASSINIINDEXFILEVIEWER_H |
|
24 | #define CASSINIINDEXFILEVIEWER_H | |
3 |
|
25 | |||
4 | #include <QWidget> |
|
26 | #include <QWidget> | |
5 | #include <cassiniindexfile.h> |
|
27 | #include <cassiniindexfile.h> | |
6 |
|
28 | |||
7 | namespace Ui { |
|
29 | namespace Ui { | |
8 | class CassiniIndexFileViewer; |
|
30 | class CassiniIndexFileViewer; | |
9 | } |
|
31 | } | |
10 |
|
32 | |||
11 | class CassiniIndexFileViewer : public QWidget |
|
33 | class CassiniIndexFileViewer : public QWidget | |
12 | { |
|
34 | { | |
13 | Q_OBJECT |
|
35 | Q_OBJECT | |
14 |
|
36 | |||
15 | public: |
|
37 | public: | |
16 | explicit CassiniIndexFileViewer(QWidget *parent = 0); |
|
38 | explicit CassiniIndexFileViewer(QWidget *parent = 0); | |
17 | ~CassiniIndexFileViewer(); |
|
39 | ~CassiniIndexFileViewer(); | |
18 |
|
40 | |||
19 | public slots: |
|
41 | public slots: | |
20 | void filterCol(const QString& pattern); |
|
42 | void filterCol(const QString& pattern); | |
21 | void loadFile(); |
|
43 | void loadFile(); | |
22 | protected: |
|
44 | protected: | |
23 | void changeEvent(QEvent *e); |
|
45 | void changeEvent(QEvent *e); | |
24 |
|
46 | |||
25 | private: |
|
47 | private: | |
26 | Ui::CassiniIndexFileViewer *ui; |
|
48 | Ui::CassiniIndexFileViewer *ui; | |
27 | CassiniIndexFile* indexFile; |
|
49 | CassiniIndexFile* indexFile; | |
28 | }; |
|
50 | }; | |
29 |
|
51 | |||
30 | #endif // CASSINIINDEXFILEVIEWER_H |
|
52 | #endif // CASSINIINDEXFILEVIEWER_H |
@@ -1,277 +1,306 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "cassinitools.h" |
|
23 | #include "cassinitools.h" | |
2 | #include <qlopplots.h> |
|
24 | #include <qlopplots.h> | |
3 | #include <QPen> |
|
25 | #include <QPen> | |
4 | #include <QAction> |
|
26 | #include <QAction> | |
5 | #include <fftw3.h> |
|
27 | #include <fftw3.h> | |
|
28 | #include <omp.h> | |||
6 |
|
29 | |||
7 | CassiniTools* CassiniTools::_self=NULL; |
|
30 | CassiniTools* CassiniTools::_self=NULL; | |
8 | QDockWidget* CassiniTools::m_gui=NULL; |
|
31 | QDockWidget* CassiniTools::m_gui=NULL; | |
9 | CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL; |
|
32 | CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL; | |
10 | CassiniDataFile* CassiniTools::m_dataFile=NULL; |
|
33 | CassiniDataFile* CassiniTools::m_dataFile=NULL; | |
11 | int CassiniTools::m_defaultPlot=-1; |
|
34 | int CassiniTools::m_defaultPlot=-1; | |
12 | int CassiniTools::m_fftPlot=-1; |
|
35 | int CassiniTools::m_fftPlot=-1; | |
13 | SocExplorerPlotActions* CassiniTools::ExportAction=NULL; |
|
36 | SocExplorerPlotActions* CassiniTools::ExportAction=NULL; | |
14 |
|
37 | |||
15 | Qt::GlobalColor QLopColours[]= {Qt::black, |
|
38 | Qt::GlobalColor QLopColours[]= {Qt::black, | |
16 | Qt::red, |
|
39 | Qt::red, | |
17 | Qt::blue, |
|
40 | Qt::blue, | |
18 | Qt::green, |
|
41 | Qt::green, | |
19 | Qt::darkGreen, |
|
42 | Qt::darkGreen, | |
20 | Qt::cyan, |
|
43 | Qt::cyan, | |
21 | Qt::darkRed, |
|
44 | Qt::darkRed, | |
22 | Qt::gray, |
|
45 | Qt::gray, | |
23 | Qt::yellow, |
|
46 | Qt::yellow, | |
24 | Qt::darkBlue, |
|
47 | Qt::darkBlue, | |
25 | Qt::darkCyan, |
|
48 | Qt::darkCyan, | |
26 | Qt::magenta, |
|
49 | Qt::magenta, | |
27 | Qt::darkMagenta, |
|
50 | Qt::darkMagenta, | |
28 | Qt::darkYellow, |
|
51 | Qt::darkYellow, | |
29 | Qt::darkGray, |
|
52 | Qt::darkGray, | |
30 | Qt::lightGray}; |
|
53 | Qt::lightGray}; | |
31 |
|
54 | |||
32 | int QLopColoursCount=16; |
|
55 | int QLopColoursCount=16; | |
33 |
|
56 | |||
34 | #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();} |
|
57 | #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();} | |
35 |
|
58 | |||
36 | CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent) |
|
59 | CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent) | |
37 | { |
|
60 | { | |
38 | m_dataFile = new CassiniDataFile(); |
|
61 | m_dataFile = new CassiniDataFile(); | |
39 | connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList))); |
|
62 | connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList))); | |
40 | m_serviceName="CassiniTools"; |
|
63 | m_serviceName="CassiniTools"; | |
41 | m_noGui=noGUI; |
|
64 | m_noGui=noGUI; | |
|
65 | fftw_init_threads(); | |||
42 | } |
|
66 | } | |
43 |
|
67 | |||
44 | CassiniTools::~CassiniTools() |
|
68 | CassiniTools::~CassiniTools() | |
45 | { |
|
69 | { | |
46 | delete m_dataFile; |
|
70 | delete m_dataFile; | |
47 | delete m_CassiniToolsGUI; |
|
71 | delete m_CassiniToolsGUI; | |
48 | delete m_gui; |
|
72 | delete m_gui; | |
49 | } |
|
73 | } | |
50 |
|
74 | |||
51 | void CassiniTools::makePlot() |
|
75 | void CassiniTools::makePlot() | |
52 | { |
|
76 | { | |
53 | m_defaultPlot = QLopPlots::addPlot(); |
|
77 | m_defaultPlot = QLopPlots::addPlot(); | |
54 | m_fftPlot = QLopPlots::addPlot(); |
|
78 | m_fftPlot = QLopPlots::addPlot(); | |
55 | SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot); |
|
79 | SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot); | |
56 | if(plot) |
|
80 | if(plot) | |
57 | { |
|
81 | { | |
58 | plot->setTitle(_self->m_serviceName + " plot"); |
|
82 | plot->setTitle(_self->m_serviceName + " plot"); | |
59 | plot->setXaxisTickLabelType(QCPAxis::ltDateTime); |
|
83 | plot->setXaxisTickLabelType(QCPAxis::ltDateTime); | |
60 | plot->setXaxisDateTimeFormat("hh:mm:ss.zzz"); |
|
84 | plot->setXaxisDateTimeFormat("hh:mm:ss.zzz"); | |
61 | plot->setContextMenuPolicy(Qt::ActionsContextMenu); |
|
85 | plot->setContextMenuPolicy(Qt::ActionsContextMenu); | |
62 | SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self); |
|
86 | SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self); | |
63 | plot->addAction(action); |
|
87 | plot->addAction(action); | |
64 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int))); |
|
88 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int))); | |
65 | ExportAction=new SocExplorerPlotActions("export view to "+QString(plot->title()).replace(".TAB","-part.TAB"),plot->PID(),_self); |
|
89 | ExportAction=new SocExplorerPlotActions("export view to "+QString(plot->title()).replace(".TAB","-part.TAB"),plot->PID(),_self); | |
66 | plot->addAction(ExportAction); |
|
90 | plot->addAction(ExportAction); | |
67 | QObject::connect(ExportAction,SIGNAL(triggered(int)),_self,SLOT(export_view_Predefined_FileName(int))); |
|
91 | QObject::connect(ExportAction,SIGNAL(triggered(int)),_self,SLOT(export_view_Predefined_FileName(int))); | |
68 | action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self); |
|
92 | action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self); | |
69 | plot->addAction(action); |
|
93 | plot->addAction(action); | |
70 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int))); |
|
94 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int))); | |
71 | } |
|
95 | } | |
72 | } |
|
96 | } | |
73 |
|
97 | |||
74 | void CassiniTools::init(bool noGUI, QObject *parent) |
|
98 | void CassiniTools::init(bool noGUI, QObject *parent) | |
75 | { |
|
99 | { | |
76 | if(Q_UNLIKELY(_self==NULL)) |
|
100 | if(Q_UNLIKELY(_self==NULL)) | |
77 | { |
|
101 | { | |
78 | _self=new CassiniTools(noGUI,parent); |
|
102 | _self=new CassiniTools(noGUI,parent); | |
79 | } |
|
103 | } | |
80 | } |
|
104 | } | |
81 |
|
105 | |||
82 | CassiniTools *CassiniTools::self() |
|
106 | CassiniTools *CassiniTools::self() | |
83 | { |
|
107 | { | |
84 | _INIT(); |
|
108 | _INIT(); | |
85 | return _self; |
|
109 | return _self; | |
86 | } |
|
110 | } | |
87 |
|
111 | |||
88 | void CassiniTools::decodeFGMData(const QString &file) |
|
112 | void CassiniTools::decodeFGMData(const QString &file) | |
89 | { |
|
113 | { | |
90 | _INIT(); |
|
114 | _INIT(); | |
91 | m_dataFile->parseFile(file); |
|
115 | m_dataFile->parseFile(file); | |
92 | } |
|
116 | } | |
93 |
|
117 | |||
94 | void CassiniTools::plotFile(const QString &File) |
|
118 | void CassiniTools::plotFile(const QString &File) | |
95 | { |
|
119 | { | |
96 | if(!m_dataFile->isRunning()) |
|
120 | if(!m_dataFile->isRunning()) | |
97 | { |
|
121 | { | |
98 | m_dataFile->parseFile(File); |
|
122 | m_dataFile->parseFile(File); | |
99 | // TODO fixme |
|
123 | // TODO fixme | |
100 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); |
|
124 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); | |
101 | if(plot==NULL) |
|
125 | if(plot==NULL) | |
102 | { |
|
126 | { | |
103 | makePlot(); |
|
127 | makePlot(); | |
104 | plot = QLopPlots::getPlot(m_defaultPlot); |
|
128 | plot = QLopPlots::getPlot(m_defaultPlot); | |
105 | } |
|
129 | } | |
106 | if(plot) |
|
130 | if(plot) | |
107 | { |
|
131 | { | |
108 | plot->setTitle(File); |
|
132 | plot->setTitle(File); | |
109 | ExportAction->setText("export view to "+QString(File).replace(".TAB","-part.TAB")); |
|
133 | ExportAction->setText("export view to "+QString(File).replace(".TAB","-part.TAB")); | |
110 | } |
|
134 | } | |
111 | } |
|
135 | } | |
112 | } |
|
136 | } | |
113 |
|
137 | |||
114 | void CassiniTools::plot_TAB_File(const QString &fileName) |
|
138 | void CassiniTools::plot_TAB_File(const QString &fileName) | |
115 | { |
|
139 | { | |
116 | //TODO fix: accent not accepted |
|
140 | //TODO fix: accent not accepted | |
117 | plotFile(fileName); |
|
141 | plotFile(fileName); | |
118 | } |
|
142 | } | |
119 |
|
143 | |||
120 | void CassiniTools::export_view(int PID) |
|
144 | void CassiniTools::export_view(int PID) | |
121 | { |
|
145 | { | |
122 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); |
|
146 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); | |
123 | if(plot==NULL) |
|
147 | if(plot==NULL) | |
124 | return; |
|
148 | return; | |
125 | { |
|
149 | { | |
126 | QString fileName = plot->title(); |
|
150 | QString fileName = plot->title(); | |
127 | fileName = QFileDialog::getSaveFileName(0,tr("Set filename"),fileName.replace(".TAB","-part.TAB")); |
|
151 | fileName = QFileDialog::getSaveFileName(0,tr("Set filename"),fileName.replace(".TAB","-part.TAB")); | |
128 | if(fileName!="") |
|
152 | if(fileName!="") | |
129 | { |
|
153 | { | |
130 | QLopDataList vectors; |
|
154 | QLopDataList vectors; | |
131 | for(int i=0;i<plot->graphCount();i++) |
|
155 | for(int i=0;i<plot->graphCount();i++) | |
132 | { |
|
156 | { | |
133 | QLopData* vect = new QLopData(); |
|
157 | QLopData* vect = new QLopData(); | |
134 | vect->data = plot->getVisibleData(i); |
|
158 | vect->data = plot->getVisibleData(i); | |
135 | vectors.append(vect); |
|
159 | vectors.append(vect); | |
136 | } |
|
160 | } | |
137 | m_dataFile->saveFile(fileName,vectors); |
|
161 | m_dataFile->saveFile(fileName,vectors); | |
138 | } |
|
162 | } | |
139 | } |
|
163 | } | |
140 | } |
|
164 | } | |
141 |
|
165 | |||
142 | void CassiniTools::export_view_Predefined_FileName(int PID) |
|
166 | void CassiniTools::export_view_Predefined_FileName(int PID) | |
143 | { |
|
167 | { | |
144 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); |
|
168 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); | |
145 | if(plot==NULL) |
|
169 | if(plot==NULL) | |
146 | return; |
|
170 | return; | |
147 | { |
|
171 | { | |
148 | QString fileName = QString(plot->title()).replace(".TAB","-part.TAB"); |
|
172 | QString fileName = QString(plot->title()).replace(".TAB","-part.TAB"); | |
149 | if(fileName!="") |
|
173 | if(fileName!="") | |
150 | { |
|
174 | { | |
151 | QLopDataList vectors; |
|
175 | QLopDataList vectors; | |
152 | for(int i=0;i<plot->graphCount();i++) |
|
176 | for(int i=0;i<plot->graphCount();i++) | |
153 | { |
|
177 | { | |
154 | QLopData* vect = new QLopData(); |
|
178 | QLopData* vect = new QLopData(); | |
155 | vect->data = plot->getVisibleData(i); |
|
179 | vect->data = plot->getVisibleData(i); | |
156 | vectors.append(vect); |
|
180 | vectors.append(vect); | |
157 | } |
|
181 | } | |
158 | m_dataFile->saveFile(fileName,vectors); |
|
182 | m_dataFile->saveFile(fileName,vectors); | |
159 | } |
|
183 | } | |
160 | } |
|
184 | } | |
161 | } |
|
185 | } | |
162 |
|
186 | |||
163 | void CassiniTools::compute_fft_on_view(int PID) |
|
187 | void CassiniTools::compute_fft_on_view(int PID) | |
164 | { |
|
188 | { | |
|
189 | ||||
|
190 | QElapsedTimer timr; | |||
165 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); |
|
191 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); | |
166 | if(plot==NULL) |
|
192 | if(plot==NULL) | |
167 | return; |
|
193 | return; | |
168 | { |
|
194 | { | |
|
195 | timr.start(); | |||
169 | QLopDataList vectors; |
|
196 | QLopDataList vectors; | |
170 | for(int i=0;i<plot->graphCount();i++) |
|
197 | for(int i=0;i<plot->graphCount();i++) | |
171 | { |
|
198 | { | |
172 | QLopData* vect = new QLopData(); |
|
199 | QLopData* vect = new QLopData(); | |
173 | vect->data = plot->getVisibleData(i); |
|
200 | vect->data = plot->getVisibleData(i); | |
174 | vectors.append(vect); |
|
201 | vectors.append(vect); | |
175 | } |
|
202 | } | |
176 | if(vectors.count()==3) |
|
203 | if(vectors.count()==3) | |
177 | { |
|
204 | { | |
178 | QLopData* ch1V=vectors.at(0); |
|
205 | QLopData* ch1V=vectors.at(0); | |
179 | QLopData* ch2V=vectors.at(1); |
|
206 | QLopData* ch2V=vectors.at(1); | |
180 | QLopData* ch3V=vectors.at(2); |
|
207 | QLopData* ch3V=vectors.at(2); | |
181 | QLopData* FFTout=new QLopData(); |
|
208 | QLopData* FFTout=new QLopData(); | |
182 | if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) |
|
209 | if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) | |
183 | { |
|
210 | { | |
184 |
|
211 | |||
185 | double* in; |
|
212 | double* in; | |
186 | fftw_complex *out; |
|
213 | fftw_complex *out; | |
187 | fftw_plan p; |
|
214 | fftw_plan p; | |
188 | FFTout->data = new QVector<QCPData>(ch1V->data->count()/2); |
|
215 | FFTout->data = new QVector<QCPData>(ch1V->data->count()/2); | |
189 | in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count()); |
|
216 | in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count()); | |
190 | out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count()); |
|
217 | out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count()); | |
191 | double av=0; |
|
218 | double av=0; | |
192 | for(int i=0;i<ch1V->data->count();i++) |
|
219 | for(int i=0;i<ch1V->data->count();i++) | |
193 | { |
|
220 | { | |
194 | in[i]=sqrt((ch1V->data->at(i).value*ch1V->data->at(i).value) + (ch2V->data->at(i).value*ch2V->data->at(i).value) + (ch3V->data->at(i).value*ch3V->data->at(i).value)); |
|
221 | in[i]=sqrt((ch1V->data->at(i).value*ch1V->data->at(i).value) + (ch2V->data->at(i).value*ch2V->data->at(i).value) + (ch3V->data->at(i).value*ch3V->data->at(i).value)); | |
195 | av = av+in[i]; |
|
222 | av = av+in[i]; | |
196 | } |
|
223 | } | |
197 | av/=ch1V->data->count(); |
|
224 | av/=ch1V->data->count(); | |
198 | for(int i=0;i<ch1V->data->count();i++) |
|
225 | for(int i=0;i<ch1V->data->count();i++) | |
199 | { |
|
226 | { | |
200 | in[i]=in[i]-av; |
|
227 | in[i]=in[i]-av; | |
201 | } |
|
228 | } | |
|
229 | fftw_plan_with_nthreads(4); | |||
202 | p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE); |
|
230 | p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE); | |
203 | fftw_execute(p); /* repeat as needed */ |
|
231 | fftw_execute(p); /* repeat as needed */ | |
204 | fftw_destroy_plan(p); |
|
232 | fftw_destroy_plan(p); | |
205 | fftw_free(in); |
|
233 | fftw_free(in); | |
206 | for(int i=0;i<ch1V->data->count()/2;i++) |
|
234 | for(int i=0;i<ch1V->data->count()/2;i++) | |
207 | { |
|
235 | { | |
208 | // (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count(); |
|
236 | // (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count(); | |
209 | (*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count()); |
|
237 | (*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count()); | |
210 | (*FFTout->data)[i].key = i; |
|
238 | (*FFTout->data)[i].key = i; | |
211 | } |
|
239 | } | |
212 | fftw_free(out); |
|
240 | fftw_free(out); | |
213 | SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot); |
|
241 | SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot); | |
214 | if(plot==NULL) |
|
242 | if(plot==NULL) | |
215 | return; |
|
243 | return; | |
216 | plot->removeAllGraphs(); |
|
244 | plot->removeAllGraphs(); | |
217 | plot->addGraph(); |
|
245 | plot->addGraph(); | |
218 | plot->setXaxisLog(); |
|
246 | plot->setXaxisLog(); | |
219 | plot->setYaxisLog(); |
|
247 | plot->setYaxisLog(); | |
220 | plot->setAdaptativeSampling(0,true); |
|
248 | plot->setAdaptativeSampling(0,true); | |
221 | QPen pen = plot->getGraphPen(0); |
|
249 | QPen pen = plot->getGraphPen(0); | |
222 | pen.setColor(QLopColours[0%QLopColoursCount]); |
|
250 | pen.setColor(QLopColours[0%QLopColoursCount]); | |
223 | plot->setGraphPen(0,pen); |
|
251 | plot->setGraphPen(0,pen); | |
224 | plot->setGraphData(0,FFTout->data,false); |
|
252 | plot->setGraphData(0,FFTout->data,false); | |
225 | plot->rescaleAxis(); |
|
253 | plot->rescaleAxis(); | |
226 | plot->replot(); |
|
254 | plot->replot(); | |
227 |
|
255 | |||
|
256 | qDebug()<< ch1V->data->count() <<" Points loaded in "<< timr.elapsed()<<"ms"; | |||
228 | } |
|
257 | } | |
229 | } |
|
258 | } | |
230 | } |
|
259 | } | |
231 | } |
|
260 | } | |
232 |
|
261 | |||
233 | QDockWidget *CassiniTools::getGUI() |
|
262 | QDockWidget *CassiniTools::getGUI() | |
234 | { |
|
263 | { | |
235 | if(!m_noGui && (m_gui==NULL)) |
|
264 | if(!m_noGui && (m_gui==NULL)) | |
236 | { |
|
265 | { | |
237 | m_gui=new QDockWidget("Cassini Tools"); |
|
266 | m_gui=new QDockWidget("Cassini Tools"); | |
238 | m_CassiniToolsGUI = new CassiniToolsGUI(); |
|
267 | m_CassiniToolsGUI = new CassiniToolsGUI(); | |
239 | m_gui->setWidget(m_CassiniToolsGUI); |
|
268 | m_gui->setWidget(m_CassiniToolsGUI); | |
240 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
269 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | |
241 | } |
|
270 | } | |
242 | return m_gui; |
|
271 | return m_gui; | |
243 | } |
|
272 | } | |
244 |
|
273 | |||
245 | const QString &CassiniTools::serviceName() |
|
274 | const QString &CassiniTools::serviceName() | |
246 | { |
|
275 | { | |
247 | _INIT(); |
|
276 | _INIT(); | |
248 | return m_serviceName; |
|
277 | return m_serviceName; | |
249 | } |
|
278 | } | |
250 |
|
279 | |||
251 | void CassiniTools::dataReady(QLopDataList data) |
|
280 | void CassiniTools::dataReady(QLopDataList data) | |
252 | { |
|
281 | { | |
253 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); |
|
282 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); | |
254 | if(plot==NULL) |
|
283 | if(plot==NULL) | |
255 | { |
|
284 | { | |
256 | makePlot(); |
|
285 | makePlot(); | |
257 | plot = QLopPlots::getPlot(m_defaultPlot); |
|
286 | plot = QLopPlots::getPlot(m_defaultPlot); | |
258 | } |
|
287 | } | |
259 | if(plot) |
|
288 | if(plot) | |
260 | { |
|
289 | { | |
261 | plot->removeAllGraphs(); |
|
290 | plot->removeAllGraphs(); | |
262 | for(int i=0;i<data.count();i++) |
|
291 | for(int i=0;i<data.count();i++) | |
263 | { |
|
292 | { | |
264 | plot->addGraph(); |
|
293 | plot->addGraph(); | |
265 | plot->setAdaptativeSampling(i,true); |
|
294 | plot->setAdaptativeSampling(i,true); | |
266 | plot->setUseFastVector(i,true); |
|
295 | plot->setUseFastVector(i,true); | |
267 | QPen pen = plot->getGraphPen(i); |
|
296 | QPen pen = plot->getGraphPen(i); | |
268 | pen.setColor(QLopColours[i%QLopColoursCount]); |
|
297 | pen.setColor(QLopColours[i%QLopColoursCount]); | |
269 | plot->setGraphPen(i,pen); |
|
298 | plot->setGraphPen(i,pen); | |
270 | plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")"); |
|
299 | plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")"); | |
271 | plot->setGraphData(i,data.at(i)->data,false); |
|
300 | plot->setGraphData(i,data.at(i)->data,false); | |
272 | } |
|
301 | } | |
273 | plot->rescaleAxis(); |
|
302 | plot->rescaleAxis(); | |
274 | plot->replot(); |
|
303 | plot->replot(); | |
275 | } |
|
304 | } | |
276 | } |
|
305 | } | |
277 |
|
306 |
@@ -1,43 +1,64 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
1 | #ifndef CASSINITOOLS_H |
|
22 | #ifndef CASSINITOOLS_H | |
2 | #define CASSINITOOLS_H |
|
23 | #define CASSINITOOLS_H | |
3 |
|
24 | |||
4 | #include <QObject> |
|
25 | #include <QObject> | |
5 | #include <QWidget> |
|
26 | #include <QWidget> | |
6 | #include <qlopservice.h> |
|
27 | #include <qlopservice.h> | |
7 | #include <cassinitoolsgui.h> |
|
28 | #include <cassinitoolsgui.h> | |
8 | #include <cassinidatafile.h> |
|
29 | #include <cassinidatafile.h> | |
9 | #include <qlopdata.h> |
|
30 | #include <qlopdata.h> | |
10 | #include <SocExplorerPlot.h> |
|
31 | #include <SocExplorerPlot.h> | |
11 |
|
32 | |||
12 | class CassiniTools: public QLopService |
|
33 | class CassiniTools: public QLopService | |
13 | { |
|
34 | { | |
14 | Q_OBJECT |
|
35 | Q_OBJECT | |
15 | private: |
|
36 | private: | |
16 | static CassiniTools* _self; |
|
37 | static CassiniTools* _self; | |
17 | static QDockWidget* m_gui; |
|
38 | static QDockWidget* m_gui; | |
18 | static CassiniToolsGUI* m_CassiniToolsGUI; |
|
39 | static CassiniToolsGUI* m_CassiniToolsGUI; | |
19 | static CassiniDataFile* m_dataFile; |
|
40 | static CassiniDataFile* m_dataFile; | |
20 | static int m_defaultPlot,m_fftPlot; |
|
41 | static int m_defaultPlot,m_fftPlot; | |
21 | static SocExplorerPlotActions* ExportAction; |
|
42 | static SocExplorerPlotActions* ExportAction; | |
22 | CassiniTools(bool noGUI=false, QObject *parent=0); |
|
43 | CassiniTools(bool noGUI=false, QObject *parent=0); | |
23 | ~CassiniTools(); |
|
44 | ~CassiniTools(); | |
24 | static void makePlot(); |
|
45 | static void makePlot(); | |
25 | public: |
|
46 | public: | |
26 | static void init(bool noGUI=false,QObject *parent = 0); |
|
47 | static void init(bool noGUI=false,QObject *parent = 0); | |
27 | static CassiniTools *self(); |
|
48 | static CassiniTools *self(); | |
28 | static void decodeFGMData(const QString& file); |
|
49 | static void decodeFGMData(const QString& file); | |
29 | // QLopService methodes |
|
50 | // QLopService methodes | |
30 | QDockWidget* getGUI(); |
|
51 | QDockWidget* getGUI(); | |
31 | const QString& serviceName(); |
|
52 | const QString& serviceName(); | |
32 | static void plotFile(const QString &File); |
|
53 | static void plotFile(const QString &File); | |
33 | public slots: |
|
54 | public slots: | |
34 | void plot_TAB_File(const QString& fileName); |
|
55 | void plot_TAB_File(const QString& fileName); | |
35 | void export_view(int PID); |
|
56 | void export_view(int PID); | |
36 | void export_view_Predefined_FileName(int PID); |
|
57 | void export_view_Predefined_FileName(int PID); | |
37 | void compute_fft_on_view(int PID); |
|
58 | void compute_fft_on_view(int PID); | |
38 | private slots: |
|
59 | private slots: | |
39 | void dataReady(QLopDataList data); |
|
60 | void dataReady(QLopDataList data); | |
40 | }; |
|
61 | }; | |
41 |
|
62 | |||
42 | #endif // CASSINITOOLS_H |
|
63 | #endif // CASSINITOOLS_H | |
43 |
|
64 |
@@ -1,43 +1,65 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "cassinitoolsgui.h" |
|
23 | #include "cassinitoolsgui.h" | |
2 | #include "ui_cassinitoolsgui.h" |
|
24 | #include "ui_cassinitoolsgui.h" | |
3 | #include <cassinitools.h> |
|
25 | #include <cassinitools.h> | |
4 |
|
26 | |||
5 | CassiniToolsGUI::CassiniToolsGUI(QWidget *parent) : |
|
27 | CassiniToolsGUI::CassiniToolsGUI(QWidget *parent) : | |
6 | QWidget(parent), |
|
28 | QWidget(parent), | |
7 | ui(new Ui::CassiniToolsGUI) |
|
29 | ui(new Ui::CassiniToolsGUI) | |
8 | { |
|
30 | { | |
9 | ui->setupUi(this); |
|
31 | ui->setupUi(this); | |
10 | connect(this->ui->addFolderViewQpb,SIGNAL(clicked()),this,SLOT(addFolderView())); |
|
32 | connect(this->ui->addFolderViewQpb,SIGNAL(clicked()),this,SLOT(addFolderView())); | |
11 | } |
|
33 | } | |
12 |
|
34 | |||
13 | CassiniToolsGUI::~CassiniToolsGUI() |
|
35 | CassiniToolsGUI::~CassiniToolsGUI() | |
14 | { |
|
36 | { | |
15 | delete ui; |
|
37 | delete ui; | |
16 | } |
|
38 | } | |
17 |
|
39 | |||
18 | void CassiniToolsGUI::addFolderView() |
|
40 | void CassiniToolsGUI::addFolderView() | |
19 | { |
|
41 | { | |
20 | this->fileBrowsers.append(new FileBrowser()); |
|
42 | this->fileBrowsers.append(new FileBrowser()); | |
21 | this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->fileBrowsers.last()); |
|
43 | this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->fileBrowsers.last()); | |
22 | this->fileBrowsers.last()->setWindowTitle( QString("Browser %1").arg(this->fileBrowsers.length())); |
|
44 | this->fileBrowsers.last()->setWindowTitle( QString("Browser %1").arg(this->fileBrowsers.length())); | |
23 | this->fileBrowsers.last()->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
45 | this->fileBrowsers.last()->setAllowedAreas(Qt::AllDockWidgetAreas); | |
24 | this->fileBrowsers.last()->setNameFilters(QStringList()<<"*.TAB"); |
|
46 | this->fileBrowsers.last()->setNameFilters(QStringList()<<"*.TAB"); | |
25 | connect(this->fileBrowsers.last(),SIGNAL(fileDoubleClicked(QString)),this,SLOT(plotFile(QString))); |
|
47 | connect(this->fileBrowsers.last(),SIGNAL(fileDoubleClicked(QString)),this,SLOT(plotFile(QString))); | |
26 | } |
|
48 | } | |
27 |
|
49 | |||
28 | void CassiniToolsGUI::plotFile(const QString &File) |
|
50 | void CassiniToolsGUI::plotFile(const QString &File) | |
29 | { |
|
51 | { | |
30 | CassiniTools::plotFile(File); |
|
52 | CassiniTools::plotFile(File); | |
31 | } |
|
53 | } | |
32 |
|
54 | |||
33 | void CassiniToolsGUI::changeEvent(QEvent *e) |
|
55 | void CassiniToolsGUI::changeEvent(QEvent *e) | |
34 | { |
|
56 | { | |
35 | QWidget::changeEvent(e); |
|
57 | QWidget::changeEvent(e); | |
36 | switch (e->type()) { |
|
58 | switch (e->type()) { | |
37 | case QEvent::LanguageChange: |
|
59 | case QEvent::LanguageChange: | |
38 | ui->retranslateUi(this); |
|
60 | ui->retranslateUi(this); | |
39 | break; |
|
61 | break; | |
40 | default: |
|
62 | default: | |
41 | break; |
|
63 | break; | |
42 | } |
|
64 | } | |
43 | } |
|
65 | } |
@@ -1,30 +1,52 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef CASSINITOOLSGUI_H |
|
23 | #ifndef CASSINITOOLSGUI_H | |
2 | #define CASSINITOOLSGUI_H |
|
24 | #define CASSINITOOLSGUI_H | |
3 |
|
25 | |||
4 | #include <QWidget> |
|
26 | #include <QWidget> | |
5 | #include <filebrowser.h> |
|
27 | #include <filebrowser.h> | |
6 |
|
28 | |||
7 | namespace Ui { |
|
29 | namespace Ui { | |
8 | class CassiniToolsGUI; |
|
30 | class CassiniToolsGUI; | |
9 | } |
|
31 | } | |
10 |
|
32 | |||
11 | class CassiniToolsGUI : public QWidget |
|
33 | class CassiniToolsGUI : public QWidget | |
12 | { |
|
34 | { | |
13 | Q_OBJECT |
|
35 | Q_OBJECT | |
14 |
|
36 | |||
15 | public: |
|
37 | public: | |
16 | explicit CassiniToolsGUI(QWidget *parent = 0); |
|
38 | explicit CassiniToolsGUI(QWidget *parent = 0); | |
17 | ~CassiniToolsGUI(); |
|
39 | ~CassiniToolsGUI(); | |
18 |
|
40 | |||
19 | protected: |
|
41 | protected: | |
20 | void changeEvent(QEvent *e); |
|
42 | void changeEvent(QEvent *e); | |
21 |
|
43 | |||
22 | private slots: |
|
44 | private slots: | |
23 | void addFolderView(); |
|
45 | void addFolderView(); | |
24 | void plotFile(const QString &File); |
|
46 | void plotFile(const QString &File); | |
25 | private: |
|
47 | private: | |
26 | Ui::CassiniToolsGUI *ui; |
|
48 | Ui::CassiniToolsGUI *ui; | |
27 | QList<FileBrowser*> fileBrowsers; |
|
49 | QList<FileBrowser*> fileBrowsers; | |
28 | }; |
|
50 | }; | |
29 |
|
51 | |||
30 | #endif // CASSINITOOLSGUI_H |
|
52 | #endif // CASSINITOOLSGUI_H |
@@ -1,119 +1,141 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "expxmldownloader.h" |
|
23 | #include "expxmldownloader.h" | |
2 | #include <QDebug> |
|
24 | #include <QDebug> | |
3 | #include <QFile> |
|
25 | #include <QFile> | |
4 | #include <QQueue> |
|
26 | #include <QQueue> | |
5 | #include <QDate> |
|
27 | #include <QDate> | |
6 | #include <QDateTime> |
|
28 | #include <QDateTime> | |
7 |
|
29 | |||
8 | ExpXmlDownLoader::ExpXmlDownLoader(QObject *parent) : QObject(parent) |
|
30 | ExpXmlDownLoader::ExpXmlDownLoader(QObject *parent) : QObject(parent) | |
9 | { |
|
31 | { | |
10 | this->m_doc = NULL; |
|
32 | this->m_doc = NULL; | |
11 | } |
|
33 | } | |
12 |
|
34 | |||
13 | ExpXmlDownLoader::~ExpXmlDownLoader() |
|
35 | ExpXmlDownLoader::~ExpXmlDownLoader() | |
14 | { |
|
36 | { | |
15 |
|
37 | |||
16 | } |
|
38 | } | |
17 |
|
39 | |||
18 | bool ExpXmlDownLoader::parseXml(const QString &fileName) |
|
40 | bool ExpXmlDownLoader::parseXml(const QString &fileName) | |
19 | { |
|
41 | { | |
20 | QQueue<QString> nodes; |
|
42 | QQueue<QString> nodes; | |
21 | nodes<<"RESOURCE"<<"TABLE"<<"DATA"<<"TABLEDATA"; |
|
43 | nodes<<"RESOURCE"<<"TABLE"<<"DATA"<<"TABLEDATA"; | |
22 | if(m_doc!=NULL) |
|
44 | if(m_doc!=NULL) | |
23 | delete m_doc; |
|
45 | delete m_doc; | |
24 | m_doc = new QDomDocument(fileName); |
|
46 | m_doc = new QDomDocument(fileName); | |
25 | QFile file(fileName); |
|
47 | QFile file(fileName); | |
26 | if (!file.open(QIODevice::ReadOnly)) |
|
48 | if (!file.open(QIODevice::ReadOnly)) | |
27 | return false; |
|
49 | return false; | |
28 | if (!m_doc->setContent(&file)) { |
|
50 | if (!m_doc->setContent(&file)) { | |
29 | file.close(); |
|
51 | file.close(); | |
30 | return false; |
|
52 | return false; | |
31 | } |
|
53 | } | |
32 | file.close(); |
|
54 | file.close(); | |
33 | if(m_doc->isNull()) |
|
55 | if(m_doc->isNull()) | |
34 | { |
|
56 | { | |
35 | delete m_doc; |
|
57 | delete m_doc; | |
36 | return false; |
|
58 | return false; | |
37 | } |
|
59 | } | |
38 | QDomElement docElem = m_doc->documentElement(); |
|
60 | QDomElement docElem = m_doc->documentElement(); | |
39 | QDomNode n = docElem.firstChild(); |
|
61 | QDomNode n = docElem.firstChild(); | |
40 | while(!n.isNull() && !nodes.empty()) |
|
62 | while(!n.isNull() && !nodes.empty()) | |
41 | { |
|
63 | { | |
42 | if(n.toElement().tagName()==nodes.head()) |
|
64 | if(n.toElement().tagName()==nodes.head()) | |
43 | { |
|
65 | { | |
44 | nodes.dequeue(); |
|
66 | nodes.dequeue(); | |
45 | n=n.firstChild(); |
|
67 | n=n.firstChild(); | |
46 | } |
|
68 | } | |
47 | else |
|
69 | else | |
48 | { |
|
70 | { | |
49 | n = n.nextSibling(); |
|
71 | n = n.nextSibling(); | |
50 | } |
|
72 | } | |
51 | } |
|
73 | } | |
52 | extractIntervals(n); |
|
74 | extractIntervals(n); | |
53 | makeDownloadList(); |
|
75 | makeDownloadList(); | |
54 | return true; |
|
76 | return true; | |
55 | } |
|
77 | } | |
56 |
|
78 | |||
57 | const QList<QDate> &ExpXmlDownLoader::daysToDownload() |
|
79 | const QList<QDate> &ExpXmlDownLoader::daysToDownload() | |
58 | { |
|
80 | { | |
59 | return m_FilesToDownload; |
|
81 | return m_FilesToDownload; | |
60 | } |
|
82 | } | |
61 |
|
83 | |||
62 | void ExpXmlDownLoader::extractIntervals(QDomNode n) |
|
84 | void ExpXmlDownLoader::extractIntervals(QDomNode n) | |
63 | { |
|
85 | { | |
64 | QDomNode inter; |
|
86 | QDomNode inter; | |
65 | m_intervals.clear(); |
|
87 | m_intervals.clear(); | |
66 | while(!n.isNull()) |
|
88 | while(!n.isNull()) | |
67 | { |
|
89 | { | |
68 | if(n.toElement().tagName()=="TR") |
|
90 | if(n.toElement().tagName()=="TR") | |
69 | { |
|
91 | { | |
70 | ExpXmlDownLoaderIntervals interval; |
|
92 | ExpXmlDownLoaderIntervals interval; | |
71 | inter=n.firstChild(); |
|
93 | inter=n.firstChild(); | |
72 | if(inter.toElement().tagName()=="TD") |
|
94 | if(inter.toElement().tagName()=="TD") | |
73 | { |
|
95 | { | |
74 | interval.start = inter.toElement().text(); |
|
96 | interval.start = inter.toElement().text(); | |
75 | } |
|
97 | } | |
76 | inter=inter.nextSibling(); |
|
98 | inter=inter.nextSibling(); | |
77 | if(inter.toElement().tagName()=="TD") |
|
99 | if(inter.toElement().tagName()=="TD") | |
78 | { |
|
100 | { | |
79 | interval.stop = inter.toElement().text(); |
|
101 | interval.stop = inter.toElement().text(); | |
80 | } |
|
102 | } | |
81 | m_intervals.append(interval); |
|
103 | m_intervals.append(interval); | |
82 | } |
|
104 | } | |
83 | n = n.nextSibling(); |
|
105 | n = n.nextSibling(); | |
84 | } |
|
106 | } | |
85 | } |
|
107 | } | |
86 |
|
108 | |||
87 | void ExpXmlDownLoader::makeDownloadList() |
|
109 | void ExpXmlDownLoader::makeDownloadList() | |
88 | { |
|
110 | { | |
89 | for(int i=0;i<m_intervals.count();i++) |
|
111 | for(int i=0;i<m_intervals.count();i++) | |
90 | { |
|
112 | { | |
91 | QList<QDate> daysToDl; |
|
113 | QList<QDate> daysToDl; | |
92 | QDateTime start,stop; |
|
114 | QDateTime start,stop; | |
93 | start=start.fromString(m_intervals[i].start,Qt::ISODate); |
|
115 | start=start.fromString(m_intervals[i].start,Qt::ISODate); | |
94 | stop=stop.fromString(m_intervals[i].stop,Qt::ISODate); |
|
116 | stop=stop.fromString(m_intervals[i].stop,Qt::ISODate); | |
95 | int days=start.daysTo(stop); |
|
117 | int days=start.daysTo(stop); | |
96 | daysToDl.append(start.date()); |
|
118 | daysToDl.append(start.date()); | |
97 | if(days) |
|
119 | if(days) | |
98 | { |
|
120 | { | |
99 | for(int j=0;j<days;j++) |
|
121 | for(int j=0;j<days;j++) | |
100 | { |
|
122 | { | |
101 | daysToDl.append(start.addDays(j+1).date()); |
|
123 | daysToDl.append(start.addDays(j+1).date()); | |
102 | } |
|
124 | } | |
103 | } |
|
125 | } | |
104 | addDaysToDownload(daysToDl); |
|
126 | addDaysToDownload(daysToDl); | |
105 | } |
|
127 | } | |
106 | qDebug()<<m_FilesToDownload.count(); |
|
128 | qDebug()<<m_FilesToDownload.count(); | |
107 | } |
|
129 | } | |
108 |
|
130 | |||
109 | void ExpXmlDownLoader::addDaysToDownload(QList<QDate> days) |
|
131 | void ExpXmlDownLoader::addDaysToDownload(QList<QDate> days) | |
110 | { |
|
132 | { | |
111 | for(int i=0;i<days.count();i++) |
|
133 | for(int i=0;i<days.count();i++) | |
112 | { |
|
134 | { | |
113 | if(!m_FilesToDownload.contains(days.at(i))) |
|
135 | if(!m_FilesToDownload.contains(days.at(i))) | |
114 | { |
|
136 | { | |
115 | m_FilesToDownload.append(days.at(i)); |
|
137 | m_FilesToDownload.append(days.at(i)); | |
116 | } |
|
138 | } | |
117 | } |
|
139 | } | |
118 | } |
|
140 | } | |
119 |
|
141 |
@@ -1,35 +1,57 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef EXPXMLDOWNLOADER_H |
|
23 | #ifndef EXPXMLDOWNLOADER_H | |
2 | #define EXPXMLDOWNLOADER_H |
|
24 | #define EXPXMLDOWNLOADER_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 | #include <QDomDocument> |
|
27 | #include <QDomDocument> | |
6 | #include <QList> |
|
28 | #include <QList> | |
7 |
|
29 | |||
8 | typedef struct ExpXmlDownLoaderIntervals |
|
30 | typedef struct ExpXmlDownLoaderIntervals | |
9 | { |
|
31 | { | |
10 | QString date; |
|
32 | QString date; | |
11 | QString start; |
|
33 | QString start; | |
12 | QString stop; |
|
34 | QString stop; | |
13 | }ExpXmlDownLoaderIntervals; |
|
35 | }ExpXmlDownLoaderIntervals; | |
14 | class ExpXmlDownLoader : public QObject |
|
36 | class ExpXmlDownLoader : public QObject | |
15 | { |
|
37 | { | |
16 | Q_OBJECT |
|
38 | Q_OBJECT | |
17 | public: |
|
39 | public: | |
18 | explicit ExpXmlDownLoader(QObject *parent = 0); |
|
40 | explicit ExpXmlDownLoader(QObject *parent = 0); | |
19 | ~ExpXmlDownLoader(); |
|
41 | ~ExpXmlDownLoader(); | |
20 | bool parseXml(const QString& fileName); |
|
42 | bool parseXml(const QString& fileName); | |
21 | const QList<QDate>& daysToDownload(); |
|
43 | const QList<QDate>& daysToDownload(); | |
22 | signals: |
|
44 | signals: | |
23 |
|
45 | |||
24 | public slots: |
|
46 | public slots: | |
25 |
|
47 | |||
26 | private: |
|
48 | private: | |
27 | void extractIntervals(QDomNode n); |
|
49 | void extractIntervals(QDomNode n); | |
28 | void makeDownloadList(); |
|
50 | void makeDownloadList(); | |
29 | void addDaysToDownload(QList<QDate> days); |
|
51 | void addDaysToDownload(QList<QDate> days); | |
30 | QDomDocument* m_doc; |
|
52 | QDomDocument* m_doc; | |
31 | QList<ExpXmlDownLoaderIntervals> m_intervals; |
|
53 | QList<ExpXmlDownLoaderIntervals> m_intervals; | |
32 | QList<QDate> m_FilesToDownload; |
|
54 | QList<QDate> m_FilesToDownload; | |
33 | }; |
|
55 | }; | |
34 |
|
56 | |||
35 | #endif // EXPXMLDOWNLOADER_H |
|
57 | #endif // EXPXMLDOWNLOADER_H |
@@ -1,34 +1,56 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "downloadhistory.h" |
|
23 | #include "downloadhistory.h" | |
2 | #include "ui_downloadhistory.h" |
|
24 | #include "ui_downloadhistory.h" | |
3 |
|
25 | |||
4 | DownLoadHistory::DownLoadHistory(QWidget *parent) : |
|
26 | DownLoadHistory::DownLoadHistory(QWidget *parent) : | |
5 | QWidget(parent), |
|
27 | QWidget(parent), | |
6 | ui(new Ui::DownLoadHistory) |
|
28 | ui(new Ui::DownLoadHistory) | |
7 | { |
|
29 | { | |
8 | ui->setupUi(this); |
|
30 | ui->setupUi(this); | |
9 | vblayout = new QVBoxLayout(this->ui->scrollAreaWidgetContents); |
|
31 | vblayout = new QVBoxLayout(this->ui->scrollAreaWidgetContents); | |
10 | vblayout->addStretch(1); |
|
32 | vblayout->addStretch(1); | |
11 | } |
|
33 | } | |
12 |
|
34 | |||
13 | DownLoadHistory::~DownLoadHistory() |
|
35 | DownLoadHistory::~DownLoadHistory() | |
14 | { |
|
36 | { | |
15 | delete ui; |
|
37 | delete ui; | |
16 | } |
|
38 | } | |
17 |
|
39 | |||
18 | void DownLoadHistory::addElement(DownloadHistoryElement *element) |
|
40 | void DownLoadHistory::addElement(DownloadHistoryElement *element) | |
19 | { |
|
41 | { | |
20 | if(element) |
|
42 | if(element) | |
21 | this->vblayout->insertWidget(0,element); |
|
43 | this->vblayout->insertWidget(0,element); | |
22 | } |
|
44 | } | |
23 |
|
45 | |||
24 | void DownLoadHistory::changeEvent(QEvent *e) |
|
46 | void DownLoadHistory::changeEvent(QEvent *e) | |
25 | { |
|
47 | { | |
26 | QWidget::changeEvent(e); |
|
48 | QWidget::changeEvent(e); | |
27 | switch (e->type()) { |
|
49 | switch (e->type()) { | |
28 | case QEvent::LanguageChange: |
|
50 | case QEvent::LanguageChange: | |
29 | ui->retranslateUi(this); |
|
51 | ui->retranslateUi(this); | |
30 | break; |
|
52 | break; | |
31 | default: |
|
53 | default: | |
32 | break; |
|
54 | break; | |
33 | } |
|
55 | } | |
34 | } |
|
56 | } |
@@ -1,28 +1,50 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef DOWNLOADHISTORY_H |
|
23 | #ifndef DOWNLOADHISTORY_H | |
2 | #define DOWNLOADHISTORY_H |
|
24 | #define DOWNLOADHISTORY_H | |
3 |
|
25 | |||
4 | #include <QWidget> |
|
26 | #include <QWidget> | |
5 | #include <downloadhistoryelement.h> |
|
27 | #include <downloadhistoryelement.h> | |
6 | #include <QVBoxLayout> |
|
28 | #include <QVBoxLayout> | |
7 |
|
29 | |||
8 | namespace Ui { |
|
30 | namespace Ui { | |
9 | class DownLoadHistory; |
|
31 | class DownLoadHistory; | |
10 | } |
|
32 | } | |
11 |
|
33 | |||
12 | class DownLoadHistory : public QWidget |
|
34 | class DownLoadHistory : public QWidget | |
13 | { |
|
35 | { | |
14 | Q_OBJECT |
|
36 | Q_OBJECT | |
15 |
|
37 | |||
16 | public: |
|
38 | public: | |
17 | explicit DownLoadHistory(QWidget *parent = 0); |
|
39 | explicit DownLoadHistory(QWidget *parent = 0); | |
18 | ~DownLoadHistory(); |
|
40 | ~DownLoadHistory(); | |
19 | void addElement(DownloadHistoryElement* element); |
|
41 | void addElement(DownloadHistoryElement* element); | |
20 | protected: |
|
42 | protected: | |
21 | void changeEvent(QEvent *e); |
|
43 | void changeEvent(QEvent *e); | |
22 |
|
44 | |||
23 | private: |
|
45 | private: | |
24 | Ui::DownLoadHistory *ui; |
|
46 | Ui::DownLoadHistory *ui; | |
25 | QVBoxLayout* vblayout; |
|
47 | QVBoxLayout* vblayout; | |
26 | }; |
|
48 | }; | |
27 |
|
49 | |||
28 | #endif // DOWNLOADHISTORY_H |
|
50 | #endif // DOWNLOADHISTORY_H |
@@ -1,44 +1,66 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "downloadhistoryelement.h" |
|
23 | #include "downloadhistoryelement.h" | |
2 | #include "ui_downloadhistoryelement.h" |
|
24 | #include "ui_downloadhistoryelement.h" | |
3 |
|
25 | |||
4 | DownloadHistoryElement::DownloadHistoryElement(FileDownloaderTask *task, QWidget *parent) : |
|
26 | DownloadHistoryElement::DownloadHistoryElement(FileDownloaderTask *task, QWidget *parent) : | |
5 | QWidget(parent), |
|
27 | QWidget(parent), | |
6 | ui(new Ui::DownloadHistoryElement) |
|
28 | ui(new Ui::DownloadHistoryElement) | |
7 | { |
|
29 | { | |
8 | ui->setupUi(this); |
|
30 | ui->setupUi(this); | |
9 | if(task) |
|
31 | if(task) | |
10 | { |
|
32 | { | |
11 | this->associatedTask=task; |
|
33 | this->associatedTask=task; | |
12 | this->ui->DownloadDate->setText(task->startDateTime().toString("yyyy:MM:dd-hh:mm:ss")); |
|
34 | this->ui->DownloadDate->setText(task->startDateTime().toString("yyyy:MM:dd-hh:mm:ss")); | |
13 | this->ui->FileNameLbl->setText(task->fileName()); |
|
35 | this->ui->FileNameLbl->setText(task->fileName()); | |
14 | this->ui->linkLbl->setText(task->url()); |
|
36 | this->ui->linkLbl->setText(task->url()); | |
15 | connect(associatedTask,SIGNAL(updateProgress(int)),this,SLOT(updateProgress(int))); |
|
37 | connect(associatedTask,SIGNAL(updateProgress(int)),this,SLOT(updateProgress(int))); | |
16 | } |
|
38 | } | |
17 | /*this->setStyleSheet("QWidget#DownloadHistoryElement{\ |
|
39 | /*this->setStyleSheet("QWidget#DownloadHistoryElement{\ | |
18 | border: 1px solid gray;\ |
|
40 | border: 1px solid gray;\ | |
19 | border-radius: 9px;\ |
|
41 | border-radius: 9px;\ | |
20 | margin-top: 0.5em; \ |
|
42 | margin-top: 0.5em; \ | |
21 | }");*/ |
|
43 | }");*/ | |
22 | } |
|
44 | } | |
23 |
|
45 | |||
24 | DownloadHistoryElement::~DownloadHistoryElement() |
|
46 | DownloadHistoryElement::~DownloadHistoryElement() | |
25 | { |
|
47 | { | |
26 | delete ui; |
|
48 | delete ui; | |
27 | } |
|
49 | } | |
28 |
|
50 | |||
29 | void DownloadHistoryElement::updateProgress(int percent) |
|
51 | void DownloadHistoryElement::updateProgress(int percent) | |
30 | { |
|
52 | { | |
31 | this->ui->progressBar->setValue(percent); |
|
53 | this->ui->progressBar->setValue(percent); | |
32 | } |
|
54 | } | |
33 |
|
55 | |||
34 | void DownloadHistoryElement::changeEvent(QEvent *e) |
|
56 | void DownloadHistoryElement::changeEvent(QEvent *e) | |
35 | { |
|
57 | { | |
36 | QWidget::changeEvent(e); |
|
58 | QWidget::changeEvent(e); | |
37 | switch (e->type()) { |
|
59 | switch (e->type()) { | |
38 | case QEvent::LanguageChange: |
|
60 | case QEvent::LanguageChange: | |
39 | ui->retranslateUi(this); |
|
61 | ui->retranslateUi(this); | |
40 | break; |
|
62 | break; | |
41 | default: |
|
63 | default: | |
42 | break; |
|
64 | break; | |
43 | } |
|
65 | } | |
44 | } |
|
66 | } |
@@ -1,29 +1,50 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
1 | #ifndef DOWNLOADHISTORYELEMENT_H |
|
22 | #ifndef DOWNLOADHISTORYELEMENT_H | |
2 | #define DOWNLOADHISTORYELEMENT_H |
|
23 | #define DOWNLOADHISTORYELEMENT_H | |
3 |
|
24 | |||
4 | #include <QWidget> |
|
25 | #include <QWidget> | |
5 | #include <filedownloadertask.h> |
|
26 | #include <filedownloadertask.h> | |
6 |
|
27 | |||
7 | namespace Ui { |
|
28 | namespace Ui { | |
8 | class DownloadHistoryElement; |
|
29 | class DownloadHistoryElement; | |
9 | } |
|
30 | } | |
10 |
|
31 | |||
11 | class DownloadHistoryElement : public QWidget |
|
32 | class DownloadHistoryElement : public QWidget | |
12 | { |
|
33 | { | |
13 | Q_OBJECT |
|
34 | Q_OBJECT | |
14 |
|
35 | |||
15 | public: |
|
36 | public: | |
16 | explicit DownloadHistoryElement(FileDownloaderTask* task, QWidget *parent = 0); |
|
37 | explicit DownloadHistoryElement(FileDownloaderTask* task, QWidget *parent = 0); | |
17 | ~DownloadHistoryElement(); |
|
38 | ~DownloadHistoryElement(); | |
18 |
|
39 | |||
19 | public slots: |
|
40 | public slots: | |
20 | void updateProgress(int percent); |
|
41 | void updateProgress(int percent); | |
21 | protected: |
|
42 | protected: | |
22 | void changeEvent(QEvent *e); |
|
43 | void changeEvent(QEvent *e); | |
23 |
|
44 | |||
24 | private: |
|
45 | private: | |
25 | Ui::DownloadHistoryElement *ui; |
|
46 | Ui::DownloadHistoryElement *ui; | |
26 | FileDownloaderTask* associatedTask; |
|
47 | FileDownloaderTask* associatedTask; | |
27 | }; |
|
48 | }; | |
28 |
|
49 | |||
29 | #endif // DOWNLOADHISTORYELEMENT_H |
|
50 | #endif // DOWNLOADHISTORYELEMENT_H |
@@ -1,153 +1,175 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "filebrowser.h" |
|
23 | #include "filebrowser.h" | |
2 | #include "ui_filebrowser.h" |
|
24 | #include "ui_filebrowser.h" | |
3 | #include <QListView> |
|
25 | #include <QListView> | |
4 | #include <QTreeView> |
|
26 | #include <QTreeView> | |
5 |
|
27 | |||
6 | FileBrowser::FileBrowser(QWidget *parent) : |
|
28 | FileBrowser::FileBrowser(QWidget *parent) : | |
7 | QDockWidget(parent), |
|
29 | QDockWidget(parent), | |
8 | ui(new Ui::FileBrowser) |
|
30 | ui(new Ui::FileBrowser) | |
9 | { |
|
31 | { | |
10 | ui->setupUi(this); |
|
32 | ui->setupUi(this); | |
11 | this->model = new FileSystemModel(this); |
|
33 | this->model = new FileSystemModel(this); | |
12 | this->model->setRootPath(QDir::currentPath()); |
|
34 | this->model->setRootPath(QDir::currentPath()); | |
13 | this->view = new QTreeView(); |
|
35 | this->view = new QTreeView(); | |
14 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); |
|
36 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); | |
15 | this->view->setModel(this->model); |
|
37 | this->view->setModel(this->model); | |
16 | this->cd(model->rootPath()); |
|
38 | this->cd(model->rootPath()); | |
17 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); |
|
39 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); | |
18 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); |
|
40 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); | |
19 | connect(this->ui->ListViewQpb,SIGNAL(clicked()),this,SLOT(changeToListView())); |
|
41 | connect(this->ui->ListViewQpb,SIGNAL(clicked()),this,SLOT(changeToListView())); | |
20 | connect(this->ui->TreeViewQpb,SIGNAL(clicked()),this,SLOT(changeToTreeView())); |
|
42 | connect(this->ui->TreeViewQpb,SIGNAL(clicked()),this,SLOT(changeToTreeView())); | |
21 | connect(this->ui->parentDirQpb,SIGNAL(clicked()),this,SLOT(parentDir())); |
|
43 | connect(this->ui->parentDirQpb,SIGNAL(clicked()),this,SLOT(parentDir())); | |
22 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
44 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
23 | view->setDragEnabled(true); |
|
45 | view->setDragEnabled(true); | |
24 | view->setAcceptDrops(true); |
|
46 | view->setAcceptDrops(true); | |
25 | view->setDropIndicatorShown(true); |
|
47 | view->setDropIndicatorShown(true); | |
26 | view->setDragDropMode(QAbstractItemView::DragDrop); |
|
48 | view->setDragDropMode(QAbstractItemView::DragDrop); | |
27 | this->pathCompleter = new QCompleter(this->model,this); |
|
49 | this->pathCompleter = new QCompleter(this->model,this); | |
28 | this->ui->pathLineEdit->setCompleter(pathCompleter); |
|
50 | this->ui->pathLineEdit->setCompleter(pathCompleter); | |
29 | this->pathLineEditEnterEditMode(false); |
|
51 | this->pathLineEditEnterEditMode(false); | |
30 | } |
|
52 | } | |
31 |
|
53 | |||
32 | FileBrowser::~FileBrowser() |
|
54 | FileBrowser::~FileBrowser() | |
33 | { |
|
55 | { | |
34 | delete ui; |
|
56 | delete ui; | |
35 | } |
|
57 | } | |
36 |
|
58 | |||
37 | void FileBrowser::setNameFilters(const QStringList &filters,bool disables) |
|
59 | void FileBrowser::setNameFilters(const QStringList &filters,bool disables) | |
38 | { |
|
60 | { | |
39 | this->model->setNameFilters(filters); |
|
61 | this->model->setNameFilters(filters); | |
40 | this->model->setNameFilterDisables(disables); |
|
62 | this->model->setNameFilterDisables(disables); | |
41 | } |
|
63 | } | |
42 |
|
64 | |||
43 | void FileBrowser::changeToTreeView() |
|
65 | void FileBrowser::changeToTreeView() | |
44 | { |
|
66 | { | |
45 | this->ui->gridLayout->removeWidget(this->view); |
|
67 | this->ui->gridLayout->removeWidget(this->view); | |
46 | delete this->view; |
|
68 | delete this->view; | |
47 | this->view = new QTreeView(); |
|
69 | this->view = new QTreeView(); | |
48 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); |
|
70 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); | |
49 | this->view->setModel(this->model); |
|
71 | this->view->setModel(this->model); | |
50 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); |
|
72 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); | |
51 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); |
|
73 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); | |
52 | this->cd(model->rootPath()); |
|
74 | this->cd(model->rootPath()); | |
53 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
75 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
54 | view->setDragEnabled(true); |
|
76 | view->setDragEnabled(true); | |
55 | view->setAcceptDrops(true); |
|
77 | view->setAcceptDrops(true); | |
56 | view->setDropIndicatorShown(true); |
|
78 | view->setDropIndicatorShown(true); | |
57 | } |
|
79 | } | |
58 |
|
80 | |||
59 | void FileBrowser::changeToListView() |
|
81 | void FileBrowser::changeToListView() | |
60 | { |
|
82 | { | |
61 | this->ui->gridLayout->removeWidget(this->view); |
|
83 | this->ui->gridLayout->removeWidget(this->view); | |
62 | delete this->view; |
|
84 | delete this->view; | |
63 | this->view = new QListView(); |
|
85 | this->view = new QListView(); | |
64 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); |
|
86 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); | |
65 | this->view->setModel(this->model); |
|
87 | this->view->setModel(this->model); | |
66 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); |
|
88 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); | |
67 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); |
|
89 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); | |
68 | this->cd(model->rootPath()); |
|
90 | this->cd(model->rootPath()); | |
69 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
91 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
70 | view->setDragEnabled(true); |
|
92 | view->setDragEnabled(true); | |
71 | view->setAcceptDrops(true); |
|
93 | view->setAcceptDrops(true); | |
72 | view->setDropIndicatorShown(true); |
|
94 | view->setDropIndicatorShown(true); | |
73 | } |
|
95 | } | |
74 |
|
96 | |||
75 | void FileBrowser::clicked(QModelIndex index) |
|
97 | void FileBrowser::clicked(QModelIndex index) | |
76 | { |
|
98 | { | |
77 | QString file=model->filePath(index); |
|
99 | QString file=model->filePath(index); | |
78 | if(QFile::exists(file)) |
|
100 | if(QFile::exists(file)) | |
79 | emit fileClicked(file); |
|
101 | emit fileClicked(file); | |
80 | } |
|
102 | } | |
81 |
|
103 | |||
82 | void FileBrowser::doubleClicked(QModelIndex index) |
|
104 | void FileBrowser::doubleClicked(QModelIndex index) | |
83 | { |
|
105 | { | |
84 | if(model->isDir(index)) |
|
106 | if(model->isDir(index)) | |
85 | { |
|
107 | { | |
86 | this->cd(model->filePath(index)); |
|
108 | this->cd(model->filePath(index)); | |
87 | } |
|
109 | } | |
88 | else |
|
110 | else | |
89 | { |
|
111 | { | |
90 | QString file=model->filePath(index); |
|
112 | QString file=model->filePath(index); | |
91 | if(QFile::exists(file)) |
|
113 | if(QFile::exists(file)) | |
92 | emit fileDoubleClicked(file); |
|
114 | emit fileDoubleClicked(file); | |
93 | } |
|
115 | } | |
94 | } |
|
116 | } | |
95 |
|
117 | |||
96 | void FileBrowser::parentDir() |
|
118 | void FileBrowser::parentDir() | |
97 | { |
|
119 | { | |
98 | this->cd(model->rootPath()+"/.."); |
|
120 | this->cd(model->rootPath()+"/.."); | |
99 | } |
|
121 | } | |
100 |
|
122 | |||
101 | void FileBrowser::cd(const QString &newPath) |
|
123 | void FileBrowser::cd(const QString &newPath) | |
102 | { |
|
124 | { | |
103 | model->setRootPath(newPath); |
|
125 | model->setRootPath(newPath); | |
104 | this->view->setRootIndex(model->index(model->rootPath())); |
|
126 | this->view->setRootIndex(model->index(model->rootPath())); | |
105 | this->ui->pathLineEdit->setText(model->rootPath()); |
|
127 | this->ui->pathLineEdit->setText(model->rootPath()); | |
106 | } |
|
128 | } | |
107 |
|
129 | |||
108 |
|
130 | |||
109 | void FileBrowser::changeEvent(QEvent *e) |
|
131 | void FileBrowser::changeEvent(QEvent *e) | |
110 | { |
|
132 | { | |
111 | QDockWidget::changeEvent(e); |
|
133 | QDockWidget::changeEvent(e); | |
112 | switch (e->type()) { |
|
134 | switch (e->type()) { | |
113 | case QEvent::LanguageChange: |
|
135 | case QEvent::LanguageChange: | |
114 | ui->retranslateUi(this); |
|
136 | ui->retranslateUi(this); | |
115 | break; |
|
137 | break; | |
116 | default: |
|
138 | default: | |
117 | break; |
|
139 | break; | |
118 | } |
|
140 | } | |
119 | } |
|
141 | } | |
120 |
|
142 | |||
121 | void FileBrowser::keyPressEvent(QKeyEvent *e) |
|
143 | void FileBrowser::keyPressEvent(QKeyEvent *e) | |
122 | { |
|
144 | { | |
123 | switch (e->key()) |
|
145 | switch (e->key()) | |
124 | { |
|
146 | { | |
125 | case Qt::Key_L: |
|
147 | case Qt::Key_L: | |
126 | if(e->modifiers()==Qt::ControlModifier) |
|
148 | if(e->modifiers()==Qt::ControlModifier) | |
127 | { |
|
149 | { | |
128 | pathLineEditEnterEditMode(true); |
|
150 | pathLineEditEnterEditMode(true); | |
129 | e->accept(); |
|
151 | e->accept(); | |
130 | } |
|
152 | } | |
131 | break; |
|
153 | break; | |
132 | case Qt::Key_Return: |
|
154 | case Qt::Key_Return: | |
133 | pathLineEditEnterEditMode(false); |
|
155 | pathLineEditEnterEditMode(false); | |
134 | if(QFile::exists(this->ui->pathLineEdit->text())) |
|
156 | if(QFile::exists(this->ui->pathLineEdit->text())) | |
135 | { |
|
157 | { | |
136 | this->cd(this->ui->pathLineEdit->text()); |
|
158 | this->cd(this->ui->pathLineEdit->text()); | |
137 | e->accept(); |
|
159 | e->accept(); | |
138 | } |
|
160 | } | |
139 | break; |
|
161 | break; | |
140 | default: |
|
162 | default: | |
141 | break; |
|
163 | break; | |
142 | } |
|
164 | } | |
143 | if(!e->isAccepted()) |
|
165 | if(!e->isAccepted()) | |
144 | QDockWidget::keyPressEvent(e); |
|
166 | QDockWidget::keyPressEvent(e); | |
145 | } |
|
167 | } | |
146 |
|
168 | |||
147 | void FileBrowser::pathLineEditEnterEditMode(bool enter) |
|
169 | void FileBrowser::pathLineEditEnterEditMode(bool enter) | |
148 | { |
|
170 | { | |
149 | this->ui->pathLineEdit->setReadOnly(!enter); |
|
171 | this->ui->pathLineEdit->setReadOnly(!enter); | |
150 | this->ui->pathLineEdit->setDisabled(!enter); |
|
172 | this->ui->pathLineEdit->setDisabled(!enter); | |
151 | if(enter) |
|
173 | if(enter) | |
152 | this->ui->pathLineEdit->setFocus(); |
|
174 | this->ui->pathLineEdit->setFocus(); | |
153 | } |
|
175 | } |
@@ -1,44 +1,66 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef FILEBROWSER_H |
|
23 | #ifndef FILEBROWSER_H | |
2 | #define FILEBROWSER_H |
|
24 | #define FILEBROWSER_H | |
3 |
|
25 | |||
4 | #include <QDockWidget> |
|
26 | #include <QDockWidget> | |
5 | #include <QFileSystemModel> |
|
27 | #include <QFileSystemModel> | |
6 | #include <QAbstractItemView> |
|
28 | #include <QAbstractItemView> | |
7 | #include <filesystemmodel.h> |
|
29 | #include <filesystemmodel.h> | |
8 | #include <QKeyEvent> |
|
30 | #include <QKeyEvent> | |
9 | #include <QCompleter> |
|
31 | #include <QCompleter> | |
10 |
|
32 | |||
11 | namespace Ui { |
|
33 | namespace Ui { | |
12 | class FileBrowser; |
|
34 | class FileBrowser; | |
13 | } |
|
35 | } | |
14 |
|
36 | |||
15 | class FileBrowser : public QDockWidget |
|
37 | class FileBrowser : public QDockWidget | |
16 | { |
|
38 | { | |
17 | Q_OBJECT |
|
39 | Q_OBJECT | |
18 |
|
40 | |||
19 | public: |
|
41 | public: | |
20 | explicit FileBrowser(QWidget *parent = 0); |
|
42 | explicit FileBrowser(QWidget *parent = 0); | |
21 | ~FileBrowser(); |
|
43 | ~FileBrowser(); | |
22 | void setNameFilters(const QStringList & filters, bool disables=false); |
|
44 | void setNameFilters(const QStringList & filters, bool disables=false); | |
23 | signals: |
|
45 | signals: | |
24 | void fileClicked(const QString& file); |
|
46 | void fileClicked(const QString& file); | |
25 | void fileDoubleClicked(const QString& file); |
|
47 | void fileDoubleClicked(const QString& file); | |
26 | private slots: |
|
48 | private slots: | |
27 | void changeToTreeView(); |
|
49 | void changeToTreeView(); | |
28 | void changeToListView(); |
|
50 | void changeToListView(); | |
29 | void clicked(QModelIndex index); |
|
51 | void clicked(QModelIndex index); | |
30 | void doubleClicked(QModelIndex index); |
|
52 | void doubleClicked(QModelIndex index); | |
31 | void parentDir(); |
|
53 | void parentDir(); | |
32 | void cd(const QString& newPath); |
|
54 | void cd(const QString& newPath); | |
33 | protected: |
|
55 | protected: | |
34 | void changeEvent(QEvent *e); |
|
56 | void changeEvent(QEvent *e); | |
35 | void keyPressEvent(QKeyEvent *e); |
|
57 | void keyPressEvent(QKeyEvent *e); | |
36 | private: |
|
58 | private: | |
37 | void pathLineEditEnterEditMode(bool enter=true); |
|
59 | void pathLineEditEnterEditMode(bool enter=true); | |
38 | Ui::FileBrowser *ui; |
|
60 | Ui::FileBrowser *ui; | |
39 | FileSystemModel* model; |
|
61 | FileSystemModel* model; | |
40 | QAbstractItemView* view; |
|
62 | QAbstractItemView* view; | |
41 | QCompleter* pathCompleter; |
|
63 | QCompleter* pathCompleter; | |
42 | }; |
|
64 | }; | |
43 |
|
65 | |||
44 | #endif // FILEBROWSER_H |
|
66 | #endif // FILEBROWSER_H |
@@ -1,25 +1,47 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "filesystemmodel.h" |
|
23 | #include "filesystemmodel.h" | |
2 | FileSystemModel::FileSystemModel(QObject *parent):QFileSystemModel(parent) |
|
24 | FileSystemModel::FileSystemModel(QObject *parent):QFileSystemModel(parent) | |
3 | { |
|
25 | { | |
4 | this->setReadOnly(false); |
|
26 | this->setReadOnly(false); | |
5 | } |
|
27 | } | |
6 |
|
28 | |||
7 | FileSystemModel::~FileSystemModel() |
|
29 | FileSystemModel::~FileSystemModel() | |
8 | { |
|
30 | { | |
9 | } |
|
31 | } | |
10 |
|
32 | |||
11 | Qt::DropActions FileSystemModel::supportedDropActions() const |
|
33 | Qt::DropActions FileSystemModel::supportedDropActions() const | |
12 | { |
|
34 | { | |
13 | return Qt::MoveAction; |
|
35 | return Qt::MoveAction; | |
14 | } |
|
36 | } | |
15 |
|
37 | |||
16 |
|
38 | |||
17 | Qt::ItemFlags FileSystemModel::flags(const QModelIndex &index) const |
|
39 | Qt::ItemFlags FileSystemModel::flags(const QModelIndex &index) const | |
18 | { |
|
40 | { | |
19 | Qt::ItemFlags defaultFlags = QFileSystemModel::flags(index); |
|
41 | Qt::ItemFlags defaultFlags = QFileSystemModel::flags(index); | |
20 | defaultFlags &= ~Qt::ItemIsEditable; |
|
42 | defaultFlags &= ~Qt::ItemIsEditable; | |
21 | if (index.isValid()) |
|
43 | if (index.isValid()) | |
22 | return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; |
|
44 | return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; | |
23 | else |
|
45 | else | |
24 | return Qt::ItemIsDropEnabled | defaultFlags; |
|
46 | return Qt::ItemIsDropEnabled | defaultFlags; | |
25 | } |
|
47 | } |
@@ -1,16 +1,38 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef FILESYSTEMMODEL_H |
|
23 | #ifndef FILESYSTEMMODEL_H | |
2 | #define FILESYSTEMMODEL_H |
|
24 | #define FILESYSTEMMODEL_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 | #include <QFileSystemModel> |
|
27 | #include <QFileSystemModel> | |
6 |
|
28 | |||
7 | class FileSystemModel : public QFileSystemModel |
|
29 | class FileSystemModel : public QFileSystemModel | |
8 | { |
|
30 | { | |
9 | public: |
|
31 | public: | |
10 | FileSystemModel(QObject* parent=0); |
|
32 | FileSystemModel(QObject* parent=0); | |
11 | ~FileSystemModel(); |
|
33 | ~FileSystemModel(); | |
12 | Qt::DropActions supportedDropActions() const; |
|
34 | Qt::DropActions supportedDropActions() const; | |
13 | Qt::ItemFlags flags(const QModelIndex &index) const; |
|
35 | Qt::ItemFlags flags(const QModelIndex &index) const; | |
14 | }; |
|
36 | }; | |
15 |
|
37 | |||
16 | #endif // FILESYSTEMMODEL_H |
|
38 | #endif // FILESYSTEMMODEL_H |
@@ -1,629 +1,653 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | /* | |||
|
23 | * This code is mainly a copy of QCustomPlot's QCPGraph class | |||
|
24 | */ | |||
1 | #include "qcustomplotvect.h" |
|
25 | #include "qcustomplotvect.h" | |
2 | #include <QVector> |
|
26 | #include <QVector> | |
3 | #include <QVectorIterator> |
|
27 | #include <QVectorIterator> | |
4 | QCustomPlotVect::QCustomPlotVect(QWidget *parent) |
|
28 | QCustomPlotVect::QCustomPlotVect(QWidget *parent) | |
5 | :QCustomPlot(parent) |
|
29 | :QCustomPlot(parent) | |
6 | { |
|
30 | { | |
7 |
|
31 | |||
8 | } |
|
32 | } | |
9 |
|
33 | |||
10 | QCustomPlotVect::~QCustomPlotVect() |
|
34 | QCustomPlotVect::~QCustomPlotVect() | |
11 | { |
|
35 | { | |
12 |
|
36 | |||
13 | } |
|
37 | } | |
14 |
|
38 | |||
15 | QCPGraphVect *QCustomPlotVect::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) |
|
39 | QCPGraphVect *QCustomPlotVect::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) | |
16 | { |
|
40 | { | |
17 | if (!keyAxis) keyAxis = xAxis; |
|
41 | if (!keyAxis) keyAxis = xAxis; | |
18 | if (!valueAxis) valueAxis = yAxis; |
|
42 | if (!valueAxis) valueAxis = yAxis; | |
19 | if (!keyAxis || !valueAxis) |
|
43 | if (!keyAxis || !valueAxis) | |
20 | { |
|
44 | { | |
21 | qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; |
|
45 | qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; | |
22 | return 0; |
|
46 | return 0; | |
23 | } |
|
47 | } | |
24 | if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) |
|
48 | if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) | |
25 | { |
|
49 | { | |
26 | qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; |
|
50 | qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; | |
27 | return 0; |
|
51 | return 0; | |
28 | } |
|
52 | } | |
29 |
|
53 | |||
30 | QCPGraphVect *newGraph = new QCPGraphVect(keyAxis, valueAxis); |
|
54 | QCPGraphVect *newGraph = new QCPGraphVect(keyAxis, valueAxis); | |
31 | if (addPlottable(newGraph)) |
|
55 | if (addPlottable(newGraph)) | |
32 | { |
|
56 | { | |
33 | newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); |
|
57 | newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); | |
34 | return newGraph; |
|
58 | return newGraph; | |
35 | } else |
|
59 | } else | |
36 | { |
|
60 | { | |
37 | delete newGraph; |
|
61 | delete newGraph; | |
38 | return 0; |
|
62 | return 0; | |
39 | } |
|
63 | } | |
40 | } |
|
64 | } | |
41 |
|
65 | |||
42 |
|
66 | |||
43 | QCPGraphVect::QCPGraphVect(QCPAxis *keyAxis, QCPAxis *valueAxis) |
|
67 | QCPGraphVect::QCPGraphVect(QCPAxis *keyAxis, QCPAxis *valueAxis) | |
44 | :QCPGraph(keyAxis,valueAxis) |
|
68 | :QCPGraph(keyAxis,valueAxis) | |
45 | { |
|
69 | { | |
46 | mData = new QVector<QCPData>(); |
|
70 | mData = new QVector<QCPData>(); | |
47 | } |
|
71 | } | |
48 |
|
72 | |||
49 | QCPGraphVect::~QCPGraphVect() |
|
73 | QCPGraphVect::~QCPGraphVect() | |
50 | { |
|
74 | { | |
51 | delete mData; |
|
75 | delete mData; | |
52 | } |
|
76 | } | |
53 |
|
77 | |||
54 | void QCPGraphVect::setData(QVector<QCPData> *data) |
|
78 | void QCPGraphVect::setData(QVector<QCPData> *data) | |
55 | { |
|
79 | { | |
56 | if(data!=mData) |
|
80 | if(data!=mData) | |
57 | { |
|
81 | { | |
58 | delete this->mData; |
|
82 | delete this->mData; | |
59 | this->mData = data; |
|
83 | this->mData = data; | |
60 | } |
|
84 | } | |
61 | } |
|
85 | } | |
62 |
|
86 | |||
63 | QVector<QCPData> *QCPGraphVect::getVisibleData() |
|
87 | QVector<QCPData> *QCPGraphVect::getVisibleData() | |
64 | { |
|
88 | { | |
65 | QVector<QCPData>* data = new QVector<QCPData>(); |
|
89 | QVector<QCPData>* data = new QVector<QCPData>(); | |
66 | bool mAdaptiveSampling_save = mAdaptiveSampling; |
|
90 | bool mAdaptiveSampling_save = mAdaptiveSampling; | |
67 | mAdaptiveSampling = false; |
|
91 | mAdaptiveSampling = false; | |
68 | getPreparedData(data,NULL); |
|
92 | getPreparedData(data,NULL); | |
69 | mAdaptiveSampling = mAdaptiveSampling_save; |
|
93 | mAdaptiveSampling = mAdaptiveSampling_save; | |
70 | return data; |
|
94 | return data; | |
71 | } |
|
95 | } | |
72 |
|
96 | |||
73 | void QCPGraphVect::draw(QCPPainter *painter) |
|
97 | void QCPGraphVect::draw(QCPPainter *painter) | |
74 | { |
|
98 | { | |
75 | if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } |
|
99 | if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } | |
76 | int test = mKeyAxis.data()->range().size(); |
|
100 | int test = mKeyAxis.data()->range().size(); | |
77 | test = mData->count(); |
|
101 | test = mData->count(); | |
78 | if (mKeyAxis.data()->range().size() <= 0 || mData->isEmpty()) return; |
|
102 | if (mKeyAxis.data()->range().size() <= 0 || mData->isEmpty()) return; | |
79 | if (mLineStyle == lsNone && mScatterStyle.isNone()) return; |
|
103 | if (mLineStyle == lsNone && mScatterStyle.isNone()) return; | |
80 |
|
104 | |||
81 | // allocate line and (if necessary) point vectors: |
|
105 | // allocate line and (if necessary) point vectors: | |
82 | QVector<QPointF> *lineData = new QVector<QPointF>; |
|
106 | QVector<QPointF> *lineData = new QVector<QPointF>; | |
83 | QVector<QCPData> *scatterData = 0; |
|
107 | QVector<QCPData> *scatterData = 0; | |
84 | if (!mScatterStyle.isNone()) |
|
108 | if (!mScatterStyle.isNone()) | |
85 | scatterData = new QVector<QCPData>; |
|
109 | scatterData = new QVector<QCPData>; | |
86 |
|
110 | |||
87 | // fill vectors with data appropriate to plot style: |
|
111 | // fill vectors with data appropriate to plot style: | |
88 | getPlotData(lineData, scatterData); |
|
112 | getPlotData(lineData, scatterData); | |
89 |
|
113 | |||
90 | // check data validity if flag set: |
|
114 | // check data validity if flag set: | |
91 | #ifdef QCUSTOMPLOT_CHECK_DATA |
|
115 | #ifdef QCUSTOMPLOT_CHECK_DATA | |
92 | QCPDataMap::const_iterator it; |
|
116 | QCPDataMap::const_iterator it; | |
93 | for (it = mData->constBegin(); it != mData->constEnd(); ++it) |
|
117 | for (it = mData->constBegin(); it != mData->constEnd(); ++it) | |
94 | { |
|
118 | { | |
95 | if (QCP::isInvalidData(it.value().key, it.value().value) || |
|
119 | if (QCP::isInvalidData(it.value().key, it.value().value) || | |
96 | QCP::isInvalidData(it.value().keyErrorPlus, it.value().keyErrorMinus) || |
|
120 | QCP::isInvalidData(it.value().keyErrorPlus, it.value().keyErrorMinus) || | |
97 | QCP::isInvalidData(it.value().valueErrorPlus, it.value().valueErrorPlus)) |
|
121 | QCP::isInvalidData(it.value().valueErrorPlus, it.value().valueErrorPlus)) | |
98 | qDebug() << Q_FUNC_INFO << "Data point at" << it.key() << "invalid." << "Plottable name:" << name(); |
|
122 | qDebug() << Q_FUNC_INFO << "Data point at" << it.key() << "invalid." << "Plottable name:" << name(); | |
99 | } |
|
123 | } | |
100 | #endif |
|
124 | #endif | |
101 |
|
125 | |||
102 | // draw fill of graph: |
|
126 | // draw fill of graph: | |
103 | drawFill(painter, lineData); |
|
127 | drawFill(painter, lineData); | |
104 |
|
128 | |||
105 | // draw line: |
|
129 | // draw line: | |
106 | if (mLineStyle == lsImpulse) |
|
130 | if (mLineStyle == lsImpulse) | |
107 | drawImpulsePlot(painter, lineData); |
|
131 | drawImpulsePlot(painter, lineData); | |
108 | else if (mLineStyle != lsNone) |
|
132 | else if (mLineStyle != lsNone) | |
109 | drawLinePlot(painter, lineData); // also step plots can be drawn as a line plot |
|
133 | drawLinePlot(painter, lineData); // also step plots can be drawn as a line plot | |
110 |
|
134 | |||
111 | // draw scatters: |
|
135 | // draw scatters: | |
112 | if (scatterData) |
|
136 | if (scatterData) | |
113 | drawScatterPlot(painter, scatterData); |
|
137 | drawScatterPlot(painter, scatterData); | |
114 |
|
138 | |||
115 | // free allocated line and point vectors: |
|
139 | // free allocated line and point vectors: | |
116 | delete lineData; |
|
140 | delete lineData; | |
117 | if (scatterData) |
|
141 | if (scatterData) | |
118 | delete scatterData; |
|
142 | delete scatterData; | |
119 | } |
|
143 | } | |
120 |
|
144 | |||
121 | void QCPGraphVect::getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const |
|
145 | void QCPGraphVect::getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const | |
122 | { |
|
146 | { | |
123 | switch(mLineStyle) |
|
147 | switch(mLineStyle) | |
124 | { |
|
148 | { | |
125 | case lsNone: getScatterPlotData(scatterData); break; |
|
149 | case lsNone: getScatterPlotData(scatterData); break; | |
126 | case lsLine: getLinePlotData(lineData, scatterData); break; |
|
150 | case lsLine: getLinePlotData(lineData, scatterData); break; | |
127 | case lsStepLeft: getStepLeftPlotData(lineData, scatterData); break; |
|
151 | case lsStepLeft: getStepLeftPlotData(lineData, scatterData); break; | |
128 | case lsStepRight: getStepRightPlotData(lineData, scatterData); break; |
|
152 | case lsStepRight: getStepRightPlotData(lineData, scatterData); break; | |
129 | case lsStepCenter: getStepCenterPlotData(lineData, scatterData); break; |
|
153 | case lsStepCenter: getStepCenterPlotData(lineData, scatterData); break; | |
130 | case lsImpulse: getImpulsePlotData(lineData, scatterData); break; |
|
154 | case lsImpulse: getImpulsePlotData(lineData, scatterData); break; | |
131 | } |
|
155 | } | |
132 | } |
|
156 | } | |
133 |
|
157 | |||
134 | void QCPGraphVect::getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const |
|
158 | void QCPGraphVect::getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const | |
135 | { |
|
159 | { | |
136 | QCPAxis *keyAxis = mKeyAxis.data(); |
|
160 | QCPAxis *keyAxis = mKeyAxis.data(); | |
137 | QCPAxis *valueAxis = mValueAxis.data(); |
|
161 | QCPAxis *valueAxis = mValueAxis.data(); | |
138 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } |
|
162 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } | |
139 | if (!linePixelData) { qDebug() << Q_FUNC_INFO << "null pointer passed as linePixelData"; return; } |
|
163 | if (!linePixelData) { qDebug() << Q_FUNC_INFO << "null pointer passed as linePixelData"; return; } | |
140 |
|
164 | |||
141 | QVector<QCPData> lineData; |
|
165 | QVector<QCPData> lineData; | |
142 | getPreparedData(&lineData, scatterData); |
|
166 | getPreparedData(&lineData, scatterData); | |
143 | linePixelData->reserve(lineData.size()+2); // added 2 to reserve memory for lower/upper fill base points that might be needed for fill |
|
167 | linePixelData->reserve(lineData.size()+2); // added 2 to reserve memory for lower/upper fill base points that might be needed for fill | |
144 | linePixelData->resize(lineData.size()); |
|
168 | linePixelData->resize(lineData.size()); | |
145 |
|
169 | |||
146 | // transform lineData points to pixels: |
|
170 | // transform lineData points to pixels: | |
147 | if (keyAxis->orientation() == Qt::Vertical) |
|
171 | if (keyAxis->orientation() == Qt::Vertical) | |
148 | { |
|
172 | { | |
149 | for (int i=0; i<lineData.size(); ++i) |
|
173 | for (int i=0; i<lineData.size(); ++i) | |
150 | { |
|
174 | { | |
151 | (*linePixelData)[i].setX(valueAxis->coordToPixel(lineData.at(i).value)); |
|
175 | (*linePixelData)[i].setX(valueAxis->coordToPixel(lineData.at(i).value)); | |
152 | (*linePixelData)[i].setY(keyAxis->coordToPixel(lineData.at(i).key)); |
|
176 | (*linePixelData)[i].setY(keyAxis->coordToPixel(lineData.at(i).key)); | |
153 | } |
|
177 | } | |
154 | } else // key axis is horizontal |
|
178 | } else // key axis is horizontal | |
155 | { |
|
179 | { | |
156 | for (int i=0; i<lineData.size(); ++i) |
|
180 | for (int i=0; i<lineData.size(); ++i) | |
157 | { |
|
181 | { | |
158 | (*linePixelData)[i].setX(keyAxis->coordToPixel(lineData.at(i).key)); |
|
182 | (*linePixelData)[i].setX(keyAxis->coordToPixel(lineData.at(i).key)); | |
159 | (*linePixelData)[i].setY(valueAxis->coordToPixel(lineData.at(i).value)); |
|
183 | (*linePixelData)[i].setY(valueAxis->coordToPixel(lineData.at(i).value)); | |
160 | } |
|
184 | } | |
161 | } |
|
185 | } | |
162 | } |
|
186 | } | |
163 |
|
187 | |||
164 | QCPRange QCPGraphVect::getKeyRange(bool &foundRange, QCPAbstractPlottable::SignDomain inSignDomain, bool includeErrors) const |
|
188 | QCPRange QCPGraphVect::getKeyRange(bool &foundRange, QCPAbstractPlottable::SignDomain inSignDomain, bool includeErrors) const | |
165 | { |
|
189 | { | |
166 |
|
190 | |||
167 | QCPRange range; |
|
191 | QCPRange range; | |
168 | bool haveLower = false; |
|
192 | bool haveLower = false; | |
169 | bool haveUpper = false; |
|
193 | bool haveUpper = false; | |
170 |
|
194 | |||
171 | double current, currentErrorMinus, currentErrorPlus; |
|
195 | double current, currentErrorMinus, currentErrorPlus; | |
172 |
|
196 | |||
173 | if (inSignDomain == sdBoth) // range may be anywhere |
|
197 | if (inSignDomain == sdBoth) // range may be anywhere | |
174 | { |
|
198 | { | |
175 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
199 | QVector<QCPData>::const_iterator it = mData->constBegin(); | |
176 | while (it != mData->constEnd()) |
|
200 | while (it != mData->constEnd()) | |
177 | { |
|
201 | { | |
178 | current = (*it).key; |
|
202 | current = (*it).key; | |
179 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); |
|
203 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); | |
180 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); |
|
204 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); | |
181 | if (current-currentErrorMinus < range.lower || !haveLower) |
|
205 | if (current-currentErrorMinus < range.lower || !haveLower) | |
182 | { |
|
206 | { | |
183 | range.lower = current-currentErrorMinus; |
|
207 | range.lower = current-currentErrorMinus; | |
184 | haveLower = true; |
|
208 | haveLower = true; | |
185 | } |
|
209 | } | |
186 | if (current+currentErrorPlus > range.upper || !haveUpper) |
|
210 | if (current+currentErrorPlus > range.upper || !haveUpper) | |
187 | { |
|
211 | { | |
188 | range.upper = current+currentErrorPlus; |
|
212 | range.upper = current+currentErrorPlus; | |
189 | haveUpper = true; |
|
213 | haveUpper = true; | |
190 | } |
|
214 | } | |
191 | ++it; |
|
215 | ++it; | |
192 | } |
|
216 | } | |
193 | } else if (inSignDomain == sdNegative) // range may only be in the negative sign domain |
|
217 | } else if (inSignDomain == sdNegative) // range may only be in the negative sign domain | |
194 | { |
|
218 | { | |
195 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
219 | QVector<QCPData>::const_iterator it = mData->constBegin(); | |
196 | while (it != mData->constEnd()) |
|
220 | while (it != mData->constEnd()) | |
197 | { |
|
221 | { | |
198 | current = (*it).key; |
|
222 | current = (*it).key; | |
199 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); |
|
223 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); | |
200 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); |
|
224 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); | |
201 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0) |
|
225 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0) | |
202 | { |
|
226 | { | |
203 | range.lower = current-currentErrorMinus; |
|
227 | range.lower = current-currentErrorMinus; | |
204 | haveLower = true; |
|
228 | haveLower = true; | |
205 | } |
|
229 | } | |
206 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0) |
|
230 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0) | |
207 | { |
|
231 | { | |
208 | range.upper = current+currentErrorPlus; |
|
232 | range.upper = current+currentErrorPlus; | |
209 | haveUpper = true; |
|
233 | haveUpper = true; | |
210 | } |
|
234 | } | |
211 | if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to geht that point. |
|
235 | if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to geht that point. | |
212 | { |
|
236 | { | |
213 | if ((current < range.lower || !haveLower) && current < 0) |
|
237 | if ((current < range.lower || !haveLower) && current < 0) | |
214 | { |
|
238 | { | |
215 | range.lower = current; |
|
239 | range.lower = current; | |
216 | haveLower = true; |
|
240 | haveLower = true; | |
217 | } |
|
241 | } | |
218 | if ((current > range.upper || !haveUpper) && current < 0) |
|
242 | if ((current > range.upper || !haveUpper) && current < 0) | |
219 | { |
|
243 | { | |
220 | range.upper = current; |
|
244 | range.upper = current; | |
221 | haveUpper = true; |
|
245 | haveUpper = true; | |
222 | } |
|
246 | } | |
223 | } |
|
247 | } | |
224 | ++it; |
|
248 | ++it; | |
225 | } |
|
249 | } | |
226 | } else if (inSignDomain == sdPositive) // range may only be in the positive sign domain |
|
250 | } else if (inSignDomain == sdPositive) // range may only be in the positive sign domain | |
227 | { |
|
251 | { | |
228 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
252 | QVector<QCPData>::const_iterator it = mData->constBegin(); | |
229 | while (it != mData->constEnd()) |
|
253 | while (it != mData->constEnd()) | |
230 | { |
|
254 | { | |
231 | current = (*it).key; |
|
255 | current = (*it).key; | |
232 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); |
|
256 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); | |
233 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); |
|
257 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); | |
234 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0) |
|
258 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0) | |
235 | { |
|
259 | { | |
236 | range.lower = current-currentErrorMinus; |
|
260 | range.lower = current-currentErrorMinus; | |
237 | haveLower = true; |
|
261 | haveLower = true; | |
238 | } |
|
262 | } | |
239 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0) |
|
263 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0) | |
240 | { |
|
264 | { | |
241 | range.upper = current+currentErrorPlus; |
|
265 | range.upper = current+currentErrorPlus; | |
242 | haveUpper = true; |
|
266 | haveUpper = true; | |
243 | } |
|
267 | } | |
244 | if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to get that point. |
|
268 | if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to get that point. | |
245 | { |
|
269 | { | |
246 | if ((current < range.lower || !haveLower) && current > 0) |
|
270 | if ((current < range.lower || !haveLower) && current > 0) | |
247 | { |
|
271 | { | |
248 | range.lower = current; |
|
272 | range.lower = current; | |
249 | haveLower = true; |
|
273 | haveLower = true; | |
250 | } |
|
274 | } | |
251 | if ((current > range.upper || !haveUpper) && current > 0) |
|
275 | if ((current > range.upper || !haveUpper) && current > 0) | |
252 | { |
|
276 | { | |
253 | range.upper = current; |
|
277 | range.upper = current; | |
254 | haveUpper = true; |
|
278 | haveUpper = true; | |
255 | } |
|
279 | } | |
256 | } |
|
280 | } | |
257 | ++it; |
|
281 | ++it; | |
258 | } |
|
282 | } | |
259 | } |
|
283 | } | |
260 |
|
284 | |||
261 | foundRange = haveLower && haveUpper; |
|
285 | foundRange = haveLower && haveUpper; | |
262 | return range; |
|
286 | return range; | |
263 | } |
|
287 | } | |
264 |
|
288 | |||
265 | QCPRange QCPGraphVect::getValueRange(bool &foundRange, QCPAbstractPlottable::SignDomain inSignDomain, bool includeErrors) const |
|
289 | QCPRange QCPGraphVect::getValueRange(bool &foundRange, QCPAbstractPlottable::SignDomain inSignDomain, bool includeErrors) const | |
266 | { |
|
290 | { | |
267 | QCPRange range; |
|
291 | QCPRange range; | |
268 | bool haveLower = false; |
|
292 | bool haveLower = false; | |
269 | bool haveUpper = false; |
|
293 | bool haveUpper = false; | |
270 |
|
294 | |||
271 | double current, currentErrorMinus, currentErrorPlus; |
|
295 | double current, currentErrorMinus, currentErrorPlus; | |
272 |
|
296 | |||
273 | if (inSignDomain == sdBoth) // range may be anywhere |
|
297 | if (inSignDomain == sdBoth) // range may be anywhere | |
274 | { |
|
298 | { | |
275 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
299 | QVector<QCPData>::const_iterator it = mData->constBegin(); | |
276 | while (it != mData->constEnd()) |
|
300 | while (it != mData->constEnd()) | |
277 | { |
|
301 | { | |
278 | current = (*it).value; |
|
302 | current = (*it).value; | |
279 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); |
|
303 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); | |
280 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); |
|
304 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); | |
281 | if (current-currentErrorMinus < range.lower || !haveLower) |
|
305 | if (current-currentErrorMinus < range.lower || !haveLower) | |
282 | { |
|
306 | { | |
283 | range.lower = current-currentErrorMinus; |
|
307 | range.lower = current-currentErrorMinus; | |
284 | haveLower = true; |
|
308 | haveLower = true; | |
285 | } |
|
309 | } | |
286 | if (current+currentErrorPlus > range.upper || !haveUpper) |
|
310 | if (current+currentErrorPlus > range.upper || !haveUpper) | |
287 | { |
|
311 | { | |
288 | range.upper = current+currentErrorPlus; |
|
312 | range.upper = current+currentErrorPlus; | |
289 | haveUpper = true; |
|
313 | haveUpper = true; | |
290 | } |
|
314 | } | |
291 | ++it; |
|
315 | ++it; | |
292 | } |
|
316 | } | |
293 | } else if (inSignDomain == sdNegative) // range may only be in the negative sign domain |
|
317 | } else if (inSignDomain == sdNegative) // range may only be in the negative sign domain | |
294 | { |
|
318 | { | |
295 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
319 | QVector<QCPData>::const_iterator it = mData->constBegin(); | |
296 | while (it != mData->constEnd()) |
|
320 | while (it != mData->constEnd()) | |
297 | { |
|
321 | { | |
298 | current = (*it).value; |
|
322 | current = (*it).value; | |
299 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); |
|
323 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); | |
300 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); |
|
324 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); | |
301 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0) |
|
325 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0) | |
302 | { |
|
326 | { | |
303 | range.lower = current-currentErrorMinus; |
|
327 | range.lower = current-currentErrorMinus; | |
304 | haveLower = true; |
|
328 | haveLower = true; | |
305 | } |
|
329 | } | |
306 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0) |
|
330 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0) | |
307 | { |
|
331 | { | |
308 | range.upper = current+currentErrorPlus; |
|
332 | range.upper = current+currentErrorPlus; | |
309 | haveUpper = true; |
|
333 | haveUpper = true; | |
310 | } |
|
334 | } | |
311 | if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to get that point. |
|
335 | if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to get that point. | |
312 | { |
|
336 | { | |
313 | if ((current < range.lower || !haveLower) && current < 0) |
|
337 | if ((current < range.lower || !haveLower) && current < 0) | |
314 | { |
|
338 | { | |
315 | range.lower = current; |
|
339 | range.lower = current; | |
316 | haveLower = true; |
|
340 | haveLower = true; | |
317 | } |
|
341 | } | |
318 | if ((current > range.upper || !haveUpper) && current < 0) |
|
342 | if ((current > range.upper || !haveUpper) && current < 0) | |
319 | { |
|
343 | { | |
320 | range.upper = current; |
|
344 | range.upper = current; | |
321 | haveUpper = true; |
|
345 | haveUpper = true; | |
322 | } |
|
346 | } | |
323 | } |
|
347 | } | |
324 | ++it; |
|
348 | ++it; | |
325 | } |
|
349 | } | |
326 | } else if (inSignDomain == sdPositive) // range may only be in the positive sign domain |
|
350 | } else if (inSignDomain == sdPositive) // range may only be in the positive sign domain | |
327 | { |
|
351 | { | |
328 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
352 | QVector<QCPData>::const_iterator it = mData->constBegin(); | |
329 | while (it != mData->constEnd()) |
|
353 | while (it != mData->constEnd()) | |
330 | { |
|
354 | { | |
331 | current = (*it).value; |
|
355 | current = (*it).value; | |
332 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); |
|
356 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); | |
333 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); |
|
357 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); | |
334 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0) |
|
358 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0) | |
335 | { |
|
359 | { | |
336 | range.lower = current-currentErrorMinus; |
|
360 | range.lower = current-currentErrorMinus; | |
337 | haveLower = true; |
|
361 | haveLower = true; | |
338 | } |
|
362 | } | |
339 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0) |
|
363 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0) | |
340 | { |
|
364 | { | |
341 | range.upper = current+currentErrorPlus; |
|
365 | range.upper = current+currentErrorPlus; | |
342 | haveUpper = true; |
|
366 | haveUpper = true; | |
343 | } |
|
367 | } | |
344 | if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to geht that point. |
|
368 | if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to geht that point. | |
345 | { |
|
369 | { | |
346 | if ((current < range.lower || !haveLower) && current > 0) |
|
370 | if ((current < range.lower || !haveLower) && current > 0) | |
347 | { |
|
371 | { | |
348 | range.lower = current; |
|
372 | range.lower = current; | |
349 | haveLower = true; |
|
373 | haveLower = true; | |
350 | } |
|
374 | } | |
351 | if ((current > range.upper || !haveUpper) && current > 0) |
|
375 | if ((current > range.upper || !haveUpper) && current > 0) | |
352 | { |
|
376 | { | |
353 | range.upper = current; |
|
377 | range.upper = current; | |
354 | haveUpper = true; |
|
378 | haveUpper = true; | |
355 | } |
|
379 | } | |
356 | } |
|
380 | } | |
357 | ++it; |
|
381 | ++it; | |
358 | } |
|
382 | } | |
359 | } |
|
383 | } | |
360 |
|
384 | |||
361 | foundRange = haveLower && haveUpper; |
|
385 | foundRange = haveLower && haveUpper; | |
362 | return range; |
|
386 | return range; | |
363 | } |
|
387 | } | |
364 |
|
388 | |||
365 | void QCPGraphVect::getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const |
|
389 | void QCPGraphVect::getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const | |
366 | { |
|
390 | { | |
367 | QCPAxis *keyAxis = mKeyAxis.data(); |
|
391 | QCPAxis *keyAxis = mKeyAxis.data(); | |
368 | QCPAxis *valueAxis = mValueAxis.data(); |
|
392 | QCPAxis *valueAxis = mValueAxis.data(); | |
369 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } |
|
393 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } | |
370 | // get visible data range: |
|
394 | // get visible data range: | |
371 | QVector<QCPData>::const_iterator lower, upper; // note that upper is the actual upper point, and not 1 step after the upper point |
|
395 | QVector<QCPData>::const_iterator lower, upper; // note that upper is the actual upper point, and not 1 step after the upper point | |
372 | getVisibleDataBounds(lower, upper); |
|
396 | getVisibleDataBounds(lower, upper); | |
373 | if (lower == mData->constEnd() || upper == mData->constEnd()) |
|
397 | if (lower == mData->constEnd() || upper == mData->constEnd()) | |
374 | return; |
|
398 | return; | |
375 |
|
399 | |||
376 | // count points in visible range, taking into account that we only need to count to the limit maxCount if using adaptive sampling: |
|
400 | // count points in visible range, taking into account that we only need to count to the limit maxCount if using adaptive sampling: | |
377 | int maxCount = std::numeric_limits<int>::max(); |
|
401 | int maxCount = std::numeric_limits<int>::max(); | |
378 | if (mAdaptiveSampling) |
|
402 | if (mAdaptiveSampling) | |
379 | { |
|
403 | { | |
380 | int keyPixelSpan = qAbs(keyAxis->coordToPixel((*lower).key)-keyAxis->coordToPixel((*upper).key)); |
|
404 | int keyPixelSpan = qAbs(keyAxis->coordToPixel((*lower).key)-keyAxis->coordToPixel((*upper).key)); | |
381 | maxCount = 2*keyPixelSpan+2; |
|
405 | maxCount = 2*keyPixelSpan+2; | |
382 | } |
|
406 | } | |
383 | int dataCount = countDataInBounds(lower, upper, maxCount); |
|
407 | int dataCount = countDataInBounds(lower, upper, maxCount); | |
384 |
|
408 | |||
385 | if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average |
|
409 | if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average | |
386 | { |
|
410 | { | |
387 | if (lineData) |
|
411 | if (lineData) | |
388 | { |
|
412 | { | |
389 | QVector<QCPData>::const_iterator it = lower; |
|
413 | QVector<QCPData>::const_iterator it = lower; | |
390 | QVector<QCPData>::const_iterator upperEnd = upper+1; |
|
414 | QVector<QCPData>::const_iterator upperEnd = upper+1; | |
391 | double minValue = (*it).value; |
|
415 | double minValue = (*it).value; | |
392 | double maxValue = (*it).value; |
|
416 | double maxValue = (*it).value; | |
393 | QVector<QCPData>::const_iterator currentIntervalFirstPoint = it; |
|
417 | QVector<QCPData>::const_iterator currentIntervalFirstPoint = it; | |
394 | int reversedFactor = keyAxis->rangeReversed() != (keyAxis->orientation()==Qt::Vertical) ? -1 : 1; // is used to calculate keyEpsilon pixel into the correct direction |
|
418 | int reversedFactor = keyAxis->rangeReversed() != (keyAxis->orientation()==Qt::Vertical) ? -1 : 1; // is used to calculate keyEpsilon pixel into the correct direction | |
395 | int reversedRound = keyAxis->rangeReversed() != (keyAxis->orientation()==Qt::Vertical) ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey |
|
419 | int reversedRound = keyAxis->rangeReversed() != (keyAxis->orientation()==Qt::Vertical) ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey | |
396 | double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*lower).key)+reversedRound)); |
|
420 | double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*lower).key)+reversedRound)); | |
397 | double lastIntervalEndKey = currentIntervalStartKey; |
|
421 | double lastIntervalEndKey = currentIntervalStartKey; | |
398 | double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates |
|
422 | double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates | |
399 | bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) |
|
423 | bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) | |
400 | int intervalDataCount = 1; |
|
424 | int intervalDataCount = 1; | |
401 | ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect |
|
425 | ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect | |
402 | while (it != upperEnd) |
|
426 | while (it != upperEnd) | |
403 | { |
|
427 | { | |
404 | if ((*it).key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary |
|
428 | if ((*it).key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary | |
405 | { |
|
429 | { | |
406 | if ((*it).value < minValue) |
|
430 | if ((*it).value < minValue) | |
407 | minValue = (*it).value; |
|
431 | minValue = (*it).value; | |
408 | else if ((*it).value > maxValue) |
|
432 | else if ((*it).value > maxValue) | |
409 | maxValue = (*it).value; |
|
433 | maxValue = (*it).value; | |
410 | ++intervalDataCount; |
|
434 | ++intervalDataCount; | |
411 | } else // new pixel interval started |
|
435 | } else // new pixel interval started | |
412 | { |
|
436 | { | |
413 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster |
|
437 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster | |
414 | { |
|
438 | { | |
415 | if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point |
|
439 | if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point | |
416 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.2, (*currentIntervalFirstPoint).value)); |
|
440 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.2, (*currentIntervalFirstPoint).value)); | |
417 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); |
|
441 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); | |
418 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); |
|
442 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); | |
419 | if ((*it).key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point |
|
443 | if ((*it).key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point | |
420 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.8, (*(it-1)).value)); |
|
444 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.8, (*(it-1)).value)); | |
421 | } else |
|
445 | } else | |
422 | lineData->append(QCPData((*currentIntervalFirstPoint).key, (*currentIntervalFirstPoint).value)); |
|
446 | lineData->append(QCPData((*currentIntervalFirstPoint).key, (*currentIntervalFirstPoint).value)); | |
423 | lastIntervalEndKey = (*(it-1)).key; |
|
447 | lastIntervalEndKey = (*(it-1)).key; | |
424 | minValue = (*it).value; |
|
448 | minValue = (*it).value; | |
425 | maxValue = (*it).value; |
|
449 | maxValue = (*it).value; | |
426 | currentIntervalFirstPoint = it; |
|
450 | currentIntervalFirstPoint = it; | |
427 | currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*it).key)+reversedRound)); |
|
451 | currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*it).key)+reversedRound)); | |
428 | if (keyEpsilonVariable) |
|
452 | if (keyEpsilonVariable) | |
429 | keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); |
|
453 | keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); | |
430 | intervalDataCount = 1; |
|
454 | intervalDataCount = 1; | |
431 | } |
|
455 | } | |
432 | ++it; |
|
456 | ++it; | |
433 | } |
|
457 | } | |
434 | // handle last interval: |
|
458 | // handle last interval: | |
435 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster |
|
459 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster | |
436 | { |
|
460 | { | |
437 | if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point |
|
461 | if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point | |
438 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.2, (*currentIntervalFirstPoint).value)); |
|
462 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.2, (*currentIntervalFirstPoint).value)); | |
439 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); |
|
463 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); | |
440 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); |
|
464 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); | |
441 | } else |
|
465 | } else | |
442 | lineData->append(QCPData((*currentIntervalFirstPoint).key, (*currentIntervalFirstPoint).value)); |
|
466 | lineData->append(QCPData((*currentIntervalFirstPoint).key, (*currentIntervalFirstPoint).value)); | |
443 | } |
|
467 | } | |
444 |
|
468 | |||
445 | if (scatterData) |
|
469 | if (scatterData) | |
446 | { |
|
470 | { | |
447 | double valueMaxRange = valueAxis->range().upper; |
|
471 | double valueMaxRange = valueAxis->range().upper; | |
448 | double valueMinRange = valueAxis->range().lower; |
|
472 | double valueMinRange = valueAxis->range().lower; | |
449 | QVector<QCPData>::const_iterator it = lower; |
|
473 | QVector<QCPData>::const_iterator it = lower; | |
450 | QVector<QCPData>::const_iterator upperEnd = upper+1; |
|
474 | QVector<QCPData>::const_iterator upperEnd = upper+1; | |
451 | double minValue = (*it).value; |
|
475 | double minValue = (*it).value; | |
452 | double maxValue = (*it).value; |
|
476 | double maxValue = (*it).value; | |
453 | QVector<QCPData>::const_iterator minValueIt = it; |
|
477 | QVector<QCPData>::const_iterator minValueIt = it; | |
454 | QVector<QCPData>::const_iterator maxValueIt = it; |
|
478 | QVector<QCPData>::const_iterator maxValueIt = it; | |
455 | QVector<QCPData>::const_iterator currentIntervalStart = it; |
|
479 | QVector<QCPData>::const_iterator currentIntervalStart = it; | |
456 | int reversedFactor = keyAxis->rangeReversed() ? -1 : 1; // is used to calculate keyEpsilon pixel into the correct direction |
|
480 | int reversedFactor = keyAxis->rangeReversed() ? -1 : 1; // is used to calculate keyEpsilon pixel into the correct direction | |
457 | int reversedRound = keyAxis->rangeReversed() ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey |
|
481 | int reversedRound = keyAxis->rangeReversed() ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey | |
458 | double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*lower).key)+reversedRound)); |
|
482 | double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*lower).key)+reversedRound)); | |
459 | double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates |
|
483 | double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates | |
460 | bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) |
|
484 | bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) | |
461 | int intervalDataCount = 1; |
|
485 | int intervalDataCount = 1; | |
462 | ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect |
|
486 | ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect | |
463 | while (it != upperEnd) |
|
487 | while (it != upperEnd) | |
464 | { |
|
488 | { | |
465 | if ((*it).key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary |
|
489 | if ((*it).key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary | |
466 | { |
|
490 | { | |
467 | if ((*it).value < minValue && (*it).value > valueMinRange && (*it).value < valueMaxRange) |
|
491 | if ((*it).value < minValue && (*it).value > valueMinRange && (*it).value < valueMaxRange) | |
468 | { |
|
492 | { | |
469 | minValue = (*it).value; |
|
493 | minValue = (*it).value; | |
470 | minValueIt = it; |
|
494 | minValueIt = it; | |
471 | } else if ((*it).value > maxValue && (*it).value > valueMinRange && (*it).value < valueMaxRange) |
|
495 | } else if ((*it).value > maxValue && (*it).value > valueMinRange && (*it).value < valueMaxRange) | |
472 | { |
|
496 | { | |
473 | maxValue = (*it).value; |
|
497 | maxValue = (*it).value; | |
474 | maxValueIt = it; |
|
498 | maxValueIt = it; | |
475 | } |
|
499 | } | |
476 | ++intervalDataCount; |
|
500 | ++intervalDataCount; | |
477 | } else // new pixel started |
|
501 | } else // new pixel started | |
478 | { |
|
502 | { | |
479 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them |
|
503 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them | |
480 | { |
|
504 | { | |
481 | // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): |
|
505 | // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): | |
482 | double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); |
|
506 | double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); | |
483 | int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average |
|
507 | int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average | |
484 | QVector<QCPData>::const_iterator intervalIt = currentIntervalStart; |
|
508 | QVector<QCPData>::const_iterator intervalIt = currentIntervalStart; | |
485 | int c = 0; |
|
509 | int c = 0; | |
486 | while (intervalIt != it) |
|
510 | while (intervalIt != it) | |
487 | { |
|
511 | { | |
488 | if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && (*intervalIt).value > valueMinRange && (*intervalIt).value < valueMaxRange) |
|
512 | if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && (*intervalIt).value > valueMinRange && (*intervalIt).value < valueMaxRange) | |
489 | scatterData->append((*intervalIt)); |
|
513 | scatterData->append((*intervalIt)); | |
490 | ++c; |
|
514 | ++c; | |
491 | ++intervalIt; |
|
515 | ++intervalIt; | |
492 | } |
|
516 | } | |
493 | } else if ((*currentIntervalStart).value > valueMinRange && (*currentIntervalStart).value < valueMaxRange) |
|
517 | } else if ((*currentIntervalStart).value > valueMinRange && (*currentIntervalStart).value < valueMaxRange) | |
494 | scatterData->append((*currentIntervalStart)); |
|
518 | scatterData->append((*currentIntervalStart)); | |
495 | minValue = (*it).value; |
|
519 | minValue = (*it).value; | |
496 | maxValue = (*it).value; |
|
520 | maxValue = (*it).value; | |
497 | currentIntervalStart = it; |
|
521 | currentIntervalStart = it; | |
498 | currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*it).key)+reversedRound)); |
|
522 | currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*it).key)+reversedRound)); | |
499 | if (keyEpsilonVariable) |
|
523 | if (keyEpsilonVariable) | |
500 | keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); |
|
524 | keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); | |
501 | intervalDataCount = 1; |
|
525 | intervalDataCount = 1; | |
502 | } |
|
526 | } | |
503 | ++it; |
|
527 | ++it; | |
504 | } |
|
528 | } | |
505 | // handle last interval: |
|
529 | // handle last interval: | |
506 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them |
|
530 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them | |
507 | { |
|
531 | { | |
508 | // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): |
|
532 | // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): | |
509 | double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); |
|
533 | double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); | |
510 | int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average |
|
534 | int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average | |
511 | QVector<QCPData>::const_iterator intervalIt = currentIntervalStart; |
|
535 | QVector<QCPData>::const_iterator intervalIt = currentIntervalStart; | |
512 | int c = 0; |
|
536 | int c = 0; | |
513 | while (intervalIt != it) |
|
537 | while (intervalIt != it) | |
514 | { |
|
538 | { | |
515 | if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && (*intervalIt).value > valueMinRange && (*intervalIt).value < valueMaxRange) |
|
539 | if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && (*intervalIt).value > valueMinRange && (*intervalIt).value < valueMaxRange) | |
516 | scatterData->append((*intervalIt)); |
|
540 | scatterData->append((*intervalIt)); | |
517 | ++c; |
|
541 | ++c; | |
518 | ++intervalIt; |
|
542 | ++intervalIt; | |
519 | } |
|
543 | } | |
520 | } else if ((*currentIntervalStart).value > valueMinRange && (*currentIntervalStart).value < valueMaxRange) |
|
544 | } else if ((*currentIntervalStart).value > valueMinRange && (*currentIntervalStart).value < valueMaxRange) | |
521 | scatterData->append(*currentIntervalStart); |
|
545 | scatterData->append(*currentIntervalStart); | |
522 | } |
|
546 | } | |
523 | } else // don't use adaptive sampling algorithm, transfer points one-to-one from the map into the output parameters |
|
547 | } else // don't use adaptive sampling algorithm, transfer points one-to-one from the map into the output parameters | |
524 | { |
|
548 | { | |
525 | QVector<QCPData> *dataVector = 0; |
|
549 | QVector<QCPData> *dataVector = 0; | |
526 | if (lineData) |
|
550 | if (lineData) | |
527 | { |
|
551 | { | |
528 | dataVector = lineData; |
|
552 | dataVector = lineData; | |
529 | } |
|
553 | } | |
530 | else if (scatterData) |
|
554 | else if (scatterData) | |
531 | dataVector = scatterData; |
|
555 | dataVector = scatterData; | |
532 | if (dataVector) |
|
556 | if (dataVector) | |
533 | { |
|
557 | { | |
534 | QVector<QCPData>::const_iterator it = lower; |
|
558 | QVector<QCPData>::const_iterator it = lower; | |
535 | QVector<QCPData>::const_iterator upperEnd = upper+1; |
|
559 | QVector<QCPData>::const_iterator upperEnd = upper+1; | |
536 | dataVector->reserve(dataCount+2); // +2 for possible fill end points |
|
560 | dataVector->reserve(dataCount+2); // +2 for possible fill end points | |
537 | while (it != upperEnd) |
|
561 | while (it != upperEnd) | |
538 | { |
|
562 | { | |
539 | dataVector->append(*it); |
|
563 | dataVector->append(*it); | |
540 | ++it; |
|
564 | ++it; | |
541 | } |
|
565 | } | |
542 | } |
|
566 | } | |
543 | if (lineData && scatterData) |
|
567 | if (lineData && scatterData) | |
544 | *scatterData = *dataVector; |
|
568 | *scatterData = *dataVector; | |
545 | } |
|
569 | } | |
546 | } |
|
570 | } | |
547 |
|
571 | |||
548 | QVector<QCPData>::const_iterator __lowerBoundDico_vect(QVector<QCPData>* vector,double key) |
|
572 | QVector<QCPData>::const_iterator __lowerBoundDico_vect(QVector<QCPData>* vector,double key) | |
549 | { |
|
573 | { | |
550 | int DX=vector->size()/2; |
|
574 | int DX=vector->size()/2; | |
551 | int pos=DX; |
|
575 | int pos=DX; | |
552 | // double test=(*vector)[vector->length()-1].key; |
|
576 | // double test=(*vector)[vector->length()-1].key; | |
553 | if(key>((*vector)[vector->length()-1].key)) |
|
577 | if(key>((*vector)[vector->length()-1].key)) | |
554 | return vector->constEnd(); |
|
578 | return vector->constEnd(); | |
555 | if(key<((*vector)[0].key)) |
|
579 | if(key<((*vector)[0].key)) | |
556 | return vector->constBegin(); |
|
580 | return vector->constBegin(); | |
557 | while (DX>1) |
|
581 | while (DX>1) | |
558 | { |
|
582 | { | |
559 | DX=DX/2; |
|
583 | DX=DX/2; | |
560 | if((*vector)[pos].key > key) |
|
584 | if((*vector)[pos].key > key) | |
561 | { |
|
585 | { | |
562 | pos-=DX; |
|
586 | pos-=DX; | |
563 | } |
|
587 | } | |
564 | else |
|
588 | else | |
565 | { |
|
589 | { | |
566 | pos+=DX; |
|
590 | pos+=DX; | |
567 | } |
|
591 | } | |
568 | } |
|
592 | } | |
569 | if((*vector)[pos].key >= key) |
|
593 | if((*vector)[pos].key >= key) | |
570 | return vector->constBegin()+pos; |
|
594 | return vector->constBegin()+pos; | |
571 | return vector->constBegin()+pos+1; |
|
595 | return vector->constBegin()+pos+1; | |
572 | } |
|
596 | } | |
573 |
|
597 | |||
574 |
|
598 | |||
575 | QVector<QCPData>::const_iterator __upperBoundDico_vect(QVector<QCPData>* vector,double key) |
|
599 | QVector<QCPData>::const_iterator __upperBoundDico_vect(QVector<QCPData>* vector,double key) | |
576 | { |
|
600 | { | |
577 | int DX=vector->size()/2; |
|
601 | int DX=vector->size()/2; | |
578 | int pos=DX; |
|
602 | int pos=DX; | |
579 | if(key>((*vector)[vector->length()-1].key)) |
|
603 | if(key>((*vector)[vector->length()-1].key)) | |
580 | return vector->constEnd(); |
|
604 | return vector->constEnd(); | |
581 | if(key<((*vector)[0].key)) |
|
605 | if(key<((*vector)[0].key)) | |
582 | return vector->constBegin(); |
|
606 | return vector->constBegin(); | |
583 | while (DX>1) |
|
607 | while (DX>1) | |
584 | { |
|
608 | { | |
585 | DX=DX/2; |
|
609 | DX=DX/2; | |
586 | if((*vector)[pos].key > key) |
|
610 | if((*vector)[pos].key > key) | |
587 | { |
|
611 | { | |
588 | pos-=DX; |
|
612 | pos-=DX; | |
589 | } |
|
613 | } | |
590 | else |
|
614 | else | |
591 | { |
|
615 | { | |
592 | pos+=DX; |
|
616 | pos+=DX; | |
593 | } |
|
617 | } | |
594 | } |
|
618 | } | |
595 | return vector->constBegin()+pos+1; |
|
619 | return vector->constBegin()+pos+1; | |
596 | } |
|
620 | } | |
597 |
|
621 | |||
598 |
|
622 | |||
599 | void QCPGraphVect::getVisibleDataBounds(QVector<QCPData>::const_iterator &lower, QVector<QCPData>::const_iterator &upper) const |
|
623 | void QCPGraphVect::getVisibleDataBounds(QVector<QCPData>::const_iterator &lower, QVector<QCPData>::const_iterator &upper) const | |
600 | { |
|
624 | { | |
601 | if (!mKeyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } |
|
625 | if (!mKeyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } | |
602 | if (mData->isEmpty()) |
|
626 | if (mData->isEmpty()) | |
603 | { |
|
627 | { | |
604 | lower = mData->constEnd(); |
|
628 | lower = mData->constEnd(); | |
605 | upper = mData->constEnd(); |
|
629 | upper = mData->constEnd(); | |
606 | return; |
|
630 | return; | |
607 | } |
|
631 | } | |
608 | QVector<QCPData>::const_iterator lbound = __lowerBoundDico_vect(mData,mKeyAxis.data()->range().lower); |
|
632 | QVector<QCPData>::const_iterator lbound = __lowerBoundDico_vect(mData,mKeyAxis.data()->range().lower); | |
609 | QVector<QCPData>::const_iterator ubound = __upperBoundDico_vect(mData,mKeyAxis.data()->range().upper); |
|
633 | QVector<QCPData>::const_iterator ubound = __upperBoundDico_vect(mData,mKeyAxis.data()->range().upper); | |
610 | bool lowoutlier = lbound != mData->constBegin(); // indicates whether there exist points below axis range |
|
634 | bool lowoutlier = lbound != mData->constBegin(); // indicates whether there exist points below axis range | |
611 | bool highoutlier = ubound != mData->constEnd(); // indicates whether there exist points above axis range |
|
635 | bool highoutlier = ubound != mData->constEnd(); // indicates whether there exist points above axis range | |
612 |
|
636 | |||
613 | lower = (lowoutlier ? lbound-1 : lbound); // data point range that will be actually drawn |
|
637 | lower = (lowoutlier ? lbound-1 : lbound); // data point range that will be actually drawn | |
614 | upper = (highoutlier ? ubound : ubound-1); // data point range that will be actually drawn |
|
638 | upper = (highoutlier ? ubound : ubound-1); // data point range that will be actually drawn | |
615 | } |
|
639 | } | |
616 |
|
640 | |||
617 | int QCPGraphVect::countDataInBounds(const QVector<QCPData>::const_iterator &lower, const QVector<QCPData>::const_iterator &upper, int maxCount) const |
|
641 | int QCPGraphVect::countDataInBounds(const QVector<QCPData>::const_iterator &lower, const QVector<QCPData>::const_iterator &upper, int maxCount) const | |
618 | { |
|
642 | { | |
619 | if (upper == mData->constEnd() && lower == mData->constEnd()) |
|
643 | if (upper == mData->constEnd() && lower == mData->constEnd()) | |
620 | return 0; |
|
644 | return 0; | |
621 | QVector<QCPData>::const_iterator it = lower; |
|
645 | QVector<QCPData>::const_iterator it = lower; | |
622 | int count = 1; |
|
646 | int count = 1; | |
623 | while (it != upper && count < maxCount) |
|
647 | while (it != upper && count < maxCount) | |
624 | { |
|
648 | { | |
625 | ++it; |
|
649 | ++it; | |
626 | ++count; |
|
650 | ++count; | |
627 | } |
|
651 | } | |
628 | return count; |
|
652 | return count; | |
629 | } |
|
653 | } |
@@ -1,39 +1,63 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | /* | |||
|
23 | * This code is mainly a copy of QCustomPlot's QCPGraph class | |||
|
24 | */ | |||
1 | #ifndef QCUSTOMPLOTVECT_H |
|
25 | #ifndef QCUSTOMPLOTVECT_H | |
2 | #define QCUSTOMPLOTVECT_H |
|
26 | #define QCUSTOMPLOTVECT_H | |
3 |
|
27 | |||
4 | #include <QWidget> |
|
28 | #include <QWidget> | |
5 | #include <qcustomplot.h> |
|
29 | #include <qcustomplot.h> | |
6 |
|
30 | |||
7 | class QCPGraphVect : public QCPGraph |
|
31 | class QCPGraphVect : public QCPGraph | |
8 | { |
|
32 | { | |
9 | Q_OBJECT |
|
33 | Q_OBJECT | |
10 | public: |
|
34 | public: | |
11 | explicit QCPGraphVect(QCPAxis *keyAxis, QCPAxis *valueAxis); |
|
35 | explicit QCPGraphVect(QCPAxis *keyAxis, QCPAxis *valueAxis); | |
12 | ~QCPGraphVect(); |
|
36 | ~QCPGraphVect(); | |
13 | QVector<QCPData> *data() const { return mData; } |
|
37 | QVector<QCPData> *data() const { return mData; } | |
14 | void setData(QVector<QCPData> *data); |
|
38 | void setData(QVector<QCPData> *data); | |
15 | QVector<QCPData>* getVisibleData(); |
|
39 | QVector<QCPData>* getVisibleData(); | |
16 | protected: |
|
40 | protected: | |
17 | QVector<QCPData>* mData; |
|
41 | QVector<QCPData>* mData; | |
18 | virtual void draw(QCPPainter *painter); |
|
42 | virtual void draw(QCPPainter *painter); | |
19 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface |
|
43 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface | |
20 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; |
|
44 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; | |
21 | void getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const; |
|
45 | void getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const; | |
22 | void getVisibleDataBounds(QVector<QCPData>::const_iterator &lower, QVector<QCPData>::const_iterator &upper) const; |
|
46 | void getVisibleDataBounds(QVector<QCPData>::const_iterator &lower, QVector<QCPData>::const_iterator &upper) const; | |
23 | int countDataInBounds(const QVector<QCPData>::const_iterator &lower, const QVector<QCPData>::const_iterator &upper, int maxCount) const; |
|
47 | int countDataInBounds(const QVector<QCPData>::const_iterator &lower, const QVector<QCPData>::const_iterator &upper, int maxCount) const; | |
24 |
|
48 | |||
25 | void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const; |
|
49 | void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const; | |
26 | void getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const; |
|
50 | void getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const; | |
27 | }; |
|
51 | }; | |
28 |
|
52 | |||
29 | class QCustomPlotVect : public QCustomPlot |
|
53 | class QCustomPlotVect : public QCustomPlot | |
30 | { |
|
54 | { | |
31 | Q_OBJECT |
|
55 | Q_OBJECT | |
32 | public: |
|
56 | public: | |
33 | QCustomPlotVect(QWidget *parent = 0); |
|
57 | QCustomPlotVect(QWidget *parent = 0); | |
34 | ~QCustomPlotVect(); |
|
58 | ~QCustomPlotVect(); | |
35 | QCPGraphVect *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); |
|
59 | QCPGraphVect *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); | |
36 | protected: |
|
60 | protected: | |
37 | }; |
|
61 | }; | |
38 |
|
62 | |||
39 | #endif // QCUSTOMPLOTVECT_H |
|
63 | #endif // QCUSTOMPLOTVECT_H |
@@ -1,153 +1,175 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "qlopplots.h" |
|
23 | #include "qlopplots.h" | |
2 | #include <QMainWindow> |
|
24 | #include <QMainWindow> | |
3 |
|
25 | |||
4 | QLopPlots* QLopPlots::_self=NULL; |
|
26 | QLopPlots* QLopPlots::_self=NULL; | |
5 | SocExplorerPlot* QLopPlots::m_LastPlot=NULL; |
|
27 | SocExplorerPlot* QLopPlots::m_LastPlot=NULL; | |
6 | QDockWidget* QLopPlots::m_gui=NULL; |
|
28 | QDockWidget* QLopPlots::m_gui=NULL; | |
7 | QHash<int,SocExplorerPlot*>* QLopPlots::m_plots=NULL; |
|
29 | QHash<int,SocExplorerPlot*>* QLopPlots::m_plots=NULL; | |
8 | toolBarContainer* QLopPlots::m_DocContainer=NULL; |
|
30 | toolBarContainer* QLopPlots::m_DocContainer=NULL; | |
9 |
|
31 | |||
10 |
|
32 | |||
11 | #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();} |
|
33 | #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();} | |
12 |
|
34 | |||
13 |
|
35 | |||
14 | QLopPlots::QLopPlots(bool noGUI,QObject *parent) |
|
36 | QLopPlots::QLopPlots(bool noGUI,QObject *parent) | |
15 | { |
|
37 | { | |
16 | m_noGui = noGUI; |
|
38 | m_noGui = noGUI; | |
17 | m_serviceName = "QLopPlots"; |
|
39 | m_serviceName = "QLopPlots"; | |
18 | m_plots = new QHash<int,SocExplorerPlot*>(); |
|
40 | m_plots = new QHash<int,SocExplorerPlot*>(); | |
19 | } |
|
41 | } | |
20 |
|
42 | |||
21 | QLopPlots::~QLopPlots() |
|
43 | QLopPlots::~QLopPlots() | |
22 | { |
|
44 | { | |
23 |
|
45 | |||
24 | } |
|
46 | } | |
25 |
|
47 | |||
26 | int QLopPlots::getPlotID() |
|
48 | int QLopPlots::getPlotID() | |
27 | { |
|
49 | { | |
28 | _INIT(); |
|
50 | _INIT(); | |
29 | for(int i=0;i<32768;i++) |
|
51 | for(int i=0;i<32768;i++) | |
30 | { |
|
52 | { | |
31 | if(!m_plots->contains(i)) |
|
53 | if(!m_plots->contains(i)) | |
32 | { |
|
54 | { | |
33 | return i; |
|
55 | return i; | |
34 | } |
|
56 | } | |
35 | } |
|
57 | } | |
36 | return -1; |
|
58 | return -1; | |
37 | } |
|
59 | } | |
38 |
|
60 | |||
39 | void QLopPlots::init(bool noGUI, QObject *parent) |
|
61 | void QLopPlots::init(bool noGUI, QObject *parent) | |
40 | { |
|
62 | { | |
41 | if(Q_UNLIKELY(_self==NULL)) |
|
63 | if(Q_UNLIKELY(_self==NULL)) | |
42 | { |
|
64 | { | |
43 | _self=new QLopPlots(noGUI,parent); |
|
65 | _self=new QLopPlots(noGUI,parent); | |
44 | } |
|
66 | } | |
45 | } |
|
67 | } | |
46 |
|
68 | |||
47 | QLopPlots *QLopPlots::self() |
|
69 | QLopPlots *QLopPlots::self() | |
48 | { |
|
70 | { | |
49 | _INIT(); |
|
71 | _INIT(); | |
50 | return _self; |
|
72 | return _self; | |
51 | } |
|
73 | } | |
52 |
|
74 | |||
53 | SocExplorerPlot *QLopPlots::getPlot(int plotID) |
|
75 | SocExplorerPlot *QLopPlots::getPlot(int plotID) | |
54 | { |
|
76 | { | |
55 | _INIT(); |
|
77 | _INIT(); | |
56 | if(!_self->m_noGui && (m_gui==NULL)) |
|
78 | if(!_self->m_noGui && (m_gui==NULL)) | |
57 | { |
|
79 | { | |
58 | m_gui=new QDockWidget("Plots"); |
|
80 | m_gui=new QDockWidget("Plots"); | |
59 | m_DocContainer = new toolBarContainer(); |
|
81 | m_DocContainer = new toolBarContainer(); | |
60 | // m_SocExplorerPlot = new SocExplorerPlot(); |
|
82 | // m_SocExplorerPlot = new SocExplorerPlot(); | |
61 | m_gui->setWidget(m_DocContainer); |
|
83 | m_gui->setWidget(m_DocContainer); | |
62 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
84 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | |
63 | } |
|
85 | } | |
64 | if(m_plots->contains(plotID)) |
|
86 | if(m_plots->contains(plotID)) | |
65 | { |
|
87 | { | |
66 | return m_plots->value(plotID); |
|
88 | return m_plots->value(plotID); | |
67 | } |
|
89 | } | |
68 | if(plotID==-1) |
|
90 | if(plotID==-1) | |
69 | { |
|
91 | { | |
70 | return m_LastPlot; |
|
92 | return m_LastPlot; | |
71 | } |
|
93 | } | |
72 | return NULL; |
|
94 | return NULL; | |
73 | } |
|
95 | } | |
74 |
|
96 | |||
75 | int QLopPlots::addPlot() |
|
97 | int QLopPlots::addPlot() | |
76 | { |
|
98 | { | |
77 | _INIT(); |
|
99 | _INIT(); | |
78 | int pid=getPlotID(); |
|
100 | int pid=getPlotID(); | |
79 | if(pid!=-1) |
|
101 | if(pid!=-1) | |
80 | { |
|
102 | { | |
81 | SocExplorerPlot* plot=new SocExplorerPlot(); |
|
103 | SocExplorerPlot* plot=new SocExplorerPlot(); | |
82 | plot->setPID(pid); |
|
104 | plot->setPID(pid); | |
83 | m_plots->insert(pid,plot); |
|
105 | m_plots->insert(pid,plot); | |
84 | QDockWidget* dock = new QDockWidget(); |
|
106 | QDockWidget* dock = new QDockWidget(); | |
85 | dock->setWidget(plot); |
|
107 | dock->setWidget(plot); | |
86 | dock->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
108 | dock->setAllowedAreas(Qt::AllDockWidgetAreas); | |
87 | m_DocContainer->addDockWidget(Qt::TopDockWidgetArea,dock); |
|
109 | m_DocContainer->addDockWidget(Qt::TopDockWidgetArea,dock); | |
88 | m_LastPlot=plot; |
|
110 | m_LastPlot=plot; | |
89 | QObject::connect(plot,SIGNAL(titleChanged(QString)),dock,SLOT(setWindowTitle(QString))); |
|
111 | QObject::connect(plot,SIGNAL(titleChanged(QString)),dock,SLOT(setWindowTitle(QString))); | |
90 | plot->setTitle(QString("Plot %1").arg(pid)); |
|
112 | plot->setTitle(QString("Plot %1").arg(pid)); | |
91 | } |
|
113 | } | |
92 | return pid; |
|
114 | return pid; | |
93 | } |
|
115 | } | |
94 |
|
116 | |||
95 | bool QLopPlots::removePlot(int plotID) |
|
117 | bool QLopPlots::removePlot(int plotID) | |
96 | { |
|
118 | { | |
97 | _INIT(); |
|
119 | _INIT(); | |
98 | if(m_plots->contains(plotID)) |
|
120 | if(m_plots->contains(plotID)) | |
99 | { |
|
121 | { | |
100 | SocExplorerPlot* plot=m_plots->value(plotID); |
|
122 | SocExplorerPlot* plot=m_plots->value(plotID); | |
101 | m_plots->remove(plotID); |
|
123 | m_plots->remove(plotID); | |
102 | QDockWidget* dock=(QDockWidget*)plot->parentWidget(); |
|
124 | QDockWidget* dock=(QDockWidget*)plot->parentWidget(); | |
103 | m_DocContainer->removeDockWidget(dock); |
|
125 | m_DocContainer->removeDockWidget(dock); | |
104 | if(plot==m_LastPlot) |
|
126 | if(plot==m_LastPlot) | |
105 | { |
|
127 | { | |
106 | //TODO may cause troubles... |
|
128 | //TODO may cause troubles... | |
107 | m_LastPlot = NULL; |
|
129 | m_LastPlot = NULL; | |
108 | } |
|
130 | } | |
109 | if(dock!=NULL) |
|
131 | if(dock!=NULL) | |
110 | { |
|
132 | { | |
111 | delete dock; |
|
133 | delete dock; | |
112 | } |
|
134 | } | |
113 | if(plot!=NULL) |
|
135 | if(plot!=NULL) | |
114 | { |
|
136 | { | |
115 | delete plot; |
|
137 | delete plot; | |
116 | } |
|
138 | } | |
117 | } |
|
139 | } | |
118 | return false; |
|
140 | return false; | |
119 | } |
|
141 | } | |
120 |
|
142 | |||
121 | QDockWidget *QLopPlots::getGUI() |
|
143 | QDockWidget *QLopPlots::getGUI() | |
122 | { |
|
144 | { | |
123 | if(!m_noGui && (m_gui==NULL)) |
|
145 | if(!m_noGui && (m_gui==NULL)) | |
124 | { |
|
146 | { | |
125 | m_gui=new QDockWidget("Plots"); |
|
147 | m_gui=new QDockWidget("Plots"); | |
126 | m_DocContainer = new toolBarContainer(); |
|
148 | m_DocContainer = new toolBarContainer(); | |
127 | // m_SocExplorerPlot = new SocExplorerPlot(); |
|
149 | // m_SocExplorerPlot = new SocExplorerPlot(); | |
128 | m_gui->setWidget(m_DocContainer); |
|
150 | m_gui->setWidget(m_DocContainer); | |
129 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
151 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | |
130 | } |
|
152 | } | |
131 | return m_gui; |
|
153 | return m_gui; | |
132 | } |
|
154 | } | |
133 |
|
155 | |||
134 | const QString &QLopPlots::serviceName() |
|
156 | const QString &QLopPlots::serviceName() | |
135 | { |
|
157 | { | |
136 | return m_serviceName; |
|
158 | return m_serviceName; | |
137 | } |
|
159 | } | |
138 |
|
160 | |||
139 | SocExplorerPlot *QLopPlots::get_plot(int plotID) |
|
161 | SocExplorerPlot *QLopPlots::get_plot(int plotID) | |
140 | { |
|
162 | { | |
141 | return getPlot(plotID); |
|
163 | return getPlot(plotID); | |
142 | } |
|
164 | } | |
143 |
|
165 | |||
144 | int QLopPlots::add_plot() |
|
166 | int QLopPlots::add_plot() | |
145 | { |
|
167 | { | |
146 | return addPlot(); |
|
168 | return addPlot(); | |
147 | } |
|
169 | } | |
148 |
|
170 | |||
149 | bool QLopPlots::remove_plot(int plotID) |
|
171 | bool QLopPlots::remove_plot(int plotID) | |
150 | { |
|
172 | { | |
151 | return removePlot(plotID); |
|
173 | return removePlot(plotID); | |
152 | } |
|
174 | } | |
153 |
|
175 |
@@ -1,41 +1,63 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef QLOPPLOTS_H |
|
23 | #ifndef QLOPPLOTS_H | |
2 | #define QLOPPLOTS_H |
|
24 | #define QLOPPLOTS_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 | #include <QWidget> |
|
27 | #include <QWidget> | |
6 | #include <qlopservice.h> |
|
28 | #include <qlopservice.h> | |
7 | #include <SocExplorerPlot.h> |
|
29 | #include <SocExplorerPlot.h> | |
8 | #include <QList> |
|
30 | #include <QList> | |
9 | #include <QHash> |
|
31 | #include <QHash> | |
10 | #include <toolbarcontainer.h> |
|
32 | #include <toolbarcontainer.h> | |
11 |
|
33 | |||
12 | class QLopPlots: public QLopService |
|
34 | class QLopPlots: public QLopService | |
13 | { |
|
35 | { | |
14 | Q_OBJECT |
|
36 | Q_OBJECT | |
15 | private: |
|
37 | private: | |
16 | static QLopPlots* _self; |
|
38 | static QLopPlots* _self; | |
17 | static SocExplorerPlot* m_LastPlot; |
|
39 | static SocExplorerPlot* m_LastPlot; | |
18 | static QHash<int,SocExplorerPlot*>* m_plots; |
|
40 | static QHash<int,SocExplorerPlot*>* m_plots; | |
19 | static QDockWidget* m_gui; |
|
41 | static QDockWidget* m_gui; | |
20 | static toolBarContainer* m_DocContainer; |
|
42 | static toolBarContainer* m_DocContainer; | |
21 | QLopPlots(bool noGUI=false,QObject *parent = 0); |
|
43 | QLopPlots(bool noGUI=false,QObject *parent = 0); | |
22 | ~QLopPlots(); |
|
44 | ~QLopPlots(); | |
23 | static int getPlotID(); |
|
45 | static int getPlotID(); | |
24 |
|
46 | |||
25 | public: |
|
47 | public: | |
26 | static void init(bool noGUI=false,QObject *parent = 0); |
|
48 | static void init(bool noGUI=false,QObject *parent = 0); | |
27 | static QLopPlots *self(); |
|
49 | static QLopPlots *self(); | |
28 | static SocExplorerPlot* getPlot(int plotID=-1); |
|
50 | static SocExplorerPlot* getPlot(int plotID=-1); | |
29 | static int addPlot(); |
|
51 | static int addPlot(); | |
30 | static bool removePlot(int plotID); |
|
52 | static bool removePlot(int plotID); | |
31 | // QLopService methodes |
|
53 | // QLopService methodes | |
32 | QDockWidget* getGUI(); |
|
54 | QDockWidget* getGUI(); | |
33 | const QString& serviceName(); |
|
55 | const QString& serviceName(); | |
34 | public slots: |
|
56 | public slots: | |
35 | SocExplorerPlot* get_plot(int plotID); |
|
57 | SocExplorerPlot* get_plot(int plotID); | |
36 | int add_plot(); |
|
58 | int add_plot(); | |
37 | bool remove_plot(int plotID); |
|
59 | bool remove_plot(int plotID); | |
38 | public: |
|
60 | public: | |
39 | }; |
|
61 | }; | |
40 |
|
62 | |||
41 | #endif // QLOPPLOTS_H |
|
63 | #endif // QLOPPLOTS_H |
@@ -1,12 +1,34 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "abstractfileloader.h" |
|
23 | #include "abstractfileloader.h" | |
2 |
|
24 | |||
3 | AbstractFileLoader::AbstractFileLoader(QObject *parent) : QThread(parent) |
|
25 | AbstractFileLoader::AbstractFileLoader(QObject *parent) : QThread(parent) | |
4 | { |
|
26 | { | |
5 |
|
27 | |||
6 | } |
|
28 | } | |
7 |
|
29 | |||
8 | AbstractFileLoader::~AbstractFileLoader() |
|
30 | AbstractFileLoader::~AbstractFileLoader() | |
9 | { |
|
31 | { | |
10 |
|
32 | |||
11 | } |
|
33 | } | |
12 |
|
34 |
@@ -1,32 +1,54 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef ABSTRACTFILELOADER_H |
|
23 | #ifndef ABSTRACTFILELOADER_H | |
2 | #define ABSTRACTFILELOADER_H |
|
24 | #define ABSTRACTFILELOADER_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 | #include <QThread> |
|
27 | #include <QThread> | |
6 | #include "qcustomplot.h" |
|
28 | #include "qcustomplot.h" | |
7 | #include <qlopdata.h> |
|
29 | #include <qlopdata.h> | |
8 | //typedef struct dataVector |
|
30 | //typedef struct dataVector | |
9 | //{ |
|
31 | //{ | |
10 | // QString name; |
|
32 | // QString name; | |
11 | // QString unit; |
|
33 | // QString unit; | |
12 | // QVector<QCPData>* data; |
|
34 | // QVector<QCPData>* data; | |
13 | //}dataVector; |
|
35 | //}dataVector; | |
14 |
|
36 | |||
15 | //typedef QList<dataVector> QListOfDataVector; |
|
37 | //typedef QList<dataVector> QListOfDataVector; | |
16 |
|
38 | |||
17 | class AbstractFileLoader : public QThread |
|
39 | class AbstractFileLoader : public QThread | |
18 | { |
|
40 | { | |
19 | Q_OBJECT |
|
41 | Q_OBJECT | |
20 | public: |
|
42 | public: | |
21 | explicit AbstractFileLoader(QObject *parent = 0); |
|
43 | explicit AbstractFileLoader(QObject *parent = 0); | |
22 | ~AbstractFileLoader(); |
|
44 | ~AbstractFileLoader(); | |
23 |
|
45 | |||
24 | virtual void parseFile(const QString &fileName)=0; |
|
46 | virtual void parseFile(const QString &fileName)=0; | |
25 | signals: |
|
47 | signals: | |
26 | void dataReady(QLopDataList data); |
|
48 | void dataReady(QLopDataList data); | |
27 | void updateProgress(int threadId,int percentProgress); |
|
49 | void updateProgress(int threadId,int percentProgress); | |
28 |
|
50 | |||
29 | public slots: |
|
51 | public slots: | |
30 | }; |
|
52 | }; | |
31 |
|
53 | |||
32 | #endif // ABSTRACTFILELOADER_H |
|
54 | #endif // ABSTRACTFILELOADER_H |
@@ -1,153 +1,175 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "filedownloader.h" |
|
23 | #include "filedownloader.h" | |
2 | #include <QFile> |
|
24 | #include <QFile> | |
3 | FileDownloader* FileDownloader::_self=NULL; |
|
25 | FileDownloader* FileDownloader::_self=NULL; | |
4 | QNetworkAccessManager* FileDownloader::m_WebCtrl=NULL; |
|
26 | QNetworkAccessManager* FileDownloader::m_WebCtrl=NULL; | |
5 | QList<FileDownloaderTask*>* FileDownloader::m_pendingTasks=NULL; |
|
27 | QList<FileDownloaderTask*>* FileDownloader::m_pendingTasks=NULL; | |
6 | QDockWidget* FileDownloader::m_gui=NULL; |
|
28 | QDockWidget* FileDownloader::m_gui=NULL; | |
7 | DownLoadHistory* FileDownloader::m_DownLoadHistory=NULL; |
|
29 | DownLoadHistory* FileDownloader::m_DownLoadHistory=NULL; | |
8 |
|
30 | |||
9 | #define _INIT \ |
|
31 | #define _INIT \ | |
10 | if(Q_UNLIKELY(_self==NULL))\ |
|
32 | if(Q_UNLIKELY(_self==NULL))\ | |
11 | {\ |
|
33 | {\ | |
12 | init();\ |
|
34 | init();\ | |
13 | }\ |
|
35 | }\ | |
14 |
|
36 | |||
15 |
|
37 | |||
16 | int FileDownloader::downloadFile(QUrl fileUrl, const QString &name) |
|
38 | int FileDownloader::downloadFile(QUrl fileUrl, const QString &name) | |
17 | { |
|
39 | { | |
18 | _INIT |
|
40 | _INIT | |
19 | if(QFile::exists(name)|| QFile::exists(name+".part")) |
|
41 | if(QFile::exists(name)|| QFile::exists(name+".part")) | |
20 | { |
|
42 | { | |
21 | return -1; |
|
43 | return -1; | |
22 | } |
|
44 | } | |
23 | FileDownloaderTask* task=NULL; |
|
45 | FileDownloaderTask* task=NULL; | |
24 | int ID=_self->getTaskId(); |
|
46 | int ID=_self->getTaskId(); | |
25 | if(ID!=-1) |
|
47 | if(ID!=-1) | |
26 | { |
|
48 | { | |
27 | QNetworkRequest request(fileUrl); |
|
49 | QNetworkRequest request(fileUrl); | |
28 | QNetworkReply* reply = m_WebCtrl->get(request); |
|
50 | QNetworkReply* reply = m_WebCtrl->get(request); | |
29 | if(reply && (reply->error()==QNetworkReply::NoError)) |
|
51 | if(reply && (reply->error()==QNetworkReply::NoError)) | |
30 | { |
|
52 | { | |
31 | task=new FileDownloaderTask(reply,ID,name,_self); |
|
53 | task=new FileDownloaderTask(reply,ID,name,_self); | |
32 | m_pendingTasks->append(task); |
|
54 | m_pendingTasks->append(task); | |
33 | if(!_self->m_noGui) |
|
55 | if(!_self->m_noGui) | |
34 | { |
|
56 | { | |
35 | m_DownLoadHistory->addElement(new DownloadHistoryElement(task)); |
|
57 | m_DownLoadHistory->addElement(new DownloadHistoryElement(task)); | |
36 | } |
|
58 | } | |
37 | } |
|
59 | } | |
38 | else |
|
60 | else | |
39 | { |
|
61 | { | |
40 | return -1; |
|
62 | return -1; | |
41 | } |
|
63 | } | |
42 | } |
|
64 | } | |
43 | return ID; |
|
65 | return ID; | |
44 | } |
|
66 | } | |
45 |
|
67 | |||
46 | int FileDownloader::downloadFile(QString fileUrl, const QString &name) |
|
68 | int FileDownloader::downloadFile(QString fileUrl, const QString &name) | |
47 | { |
|
69 | { | |
48 | return downloadFile(QUrl(fileUrl),name); |
|
70 | return downloadFile(QUrl(fileUrl),name); | |
49 | } |
|
71 | } | |
50 |
|
72 | |||
51 | QDockWidget *FileDownloader::getGUI() |
|
73 | QDockWidget *FileDownloader::getGUI() | |
52 | { |
|
74 | { | |
53 | if(!_self->m_noGui && (m_gui==NULL)) |
|
75 | if(!_self->m_noGui && (m_gui==NULL)) | |
54 | { |
|
76 | { | |
55 | m_DownLoadHistory=new DownLoadHistory(); |
|
77 | m_DownLoadHistory=new DownLoadHistory(); | |
56 | m_gui=new QDockWidget("Download History"); |
|
78 | m_gui=new QDockWidget("Download History"); | |
57 | m_gui->setWidget(m_DownLoadHistory); |
|
79 | m_gui->setWidget(m_DownLoadHistory); | |
58 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
80 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | |
59 | } |
|
81 | } | |
60 | return (QDockWidget*) m_gui; |
|
82 | return (QDockWidget*) m_gui; | |
61 | } |
|
83 | } | |
62 |
|
84 | |||
63 | const QString &FileDownloader::serviceName() |
|
85 | const QString &FileDownloader::serviceName() | |
64 | { |
|
86 | { | |
65 | return m_serviceName; |
|
87 | return m_serviceName; | |
66 | } |
|
88 | } | |
67 |
|
89 | |||
68 | int FileDownloader::download_file(QUrl fileUrl, const QString &name) |
|
90 | int FileDownloader::download_file(QUrl fileUrl, const QString &name) | |
69 | { |
|
91 | { | |
70 | return downloadFile(fileUrl,name); |
|
92 | return downloadFile(fileUrl,name); | |
71 | } |
|
93 | } | |
72 |
|
94 | |||
73 | int FileDownloader::download_file(QString fileUrl, const QString &name) |
|
95 | int FileDownloader::download_file(QString fileUrl, const QString &name) | |
74 | { |
|
96 | { | |
75 | return downloadFile(fileUrl,name); |
|
97 | return downloadFile(fileUrl,name); | |
76 | } |
|
98 | } | |
77 |
|
99 | |||
78 | FileDownloaderTask* FileDownloader::getDownloadTask(int ID) |
|
100 | FileDownloaderTask* FileDownloader::getDownloadTask(int ID) | |
79 | { |
|
101 | { | |
80 | _INIT |
|
102 | _INIT | |
81 | for(int i=0;i<m_pendingTasks->count();i++) |
|
103 | for(int i=0;i<m_pendingTasks->count();i++) | |
82 | { |
|
104 | { | |
83 | if(m_pendingTasks->at(i)->ID()==ID) |
|
105 | if(m_pendingTasks->at(i)->ID()==ID) | |
84 | return m_pendingTasks->at(i); |
|
106 | return m_pendingTasks->at(i); | |
85 | } |
|
107 | } | |
86 | return NULL; |
|
108 | return NULL; | |
87 | } |
|
109 | } | |
88 |
|
110 | |||
89 | bool FileDownloader::taskIsCompleted(int ID) |
|
111 | bool FileDownloader::taskIsCompleted(int ID) | |
90 | { |
|
112 | { | |
91 | return getDownloadTask(ID)->downloadComplete(); |
|
113 | return getDownloadTask(ID)->downloadComplete(); | |
92 | } |
|
114 | } | |
93 |
|
115 | |||
94 | FileDownloader *FileDownloader::self() |
|
116 | FileDownloader *FileDownloader::self() | |
95 | { |
|
117 | { | |
96 | _INIT |
|
118 | _INIT | |
97 | return _self; |
|
119 | return _self; | |
98 | } |
|
120 | } | |
99 |
|
121 | |||
100 | int FileDownloader::getTaskId() |
|
122 | int FileDownloader::getTaskId() | |
101 | { |
|
123 | { | |
102 | for(unsigned int i=0;i<INT_MAX;i++) |
|
124 | for(unsigned int i=0;i<INT_MAX;i++) | |
103 | { |
|
125 | { | |
104 | bool idValid=true; |
|
126 | bool idValid=true; | |
105 | for(int j=0;j<m_pendingTasks->count();j++) |
|
127 | for(int j=0;j<m_pendingTasks->count();j++) | |
106 | { |
|
128 | { | |
107 | if(m_pendingTasks->at(j)->ID()==(int)i) |
|
129 | if(m_pendingTasks->at(j)->ID()==(int)i) | |
108 | idValid=false; |
|
130 | idValid=false; | |
109 | } |
|
131 | } | |
110 | if(idValid) |
|
132 | if(idValid) | |
111 | return (int)i; |
|
133 | return (int)i; | |
112 | } |
|
134 | } | |
113 | return -1; |
|
135 | return -1; | |
114 | } |
|
136 | } | |
115 |
|
137 | |||
116 | void FileDownloader::init(bool noGUI, QObject *parent) |
|
138 | void FileDownloader::init(bool noGUI, QObject *parent) | |
117 | { |
|
139 | { | |
118 | if(Q_UNLIKELY(_self==NULL)) |
|
140 | if(Q_UNLIKELY(_self==NULL)) | |
119 | { |
|
141 | { | |
120 | _self=new FileDownloader(noGUI,parent); |
|
142 | _self=new FileDownloader(noGUI,parent); | |
121 | } |
|
143 | } | |
122 | } |
|
144 | } | |
123 |
|
145 | |||
124 | FileDownloader::FileDownloader(bool noGUI,QObject *parent) : QLopService(parent) |
|
146 | FileDownloader::FileDownloader(bool noGUI,QObject *parent) : QLopService(parent) | |
125 | { |
|
147 | { | |
126 | QNetworkProxyQuery q(QUrl("http://www.google.com")); |
|
148 | QNetworkProxyQuery q(QUrl("http://www.google.com")); | |
127 | q.setQueryType(QNetworkProxyQuery::UrlRequest); |
|
149 | q.setQueryType(QNetworkProxyQuery::UrlRequest); | |
128 | q.setProtocolTag("http"); |
|
150 | q.setProtocolTag("http"); | |
129 | QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(q); |
|
151 | QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(q); | |
130 | if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy ) |
|
152 | if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy ) | |
131 | QNetworkProxy::setApplicationProxy(proxies[0]); |
|
153 | QNetworkProxy::setApplicationProxy(proxies[0]); | |
132 | else |
|
154 | else | |
133 | qDebug("No proxy server selected"); |
|
155 | qDebug("No proxy server selected"); | |
134 | m_WebCtrl = new QNetworkAccessManager(this); |
|
156 | m_WebCtrl = new QNetworkAccessManager(this); | |
135 | m_pendingTasks = new QList<FileDownloaderTask*>(); |
|
157 | m_pendingTasks = new QList<FileDownloaderTask*>(); | |
136 | m_noGui=noGUI; |
|
158 | m_noGui=noGUI; | |
137 | m_serviceName="FileDownloader"; |
|
159 | m_serviceName="FileDownloader"; | |
138 |
|
160 | |||
139 | } |
|
161 | } | |
140 |
|
162 | |||
141 | FileDownloader::~FileDownloader() |
|
163 | FileDownloader::~FileDownloader() | |
142 | { |
|
164 | { | |
143 | if(!m_noGui) |
|
165 | if(!m_noGui) | |
144 | delete m_gui; |
|
166 | delete m_gui; | |
145 | while (m_pendingTasks->count()) |
|
167 | while (m_pendingTasks->count()) | |
146 | { |
|
168 | { | |
147 | FileDownloaderTask* task=m_pendingTasks->last(); |
|
169 | FileDownloaderTask* task=m_pendingTasks->last(); | |
148 | m_pendingTasks->removeLast(); |
|
170 | m_pendingTasks->removeLast(); | |
149 | delete task; |
|
171 | delete task; | |
150 | } |
|
172 | } | |
151 | delete m_WebCtrl; |
|
173 | delete m_WebCtrl; | |
152 | } |
|
174 | } | |
153 |
|
175 |
@@ -1,46 +1,68 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef FILEDOWNLOADER_H |
|
23 | #ifndef FILEDOWNLOADER_H | |
2 | #define FILEDOWNLOADER_H |
|
24 | #define FILEDOWNLOADER_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 | #include <QNetworkAccessManager> |
|
27 | #include <QNetworkAccessManager> | |
6 | #include <QNetworkReply> |
|
28 | #include <QNetworkReply> | |
7 | #include <QNetworkProxy> |
|
29 | #include <QNetworkProxy> | |
8 | #include <QList> |
|
30 | #include <QList> | |
9 | #include <QHash> |
|
31 | #include <QHash> | |
10 | #include <filedownloadertask.h> |
|
32 | #include <filedownloadertask.h> | |
11 | #include <downloadhistory.h> |
|
33 | #include <downloadhistory.h> | |
12 | #include <qlopservice.h> |
|
34 | #include <qlopservice.h> | |
13 | #include <QDockWidget> |
|
35 | #include <QDockWidget> | |
14 |
|
36 | |||
15 | class FileDownloader : public QLopService |
|
37 | class FileDownloader : public QLopService | |
16 | { |
|
38 | { | |
17 | Q_OBJECT |
|
39 | Q_OBJECT | |
18 | private: |
|
40 | private: | |
19 | static FileDownloader* _self; |
|
41 | static FileDownloader* _self; | |
20 | static QNetworkAccessManager* m_WebCtrl; |
|
42 | static QNetworkAccessManager* m_WebCtrl; | |
21 | static QList<FileDownloaderTask*>* m_pendingTasks; |
|
43 | static QList<FileDownloaderTask*>* m_pendingTasks; | |
22 | static DownLoadHistory* m_DownLoadHistory; |
|
44 | static DownLoadHistory* m_DownLoadHistory; | |
23 | static QDockWidget* m_gui; |
|
45 | static QDockWidget* m_gui; | |
24 | FileDownloader(bool noGUI=false,QObject *parent = 0); |
|
46 | FileDownloader(bool noGUI=false,QObject *parent = 0); | |
25 | ~FileDownloader(); |
|
47 | ~FileDownloader(); | |
26 |
|
48 | |||
27 | public: |
|
49 | public: | |
28 | static void init(bool noGUI=false,QObject *parent = 0); |
|
50 | static void init(bool noGUI=false,QObject *parent = 0); | |
29 | static int downloadFile(QUrl fileUrl,const QString& name); |
|
51 | static int downloadFile(QUrl fileUrl,const QString& name); | |
30 | static int downloadFile(QString fileUrl,const QString& name); |
|
52 | static int downloadFile(QString fileUrl,const QString& name); | |
31 | static FileDownloaderTask *getDownloadTask(int ID); |
|
53 | static FileDownloaderTask *getDownloadTask(int ID); | |
32 | static bool taskIsCompleted(int ID); |
|
54 | static bool taskIsCompleted(int ID); | |
33 | static FileDownloader *self(); |
|
55 | static FileDownloader *self(); | |
34 | // QLopService methodes |
|
56 | // QLopService methodes | |
35 | QDockWidget* getGUI(); |
|
57 | QDockWidget* getGUI(); | |
36 | const QString& serviceName(); |
|
58 | const QString& serviceName(); | |
37 | signals: |
|
59 | signals: | |
38 |
|
60 | |||
39 | public slots: |
|
61 | public slots: | |
40 | int download_file(QUrl fileUrl,const QString& name); |
|
62 | int download_file(QUrl fileUrl,const QString& name); | |
41 | int download_file(QString fileUrl,const QString& name); |
|
63 | int download_file(QString fileUrl,const QString& name); | |
42 | private: |
|
64 | private: | |
43 | int getTaskId(); |
|
65 | int getTaskId(); | |
44 | }; |
|
66 | }; | |
45 |
|
67 | |||
46 | #endif // FILEDOWNLOADER_H |
|
68 | #endif // FILEDOWNLOADER_H |
@@ -1,53 +1,75 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "filedownloadertask.h" |
|
23 | #include "filedownloadertask.h" | |
2 |
|
24 | |||
3 | FileDownloaderTask::FileDownloaderTask(QNetworkReply *reply, int ID, const QString &fileName, QObject *parent) : QObject(parent) |
|
25 | FileDownloaderTask::FileDownloaderTask(QNetworkReply *reply, int ID, const QString &fileName, QObject *parent) : QObject(parent) | |
4 | { |
|
26 | { | |
5 | this->m_Reply = reply; |
|
27 | this->m_Reply = reply; | |
6 | this->m_downloadComplete = false; |
|
28 | this->m_downloadComplete = false; | |
7 | this->m_FileName = fileName; |
|
29 | this->m_FileName = fileName; | |
8 | this->m_taskId = ID; |
|
30 | this->m_taskId = ID; | |
9 | this->m_file = new QFile(fileName+".part"); |
|
31 | this->m_file = new QFile(fileName+".part"); | |
10 | this->m_file->open(QIODevice::WriteOnly|QIODevice::Truncate); |
|
32 | this->m_file->open(QIODevice::WriteOnly|QIODevice::Truncate); | |
11 | this->m_startDateTime = QDateTime::currentDateTime(); |
|
33 | this->m_startDateTime = QDateTime::currentDateTime(); | |
12 | this->m_URL = m_Reply->url().toString(); |
|
34 | this->m_URL = m_Reply->url().toString(); | |
13 | connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); |
|
35 | connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); | |
14 | connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SIGNAL(updateProgress(qint64,qint64))); |
|
36 | connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SIGNAL(updateProgress(qint64,qint64))); | |
15 | connect(this->m_Reply,SIGNAL(readyRead()),this,SLOT(readReady())); |
|
37 | connect(this->m_Reply,SIGNAL(readyRead()),this,SLOT(readReady())); | |
16 | connect(this->m_Reply,SIGNAL(finished()),this,SLOT(downloadFinished())); |
|
38 | connect(this->m_Reply,SIGNAL(finished()),this,SLOT(downloadFinished())); | |
17 | } |
|
39 | } | |
18 |
|
40 | |||
19 | FileDownloaderTask::~FileDownloaderTask() |
|
41 | FileDownloaderTask::~FileDownloaderTask() | |
20 | { |
|
42 | { | |
21 | delete m_file; |
|
43 | delete m_file; | |
22 | delete m_Reply; |
|
44 | delete m_Reply; | |
23 | } |
|
45 | } | |
24 |
|
46 | |||
25 | int FileDownloaderTask::ID(){return m_taskId;} |
|
47 | int FileDownloaderTask::ID(){return m_taskId;} | |
26 |
|
48 | |||
27 | const QString &FileDownloaderTask::fileName(){return m_FileName;} |
|
49 | const QString &FileDownloaderTask::fileName(){return m_FileName;} | |
28 |
|
50 | |||
29 | const QString &FileDownloaderTask::url(){return m_URL;} |
|
51 | const QString &FileDownloaderTask::url(){return m_URL;} | |
30 |
|
52 | |||
31 | const QDateTime &FileDownloaderTask::startDateTime(){return m_startDateTime;} |
|
53 | const QDateTime &FileDownloaderTask::startDateTime(){return m_startDateTime;} | |
32 |
|
54 | |||
33 | bool FileDownloaderTask::downloadComplete(){return m_downloadComplete;} |
|
55 | bool FileDownloaderTask::downloadComplete(){return m_downloadComplete;} | |
34 |
|
56 | |||
35 | void FileDownloaderTask::downloadProgress(qint64 bytesSent, qint64 bytesTotal) |
|
57 | void FileDownloaderTask::downloadProgress(qint64 bytesSent, qint64 bytesTotal) | |
36 | { |
|
58 | { | |
37 | if(bytesTotal!=0) |
|
59 | if(bytesTotal!=0) | |
38 | emit updateProgress((100*bytesSent)/bytesTotal); |
|
60 | emit updateProgress((100*bytesSent)/bytesTotal); | |
39 | } |
|
61 | } | |
40 |
|
62 | |||
41 | void FileDownloaderTask::readReady() |
|
63 | void FileDownloaderTask::readReady() | |
42 | { |
|
64 | { | |
43 | this->m_file->write(this->m_Reply->readAll()); |
|
65 | this->m_file->write(this->m_Reply->readAll()); | |
44 | } |
|
66 | } | |
45 |
|
67 | |||
46 | void FileDownloaderTask::downloadFinished() |
|
68 | void FileDownloaderTask::downloadFinished() | |
47 | { |
|
69 | { | |
48 | this->m_downloadComplete = true; |
|
70 | this->m_downloadComplete = true; | |
49 | this->m_file->write(this->m_Reply->readAll()); |
|
71 | this->m_file->write(this->m_Reply->readAll()); | |
50 | this->m_file->close(); |
|
72 | this->m_file->close(); | |
51 | this->m_file->rename(this->m_FileName); |
|
73 | this->m_file->rename(this->m_FileName); | |
52 | } |
|
74 | } | |
53 |
|
75 |
@@ -1,45 +1,67 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef FILEDOWNLOADERTASK_H |
|
23 | #ifndef FILEDOWNLOADERTASK_H | |
2 | #define FILEDOWNLOADERTASK_H |
|
24 | #define FILEDOWNLOADERTASK_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 | #include <QByteArray> |
|
27 | #include <QByteArray> | |
6 | #include <QNetworkAccessManager> |
|
28 | #include <QNetworkAccessManager> | |
7 | #include <QNetworkRequest> |
|
29 | #include <QNetworkRequest> | |
8 | #include <QNetworkReply> |
|
30 | #include <QNetworkReply> | |
9 | #include <QFile> |
|
31 | #include <QFile> | |
10 | #include <QDateTime> |
|
32 | #include <QDateTime> | |
11 |
|
33 | |||
12 | // TODO add download speed and remaining time. |
|
34 | // TODO add download speed and remaining time. | |
13 |
|
35 | |||
14 | class FileDownloaderTask : public QObject |
|
36 | class FileDownloaderTask : public QObject | |
15 | { |
|
37 | { | |
16 | Q_OBJECT |
|
38 | Q_OBJECT | |
17 | public: |
|
39 | public: | |
18 | explicit FileDownloaderTask(QNetworkReply* reply,int ID,const QString& fileName,QObject *parent = 0); |
|
40 | explicit FileDownloaderTask(QNetworkReply* reply,int ID,const QString& fileName,QObject *parent = 0); | |
19 | ~FileDownloaderTask(); |
|
41 | ~FileDownloaderTask(); | |
20 | int ID(); |
|
42 | int ID(); | |
21 | const QString& fileName(); |
|
43 | const QString& fileName(); | |
22 | const QString& url(); |
|
44 | const QString& url(); | |
23 | const QDateTime& startDateTime(); |
|
45 | const QDateTime& startDateTime(); | |
24 | bool downloadComplete(); |
|
46 | bool downloadComplete(); | |
25 | signals: |
|
47 | signals: | |
26 | void updateProgress(int percent); |
|
48 | void updateProgress(int percent); | |
27 | void updateProgress(qint64 bytesSent, qint64 bytesTotal); |
|
49 | void updateProgress(qint64 bytesSent, qint64 bytesTotal); | |
28 | public slots: |
|
50 | public slots: | |
29 |
|
51 | |||
30 | private slots: |
|
52 | private slots: | |
31 | void downloadProgress(qint64 bytesSent, qint64 bytesTotal); |
|
53 | void downloadProgress(qint64 bytesSent, qint64 bytesTotal); | |
32 | void readReady(); |
|
54 | void readReady(); | |
33 | void downloadFinished(); |
|
55 | void downloadFinished(); | |
34 | private: |
|
56 | private: | |
35 | int m_taskId; |
|
57 | int m_taskId; | |
36 | QNetworkReply* m_Reply; |
|
58 | QNetworkReply* m_Reply; | |
37 | QByteArray m_DownloadedData; |
|
59 | QByteArray m_DownloadedData; | |
38 | bool m_downloadComplete; |
|
60 | bool m_downloadComplete; | |
39 | QFile* m_file; |
|
61 | QFile* m_file; | |
40 | QString m_FileName; |
|
62 | QString m_FileName; | |
41 | QString m_URL; |
|
63 | QString m_URL; | |
42 | QDateTime m_startDateTime; |
|
64 | QDateTime m_startDateTime; | |
43 | }; |
|
65 | }; | |
44 |
|
66 | |||
45 | #endif // FILEDOWNLOADERTASK_H |
|
67 | #endif // FILEDOWNLOADERTASK_H |
@@ -1,15 +1,37 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef QLOP |
|
23 | #ifndef QLOP | |
2 | #define QLOP |
|
24 | #define QLOP | |
3 | #ifdef WIN32 |
|
25 | #ifdef WIN32 | |
4 | #define QLOP_PLUGINS_INSTALL_PATH qApp->applicationDirPath()+"/plugins" |
|
26 | #define QLOP_PLUGINS_INSTALL_PATH qApp->applicationDirPath()+"/plugins" | |
5 | #define QLOP_CONFIG_PATH qApp->applicationDirPath()+"/config" |
|
27 | #define QLOP_CONFIG_PATH qApp->applicationDirPath()+"/config" | |
6 | #define PYMODULES qApp->applicationDirPath()+"/python" |
|
28 | #define PYMODULES qApp->applicationDirPath()+"/python" | |
7 | #else |
|
29 | #else | |
8 | #ifdef UNIX |
|
30 | #ifdef UNIX | |
9 | #define QLOP_PLUGINS_INSTALL_PATH QDir::homePath()+"/.QLop/plugins" |
|
31 | #define QLOP_PLUGINS_INSTALL_PATH QDir::homePath()+"/.QLop/plugins" | |
10 | #define QLOP_CONFIG_PATH QDir::homePath()+"/.QLop/config" |
|
32 | #define QLOP_CONFIG_PATH QDir::homePath()+"/.QLop/config" | |
11 | #define PYMODULES "/etc/QLop/python" |
|
33 | #define PYMODULES "/etc/QLop/python" | |
12 | #endif |
|
34 | #endif | |
13 | #endif |
|
35 | #endif | |
14 | #endif // QLOP |
|
36 | #endif // QLOP | |
15 |
|
37 |
@@ -1,12 +1,34 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "qlopdata.h" |
|
23 | #include "qlopdata.h" | |
2 |
|
24 | |||
3 | QLopData::QLopData(QObject *parent) : QObject(parent) |
|
25 | QLopData::QLopData(QObject *parent) : QObject(parent) | |
4 | { |
|
26 | { | |
5 |
|
27 | |||
6 | } |
|
28 | } | |
7 |
|
29 | |||
8 | QLopData::~QLopData() |
|
30 | QLopData::~QLopData() | |
9 | { |
|
31 | { | |
10 | delete data; |
|
32 | delete data; | |
11 | } |
|
33 | } | |
12 |
|
34 |
@@ -1,34 +1,56 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef QLOPDATA_H |
|
23 | #ifndef QLOPDATA_H | |
2 | #define QLOPDATA_H |
|
24 | #define QLOPDATA_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 | #include <qcustomplot.h> |
|
27 | #include <qcustomplot.h> | |
6 |
|
28 | |||
7 | typedef struct dataVector |
|
29 | typedef struct dataVector | |
8 | { |
|
30 | { | |
9 | QString name; |
|
31 | QString name; | |
10 | QString unit; |
|
32 | QString unit; | |
11 | QVector<QCPData>* data; |
|
33 | QVector<QCPData>* data; | |
12 | }dataVector; |
|
34 | }dataVector; | |
13 |
|
35 | |||
14 | typedef QList<dataVector> QListOfDataVector; |
|
36 | typedef QList<dataVector> QListOfDataVector; | |
15 |
|
37 | |||
16 |
|
38 | |||
17 |
|
39 | |||
18 | class QLopData : public QObject |
|
40 | class QLopData : public QObject | |
19 | { |
|
41 | { | |
20 | Q_OBJECT |
|
42 | Q_OBJECT | |
21 | public: |
|
43 | public: | |
22 | explicit QLopData(QObject *parent = 0); |
|
44 | explicit QLopData(QObject *parent = 0); | |
23 | ~QLopData(); |
|
45 | ~QLopData(); | |
24 | QString name; |
|
46 | QString name; | |
25 | QString unit; |
|
47 | QString unit; | |
26 | QVector<QCPData>* data; |
|
48 | QVector<QCPData>* data; | |
27 | signals: |
|
49 | signals: | |
28 | void dataChanged(); |
|
50 | void dataChanged(); | |
29 | public slots: |
|
51 | public slots: | |
30 | private: |
|
52 | private: | |
31 | }; |
|
53 | }; | |
32 | typedef QList<QLopData*> QLopDataList; |
|
54 | typedef QList<QLopData*> QLopDataList; | |
33 |
|
55 | |||
34 | #endif // QLOPDATA_H |
|
56 | #endif // QLOPDATA_H |
@@ -1,12 +1,34 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "qlopservice.h" |
|
23 | #include "qlopservice.h" | |
2 |
|
24 | |||
3 | QLopService::QLopService(QObject *parent) : QObject(parent) |
|
25 | QLopService::QLopService(QObject *parent) : QObject(parent) | |
4 | { |
|
26 | { | |
5 |
|
27 | |||
6 | } |
|
28 | } | |
7 |
|
29 | |||
8 | QLopService::~QLopService() |
|
30 | QLopService::~QLopService() | |
9 | { |
|
31 | { | |
10 |
|
32 | |||
11 | } |
|
33 | } | |
12 |
|
34 |
@@ -1,24 +1,46 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #ifndef QLOPSERVICE_H |
|
23 | #ifndef QLOPSERVICE_H | |
2 | #define QLOPSERVICE_H |
|
24 | #define QLOPSERVICE_H | |
3 |
|
25 | |||
4 | #include <QObject> |
|
26 | #include <QObject> | |
5 | #include <QWidget> |
|
27 | #include <QWidget> | |
6 | #include <QDockWidget> |
|
28 | #include <QDockWidget> | |
7 |
|
29 | |||
8 | class QLopService : public QObject |
|
30 | class QLopService : public QObject | |
9 | { |
|
31 | { | |
10 | Q_OBJECT |
|
32 | Q_OBJECT | |
11 | public: |
|
33 | public: | |
12 | explicit QLopService(QObject *parent = 0); |
|
34 | explicit QLopService(QObject *parent = 0); | |
13 | ~QLopService(); |
|
35 | ~QLopService(); | |
14 | virtual QDockWidget* getGUI()=0; |
|
36 | virtual QDockWidget* getGUI()=0; | |
15 | virtual const QString& serviceName(){return m_serviceName;} |
|
37 | virtual const QString& serviceName(){return m_serviceName;} | |
16 | signals: |
|
38 | signals: | |
17 |
|
39 | |||
18 | public slots: |
|
40 | public slots: | |
19 | protected: |
|
41 | protected: | |
20 | bool m_noGui; |
|
42 | bool m_noGui; | |
21 | QString m_serviceName; |
|
43 | QString m_serviceName; | |
22 | }; |
|
44 | }; | |
23 |
|
45 | |||
24 | #endif // QLOPSERVICE_H |
|
46 | #endif // QLOPSERVICE_H |
This diff has been collapsed as it changes many lines, (566 lines changed) Show them Hide them | |||||
@@ -1,669 +1,715 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "SocExplorerPlot.h" |
|
22 | #include "SocExplorerPlot.h" | |
23 | #include <QSvgGenerator> |
|
23 | #include <QSvgGenerator> | |
24 | #include <qcpdocumentobject.h> |
|
24 | #include <qcpdocumentobject.h> | |
25 | #include <QPdfWriter> |
|
25 | #include <QPdfWriter> | |
26 | #include <QPrinter> |
|
26 | #include <QPrinter> | |
27 |
|
27 | |||
28 | SocExplorerPlot::SocExplorerPlot(QWidget *parent) : |
|
28 | SocExplorerPlot::SocExplorerPlot(QWidget *parent) : | |
29 | QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this)) |
|
29 | QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this)) | |
30 | { |
|
30 | { | |
31 | this->m_plot = new QCustomPlotVect(this); |
|
31 | this->m_plot = new QCustomPlotVect(this); | |
32 | this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | |
|
32 | this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | | |
33 | QCP::iSelectLegend | QCP::iSelectPlottables); |
|
33 | QCP::iSelectLegend | QCP::iSelectPlottables); | |
34 | this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical); |
|
34 | this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical); | |
35 | this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); |
|
35 | this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); | |
36 | this->m_mainlayout = new QGridLayout(this); |
|
36 | this->m_mainlayout = new QGridLayout(this); | |
37 | this->setLayout(this->m_mainlayout); |
|
37 | this->setLayout(this->m_mainlayout); | |
38 | this->m_mainlayout->addWidget(this->m_plot); |
|
38 | this->m_mainlayout->addWidget(this->m_plot); | |
39 | this->setMinimumSize(400,300); |
|
39 | this->setMinimumSize(400,300); | |
40 | this->setFocusPolicy(Qt::WheelFocus); |
|
40 | this->setFocusPolicy(Qt::WheelFocus); | |
41 | this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); |
|
41 | this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); | |
42 | this->ctrl_hold = false; |
|
42 | this->ctrl_hold = false; | |
43 | this->shift_hold = false; |
|
43 | this->shift_hold = false; | |
44 | this->mouse_hold = false; |
|
44 | this->mouse_hold = false; | |
45 | this->m_plot->setNoAntialiasingOnDrag(true); |
|
45 | this->m_plot->setNoAntialiasingOnDrag(true); | |
46 | this->show(); |
|
46 | this->show(); | |
47 | this->m_plot->legend->setVisible(true); |
|
47 | this->m_plot->legend->setVisible(true); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | SocExplorerPlot::~SocExplorerPlot() |
|
50 | SocExplorerPlot::~SocExplorerPlot() | |
51 | { |
|
51 | { | |
52 | delete mRubberBand; |
|
52 | delete mRubberBand; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void SocExplorerPlot::show() |
|
55 | void SocExplorerPlot::show() | |
56 | { |
|
56 | { | |
57 | QWidget::show(); |
|
57 | QWidget::show(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void SocExplorerPlot::replot() |
|
60 | void SocExplorerPlot::replot() | |
61 | { |
|
61 | { | |
62 | this->m_plot->replot(); |
|
62 | this->m_plot->replot(); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void SocExplorerPlot::exportToSVG(const QString &fileName) |
|
65 | void SocExplorerPlot::exportToSVG(const QString &fileName) | |
66 | { |
|
66 | { | |
67 | QSvgGenerator printer; |
|
67 | QSvgGenerator printer; | |
68 | printer.setFileName(fileName); |
|
68 | printer.setFileName(fileName); | |
69 | QCPPainter qcpPainter; |
|
69 | QCPPainter qcpPainter; | |
70 | qcpPainter.begin(&printer); |
|
70 | qcpPainter.begin(&printer); | |
71 | m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height()); |
|
71 | m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height()); | |
72 | qcpPainter.end(); |
|
72 | qcpPainter.end(); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void SocExplorerPlot::exportToPDF(const QString &fileName) |
|
75 | void SocExplorerPlot::exportToPDF(const QString &fileName) | |
76 | { |
|
76 | { | |
77 | QPrinter printer(QPrinter::HighResolution); |
|
77 | QPrinter printer(QPrinter::HighResolution); | |
78 | printer.setOutputFormat(QPrinter::PdfFormat); |
|
78 | printer.setOutputFormat(QPrinter::PdfFormat); | |
79 | printer.setOrientation(QPrinter::Landscape); |
|
79 | printer.setOrientation(QPrinter::Landscape); | |
80 | printer.setOutputFileName(fileName); |
|
80 | printer.setOutputFileName(fileName); | |
81 | printer.setFullPage(true); |
|
81 | printer.setFullPage(true); | |
82 | QCPPainter qcpPainter; |
|
82 | QCPPainter qcpPainter; | |
83 | qcpPainter.begin(&printer); |
|
83 | qcpPainter.begin(&printer); | |
84 | m_plot->toPainter(&qcpPainter, printer.width(), printer.height()); |
|
84 | m_plot->toPainter(&qcpPainter, printer.width(), printer.height()); | |
85 | qcpPainter.end(); |
|
85 | qcpPainter.end(); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void SocExplorerPlot::addAction(SocExplorerPlotActions *action) |
|
88 | void SocExplorerPlot::addAction(SocExplorerPlotActions *action) | |
89 | { |
|
89 | { | |
90 | this->m_actions.append(action); |
|
90 | this->m_actions.append(action); | |
91 | QWidget::addAction((QAction*)action); |
|
91 | QWidget::addAction((QAction*)action); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex) |
|
94 | QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex) | |
95 | { |
|
95 | { | |
96 | QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData(); |
|
96 | QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData(); | |
97 | return visibleData; |
|
97 | return visibleData; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void SocExplorerPlot::setTitle(QString title) |
|
100 | void SocExplorerPlot::setTitle(QString title) | |
101 | { |
|
101 | { | |
102 | Q_UNUSED(title) |
|
102 | Q_UNUSED(title) | |
103 | //this->m_plot->setTitle(title); |
|
103 | //this->m_plot->setTitle(title); | |
104 | /*! |
|
104 | /*! | |
105 | @todo Function borcken fixe this! |
|
105 | @todo Function borcken fixe this! | |
106 | */ |
|
106 | */ | |
107 | this->m_Title = title; |
|
107 | this->m_Title = title; | |
108 | emit titleChanged(title); |
|
108 | emit titleChanged(title); | |
109 | this->repaint(); |
|
109 | this->repaint(); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | const QString &SocExplorerPlot::title() |
|
112 | const QString &SocExplorerPlot::title() | |
113 | { |
|
113 | { | |
114 | return m_Title; |
|
114 | return m_Title; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void SocExplorerPlot::setXaxisLabel(QString label) |
|
117 | void SocExplorerPlot::setXaxisLabel(QString label) | |
118 | { |
|
118 | { | |
119 | this->m_plot->xAxis->setLabel(label); |
|
119 | this->m_plot->xAxis->setLabel(label); | |
120 | this->repaint(); |
|
120 | this->repaint(); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void SocExplorerPlot::setXaxisLog() |
|
123 | void SocExplorerPlot::setXaxisLog() | |
124 | { |
|
124 | { | |
125 | this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic); |
|
125 | this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | void SocExplorerPlot::setYaxisLabel(QString label) |
|
128 | void SocExplorerPlot::setYaxisLabel(QString label) | |
129 | { |
|
129 | { | |
130 | this->m_plot->yAxis->setLabel(label); |
|
130 | this->m_plot->yAxis->setLabel(label); | |
131 | this->repaint(); |
|
131 | this->repaint(); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void SocExplorerPlot::setYaxisLog() |
|
134 | void SocExplorerPlot::setYaxisLog() | |
135 | { |
|
135 | { | |
136 | this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic); |
|
136 | this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic); | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | void SocExplorerPlot::setXaxisRange(double lower, double upper) |
|
139 | void SocExplorerPlot::setXaxisRange(double lower, double upper) | |
140 | { |
|
140 | { | |
141 | this->m_plot->xAxis->setRange(lower,upper); |
|
141 | this->m_plot->xAxis->setRange(lower,upper); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void SocExplorerPlot::setYaxisRange(double lower, double upper) |
|
144 | void SocExplorerPlot::setYaxisRange(double lower, double upper) | |
145 | { |
|
145 | { | |
146 | this->m_plot->yAxis->setRange(lower,upper); |
|
146 | this->m_plot->yAxis->setRange(lower,upper); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 |
|
149 | |||
150 | void SocExplorerPlot::rescaleAxis() |
|
150 | void SocExplorerPlot::rescaleAxis() | |
151 | { |
|
151 | { | |
152 | this->m_plot->rescaleAxes(); |
|
152 | this->m_plot->rescaleAxes(); | |
153 | this->m_plot->replot(); |
|
153 | this->m_plot->replot(); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void SocExplorerPlot::setLegendFont(QFont font) |
|
156 | void SocExplorerPlot::setLegendFont(QFont font) | |
157 | { |
|
157 | { | |
158 | this->m_plot->legend->setFont(font); |
|
158 | this->m_plot->legend->setFont(font); | |
159 | this->repaint(); |
|
159 | this->repaint(); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void SocExplorerPlot::setLegendSelectedFont(QFont font) |
|
162 | void SocExplorerPlot::setLegendSelectedFont(QFont font) | |
163 | { |
|
163 | { | |
164 | this->m_plot->legend->setSelectedFont(font); |
|
164 | this->m_plot->legend->setSelectedFont(font); | |
165 | this->repaint(); |
|
165 | this->repaint(); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable) |
|
168 | void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable) | |
169 | { |
|
169 | { | |
170 | this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable); |
|
170 | this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable) |
|
173 | void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable) | |
174 | { |
|
174 | { | |
175 | // TODO deprecated |
|
175 | // TODO deprecated | |
176 | // this->m_plot->graph(graphIndex)->setUseFastVectors(enable); |
|
176 | // this->m_plot->graph(graphIndex)->setUseFastVectors(enable); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | int SocExplorerPlot::addGraph() |
|
179 | int SocExplorerPlot::addGraph() | |
180 | { |
|
180 | { | |
181 | this->m_plot->addGraph(); |
|
181 | this->m_plot->addGraph(); | |
182 | return this->m_plot->graphCount() -1; |
|
182 | return this->m_plot->graphCount() -1; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | bool SocExplorerPlot::removeGraph(int graphIndex) |
|
185 | bool SocExplorerPlot::removeGraph(int graphIndex) | |
186 | { |
|
186 | { | |
187 | return this->m_plot->removeGraph(graphIndex); |
|
187 | return this->m_plot->removeGraph(graphIndex); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | int SocExplorerPlot::graphCount() |
|
190 | int SocExplorerPlot::graphCount() | |
191 | { |
|
191 | { | |
192 | return m_plot->graphCount(); |
|
192 | return m_plot->graphCount(); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | void SocExplorerPlot::removeAllGraphs() |
|
195 | void SocExplorerPlot::removeAllGraphs() | |
196 | { |
|
196 | { | |
197 | int graphCount=this->m_plot->graphCount(); |
|
197 | int graphCount=this->m_plot->graphCount(); | |
198 | for(int i=0;i<graphCount;i++) |
|
198 | for(int i=0;i<graphCount;i++) | |
199 | { |
|
199 | { | |
200 | this->m_plot->removeGraph(0); |
|
200 | this->m_plot->removeGraph(0); | |
201 | } |
|
201 | } | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 |
|
204 | |||
205 | void SocExplorerPlot::setGraphName(int graphIndex,QString name) |
|
205 | void SocExplorerPlot::setGraphName(int graphIndex,QString name) | |
206 | { |
|
206 | { | |
207 | if(graphIndex<this->m_plot->graphCount()) |
|
207 | if(graphIndex<this->m_plot->graphCount()) | |
208 | { |
|
208 | { | |
209 | this->m_plot->graph(graphIndex)->setName(name); |
|
209 | this->m_plot->graph(graphIndex)->setName(name); | |
210 | } |
|
210 | } | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | const QString &SocExplorerPlot::graphName(int graphIndex) |
|
213 | const QString &SocExplorerPlot::graphName(int graphIndex) | |
214 | { |
|
214 | { | |
215 | if(graphIndex<this->m_plot->graphCount()) |
|
215 | if(graphIndex<this->m_plot->graphCount()) | |
216 | { |
|
216 | { | |
217 | return this->m_plot->graph(graphIndex)->name(); |
|
217 | return this->m_plot->graph(graphIndex)->name(); | |
218 | } |
|
218 | } | |
219 | return ""; |
|
219 | return ""; | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 |
|
222 | |||
223 | void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) |
|
223 | void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) | |
224 | { |
|
224 | { | |
225 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double)) |
|
225 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double)) | |
226 | { |
|
226 | { | |
227 | QVector<double> _x(x.count()), _y(y.count()); |
|
227 | QVector<double> _x(x.count()), _y(y.count()); | |
228 | for(int i=0;i<x.count();i++) |
|
228 | for(int i=0;i<x.count();i++) | |
229 | { |
|
229 | { | |
230 | /*_x[i] = x.at(i).value<double>(); |
|
230 | /*_x[i] = x.at(i).value<double>(); | |
231 | _y[i] = y.at(i).value<double>();*/ |
|
231 | _y[i] = y.at(i).value<double>();*/ | |
232 | _x[i] = x.at(i).toDouble(); |
|
232 | _x[i] = x.at(i).toDouble(); | |
233 | _y[i] = y.at(i).toDouble(); |
|
233 | _y[i] = y.at(i).toDouble(); | |
234 | } |
|
234 | } | |
235 | this->m_plot->graph(graphIndex)->setData(_x,_y); |
|
235 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |
236 | } |
|
236 | } | |
237 | else |
|
237 | else | |
238 | { |
|
238 | { | |
239 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime)) |
|
239 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime)) | |
240 | { |
|
240 | { | |
241 | QVector<double> _x(x.count()), _y(y.count()); |
|
241 | QVector<double> _x(x.count()), _y(y.count()); | |
242 | for(int i=0;i<x.count();i++) |
|
242 | for(int i=0;i<x.count();i++) | |
243 | { |
|
243 | { | |
244 | /*_x[i] = x.at(i).value<double>(); |
|
244 | /*_x[i] = x.at(i).value<double>(); | |
245 | _y[i] = y.at(i).value<double>();*/ |
|
245 | _y[i] = y.at(i).value<double>();*/ | |
246 | _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); |
|
246 | _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); | |
247 | _y[i] = y.at(i).toDouble(); |
|
247 | _y[i] = y.at(i).toDouble(); | |
248 | } |
|
248 | } | |
249 | this->m_plot->graph(graphIndex)->setData(_x,_y); |
|
249 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |
250 | this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); |
|
250 | this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); | |
251 | this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz"); |
|
251 | this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz"); | |
252 |
|
252 | |||
253 | } |
|
253 | } | |
254 | } |
|
254 | } | |
255 | this->m_plot->replot(); |
|
255 | this->m_plot->replot(); | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot) |
|
258 | void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot) | |
259 | { |
|
259 | { | |
260 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) |
|
260 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) | |
261 | { |
|
261 | { | |
262 | this->m_plot->graph(graphIndex)->setData(data,copy); |
|
262 | this->m_plot->graph(graphIndex)->setData(data,copy); | |
263 | } |
|
263 | } | |
264 | if(replot) |
|
264 | if(replot) | |
265 | this->m_plot->replot(); |
|
265 | this->m_plot->replot(); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot) |
|
268 | void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot) | |
269 | { |
|
269 | { | |
270 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) |
|
270 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) | |
271 | { |
|
271 | { | |
272 | ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data); |
|
272 | ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data); | |
273 | } |
|
273 | } | |
274 | if(replot) |
|
274 | if(replot) | |
275 | this->m_plot->replot(); |
|
275 | this->m_plot->replot(); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) |
|
278 | void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) | |
279 | { |
|
279 | { | |
280 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) |
|
280 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) | |
281 | { |
|
281 | { | |
282 | QVector<double> _x(x.count()), _y(y.count()); |
|
282 | QVector<double> _x(x.count()), _y(y.count()); | |
283 | for(int i=0;i<x.count();i++) |
|
283 | for(int i=0;i<x.count();i++) | |
284 | { |
|
284 | { | |
285 | /*_x[i] = x.at(i).value<double>(); |
|
285 | /*_x[i] = x.at(i).value<double>(); | |
286 | _y[i] = y.at(i).value<double>();*/ |
|
286 | _y[i] = y.at(i).value<double>();*/ | |
287 | _x[i] = x.at(i).toDouble(); |
|
287 | _x[i] = x.at(i).toDouble(); | |
288 | _y[i] = y.at(i).toDouble(); |
|
288 | _y[i] = y.at(i).toDouble(); | |
289 | } |
|
289 | } | |
290 | this->m_plot->graph(graphIndex)->addData(_x,_y); |
|
290 | this->m_plot->graph(graphIndex)->addData(_x,_y); | |
291 | } |
|
291 | } | |
292 | this->m_plot->replot(); |
|
292 | this->m_plot->replot(); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y) |
|
295 | void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y) | |
296 | { |
|
296 | { | |
297 | if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double)) |
|
297 | if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double)) | |
298 | { |
|
298 | { | |
299 | this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble()); |
|
299 | this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble()); | |
300 | } |
|
300 | } | |
301 | this->m_plot->replot(); |
|
301 | this->m_plot->replot(); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen) |
|
304 | void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen) | |
305 | { |
|
305 | { | |
306 | if(graphIndex<this->m_plot->graphCount()) |
|
306 | if(graphIndex<this->m_plot->graphCount()) | |
307 | { |
|
307 | { | |
308 | this->m_plot->graph(graphIndex)->setPen(pen); |
|
308 | this->m_plot->graph(graphIndex)->setPen(pen); | |
309 | } |
|
309 | } | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | QPen SocExplorerPlot::getGraphPen(int graphIndex) |
|
312 | QPen SocExplorerPlot::getGraphPen(int graphIndex) | |
313 | { |
|
313 | { | |
314 | if(graphIndex<this->m_plot->graphCount()) |
|
314 | if(graphIndex<this->m_plot->graphCount()) | |
315 | { |
|
315 | { | |
316 | return this->m_plot->graph(graphIndex)->pen(); |
|
316 | return this->m_plot->graph(graphIndex)->pen(); | |
317 | } |
|
317 | } | |
318 | return this->m_plot->graph()->pen(); |
|
318 | return this->m_plot->graph()->pen(); | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 |
|
321 | |||
322 |
|
322 | |||
323 | void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle) |
|
323 | void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle) | |
324 | { |
|
324 | { | |
325 | if(graphIndex<this->m_plot->graphCount()) |
|
325 | if(graphIndex<this->m_plot->graphCount()) | |
326 | { |
|
326 | { | |
327 | if(!lineStyle.compare("none")) |
|
327 | if(!lineStyle.compare("none")) | |
328 | { |
|
328 | { | |
329 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); |
|
329 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); | |
330 | return; |
|
330 | return; | |
331 | } |
|
331 | } | |
332 | if(!lineStyle.compare("line")) |
|
332 | if(!lineStyle.compare("line")) | |
333 | { |
|
333 | { | |
334 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); |
|
334 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); | |
335 | return; |
|
335 | return; | |
336 | } |
|
336 | } | |
337 | if(!lineStyle.compare("stepleft")) |
|
337 | if(!lineStyle.compare("stepleft")) | |
338 | { |
|
338 | { | |
339 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); |
|
339 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); | |
340 | return; |
|
340 | return; | |
341 | } |
|
341 | } | |
342 | if(!lineStyle.compare("stepright")) |
|
342 | if(!lineStyle.compare("stepright")) | |
343 | { |
|
343 | { | |
344 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); |
|
344 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); | |
345 | return; |
|
345 | return; | |
346 | } |
|
346 | } | |
347 | if(!lineStyle.compare("stepcenter")) |
|
347 | if(!lineStyle.compare("stepcenter")) | |
348 | { |
|
348 | { | |
349 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); |
|
349 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); | |
350 | return; |
|
350 | return; | |
351 | } |
|
351 | } | |
352 | if(!lineStyle.compare("impulse")) |
|
352 | if(!lineStyle.compare("impulse")) | |
353 | { |
|
353 | { | |
354 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); |
|
354 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); | |
355 | return; |
|
355 | return; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 |
|
358 | |||
359 | } |
|
359 | } | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle) |
|
362 | void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle) | |
363 | { |
|
363 | { | |
364 | if(graphIndex<this->m_plot->graphCount()) |
|
364 | if(graphIndex<this->m_plot->graphCount()) | |
365 | { |
|
365 | { | |
366 | if(!scatterStyle.compare("none")) |
|
366 | if(!scatterStyle.compare("none")) | |
367 | { |
|
367 | { | |
368 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); |
|
368 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); | |
369 | return; |
|
369 | return; | |
370 | } |
|
370 | } | |
371 | if(!scatterStyle.compare("dot")) |
|
371 | if(!scatterStyle.compare("dot")) | |
372 | { |
|
372 | { | |
373 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); |
|
373 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); | |
374 | return; |
|
374 | return; | |
375 | } |
|
375 | } | |
376 | if(!scatterStyle.compare("cross")) |
|
376 | if(!scatterStyle.compare("cross")) | |
377 | { |
|
377 | { | |
378 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); |
|
378 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); | |
379 | return; |
|
379 | return; | |
380 | } |
|
380 | } | |
381 | if(!scatterStyle.compare("plus")) |
|
381 | if(!scatterStyle.compare("plus")) | |
382 | { |
|
382 | { | |
383 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); |
|
383 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); | |
384 | return; |
|
384 | return; | |
385 | } |
|
385 | } | |
386 | if(!scatterStyle.compare("circle")) |
|
386 | if(!scatterStyle.compare("circle")) | |
387 | { |
|
387 | { | |
388 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); |
|
388 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); | |
389 | return; |
|
389 | return; | |
390 | } |
|
390 | } | |
391 | if(!scatterStyle.compare("disc")) |
|
391 | if(!scatterStyle.compare("disc")) | |
392 | { |
|
392 | { | |
393 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); |
|
393 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); | |
394 | return; |
|
394 | return; | |
395 | } |
|
395 | } | |
396 | if(!scatterStyle.compare("square")) |
|
396 | if(!scatterStyle.compare("square")) | |
397 | { |
|
397 | { | |
398 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); |
|
398 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); | |
399 | return; |
|
399 | return; | |
400 | } |
|
400 | } | |
401 | if(!scatterStyle.compare("diamond")) |
|
401 | if(!scatterStyle.compare("diamond")) | |
402 | { |
|
402 | { | |
403 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); |
|
403 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); | |
404 | return; |
|
404 | return; | |
405 | } |
|
405 | } | |
406 | if(!scatterStyle.compare("star")) |
|
406 | if(!scatterStyle.compare("star")) | |
407 | { |
|
407 | { | |
408 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); |
|
408 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); | |
409 | return; |
|
409 | return; | |
410 | } |
|
410 | } | |
411 | if(!scatterStyle.compare("triangle")) |
|
411 | if(!scatterStyle.compare("triangle")) | |
412 | { |
|
412 | { | |
413 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); |
|
413 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); | |
414 | return; |
|
414 | return; | |
415 | } |
|
415 | } | |
416 | if(!scatterStyle.compare("invertedtriangle")) |
|
416 | if(!scatterStyle.compare("invertedtriangle")) | |
417 | { |
|
417 | { | |
418 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); |
|
418 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); | |
419 | return; |
|
419 | return; | |
420 | } |
|
420 | } | |
421 | if(!scatterStyle.compare("crosssquare")) |
|
421 | if(!scatterStyle.compare("crosssquare")) | |
422 | { |
|
422 | { | |
423 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); |
|
423 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); | |
424 | return; |
|
424 | return; | |
425 | } |
|
425 | } | |
426 | if(!scatterStyle.compare("plussquare")) |
|
426 | if(!scatterStyle.compare("plussquare")) | |
427 | { |
|
427 | { | |
428 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); |
|
428 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); | |
429 | return; |
|
429 | return; | |
430 | } |
|
430 | } | |
431 | if(!scatterStyle.compare("crosscircle")) |
|
431 | if(!scatterStyle.compare("crosscircle")) | |
432 | { |
|
432 | { | |
433 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); |
|
433 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); | |
434 | return; |
|
434 | return; | |
435 | } |
|
435 | } | |
436 | if(!scatterStyle.compare("pluscircle")) |
|
436 | if(!scatterStyle.compare("pluscircle")) | |
437 | { |
|
437 | { | |
438 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); |
|
438 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); | |
439 | return; |
|
439 | return; | |
440 | } |
|
440 | } | |
441 | if(!scatterStyle.compare("peace")) |
|
441 | if(!scatterStyle.compare("peace")) | |
442 | { |
|
442 | { | |
443 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); |
|
443 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); | |
444 | return; |
|
444 | return; | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | } |
|
447 | } | |
448 | } |
|
448 | } | |
449 |
|
449 | |||
450 | void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type) |
|
450 | void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type) | |
451 | { |
|
451 | { | |
452 | this->m_plot->xAxis->setTickLabelType(type); |
|
452 | this->m_plot->xAxis->setTickLabelType(type); | |
453 | } |
|
453 | } | |
454 |
|
454 | |||
455 | void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format) |
|
455 | void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format) | |
456 | { |
|
456 | { | |
457 | this->m_plot->xAxis->setDateTimeFormat(format); |
|
457 | this->m_plot->xAxis->setDateTimeFormat(format); | |
458 | } |
|
458 | } | |
459 |
|
459 | |||
460 |
|
460 | |||
461 |
|
461 | |||
462 |
|
462 | |||
463 |
|
463 | |||
464 | void SocExplorerPlot::keyPressEvent(QKeyEvent * event) |
|
464 | void SocExplorerPlot::keyPressEvent(QKeyEvent * event) | |
465 | { |
|
465 | { | |
466 | switch(event->key()) |
|
466 | switch(event->key()) | |
467 | { |
|
467 | { | |
468 | case Qt::Key_Control: |
|
468 | case Qt::Key_Control: | |
469 | this->ctrl_hold = true; |
|
469 | this->ctrl_hold = true; | |
470 | setCursor(Qt::CrossCursor); |
|
470 | setCursor(Qt::CrossCursor); | |
471 | break; |
|
471 | break; | |
472 | case Qt::Key_Shift: |
|
472 | case Qt::Key_Shift: | |
473 | this->shift_hold = true; |
|
473 | this->shift_hold = true; | |
474 | break; |
|
474 | break; | |
475 | case Qt::Key_M: |
|
475 | case Qt::Key_M: | |
476 | this->rescaleAxis(); |
|
476 | this->rescaleAxis(); | |
477 | break; |
|
477 | break; | |
478 | case Qt::Key_Left: |
|
478 | case Qt::Key_Left: | |
479 | if(!ctrl_hold) |
|
479 | if(!ctrl_hold) | |
480 | { |
|
480 | { | |
481 | move(-0.1,Qt::Horizontal); |
|
481 | move(-0.1,Qt::Horizontal); | |
482 | } |
|
482 | } | |
483 | else |
|
483 | else | |
484 | { |
|
484 | { | |
485 | zoom(2,this->width()/2,Qt::Horizontal); |
|
485 | zoom(2,this->width()/2,Qt::Horizontal); | |
486 | } |
|
486 | } | |
487 | break; |
|
487 | break; | |
488 | case Qt::Key_Right: |
|
488 | case Qt::Key_Right: | |
489 | if(!ctrl_hold) |
|
489 | if(!ctrl_hold) | |
490 | { |
|
490 | { | |
491 | move(0.1,Qt::Horizontal); |
|
491 | move(0.1,Qt::Horizontal); | |
492 | } |
|
492 | } | |
493 | else |
|
493 | else | |
494 | { |
|
494 | { | |
495 | zoom(0.5,this->width()/2,Qt::Horizontal); |
|
495 | zoom(0.5,this->width()/2,Qt::Horizontal); | |
496 | } |
|
496 | } | |
497 | break; |
|
497 | break; | |
498 | case Qt::Key_Up: |
|
498 | case Qt::Key_Up: | |
499 | if(!ctrl_hold) |
|
499 | if(!ctrl_hold) | |
500 | { |
|
500 | { | |
501 | move(0.1,Qt::Vertical); |
|
501 | move(0.1,Qt::Vertical); | |
502 | } |
|
502 | } | |
503 | else |
|
503 | else | |
504 | { |
|
504 | { | |
505 | zoom(0.5,this->height()/2,Qt::Vertical); |
|
505 | zoom(0.5,this->height()/2,Qt::Vertical); | |
506 | } |
|
506 | } | |
507 | break; |
|
507 | break; | |
508 | case Qt::Key_Down: |
|
508 | case Qt::Key_Down: | |
509 | if(!ctrl_hold) |
|
509 | if(!ctrl_hold) | |
510 | { |
|
510 | { | |
511 | move(-0.1,Qt::Vertical); |
|
511 | move(-0.1,Qt::Vertical); | |
512 | } |
|
512 | } | |
513 | else |
|
513 | else | |
514 | { |
|
514 | { | |
515 | zoom(2,this->height()/2,Qt::Vertical); |
|
515 | zoom(2,this->height()/2,Qt::Vertical); | |
516 | } |
|
516 | } | |
517 | break; |
|
517 | break; | |
518 | default: |
|
518 | default: | |
519 | QWidget::keyPressEvent(event); |
|
519 | QWidget::keyPressEvent(event); | |
520 | break; |
|
520 | break; | |
521 | } |
|
521 | } | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) |
|
524 | void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) | |
525 | { |
|
525 | { | |
526 | switch(event->key()) |
|
526 | switch(event->key()) | |
527 | { |
|
527 | { | |
528 | case Qt::Key_Control: |
|
528 | case Qt::Key_Control: | |
529 | event->accept(); |
|
529 | event->accept(); | |
530 | this->ctrl_hold = false; |
|
530 | this->ctrl_hold = false; | |
531 | break; |
|
531 | break; | |
532 | case Qt::Key_Shift: |
|
532 | case Qt::Key_Shift: | |
533 | event->accept(); |
|
533 | event->accept(); | |
534 | this->shift_hold = false; |
|
534 | this->shift_hold = false; | |
535 | break; |
|
535 | break; | |
536 | default: |
|
536 | default: | |
537 | QWidget::keyReleaseEvent(event); |
|
537 | QWidget::keyReleaseEvent(event); | |
538 | break; |
|
538 | break; | |
539 | } |
|
539 | } | |
540 | setCursor(Qt::ArrowCursor); |
|
540 | setCursor(Qt::ArrowCursor); | |
541 | } |
|
541 | } | |
542 |
|
542 | |||
543 | void SocExplorerPlot::wheelEvent(QWheelEvent * event) |
|
543 | void SocExplorerPlot::wheelEvent(QWheelEvent * event) | |
544 | { |
|
544 | { | |
545 | double factor; |
|
545 | double factor; | |
546 | double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually |
|
546 | double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually | |
547 | if(ctrl_hold) |
|
547 | if(ctrl_hold) | |
548 | { |
|
548 | { | |
549 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) |
|
549 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) | |
550 | { |
|
550 | { | |
551 | setCursor(Qt::SizeVerCursor); |
|
551 | setCursor(Qt::SizeVerCursor); | |
552 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); |
|
552 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); | |
553 | zoom(factor,event->pos().y(),Qt::Vertical); |
|
553 | zoom(factor,event->pos().y(),Qt::Vertical); | |
554 | } |
|
554 | } | |
555 | QWidget::wheelEvent(event); |
|
555 | QWidget::wheelEvent(event); | |
556 | return; |
|
556 | return; | |
557 | } |
|
557 | } | |
558 | if(shift_hold) |
|
558 | if(shift_hold) | |
559 | { |
|
559 | { | |
560 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) |
|
560 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) | |
561 | { |
|
561 | { | |
562 | setCursor(Qt::SizeHorCursor); |
|
562 | setCursor(Qt::SizeHorCursor); | |
563 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); |
|
563 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); | |
564 | zoom(factor,event->pos().x(),Qt::Horizontal); |
|
564 | zoom(factor,event->pos().x(),Qt::Horizontal); | |
565 | } |
|
565 | } | |
566 | QWidget::wheelEvent(event); |
|
566 | QWidget::wheelEvent(event); | |
567 | return; |
|
567 | return; | |
568 | } |
|
568 | } | |
569 |
move(wheelSteps |
|
569 | move(wheelSteps,Qt::Horizontal); | |
570 | QWidget::wheelEvent(event); |
|
570 | QWidget::wheelEvent(event); | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 |
|
573 | |||
574 |
|
574 | |||
575 |
|
575 | |||
576 | void SocExplorerPlot::mousePressEvent(QMouseEvent *event) |
|
576 | void SocExplorerPlot::mousePressEvent(QMouseEvent *event) | |
577 | { |
|
577 | { | |
578 | if(event->button()==Qt::LeftButton) |
|
578 | if(event->button()==Qt::LeftButton) | |
579 | { |
|
579 | { | |
580 | if(ctrl_hold) |
|
580 | if(ctrl_hold) | |
581 | { |
|
581 | { | |
582 | setCursor(Qt::CrossCursor); |
|
582 | setCursor(Qt::CrossCursor); | |
583 | mOrigin = event->pos(); |
|
583 | mOrigin = event->pos(); | |
584 | mRubberBand->setGeometry(QRect(mOrigin, QSize())); |
|
584 | mRubberBand->setGeometry(QRect(mOrigin, QSize())); | |
585 | mRubberBand->show(); |
|
585 | mRubberBand->show(); | |
586 | } |
|
586 | } | |
587 | else |
|
587 | else | |
588 | { |
|
588 | { | |
589 | setCursor(Qt::ClosedHandCursor); |
|
589 | setCursor(Qt::ClosedHandCursor); | |
590 | mDragStart = event->pos(); |
|
590 | mDragStart = event->pos(); | |
591 | this->mouse_hold = true; |
|
591 | this->mouse_hold = true; | |
592 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); |
|
592 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); | |
593 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); |
|
593 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); | |
594 | } |
|
594 | } | |
595 | } |
|
595 | } | |
596 | QWidget::mousePressEvent(event); |
|
596 | QWidget::mousePressEvent(event); | |
597 | } |
|
597 | } | |
598 |
|
598 | |||
599 | void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event) |
|
599 | void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event) | |
600 | { |
|
600 | { | |
601 | if(event->button()==Qt::LeftButton) |
|
601 | if(event->button()==Qt::LeftButton) | |
602 | { |
|
602 | { | |
603 | this->mouse_hold = false; |
|
603 | this->mouse_hold = false; | |
604 | } |
|
604 | } | |
605 | if (mRubberBand->isVisible()) |
|
605 | if (mRubberBand->isVisible()) | |
606 | { |
|
606 | { | |
607 | const QRect & zoomRect = mRubberBand->geometry(); |
|
607 | const QRect & zoomRect = mRubberBand->geometry(); | |
608 | int xp1, yp1, xp2, yp2; |
|
608 | int xp1, yp1, xp2, yp2; | |
609 | zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2); |
|
609 | zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2); | |
610 | double x1 = this->m_plot->xAxis->pixelToCoord(xp1); |
|
610 | double x1 = this->m_plot->xAxis->pixelToCoord(xp1); | |
611 | double x2 = this->m_plot->xAxis->pixelToCoord(xp2); |
|
611 | double x2 = this->m_plot->xAxis->pixelToCoord(xp2); | |
612 | double y1 = this->m_plot->yAxis->pixelToCoord(yp1); |
|
612 | double y1 = this->m_plot->yAxis->pixelToCoord(yp1); | |
613 | double y2 = this->m_plot->yAxis->pixelToCoord(yp2); |
|
613 | double y2 = this->m_plot->yAxis->pixelToCoord(yp2); | |
614 |
|
614 | |||
615 | this->m_plot->xAxis->setRange(x1, x2); |
|
615 | this->m_plot->xAxis->setRange(x1, x2); | |
616 | this->m_plot->yAxis->setRange(y1, y2); |
|
616 | this->m_plot->yAxis->setRange(y1, y2); | |
617 |
|
617 | |||
618 | mRubberBand->hide(); |
|
618 | mRubberBand->hide(); | |
619 | this->m_plot->replot(); |
|
619 | this->m_plot->replot(); | |
620 | } |
|
620 | } | |
621 | setCursor(Qt::ArrowCursor); |
|
621 | setCursor(Qt::ArrowCursor); | |
622 | QWidget::mouseReleaseEvent(event); |
|
622 | QWidget::mouseReleaseEvent(event); | |
623 | } |
|
623 | } | |
624 |
|
624 | |||
625 | void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation) |
|
625 | void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation) | |
626 | { |
|
626 | { | |
627 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation); |
|
627 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation); | |
628 | axis->scaleRange(factor, axis->pixelToCoord(center)); |
|
628 | axis->scaleRange(factor, axis->pixelToCoord(center)); | |
629 | this->m_plot->replot(); |
|
629 | this->m_plot->replot(); | |
630 | } |
|
630 | } | |
631 |
|
631 | |||
632 | void SocExplorerPlot::move(double factor, Qt::Orientation orientation) |
|
632 | void SocExplorerPlot::move(double factor, Qt::Orientation orientation) | |
633 | { |
|
633 | { | |
634 | QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation); |
|
634 | QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation); | |
635 | double rg = (axis->range().upper - axis->range().lower)*(factor); |
|
635 | // double rg = (axis->range().upper - axis->range().lower)*(factor); | |
636 | axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); |
|
636 | // axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | |
637 | this->m_plot->replot(); |
|
637 | double rg =0.0; | |
|
638 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); | |||
|
639 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); | |||
|
640 | if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) | |||
|
641 | { | |||
|
642 | rg = (axis->range().upper - axis->range().lower)*(factor/10); | |||
|
643 | axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | |||
|
644 | } | |||
|
645 | else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) | |||
|
646 | { | |||
|
647 | // rg = (axis->range().upper / axis->range().lower)*(factor/100); | |||
|
648 | int start,stop; | |||
|
649 | double diff; | |||
|
650 | if(factor>0.0) | |||
|
651 | { | |||
|
652 | stop =this->width()*factor/10; | |||
|
653 | start = 2*this->width()*factor/10; | |||
|
654 | } | |||
|
655 | if(factor<0.0) | |||
|
656 | { | |||
|
657 | factor*=-1.0; | |||
|
658 | start =this->width()*factor/10; | |||
|
659 | stop = 2*this->width()*factor/10; | |||
|
660 | } | |||
|
661 | diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop); | |||
|
662 | axis->setRange(this->m_plot->axisRect()->rangeDragAxis(orientation)->range().lower*diff, this->m_plot->axisRect()->rangeDragAxis(orientation)->range().upper*diff); | |||
|
663 | } | |||
|
664 | this->m_plot->replot(); | |||
638 | } |
|
665 | } | |
639 |
|
666 | |||
640 |
|
667 | |||
641 | void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event) |
|
668 | void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event) | |
642 | { |
|
669 | { | |
643 | if(mouse_hold) |
|
670 | if(mouse_hold) | |
644 | { |
|
671 | { | |
645 | QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); |
|
672 | QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |
646 | QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical); |
|
673 | QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical); | |
647 |
double diff = |
|
674 | // double diff = rangeDragHorzAxis->pixelToCoord(mDragStart.x()) / rangeDragHorzAxis->pixelToCoord(event->pos().x()); | |
648 |
|
|
675 | // rangeDragHorzAxis->setRange(mDragStartHorzRange.lower*diff, mDragStartHorzRange.upper*diff); | |
649 | diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y()); |
|
676 | double diff=0; | |
650 | Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff); |
|
677 | if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) | |
651 | this->m_plot->replot(); |
|
678 | { | |
|
679 | diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x()); | |||
|
680 | Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff); | |||
|
681 | } | |||
|
682 | else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) | |||
|
683 | { | |||
|
684 | diff = Haxis->pixelToCoord(mDragStart.x()) / Haxis->pixelToCoord(event->pos().x()); | |||
|
685 | Haxis->setRange(DragStartHorzRange.lower*diff, DragStartHorzRange.upper*diff); | |||
|
686 | } | |||
|
687 | if(this->m_plot->yAxis->scaleType() == QCPAxis::stLinear) | |||
|
688 | { | |||
|
689 | diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y()); | |||
|
690 | Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff); | |||
|
691 | } | |||
|
692 | else if(this->m_plot->yAxis->scaleType() == QCPAxis::stLogarithmic) | |||
|
693 | { | |||
|
694 | diff = Vaxis->pixelToCoord(mDragStart.y()) / Vaxis->pixelToCoord(event->pos().y()); | |||
|
695 | Vaxis->setRange(DragStartVertRange.lower*diff, DragStartVertRange.upper*diff); | |||
|
696 | } | |||
|
697 | this->m_plot->replot(); | |||
652 | } |
|
698 | } | |
653 | if (mRubberBand->isVisible()) |
|
699 | if (mRubberBand->isVisible()) | |
654 | { |
|
700 | { | |
655 | mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); |
|
701 | mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); | |
656 | } |
|
702 | } | |
657 | QWidget::mouseMoveEvent(event); |
|
703 | QWidget::mouseMoveEvent(event); | |
658 | } |
|
704 | } | |
659 |
|
705 | |||
660 |
|
706 | |||
661 |
|
707 | |||
662 |
|
708 | |||
663 |
|
709 | |||
664 |
|
710 | |||
665 |
|
711 | |||
666 |
|
712 | |||
667 |
|
713 | |||
668 |
|
714 | |||
669 |
|
715 |
General Comments 0
You need to be logged in to leave comments.
Login now