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_pUi(new Ui::ProjectSettingsViewWidget)
58, m_sDataPath(sDataPath)
59, m_sCurrentProject(sCurrentProject)
60, m_sCurrentSubject(sCurrentSubject)
61, m_sCurrentParadigm(sCurrentParadigm)
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 confirmBox;
250 confirmBox.setText(QString("Deleting subject data '%1'.").arg(m_pUi->m_qComboBox_SubjectSelection->currentText()));
251 confirmBox.setInformativeText("Do really want to delete the data permantley? The deleted data cannot be recovered!");
252 confirmBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
253 confirmBox.setDefaultButton(QMessageBox::No);
254 confirmBox.setWindowModality(Qt::ApplicationModal);
255 confirmBox.setIcon(QMessageBox::Critical);
256 int ret = confirmBox.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 confirmBox;
292 confirmBox.setText(QString("Deleting project data '%1'.").arg(m_pUi->m_qComboBox_ProjectSelection->currentText()));
293 confirmBox.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 confirmBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
295 confirmBox.setDefaultButton(QMessageBox::No);
296 confirmBox.setWindowModality(Qt::ApplicationModal);
297 confirmBox.setIcon(QMessageBox::Critical);
298 int ret = confirmBox.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 if (!QDir(m_sDataPath + "/" + sProject).exists())
326 QDir().mkdir(m_sDataPath + "/" + sProject);
327
328 m_sCurrentProject = sProject;
329 emit newProject(m_sCurrentProject);
330
331 scanForProjects();
332 scanForSubjects();
333 updateFileName();
334 }
335}
336
337//=============================================================================================================
338
339void ProjectSettingsView::addSubject()
340{
341 bool ok;
342 QString sSubject = QInputDialog::getText(this, tr("Add new Subject"),
343 tr("Add new Subject:"), QLineEdit::Normal,
344 tr("NewSubject"), &ok);
345
346 if (ok && !sSubject.isEmpty()) {
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 // Repopulating the combo box must not report its transient selections as user choices.
372 const QSignalBlocker blocker(m_pUi->m_qComboBox_ProjectSelection);
373
374 //clear
375 m_pUi->m_qComboBox_ProjectSelection->clear();
376 m_sListProjects.clear();
377
378 QDir t_qDirData(m_sDataPath);
379
380 QFileInfoList t_qFileInfoList = t_qDirData.entryInfoList();
381 QFileInfoList::const_iterator it;
382 for (it = t_qFileInfoList.constBegin(); it != t_qFileInfoList.constEnd(); ++it)
383 if (it->isDir() && it->fileName() != "." && it->fileName() != "..")
384 m_sListProjects.append(it->fileName());
385
386 m_pUi->m_qComboBox_ProjectSelection->insertItems(0, m_sListProjects);
387 m_pUi->m_qComboBox_ProjectSelection->setCurrentIndex(m_pUi->m_qComboBox_ProjectSelection->findText(m_sCurrentProject));
388}
389
390//=============================================================================================================
391
392void ProjectSettingsView::scanForSubjects()
393{
394 // Repopulating the combo box must not report its transient selections as user choices.
395 const QSignalBlocker blocker(m_pUi->m_qComboBox_SubjectSelection);
396
397 //clear
398 m_pUi->m_qComboBox_SubjectSelection->clear();
399 m_sListSubjects.clear();
400
401 QDir t_qDirProject(m_sDataPath + "/" + m_sCurrentProject);
402
403 QFileInfoList t_qFileInfoList = t_qDirProject.entryInfoList();
404 QFileInfoList::const_iterator it;
405 for (it = t_qFileInfoList.constBegin(); it != t_qFileInfoList.constEnd(); ++it)
406 if (it->isDir() && it->fileName() != "." && it->fileName() != "..")
407 m_sListSubjects.append(it->fileName());
408
409 m_pUi->m_qComboBox_SubjectSelection->insertItems(0, m_sListSubjects);
410
411 qint32 idx = m_pUi->m_qComboBox_SubjectSelection->findText(m_sCurrentSubject);
412 if (idx >= 0)
413 m_pUi->m_qComboBox_SubjectSelection->setCurrentIndex(idx);
414 else {
415 m_pUi->m_qComboBox_SubjectSelection->setCurrentIndex(0);
416 selectNewSubject(m_pUi->m_qComboBox_SubjectSelection->itemText(0));
417 }
418}
419
420//=============================================================================================================
421
422void ProjectSettingsView::selectNewProject(const QString& sNewProject)
423{
424 m_sCurrentProject = sNewProject;
425 emit newProject(m_sCurrentProject);
426
427 scanForSubjects();
428 updateFileName();
429}
430
431//=============================================================================================================
432
433void ProjectSettingsView::selectNewSubject(const QString& sNewSubject)
434{
435 m_sCurrentSubject = sNewSubject;
436 emit newSubject(m_sCurrentSubject);
437
438 updateFileName();
439}
440
441//=============================================================================================================
442
443void ProjectSettingsView::updateFileName(bool currentTime)
444{
445 QString sFilePath = m_sDataPath + "/" + m_sCurrentProject + "/" + m_sCurrentSubject;
446
447 QString sTimeStamp;
448
449 if (currentTime) {
450 sTimeStamp = QDateTime::currentDateTime().toString("yyMMdd_hhmmss");
451 } else {
452 sTimeStamp = "<YYMMDD_HMS>";
453 }
454
455 if (m_sCurrentParadigm.isEmpty())
456 sFilePath.append("/" + sTimeStamp + "_" + m_sCurrentSubject + "_raw.fif");
457 else
458 sFilePath.append("/" + sTimeStamp + "_" + m_sCurrentSubject + "_" + m_sCurrentParadigm + "_raw.fif");
459
460 m_sFileName = sFilePath;
461
462 m_pUi->m_qLineEditFileName->setText(m_sFileName);
463
464 emit fileNameChanged(m_sFileName);
465}
466
467//=============================================================================================================
468
469void ProjectSettingsView::onTimeChanged()
470{
471 m_iRecordingTime = (m_pUi->m_spinBox_hours->value() * 60 * 60) + (m_pUi->m_spinBox_min->value() * 60) + (m_pUi->m_spinBox_sec->value());
472
473 m_iRecordingTime *= 1000;
474
475 QTime remainingTime(0, 0, 0, 0);
476
477 QTime remainingTimeFinal = remainingTime.addMSecs(m_iRecordingTime);
478
479 m_pUi->m_label_timeToGo->setText(remainingTimeFinal.toString());
480
481 emit timerChanged(m_iRecordingTime);
482}
483
484//=============================================================================================================
485
486void ProjectSettingsView::onRecordingTimerStateChanged(bool state)
487{
488 emit recordingTimerStateChanged(state);
489}
490
491//=============================================================================================================
492
496
497//=============================================================================================================
498
500{
501 updateFileName();
502}
503
504//=============================================================================================================
505
506void ProjectSettingsView::browseDirectories()
507{
508 QString sDir = QFileDialog::getExistingDirectory(this,
509 tr("Select Project Directory"),
510 QDir::homePath(),
511 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
512 if (!sDir.isEmpty() && !sDir.isNull()) {
513 m_sDataPath = sDir;
514 m_pUi->m_lineEditDirectory->setText(m_sDataPath);
515 scanForProjects();
516 scanForSubjects();
517 updateFileName(true);
518 }
519}
520
521//=============================================================================================================
522
524{
525 m_pUi->m_qLine->hide();
526 m_pUi->m_qLineEditFileName->hide();
527 m_pUi->m_qLabel->hide();
528}
529
530//=============================================================================================================
531
533{
534 m_pUi->m_qLine->show();
535 m_pUi->m_qLineEditFileName->show();
536 m_pUi->m_qLabel->show();
537}
538
539//=============================================================================================================
540
542{
543 m_pUi->m_qLabel_Paradigm->hide();
544 m_pUi->m_qLineEditParadigm->hide();
545}
546
547//=============================================================================================================
548
550{
551 m_pUi->m_qLabel_Paradigm->show();
552 m_pUi->m_qLineEditParadigm->show();
553}
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)