##// END OF EJS Templates
QLop dataBase started, WIP.
jeandet -
r12:ae7af17c2621 default
parent child
Show More
@@ -0,0 +1,83
1 #include "qlopdatabase.h"
2
3 QList<QLopData*>* QLopDataBase::m_dataBase=NULL;
4 QLopDataBase* QLopDataBase::_self=NULL;
5
6 #define INIT() \
7 if(Q_UNLIKELY(_self==NULL))\
8 {\
9 init();\
10 }
11
12 QLopDataBase::QLopDataBase(QObject *parent) : QObject(parent)
13 {
14 this->m_dataBase = new QList<QLopData*>();
15 }
16
17 QLopDataBase::~QLopDataBase()
18 {
19
20 }
21
22 void QLopDataBase::init()
23 {
24 _self=new QLopDataBase();
25 }
26
27 int QLopDataBase::addData(QLopData *data)
28 {
29 INIT();
30 if(!m_dataBase->contains(data))
31 {
32 m_dataBase->append(data);
33 return 1;
34 }
35 return 0;
36 }
37
38 int QLopDataBase::addData(const QLopDataList& data)
39 {
40 INIT();
41 int addedData=0;
42 for (int i = 0; i < data.count(); i++)
43 {
44 addedData += addData(data.at(i));
45 }
46 return addedData;
47 }
48
49 QLopDataBase *QLopDataBase::self()
50 {
51 INIT();
52 return _self;
53 }
54
55 int QLopDataBase::count()
56 {
57 return m_dataBase->count();
58 }
59
60 QLopData *QLopDataBase::getData(const QString &name)
61 {
62 for (int i = 0; i < m_dataBase->count(); i++)
63 {
64 if(Q_UNLIKELY(m_dataBase->at(i)->name==name))
65 {
66 return m_dataBase->at(i);
67 }
68 }
69 return NULL;
70 }
71
72 QLopData *QLopDataBase::getData(int ID)
73 {
74 for (int i = 0; i < m_dataBase->count(); i++)
75 {
76 if(Q_UNLIKELY(m_dataBase->at(i)->ID==ID))
77 {
78 return m_dataBase->at(i);
79 }
80 }
81 return NULL;
82 }
83
@@ -0,0 +1,29
1 #ifndef QLOPDATABASE_H
2 #define QLOPDATABASE_H
3
4 #include <QObject>
5 #include <qlopdata.h>
6 #include <QList>
7
8 class QLopDataBase : public QObject
9 {
10 Q_OBJECT
11 explicit QLopDataBase(QObject *parent = 0);
12 ~QLopDataBase();
13 static QLopDataBase* _self;
14 public:
15 static void init();
16 static int addData(QLopData* data);
17 static int addData(const QLopDataList &data);
18 static QLopDataBase* self();
19 static int count();
20 static QLopData* getData(const QString& name);
21 static QLopData* getData(int ID);
22 signals:
23
24 public slots:
25 private:
26 static QList<QLopData*>* m_dataBase;
27 };
28
29 #endif // QLOPDATABASE_H
@@ -1,110 +1,112
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 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 src/Core/Widgets/qcustomplotvect.cpp
56 src/Core/Widgets/qcustomplotvect.cpp \
57 src/Core/qlopdatabase.cpp
57 58
58 59 HEADERS += src/mainwindow.h \
59 60 src/SocExplorerPlot.h \
60 61 src/QCustomPlot/qcustomplot.h \
61 62 src/toolbarcontainer.h \
62 63 src/Core/abstractfileloader.h \
63 64 src/Core/filedownloader.h \
64 65 src/Core/filedownloadertask.h \
65 66 src/Core/Widgets/downloadhistory.h \
66 67 src/Core/Widgets/downloadhistoryelement.h \
67 68 src/Core/qlopservice.h \
68 69 src/Cassini/expxmldownloader.h \
69 70 src/Cassini/cassinidatadownloader.h \
70 71 src/Cassini/cassinidatafile.h \
71 72 src/Cassini/cassiniindexfile.h \
72 73 src/Cassini/cassiniindexfileviewer.h \
73 74 src/Cassini/cassinitools.h \
74 75 src/Cassini/cassinitoolsgui.h \
75 76 src/Core/Widgets/qlopplots.h \
76 77 src/Core/qlopdata.h \
77 78 src/Core/Widgets/PyWdgt/pythonconsole.h \
78 79 src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.h \
79 80 src/Core/qlop.h \
80 81 src/Core/pyqlop.h \
81 82 src/QCustomPlot/qcpdocumentobject.h \
82 83 src/Core/Widgets/filebrowser.h \
83 84 src/Core/Widgets/filesystemmodel.h \
84 src/Core/Widgets/qcustomplotvect.h
85 src/Core/Widgets/qcustomplotvect.h \
86 src/Core/qlopdatabase.h
85 87
86 88 FORMS += src/mainwindow.ui \
87 89 src/Core/Widgets/downloadhistory.ui \
88 90 src/Core/Widgets/downloadhistoryelement.ui \
89 91 src/Cassini/cassinidatadownloader.ui \
90 92 src/Cassini/cassiniindexfileviewer.ui \
91 93 src/Cassini/cassinitoolsgui.ui \
92 94 src/Core/Widgets/filebrowser.ui
93 95
94 96 RESOURCES += \
95 97 resources/qlop.qrc
96 98
97 99 include(src/Core/Widgets/NicePyConsole/NicePyConsole.pri)
98 100 include(src/Core/pythonQtOut/generated_cpp/PyQLop/PyQLop.pri)
99 101
100 102 win32 {
101 103 DEFINES += WIN32
102 104 }
103 105
104 106 unix {
105 107 DEFINES += UNIX
106 108 }
107 109
108 110 DISTFILES += \
109 111 src/Core/pythongenerator.sh \
110 112 src/Core/pythonQtgeneratorCfg.txt
@@ -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 QLopData* ch1V=new QLopData();
207 QLopData* ch2V=new QLopData();
208 QLopData* ch3V=new QLopData();
206 QLopDataVector* ch1V=new QLopDataVector();
207 QLopDataVector* ch2V=new QLopDataVector();
208 QLopDataVector* ch3V=new QLopDataVector();
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 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 QLopData* ch1V=m_data.at(0);
285 QLopData* ch2V=m_data.at(1);
286 QLopData* ch3V=m_data.at(2);
284 QLopDataVector* ch1V=(QLopDataVector*)m_data.at(0);
285 QLopDataVector* ch2V=(QLopDataVector*)m_data.at(1);
286 QLopDataVector* ch3V=(QLopDataVector*)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,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
23 23 #include "cassinitools.h"
24 24 #include <qlopplots.h>
25 25 #include <QPen>
26 26 #include <QAction>
27 27 #include <fftw3.h>
28 28 #include <omp.h>
29 29
30 30 CassiniTools* CassiniTools::_self=NULL;
31 31 QDockWidget* CassiniTools::m_gui=NULL;
32 32 CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL;
33 33 CassiniDataFile* CassiniTools::m_dataFile=NULL;
34 34 int CassiniTools::m_defaultPlot=-1;
35 35 int CassiniTools::m_fftPlot=-1;
36 36 SocExplorerPlotActions* CassiniTools::ExportAction=NULL;
37 37
38 38 Qt::GlobalColor QLopColours[]= {Qt::black,
39 39 Qt::red,
40 40 Qt::blue,
41 41 Qt::green,
42 42 Qt::darkGreen,
43 43 Qt::cyan,
44 44 Qt::darkRed,
45 45 Qt::gray,
46 46 Qt::yellow,
47 47 Qt::darkBlue,
48 48 Qt::darkCyan,
49 49 Qt::magenta,
50 50 Qt::darkMagenta,
51 51 Qt::darkYellow,
52 52 Qt::darkGray,
53 53 Qt::lightGray};
54 54
55 55 int QLopColoursCount=16;
56 56
57 57 #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();}
58 58
59 59 CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent)
60 60 {
61 61 m_dataFile = new CassiniDataFile();
62 62 connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList)));
63 63 m_serviceName="CassiniTools";
64 64 m_noGui=noGUI;
65 65 fftw_init_threads();
66 66 }
67 67
68 68 CassiniTools::~CassiniTools()
69 69 {
70 70 delete m_dataFile;
71 71 delete m_CassiniToolsGUI;
72 72 delete m_gui;
73 73 }
74 74
75 75 void CassiniTools::makePlot()
76 76 {
77 77 m_defaultPlot = QLopPlots::addPlot();
78 78 m_fftPlot = QLopPlots::addPlot();
79 79 SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot);
80 80 if(plot)
81 81 {
82 82 plot->setTitle(_self->m_serviceName + " plot");
83 83 plot->setXaxisTickLabelType(QCPAxis::ltDateTime);
84 84 plot->setXaxisDateTimeFormat("hh:mm:ss.zzz");
85 85 plot->setContextMenuPolicy(Qt::ActionsContextMenu);
86 86 SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self);
87 87 plot->addAction(action);
88 88 QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int)));
89 89 ExportAction=new SocExplorerPlotActions("export view to "+QString(plot->title()).replace(".TAB","-part.TAB"),plot->PID(),_self);
90 90 plot->addAction(ExportAction);
91 91 QObject::connect(ExportAction,SIGNAL(triggered(int)),_self,SLOT(export_view_Predefined_FileName(int)));
92 92 action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self);
93 93 plot->addAction(action);
94 94 QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int)));
95 95 }
96 96 }
97 97
98 98 void CassiniTools::init(bool noGUI, QObject *parent)
99 99 {
100 100 if(Q_UNLIKELY(_self==NULL))
101 101 {
102 102 _self=new CassiniTools(noGUI,parent);
103 103 }
104 104 }
105 105
106 106 CassiniTools *CassiniTools::self()
107 107 {
108 108 _INIT();
109 109 return _self;
110 110 }
111 111
112 112 void CassiniTools::decodeFGMData(const QString &file)
113 113 {
114 114 _INIT();
115 115 m_dataFile->parseFile(file);
116 116 }
117 117
118 118 void CassiniTools::plotFile(const QString &File)
119 119 {
120 120 if(!m_dataFile->isRunning())
121 121 {
122 122 m_dataFile->parseFile(File);
123 123 // TODO fixme
124 124 SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
125 125 if(plot==NULL)
126 126 {
127 127 makePlot();
128 128 plot = QLopPlots::getPlot(m_defaultPlot);
129 129 }
130 130 if(plot)
131 131 {
132 132 plot->setTitle(File);
133 133 ExportAction->setText("export view to "+QString(File).replace(".TAB","-part.TAB"));
134 134 }
135 135 }
136 136 }
137 137
138 138 void CassiniTools::plot_TAB_File(const QString &fileName)
139 139 {
140 140 //TODO fix: accent not accepted
141 141 plotFile(fileName);
142 142 }
143 143
144 144 void CassiniTools::export_view(int PID)
145 145 {
146 146 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
147 147 if(plot==NULL)
148 148 return;
149 149 {
150 150 QString fileName = plot->title();
151 151 fileName = QFileDialog::getSaveFileName(0,tr("Set filename"),fileName.replace(".TAB","-part.TAB"));
152 152 if(fileName!="")
153 153 {
154 154 QLopDataList vectors;
155 155 for(int i=0;i<plot->graphCount();i++)
156 156 {
157 QLopData* vect = new QLopData();
157 QLopDataVector* vect = new QLopDataVector();
158 158 vect->data = plot->getVisibleData(i);
159 159 vectors.append(vect);
160 160 }
161 161 m_dataFile->saveFile(fileName,vectors);
162 162 }
163 163 }
164 164 }
165 165
166 166 void CassiniTools::export_view_Predefined_FileName(int PID)
167 167 {
168 168 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
169 169 if(plot==NULL)
170 170 return;
171 171 {
172 172 QString fileName = QString(plot->title()).replace(".TAB","-part.TAB");
173 173 if(fileName!="")
174 174 {
175 175 QLopDataList vectors;
176 176 for(int i=0;i<plot->graphCount();i++)
177 177 {
178 QLopData* vect = new QLopData();
178 QLopDataVector* vect = new QLopDataVector();
179 179 vect->data = plot->getVisibleData(i);
180 180 vectors.append(vect);
181 181 }
182 182 m_dataFile->saveFile(fileName,vectors);
183 183 }
184 184 }
185 185 }
186 186
187 187 void CassiniTools::compute_fft_on_view(int PID)
188 188 {
189 189
190 190 QElapsedTimer timr;
191 191 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
192 192 if(plot==NULL)
193 193 return;
194 194 {
195 195 timr.start();
196 196 QLopDataList vectors;
197 197 for(int i=0;i<plot->graphCount();i++)
198 198 {
199 QLopData* vect = new QLopData();
199 QLopDataVector* vect = new QLopDataVector();
200 200 vect->data = plot->getVisibleData(i);
201 201 vectors.append(vect);
202 202 }
203 203 if(vectors.count()==3)
204 204 {
205 QLopData* ch1V=vectors.at(0);
206 QLopData* ch2V=vectors.at(1);
207 QLopData* ch3V=vectors.at(2);
208 QLopData* FFTout=new QLopData();
205 QLopDataVector* ch1V=(QLopDataVector*)vectors.at(0);
206 QLopDataVector* ch2V=(QLopDataVector*)vectors.at(1);
207 QLopDataVector* ch3V=(QLopDataVector*)vectors.at(2);
208 QLopDataVector* FFTout=new QLopDataVector();
209 209 if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count())
210 210 {
211 211
212 212 double* in;
213 213 fftw_complex *out;
214 214 fftw_plan p;
215 215 FFTout->data = new QVector<QCPData>(ch1V->data->count()/2);
216 216 in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count());
217 217 out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count());
218 218 double av=0;
219 219 for(int i=0;i<ch1V->data->count();i++)
220 220 {
221 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));
222 222 av = av+in[i];
223 223 }
224 224 av/=ch1V->data->count();
225 225 for(int i=0;i<ch1V->data->count();i++)
226 226 {
227 227 in[i]=in[i]-av;
228 228 }
229 229 fftw_plan_with_nthreads(4);
230 230 p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE);
231 231 fftw_execute(p); /* repeat as needed */
232 232 fftw_destroy_plan(p);
233 233 fftw_free(in);
234 234 for(int i=0;i<ch1V->data->count()/2;i++)
235 235 {
236 236 // (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count();
237 237 (*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count());
238 238 (*FFTout->data)[i].key = i;
239 239 }
240 240 fftw_free(out);
241 241 SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot);
242 242 if(plot==NULL)
243 243 return;
244 244 plot->removeAllGraphs();
245 245 plot->addGraph();
246 246 plot->setXaxisLog();
247 247 plot->setYaxisLog();
248 248 plot->setAdaptativeSampling(0,true);
249 249 QPen pen = plot->getGraphPen(0);
250 250 pen.setColor(QLopColours[0%QLopColoursCount]);
251 251 plot->setGraphPen(0,pen);
252 252 plot->setGraphData(0,FFTout->data,false);
253 253 plot->rescaleAxis();
254 254 plot->replot();
255 255
256 256 qDebug()<< ch1V->data->count() <<" Points loaded in "<< timr.elapsed()<<"ms";
257 257 }
258 258 }
259 259 }
260 260 }
261 261
262 262 QDockWidget *CassiniTools::getGUI()
263 263 {
264 264 if(!m_noGui && (m_gui==NULL))
265 265 {
266 266 m_gui=new QDockWidget("Cassini Tools");
267 267 m_CassiniToolsGUI = new CassiniToolsGUI();
268 268 m_gui->setWidget(m_CassiniToolsGUI);
269 269 m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
270 270 }
271 271 return m_gui;
272 272 }
273 273
274 274 const QString &CassiniTools::serviceName()
275 275 {
276 276 _INIT();
277 277 return m_serviceName;
278 278 }
279 279
280 280 void CassiniTools::dataReady(QLopDataList data)
281 281 {
282 282 SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
283 283 if(plot==NULL)
284 284 {
285 285 makePlot();
286 286 plot = QLopPlots::getPlot(m_defaultPlot);
287 287 }
288 288 if(plot)
289 289 {
290 290 plot->removeAllGraphs();
291 291 for(int i=0;i<data.count();i++)
292 292 {
293 293 plot->addGraph();
294 294 plot->setAdaptativeSampling(i,true);
295 295 plot->setUseFastVector(i,true);
296 296 QPen pen = plot->getGraphPen(i);
297 297 pen.setColor(QLopColours[i%QLopColoursCount]);
298 298 plot->setGraphPen(i,pen);
299 299 plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")");
300 plot->setGraphData(i,data.at(i)->data,false);
300 plot->setGraphData(i,((QLopDataVector*)data.at(i))->data,false);
301 301 }
302 302 plot->rescaleAxis();
303 303 plot->replot();
304 304 }
305 305 }
306 306
@@ -1,107 +1,118
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>CassiniToolsGUI</class>
4 4 <widget class="QWidget" name="CassiniToolsGUI">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>400</width>
10 10 <height>300</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QGridLayout" name="gridLayout">
17 17 <item row="0" column="0">
18 18 <widget class="QTabWidget" name="tabWidget">
19 19 <property name="currentIndex">
20 20 <number>2</number>
21 21 </property>
22 22 <widget class="QWidget" name="tab">
23 23 <attribute name="title">
24 24 <string>Data downloader</string>
25 25 </attribute>
26 26 <layout class="QGridLayout" name="gridLayout_2">
27 27 <item row="0" column="0">
28 28 <widget class="CassiniDataDownloader" name="widget" native="true"/>
29 29 </item>
30 30 </layout>
31 31 </widget>
32 32 <widget class="QWidget" name="tab_2">
33 33 <attribute name="title">
34 34 <string>Index file viewer</string>
35 35 </attribute>
36 36 <layout class="QGridLayout" name="gridLayout_3">
37 37 <item row="0" column="0">
38 38 <widget class="CassiniIndexFileViewer" name="widget_2" native="true"/>
39 39 </item>
40 40 </layout>
41 41 </widget>
42 42 <widget class="QWidget" name="tab_3">
43 43 <attribute name="title">
44 44 <string>Folder browser</string>
45 45 </attribute>
46 46 <layout class="QGridLayout" name="gridLayout_4">
47 47 <item row="0" column="1">
48 48 <widget class="QPushButton" name="addFolderViewQpb">
49 <property name="font">
50 <font>
51 <pointsize>7</pointsize>
52 </font>
53 </property>
49 54 <property name="text">
50 55 <string/>
51 56 </property>
52 57 <property name="icon">
53 58 <iconset resource="../../resources/qlop.qrc">
54 59 <normaloff>:/img/Gnome-list-add.svg</normaloff>:/img/Gnome-list-add.svg</iconset>
55 60 </property>
61 <property name="iconSize">
62 <size>
63 <width>16</width>
64 <height>16</height>
65 </size>
66 </property>
56 67 <property name="flat">
57 68 <bool>false</bool>
58 69 </property>
59 70 </widget>
60 71 </item>
61 72 <item row="0" column="0">
62 73 <spacer name="horizontalSpacer">
63 74 <property name="orientation">
64 75 <enum>Qt::Horizontal</enum>
65 76 </property>
66 77 <property name="sizeHint" stdset="0">
67 78 <size>
68 79 <width>40</width>
69 <height>20</height>
80 <height>8</height>
70 81 </size>
71 82 </property>
72 83 </spacer>
73 84 </item>
74 85 <item row="1" column="0" colspan="2">
75 86 <widget class="toolBarContainer" name="folderViews" native="true"/>
76 87 </item>
77 88 </layout>
78 89 </widget>
79 90 </widget>
80 91 </item>
81 92 </layout>
82 93 </widget>
83 94 <customwidgets>
84 95 <customwidget>
85 96 <class>toolBarContainer</class>
86 97 <extends>QWidget</extends>
87 98 <header location="global">toolbarcontainer.h</header>
88 99 <container>1</container>
89 100 </customwidget>
90 101 <customwidget>
91 102 <class>CassiniDataDownloader</class>
92 103 <extends>QWidget</extends>
93 104 <header location="global">cassinidatadownloader.h</header>
94 105 <container>1</container>
95 106 </customwidget>
96 107 <customwidget>
97 108 <class>CassiniIndexFileViewer</class>
98 109 <extends>QWidget</extends>
99 110 <header location="global">cassiniindexfileviewer.h</header>
100 111 <container>1</container>
101 112 </customwidget>
102 113 </customwidgets>
103 114 <resources>
104 115 <include location="../../resources/qlop.qrc"/>
105 116 </resources>
106 117 <connections/>
107 118 </ui>
@@ -1,175 +1,214
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
23 23 #include "filebrowser.h"
24 24 #include "ui_filebrowser.h"
25 25 #include <QListView>
26 26 #include <QTreeView>
27 27
28 28 FileBrowser::FileBrowser(QWidget *parent) :
29 29 QDockWidget(parent),
30 30 ui(new Ui::FileBrowser)
31 31 {
32 this->doubleClickEater = new DoubleClickEater();
32 33 ui->setupUi(this);
33 34 this->model = new FileSystemModel(this);
34 35 this->model->setRootPath(QDir::currentPath());
35 36 this->view = new QTreeView();
36 37 this->ui->gridLayout->addWidget(this->view,1,0,1,-1);
37 38 this->view->setModel(this->model);
38 39 this->cd(model->rootPath());
39 40 connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex)));
40 41 connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex)));
42 connect(this->view,SIGNAL(activated(QModelIndex)),this,SLOT(activated(QModelIndex)));
41 43 connect(this->ui->ListViewQpb,SIGNAL(clicked()),this,SLOT(changeToListView()));
42 44 connect(this->ui->TreeViewQpb,SIGNAL(clicked()),this,SLOT(changeToTreeView()));
43 45 connect(this->ui->parentDirQpb,SIGNAL(clicked()),this,SLOT(parentDir()));
44 46 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
45 47 view->setDragEnabled(true);
46 48 view->setAcceptDrops(true);
47 49 view->setDropIndicatorShown(true);
48 50 view->setDragDropMode(QAbstractItemView::DragDrop);
49 51 this->pathCompleter = new QCompleter(this->model,this);
50 52 this->ui->pathLineEdit->setCompleter(pathCompleter);
51 53 this->pathLineEditEnterEditMode(false);
54 this->setFocusPolicy(Qt::StrongFocus);
55 this->ui->pathLineEdit->installEventFilter(this->doubleClickEater);
56 connect(this->doubleClickEater,SIGNAL(doubleClicked()),this,SLOT(pathLineEditDblClicked()));
52 57 }
53 58
54 59 FileBrowser::~FileBrowser()
55 60 {
56 61 delete ui;
57 62 }
58 63
59 64 void FileBrowser::setNameFilters(const QStringList &filters,bool disables)
60 65 {
61 66 this->model->setNameFilters(filters);
62 67 this->model->setNameFilterDisables(disables);
63 68 }
64 69
65 70 void FileBrowser::changeToTreeView()
66 71 {
67 72 this->ui->gridLayout->removeWidget(this->view);
68 73 delete this->view;
69 74 this->view = new QTreeView();
70 75 this->ui->gridLayout->addWidget(this->view,1,0,1,-1);
71 76 this->view->setModel(this->model);
72 77 connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex)));
73 78 connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex)));
74 79 this->cd(model->rootPath());
75 80 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
76 81 view->setDragEnabled(true);
77 82 view->setAcceptDrops(true);
78 83 view->setDropIndicatorShown(true);
79 84 }
80 85
81 86 void FileBrowser::changeToListView()
82 87 {
83 88 this->ui->gridLayout->removeWidget(this->view);
84 89 delete this->view;
85 90 this->view = new QListView();
86 91 this->ui->gridLayout->addWidget(this->view,1,0,1,-1);
87 92 this->view->setModel(this->model);
88 93 connect(this->view,SIGNAL(clicked(QModelIndex)),this,SLOT(clicked(QModelIndex)));
89 94 connect(this->view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClicked(QModelIndex)));
90 95 this->cd(model->rootPath());
91 96 view->setSelectionMode(QAbstractItemView::ExtendedSelection);
92 97 view->setDragEnabled(true);
93 98 view->setAcceptDrops(true);
94 99 view->setDropIndicatorShown(true);
95 100 }
96 101
97 102 void FileBrowser::clicked(QModelIndex index)
98 103 {
99 104 QString file=model->filePath(index);
100 105 if(QFile::exists(file))
101 106 emit fileClicked(file);
102 107 }
103 108
104 109 void FileBrowser::doubleClicked(QModelIndex index)
105 110 {
106 111 if(model->isDir(index))
107 112 {
108 113 this->cd(model->filePath(index));
109 114 }
110 115 else
111 116 {
112 117 QString file=model->filePath(index);
113 118 if(QFile::exists(file))
114 119 emit fileDoubleClicked(file);
115 120 }
116 121 }
117 122
123 void FileBrowser::activated(const QModelIndex &index)
124 {
125 doubleClicked(index);
126 }
127
118 128 void FileBrowser::parentDir()
119 129 {
120 130 this->cd(model->rootPath()+"/..");
121 131 }
122 132
123 133 void FileBrowser::cd(const QString &newPath)
124 134 {
125 135 model->setRootPath(newPath);
126 136 this->view->setRootIndex(model->index(model->rootPath()));
127 137 this->ui->pathLineEdit->setText(model->rootPath());
128 138 }
129 139
140 void FileBrowser::pathLineEditDblClicked()
141 {
142 if(this->ui->pathLineEdit->isReadOnly())
143 pathLineEditEnterEditMode(true);
144 }
145
130 146
131 147 void FileBrowser::changeEvent(QEvent *e)
132 148 {
133 149 QDockWidget::changeEvent(e);
134 150 switch (e->type()) {
135 151 case QEvent::LanguageChange:
136 152 ui->retranslateUi(this);
137 153 break;
138 154 default:
139 155 break;
140 156 }
141 157 }
142 158
143 159 void FileBrowser::keyPressEvent(QKeyEvent *e)
144 160 {
145 161 switch (e->key())
146 162 {
147 163 case Qt::Key_L:
148 164 if(e->modifiers()==Qt::ControlModifier)
149 165 {
150 166 pathLineEditEnterEditMode(true);
151 167 e->accept();
152 168 }
153 169 break;
154 170 case Qt::Key_Return:
155 pathLineEditEnterEditMode(false);
156 if(QFile::exists(this->ui->pathLineEdit->text()))
171 if(!this->view->hasFocus())
157 172 {
158 this->cd(this->ui->pathLineEdit->text());
159 e->accept();
173 if(QFile::exists(this->ui->pathLineEdit->text()))
174 {
175 this->cd(this->ui->pathLineEdit->text());
176 e->accept();
177 }
178 pathLineEditEnterEditMode(false);
179 }
180 break;
181 case Qt::Key_Backspace:
182 if(this->view->hasFocus())
183 {
184 parentDir();
160 185 }
161 186 break;
162 187 default:
163 188 break;
164 189 }
165 190 if(!e->isAccepted())
166 191 QDockWidget::keyPressEvent(e);
167 192 }
168 193
169 194 void FileBrowser::pathLineEditEnterEditMode(bool enter)
170 195 {
171 196 this->ui->pathLineEdit->setReadOnly(!enter);
172 197 this->ui->pathLineEdit->setDisabled(!enter);
173 198 if(enter)
174 199 this->ui->pathLineEdit->setFocus();
175 200 }
201
202
203 bool DoubleClickEater::eventFilter(QObject *obj, QEvent *event)
204 {
205 if (event->type() == QEvent::MouseButtonDblClick)
206 {
207 emit doubleClicked();
208 return true;
209 } else
210 {
211 // standard event processing
212 return QObject::eventFilter(obj, event);
213 }
214 }
@@ -1,66 +1,84
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
23 23 #ifndef FILEBROWSER_H
24 24 #define FILEBROWSER_H
25 25
26 26 #include <QDockWidget>
27 27 #include <QFileSystemModel>
28 28 #include <QAbstractItemView>
29 29 #include <filesystemmodel.h>
30 30 #include <QKeyEvent>
31 31 #include <QCompleter>
32 32
33 33 namespace Ui {
34 34 class FileBrowser;
35 35 }
36 36
37 class DoubleClickEater : public QObject
38 {
39 Q_OBJECT
40 public:
41 DoubleClickEater(){}
42 ~DoubleClickEater(){}
43 signals:
44 void doubleClicked();
45 protected:
46 bool eventFilter(QObject *obj, QEvent *event);
47 };
48
49
50
51
37 52 class FileBrowser : public QDockWidget
38 53 {
39 54 Q_OBJECT
40 55
41 56 public:
42 57 explicit FileBrowser(QWidget *parent = 0);
43 58 ~FileBrowser();
44 59 void setNameFilters(const QStringList & filters, bool disables=false);
45 60 signals:
46 61 void fileClicked(const QString& file);
47 62 void fileDoubleClicked(const QString& file);
48 63 private slots:
49 64 void changeToTreeView();
50 65 void changeToListView();
51 66 void clicked(QModelIndex index);
52 67 void doubleClicked(QModelIndex index);
68 void activated(const QModelIndex & index);
53 69 void parentDir();
54 70 void cd(const QString& newPath);
71 void pathLineEditDblClicked();
55 72 protected:
56 73 void changeEvent(QEvent *e);
57 74 void keyPressEvent(QKeyEvent *e);
58 75 private:
59 76 void pathLineEditEnterEditMode(bool enter=true);
60 77 Ui::FileBrowser *ui;
61 78 FileSystemModel* model;
62 79 QAbstractItemView* view;
63 80 QCompleter* pathCompleter;
81 DoubleClickEater* doubleClickEater;
64 82 };
65 83
66 84 #endif // FILEBROWSER_H
@@ -1,34 +1,47
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
23 23 #include "qlopdata.h"
24 24
25 25 QLopData::QLopData(QObject *parent) : QObject(parent)
26 26 {
27
27 this->unit = "";
28 this->source = "Not set";
29 this->type = QLopData::None;
28 30 }
29 31
30 32 QLopData::~QLopData()
31 33 {
34 // delete data;
35 }
36
37
38
39 QLopDataVector::QLopDataVector(QObject *parent)
40 {
41 this->type = QLopData::Vector;
42 }
43
44 QLopDataVector::~QLopDataVector()
45 {
32 46 delete data;
33 47 }
34
@@ -1,56 +1,78
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
23 23 #ifndef QLOPDATA_H
24 24 #define QLOPDATA_H
25 25
26 26 #include <QObject>
27 27 #include <qcustomplot.h>
28 28
29 29 typedef struct dataVector
30 30 {
31 31 QString name;
32 32 QString unit;
33 33 QVector<QCPData>* data;
34 34 }dataVector;
35 35
36 36 typedef QList<dataVector> QListOfDataVector;
37 37
38 38
39 39
40 40 class QLopData : public QObject
41 41 {
42 42 Q_OBJECT
43 43 public:
44 typedef enum QLopDataType
45 {
46 Scalar=0,
47 Vector=1,
48 Matrix=2,
49 None=-1,
50 }
51 QLopDataType;
44 52 explicit QLopData(QObject *parent = 0);
45 53 ~QLopData();
46 54 QString name;
55 QString source;
47 56 QString unit;
57 QLopDataType type;
58 int ID;
59 signals:
60 void dataChanged();
61 public slots:
62 private:
63 };
64
65 class QLopDataVector : public QLopData
66 {
67 Q_OBJECT
68 public:
69 explicit QLopDataVector(QObject *parent = 0);
70 ~QLopDataVector();
48 71 QVector<QCPData>* data;
49 72 signals:
50 void dataChanged();
51 73 public slots:
52 74 private:
53 75 };
54 76 typedef QList<QLopData*> QLopDataList;
55 77
56 78 #endif // QLOPDATA_H
General Comments 0
You need to be logged in to leave comments. Login now