@@ -1,110 +1,110 | |||
|
1 | 1 | #------------------------------------------------- |
|
2 | 2 | # |
|
3 | 3 | # Project created by QtCreator 2015-01-07T02:41:29 |
|
4 | 4 | # |
|
5 | 5 | #------------------------------------------------- |
|
6 | 6 | |
|
7 | 7 | QT += core gui network xml svg |
|
8 | 8 | CONFIG += pythonqt |
|
9 | 9 | |
|
10 | 10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport |
|
11 | 11 | |
|
12 | 12 | DESTDIR =./bin |
|
13 | 13 | |
|
14 | 14 | TARGET = QLop |
|
15 | 15 | TEMPLATE = app |
|
16 | 16 | |
|
17 | LIBS+=-lfftw3 | |
|
17 | LIBS+=-lfftw3_threads -lfftw3 | |
|
18 | 18 | |
|
19 | 19 | INCLUDEPATH += src/QCustomPlot \ |
|
20 | 20 | src src/Cassini \ |
|
21 | 21 | src/Core src/Core/Widgets \ |
|
22 | 22 | src/Core/Widgets/PyWdgt |
|
23 | 23 | |
|
24 | 24 | QMAKE_CXXFLAGS_RELEASE += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx |
|
25 | 25 | QMAKE_LFLAGS_RELEASE += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx |
|
26 | 26 | |
|
27 | 27 | QMAKE_CXXFLAGS_DEBUG += -O0 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx |
|
28 | 28 | QMAKE_LFLAGS_DEBUG += -O0 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | SOURCES += src/main.cpp\ |
|
32 | 32 | src/mainwindow.cpp \ |
|
33 | 33 | src/SocExplorerPlot.cpp \ |
|
34 | 34 | src/QCustomPlot/qcustomplot.cpp \ |
|
35 | 35 | src/toolbarcontainer.cpp \ |
|
36 | 36 | src/Core/abstractfileloader.cpp \ |
|
37 | 37 | src/Core/filedownloader.cpp \ |
|
38 | 38 | src/Core/filedownloadertask.cpp \ |
|
39 | 39 | src/Core/Widgets/downloadhistory.cpp \ |
|
40 | 40 | src/Core/Widgets/downloadhistoryelement.cpp \ |
|
41 | 41 | src/Core/qlopservice.cpp \ |
|
42 | 42 | src/Cassini/expxmldownloader.cpp \ |
|
43 | 43 | src/Cassini/cassinidatadownloader.cpp \ |
|
44 | 44 | src/Cassini/cassinidatafile.cpp \ |
|
45 | 45 | src/Cassini/cassiniindexfile.cpp \ |
|
46 | 46 | src/Cassini/cassiniindexfileviewer.cpp \ |
|
47 | 47 | src/Cassini/cassinitools.cpp \ |
|
48 | 48 | src/Cassini/cassinitoolsgui.cpp \ |
|
49 | 49 | src/Core/Widgets/qlopplots.cpp \ |
|
50 | 50 | src/Core/qlopdata.cpp \ |
|
51 | 51 | src/Core/Widgets/PyWdgt/pythonconsole.cpp \ |
|
52 | 52 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.cpp \ |
|
53 | 53 | src/QCustomPlot/qcpdocumentobject.cpp \ |
|
54 | 54 | src/Core/Widgets/filebrowser.cpp \ |
|
55 | 55 | src/Core/Widgets/filesystemmodel.cpp \ |
|
56 | 56 | src/Core/Widgets/qcustomplotvect.cpp |
|
57 | 57 | |
|
58 | 58 | HEADERS += src/mainwindow.h \ |
|
59 | 59 | src/SocExplorerPlot.h \ |
|
60 | 60 | src/QCustomPlot/qcustomplot.h \ |
|
61 | 61 | src/toolbarcontainer.h \ |
|
62 | 62 | src/Core/abstractfileloader.h \ |
|
63 | 63 | src/Core/filedownloader.h \ |
|
64 | 64 | src/Core/filedownloadertask.h \ |
|
65 | 65 | src/Core/Widgets/downloadhistory.h \ |
|
66 | 66 | src/Core/Widgets/downloadhistoryelement.h \ |
|
67 | 67 | src/Core/qlopservice.h \ |
|
68 | 68 | src/Cassini/expxmldownloader.h \ |
|
69 | 69 | src/Cassini/cassinidatadownloader.h \ |
|
70 | 70 | src/Cassini/cassinidatafile.h \ |
|
71 | 71 | src/Cassini/cassiniindexfile.h \ |
|
72 | 72 | src/Cassini/cassiniindexfileviewer.h \ |
|
73 | 73 | src/Cassini/cassinitools.h \ |
|
74 | 74 | src/Cassini/cassinitoolsgui.h \ |
|
75 | 75 | src/Core/Widgets/qlopplots.h \ |
|
76 | 76 | src/Core/qlopdata.h \ |
|
77 | 77 | src/Core/Widgets/PyWdgt/pythonconsole.h \ |
|
78 | 78 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.h \ |
|
79 | 79 | src/Core/qlop.h \ |
|
80 | 80 | src/Core/pyqlop.h \ |
|
81 | 81 | src/QCustomPlot/qcpdocumentobject.h \ |
|
82 | 82 | src/Core/Widgets/filebrowser.h \ |
|
83 | 83 | src/Core/Widgets/filesystemmodel.h \ |
|
84 | 84 | src/Core/Widgets/qcustomplotvect.h |
|
85 | 85 | |
|
86 | 86 | FORMS += src/mainwindow.ui \ |
|
87 | 87 | src/Core/Widgets/downloadhistory.ui \ |
|
88 | 88 | src/Core/Widgets/downloadhistoryelement.ui \ |
|
89 | 89 | src/Cassini/cassinidatadownloader.ui \ |
|
90 | 90 | src/Cassini/cassiniindexfileviewer.ui \ |
|
91 | 91 | src/Cassini/cassinitoolsgui.ui \ |
|
92 | 92 | src/Core/Widgets/filebrowser.ui |
|
93 | 93 | |
|
94 | 94 | RESOURCES += \ |
|
95 | 95 | resources/qlop.qrc |
|
96 | 96 | |
|
97 | 97 | include(src/Core/Widgets/NicePyConsole/NicePyConsole.pri) |
|
98 | 98 | include(src/Core/pythonQtOut/generated_cpp/PyQLop/PyQLop.pri) |
|
99 | 99 | |
|
100 | 100 | win32 { |
|
101 | 101 | DEFINES += WIN32 |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | unix { |
|
105 | 105 | DEFINES += UNIX |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | DISTFILES += \ |
|
109 | 109 | src/Core/pythongenerator.sh \ |
|
110 | 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 | 23 | #include "cassinidatadownloader.h" |
|
2 | 24 | #include "ui_cassinidatadownloader.h" |
|
3 | 25 | #include <filedownloader.h> |
|
4 | 26 | #include <QDir> |
|
5 | 27 | #include <QFileDialog> |
|
6 | 28 | #include <QFile> |
|
7 | 29 | |
|
8 | 30 | CassiniDataDownloader::CassiniDataDownloader(QWidget *parent) : |
|
9 | 31 | QWidget(parent), |
|
10 | 32 | ui(new Ui::CassiniDataDownloader) |
|
11 | 33 | { |
|
12 | 34 | ui->setupUi(this); |
|
13 | 35 | m_xmlLoader = new ExpXmlDownLoader(); |
|
14 | 36 | connect(this->ui->calendar,SIGNAL(activated(QDate)),this,SLOT(downloadData(QDate))); |
|
15 | 37 | connect(this->ui->LoadXmlFileQpb,SIGNAL(clicked()),this,SLOT(loadXmlFile())); |
|
16 | 38 | } |
|
17 | 39 | |
|
18 | 40 | CassiniDataDownloader::~CassiniDataDownloader() |
|
19 | 41 | { |
|
20 | 42 | delete ui; |
|
21 | 43 | delete m_xmlLoader; |
|
22 | 44 | } |
|
23 | 45 | |
|
24 | 46 | void CassiniDataDownloader::changeEvent(QEvent *e) |
|
25 | 47 | { |
|
26 | 48 | QWidget::changeEvent(e); |
|
27 | 49 | switch (e->type()) { |
|
28 | 50 | case QEvent::LanguageChange: |
|
29 | 51 | ui->retranslateUi(this); |
|
30 | 52 | break; |
|
31 | 53 | default: |
|
32 | 54 | break; |
|
33 | 55 | } |
|
34 | 56 | } |
|
35 | 57 | |
|
36 | 58 | void CassiniDataDownloader::downloadData(const QDate &date) |
|
37 | 59 | { |
|
38 | 60 | QDate tmpDate; |
|
39 | 61 | QStringList months=QStringList()<< "JAN" << "FEB" << "MAR" << "APR" << "MAY" << "JUN" << "JUI" << "AUG" << "SEP" << "OCT" << "NOV" << "DEC"; |
|
40 | 62 | tmpDate.setDate(date.year(),date.month(),1); |
|
41 | 63 | int firstDayOfMonth=tmpDate.dayOfYear(); |
|
42 | 64 | tmpDate.setDate(tmpDate.year(),tmpDate.month(),tmpDate.daysInMonth()); |
|
43 | 65 | int lastDayOfMonth=tmpDate.dayOfYear(); |
|
44 | 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 | 67 | + QString("%1").arg(date.year()) +"/" + QString("%1_%2_").arg(firstDayOfMonth,3).arg(lastDayOfMonth,3).replace(' ','0') \ |
|
46 | 68 | + months.at(date.month()-1) + "/" ; |
|
47 | 69 | qDebug()<<link; |
|
48 | 70 | QString dataFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.TAB"; |
|
49 | 71 | QString headerFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.LBL"; |
|
50 | 72 | // "_FGM_KRTP.TAB" |
|
51 | 73 | FileDownloader::downloadFile(link+dataFileName,QDir::homePath() +"/Téléchargements/"+dataFileName); |
|
52 | 74 | FileDownloader::downloadFile(link+headerFileName,QDir::homePath() +"/Téléchargements/"+headerFileName); |
|
53 | 75 | } |
|
54 | 76 | |
|
55 | 77 | void CassiniDataDownloader::loadXmlFile() |
|
56 | 78 | { |
|
57 | 79 | QString file=QFileDialog::getOpenFileName(); |
|
58 | 80 | if(QFile::exists(file)) |
|
59 | 81 | { |
|
60 | 82 | if(m_xmlLoader->parseXml(file)) |
|
61 | 83 | { |
|
62 | 84 | QList<QDate> daysToDl = m_xmlLoader->daysToDownload(); |
|
63 | 85 | for(int i=0;i<daysToDl.count();i++) |
|
64 | 86 | { |
|
65 | 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 | 23 | #ifndef CASSINIDATADOWNLOADER_H |
|
2 | 24 | #define CASSINIDATADOWNLOADER_H |
|
3 | 25 | |
|
4 | 26 | #include <QWidget> |
|
5 | 27 | #include <QDate> |
|
6 | 28 | #include <expxmldownloader.h> |
|
7 | 29 | |
|
8 | 30 | namespace Ui { |
|
9 | 31 | class CassiniDataDownloader; |
|
10 | 32 | } |
|
11 | 33 | |
|
12 | 34 | class CassiniDataDownloader : public QWidget |
|
13 | 35 | { |
|
14 | 36 | Q_OBJECT |
|
15 | 37 | |
|
16 | 38 | public: |
|
17 | 39 | explicit CassiniDataDownloader(QWidget *parent = 0); |
|
18 | 40 | ~CassiniDataDownloader(); |
|
19 | 41 | |
|
20 | 42 | protected: |
|
21 | 43 | void changeEvent(QEvent *e); |
|
22 | 44 | private slots: |
|
23 | 45 | void downloadData(const QDate & date ); |
|
24 | 46 | void loadXmlFile(); |
|
25 | 47 | private: |
|
26 | 48 | Ui::CassiniDataDownloader *ui; |
|
27 | 49 | ExpXmlDownLoader* m_xmlLoader; |
|
28 | 50 | }; |
|
29 | 51 | |
|
30 | 52 | #endif // CASSINIDATADOWNLOADER_H |
@@ -1,306 +1,306 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the QLop Software |
|
3 | 3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 2 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | ----------------------------------------------------------------------------*/ |
|
22 | 22 | #include "cassinidatafile.h" |
|
23 | 23 | #include <QFile> |
|
24 | 24 | #include <stdio.h> |
|
25 | 25 | #include <QDateTime> |
|
26 | 26 | #include <QVector> |
|
27 | 27 | #include <QProgressDialog> |
|
28 | 28 | #include <omp.h> |
|
29 | 29 | #include <QTimer> |
|
30 | 30 | #include <QElapsedTimer> |
|
31 | 31 | #include <sys/time.h> |
|
32 | 32 | |
|
33 | 33 | CassiniDataFile::CassiniDataFile(QObject *parent) : AbstractFileLoader(parent) |
|
34 | 34 | { |
|
35 | 35 | |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | CassiniDataFile::~CassiniDataFile() |
|
39 | 39 | { |
|
40 | 40 | |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | void CassiniDataFile::parseFile(const QString &fileName) |
|
44 | 44 | { |
|
45 | 45 | this->fileName = fileName; |
|
46 | 46 | m_Write = false; |
|
47 | 47 | this->start(); |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void CassiniDataFile::saveFile(const QString &fileName, QLopDataList data) |
|
51 | 51 | { |
|
52 | 52 | this->fileName = fileName; |
|
53 | 53 | m_Write = true; |
|
54 | 54 | m_data = data; |
|
55 | 55 | this->start(); |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | inline double __decodeVal(int ofset,unsigned char* data) |
|
59 | 59 | { |
|
60 | 60 | if(data[ofset]=='-') |
|
61 | 61 | return -0.001 * (double)( |
|
62 | 62 | (10000 * (int)(data[ofset+1] & 0x0F)) |
|
63 | 63 | + (1000 * (int)(data[ofset+2] & 0x0F)) |
|
64 | 64 | + (100 * (int)(data[ofset+4] & 0x0F)) |
|
65 | 65 | + (10 * (int)(data[ofset+5] & 0x0F)) |
|
66 | 66 | + ( (int)(data[ofset+6] & 0x0F)) |
|
67 | 67 | ); |
|
68 | 68 | else |
|
69 | 69 | { |
|
70 | 70 | if(data[ofset+1]=='-') |
|
71 | 71 | { |
|
72 | 72 | return -0.001 * (double)( |
|
73 | 73 | (1000 * (int)(data[ofset+2] & 0x0F)) |
|
74 | 74 | + (100 * (int)(data[ofset+4] & 0x0F)) |
|
75 | 75 | + (10 * (int)(data[ofset+5] & 0x0F)) |
|
76 | 76 | + ( (int)(data[ofset+6] & 0x0F)) |
|
77 | 77 | ); |
|
78 | 78 | } |
|
79 | 79 | else |
|
80 | 80 | { |
|
81 | 81 | return 0.001 * (double)( |
|
82 | 82 | (10000 * (int)(data[ofset+1] & 0x0F)) |
|
83 | 83 | + (1000 * (int)(data[ofset+2] & 0x0F)) |
|
84 | 84 | + (100 * (int)(data[ofset+4] & 0x0F)) |
|
85 | 85 | + (10 * (int)(data[ofset+5] & 0x0F)) |
|
86 | 86 | + ( (int)(data[ofset+6] & 0x0F)) |
|
87 | 87 | ); |
|
88 | 88 | } |
|
89 | 89 | } |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | inline QDate __decodeDate(int ofset,unsigned char* data) |
|
93 | 93 | { |
|
94 | 94 | int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F)); |
|
95 | 95 | int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F)); |
|
96 | 96 | int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F)); |
|
97 | 97 | return QDate(y,m,d); |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | inline QTime __decodeTime(int ofset,unsigned char* data) |
|
101 | 101 | { |
|
102 | 102 | int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F)); |
|
103 | 103 | int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F)); |
|
104 | 104 | int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F)); |
|
105 | 105 | int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F)); |
|
106 | 106 | return QTime(h,m,s,ms); |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | double __decodeTimeFromEpochMs(int ofset,unsigned char* data) |
|
110 | 110 | { |
|
111 | 111 | struct tm t; |
|
112 | 112 | time_t t_of_day; |
|
113 | 113 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; |
|
114 | 114 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); |
|
115 | 115 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); |
|
116 | 116 | t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); |
|
117 | 117 | t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); |
|
118 | 118 | t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); |
|
119 | 119 | int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); |
|
120 | 120 | t_of_day = mktime(&t); |
|
121 | 121 | return (t_of_day*1000.0)+ms; |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | double __decodeTimeFromEpoch(int ofset,unsigned char* data) |
|
125 | 125 | { |
|
126 | 126 | struct tm t; |
|
127 | 127 | time_t t_of_day; |
|
128 | 128 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; |
|
129 | 129 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); |
|
130 | 130 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); |
|
131 | 131 | t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); |
|
132 | 132 | t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); |
|
133 | 133 | t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); |
|
134 | 134 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); |
|
135 | 135 | t_of_day = mktime(&t); |
|
136 | 136 | return (double)t_of_day+((double)ms*(double)0.001); |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | double __decodeTimeHMSmS(int ofset,unsigned char* data) |
|
140 | 140 | { |
|
141 | 141 | int h,m,s; |
|
142 | 142 | h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); |
|
143 | 143 | m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); |
|
144 | 144 | s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); |
|
145 | 145 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); |
|
146 | 146 | return (double)((h*3600)+(m*60)+s) + (ms*0.001); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | double __decodeTimeDHMSmS(int ofset,unsigned char* data) |
|
150 | 150 | { |
|
151 | 151 | int d,h,m,s; |
|
152 | 152 | d=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); |
|
153 | 153 | h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); |
|
154 | 154 | m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); |
|
155 | 155 | s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); |
|
156 | 156 | double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); |
|
157 | 157 | return (double)((d*3600*24)+(h*3600)+(m*60)+s) + (ms*0.001); |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | double __decodeTimeFromEpochDayOnly(int ofset,unsigned char* data) |
|
161 | 161 | { |
|
162 | 162 | struct tm t; |
|
163 | 163 | time_t t_of_day; |
|
164 | 164 | // t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; |
|
165 | 165 | t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)); |
|
166 | 166 | t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); |
|
167 | 167 | t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); |
|
168 | 168 | t.tm_hour=0; |
|
169 | 169 | t.tm_min=0; |
|
170 | 170 | t.tm_sec=0; |
|
171 | 171 | // t_of_day = mktime(&t); |
|
172 | 172 | // return (double)t_of_day; |
|
173 | 173 | QDateTime date(QDate(t.tm_year,t.tm_mon,1),QTime(0,0)); |
|
174 | 174 | // date.setDate(); |
|
175 | 175 | return (double)((date.toMSecsSinceEpoch()/1000.0)-(24*3600)); |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | void CassiniDataFile::run() |
|
179 | 179 | { |
|
180 | 180 | if(!m_Write) |
|
181 | 181 | { |
|
182 | 182 | readFile(); |
|
183 | 183 | } |
|
184 | 184 | else |
|
185 | 185 | { |
|
186 | 186 | writeFile(); |
|
187 | 187 | } |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | 190 | void CassiniDataFile::readFile() |
|
191 | 191 | { |
|
192 | 192 | FILE* dataFile; |
|
193 | 193 | dataFile = fopen(fileName.toStdString().c_str(),"r"); |
|
194 | 194 | |
|
195 | 195 | if(dataFile != NULL) |
|
196 | 196 | { |
|
197 | 197 | fseek(dataFile, 0L, SEEK_END); |
|
198 | 198 | int FileSize=ftell(dataFile); |
|
199 | 199 | int lineCnt = FileSize/58; |
|
200 | 200 | int curLine=0; |
|
201 | 201 | int lastLineUpdate=0; |
|
202 | 202 | QVector<QCPData> *ch1=new QVector<QCPData>(lineCnt); |
|
203 | 203 | QVector<QCPData> *ch2=new QVector<QCPData>(lineCnt); |
|
204 | 204 | QVector<QCPData> *ch3=new QVector<QCPData>(lineCnt); |
|
205 | 205 | QLopDataList data; |
|
206 | 206 | QLopData* ch1V=new QLopData(); |
|
207 | 207 | QLopData* ch2V=new QLopData(); |
|
208 | 208 | QLopData* ch3V=new QLopData(); |
|
209 | 209 | ch1V->data=ch1; |
|
210 | 210 | ch2V->data=ch2; |
|
211 | 211 | ch3V->data=ch3; |
|
212 | 212 | ch1V->name="r"; |
|
213 | 213 | ch2V->name="theta"; |
|
214 | 214 | ch3V->name="phi"; |
|
215 | 215 | ch1V->unit="nT"; |
|
216 | 216 | ch2V->unit="nT"; |
|
217 | 217 | ch3V->unit="nT"; |
|
218 | 218 | data.append(ch1V); |
|
219 | 219 | data.append(ch2V); |
|
220 | 220 | data.append(ch3V); |
|
221 | 221 | QElapsedTimer timr; |
|
222 | 222 | |
|
223 | 223 | double _x=0.0,day=0.0; |
|
224 | 224 | char* line; |
|
225 | 225 | QCPData data1,data2,data3; |
|
226 | 226 | char* fileContent=(char*)malloc(FileSize); |
|
227 | 227 | if(Q_UNLIKELY(fileContent==NULL))return; |
|
228 | 228 | int threadIndex,numThreads=omp_get_num_threads(); |
|
229 | 229 | int updateTriger=(lineCnt/100)/numThreads; |
|
230 | 230 | fseek(dataFile, 0L, SEEK_SET); |
|
231 | 231 | char* svglocale=NULL; |
|
232 | 232 | setlocale(LC_NUMERIC,svglocale); |
|
233 | 233 | setlocale(LC_NUMERIC, "en_US"); |
|
234 | 234 | if(fread(fileContent,1,FileSize,dataFile)) |
|
235 | 235 | { |
|
236 | 236 | line = fileContent; |
|
237 | 237 | QDateTime date; |
|
238 | 238 | timr.start(); |
|
239 | 239 | day=__decodeTimeFromEpochDayOnly(0,(unsigned char*)line); |
|
240 | 240 | //#pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt) |
|
241 | 241 | // { |
|
242 | 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 | 243 | for(int i=0;i<lineCnt;i++) |
|
244 | 244 | { |
|
245 | 245 | // _x= i; |
|
246 | 246 | _x= day + __decodeTimeDHMSmS((i*58),(unsigned char*)line); |
|
247 | 247 | // _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line); |
|
248 | 248 | data1.key=_x; |
|
249 | 249 | data2.key=_x; |
|
250 | 250 | data3.key=_x; |
|
251 | 251 | data1.value=__decodeVal(((i*58)+27),(unsigned char*)line); |
|
252 | 252 | data2.value=__decodeVal(((i*58)+38),(unsigned char*)line); |
|
253 | 253 | data3.value=__decodeVal(((i*58)+49),(unsigned char*)line); |
|
254 | 254 | (*ch1)[i]=data1; |
|
255 | 255 | (*ch2)[i]=data2; |
|
256 | 256 | (*ch3)[i]=data3; |
|
257 | 257 | curLine++; |
|
258 | 258 | if(Q_UNLIKELY(lastLineUpdate++>updateTriger)) |
|
259 | 259 | { |
|
260 | 260 | lastLineUpdate=0; |
|
261 | 261 | int test=((curLine*numThreads *100)/ (lineCnt)); |
|
262 | 262 | emit updateProgress(omp_get_thread_num(),test); |
|
263 | 263 | } |
|
264 | 264 | } |
|
265 | 265 | } |
|
266 | 266 | //#pragma omp barrier |
|
267 | 267 | free(fileContent); |
|
268 | 268 | // } |
|
269 | qDebug()<< lineCnt <<" Points loade in "<< timr.elapsed()<<"ms"; | |
|
269 | qDebug()<< lineCnt <<" Points loaded in "<< timr.elapsed()<<"ms"; | |
|
270 | 270 | setlocale(LC_NUMERIC,svglocale); |
|
271 | 271 | emit dataReady(data); |
|
272 | 272 | } |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | void CassiniDataFile::writeFile() |
|
276 | 276 | { |
|
277 | 277 | QFile dataFile(fileName); |
|
278 | 278 | dataFile.open(QIODevice::WriteOnly); |
|
279 | 279 | QTextStream out(&dataFile); |
|
280 | 280 | if(dataFile.isOpen()) |
|
281 | 281 | { |
|
282 | 282 | if(m_data.count()==3) |
|
283 | 283 | { |
|
284 | 284 | QLopData* ch1V=m_data.at(0); |
|
285 | 285 | QLopData* ch2V=m_data.at(1); |
|
286 | 286 | QLopData* ch3V=m_data.at(2); |
|
287 | 287 | if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) |
|
288 | 288 | { |
|
289 | 289 | for(int i=0;i<ch1V->data->count();i++) |
|
290 | 290 | { |
|
291 | 291 | double key = ch1V->data->at(i).key; |
|
292 | 292 | QDateTime date = QDateTime::fromMSecsSinceEpoch(key*1000); |
|
293 | 293 | out << date.toString(Qt::ISODate)+QString(".%1").arg(date.time().msec(),3); |
|
294 | 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 | 295 | out << "\r\n"; |
|
296 | 296 | } |
|
297 | 297 | } |
|
298 | 298 | dataFile.flush(); |
|
299 | 299 | m_data.clear(); |
|
300 | 300 | delete ch1V; |
|
301 | 301 | delete ch2V; |
|
302 | 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 | 23 | #include "cassiniindexfile.h" |
|
2 | 24 | |
|
3 | 25 | #include <QFile> |
|
4 | 26 | #include <stdio.h> |
|
5 | 27 | #include <QStringList> |
|
6 | 28 | |
|
7 | 29 | CassiniIndexFile::CassiniIndexFile() |
|
8 | 30 | { |
|
9 | 31 | |
|
10 | 32 | } |
|
11 | 33 | |
|
12 | 34 | CassiniIndexFile::~CassiniIndexFile() |
|
13 | 35 | { |
|
14 | 36 | |
|
15 | 37 | } |
|
16 | 38 | |
|
17 | 39 | QList<CassiniIndexLine> CassiniIndexFile::loadFile(const QString &file) |
|
18 | 40 | { |
|
19 | 41 | QFile dataFile(file); |
|
20 | 42 | dataFile.open(QIODevice::ReadOnly); |
|
21 | 43 | QList<CassiniIndexLine> lines; |
|
22 | 44 | if(dataFile.isOpen()) |
|
23 | 45 | { |
|
24 | 46 | QString line; |
|
25 | 47 | QStringList cels; |
|
26 | 48 | CassiniIndexLine indexLine; |
|
27 | 49 | line=dataFile.readLine(); |
|
28 | 50 | while(!dataFile.atEnd()) |
|
29 | 51 | { |
|
30 | 52 | line=dataFile.readLine(); |
|
31 | 53 | cels= line.split(','); |
|
32 | 54 | for(int i=0;i<8;i++) |
|
33 | 55 | { |
|
34 | 56 | indexLine.cels[i]=""; |
|
35 | 57 | } |
|
36 | 58 | if(cels.count()<=8) |
|
37 | 59 | { |
|
38 | 60 | for(int i=0;i<cels.count();i++) |
|
39 | 61 | { |
|
40 | 62 | indexLine.cels[i]=cels.at(i); |
|
41 | 63 | } |
|
42 | 64 | lines.append(indexLine); |
|
43 | 65 | } |
|
44 | 66 | } |
|
45 | 67 | } |
|
46 | 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 | 23 | #ifndef CASSINIINDEXFILE_H |
|
2 | 24 | #define CASSINIINDEXFILE_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | |
|
6 | 28 | |
|
7 | 29 | #define DATA_SET_ID 0 |
|
8 | 30 | #define FILE_SPECIFICATION_NAME 1 |
|
9 | 31 | #define PRODUCT_ID 2 |
|
10 | 32 | #define VOLUME_ID 3 |
|
11 | 33 | #define PRODUCT_CREATION_TIME 4 |
|
12 | 34 | #define TARGET_NAME 5 |
|
13 | 35 | #define START_TIME 6 |
|
14 | 36 | #define STOP_TIME 7 |
|
15 | 37 | |
|
16 | 38 | |
|
17 | 39 | typedef struct CassiniIndexLine |
|
18 | 40 | { |
|
19 | 41 | QString cels[8]; |
|
20 | 42 | }CassiniIndexLine; |
|
21 | 43 | |
|
22 | 44 | class CassiniIndexFile:QObject |
|
23 | 45 | { |
|
24 | 46 | Q_OBJECT |
|
25 | 47 | public: |
|
26 | 48 | CassiniIndexFile(); |
|
27 | 49 | ~CassiniIndexFile(); |
|
28 | 50 | QList<CassiniIndexLine> loadFile(const QString& file); |
|
29 | 51 | signals: |
|
30 | 52 | public slots: |
|
31 | 53 | private: |
|
32 | 54 | }; |
|
33 | 55 | |
|
34 | 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 | 23 | #include "cassiniindexfileviewer.h" |
|
2 | 24 | #include "ui_cassiniindexfileviewer.h" |
|
3 | 25 | #include <QFileDialog> |
|
4 | 26 | |
|
5 | 27 | CassiniIndexFileViewer::CassiniIndexFileViewer(QWidget *parent) : |
|
6 | 28 | QWidget(parent), |
|
7 | 29 | ui(new Ui::CassiniIndexFileViewer) |
|
8 | 30 | { |
|
9 | 31 | ui->setupUi(this); |
|
10 | 32 | this->indexFile = new CassiniIndexFile(); |
|
11 | 33 | connect(this->ui->loadFileQpb,SIGNAL(clicked()),this,SLOT(loadFile())); |
|
12 | 34 | connect(this->ui->FilteerInput,SIGNAL(textChanged(QString)),this,SLOT(filterCol(QString))); |
|
13 | 35 | } |
|
14 | 36 | |
|
15 | 37 | CassiniIndexFileViewer::~CassiniIndexFileViewer() |
|
16 | 38 | { |
|
17 | 39 | delete this->indexFile; |
|
18 | 40 | delete ui; |
|
19 | 41 | } |
|
20 | 42 | |
|
21 | 43 | void CassiniIndexFileViewer::filterCol(const QString &pattern) |
|
22 | 44 | { |
|
23 | 45 | Qt::MatchFlags flag = Qt::MatchContains | Qt::MatchStartsWith | Qt::MatchEndsWith | Qt::MatchRegExp | Qt::MatchWildcard | Qt::MatchWrap |Qt::MatchRecursive; |
|
24 | 46 | if(this->ui->FilterCaseSensitive->isChecked()) |
|
25 | 47 | flag |= Qt::MatchCaseSensitive; |
|
26 | 48 | if(pattern.isEmpty()) |
|
27 | 49 | { |
|
28 | 50 | for(int i=0;i<this->ui->IndexView->rowCount();i++) |
|
29 | 51 | this->ui->IndexView->setRowHidden(i,false); |
|
30 | 52 | } |
|
31 | 53 | else |
|
32 | 54 | { |
|
33 | 55 | for(int i=0;i<this->ui->IndexView->rowCount();i++) |
|
34 | 56 | this->ui->IndexView->setRowHidden(i,true); |
|
35 | 57 | QList<QTableWidgetItem*> items = this->ui->IndexView->findItems(pattern,flag); |
|
36 | 58 | for(int i=0;i<items.count();i++) |
|
37 | 59 | this->ui->IndexView->setRowHidden(items.at(i)->row(),false); |
|
38 | 60 | } |
|
39 | 61 | } |
|
40 | 62 | |
|
41 | 63 | void CassiniIndexFileViewer::loadFile() |
|
42 | 64 | { |
|
43 | 65 | QList<CassiniIndexLine> lines=this->indexFile->loadFile(QFileDialog::getOpenFileName()); |
|
44 | 66 | this->ui->IndexView->clear(); |
|
45 | 67 | this->ui->IndexView->setRowCount(lines.count()); |
|
46 | 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 | 69 | for(int i=0;i<lines.count();i++) |
|
48 | 70 | { |
|
49 | 71 | for(int j=0;j<8;j++) |
|
50 | 72 | { |
|
51 | 73 | QString cel=QString(lines.at(i).cels[j]).remove('\n').remove('\r'); |
|
52 | 74 | QTableWidgetItem *newItem = new QTableWidgetItem(cel); |
|
53 | 75 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); |
|
54 | 76 | this->ui->IndexView->setItem(i, j, newItem); |
|
55 | 77 | } |
|
56 | 78 | } |
|
57 | 79 | } |
|
58 | 80 | |
|
59 | 81 | void CassiniIndexFileViewer::changeEvent(QEvent *e) |
|
60 | 82 | { |
|
61 | 83 | QWidget::changeEvent(e); |
|
62 | 84 | switch (e->type()) { |
|
63 | 85 | case QEvent::LanguageChange: |
|
64 | 86 | ui->retranslateUi(this); |
|
65 | 87 | break; |
|
66 | 88 | default: |
|
67 | 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 | 23 | #ifndef CASSINIINDEXFILEVIEWER_H |
|
2 | 24 | #define CASSINIINDEXFILEVIEWER_H |
|
3 | 25 | |
|
4 | 26 | #include <QWidget> |
|
5 | 27 | #include <cassiniindexfile.h> |
|
6 | 28 | |
|
7 | 29 | namespace Ui { |
|
8 | 30 | class CassiniIndexFileViewer; |
|
9 | 31 | } |
|
10 | 32 | |
|
11 | 33 | class CassiniIndexFileViewer : public QWidget |
|
12 | 34 | { |
|
13 | 35 | Q_OBJECT |
|
14 | 36 | |
|
15 | 37 | public: |
|
16 | 38 | explicit CassiniIndexFileViewer(QWidget *parent = 0); |
|
17 | 39 | ~CassiniIndexFileViewer(); |
|
18 | 40 | |
|
19 | 41 | public slots: |
|
20 | 42 | void filterCol(const QString& pattern); |
|
21 | 43 | void loadFile(); |
|
22 | 44 | protected: |
|
23 | 45 | void changeEvent(QEvent *e); |
|
24 | 46 | |
|
25 | 47 | private: |
|
26 | 48 | Ui::CassiniIndexFileViewer *ui; |
|
27 | 49 | CassiniIndexFile* indexFile; |
|
28 | 50 | }; |
|
29 | 51 | |
|
30 | 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 | 23 | #include "cassinitools.h" |
|
2 | 24 | #include <qlopplots.h> |
|
3 | 25 | #include <QPen> |
|
4 | 26 | #include <QAction> |
|
5 | 27 | #include <fftw3.h> |
|
28 | #include <omp.h> | |
|
6 | 29 | |
|
7 | 30 | CassiniTools* CassiniTools::_self=NULL; |
|
8 | 31 | QDockWidget* CassiniTools::m_gui=NULL; |
|
9 | 32 | CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL; |
|
10 | 33 | CassiniDataFile* CassiniTools::m_dataFile=NULL; |
|
11 | 34 | int CassiniTools::m_defaultPlot=-1; |
|
12 | 35 | int CassiniTools::m_fftPlot=-1; |
|
13 | 36 | SocExplorerPlotActions* CassiniTools::ExportAction=NULL; |
|
14 | 37 | |
|
15 | 38 | Qt::GlobalColor QLopColours[]= {Qt::black, |
|
16 | 39 | Qt::red, |
|
17 | 40 | Qt::blue, |
|
18 | 41 | Qt::green, |
|
19 | 42 | Qt::darkGreen, |
|
20 | 43 | Qt::cyan, |
|
21 | 44 | Qt::darkRed, |
|
22 | 45 | Qt::gray, |
|
23 | 46 | Qt::yellow, |
|
24 | 47 | Qt::darkBlue, |
|
25 | 48 | Qt::darkCyan, |
|
26 | 49 | Qt::magenta, |
|
27 | 50 | Qt::darkMagenta, |
|
28 | 51 | Qt::darkYellow, |
|
29 | 52 | Qt::darkGray, |
|
30 | 53 | Qt::lightGray}; |
|
31 | 54 | |
|
32 | 55 | int QLopColoursCount=16; |
|
33 | 56 | |
|
34 | 57 | #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();} |
|
35 | 58 | |
|
36 | 59 | CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent) |
|
37 | 60 | { |
|
38 | 61 | m_dataFile = new CassiniDataFile(); |
|
39 | 62 | connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList))); |
|
40 | 63 | m_serviceName="CassiniTools"; |
|
41 | 64 | m_noGui=noGUI; |
|
65 | fftw_init_threads(); | |
|
42 | 66 | } |
|
43 | 67 | |
|
44 | 68 | CassiniTools::~CassiniTools() |
|
45 | 69 | { |
|
46 | 70 | delete m_dataFile; |
|
47 | 71 | delete m_CassiniToolsGUI; |
|
48 | 72 | delete m_gui; |
|
49 | 73 | } |
|
50 | 74 | |
|
51 | 75 | void CassiniTools::makePlot() |
|
52 | 76 | { |
|
53 | 77 | m_defaultPlot = QLopPlots::addPlot(); |
|
54 | 78 | m_fftPlot = QLopPlots::addPlot(); |
|
55 | 79 | SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot); |
|
56 | 80 | if(plot) |
|
57 | 81 | { |
|
58 | 82 | plot->setTitle(_self->m_serviceName + " plot"); |
|
59 | 83 | plot->setXaxisTickLabelType(QCPAxis::ltDateTime); |
|
60 | 84 | plot->setXaxisDateTimeFormat("hh:mm:ss.zzz"); |
|
61 | 85 | plot->setContextMenuPolicy(Qt::ActionsContextMenu); |
|
62 | 86 | SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self); |
|
63 | 87 | plot->addAction(action); |
|
64 | 88 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int))); |
|
65 | 89 | ExportAction=new SocExplorerPlotActions("export view to "+QString(plot->title()).replace(".TAB","-part.TAB"),plot->PID(),_self); |
|
66 | 90 | plot->addAction(ExportAction); |
|
67 | 91 | QObject::connect(ExportAction,SIGNAL(triggered(int)),_self,SLOT(export_view_Predefined_FileName(int))); |
|
68 | 92 | action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self); |
|
69 | 93 | plot->addAction(action); |
|
70 | 94 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int))); |
|
71 | 95 | } |
|
72 | 96 | } |
|
73 | 97 | |
|
74 | 98 | void CassiniTools::init(bool noGUI, QObject *parent) |
|
75 | 99 | { |
|
76 | 100 | if(Q_UNLIKELY(_self==NULL)) |
|
77 | 101 | { |
|
78 | 102 | _self=new CassiniTools(noGUI,parent); |
|
79 | 103 | } |
|
80 | 104 | } |
|
81 | 105 | |
|
82 | 106 | CassiniTools *CassiniTools::self() |
|
83 | 107 | { |
|
84 | 108 | _INIT(); |
|
85 | 109 | return _self; |
|
86 | 110 | } |
|
87 | 111 | |
|
88 | 112 | void CassiniTools::decodeFGMData(const QString &file) |
|
89 | 113 | { |
|
90 | 114 | _INIT(); |
|
91 | 115 | m_dataFile->parseFile(file); |
|
92 | 116 | } |
|
93 | 117 | |
|
94 | 118 | void CassiniTools::plotFile(const QString &File) |
|
95 | 119 | { |
|
96 | 120 | if(!m_dataFile->isRunning()) |
|
97 | 121 | { |
|
98 | 122 | m_dataFile->parseFile(File); |
|
99 | 123 | // TODO fixme |
|
100 | 124 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); |
|
101 | 125 | if(plot==NULL) |
|
102 | 126 | { |
|
103 | 127 | makePlot(); |
|
104 | 128 | plot = QLopPlots::getPlot(m_defaultPlot); |
|
105 | 129 | } |
|
106 | 130 | if(plot) |
|
107 | 131 | { |
|
108 | 132 | plot->setTitle(File); |
|
109 | 133 | ExportAction->setText("export view to "+QString(File).replace(".TAB","-part.TAB")); |
|
110 | 134 | } |
|
111 | 135 | } |
|
112 | 136 | } |
|
113 | 137 | |
|
114 | 138 | void CassiniTools::plot_TAB_File(const QString &fileName) |
|
115 | 139 | { |
|
116 | 140 | //TODO fix: accent not accepted |
|
117 | 141 | plotFile(fileName); |
|
118 | 142 | } |
|
119 | 143 | |
|
120 | 144 | void CassiniTools::export_view(int PID) |
|
121 | 145 | { |
|
122 | 146 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); |
|
123 | 147 | if(plot==NULL) |
|
124 | 148 | return; |
|
125 | 149 | { |
|
126 | 150 | QString fileName = plot->title(); |
|
127 | 151 | fileName = QFileDialog::getSaveFileName(0,tr("Set filename"),fileName.replace(".TAB","-part.TAB")); |
|
128 | 152 | if(fileName!="") |
|
129 | 153 | { |
|
130 | 154 | QLopDataList vectors; |
|
131 | 155 | for(int i=0;i<plot->graphCount();i++) |
|
132 | 156 | { |
|
133 | 157 | QLopData* vect = new QLopData(); |
|
134 | 158 | vect->data = plot->getVisibleData(i); |
|
135 | 159 | vectors.append(vect); |
|
136 | 160 | } |
|
137 | 161 | m_dataFile->saveFile(fileName,vectors); |
|
138 | 162 | } |
|
139 | 163 | } |
|
140 | 164 | } |
|
141 | 165 | |
|
142 | 166 | void CassiniTools::export_view_Predefined_FileName(int PID) |
|
143 | 167 | { |
|
144 | 168 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); |
|
145 | 169 | if(plot==NULL) |
|
146 | 170 | return; |
|
147 | 171 | { |
|
148 | 172 | QString fileName = QString(plot->title()).replace(".TAB","-part.TAB"); |
|
149 | 173 | if(fileName!="") |
|
150 | 174 | { |
|
151 | 175 | QLopDataList vectors; |
|
152 | 176 | for(int i=0;i<plot->graphCount();i++) |
|
153 | 177 | { |
|
154 | 178 | QLopData* vect = new QLopData(); |
|
155 | 179 | vect->data = plot->getVisibleData(i); |
|
156 | 180 | vectors.append(vect); |
|
157 | 181 | } |
|
158 | 182 | m_dataFile->saveFile(fileName,vectors); |
|
159 | 183 | } |
|
160 | 184 | } |
|
161 | 185 | } |
|
162 | 186 | |
|
163 | 187 | void CassiniTools::compute_fft_on_view(int PID) |
|
164 | 188 | { |
|
189 | ||
|
190 | QElapsedTimer timr; | |
|
165 | 191 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); |
|
166 | 192 | if(plot==NULL) |
|
167 | 193 | return; |
|
168 | 194 | { |
|
195 | timr.start(); | |
|
169 | 196 | QLopDataList vectors; |
|
170 | 197 | for(int i=0;i<plot->graphCount();i++) |
|
171 | 198 | { |
|
172 | 199 | QLopData* vect = new QLopData(); |
|
173 | 200 | vect->data = plot->getVisibleData(i); |
|
174 | 201 | vectors.append(vect); |
|
175 | 202 | } |
|
176 | 203 | if(vectors.count()==3) |
|
177 | 204 | { |
|
178 | 205 | QLopData* ch1V=vectors.at(0); |
|
179 | 206 | QLopData* ch2V=vectors.at(1); |
|
180 | 207 | QLopData* ch3V=vectors.at(2); |
|
181 | 208 | QLopData* FFTout=new QLopData(); |
|
182 | 209 | if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) |
|
183 | 210 | { |
|
184 | 211 | |
|
185 | 212 | double* in; |
|
186 | 213 | fftw_complex *out; |
|
187 | 214 | fftw_plan p; |
|
188 | 215 | FFTout->data = new QVector<QCPData>(ch1V->data->count()/2); |
|
189 | 216 | in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count()); |
|
190 | 217 | out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count()); |
|
191 | 218 | double av=0; |
|
192 | 219 | for(int i=0;i<ch1V->data->count();i++) |
|
193 | 220 | { |
|
194 | 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 | 222 | av = av+in[i]; |
|
196 | 223 | } |
|
197 | 224 | av/=ch1V->data->count(); |
|
198 | 225 | for(int i=0;i<ch1V->data->count();i++) |
|
199 | 226 | { |
|
200 | 227 | in[i]=in[i]-av; |
|
201 | 228 | } |
|
229 | fftw_plan_with_nthreads(4); | |
|
202 | 230 | p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE); |
|
203 | 231 | fftw_execute(p); /* repeat as needed */ |
|
204 | 232 | fftw_destroy_plan(p); |
|
205 | 233 | fftw_free(in); |
|
206 | 234 | for(int i=0;i<ch1V->data->count()/2;i++) |
|
207 | 235 | { |
|
208 | 236 | // (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count(); |
|
209 | 237 | (*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count()); |
|
210 | 238 | (*FFTout->data)[i].key = i; |
|
211 | 239 | } |
|
212 | 240 | fftw_free(out); |
|
213 | 241 | SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot); |
|
214 | 242 | if(plot==NULL) |
|
215 | 243 | return; |
|
216 | 244 | plot->removeAllGraphs(); |
|
217 | 245 | plot->addGraph(); |
|
218 | 246 | plot->setXaxisLog(); |
|
219 | 247 | plot->setYaxisLog(); |
|
220 | 248 | plot->setAdaptativeSampling(0,true); |
|
221 | 249 | QPen pen = plot->getGraphPen(0); |
|
222 | 250 | pen.setColor(QLopColours[0%QLopColoursCount]); |
|
223 | 251 | plot->setGraphPen(0,pen); |
|
224 | 252 | plot->setGraphData(0,FFTout->data,false); |
|
225 | 253 | plot->rescaleAxis(); |
|
226 | 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 | 262 | QDockWidget *CassiniTools::getGUI() |
|
234 | 263 | { |
|
235 | 264 | if(!m_noGui && (m_gui==NULL)) |
|
236 | 265 | { |
|
237 | 266 | m_gui=new QDockWidget("Cassini Tools"); |
|
238 | 267 | m_CassiniToolsGUI = new CassiniToolsGUI(); |
|
239 | 268 | m_gui->setWidget(m_CassiniToolsGUI); |
|
240 | 269 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
241 | 270 | } |
|
242 | 271 | return m_gui; |
|
243 | 272 | } |
|
244 | 273 | |
|
245 | 274 | const QString &CassiniTools::serviceName() |
|
246 | 275 | { |
|
247 | 276 | _INIT(); |
|
248 | 277 | return m_serviceName; |
|
249 | 278 | } |
|
250 | 279 | |
|
251 | 280 | void CassiniTools::dataReady(QLopDataList data) |
|
252 | 281 | { |
|
253 | 282 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); |
|
254 | 283 | if(plot==NULL) |
|
255 | 284 | { |
|
256 | 285 | makePlot(); |
|
257 | 286 | plot = QLopPlots::getPlot(m_defaultPlot); |
|
258 | 287 | } |
|
259 | 288 | if(plot) |
|
260 | 289 | { |
|
261 | 290 | plot->removeAllGraphs(); |
|
262 | 291 | for(int i=0;i<data.count();i++) |
|
263 | 292 | { |
|
264 | 293 | plot->addGraph(); |
|
265 | 294 | plot->setAdaptativeSampling(i,true); |
|
266 | 295 | plot->setUseFastVector(i,true); |
|
267 | 296 | QPen pen = plot->getGraphPen(i); |
|
268 | 297 | pen.setColor(QLopColours[i%QLopColoursCount]); |
|
269 | 298 | plot->setGraphPen(i,pen); |
|
270 | 299 | plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")"); |
|
271 | 300 | plot->setGraphData(i,data.at(i)->data,false); |
|
272 | 301 | } |
|
273 | 302 | plot->rescaleAxis(); |
|
274 | 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 | 22 | #ifndef CASSINITOOLS_H |
|
2 | 23 | #define CASSINITOOLS_H |
|
3 | 24 | |
|
4 | 25 | #include <QObject> |
|
5 | 26 | #include <QWidget> |
|
6 | 27 | #include <qlopservice.h> |
|
7 | 28 | #include <cassinitoolsgui.h> |
|
8 | 29 | #include <cassinidatafile.h> |
|
9 | 30 | #include <qlopdata.h> |
|
10 | 31 | #include <SocExplorerPlot.h> |
|
11 | 32 | |
|
12 | 33 | class CassiniTools: public QLopService |
|
13 | 34 | { |
|
14 | 35 | Q_OBJECT |
|
15 | 36 | private: |
|
16 | 37 | static CassiniTools* _self; |
|
17 | 38 | static QDockWidget* m_gui; |
|
18 | 39 | static CassiniToolsGUI* m_CassiniToolsGUI; |
|
19 | 40 | static CassiniDataFile* m_dataFile; |
|
20 | 41 | static int m_defaultPlot,m_fftPlot; |
|
21 | 42 | static SocExplorerPlotActions* ExportAction; |
|
22 | 43 | CassiniTools(bool noGUI=false, QObject *parent=0); |
|
23 | 44 | ~CassiniTools(); |
|
24 | 45 | static void makePlot(); |
|
25 | 46 | public: |
|
26 | 47 | static void init(bool noGUI=false,QObject *parent = 0); |
|
27 | 48 | static CassiniTools *self(); |
|
28 | 49 | static void decodeFGMData(const QString& file); |
|
29 | 50 | // QLopService methodes |
|
30 | 51 | QDockWidget* getGUI(); |
|
31 | 52 | const QString& serviceName(); |
|
32 | 53 | static void plotFile(const QString &File); |
|
33 | 54 | public slots: |
|
34 | 55 | void plot_TAB_File(const QString& fileName); |
|
35 | 56 | void export_view(int PID); |
|
36 | 57 | void export_view_Predefined_FileName(int PID); |
|
37 | 58 | void compute_fft_on_view(int PID); |
|
38 | 59 | private slots: |
|
39 | 60 | void dataReady(QLopDataList data); |
|
40 | 61 | }; |
|
41 | 62 | |
|
42 | 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 | 23 | #include "cassinitoolsgui.h" |
|
2 | 24 | #include "ui_cassinitoolsgui.h" |
|
3 | 25 | #include <cassinitools.h> |
|
4 | 26 | |
|
5 | 27 | CassiniToolsGUI::CassiniToolsGUI(QWidget *parent) : |
|
6 | 28 | QWidget(parent), |
|
7 | 29 | ui(new Ui::CassiniToolsGUI) |
|
8 | 30 | { |
|
9 | 31 | ui->setupUi(this); |
|
10 | 32 | connect(this->ui->addFolderViewQpb,SIGNAL(clicked()),this,SLOT(addFolderView())); |
|
11 | 33 | } |
|
12 | 34 | |
|
13 | 35 | CassiniToolsGUI::~CassiniToolsGUI() |
|
14 | 36 | { |
|
15 | 37 | delete ui; |
|
16 | 38 | } |
|
17 | 39 | |
|
18 | 40 | void CassiniToolsGUI::addFolderView() |
|
19 | 41 | { |
|
20 | 42 | this->fileBrowsers.append(new FileBrowser()); |
|
21 | 43 | this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->fileBrowsers.last()); |
|
22 | 44 | this->fileBrowsers.last()->setWindowTitle( QString("Browser %1").arg(this->fileBrowsers.length())); |
|
23 | 45 | this->fileBrowsers.last()->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
24 | 46 | this->fileBrowsers.last()->setNameFilters(QStringList()<<"*.TAB"); |
|
25 | 47 | connect(this->fileBrowsers.last(),SIGNAL(fileDoubleClicked(QString)),this,SLOT(plotFile(QString))); |
|
26 | 48 | } |
|
27 | 49 | |
|
28 | 50 | void CassiniToolsGUI::plotFile(const QString &File) |
|
29 | 51 | { |
|
30 | 52 | CassiniTools::plotFile(File); |
|
31 | 53 | } |
|
32 | 54 | |
|
33 | 55 | void CassiniToolsGUI::changeEvent(QEvent *e) |
|
34 | 56 | { |
|
35 | 57 | QWidget::changeEvent(e); |
|
36 | 58 | switch (e->type()) { |
|
37 | 59 | case QEvent::LanguageChange: |
|
38 | 60 | ui->retranslateUi(this); |
|
39 | 61 | break; |
|
40 | 62 | default: |
|
41 | 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 | 23 | #ifndef CASSINITOOLSGUI_H |
|
2 | 24 | #define CASSINITOOLSGUI_H |
|
3 | 25 | |
|
4 | 26 | #include <QWidget> |
|
5 | 27 | #include <filebrowser.h> |
|
6 | 28 | |
|
7 | 29 | namespace Ui { |
|
8 | 30 | class CassiniToolsGUI; |
|
9 | 31 | } |
|
10 | 32 | |
|
11 | 33 | class CassiniToolsGUI : public QWidget |
|
12 | 34 | { |
|
13 | 35 | Q_OBJECT |
|
14 | 36 | |
|
15 | 37 | public: |
|
16 | 38 | explicit CassiniToolsGUI(QWidget *parent = 0); |
|
17 | 39 | ~CassiniToolsGUI(); |
|
18 | 40 | |
|
19 | 41 | protected: |
|
20 | 42 | void changeEvent(QEvent *e); |
|
21 | 43 | |
|
22 | 44 | private slots: |
|
23 | 45 | void addFolderView(); |
|
24 | 46 | void plotFile(const QString &File); |
|
25 | 47 | private: |
|
26 | 48 | Ui::CassiniToolsGUI *ui; |
|
27 | 49 | QList<FileBrowser*> fileBrowsers; |
|
28 | 50 | }; |
|
29 | 51 | |
|
30 | 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 | 23 | #include "expxmldownloader.h" |
|
2 | 24 | #include <QDebug> |
|
3 | 25 | #include <QFile> |
|
4 | 26 | #include <QQueue> |
|
5 | 27 | #include <QDate> |
|
6 | 28 | #include <QDateTime> |
|
7 | 29 | |
|
8 | 30 | ExpXmlDownLoader::ExpXmlDownLoader(QObject *parent) : QObject(parent) |
|
9 | 31 | { |
|
10 | 32 | this->m_doc = NULL; |
|
11 | 33 | } |
|
12 | 34 | |
|
13 | 35 | ExpXmlDownLoader::~ExpXmlDownLoader() |
|
14 | 36 | { |
|
15 | 37 | |
|
16 | 38 | } |
|
17 | 39 | |
|
18 | 40 | bool ExpXmlDownLoader::parseXml(const QString &fileName) |
|
19 | 41 | { |
|
20 | 42 | QQueue<QString> nodes; |
|
21 | 43 | nodes<<"RESOURCE"<<"TABLE"<<"DATA"<<"TABLEDATA"; |
|
22 | 44 | if(m_doc!=NULL) |
|
23 | 45 | delete m_doc; |
|
24 | 46 | m_doc = new QDomDocument(fileName); |
|
25 | 47 | QFile file(fileName); |
|
26 | 48 | if (!file.open(QIODevice::ReadOnly)) |
|
27 | 49 | return false; |
|
28 | 50 | if (!m_doc->setContent(&file)) { |
|
29 | 51 | file.close(); |
|
30 | 52 | return false; |
|
31 | 53 | } |
|
32 | 54 | file.close(); |
|
33 | 55 | if(m_doc->isNull()) |
|
34 | 56 | { |
|
35 | 57 | delete m_doc; |
|
36 | 58 | return false; |
|
37 | 59 | } |
|
38 | 60 | QDomElement docElem = m_doc->documentElement(); |
|
39 | 61 | QDomNode n = docElem.firstChild(); |
|
40 | 62 | while(!n.isNull() && !nodes.empty()) |
|
41 | 63 | { |
|
42 | 64 | if(n.toElement().tagName()==nodes.head()) |
|
43 | 65 | { |
|
44 | 66 | nodes.dequeue(); |
|
45 | 67 | n=n.firstChild(); |
|
46 | 68 | } |
|
47 | 69 | else |
|
48 | 70 | { |
|
49 | 71 | n = n.nextSibling(); |
|
50 | 72 | } |
|
51 | 73 | } |
|
52 | 74 | extractIntervals(n); |
|
53 | 75 | makeDownloadList(); |
|
54 | 76 | return true; |
|
55 | 77 | } |
|
56 | 78 | |
|
57 | 79 | const QList<QDate> &ExpXmlDownLoader::daysToDownload() |
|
58 | 80 | { |
|
59 | 81 | return m_FilesToDownload; |
|
60 | 82 | } |
|
61 | 83 | |
|
62 | 84 | void ExpXmlDownLoader::extractIntervals(QDomNode n) |
|
63 | 85 | { |
|
64 | 86 | QDomNode inter; |
|
65 | 87 | m_intervals.clear(); |
|
66 | 88 | while(!n.isNull()) |
|
67 | 89 | { |
|
68 | 90 | if(n.toElement().tagName()=="TR") |
|
69 | 91 | { |
|
70 | 92 | ExpXmlDownLoaderIntervals interval; |
|
71 | 93 | inter=n.firstChild(); |
|
72 | 94 | if(inter.toElement().tagName()=="TD") |
|
73 | 95 | { |
|
74 | 96 | interval.start = inter.toElement().text(); |
|
75 | 97 | } |
|
76 | 98 | inter=inter.nextSibling(); |
|
77 | 99 | if(inter.toElement().tagName()=="TD") |
|
78 | 100 | { |
|
79 | 101 | interval.stop = inter.toElement().text(); |
|
80 | 102 | } |
|
81 | 103 | m_intervals.append(interval); |
|
82 | 104 | } |
|
83 | 105 | n = n.nextSibling(); |
|
84 | 106 | } |
|
85 | 107 | } |
|
86 | 108 | |
|
87 | 109 | void ExpXmlDownLoader::makeDownloadList() |
|
88 | 110 | { |
|
89 | 111 | for(int i=0;i<m_intervals.count();i++) |
|
90 | 112 | { |
|
91 | 113 | QList<QDate> daysToDl; |
|
92 | 114 | QDateTime start,stop; |
|
93 | 115 | start=start.fromString(m_intervals[i].start,Qt::ISODate); |
|
94 | 116 | stop=stop.fromString(m_intervals[i].stop,Qt::ISODate); |
|
95 | 117 | int days=start.daysTo(stop); |
|
96 | 118 | daysToDl.append(start.date()); |
|
97 | 119 | if(days) |
|
98 | 120 | { |
|
99 | 121 | for(int j=0;j<days;j++) |
|
100 | 122 | { |
|
101 | 123 | daysToDl.append(start.addDays(j+1).date()); |
|
102 | 124 | } |
|
103 | 125 | } |
|
104 | 126 | addDaysToDownload(daysToDl); |
|
105 | 127 | } |
|
106 | 128 | qDebug()<<m_FilesToDownload.count(); |
|
107 | 129 | } |
|
108 | 130 | |
|
109 | 131 | void ExpXmlDownLoader::addDaysToDownload(QList<QDate> days) |
|
110 | 132 | { |
|
111 | 133 | for(int i=0;i<days.count();i++) |
|
112 | 134 | { |
|
113 | 135 | if(!m_FilesToDownload.contains(days.at(i))) |
|
114 | 136 | { |
|
115 | 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 | 23 | #ifndef EXPXMLDOWNLOADER_H |
|
2 | 24 | #define EXPXMLDOWNLOADER_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | #include <QDomDocument> |
|
6 | 28 | #include <QList> |
|
7 | 29 | |
|
8 | 30 | typedef struct ExpXmlDownLoaderIntervals |
|
9 | 31 | { |
|
10 | 32 | QString date; |
|
11 | 33 | QString start; |
|
12 | 34 | QString stop; |
|
13 | 35 | }ExpXmlDownLoaderIntervals; |
|
14 | 36 | class ExpXmlDownLoader : public QObject |
|
15 | 37 | { |
|
16 | 38 | Q_OBJECT |
|
17 | 39 | public: |
|
18 | 40 | explicit ExpXmlDownLoader(QObject *parent = 0); |
|
19 | 41 | ~ExpXmlDownLoader(); |
|
20 | 42 | bool parseXml(const QString& fileName); |
|
21 | 43 | const QList<QDate>& daysToDownload(); |
|
22 | 44 | signals: |
|
23 | 45 | |
|
24 | 46 | public slots: |
|
25 | 47 | |
|
26 | 48 | private: |
|
27 | 49 | void extractIntervals(QDomNode n); |
|
28 | 50 | void makeDownloadList(); |
|
29 | 51 | void addDaysToDownload(QList<QDate> days); |
|
30 | 52 | QDomDocument* m_doc; |
|
31 | 53 | QList<ExpXmlDownLoaderIntervals> m_intervals; |
|
32 | 54 | QList<QDate> m_FilesToDownload; |
|
33 | 55 | }; |
|
34 | 56 | |
|
35 | 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 | 23 | #include "downloadhistory.h" |
|
2 | 24 | #include "ui_downloadhistory.h" |
|
3 | 25 | |
|
4 | 26 | DownLoadHistory::DownLoadHistory(QWidget *parent) : |
|
5 | 27 | QWidget(parent), |
|
6 | 28 | ui(new Ui::DownLoadHistory) |
|
7 | 29 | { |
|
8 | 30 | ui->setupUi(this); |
|
9 | 31 | vblayout = new QVBoxLayout(this->ui->scrollAreaWidgetContents); |
|
10 | 32 | vblayout->addStretch(1); |
|
11 | 33 | } |
|
12 | 34 | |
|
13 | 35 | DownLoadHistory::~DownLoadHistory() |
|
14 | 36 | { |
|
15 | 37 | delete ui; |
|
16 | 38 | } |
|
17 | 39 | |
|
18 | 40 | void DownLoadHistory::addElement(DownloadHistoryElement *element) |
|
19 | 41 | { |
|
20 | 42 | if(element) |
|
21 | 43 | this->vblayout->insertWidget(0,element); |
|
22 | 44 | } |
|
23 | 45 | |
|
24 | 46 | void DownLoadHistory::changeEvent(QEvent *e) |
|
25 | 47 | { |
|
26 | 48 | QWidget::changeEvent(e); |
|
27 | 49 | switch (e->type()) { |
|
28 | 50 | case QEvent::LanguageChange: |
|
29 | 51 | ui->retranslateUi(this); |
|
30 | 52 | break; |
|
31 | 53 | default: |
|
32 | 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 | 23 | #ifndef DOWNLOADHISTORY_H |
|
2 | 24 | #define DOWNLOADHISTORY_H |
|
3 | 25 | |
|
4 | 26 | #include <QWidget> |
|
5 | 27 | #include <downloadhistoryelement.h> |
|
6 | 28 | #include <QVBoxLayout> |
|
7 | 29 | |
|
8 | 30 | namespace Ui { |
|
9 | 31 | class DownLoadHistory; |
|
10 | 32 | } |
|
11 | 33 | |
|
12 | 34 | class DownLoadHistory : public QWidget |
|
13 | 35 | { |
|
14 | 36 | Q_OBJECT |
|
15 | 37 | |
|
16 | 38 | public: |
|
17 | 39 | explicit DownLoadHistory(QWidget *parent = 0); |
|
18 | 40 | ~DownLoadHistory(); |
|
19 | 41 | void addElement(DownloadHistoryElement* element); |
|
20 | 42 | protected: |
|
21 | 43 | void changeEvent(QEvent *e); |
|
22 | 44 | |
|
23 | 45 | private: |
|
24 | 46 | Ui::DownLoadHistory *ui; |
|
25 | 47 | QVBoxLayout* vblayout; |
|
26 | 48 | }; |
|
27 | 49 | |
|
28 | 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 | 23 | #include "downloadhistoryelement.h" |
|
2 | 24 | #include "ui_downloadhistoryelement.h" |
|
3 | 25 | |
|
4 | 26 | DownloadHistoryElement::DownloadHistoryElement(FileDownloaderTask *task, QWidget *parent) : |
|
5 | 27 | QWidget(parent), |
|
6 | 28 | ui(new Ui::DownloadHistoryElement) |
|
7 | 29 | { |
|
8 | 30 | ui->setupUi(this); |
|
9 | 31 | if(task) |
|
10 | 32 | { |
|
11 | 33 | this->associatedTask=task; |
|
12 | 34 | this->ui->DownloadDate->setText(task->startDateTime().toString("yyyy:MM:dd-hh:mm:ss")); |
|
13 | 35 | this->ui->FileNameLbl->setText(task->fileName()); |
|
14 | 36 | this->ui->linkLbl->setText(task->url()); |
|
15 | 37 | connect(associatedTask,SIGNAL(updateProgress(int)),this,SLOT(updateProgress(int))); |
|
16 | 38 | } |
|
17 | 39 | /*this->setStyleSheet("QWidget#DownloadHistoryElement{\ |
|
18 | 40 | border: 1px solid gray;\ |
|
19 | 41 | border-radius: 9px;\ |
|
20 | 42 | margin-top: 0.5em; \ |
|
21 | 43 | }");*/ |
|
22 | 44 | } |
|
23 | 45 | |
|
24 | 46 | DownloadHistoryElement::~DownloadHistoryElement() |
|
25 | 47 | { |
|
26 | 48 | delete ui; |
|
27 | 49 | } |
|
28 | 50 | |
|
29 | 51 | void DownloadHistoryElement::updateProgress(int percent) |
|
30 | 52 | { |
|
31 | 53 | this->ui->progressBar->setValue(percent); |
|
32 | 54 | } |
|
33 | 55 | |
|
34 | 56 | void DownloadHistoryElement::changeEvent(QEvent *e) |
|
35 | 57 | { |
|
36 | 58 | QWidget::changeEvent(e); |
|
37 | 59 | switch (e->type()) { |
|
38 | 60 | case QEvent::LanguageChange: |
|
39 | 61 | ui->retranslateUi(this); |
|
40 | 62 | break; |
|
41 | 63 | default: |
|
42 | 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 | 22 | #ifndef DOWNLOADHISTORYELEMENT_H |
|
2 | 23 | #define DOWNLOADHISTORYELEMENT_H |
|
3 | 24 | |
|
4 | 25 | #include <QWidget> |
|
5 | 26 | #include <filedownloadertask.h> |
|
6 | 27 | |
|
7 | 28 | namespace Ui { |
|
8 | 29 | class DownloadHistoryElement; |
|
9 | 30 | } |
|
10 | 31 | |
|
11 | 32 | class DownloadHistoryElement : public QWidget |
|
12 | 33 | { |
|
13 | 34 | Q_OBJECT |
|
14 | 35 | |
|
15 | 36 | public: |
|
16 | 37 | explicit DownloadHistoryElement(FileDownloaderTask* task, QWidget *parent = 0); |
|
17 | 38 | ~DownloadHistoryElement(); |
|
18 | 39 | |
|
19 | 40 | public slots: |
|
20 | 41 | void updateProgress(int percent); |
|
21 | 42 | protected: |
|
22 | 43 | void changeEvent(QEvent *e); |
|
23 | 44 | |
|
24 | 45 | private: |
|
25 | 46 | Ui::DownloadHistoryElement *ui; |
|
26 | 47 | FileDownloaderTask* associatedTask; |
|
27 | 48 | }; |
|
28 | 49 | |
|
29 | 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 | 23 | #include "filebrowser.h" |
|
2 | 24 | #include "ui_filebrowser.h" |
|
3 | 25 | #include <QListView> |
|
4 | 26 | #include <QTreeView> |
|
5 | 27 | |
|
6 | 28 | FileBrowser::FileBrowser(QWidget *parent) : |
|
7 | 29 | QDockWidget(parent), |
|
8 | 30 | ui(new Ui::FileBrowser) |
|
9 | 31 | { |
|
10 | 32 | ui->setupUi(this); |
|
11 | 33 | this->model = new FileSystemModel(this); |
|
12 | 34 | this->model->setRootPath(QDir::currentPath()); |
|
13 | 35 | this->view = new QTreeView(); |
|
14 | 36 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); |
|
15 | 37 | this->view->setModel(this->model); |
|
16 | 38 | this->cd(model->rootPath()); |
|
17 | 39 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); |
|
18 | 40 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); |
|
19 | 41 | connect(this->ui->ListViewQpb,SIGNAL(clicked()),this,SLOT(changeToListView())); |
|
20 | 42 | connect(this->ui->TreeViewQpb,SIGNAL(clicked()),this,SLOT(changeToTreeView())); |
|
21 | 43 | connect(this->ui->parentDirQpb,SIGNAL(clicked()),this,SLOT(parentDir())); |
|
22 | 44 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
23 | 45 | view->setDragEnabled(true); |
|
24 | 46 | view->setAcceptDrops(true); |
|
25 | 47 | view->setDropIndicatorShown(true); |
|
26 | 48 | view->setDragDropMode(QAbstractItemView::DragDrop); |
|
27 | 49 | this->pathCompleter = new QCompleter(this->model,this); |
|
28 | 50 | this->ui->pathLineEdit->setCompleter(pathCompleter); |
|
29 | 51 | this->pathLineEditEnterEditMode(false); |
|
30 | 52 | } |
|
31 | 53 | |
|
32 | 54 | FileBrowser::~FileBrowser() |
|
33 | 55 | { |
|
34 | 56 | delete ui; |
|
35 | 57 | } |
|
36 | 58 | |
|
37 | 59 | void FileBrowser::setNameFilters(const QStringList &filters,bool disables) |
|
38 | 60 | { |
|
39 | 61 | this->model->setNameFilters(filters); |
|
40 | 62 | this->model->setNameFilterDisables(disables); |
|
41 | 63 | } |
|
42 | 64 | |
|
43 | 65 | void FileBrowser::changeToTreeView() |
|
44 | 66 | { |
|
45 | 67 | this->ui->gridLayout->removeWidget(this->view); |
|
46 | 68 | delete this->view; |
|
47 | 69 | this->view = new QTreeView(); |
|
48 | 70 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); |
|
49 | 71 | this->view->setModel(this->model); |
|
50 | 72 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); |
|
51 | 73 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); |
|
52 | 74 | this->cd(model->rootPath()); |
|
53 | 75 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
54 | 76 | view->setDragEnabled(true); |
|
55 | 77 | view->setAcceptDrops(true); |
|
56 | 78 | view->setDropIndicatorShown(true); |
|
57 | 79 | } |
|
58 | 80 | |
|
59 | 81 | void FileBrowser::changeToListView() |
|
60 | 82 | { |
|
61 | 83 | this->ui->gridLayout->removeWidget(this->view); |
|
62 | 84 | delete this->view; |
|
63 | 85 | this->view = new QListView(); |
|
64 | 86 | this->ui->gridLayout->addWidget(this->view,1,0,1,-1); |
|
65 | 87 | this->view->setModel(this->model); |
|
66 | 88 | connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex))); |
|
67 | 89 | connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex))); |
|
68 | 90 | this->cd(model->rootPath()); |
|
69 | 91 | view->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
70 | 92 | view->setDragEnabled(true); |
|
71 | 93 | view->setAcceptDrops(true); |
|
72 | 94 | view->setDropIndicatorShown(true); |
|
73 | 95 | } |
|
74 | 96 | |
|
75 | 97 | void FileBrowser::clicked(QModelIndex index) |
|
76 | 98 | { |
|
77 | 99 | QString file=model->filePath(index); |
|
78 | 100 | if(QFile::exists(file)) |
|
79 | 101 | emit fileClicked(file); |
|
80 | 102 | } |
|
81 | 103 | |
|
82 | 104 | void FileBrowser::doubleClicked(QModelIndex index) |
|
83 | 105 | { |
|
84 | 106 | if(model->isDir(index)) |
|
85 | 107 | { |
|
86 | 108 | this->cd(model->filePath(index)); |
|
87 | 109 | } |
|
88 | 110 | else |
|
89 | 111 | { |
|
90 | 112 | QString file=model->filePath(index); |
|
91 | 113 | if(QFile::exists(file)) |
|
92 | 114 | emit fileDoubleClicked(file); |
|
93 | 115 | } |
|
94 | 116 | } |
|
95 | 117 | |
|
96 | 118 | void FileBrowser::parentDir() |
|
97 | 119 | { |
|
98 | 120 | this->cd(model->rootPath()+"/.."); |
|
99 | 121 | } |
|
100 | 122 | |
|
101 | 123 | void FileBrowser::cd(const QString &newPath) |
|
102 | 124 | { |
|
103 | 125 | model->setRootPath(newPath); |
|
104 | 126 | this->view->setRootIndex(model->index(model->rootPath())); |
|
105 | 127 | this->ui->pathLineEdit->setText(model->rootPath()); |
|
106 | 128 | } |
|
107 | 129 | |
|
108 | 130 | |
|
109 | 131 | void FileBrowser::changeEvent(QEvent *e) |
|
110 | 132 | { |
|
111 | 133 | QDockWidget::changeEvent(e); |
|
112 | 134 | switch (e->type()) { |
|
113 | 135 | case QEvent::LanguageChange: |
|
114 | 136 | ui->retranslateUi(this); |
|
115 | 137 | break; |
|
116 | 138 | default: |
|
117 | 139 | break; |
|
118 | 140 | } |
|
119 | 141 | } |
|
120 | 142 | |
|
121 | 143 | void FileBrowser::keyPressEvent(QKeyEvent *e) |
|
122 | 144 | { |
|
123 | 145 | switch (e->key()) |
|
124 | 146 | { |
|
125 | 147 | case Qt::Key_L: |
|
126 | 148 | if(e->modifiers()==Qt::ControlModifier) |
|
127 | 149 | { |
|
128 | 150 | pathLineEditEnterEditMode(true); |
|
129 | 151 | e->accept(); |
|
130 | 152 | } |
|
131 | 153 | break; |
|
132 | 154 | case Qt::Key_Return: |
|
133 | 155 | pathLineEditEnterEditMode(false); |
|
134 | 156 | if(QFile::exists(this->ui->pathLineEdit->text())) |
|
135 | 157 | { |
|
136 | 158 | this->cd(this->ui->pathLineEdit->text()); |
|
137 | 159 | e->accept(); |
|
138 | 160 | } |
|
139 | 161 | break; |
|
140 | 162 | default: |
|
141 | 163 | break; |
|
142 | 164 | } |
|
143 | 165 | if(!e->isAccepted()) |
|
144 | 166 | QDockWidget::keyPressEvent(e); |
|
145 | 167 | } |
|
146 | 168 | |
|
147 | 169 | void FileBrowser::pathLineEditEnterEditMode(bool enter) |
|
148 | 170 | { |
|
149 | 171 | this->ui->pathLineEdit->setReadOnly(!enter); |
|
150 | 172 | this->ui->pathLineEdit->setDisabled(!enter); |
|
151 | 173 | if(enter) |
|
152 | 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 | 23 | #ifndef FILEBROWSER_H |
|
2 | 24 | #define FILEBROWSER_H |
|
3 | 25 | |
|
4 | 26 | #include <QDockWidget> |
|
5 | 27 | #include <QFileSystemModel> |
|
6 | 28 | #include <QAbstractItemView> |
|
7 | 29 | #include <filesystemmodel.h> |
|
8 | 30 | #include <QKeyEvent> |
|
9 | 31 | #include <QCompleter> |
|
10 | 32 | |
|
11 | 33 | namespace Ui { |
|
12 | 34 | class FileBrowser; |
|
13 | 35 | } |
|
14 | 36 | |
|
15 | 37 | class FileBrowser : public QDockWidget |
|
16 | 38 | { |
|
17 | 39 | Q_OBJECT |
|
18 | 40 | |
|
19 | 41 | public: |
|
20 | 42 | explicit FileBrowser(QWidget *parent = 0); |
|
21 | 43 | ~FileBrowser(); |
|
22 | 44 | void setNameFilters(const QStringList & filters, bool disables=false); |
|
23 | 45 | signals: |
|
24 | 46 | void fileClicked(const QString& file); |
|
25 | 47 | void fileDoubleClicked(const QString& file); |
|
26 | 48 | private slots: |
|
27 | 49 | void changeToTreeView(); |
|
28 | 50 | void changeToListView(); |
|
29 | 51 | void clicked(QModelIndex index); |
|
30 | 52 | void doubleClicked(QModelIndex index); |
|
31 | 53 | void parentDir(); |
|
32 | 54 | void cd(const QString& newPath); |
|
33 | 55 | protected: |
|
34 | 56 | void changeEvent(QEvent *e); |
|
35 | 57 | void keyPressEvent(QKeyEvent *e); |
|
36 | 58 | private: |
|
37 | 59 | void pathLineEditEnterEditMode(bool enter=true); |
|
38 | 60 | Ui::FileBrowser *ui; |
|
39 | 61 | FileSystemModel* model; |
|
40 | 62 | QAbstractItemView* view; |
|
41 | 63 | QCompleter* pathCompleter; |
|
42 | 64 | }; |
|
43 | 65 | |
|
44 | 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 | 23 | #include "filesystemmodel.h" |
|
2 | 24 | FileSystemModel::FileSystemModel(QObject *parent):QFileSystemModel(parent) |
|
3 | 25 | { |
|
4 | 26 | this->setReadOnly(false); |
|
5 | 27 | } |
|
6 | 28 | |
|
7 | 29 | FileSystemModel::~FileSystemModel() |
|
8 | 30 | { |
|
9 | 31 | } |
|
10 | 32 | |
|
11 | 33 | Qt::DropActions FileSystemModel::supportedDropActions() const |
|
12 | 34 | { |
|
13 | 35 | return Qt::MoveAction; |
|
14 | 36 | } |
|
15 | 37 | |
|
16 | 38 | |
|
17 | 39 | Qt::ItemFlags FileSystemModel::flags(const QModelIndex &index) const |
|
18 | 40 | { |
|
19 | 41 | Qt::ItemFlags defaultFlags = QFileSystemModel::flags(index); |
|
20 | 42 | defaultFlags &= ~Qt::ItemIsEditable; |
|
21 | 43 | if (index.isValid()) |
|
22 | 44 | return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; |
|
23 | 45 | else |
|
24 | 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 | 23 | #ifndef FILESYSTEMMODEL_H |
|
2 | 24 | #define FILESYSTEMMODEL_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | #include <QFileSystemModel> |
|
6 | 28 | |
|
7 | 29 | class FileSystemModel : public QFileSystemModel |
|
8 | 30 | { |
|
9 | 31 | public: |
|
10 | 32 | FileSystemModel(QObject* parent=0); |
|
11 | 33 | ~FileSystemModel(); |
|
12 | 34 | Qt::DropActions supportedDropActions() const; |
|
13 | 35 | Qt::ItemFlags flags(const QModelIndex &index) const; |
|
14 | 36 | }; |
|
15 | 37 | |
|
16 | 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 | 25 | #include "qcustomplotvect.h" |
|
2 | 26 | #include <QVector> |
|
3 | 27 | #include <QVectorIterator> |
|
4 | 28 | QCustomPlotVect::QCustomPlotVect(QWidget *parent) |
|
5 | 29 | :QCustomPlot(parent) |
|
6 | 30 | { |
|
7 | 31 | |
|
8 | 32 | } |
|
9 | 33 | |
|
10 | 34 | QCustomPlotVect::~QCustomPlotVect() |
|
11 | 35 | { |
|
12 | 36 | |
|
13 | 37 | } |
|
14 | 38 | |
|
15 | 39 | QCPGraphVect *QCustomPlotVect::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) |
|
16 | 40 | { |
|
17 | 41 | if (!keyAxis) keyAxis = xAxis; |
|
18 | 42 | if (!valueAxis) valueAxis = yAxis; |
|
19 | 43 | if (!keyAxis || !valueAxis) |
|
20 | 44 | { |
|
21 | 45 | qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; |
|
22 | 46 | return 0; |
|
23 | 47 | } |
|
24 | 48 | if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) |
|
25 | 49 | { |
|
26 | 50 | qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; |
|
27 | 51 | return 0; |
|
28 | 52 | } |
|
29 | 53 | |
|
30 | 54 | QCPGraphVect *newGraph = new QCPGraphVect(keyAxis, valueAxis); |
|
31 | 55 | if (addPlottable(newGraph)) |
|
32 | 56 | { |
|
33 | 57 | newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); |
|
34 | 58 | return newGraph; |
|
35 | 59 | } else |
|
36 | 60 | { |
|
37 | 61 | delete newGraph; |
|
38 | 62 | return 0; |
|
39 | 63 | } |
|
40 | 64 | } |
|
41 | 65 | |
|
42 | 66 | |
|
43 | 67 | QCPGraphVect::QCPGraphVect(QCPAxis *keyAxis, QCPAxis *valueAxis) |
|
44 | 68 | :QCPGraph(keyAxis,valueAxis) |
|
45 | 69 | { |
|
46 | 70 | mData = new QVector<QCPData>(); |
|
47 | 71 | } |
|
48 | 72 | |
|
49 | 73 | QCPGraphVect::~QCPGraphVect() |
|
50 | 74 | { |
|
51 | 75 | delete mData; |
|
52 | 76 | } |
|
53 | 77 | |
|
54 | 78 | void QCPGraphVect::setData(QVector<QCPData> *data) |
|
55 | 79 | { |
|
56 | 80 | if(data!=mData) |
|
57 | 81 | { |
|
58 | 82 | delete this->mData; |
|
59 | 83 | this->mData = data; |
|
60 | 84 | } |
|
61 | 85 | } |
|
62 | 86 | |
|
63 | 87 | QVector<QCPData> *QCPGraphVect::getVisibleData() |
|
64 | 88 | { |
|
65 | 89 | QVector<QCPData>* data = new QVector<QCPData>(); |
|
66 | 90 | bool mAdaptiveSampling_save = mAdaptiveSampling; |
|
67 | 91 | mAdaptiveSampling = false; |
|
68 | 92 | getPreparedData(data,NULL); |
|
69 | 93 | mAdaptiveSampling = mAdaptiveSampling_save; |
|
70 | 94 | return data; |
|
71 | 95 | } |
|
72 | 96 | |
|
73 | 97 | void QCPGraphVect::draw(QCPPainter *painter) |
|
74 | 98 | { |
|
75 | 99 | if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } |
|
76 | 100 | int test = mKeyAxis.data()->range().size(); |
|
77 | 101 | test = mData->count(); |
|
78 | 102 | if (mKeyAxis.data()->range().size() <= 0 || mData->isEmpty()) return; |
|
79 | 103 | if (mLineStyle == lsNone && mScatterStyle.isNone()) return; |
|
80 | 104 | |
|
81 | 105 | // allocate line and (if necessary) point vectors: |
|
82 | 106 | QVector<QPointF> *lineData = new QVector<QPointF>; |
|
83 | 107 | QVector<QCPData> *scatterData = 0; |
|
84 | 108 | if (!mScatterStyle.isNone()) |
|
85 | 109 | scatterData = new QVector<QCPData>; |
|
86 | 110 | |
|
87 | 111 | // fill vectors with data appropriate to plot style: |
|
88 | 112 | getPlotData(lineData, scatterData); |
|
89 | 113 | |
|
90 | 114 | // check data validity if flag set: |
|
91 | 115 | #ifdef QCUSTOMPLOT_CHECK_DATA |
|
92 | 116 | QCPDataMap::const_iterator it; |
|
93 | 117 | for (it = mData->constBegin(); it != mData->constEnd(); ++it) |
|
94 | 118 | { |
|
95 | 119 | if (QCP::isInvalidData(it.value().key, it.value().value) || |
|
96 | 120 | QCP::isInvalidData(it.value().keyErrorPlus, it.value().keyErrorMinus) || |
|
97 | 121 | QCP::isInvalidData(it.value().valueErrorPlus, it.value().valueErrorPlus)) |
|
98 | 122 | qDebug() << Q_FUNC_INFO << "Data point at" << it.key() << "invalid." << "Plottable name:" << name(); |
|
99 | 123 | } |
|
100 | 124 | #endif |
|
101 | 125 | |
|
102 | 126 | // draw fill of graph: |
|
103 | 127 | drawFill(painter, lineData); |
|
104 | 128 | |
|
105 | 129 | // draw line: |
|
106 | 130 | if (mLineStyle == lsImpulse) |
|
107 | 131 | drawImpulsePlot(painter, lineData); |
|
108 | 132 | else if (mLineStyle != lsNone) |
|
109 | 133 | drawLinePlot(painter, lineData); // also step plots can be drawn as a line plot |
|
110 | 134 | |
|
111 | 135 | // draw scatters: |
|
112 | 136 | if (scatterData) |
|
113 | 137 | drawScatterPlot(painter, scatterData); |
|
114 | 138 | |
|
115 | 139 | // free allocated line and point vectors: |
|
116 | 140 | delete lineData; |
|
117 | 141 | if (scatterData) |
|
118 | 142 | delete scatterData; |
|
119 | 143 | } |
|
120 | 144 | |
|
121 | 145 | void QCPGraphVect::getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const |
|
122 | 146 | { |
|
123 | 147 | switch(mLineStyle) |
|
124 | 148 | { |
|
125 | 149 | case lsNone: getScatterPlotData(scatterData); break; |
|
126 | 150 | case lsLine: getLinePlotData(lineData, scatterData); break; |
|
127 | 151 | case lsStepLeft: getStepLeftPlotData(lineData, scatterData); break; |
|
128 | 152 | case lsStepRight: getStepRightPlotData(lineData, scatterData); break; |
|
129 | 153 | case lsStepCenter: getStepCenterPlotData(lineData, scatterData); break; |
|
130 | 154 | case lsImpulse: getImpulsePlotData(lineData, scatterData); break; |
|
131 | 155 | } |
|
132 | 156 | } |
|
133 | 157 | |
|
134 | 158 | void QCPGraphVect::getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const |
|
135 | 159 | { |
|
136 | 160 | QCPAxis *keyAxis = mKeyAxis.data(); |
|
137 | 161 | QCPAxis *valueAxis = mValueAxis.data(); |
|
138 | 162 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } |
|
139 | 163 | if (!linePixelData) { qDebug() << Q_FUNC_INFO << "null pointer passed as linePixelData"; return; } |
|
140 | 164 | |
|
141 | 165 | QVector<QCPData> lineData; |
|
142 | 166 | getPreparedData(&lineData, scatterData); |
|
143 | 167 | linePixelData->reserve(lineData.size()+2); // added 2 to reserve memory for lower/upper fill base points that might be needed for fill |
|
144 | 168 | linePixelData->resize(lineData.size()); |
|
145 | 169 | |
|
146 | 170 | // transform lineData points to pixels: |
|
147 | 171 | if (keyAxis->orientation() == Qt::Vertical) |
|
148 | 172 | { |
|
149 | 173 | for (int i=0; i<lineData.size(); ++i) |
|
150 | 174 | { |
|
151 | 175 | (*linePixelData)[i].setX(valueAxis->coordToPixel(lineData.at(i).value)); |
|
152 | 176 | (*linePixelData)[i].setY(keyAxis->coordToPixel(lineData.at(i).key)); |
|
153 | 177 | } |
|
154 | 178 | } else // key axis is horizontal |
|
155 | 179 | { |
|
156 | 180 | for (int i=0; i<lineData.size(); ++i) |
|
157 | 181 | { |
|
158 | 182 | (*linePixelData)[i].setX(keyAxis->coordToPixel(lineData.at(i).key)); |
|
159 | 183 | (*linePixelData)[i].setY(valueAxis->coordToPixel(lineData.at(i).value)); |
|
160 | 184 | } |
|
161 | 185 | } |
|
162 | 186 | } |
|
163 | 187 | |
|
164 | 188 | QCPRange QCPGraphVect::getKeyRange(bool &foundRange, QCPAbstractPlottable::SignDomain inSignDomain, bool includeErrors) const |
|
165 | 189 | { |
|
166 | 190 | |
|
167 | 191 | QCPRange range; |
|
168 | 192 | bool haveLower = false; |
|
169 | 193 | bool haveUpper = false; |
|
170 | 194 | |
|
171 | 195 | double current, currentErrorMinus, currentErrorPlus; |
|
172 | 196 | |
|
173 | 197 | if (inSignDomain == sdBoth) // range may be anywhere |
|
174 | 198 | { |
|
175 | 199 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
176 | 200 | while (it != mData->constEnd()) |
|
177 | 201 | { |
|
178 | 202 | current = (*it).key; |
|
179 | 203 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); |
|
180 | 204 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); |
|
181 | 205 | if (current-currentErrorMinus < range.lower || !haveLower) |
|
182 | 206 | { |
|
183 | 207 | range.lower = current-currentErrorMinus; |
|
184 | 208 | haveLower = true; |
|
185 | 209 | } |
|
186 | 210 | if (current+currentErrorPlus > range.upper || !haveUpper) |
|
187 | 211 | { |
|
188 | 212 | range.upper = current+currentErrorPlus; |
|
189 | 213 | haveUpper = true; |
|
190 | 214 | } |
|
191 | 215 | ++it; |
|
192 | 216 | } |
|
193 | 217 | } else if (inSignDomain == sdNegative) // range may only be in the negative sign domain |
|
194 | 218 | { |
|
195 | 219 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
196 | 220 | while (it != mData->constEnd()) |
|
197 | 221 | { |
|
198 | 222 | current = (*it).key; |
|
199 | 223 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); |
|
200 | 224 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); |
|
201 | 225 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0) |
|
202 | 226 | { |
|
203 | 227 | range.lower = current-currentErrorMinus; |
|
204 | 228 | haveLower = true; |
|
205 | 229 | } |
|
206 | 230 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0) |
|
207 | 231 | { |
|
208 | 232 | range.upper = current+currentErrorPlus; |
|
209 | 233 | haveUpper = true; |
|
210 | 234 | } |
|
211 | 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 | 237 | if ((current < range.lower || !haveLower) && current < 0) |
|
214 | 238 | { |
|
215 | 239 | range.lower = current; |
|
216 | 240 | haveLower = true; |
|
217 | 241 | } |
|
218 | 242 | if ((current > range.upper || !haveUpper) && current < 0) |
|
219 | 243 | { |
|
220 | 244 | range.upper = current; |
|
221 | 245 | haveUpper = true; |
|
222 | 246 | } |
|
223 | 247 | } |
|
224 | 248 | ++it; |
|
225 | 249 | } |
|
226 | 250 | } else if (inSignDomain == sdPositive) // range may only be in the positive sign domain |
|
227 | 251 | { |
|
228 | 252 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
229 | 253 | while (it != mData->constEnd()) |
|
230 | 254 | { |
|
231 | 255 | current = (*it).key; |
|
232 | 256 | currentErrorMinus = (includeErrors ? (*it).keyErrorMinus : 0); |
|
233 | 257 | currentErrorPlus = (includeErrors ? (*it).keyErrorPlus : 0); |
|
234 | 258 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0) |
|
235 | 259 | { |
|
236 | 260 | range.lower = current-currentErrorMinus; |
|
237 | 261 | haveLower = true; |
|
238 | 262 | } |
|
239 | 263 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0) |
|
240 | 264 | { |
|
241 | 265 | range.upper = current+currentErrorPlus; |
|
242 | 266 | haveUpper = true; |
|
243 | 267 | } |
|
244 | 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 | 270 | if ((current < range.lower || !haveLower) && current > 0) |
|
247 | 271 | { |
|
248 | 272 | range.lower = current; |
|
249 | 273 | haveLower = true; |
|
250 | 274 | } |
|
251 | 275 | if ((current > range.upper || !haveUpper) && current > 0) |
|
252 | 276 | { |
|
253 | 277 | range.upper = current; |
|
254 | 278 | haveUpper = true; |
|
255 | 279 | } |
|
256 | 280 | } |
|
257 | 281 | ++it; |
|
258 | 282 | } |
|
259 | 283 | } |
|
260 | 284 | |
|
261 | 285 | foundRange = haveLower && haveUpper; |
|
262 | 286 | return range; |
|
263 | 287 | } |
|
264 | 288 | |
|
265 | 289 | QCPRange QCPGraphVect::getValueRange(bool &foundRange, QCPAbstractPlottable::SignDomain inSignDomain, bool includeErrors) const |
|
266 | 290 | { |
|
267 | 291 | QCPRange range; |
|
268 | 292 | bool haveLower = false; |
|
269 | 293 | bool haveUpper = false; |
|
270 | 294 | |
|
271 | 295 | double current, currentErrorMinus, currentErrorPlus; |
|
272 | 296 | |
|
273 | 297 | if (inSignDomain == sdBoth) // range may be anywhere |
|
274 | 298 | { |
|
275 | 299 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
276 | 300 | while (it != mData->constEnd()) |
|
277 | 301 | { |
|
278 | 302 | current = (*it).value; |
|
279 | 303 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); |
|
280 | 304 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); |
|
281 | 305 | if (current-currentErrorMinus < range.lower || !haveLower) |
|
282 | 306 | { |
|
283 | 307 | range.lower = current-currentErrorMinus; |
|
284 | 308 | haveLower = true; |
|
285 | 309 | } |
|
286 | 310 | if (current+currentErrorPlus > range.upper || !haveUpper) |
|
287 | 311 | { |
|
288 | 312 | range.upper = current+currentErrorPlus; |
|
289 | 313 | haveUpper = true; |
|
290 | 314 | } |
|
291 | 315 | ++it; |
|
292 | 316 | } |
|
293 | 317 | } else if (inSignDomain == sdNegative) // range may only be in the negative sign domain |
|
294 | 318 | { |
|
295 | 319 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
296 | 320 | while (it != mData->constEnd()) |
|
297 | 321 | { |
|
298 | 322 | current = (*it).value; |
|
299 | 323 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); |
|
300 | 324 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); |
|
301 | 325 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0) |
|
302 | 326 | { |
|
303 | 327 | range.lower = current-currentErrorMinus; |
|
304 | 328 | haveLower = true; |
|
305 | 329 | } |
|
306 | 330 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0) |
|
307 | 331 | { |
|
308 | 332 | range.upper = current+currentErrorPlus; |
|
309 | 333 | haveUpper = true; |
|
310 | 334 | } |
|
311 | 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 | 337 | if ((current < range.lower || !haveLower) && current < 0) |
|
314 | 338 | { |
|
315 | 339 | range.lower = current; |
|
316 | 340 | haveLower = true; |
|
317 | 341 | } |
|
318 | 342 | if ((current > range.upper || !haveUpper) && current < 0) |
|
319 | 343 | { |
|
320 | 344 | range.upper = current; |
|
321 | 345 | haveUpper = true; |
|
322 | 346 | } |
|
323 | 347 | } |
|
324 | 348 | ++it; |
|
325 | 349 | } |
|
326 | 350 | } else if (inSignDomain == sdPositive) // range may only be in the positive sign domain |
|
327 | 351 | { |
|
328 | 352 | QVector<QCPData>::const_iterator it = mData->constBegin(); |
|
329 | 353 | while (it != mData->constEnd()) |
|
330 | 354 | { |
|
331 | 355 | current = (*it).value; |
|
332 | 356 | currentErrorMinus = (includeErrors ? (*it).valueErrorMinus : 0); |
|
333 | 357 | currentErrorPlus = (includeErrors ? (*it).valueErrorPlus : 0); |
|
334 | 358 | if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0) |
|
335 | 359 | { |
|
336 | 360 | range.lower = current-currentErrorMinus; |
|
337 | 361 | haveLower = true; |
|
338 | 362 | } |
|
339 | 363 | if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0) |
|
340 | 364 | { |
|
341 | 365 | range.upper = current+currentErrorPlus; |
|
342 | 366 | haveUpper = true; |
|
343 | 367 | } |
|
344 | 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 | 370 | if ((current < range.lower || !haveLower) && current > 0) |
|
347 | 371 | { |
|
348 | 372 | range.lower = current; |
|
349 | 373 | haveLower = true; |
|
350 | 374 | } |
|
351 | 375 | if ((current > range.upper || !haveUpper) && current > 0) |
|
352 | 376 | { |
|
353 | 377 | range.upper = current; |
|
354 | 378 | haveUpper = true; |
|
355 | 379 | } |
|
356 | 380 | } |
|
357 | 381 | ++it; |
|
358 | 382 | } |
|
359 | 383 | } |
|
360 | 384 | |
|
361 | 385 | foundRange = haveLower && haveUpper; |
|
362 | 386 | return range; |
|
363 | 387 | } |
|
364 | 388 | |
|
365 | 389 | void QCPGraphVect::getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const |
|
366 | 390 | { |
|
367 | 391 | QCPAxis *keyAxis = mKeyAxis.data(); |
|
368 | 392 | QCPAxis *valueAxis = mValueAxis.data(); |
|
369 | 393 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } |
|
370 | 394 | // get visible data range: |
|
371 | 395 | QVector<QCPData>::const_iterator lower, upper; // note that upper is the actual upper point, and not 1 step after the upper point |
|
372 | 396 | getVisibleDataBounds(lower, upper); |
|
373 | 397 | if (lower == mData->constEnd() || upper == mData->constEnd()) |
|
374 | 398 | return; |
|
375 | 399 | |
|
376 | 400 | // count points in visible range, taking into account that we only need to count to the limit maxCount if using adaptive sampling: |
|
377 | 401 | int maxCount = std::numeric_limits<int>::max(); |
|
378 | 402 | if (mAdaptiveSampling) |
|
379 | 403 | { |
|
380 | 404 | int keyPixelSpan = qAbs(keyAxis->coordToPixel((*lower).key)-keyAxis->coordToPixel((*upper).key)); |
|
381 | 405 | maxCount = 2*keyPixelSpan+2; |
|
382 | 406 | } |
|
383 | 407 | int dataCount = countDataInBounds(lower, upper, maxCount); |
|
384 | 408 | |
|
385 | 409 | if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average |
|
386 | 410 | { |
|
387 | 411 | if (lineData) |
|
388 | 412 | { |
|
389 | 413 | QVector<QCPData>::const_iterator it = lower; |
|
390 | 414 | QVector<QCPData>::const_iterator upperEnd = upper+1; |
|
391 | 415 | double minValue = (*it).value; |
|
392 | 416 | double maxValue = (*it).value; |
|
393 | 417 | QVector<QCPData>::const_iterator currentIntervalFirstPoint = it; |
|
394 | 418 | int reversedFactor = keyAxis->rangeReversed() != (keyAxis->orientation()==Qt::Vertical) ? -1 : 1; // is used to calculate keyEpsilon pixel into the correct direction |
|
395 | 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 | 420 | double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*lower).key)+reversedRound)); |
|
397 | 421 | double lastIntervalEndKey = currentIntervalStartKey; |
|
398 | 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 | 423 | bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) |
|
400 | 424 | int intervalDataCount = 1; |
|
401 | 425 | ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect |
|
402 | 426 | while (it != upperEnd) |
|
403 | 427 | { |
|
404 | 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 | 430 | if ((*it).value < minValue) |
|
407 | 431 | minValue = (*it).value; |
|
408 | 432 | else if ((*it).value > maxValue) |
|
409 | 433 | maxValue = (*it).value; |
|
410 | 434 | ++intervalDataCount; |
|
411 | 435 | } else // new pixel interval started |
|
412 | 436 | { |
|
413 | 437 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster |
|
414 | 438 | { |
|
415 | 439 | if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point |
|
416 | 440 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.2, (*currentIntervalFirstPoint).value)); |
|
417 | 441 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); |
|
418 | 442 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); |
|
419 | 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 | 444 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.8, (*(it-1)).value)); |
|
421 | 445 | } else |
|
422 | 446 | lineData->append(QCPData((*currentIntervalFirstPoint).key, (*currentIntervalFirstPoint).value)); |
|
423 | 447 | lastIntervalEndKey = (*(it-1)).key; |
|
424 | 448 | minValue = (*it).value; |
|
425 | 449 | maxValue = (*it).value; |
|
426 | 450 | currentIntervalFirstPoint = it; |
|
427 | 451 | currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*it).key)+reversedRound)); |
|
428 | 452 | if (keyEpsilonVariable) |
|
429 | 453 | keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); |
|
430 | 454 | intervalDataCount = 1; |
|
431 | 455 | } |
|
432 | 456 | ++it; |
|
433 | 457 | } |
|
434 | 458 | // handle last interval: |
|
435 | 459 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster |
|
436 | 460 | { |
|
437 | 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 | 462 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.2, (*currentIntervalFirstPoint).value)); |
|
439 | 463 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); |
|
440 | 464 | lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); |
|
441 | 465 | } else |
|
442 | 466 | lineData->append(QCPData((*currentIntervalFirstPoint).key, (*currentIntervalFirstPoint).value)); |
|
443 | 467 | } |
|
444 | 468 | |
|
445 | 469 | if (scatterData) |
|
446 | 470 | { |
|
447 | 471 | double valueMaxRange = valueAxis->range().upper; |
|
448 | 472 | double valueMinRange = valueAxis->range().lower; |
|
449 | 473 | QVector<QCPData>::const_iterator it = lower; |
|
450 | 474 | QVector<QCPData>::const_iterator upperEnd = upper+1; |
|
451 | 475 | double minValue = (*it).value; |
|
452 | 476 | double maxValue = (*it).value; |
|
453 | 477 | QVector<QCPData>::const_iterator minValueIt = it; |
|
454 | 478 | QVector<QCPData>::const_iterator maxValueIt = it; |
|
455 | 479 | QVector<QCPData>::const_iterator currentIntervalStart = it; |
|
456 | 480 | int reversedFactor = keyAxis->rangeReversed() ? -1 : 1; // is used to calculate keyEpsilon pixel into the correct direction |
|
457 | 481 | int reversedRound = keyAxis->rangeReversed() ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey |
|
458 | 482 | double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*lower).key)+reversedRound)); |
|
459 | 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 | 484 | bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) |
|
461 | 485 | int intervalDataCount = 1; |
|
462 | 486 | ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect |
|
463 | 487 | while (it != upperEnd) |
|
464 | 488 | { |
|
465 | 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 | 491 | if ((*it).value < minValue && (*it).value > valueMinRange && (*it).value < valueMaxRange) |
|
468 | 492 | { |
|
469 | 493 | minValue = (*it).value; |
|
470 | 494 | minValueIt = it; |
|
471 | 495 | } else if ((*it).value > maxValue && (*it).value > valueMinRange && (*it).value < valueMaxRange) |
|
472 | 496 | { |
|
473 | 497 | maxValue = (*it).value; |
|
474 | 498 | maxValueIt = it; |
|
475 | 499 | } |
|
476 | 500 | ++intervalDataCount; |
|
477 | 501 | } else // new pixel started |
|
478 | 502 | { |
|
479 | 503 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them |
|
480 | 504 | { |
|
481 | 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 | 506 | double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); |
|
483 | 507 | int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average |
|
484 | 508 | QVector<QCPData>::const_iterator intervalIt = currentIntervalStart; |
|
485 | 509 | int c = 0; |
|
486 | 510 | while (intervalIt != it) |
|
487 | 511 | { |
|
488 | 512 | if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && (*intervalIt).value > valueMinRange && (*intervalIt).value < valueMaxRange) |
|
489 | 513 | scatterData->append((*intervalIt)); |
|
490 | 514 | ++c; |
|
491 | 515 | ++intervalIt; |
|
492 | 516 | } |
|
493 | 517 | } else if ((*currentIntervalStart).value > valueMinRange && (*currentIntervalStart).value < valueMaxRange) |
|
494 | 518 | scatterData->append((*currentIntervalStart)); |
|
495 | 519 | minValue = (*it).value; |
|
496 | 520 | maxValue = (*it).value; |
|
497 | 521 | currentIntervalStart = it; |
|
498 | 522 | currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel((*it).key)+reversedRound)); |
|
499 | 523 | if (keyEpsilonVariable) |
|
500 | 524 | keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); |
|
501 | 525 | intervalDataCount = 1; |
|
502 | 526 | } |
|
503 | 527 | ++it; |
|
504 | 528 | } |
|
505 | 529 | // handle last interval: |
|
506 | 530 | if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them |
|
507 | 531 | { |
|
508 | 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 | 533 | double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); |
|
510 | 534 | int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average |
|
511 | 535 | QVector<QCPData>::const_iterator intervalIt = currentIntervalStart; |
|
512 | 536 | int c = 0; |
|
513 | 537 | while (intervalIt != it) |
|
514 | 538 | { |
|
515 | 539 | if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && (*intervalIt).value > valueMinRange && (*intervalIt).value < valueMaxRange) |
|
516 | 540 | scatterData->append((*intervalIt)); |
|
517 | 541 | ++c; |
|
518 | 542 | ++intervalIt; |
|
519 | 543 | } |
|
520 | 544 | } else if ((*currentIntervalStart).value > valueMinRange && (*currentIntervalStart).value < valueMaxRange) |
|
521 | 545 | scatterData->append(*currentIntervalStart); |
|
522 | 546 | } |
|
523 | 547 | } else // don't use adaptive sampling algorithm, transfer points one-to-one from the map into the output parameters |
|
524 | 548 | { |
|
525 | 549 | QVector<QCPData> *dataVector = 0; |
|
526 | 550 | if (lineData) |
|
527 | 551 | { |
|
528 | 552 | dataVector = lineData; |
|
529 | 553 | } |
|
530 | 554 | else if (scatterData) |
|
531 | 555 | dataVector = scatterData; |
|
532 | 556 | if (dataVector) |
|
533 | 557 | { |
|
534 | 558 | QVector<QCPData>::const_iterator it = lower; |
|
535 | 559 | QVector<QCPData>::const_iterator upperEnd = upper+1; |
|
536 | 560 | dataVector->reserve(dataCount+2); // +2 for possible fill end points |
|
537 | 561 | while (it != upperEnd) |
|
538 | 562 | { |
|
539 | 563 | dataVector->append(*it); |
|
540 | 564 | ++it; |
|
541 | 565 | } |
|
542 | 566 | } |
|
543 | 567 | if (lineData && scatterData) |
|
544 | 568 | *scatterData = *dataVector; |
|
545 | 569 | } |
|
546 | 570 | } |
|
547 | 571 | |
|
548 | 572 | QVector<QCPData>::const_iterator __lowerBoundDico_vect(QVector<QCPData>* vector,double key) |
|
549 | 573 | { |
|
550 | 574 | int DX=vector->size()/2; |
|
551 | 575 | int pos=DX; |
|
552 | 576 | // double test=(*vector)[vector->length()-1].key; |
|
553 | 577 | if(key>((*vector)[vector->length()-1].key)) |
|
554 | 578 | return vector->constEnd(); |
|
555 | 579 | if(key<((*vector)[0].key)) |
|
556 | 580 | return vector->constBegin(); |
|
557 | 581 | while (DX>1) |
|
558 | 582 | { |
|
559 | 583 | DX=DX/2; |
|
560 | 584 | if((*vector)[pos].key > key) |
|
561 | 585 | { |
|
562 | 586 | pos-=DX; |
|
563 | 587 | } |
|
564 | 588 | else |
|
565 | 589 | { |
|
566 | 590 | pos+=DX; |
|
567 | 591 | } |
|
568 | 592 | } |
|
569 | 593 | if((*vector)[pos].key >= key) |
|
570 | 594 | return vector->constBegin()+pos; |
|
571 | 595 | return vector->constBegin()+pos+1; |
|
572 | 596 | } |
|
573 | 597 | |
|
574 | 598 | |
|
575 | 599 | QVector<QCPData>::const_iterator __upperBoundDico_vect(QVector<QCPData>* vector,double key) |
|
576 | 600 | { |
|
577 | 601 | int DX=vector->size()/2; |
|
578 | 602 | int pos=DX; |
|
579 | 603 | if(key>((*vector)[vector->length()-1].key)) |
|
580 | 604 | return vector->constEnd(); |
|
581 | 605 | if(key<((*vector)[0].key)) |
|
582 | 606 | return vector->constBegin(); |
|
583 | 607 | while (DX>1) |
|
584 | 608 | { |
|
585 | 609 | DX=DX/2; |
|
586 | 610 | if((*vector)[pos].key > key) |
|
587 | 611 | { |
|
588 | 612 | pos-=DX; |
|
589 | 613 | } |
|
590 | 614 | else |
|
591 | 615 | { |
|
592 | 616 | pos+=DX; |
|
593 | 617 | } |
|
594 | 618 | } |
|
595 | 619 | return vector->constBegin()+pos+1; |
|
596 | 620 | } |
|
597 | 621 | |
|
598 | 622 | |
|
599 | 623 | void QCPGraphVect::getVisibleDataBounds(QVector<QCPData>::const_iterator &lower, QVector<QCPData>::const_iterator &upper) const |
|
600 | 624 | { |
|
601 | 625 | if (!mKeyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } |
|
602 | 626 | if (mData->isEmpty()) |
|
603 | 627 | { |
|
604 | 628 | lower = mData->constEnd(); |
|
605 | 629 | upper = mData->constEnd(); |
|
606 | 630 | return; |
|
607 | 631 | } |
|
608 | 632 | QVector<QCPData>::const_iterator lbound = __lowerBoundDico_vect(mData,mKeyAxis.data()->range().lower); |
|
609 | 633 | QVector<QCPData>::const_iterator ubound = __upperBoundDico_vect(mData,mKeyAxis.data()->range().upper); |
|
610 | 634 | bool lowoutlier = lbound != mData->constBegin(); // indicates whether there exist points below axis range |
|
611 | 635 | bool highoutlier = ubound != mData->constEnd(); // indicates whether there exist points above axis range |
|
612 | 636 | |
|
613 | 637 | lower = (lowoutlier ? lbound-1 : lbound); // data point range that will be actually drawn |
|
614 | 638 | upper = (highoutlier ? ubound : ubound-1); // data point range that will be actually drawn |
|
615 | 639 | } |
|
616 | 640 | |
|
617 | 641 | int QCPGraphVect::countDataInBounds(const QVector<QCPData>::const_iterator &lower, const QVector<QCPData>::const_iterator &upper, int maxCount) const |
|
618 | 642 | { |
|
619 | 643 | if (upper == mData->constEnd() && lower == mData->constEnd()) |
|
620 | 644 | return 0; |
|
621 | 645 | QVector<QCPData>::const_iterator it = lower; |
|
622 | 646 | int count = 1; |
|
623 | 647 | while (it != upper && count < maxCount) |
|
624 | 648 | { |
|
625 | 649 | ++it; |
|
626 | 650 | ++count; |
|
627 | 651 | } |
|
628 | 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 | 25 | #ifndef QCUSTOMPLOTVECT_H |
|
2 | 26 | #define QCUSTOMPLOTVECT_H |
|
3 | 27 | |
|
4 | 28 | #include <QWidget> |
|
5 | 29 | #include <qcustomplot.h> |
|
6 | 30 | |
|
7 | 31 | class QCPGraphVect : public QCPGraph |
|
8 | 32 | { |
|
9 | 33 | Q_OBJECT |
|
10 | 34 | public: |
|
11 | 35 | explicit QCPGraphVect(QCPAxis *keyAxis, QCPAxis *valueAxis); |
|
12 | 36 | ~QCPGraphVect(); |
|
13 | 37 | QVector<QCPData> *data() const { return mData; } |
|
14 | 38 | void setData(QVector<QCPData> *data); |
|
15 | 39 | QVector<QCPData>* getVisibleData(); |
|
16 | 40 | protected: |
|
17 | 41 | QVector<QCPData>* mData; |
|
18 | 42 | virtual void draw(QCPPainter *painter); |
|
19 | 43 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface |
|
20 | 44 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; |
|
21 | 45 | void getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const; |
|
22 | 46 | void getVisibleDataBounds(QVector<QCPData>::const_iterator &lower, QVector<QCPData>::const_iterator &upper) const; |
|
23 | 47 | int countDataInBounds(const QVector<QCPData>::const_iterator &lower, const QVector<QCPData>::const_iterator &upper, int maxCount) const; |
|
24 | 48 | |
|
25 | 49 | void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const; |
|
26 | 50 | void getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const; |
|
27 | 51 | }; |
|
28 | 52 | |
|
29 | 53 | class QCustomPlotVect : public QCustomPlot |
|
30 | 54 | { |
|
31 | 55 | Q_OBJECT |
|
32 | 56 | public: |
|
33 | 57 | QCustomPlotVect(QWidget *parent = 0); |
|
34 | 58 | ~QCustomPlotVect(); |
|
35 | 59 | QCPGraphVect *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); |
|
36 | 60 | protected: |
|
37 | 61 | }; |
|
38 | 62 | |
|
39 | 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 | 23 | #include "qlopplots.h" |
|
2 | 24 | #include <QMainWindow> |
|
3 | 25 | |
|
4 | 26 | QLopPlots* QLopPlots::_self=NULL; |
|
5 | 27 | SocExplorerPlot* QLopPlots::m_LastPlot=NULL; |
|
6 | 28 | QDockWidget* QLopPlots::m_gui=NULL; |
|
7 | 29 | QHash<int,SocExplorerPlot*>* QLopPlots::m_plots=NULL; |
|
8 | 30 | toolBarContainer* QLopPlots::m_DocContainer=NULL; |
|
9 | 31 | |
|
10 | 32 | |
|
11 | 33 | #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();} |
|
12 | 34 | |
|
13 | 35 | |
|
14 | 36 | QLopPlots::QLopPlots(bool noGUI,QObject *parent) |
|
15 | 37 | { |
|
16 | 38 | m_noGui = noGUI; |
|
17 | 39 | m_serviceName = "QLopPlots"; |
|
18 | 40 | m_plots = new QHash<int,SocExplorerPlot*>(); |
|
19 | 41 | } |
|
20 | 42 | |
|
21 | 43 | QLopPlots::~QLopPlots() |
|
22 | 44 | { |
|
23 | 45 | |
|
24 | 46 | } |
|
25 | 47 | |
|
26 | 48 | int QLopPlots::getPlotID() |
|
27 | 49 | { |
|
28 | 50 | _INIT(); |
|
29 | 51 | for(int i=0;i<32768;i++) |
|
30 | 52 | { |
|
31 | 53 | if(!m_plots->contains(i)) |
|
32 | 54 | { |
|
33 | 55 | return i; |
|
34 | 56 | } |
|
35 | 57 | } |
|
36 | 58 | return -1; |
|
37 | 59 | } |
|
38 | 60 | |
|
39 | 61 | void QLopPlots::init(bool noGUI, QObject *parent) |
|
40 | 62 | { |
|
41 | 63 | if(Q_UNLIKELY(_self==NULL)) |
|
42 | 64 | { |
|
43 | 65 | _self=new QLopPlots(noGUI,parent); |
|
44 | 66 | } |
|
45 | 67 | } |
|
46 | 68 | |
|
47 | 69 | QLopPlots *QLopPlots::self() |
|
48 | 70 | { |
|
49 | 71 | _INIT(); |
|
50 | 72 | return _self; |
|
51 | 73 | } |
|
52 | 74 | |
|
53 | 75 | SocExplorerPlot *QLopPlots::getPlot(int plotID) |
|
54 | 76 | { |
|
55 | 77 | _INIT(); |
|
56 | 78 | if(!_self->m_noGui && (m_gui==NULL)) |
|
57 | 79 | { |
|
58 | 80 | m_gui=new QDockWidget("Plots"); |
|
59 | 81 | m_DocContainer = new toolBarContainer(); |
|
60 | 82 | // m_SocExplorerPlot = new SocExplorerPlot(); |
|
61 | 83 | m_gui->setWidget(m_DocContainer); |
|
62 | 84 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
63 | 85 | } |
|
64 | 86 | if(m_plots->contains(plotID)) |
|
65 | 87 | { |
|
66 | 88 | return m_plots->value(plotID); |
|
67 | 89 | } |
|
68 | 90 | if(plotID==-1) |
|
69 | 91 | { |
|
70 | 92 | return m_LastPlot; |
|
71 | 93 | } |
|
72 | 94 | return NULL; |
|
73 | 95 | } |
|
74 | 96 | |
|
75 | 97 | int QLopPlots::addPlot() |
|
76 | 98 | { |
|
77 | 99 | _INIT(); |
|
78 | 100 | int pid=getPlotID(); |
|
79 | 101 | if(pid!=-1) |
|
80 | 102 | { |
|
81 | 103 | SocExplorerPlot* plot=new SocExplorerPlot(); |
|
82 | 104 | plot->setPID(pid); |
|
83 | 105 | m_plots->insert(pid,plot); |
|
84 | 106 | QDockWidget* dock = new QDockWidget(); |
|
85 | 107 | dock->setWidget(plot); |
|
86 | 108 | dock->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
87 | 109 | m_DocContainer->addDockWidget(Qt::TopDockWidgetArea,dock); |
|
88 | 110 | m_LastPlot=plot; |
|
89 | 111 | QObject::connect(plot,SIGNAL(titleChanged(QString)),dock,SLOT(setWindowTitle(QString))); |
|
90 | 112 | plot->setTitle(QString("Plot %1").arg(pid)); |
|
91 | 113 | } |
|
92 | 114 | return pid; |
|
93 | 115 | } |
|
94 | 116 | |
|
95 | 117 | bool QLopPlots::removePlot(int plotID) |
|
96 | 118 | { |
|
97 | 119 | _INIT(); |
|
98 | 120 | if(m_plots->contains(plotID)) |
|
99 | 121 | { |
|
100 | 122 | SocExplorerPlot* plot=m_plots->value(plotID); |
|
101 | 123 | m_plots->remove(plotID); |
|
102 | 124 | QDockWidget* dock=(QDockWidget*)plot->parentWidget(); |
|
103 | 125 | m_DocContainer->removeDockWidget(dock); |
|
104 | 126 | if(plot==m_LastPlot) |
|
105 | 127 | { |
|
106 | 128 | //TODO may cause troubles... |
|
107 | 129 | m_LastPlot = NULL; |
|
108 | 130 | } |
|
109 | 131 | if(dock!=NULL) |
|
110 | 132 | { |
|
111 | 133 | delete dock; |
|
112 | 134 | } |
|
113 | 135 | if(plot!=NULL) |
|
114 | 136 | { |
|
115 | 137 | delete plot; |
|
116 | 138 | } |
|
117 | 139 | } |
|
118 | 140 | return false; |
|
119 | 141 | } |
|
120 | 142 | |
|
121 | 143 | QDockWidget *QLopPlots::getGUI() |
|
122 | 144 | { |
|
123 | 145 | if(!m_noGui && (m_gui==NULL)) |
|
124 | 146 | { |
|
125 | 147 | m_gui=new QDockWidget("Plots"); |
|
126 | 148 | m_DocContainer = new toolBarContainer(); |
|
127 | 149 | // m_SocExplorerPlot = new SocExplorerPlot(); |
|
128 | 150 | m_gui->setWidget(m_DocContainer); |
|
129 | 151 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
130 | 152 | } |
|
131 | 153 | return m_gui; |
|
132 | 154 | } |
|
133 | 155 | |
|
134 | 156 | const QString &QLopPlots::serviceName() |
|
135 | 157 | { |
|
136 | 158 | return m_serviceName; |
|
137 | 159 | } |
|
138 | 160 | |
|
139 | 161 | SocExplorerPlot *QLopPlots::get_plot(int plotID) |
|
140 | 162 | { |
|
141 | 163 | return getPlot(plotID); |
|
142 | 164 | } |
|
143 | 165 | |
|
144 | 166 | int QLopPlots::add_plot() |
|
145 | 167 | { |
|
146 | 168 | return addPlot(); |
|
147 | 169 | } |
|
148 | 170 | |
|
149 | 171 | bool QLopPlots::remove_plot(int plotID) |
|
150 | 172 | { |
|
151 | 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 | 23 | #ifndef QLOPPLOTS_H |
|
2 | 24 | #define QLOPPLOTS_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | #include <QWidget> |
|
6 | 28 | #include <qlopservice.h> |
|
7 | 29 | #include <SocExplorerPlot.h> |
|
8 | 30 | #include <QList> |
|
9 | 31 | #include <QHash> |
|
10 | 32 | #include <toolbarcontainer.h> |
|
11 | 33 | |
|
12 | 34 | class QLopPlots: public QLopService |
|
13 | 35 | { |
|
14 | 36 | Q_OBJECT |
|
15 | 37 | private: |
|
16 | 38 | static QLopPlots* _self; |
|
17 | 39 | static SocExplorerPlot* m_LastPlot; |
|
18 | 40 | static QHash<int,SocExplorerPlot*>* m_plots; |
|
19 | 41 | static QDockWidget* m_gui; |
|
20 | 42 | static toolBarContainer* m_DocContainer; |
|
21 | 43 | QLopPlots(bool noGUI=false,QObject *parent = 0); |
|
22 | 44 | ~QLopPlots(); |
|
23 | 45 | static int getPlotID(); |
|
24 | 46 | |
|
25 | 47 | public: |
|
26 | 48 | static void init(bool noGUI=false,QObject *parent = 0); |
|
27 | 49 | static QLopPlots *self(); |
|
28 | 50 | static SocExplorerPlot* getPlot(int plotID=-1); |
|
29 | 51 | static int addPlot(); |
|
30 | 52 | static bool removePlot(int plotID); |
|
31 | 53 | // QLopService methodes |
|
32 | 54 | QDockWidget* getGUI(); |
|
33 | 55 | const QString& serviceName(); |
|
34 | 56 | public slots: |
|
35 | 57 | SocExplorerPlot* get_plot(int plotID); |
|
36 | 58 | int add_plot(); |
|
37 | 59 | bool remove_plot(int plotID); |
|
38 | 60 | public: |
|
39 | 61 | }; |
|
40 | 62 | |
|
41 | 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 | 23 | #include "abstractfileloader.h" |
|
2 | 24 | |
|
3 | 25 | AbstractFileLoader::AbstractFileLoader(QObject *parent) : QThread(parent) |
|
4 | 26 | { |
|
5 | 27 | |
|
6 | 28 | } |
|
7 | 29 | |
|
8 | 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 | 23 | #ifndef ABSTRACTFILELOADER_H |
|
2 | 24 | #define ABSTRACTFILELOADER_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | #include <QThread> |
|
6 | 28 | #include "qcustomplot.h" |
|
7 | 29 | #include <qlopdata.h> |
|
8 | 30 | //typedef struct dataVector |
|
9 | 31 | //{ |
|
10 | 32 | // QString name; |
|
11 | 33 | // QString unit; |
|
12 | 34 | // QVector<QCPData>* data; |
|
13 | 35 | //}dataVector; |
|
14 | 36 | |
|
15 | 37 | //typedef QList<dataVector> QListOfDataVector; |
|
16 | 38 | |
|
17 | 39 | class AbstractFileLoader : public QThread |
|
18 | 40 | { |
|
19 | 41 | Q_OBJECT |
|
20 | 42 | public: |
|
21 | 43 | explicit AbstractFileLoader(QObject *parent = 0); |
|
22 | 44 | ~AbstractFileLoader(); |
|
23 | 45 | |
|
24 | 46 | virtual void parseFile(const QString &fileName)=0; |
|
25 | 47 | signals: |
|
26 | 48 | void dataReady(QLopDataList data); |
|
27 | 49 | void updateProgress(int threadId,int percentProgress); |
|
28 | 50 | |
|
29 | 51 | public slots: |
|
30 | 52 | }; |
|
31 | 53 | |
|
32 | 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 | 23 | #include "filedownloader.h" |
|
2 | 24 | #include <QFile> |
|
3 | 25 | FileDownloader* FileDownloader::_self=NULL; |
|
4 | 26 | QNetworkAccessManager* FileDownloader::m_WebCtrl=NULL; |
|
5 | 27 | QList<FileDownloaderTask*>* FileDownloader::m_pendingTasks=NULL; |
|
6 | 28 | QDockWidget* FileDownloader::m_gui=NULL; |
|
7 | 29 | DownLoadHistory* FileDownloader::m_DownLoadHistory=NULL; |
|
8 | 30 | |
|
9 | 31 | #define _INIT \ |
|
10 | 32 | if(Q_UNLIKELY(_self==NULL))\ |
|
11 | 33 | {\ |
|
12 | 34 | init();\ |
|
13 | 35 | }\ |
|
14 | 36 | |
|
15 | 37 | |
|
16 | 38 | int FileDownloader::downloadFile(QUrl fileUrl, const QString &name) |
|
17 | 39 | { |
|
18 | 40 | _INIT |
|
19 | 41 | if(QFile::exists(name)|| QFile::exists(name+".part")) |
|
20 | 42 | { |
|
21 | 43 | return -1; |
|
22 | 44 | } |
|
23 | 45 | FileDownloaderTask* task=NULL; |
|
24 | 46 | int ID=_self->getTaskId(); |
|
25 | 47 | if(ID!=-1) |
|
26 | 48 | { |
|
27 | 49 | QNetworkRequest request(fileUrl); |
|
28 | 50 | QNetworkReply* reply = m_WebCtrl->get(request); |
|
29 | 51 | if(reply && (reply->error()==QNetworkReply::NoError)) |
|
30 | 52 | { |
|
31 | 53 | task=new FileDownloaderTask(reply,ID,name,_self); |
|
32 | 54 | m_pendingTasks->append(task); |
|
33 | 55 | if(!_self->m_noGui) |
|
34 | 56 | { |
|
35 | 57 | m_DownLoadHistory->addElement(new DownloadHistoryElement(task)); |
|
36 | 58 | } |
|
37 | 59 | } |
|
38 | 60 | else |
|
39 | 61 | { |
|
40 | 62 | return -1; |
|
41 | 63 | } |
|
42 | 64 | } |
|
43 | 65 | return ID; |
|
44 | 66 | } |
|
45 | 67 | |
|
46 | 68 | int FileDownloader::downloadFile(QString fileUrl, const QString &name) |
|
47 | 69 | { |
|
48 | 70 | return downloadFile(QUrl(fileUrl),name); |
|
49 | 71 | } |
|
50 | 72 | |
|
51 | 73 | QDockWidget *FileDownloader::getGUI() |
|
52 | 74 | { |
|
53 | 75 | if(!_self->m_noGui && (m_gui==NULL)) |
|
54 | 76 | { |
|
55 | 77 | m_DownLoadHistory=new DownLoadHistory(); |
|
56 | 78 | m_gui=new QDockWidget("Download History"); |
|
57 | 79 | m_gui->setWidget(m_DownLoadHistory); |
|
58 | 80 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
59 | 81 | } |
|
60 | 82 | return (QDockWidget*) m_gui; |
|
61 | 83 | } |
|
62 | 84 | |
|
63 | 85 | const QString &FileDownloader::serviceName() |
|
64 | 86 | { |
|
65 | 87 | return m_serviceName; |
|
66 | 88 | } |
|
67 | 89 | |
|
68 | 90 | int FileDownloader::download_file(QUrl fileUrl, const QString &name) |
|
69 | 91 | { |
|
70 | 92 | return downloadFile(fileUrl,name); |
|
71 | 93 | } |
|
72 | 94 | |
|
73 | 95 | int FileDownloader::download_file(QString fileUrl, const QString &name) |
|
74 | 96 | { |
|
75 | 97 | return downloadFile(fileUrl,name); |
|
76 | 98 | } |
|
77 | 99 | |
|
78 | 100 | FileDownloaderTask* FileDownloader::getDownloadTask(int ID) |
|
79 | 101 | { |
|
80 | 102 | _INIT |
|
81 | 103 | for(int i=0;i<m_pendingTasks->count();i++) |
|
82 | 104 | { |
|
83 | 105 | if(m_pendingTasks->at(i)->ID()==ID) |
|
84 | 106 | return m_pendingTasks->at(i); |
|
85 | 107 | } |
|
86 | 108 | return NULL; |
|
87 | 109 | } |
|
88 | 110 | |
|
89 | 111 | bool FileDownloader::taskIsCompleted(int ID) |
|
90 | 112 | { |
|
91 | 113 | return getDownloadTask(ID)->downloadComplete(); |
|
92 | 114 | } |
|
93 | 115 | |
|
94 | 116 | FileDownloader *FileDownloader::self() |
|
95 | 117 | { |
|
96 | 118 | _INIT |
|
97 | 119 | return _self; |
|
98 | 120 | } |
|
99 | 121 | |
|
100 | 122 | int FileDownloader::getTaskId() |
|
101 | 123 | { |
|
102 | 124 | for(unsigned int i=0;i<INT_MAX;i++) |
|
103 | 125 | { |
|
104 | 126 | bool idValid=true; |
|
105 | 127 | for(int j=0;j<m_pendingTasks->count();j++) |
|
106 | 128 | { |
|
107 | 129 | if(m_pendingTasks->at(j)->ID()==(int)i) |
|
108 | 130 | idValid=false; |
|
109 | 131 | } |
|
110 | 132 | if(idValid) |
|
111 | 133 | return (int)i; |
|
112 | 134 | } |
|
113 | 135 | return -1; |
|
114 | 136 | } |
|
115 | 137 | |
|
116 | 138 | void FileDownloader::init(bool noGUI, QObject *parent) |
|
117 | 139 | { |
|
118 | 140 | if(Q_UNLIKELY(_self==NULL)) |
|
119 | 141 | { |
|
120 | 142 | _self=new FileDownloader(noGUI,parent); |
|
121 | 143 | } |
|
122 | 144 | } |
|
123 | 145 | |
|
124 | 146 | FileDownloader::FileDownloader(bool noGUI,QObject *parent) : QLopService(parent) |
|
125 | 147 | { |
|
126 | 148 | QNetworkProxyQuery q(QUrl("http://www.google.com")); |
|
127 | 149 | q.setQueryType(QNetworkProxyQuery::UrlRequest); |
|
128 | 150 | q.setProtocolTag("http"); |
|
129 | 151 | QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(q); |
|
130 | 152 | if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy ) |
|
131 | 153 | QNetworkProxy::setApplicationProxy(proxies[0]); |
|
132 | 154 | else |
|
133 | 155 | qDebug("No proxy server selected"); |
|
134 | 156 | m_WebCtrl = new QNetworkAccessManager(this); |
|
135 | 157 | m_pendingTasks = new QList<FileDownloaderTask*>(); |
|
136 | 158 | m_noGui=noGUI; |
|
137 | 159 | m_serviceName="FileDownloader"; |
|
138 | 160 | |
|
139 | 161 | } |
|
140 | 162 | |
|
141 | 163 | FileDownloader::~FileDownloader() |
|
142 | 164 | { |
|
143 | 165 | if(!m_noGui) |
|
144 | 166 | delete m_gui; |
|
145 | 167 | while (m_pendingTasks->count()) |
|
146 | 168 | { |
|
147 | 169 | FileDownloaderTask* task=m_pendingTasks->last(); |
|
148 | 170 | m_pendingTasks->removeLast(); |
|
149 | 171 | delete task; |
|
150 | 172 | } |
|
151 | 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 | 23 | #ifndef FILEDOWNLOADER_H |
|
2 | 24 | #define FILEDOWNLOADER_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | #include <QNetworkAccessManager> |
|
6 | 28 | #include <QNetworkReply> |
|
7 | 29 | #include <QNetworkProxy> |
|
8 | 30 | #include <QList> |
|
9 | 31 | #include <QHash> |
|
10 | 32 | #include <filedownloadertask.h> |
|
11 | 33 | #include <downloadhistory.h> |
|
12 | 34 | #include <qlopservice.h> |
|
13 | 35 | #include <QDockWidget> |
|
14 | 36 | |
|
15 | 37 | class FileDownloader : public QLopService |
|
16 | 38 | { |
|
17 | 39 | Q_OBJECT |
|
18 | 40 | private: |
|
19 | 41 | static FileDownloader* _self; |
|
20 | 42 | static QNetworkAccessManager* m_WebCtrl; |
|
21 | 43 | static QList<FileDownloaderTask*>* m_pendingTasks; |
|
22 | 44 | static DownLoadHistory* m_DownLoadHistory; |
|
23 | 45 | static QDockWidget* m_gui; |
|
24 | 46 | FileDownloader(bool noGUI=false,QObject *parent = 0); |
|
25 | 47 | ~FileDownloader(); |
|
26 | 48 | |
|
27 | 49 | public: |
|
28 | 50 | static void init(bool noGUI=false,QObject *parent = 0); |
|
29 | 51 | static int downloadFile(QUrl fileUrl,const QString& name); |
|
30 | 52 | static int downloadFile(QString fileUrl,const QString& name); |
|
31 | 53 | static FileDownloaderTask *getDownloadTask(int ID); |
|
32 | 54 | static bool taskIsCompleted(int ID); |
|
33 | 55 | static FileDownloader *self(); |
|
34 | 56 | // QLopService methodes |
|
35 | 57 | QDockWidget* getGUI(); |
|
36 | 58 | const QString& serviceName(); |
|
37 | 59 | signals: |
|
38 | 60 | |
|
39 | 61 | public slots: |
|
40 | 62 | int download_file(QUrl fileUrl,const QString& name); |
|
41 | 63 | int download_file(QString fileUrl,const QString& name); |
|
42 | 64 | private: |
|
43 | 65 | int getTaskId(); |
|
44 | 66 | }; |
|
45 | 67 | |
|
46 | 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 | 23 | #include "filedownloadertask.h" |
|
2 | 24 | |
|
3 | 25 | FileDownloaderTask::FileDownloaderTask(QNetworkReply *reply, int ID, const QString &fileName, QObject *parent) : QObject(parent) |
|
4 | 26 | { |
|
5 | 27 | this->m_Reply = reply; |
|
6 | 28 | this->m_downloadComplete = false; |
|
7 | 29 | this->m_FileName = fileName; |
|
8 | 30 | this->m_taskId = ID; |
|
9 | 31 | this->m_file = new QFile(fileName+".part"); |
|
10 | 32 | this->m_file->open(QIODevice::WriteOnly|QIODevice::Truncate); |
|
11 | 33 | this->m_startDateTime = QDateTime::currentDateTime(); |
|
12 | 34 | this->m_URL = m_Reply->url().toString(); |
|
13 | 35 | connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); |
|
14 | 36 | connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SIGNAL(updateProgress(qint64,qint64))); |
|
15 | 37 | connect(this->m_Reply,SIGNAL(readyRead()),this,SLOT(readReady())); |
|
16 | 38 | connect(this->m_Reply,SIGNAL(finished()),this,SLOT(downloadFinished())); |
|
17 | 39 | } |
|
18 | 40 | |
|
19 | 41 | FileDownloaderTask::~FileDownloaderTask() |
|
20 | 42 | { |
|
21 | 43 | delete m_file; |
|
22 | 44 | delete m_Reply; |
|
23 | 45 | } |
|
24 | 46 | |
|
25 | 47 | int FileDownloaderTask::ID(){return m_taskId;} |
|
26 | 48 | |
|
27 | 49 | const QString &FileDownloaderTask::fileName(){return m_FileName;} |
|
28 | 50 | |
|
29 | 51 | const QString &FileDownloaderTask::url(){return m_URL;} |
|
30 | 52 | |
|
31 | 53 | const QDateTime &FileDownloaderTask::startDateTime(){return m_startDateTime;} |
|
32 | 54 | |
|
33 | 55 | bool FileDownloaderTask::downloadComplete(){return m_downloadComplete;} |
|
34 | 56 | |
|
35 | 57 | void FileDownloaderTask::downloadProgress(qint64 bytesSent, qint64 bytesTotal) |
|
36 | 58 | { |
|
37 | 59 | if(bytesTotal!=0) |
|
38 | 60 | emit updateProgress((100*bytesSent)/bytesTotal); |
|
39 | 61 | } |
|
40 | 62 | |
|
41 | 63 | void FileDownloaderTask::readReady() |
|
42 | 64 | { |
|
43 | 65 | this->m_file->write(this->m_Reply->readAll()); |
|
44 | 66 | } |
|
45 | 67 | |
|
46 | 68 | void FileDownloaderTask::downloadFinished() |
|
47 | 69 | { |
|
48 | 70 | this->m_downloadComplete = true; |
|
49 | 71 | this->m_file->write(this->m_Reply->readAll()); |
|
50 | 72 | this->m_file->close(); |
|
51 | 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 | 23 | #ifndef FILEDOWNLOADERTASK_H |
|
2 | 24 | #define FILEDOWNLOADERTASK_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | #include <QByteArray> |
|
6 | 28 | #include <QNetworkAccessManager> |
|
7 | 29 | #include <QNetworkRequest> |
|
8 | 30 | #include <QNetworkReply> |
|
9 | 31 | #include <QFile> |
|
10 | 32 | #include <QDateTime> |
|
11 | 33 | |
|
12 | 34 | // TODO add download speed and remaining time. |
|
13 | 35 | |
|
14 | 36 | class FileDownloaderTask : public QObject |
|
15 | 37 | { |
|
16 | 38 | Q_OBJECT |
|
17 | 39 | public: |
|
18 | 40 | explicit FileDownloaderTask(QNetworkReply* reply,int ID,const QString& fileName,QObject *parent = 0); |
|
19 | 41 | ~FileDownloaderTask(); |
|
20 | 42 | int ID(); |
|
21 | 43 | const QString& fileName(); |
|
22 | 44 | const QString& url(); |
|
23 | 45 | const QDateTime& startDateTime(); |
|
24 | 46 | bool downloadComplete(); |
|
25 | 47 | signals: |
|
26 | 48 | void updateProgress(int percent); |
|
27 | 49 | void updateProgress(qint64 bytesSent, qint64 bytesTotal); |
|
28 | 50 | public slots: |
|
29 | 51 | |
|
30 | 52 | private slots: |
|
31 | 53 | void downloadProgress(qint64 bytesSent, qint64 bytesTotal); |
|
32 | 54 | void readReady(); |
|
33 | 55 | void downloadFinished(); |
|
34 | 56 | private: |
|
35 | 57 | int m_taskId; |
|
36 | 58 | QNetworkReply* m_Reply; |
|
37 | 59 | QByteArray m_DownloadedData; |
|
38 | 60 | bool m_downloadComplete; |
|
39 | 61 | QFile* m_file; |
|
40 | 62 | QString m_FileName; |
|
41 | 63 | QString m_URL; |
|
42 | 64 | QDateTime m_startDateTime; |
|
43 | 65 | }; |
|
44 | 66 | |
|
45 | 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 | 23 | #ifndef QLOP |
|
2 | 24 | #define QLOP |
|
3 | 25 | #ifdef WIN32 |
|
4 | 26 | #define QLOP_PLUGINS_INSTALL_PATH qApp->applicationDirPath()+"/plugins" |
|
5 | 27 | #define QLOP_CONFIG_PATH qApp->applicationDirPath()+"/config" |
|
6 | 28 | #define PYMODULES qApp->applicationDirPath()+"/python" |
|
7 | 29 | #else |
|
8 | 30 | #ifdef UNIX |
|
9 | 31 | #define QLOP_PLUGINS_INSTALL_PATH QDir::homePath()+"/.QLop/plugins" |
|
10 | 32 | #define QLOP_CONFIG_PATH QDir::homePath()+"/.QLop/config" |
|
11 | 33 | #define PYMODULES "/etc/QLop/python" |
|
12 | 34 | #endif |
|
13 | 35 | #endif |
|
14 | 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 | 23 | #include "qlopdata.h" |
|
2 | 24 | |
|
3 | 25 | QLopData::QLopData(QObject *parent) : QObject(parent) |
|
4 | 26 | { |
|
5 | 27 | |
|
6 | 28 | } |
|
7 | 29 | |
|
8 | 30 | QLopData::~QLopData() |
|
9 | 31 | { |
|
10 | 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 | 23 | #ifndef QLOPDATA_H |
|
2 | 24 | #define QLOPDATA_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | #include <qcustomplot.h> |
|
6 | 28 | |
|
7 | 29 | typedef struct dataVector |
|
8 | 30 | { |
|
9 | 31 | QString name; |
|
10 | 32 | QString unit; |
|
11 | 33 | QVector<QCPData>* data; |
|
12 | 34 | }dataVector; |
|
13 | 35 | |
|
14 | 36 | typedef QList<dataVector> QListOfDataVector; |
|
15 | 37 | |
|
16 | 38 | |
|
17 | 39 | |
|
18 | 40 | class QLopData : public QObject |
|
19 | 41 | { |
|
20 | 42 | Q_OBJECT |
|
21 | 43 | public: |
|
22 | 44 | explicit QLopData(QObject *parent = 0); |
|
23 | 45 | ~QLopData(); |
|
24 | 46 | QString name; |
|
25 | 47 | QString unit; |
|
26 | 48 | QVector<QCPData>* data; |
|
27 | 49 | signals: |
|
28 | 50 | void dataChanged(); |
|
29 | 51 | public slots: |
|
30 | 52 | private: |
|
31 | 53 | }; |
|
32 | 54 | typedef QList<QLopData*> QLopDataList; |
|
33 | 55 | |
|
34 | 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 | 23 | #include "qlopservice.h" |
|
2 | 24 | |
|
3 | 25 | QLopService::QLopService(QObject *parent) : QObject(parent) |
|
4 | 26 | { |
|
5 | 27 | |
|
6 | 28 | } |
|
7 | 29 | |
|
8 | 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 | 23 | #ifndef QLOPSERVICE_H |
|
2 | 24 | #define QLOPSERVICE_H |
|
3 | 25 | |
|
4 | 26 | #include <QObject> |
|
5 | 27 | #include <QWidget> |
|
6 | 28 | #include <QDockWidget> |
|
7 | 29 | |
|
8 | 30 | class QLopService : public QObject |
|
9 | 31 | { |
|
10 | 32 | Q_OBJECT |
|
11 | 33 | public: |
|
12 | 34 | explicit QLopService(QObject *parent = 0); |
|
13 | 35 | ~QLopService(); |
|
14 | 36 | virtual QDockWidget* getGUI()=0; |
|
15 | 37 | virtual const QString& serviceName(){return m_serviceName;} |
|
16 | 38 | signals: |
|
17 | 39 | |
|
18 | 40 | public slots: |
|
19 | 41 | protected: |
|
20 | 42 | bool m_noGui; |
|
21 | 43 | QString m_serviceName; |
|
22 | 44 | }; |
|
23 | 45 | |
|
24 | 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 | 2 | -- This file is a part of the QLop Software |
|
3 | 3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 2 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | ----------------------------------------------------------------------------*/ |
|
22 | 22 | #include "SocExplorerPlot.h" |
|
23 | 23 | #include <QSvgGenerator> |
|
24 | 24 | #include <qcpdocumentobject.h> |
|
25 | 25 | #include <QPdfWriter> |
|
26 | 26 | #include <QPrinter> |
|
27 | 27 | |
|
28 | 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); | |
|
32 | this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | | |
|
33 | QCP::iSelectLegend | QCP::iSelectPlottables); | |
|
34 | this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical); | |
|
35 | this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); | |
|
36 | this->m_mainlayout = new QGridLayout(this); | |
|
37 | this->setLayout(this->m_mainlayout); | |
|
38 | this->m_mainlayout->addWidget(this->m_plot); | |
|
39 | this->setMinimumSize(400,300); | |
|
40 | this->setFocusPolicy(Qt::WheelFocus); | |
|
41 | this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); | |
|
42 | this->ctrl_hold = false; | |
|
43 | this->shift_hold = false; | |
|
44 | this->mouse_hold = false; | |
|
45 | this->m_plot->setNoAntialiasingOnDrag(true); | |
|
46 | this->show(); | |
|
47 | this->m_plot->legend->setVisible(true); | |
|
31 | this->m_plot = new QCustomPlotVect(this); | |
|
32 | this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | | |
|
33 | QCP::iSelectLegend | QCP::iSelectPlottables); | |
|
34 | this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical); | |
|
35 | this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); | |
|
36 | this->m_mainlayout = new QGridLayout(this); | |
|
37 | this->setLayout(this->m_mainlayout); | |
|
38 | this->m_mainlayout->addWidget(this->m_plot); | |
|
39 | this->setMinimumSize(400,300); | |
|
40 | this->setFocusPolicy(Qt::WheelFocus); | |
|
41 | this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); | |
|
42 | this->ctrl_hold = false; | |
|
43 | this->shift_hold = false; | |
|
44 | this->mouse_hold = false; | |
|
45 | this->m_plot->setNoAntialiasingOnDrag(true); | |
|
46 | this->show(); | |
|
47 | this->m_plot->legend->setVisible(true); | |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | SocExplorerPlot::~SocExplorerPlot() |
|
51 | 51 | { |
|
52 | delete mRubberBand; | |
|
52 | delete mRubberBand; | |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | void SocExplorerPlot::show() |
|
56 | 56 | { |
|
57 | QWidget::show(); | |
|
57 | QWidget::show(); | |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void SocExplorerPlot::replot() |
|
61 | 61 | { |
|
62 | 62 | this->m_plot->replot(); |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | void SocExplorerPlot::exportToSVG(const QString &fileName) |
|
66 | 66 | { |
|
67 | 67 | QSvgGenerator printer; |
|
68 | 68 | printer.setFileName(fileName); |
|
69 | 69 | QCPPainter qcpPainter; |
|
70 | 70 | qcpPainter.begin(&printer); |
|
71 | 71 | m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height()); |
|
72 | 72 | qcpPainter.end(); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void SocExplorerPlot::exportToPDF(const QString &fileName) |
|
76 | 76 | { |
|
77 | 77 | QPrinter printer(QPrinter::HighResolution); |
|
78 | 78 | printer.setOutputFormat(QPrinter::PdfFormat); |
|
79 | 79 | printer.setOrientation(QPrinter::Landscape); |
|
80 | 80 | printer.setOutputFileName(fileName); |
|
81 | 81 | printer.setFullPage(true); |
|
82 | 82 | QCPPainter qcpPainter; |
|
83 | 83 | qcpPainter.begin(&printer); |
|
84 | 84 | m_plot->toPainter(&qcpPainter, printer.width(), printer.height()); |
|
85 | 85 | qcpPainter.end(); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | void SocExplorerPlot::addAction(SocExplorerPlotActions *action) |
|
89 | 89 | { |
|
90 | 90 | this->m_actions.append(action); |
|
91 | 91 | QWidget::addAction((QAction*)action); |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex) |
|
95 | 95 | { |
|
96 | 96 | QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData(); |
|
97 | 97 | return visibleData; |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | void SocExplorerPlot::setTitle(QString title) |
|
101 | 101 | { |
|
102 | Q_UNUSED(title) | |
|
103 | //this->m_plot->setTitle(title); | |
|
104 | /*! | |
|
102 | Q_UNUSED(title) | |
|
103 | //this->m_plot->setTitle(title); | |
|
104 | /*! | |
|
105 | 105 | @todo Function borcken fixe this! |
|
106 | 106 | */ |
|
107 | 107 | this->m_Title = title; |
|
108 | 108 | emit titleChanged(title); |
|
109 | 109 | this->repaint(); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | const QString &SocExplorerPlot::title() |
|
113 | 113 | { |
|
114 | 114 | return m_Title; |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void SocExplorerPlot::setXaxisLabel(QString label) |
|
118 | 118 | { |
|
119 | this->m_plot->xAxis->setLabel(label); | |
|
119 | this->m_plot->xAxis->setLabel(label); | |
|
120 | 120 | this->repaint(); |
|
121 | 121 | } |
|
122 | 122 | |
|
123 | 123 | void SocExplorerPlot::setXaxisLog() |
|
124 | 124 | { |
|
125 | 125 | this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic); |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | void SocExplorerPlot::setYaxisLabel(QString label) |
|
129 | 129 | { |
|
130 | this->m_plot->yAxis->setLabel(label); | |
|
130 | this->m_plot->yAxis->setLabel(label); | |
|
131 | 131 | this->repaint(); |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | void SocExplorerPlot::setYaxisLog() |
|
135 | 135 | { |
|
136 | 136 | this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic); |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 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 | 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 | 150 | void SocExplorerPlot::rescaleAxis() |
|
151 | 151 | { |
|
152 | this->m_plot->rescaleAxes(); | |
|
153 | this->m_plot->replot(); | |
|
152 | this->m_plot->rescaleAxes(); | |
|
153 | this->m_plot->replot(); | |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | void SocExplorerPlot::setLegendFont(QFont font) |
|
157 | 157 | { |
|
158 | this->m_plot->legend->setFont(font); | |
|
159 | this->repaint(); | |
|
158 | this->m_plot->legend->setFont(font); | |
|
159 | this->repaint(); | |
|
160 | 160 | } |
|
161 | 161 | |
|
162 | 162 | void SocExplorerPlot::setLegendSelectedFont(QFont font) |
|
163 | 163 | { |
|
164 | this->m_plot->legend->setSelectedFont(font); | |
|
165 | this->repaint(); | |
|
164 | this->m_plot->legend->setSelectedFont(font); | |
|
165 | this->repaint(); | |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 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 | 173 | void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable) |
|
174 | 174 | { |
|
175 | 175 | // TODO deprecated |
|
176 | // this->m_plot->graph(graphIndex)->setUseFastVectors(enable); | |
|
176 | // this->m_plot->graph(graphIndex)->setUseFastVectors(enable); | |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | int SocExplorerPlot::addGraph() |
|
180 | 180 | { |
|
181 | this->m_plot->addGraph(); | |
|
182 | return this->m_plot->graphCount() -1; | |
|
181 | this->m_plot->addGraph(); | |
|
182 | return this->m_plot->graphCount() -1; | |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | bool SocExplorerPlot::removeGraph(int graphIndex) |
|
186 | 186 | { |
|
187 | 187 | return this->m_plot->removeGraph(graphIndex); |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | 190 | int SocExplorerPlot::graphCount() |
|
191 | 191 | { |
|
192 | 192 | return m_plot->graphCount(); |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | void SocExplorerPlot::removeAllGraphs() |
|
196 | 196 | { |
|
197 | int graphCount=this->m_plot->graphCount(); | |
|
198 | for(int i=0;i<graphCount;i++) | |
|
197 | int graphCount=this->m_plot->graphCount(); | |
|
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 | 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); | |
|
210 | } | |
|
209 | this->m_plot->graph(graphIndex)->setName(name); | |
|
210 | } | |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | const QString &SocExplorerPlot::graphName(int graphIndex) |
|
214 | 214 | { |
|
215 | 215 | if(graphIndex<this->m_plot->graphCount()) |
|
216 | 216 | { |
|
217 | 217 | return this->m_plot->graph(graphIndex)->name(); |
|
218 | 218 | } |
|
219 | 219 | return ""; |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | |
|
223 | 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()); | |
|
228 | for(int i=0;i<x.count();i++) | |
|
227 | QVector<double> _x(x.count()), _y(y.count()); | |
|
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 | 231 | _y[i] = y.at(i).value<double>();*/ |
|
232 | _x[i] = x.at(i).toDouble(); | |
|
233 | _y[i] = y.at(i).toDouble(); | |
|
232 | _x[i] = x.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()); | |
|
242 | for(int i=0;i<x.count();i++) | |
|
241 | QVector<double> _x(x.count()), _y(y.count()); | |
|
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 | 245 | _y[i] = y.at(i).value<double>();*/ |
|
246 | _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); | |
|
247 | _y[i] = y.at(i).toDouble(); | |
|
246 | _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); | |
|
247 | _y[i] = y.at(i).toDouble(); | |
|
248 | 248 | } |
|
249 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |
|
250 | this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); | |
|
251 | this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz"); | |
|
249 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |
|
250 | this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); | |
|
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 | 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) | |
|
265 | this->m_plot->replot(); | |
|
264 | if(replot) | |
|
265 | this->m_plot->replot(); | |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 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) | |
|
275 | this->m_plot->replot(); | |
|
274 | if(replot) | |
|
275 | this->m_plot->replot(); | |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 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()); | |
|
283 | for(int i=0;i<x.count();i++) | |
|
282 | QVector<double> _x(x.count()), _y(y.count()); | |
|
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 | 286 | _y[i] = y.at(i).value<double>();*/ |
|
287 | _x[i] = x.at(i).toDouble(); | |
|
288 | _y[i] = y.at(i).toDouble(); | |
|
287 | _x[i] = x.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 | 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 | 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 | 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 | 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); | |
|
330 | return; | |
|
329 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); | |
|
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); | |
|
335 | return; | |
|
334 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); | |
|
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); | |
|
340 | return; | |
|
339 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); | |
|
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); | |
|
345 | return; | |
|
344 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); | |
|
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); | |
|
350 | return; | |
|
349 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); | |
|
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); | |
|
355 | return; | |
|
354 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); | |
|
355 | return; | |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | |
|
359 | 359 | } |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 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); | |
|
369 | return; | |
|
368 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); | |
|
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); | |
|
374 | return; | |
|
373 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); | |
|
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); | |
|
379 | return; | |
|
378 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); | |
|
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); | |
|
384 | return; | |
|
383 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); | |
|
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); | |
|
389 | return; | |
|
388 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); | |
|
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); | |
|
394 | return; | |
|
393 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); | |
|
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); | |
|
399 | return; | |
|
398 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); | |
|
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); | |
|
404 | return; | |
|
403 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); | |
|
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); | |
|
409 | return; | |
|
408 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); | |
|
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); | |
|
414 | return; | |
|
413 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); | |
|
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); | |
|
419 | return; | |
|
418 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); | |
|
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); | |
|
424 | return; | |
|
423 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); | |
|
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); | |
|
429 | return; | |
|
428 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); | |
|
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); | |
|
434 | return; | |
|
433 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); | |
|
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); | |
|
439 | return; | |
|
438 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); | |
|
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); | |
|
444 | return; | |
|
443 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); | |
|
444 | return; | |
|
445 | 445 | } |
|
446 | 446 | |
|
447 | 447 | } |
|
448 | 448 | } |
|
449 | 449 | |
|
450 | 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 | 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 | 464 | void SocExplorerPlot::keyPressEvent(QKeyEvent * event) |
|
465 | 465 | { |
|
466 | switch(event->key()) | |
|
466 | switch(event->key()) | |
|
467 | 467 | { |
|
468 | 468 | case Qt::Key_Control: |
|
469 | this->ctrl_hold = true; | |
|
470 | setCursor(Qt::CrossCursor); | |
|
471 | break; | |
|
469 | this->ctrl_hold = true; | |
|
470 | setCursor(Qt::CrossCursor); | |
|
471 | break; | |
|
472 | 472 | case Qt::Key_Shift: |
|
473 | this->shift_hold = true; | |
|
474 | break; | |
|
473 | this->shift_hold = true; | |
|
474 | break; | |
|
475 | 475 | case Qt::Key_M: |
|
476 | this->rescaleAxis(); | |
|
477 | break; | |
|
476 | this->rescaleAxis(); | |
|
477 | break; | |
|
478 | 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 | 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 | 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 | 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 | 518 | default: |
|
519 | QWidget::keyPressEvent(event); | |
|
520 | break; | |
|
519 | QWidget::keyPressEvent(event); | |
|
520 | break; | |
|
521 | 521 | } |
|
522 | 522 | } |
|
523 | 523 | |
|
524 | 524 | void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) |
|
525 | 525 | { |
|
526 | switch(event->key()) | |
|
526 | switch(event->key()) | |
|
527 | 527 | { |
|
528 | 528 | case Qt::Key_Control: |
|
529 | event->accept(); | |
|
530 | this->ctrl_hold = false; | |
|
531 | break; | |
|
529 | event->accept(); | |
|
530 | this->ctrl_hold = false; | |
|
531 | break; | |
|
532 | 532 | case Qt::Key_Shift: |
|
533 | event->accept(); | |
|
534 | this->shift_hold = false; | |
|
535 | break; | |
|
533 | event->accept(); | |
|
534 | this->shift_hold = false; | |
|
535 | break; | |
|
536 | 536 | default: |
|
537 | QWidget::keyReleaseEvent(event); | |
|
538 | break; | |
|
537 | QWidget::keyReleaseEvent(event); | |
|
538 | break; | |
|
539 | 539 | } |
|
540 | setCursor(Qt::ArrowCursor); | |
|
540 | setCursor(Qt::ArrowCursor); | |
|
541 | 541 | } |
|
542 | 542 | |
|
543 | 543 | void SocExplorerPlot::wheelEvent(QWheelEvent * event) |
|
544 | 544 | { |
|
545 | double factor; | |
|
546 | double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually | |
|
547 | if(ctrl_hold) | |
|
545 | double factor; | |
|
546 | double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually | |
|
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); | |
|
552 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); | |
|
553 | zoom(factor,event->pos().y(),Qt::Vertical); | |
|
551 | setCursor(Qt::SizeVerCursor); | |
|
552 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); | |
|
553 | zoom(factor,event->pos().y(),Qt::Vertical); | |
|
554 | 554 | } |
|
555 | QWidget::wheelEvent(event); | |
|
556 | return; | |
|
555 | QWidget::wheelEvent(event); | |
|
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); | |
|
563 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); | |
|
564 | zoom(factor,event->pos().x(),Qt::Horizontal); | |
|
562 | setCursor(Qt::SizeHorCursor); | |
|
563 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); | |
|
564 | zoom(factor,event->pos().x(),Qt::Horizontal); | |
|
565 | 565 | } |
|
566 | QWidget::wheelEvent(event); | |
|
567 | return; | |
|
566 | QWidget::wheelEvent(event); | |
|
567 | return; | |
|
568 | 568 | } |
|
569 |
move(wheelSteps |
|
|
570 | QWidget::wheelEvent(event); | |
|
569 | move(wheelSteps,Qt::Horizontal); | |
|
570 | QWidget::wheelEvent(event); | |
|
571 | 571 | } |
|
572 | 572 | |
|
573 | 573 | |
|
574 | 574 | |
|
575 | 575 | |
|
576 | 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); | |
|
583 | mOrigin = event->pos(); | |
|
584 | mRubberBand->setGeometry(QRect(mOrigin, QSize())); | |
|
585 | mRubberBand->show(); | |
|
582 | setCursor(Qt::CrossCursor); | |
|
583 | mOrigin = event->pos(); | |
|
584 | mRubberBand->setGeometry(QRect(mOrigin, QSize())); | |
|
585 | mRubberBand->show(); | |
|
586 | 586 | } |
|
587 | else | |
|
587 | else | |
|
588 | 588 | { |
|
589 | setCursor(Qt::ClosedHandCursor); | |
|
590 | mDragStart = event->pos(); | |
|
591 | this->mouse_hold = true; | |
|
592 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); | |
|
593 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); | |
|
589 | setCursor(Qt::ClosedHandCursor); | |
|
590 | mDragStart = event->pos(); | |
|
591 | this->mouse_hold = true; | |
|
592 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->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 | 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(); | |
|
608 | int xp1, yp1, xp2, yp2; | |
|
609 | zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2); | |
|
610 | double x1 = this->m_plot->xAxis->pixelToCoord(xp1); | |
|
611 | double x2 = this->m_plot->xAxis->pixelToCoord(xp2); | |
|
612 | double y1 = this->m_plot->yAxis->pixelToCoord(yp1); | |
|
613 | double y2 = this->m_plot->yAxis->pixelToCoord(yp2); | |
|
607 | const QRect & zoomRect = mRubberBand->geometry(); | |
|
608 | int xp1, yp1, xp2, yp2; | |
|
609 | zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2); | |
|
610 | double x1 = this->m_plot->xAxis->pixelToCoord(xp1); | |
|
611 | double x2 = this->m_plot->xAxis->pixelToCoord(xp2); | |
|
612 | double y1 = this->m_plot->yAxis->pixelToCoord(yp1); | |
|
613 | double y2 = this->m_plot->yAxis->pixelToCoord(yp2); | |
|
614 | 614 | |
|
615 | this->m_plot->xAxis->setRange(x1, x2); | |
|
616 | this->m_plot->yAxis->setRange(y1, y2); | |
|
615 | this->m_plot->xAxis->setRange(x1, x2); | |
|
616 | this->m_plot->yAxis->setRange(y1, y2); | |
|
617 | 617 | |
|
618 | mRubberBand->hide(); | |
|
619 | this->m_plot->replot(); | |
|
618 | mRubberBand->hide(); | |
|
619 | this->m_plot->replot(); | |
|
620 | 620 | } |
|
621 | setCursor(Qt::ArrowCursor); | |
|
622 | QWidget::mouseReleaseEvent(event); | |
|
621 | setCursor(Qt::ArrowCursor); | |
|
622 | QWidget::mouseReleaseEvent(event); | |
|
623 | 623 | } |
|
624 | 624 | |
|
625 | 625 | void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation) |
|
626 | 626 | { |
|
627 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation); | |
|
628 | axis->scaleRange(factor, axis->pixelToCoord(center)); | |
|
629 | this->m_plot->replot(); | |
|
627 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation); | |
|
628 | axis->scaleRange(factor, axis->pixelToCoord(center)); | |
|
629 | this->m_plot->replot(); | |
|
630 | 630 | } |
|
631 | 631 | |
|
632 | 632 | void SocExplorerPlot::move(double factor, Qt::Orientation orientation) |
|
633 | 633 | { |
|
634 | QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation); | |
|
635 | double rg = (axis->range().upper - axis->range().lower)*(factor); | |
|
636 | axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | |
|
637 | this->m_plot->replot(); | |
|
634 | QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation); | |
|
635 | // double rg = (axis->range().upper - axis->range().lower)*(factor); | |
|
636 | // axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | |
|
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 | 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); | |
|
646 | QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical); | |
|
647 |
double diff = |
|
|
648 |
|
|
|
649 | diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y()); | |
|
650 | Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff); | |
|
651 | this->m_plot->replot(); | |
|
672 | QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |
|
673 | QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical); | |
|
674 | // double diff = rangeDragHorzAxis->pixelToCoord(mDragStart.x()) / rangeDragHorzAxis->pixelToCoord(event->pos().x()); | |
|
675 | // rangeDragHorzAxis->setRange(mDragStartHorzRange.lower*diff, mDragStartHorzRange.upper*diff); | |
|
676 | double diff=0; | |
|
677 | if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) | |
|
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