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