v2.0.0
Loading...
Searching...
No Matches
projectsettingsview.cpp
Go to the documentation of this file.
1//=============================================================================================================
15
16//=============================================================================================================
17// INCLUDES
18//=============================================================================================================
19
20#include "projectsettingsview.h"
21
22#include "ui_projectsettingsview.h"
23
24//=============================================================================================================
25// QT INCLUDES
26//=============================================================================================================
27
28#include <QDir>
29#include <QDebug>
30#include <QInputDialog>
31#include <QMessageBox>
32#include <QTime>
33#include <QSettings>
34#include <QFileDialog>
35
36//=============================================================================================================
37// EIGEN INCLUDES
38//=============================================================================================================
39
40//=============================================================================================================
41// USED NAMESPACES
42//=============================================================================================================
43
44using namespace DISPLIB;
45
46//=============================================================================================================
47// DEFINE MEMBER METHODS
48//=============================================================================================================
49
50ProjectSettingsView::ProjectSettingsView(const QString& sSettingsPath,
51 const QString& sDataPath,
52 const QString& sCurrentProject,
53 const QString& sCurrentSubject,
54 const QString& sCurrentParadigm,
55 QWidget *parent)
56: AbstractView(parent)
57, m_sDataPath(sDataPath)
58, m_sCurrentProject(sCurrentProject)
59, m_sCurrentSubject(sCurrentSubject)
60, m_sCurrentParadigm(sCurrentParadigm)
61, m_pUi(new Ui::ProjectSettingsViewWidget)
62, m_iRecordingTime(5*60*1000)
63{
64 m_sSettingsPath = sSettingsPath;
65 m_pUi->setupUi(this);
66
67 scanForProjects();
68 scanForSubjects();
69
70 connectGui();
71
72 m_pUi->m_qLineEditFileName->setReadOnly(true);
73
74 m_pUi->m_lineEditDirectory->setReadOnly(true);
75 m_pUi->m_lineEditDirectory->setText(m_sDataPath);
76
77 updateFileName();
78
79 //Hide remaining time
80 m_pUi->m_label_RemainingTime->hide();
81 m_pUi->m_label_timeToGo->hide();
82
83// QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
84// tr("User name:"), QLineEdit::Normal,
85// QDir::home().dirName(), &ok);
86
87 //Hide delete buttons
88 m_pUi->m_qPushButtonDeleteProject->hide();
89 m_pUi->m_qPushButtonDeleteSubject->hide();
90
92}
93
94//=============================================================================================================
95
96void ProjectSettingsView::connectGui()
97{
98#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
99 connect(m_pUi->m_qComboBox_ProjectSelection,static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
100 this,&ProjectSettingsView::selectNewProject);
101
102 connect(m_pUi->m_qComboBox_SubjectSelection,static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
103 this,&ProjectSettingsView::selectNewSubject);
104#else
105 connect(m_pUi->m_qComboBox_ProjectSelection,&QComboBox::currentTextChanged,
106 this,&ProjectSettingsView::selectNewProject);
107
108 connect(m_pUi->m_qComboBox_SubjectSelection,&QComboBox::currentTextChanged,
109 this,&ProjectSettingsView::selectNewSubject);
110#endif
111 connect(m_pUi->m_qLineEditParadigm,&QLineEdit::textChanged,
112 this,&ProjectSettingsView::paradigmChanged);
113
114 connect(m_pUi->m_qPushButtonNewProject,&QPushButton::clicked,
115 this,&ProjectSettingsView::addProject);
116
117 connect(m_pUi->m_qPushButtonNewSubject,&QPushButton::clicked,
118 this,&ProjectSettingsView::addSubject);
119
120 connect(m_pUi->m_qPushButtonDeleteProject,&QPushButton::clicked,
121 this,&ProjectSettingsView::deleteProject);
122
123 connect(m_pUi->m_qPushButtonDeleteSubject,&QPushButton::clicked,
124 this,&ProjectSettingsView::deleteSubject);
125
126 connect(m_pUi->m_spinBox_hours, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
127 this,&ProjectSettingsView::onTimeChanged);
128
129 connect(m_pUi->m_spinBox_min, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
130 this,&ProjectSettingsView::onTimeChanged);
131
132 connect(m_pUi->m_spinBox_sec, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
133 this,&ProjectSettingsView::onTimeChanged);
134
135 connect(m_pUi->m_checkBox_useRecordingTimer,&QCheckBox::toggled,
136 this,&ProjectSettingsView::onRecordingTimerStateChanged);
137
138 connect(m_pUi->m_pushButtonDirectory, &QPushButton::released,
139 this, &ProjectSettingsView::browseDirectories);
140}
141
142//=============================================================================================================
143
145{
146 saveSettings();
147 delete m_pUi;
148}
149
150//=============================================================================================================
151
153{
154 if(m_sSettingsPath.isEmpty()) {
155 return;
156 }
157
158 // Save Settings
159 QSettings settings("MNECPP");
160}
161
162//=============================================================================================================
163
165{
166 if(m_sSettingsPath.isEmpty()) {
167 return;
168 }
169
170 // Load Settings
171 QSettings settings("MNECPP");
172}
173
174//=============================================================================================================
175
177{
178 switch(mode) {
180 break;
181 default: // default is research mode
182 break;
183 }
184}
185
186//=============================================================================================================
187
189{
190 switch(mode) {
192 break;
193 default: // default is realtime mode
194 break;
195 }
196}
197
198//=============================================================================================================
199
201{
202 QTime remainingTime(0,0,0,0);
203
204 QTime remainingTimeFinal = remainingTime.addMSecs(m_iRecordingTime-mSecsElapsed);
205
206 m_pUi->m_label_timeToGo->setText(remainingTimeFinal.toString());
207
208 QTime passedTime(0,0,0,0);
209
210 // If we are below 1 sec in difference and near to finish set to recording time specified by the user
211 // This overcomes the problem that the counter is not counted to the user specified recording time
212 // but showing the time right before finish.
213 if(m_iRecordingTime-mSecsElapsed < 500) {
214 mSecsElapsed = m_iRecordingTime;
215 }
216
217 QTime passedTimeFinal = passedTime.addMSecs(mSecsElapsed);
218
219 m_pUi->m_label_timePassed->setText(passedTimeFinal.toString("HH:mm:ss"));
220}
221
222//=============================================================================================================
223
225{
226 //Update file name before returning to include the current time since the last update was called
227 updateFileName();
228
229 return m_sFileName;
230}
231
232//=============================================================================================================
233
234void ProjectSettingsView::deleteSubject()
235{
236 QMessageBox msgBox;
237 msgBox.setText(QString("Deleting subject data '%1'.").arg(m_pUi->m_qComboBox_SubjectSelection->currentText()));
238 msgBox.setInformativeText("You are about to delete a subject. Do you want to delete all data corresponding to this subject?");
239 msgBox.setIcon(QMessageBox::Warning);
240 QPushButton *keepData = msgBox.addButton(tr("Keep data"), QMessageBox::ActionRole);
241 QPushButton *deleteData = msgBox.addButton(tr("Delete data"), QMessageBox::ActionRole);
242
243 msgBox.exec();
244
245 if(msgBox.clickedButton() == keepData)
246 return;
247
248 if(msgBox.clickedButton() == deleteData) {
249 QMessageBox msgBox;
250 msgBox.setText(QString("Deleting subject data '%1'.").arg(m_pUi->m_qComboBox_SubjectSelection->currentText()));
251 msgBox.setInformativeText("Do really want to delete the data permantley? The deleted data cannot be recovered!");
252 msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
253 msgBox.setDefaultButton(QMessageBox::No);
254 msgBox.setWindowModality(Qt::ApplicationModal);
255 msgBox.setIcon(QMessageBox::Critical);
256 int ret = msgBox.exec();
257
258 if(ret == QMessageBox::No)
259 return;
260
261 QString dirName = m_sDataPath + "/" + m_pUi->m_qComboBox_ProjectSelection->currentText() + "/" + m_pUi->m_qComboBox_SubjectSelection->currentText();
262
263 QDir dir(dirName);
264
265 bool result = dir.removeRecursively();
266
267 if(!result)
268 qDebug()<<"Could not remove all data from the subject folder!";
269 else
270 m_pUi->m_qComboBox_SubjectSelection->removeItem(m_pUi->m_qComboBox_SubjectSelection->currentIndex());
271 }
272}
273
274//=============================================================================================================
275
276void ProjectSettingsView::deleteProject()
277{
278 QMessageBox msgBox;
279 msgBox.setText(QString("Deleting project data '%1'.").arg(m_pUi->m_qComboBox_ProjectSelection->currentText()));
280 msgBox.setInformativeText("You are about to delete a project. Do you want to delete all data corresponding to this project?");
281 msgBox.setIcon(QMessageBox::Warning);
282 QPushButton *keepData = msgBox.addButton(tr("Keep data"), QMessageBox::ActionRole);
283 QPushButton *deleteData = msgBox.addButton(tr("Delete data"), QMessageBox::ActionRole);
284
285 msgBox.exec();
286
287 if(msgBox.clickedButton() == keepData)
288 return;
289
290 if(msgBox.clickedButton() == deleteData) {
291 QMessageBox msgBox;
292 msgBox.setText(QString("Deleting project data '%1'.").arg(m_pUi->m_qComboBox_ProjectSelection->currentText()));
293 msgBox.setInformativeText("Do really want to delete the data permantley? All subject data in this project will be lost! The deleted data cannot be recovered!");
294 msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
295 msgBox.setDefaultButton(QMessageBox::No);
296 msgBox.setWindowModality(Qt::ApplicationModal);
297 msgBox.setIcon(QMessageBox::Critical);
298 int ret = msgBox.exec();
299
300 if(ret == QMessageBox::No)
301 return;
302
303 QString dirName = m_sDataPath + "/" + m_pUi->m_qComboBox_ProjectSelection->currentText();
304
305 QDir dir(dirName);
306
307 bool result = dir.removeRecursively();
308
309 if(!result)
310 qDebug()<<"Could not remove all data from the project folder!";
311 else
312 m_pUi->m_qComboBox_ProjectSelection->removeItem(m_pUi->m_qComboBox_ProjectSelection->currentIndex());
313 }
314}
315
316//=============================================================================================================
317
318void ProjectSettingsView::addProject()
319{
320 bool ok;
321 QString sProject = QInputDialog::getText(this, tr("Add new Project"),
322 tr("Add new Project:"), QLineEdit::Normal,
323 tr("NewProject"), &ok);
324 if (ok && !sProject.isEmpty())
325 {
326 if(!QDir(m_sDataPath+"/" + sProject).exists())
327 QDir().mkdir(m_sDataPath+"/"+sProject);
328
329 m_sCurrentProject = sProject;
330 emit newProject(m_sCurrentProject);
331
332 scanForProjects();
333 }
334}
335
336//=============================================================================================================
337
338void ProjectSettingsView::addSubject()
339{
340 bool ok;
341 QString sSubject = QInputDialog::getText(this, tr("Add new Subject"),
342 tr("Add new Subject:"), QLineEdit::Normal,
343 tr("NewSubject"), &ok);
344
345 if (ok && !sSubject.isEmpty())
346 {
347 if(!QDir(m_sDataPath + "/" + m_sCurrentProject + "/" + sSubject).exists())
348 QDir().mkdir(m_sDataPath + "/" + m_sCurrentProject + "/" + sSubject);
349
350 m_sCurrentSubject = sSubject;
351
352 emit newSubject(m_sCurrentSubject);
353
354 scanForSubjects();
355 }
356}
357
358//=============================================================================================================
359
360void ProjectSettingsView::paradigmChanged(const QString &sNewParadigm)
361{
362 m_sCurrentParadigm = sNewParadigm;
363 emit newParadigm(m_sCurrentParadigm);
364 updateFileName();
365}
366
367//=============================================================================================================
368
369void ProjectSettingsView::scanForProjects()
370{
371 //clear
372 m_pUi->m_qComboBox_ProjectSelection->clear();
373 m_sListProjects.clear();
374
375 QDir t_qDirData(m_sDataPath);
376
377 QFileInfoList t_qFileInfoList = t_qDirData.entryInfoList();
378 QFileInfoList::const_iterator it;
379 for (it = t_qFileInfoList.constBegin(); it != t_qFileInfoList.constEnd(); ++it)
380 if(it->isDir() && it->fileName() != "." && it->fileName() != "..")
381 m_sListProjects.append(it->fileName());
382
383 m_pUi->m_qComboBox_ProjectSelection->insertItems(0,m_sListProjects);
384 m_pUi->m_qComboBox_ProjectSelection->setCurrentIndex(m_pUi->m_qComboBox_ProjectSelection->findText(m_sCurrentProject));
385}
386
387//=============================================================================================================
388
389void ProjectSettingsView::scanForSubjects()
390{
391 //clear
392 m_pUi->m_qComboBox_SubjectSelection->clear();
393 m_sListSubjects.clear();
394
395 QDir t_qDirProject(m_sDataPath+"/"+m_sCurrentProject);
396
397 QFileInfoList t_qFileInfoList = t_qDirProject.entryInfoList();
398 QFileInfoList::const_iterator it;
399 for (it = t_qFileInfoList.constBegin(); it != t_qFileInfoList.constEnd(); ++it)
400 if(it->isDir() && it->fileName() != "." && it->fileName() != "..")
401 m_sListSubjects.append(it->fileName());
402
403 m_pUi->m_qComboBox_SubjectSelection->insertItems(0,m_sListSubjects);
404
405 qint32 idx = m_pUi->m_qComboBox_SubjectSelection->findText(m_sCurrentSubject);
406 if(idx >= 0)
407 m_pUi->m_qComboBox_SubjectSelection->setCurrentIndex(idx);
408 else
409 {
410 m_pUi->m_qComboBox_SubjectSelection->setCurrentIndex(0);
411 selectNewSubject(m_pUi->m_qComboBox_SubjectSelection->itemText(0));
412 }
413}
414
415//=============================================================================================================
416
417void ProjectSettingsView::selectNewProject(const QString &sNewProject)
418{
419 m_sCurrentProject = sNewProject;
420 emit newProject(m_sCurrentProject);
421
422 scanForSubjects();
423 updateFileName();
424}
425
426//=============================================================================================================
427
428void ProjectSettingsView::selectNewSubject(const QString &sNewSubject)
429{
430 m_sCurrentSubject = sNewSubject;
431 emit newSubject(m_sCurrentSubject);
432
433 updateFileName();
434}
435
436//=============================================================================================================
437
438void ProjectSettingsView::updateFileName(bool currentTime)
439{
440 QString sFilePath = m_sDataPath + "/" + m_sCurrentProject + "/" + m_sCurrentSubject;
441
442 QString sTimeStamp;
443
444 if(currentTime) {
445 sTimeStamp = QDateTime::currentDateTime().toString("yyMMdd_hhmmss");
446 } else {
447 sTimeStamp = "<YYMMDD_HMS>";
448 }
449
450 if(m_sCurrentParadigm.isEmpty())
451 sFilePath.append("/"+ sTimeStamp + "_" + m_sCurrentSubject + "_raw.fif");
452 else
453 sFilePath.append("/"+ sTimeStamp + "_" + m_sCurrentSubject + "_" + m_sCurrentParadigm + "_raw.fif");
454
455 m_sFileName = sFilePath;
456
457 m_pUi->m_qLineEditFileName->setText(m_sFileName);
458
459 emit fileNameChanged(m_sFileName);
460}
461
462//=============================================================================================================
463
464void ProjectSettingsView::onTimeChanged()
465{
466 m_iRecordingTime = (m_pUi->m_spinBox_hours->value()*60*60)+(m_pUi->m_spinBox_min->value()*60)+(m_pUi->m_spinBox_sec->value());
467
468 m_iRecordingTime*=1000;
469
470 QTime remainingTime(0,0,0,0);
471
472 QTime remainingTimeFinal = remainingTime.addMSecs(m_iRecordingTime);
473
474 m_pUi->m_label_timeToGo->setText(remainingTimeFinal.toString());
475
476 emit timerChanged(m_iRecordingTime);
477}
478
479//=============================================================================================================
480
481void ProjectSettingsView::onRecordingTimerStateChanged(bool state)
482{
483 emit recordingTimerStateChanged(state);
484}
485
486//=============================================================================================================
487
492
493//=============================================================================================================
494
496{
497 updateFileName();
498}
499
500//=============================================================================================================
501
502void ProjectSettingsView::browseDirectories()
503{
504 QString sDir = QFileDialog::getExistingDirectory(this,
505 tr("Select Project Directory"),
506 QDir::homePath(),
507 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
508 if(!sDir.isEmpty() && !sDir.isNull()){
509 m_sDataPath = sDir;
510 m_pUi->m_lineEditDirectory->setText(m_sDataPath);
511 scanForProjects();
512 scanForSubjects();
513 updateFileName(true);
514 }
515}
516
517//=============================================================================================================
518
520{
521 m_pUi->m_qLine->hide();
522 m_pUi->m_qLineEditFileName->hide();
523 m_pUi->m_qLabel->hide();
524}
525
526//=============================================================================================================
527
529{
530 m_pUi->m_qLine->show();
531 m_pUi->m_qLineEditFileName->show();
532 m_pUi->m_qLabel->show();
533}
534
535//=============================================================================================================
536
538{
539 m_pUi->m_qLabel_Paradigm->hide();
540 m_pUi->m_qLineEditParadigm->hide();
541}
542
543//=============================================================================================================
544
546{
547 m_pUi->m_qLabel_Paradigm->show();
548 m_pUi->m_qLineEditParadigm->show();
549}
Output-path and filename-template panel for recording / export sessions.
2-D display widgets and visualisation helpers (charts, topography, colour maps).
AbstractView(QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
void newSubject(const QString &sCurrentSubject)
void fileNameChanged(const QString &sCurrentFileName)
void setRecordingElapsedTime(int mSecsElapsed)
void newProject(const QString &sCurrentProject)
ProjectSettingsView(const QString &sSettingsPath="", const QString &sDataPath="/TestData", const QString &sCurrentProject="TestProject", const QString &sCurrentSubject="TestSubject", const QString &sCurrentParadigm="UnknownParadigm", QWidget *parent=0)
void updateProcessingMode(ProcessingMode mode)
void newParadigm(const QString &sCurrentParadigm)
void recordingTimerStateChanged(bool state)