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(std::make_unique<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
148
149//=============================================================================================================
150
152{
153 if (m_sSettingsPath.isEmpty()) {
154 return;
155 }
156
157 // Save Settings
158 QSettings settings("MNECPP");
159}
160
161//=============================================================================================================
162
164{
165 if (m_sSettingsPath.isEmpty()) {
166 return;
167 }
168
169 // Load Settings
170 QSettings settings("MNECPP");
171}
172
173//=============================================================================================================
174
176{
177 switch (mode) {
179 break;
180 default: // default is research mode
181 break;
182 }
183}
184
185//=============================================================================================================
186
188{
189 switch (mode) {
191 break;
192 default: // default is realtime mode
193 break;
194 }
195}
196
197//=============================================================================================================
198
200{
201 QTime remainingTime(0, 0, 0, 0);
202
203 QTime remainingTimeFinal = remainingTime.addMSecs(m_iRecordingTime - mSecsElapsed);
204
205 m_pUi->m_label_timeToGo->setText(remainingTimeFinal.toString());
206
207 QTime passedTime(0, 0, 0, 0);
208
209 // If we are below 1 sec in difference and near to finish set to recording time specified by the user
210 // This overcomes the problem that the counter is not counted to the user specified recording time
211 // but showing the time right before finish.
212 if (m_iRecordingTime - mSecsElapsed < 500) {
213 mSecsElapsed = m_iRecordingTime;
214 }
215
216 QTime passedTimeFinal = passedTime.addMSecs(mSecsElapsed);
217
218 m_pUi->m_label_timePassed->setText(passedTimeFinal.toString("HH:mm:ss"));
219}
220
221//=============================================================================================================
222
224{
225 //Update file name before returning to include the current time since the last update was called
226 updateFileName();
227
228 return m_sFileName;
229}
230
231//=============================================================================================================
232
233void ProjectSettingsView::deleteSubject()
234{
235 QMessageBox msgBox;
236 msgBox.setText(QString("Deleting subject data '%1'.").arg(m_pUi->m_qComboBox_SubjectSelection->currentText()));
237 msgBox.setInformativeText("You are about to delete a subject. Do you want to delete all data corresponding to this subject?");
238 msgBox.setIcon(QMessageBox::Warning);
239 QPushButton* keepData = msgBox.addButton(tr("Keep data"), QMessageBox::ActionRole);
240 QPushButton* deleteData = msgBox.addButton(tr("Delete data"), QMessageBox::ActionRole);
241
242 msgBox.exec();
243
244 if (msgBox.clickedButton() == keepData)
245 return;
246
247 if (msgBox.clickedButton() == deleteData) {
248 QMessageBox confirmBox;
249 confirmBox.setText(QString("Deleting subject data '%1'.").arg(m_pUi->m_qComboBox_SubjectSelection->currentText()));
250 confirmBox.setInformativeText("Do really want to delete the data permantley? The deleted data cannot be recovered!");
251 confirmBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
252 confirmBox.setDefaultButton(QMessageBox::No);
253 confirmBox.setWindowModality(Qt::ApplicationModal);
254 confirmBox.setIcon(QMessageBox::Critical);
255 int ret = confirmBox.exec();
256
257 if (ret == QMessageBox::No)
258 return;
259
260 QString dirName = m_sDataPath + "/" + m_pUi->m_qComboBox_ProjectSelection->currentText() + "/" + m_pUi->m_qComboBox_SubjectSelection->currentText();
261
262 QDir dir(dirName);
263
264 bool result = dir.removeRecursively();
265
266 if (!result)
267 qDebug() << "Could not remove all data from the subject folder!";
268 else
269 m_pUi->m_qComboBox_SubjectSelection->removeItem(m_pUi->m_qComboBox_SubjectSelection->currentIndex());
270 }
271}
272
273//=============================================================================================================
274
275void ProjectSettingsView::deleteProject()
276{
277 QMessageBox msgBox;
278 msgBox.setText(QString("Deleting project data '%1'.").arg(m_pUi->m_qComboBox_ProjectSelection->currentText()));
279 msgBox.setInformativeText("You are about to delete a project. Do you want to delete all data corresponding to this project?");
280 msgBox.setIcon(QMessageBox::Warning);
281 QPushButton* keepData = msgBox.addButton(tr("Keep data"), QMessageBox::ActionRole);
282 QPushButton* deleteData = msgBox.addButton(tr("Delete data"), QMessageBox::ActionRole);
283
284 msgBox.exec();
285
286 if (msgBox.clickedButton() == keepData)
287 return;
288
289 if (msgBox.clickedButton() == deleteData) {
290 QMessageBox confirmBox;
291 confirmBox.setText(QString("Deleting project data '%1'.").arg(m_pUi->m_qComboBox_ProjectSelection->currentText()));
292 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!");
293 confirmBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
294 confirmBox.setDefaultButton(QMessageBox::No);
295 confirmBox.setWindowModality(Qt::ApplicationModal);
296 confirmBox.setIcon(QMessageBox::Critical);
297 int ret = confirmBox.exec();
298
299 if (ret == QMessageBox::No)
300 return;
301
302 QString dirName = m_sDataPath + "/" + m_pUi->m_qComboBox_ProjectSelection->currentText();
303
304 QDir dir(dirName);
305
306 bool result = dir.removeRecursively();
307
308 if (!result)
309 qDebug() << "Could not remove all data from the project folder!";
310 else
311 m_pUi->m_qComboBox_ProjectSelection->removeItem(m_pUi->m_qComboBox_ProjectSelection->currentIndex());
312 }
313}
314
315//=============================================================================================================
316
317void ProjectSettingsView::addProject()
318{
319 bool ok;
320 QString sProject = QInputDialog::getText(this, tr("Add new Project"),
321 tr("Add new Project:"), QLineEdit::Normal,
322 tr("NewProject"), &ok);
323 if (ok && !sProject.isEmpty()) {
324 if (!QDir(m_sDataPath + "/" + sProject).exists())
325 QDir().mkdir(m_sDataPath + "/" + sProject);
326
327 m_sCurrentProject = sProject;
328 emit newProject(m_sCurrentProject);
329
330 scanForProjects();
331 scanForSubjects();
332 updateFileName();
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 if (!QDir(m_sDataPath + "/" + m_sCurrentProject + "/" + sSubject).exists())
347 QDir().mkdir(m_sDataPath + "/" + m_sCurrentProject + "/" + sSubject);
348
349 m_sCurrentSubject = sSubject;
350
351 emit newSubject(m_sCurrentSubject);
352
353 scanForSubjects();
354 }
355}
356
357//=============================================================================================================
358
359void ProjectSettingsView::paradigmChanged(const QString& sNewParadigm)
360{
361 m_sCurrentParadigm = sNewParadigm;
362 emit newParadigm(m_sCurrentParadigm);
363 updateFileName();
364}
365
366//=============================================================================================================
367
368void ProjectSettingsView::scanForProjects()
369{
370 // Repopulating the combo box must not report its transient selections as user choices.
371 const QSignalBlocker blocker(m_pUi->m_qComboBox_ProjectSelection);
372
373 //clear
374 m_pUi->m_qComboBox_ProjectSelection->clear();
375 m_sListProjects.clear();
376
377 QDir t_qDirData(m_sDataPath);
378
379 QFileInfoList t_qFileInfoList = t_qDirData.entryInfoList();
380 QFileInfoList::const_iterator it;
381 for (it = t_qFileInfoList.constBegin(); it != t_qFileInfoList.constEnd(); ++it)
382 if (it->isDir() && it->fileName() != "." && it->fileName() != "..")
383 m_sListProjects.append(it->fileName());
384
385 m_pUi->m_qComboBox_ProjectSelection->insertItems(0, m_sListProjects);
386 m_pUi->m_qComboBox_ProjectSelection->setCurrentIndex(m_pUi->m_qComboBox_ProjectSelection->findText(m_sCurrentProject));
387}
388
389//=============================================================================================================
390
391void ProjectSettingsView::scanForSubjects()
392{
393 // Repopulating the combo box must not report its transient selections as user choices.
394 const QSignalBlocker blocker(m_pUi->m_qComboBox_SubjectSelection);
395
396 //clear
397 m_pUi->m_qComboBox_SubjectSelection->clear();
398 m_sListSubjects.clear();
399
400 QDir t_qDirProject(m_sDataPath + "/" + m_sCurrentProject);
401
402 QFileInfoList t_qFileInfoList = t_qDirProject.entryInfoList();
403 QFileInfoList::const_iterator it;
404 for (it = t_qFileInfoList.constBegin(); it != t_qFileInfoList.constEnd(); ++it)
405 if (it->isDir() && it->fileName() != "." && it->fileName() != "..")
406 m_sListSubjects.append(it->fileName());
407
408 m_pUi->m_qComboBox_SubjectSelection->insertItems(0, m_sListSubjects);
409
410 qint32 idx = m_pUi->m_qComboBox_SubjectSelection->findText(m_sCurrentSubject);
411 if (idx >= 0)
412 m_pUi->m_qComboBox_SubjectSelection->setCurrentIndex(idx);
413 else {
414 m_pUi->m_qComboBox_SubjectSelection->setCurrentIndex(0);
415 selectNewSubject(m_pUi->m_qComboBox_SubjectSelection->itemText(0));
416 }
417}
418
419//=============================================================================================================
420
421void ProjectSettingsView::selectNewProject(const QString& sNewProject)
422{
423 m_sCurrentProject = sNewProject;
424 emit newProject(m_sCurrentProject);
425
426 scanForSubjects();
427 updateFileName();
428}
429
430//=============================================================================================================
431
432void ProjectSettingsView::selectNewSubject(const QString& sNewSubject)
433{
434 m_sCurrentSubject = sNewSubject;
435 emit newSubject(m_sCurrentSubject);
436
437 updateFileName();
438}
439
440//=============================================================================================================
441
442void ProjectSettingsView::updateFileName(bool currentTime)
443{
444 QString sFilePath = m_sDataPath + "/" + m_sCurrentProject + "/" + m_sCurrentSubject;
445
446 QString sTimeStamp;
447
448 if (currentTime) {
449 sTimeStamp = QDateTime::currentDateTime().toString("yyMMdd_hhmmss");
450 } else {
451 sTimeStamp = "<YYMMDD_HMS>";
452 }
453
454 if (m_sCurrentParadigm.isEmpty())
455 sFilePath.append("/" + sTimeStamp + "_" + m_sCurrentSubject + "_raw.fif");
456 else
457 sFilePath.append("/" + sTimeStamp + "_" + m_sCurrentSubject + "_" + m_sCurrentParadigm + "_raw.fif");
458
459 m_sFileName = sFilePath;
460
461 m_pUi->m_qLineEditFileName->setText(m_sFileName);
462
463 emit fileNameChanged(m_sFileName);
464}
465
466//=============================================================================================================
467
468void ProjectSettingsView::onTimeChanged()
469{
470 m_iRecordingTime = (m_pUi->m_spinBox_hours->value() * 60 * 60) + (m_pUi->m_spinBox_min->value() * 60) + (m_pUi->m_spinBox_sec->value());
471
472 m_iRecordingTime *= 1000;
473
474 QTime remainingTime(0, 0, 0, 0);
475
476 QTime remainingTimeFinal = remainingTime.addMSecs(m_iRecordingTime);
477
478 m_pUi->m_label_timeToGo->setText(remainingTimeFinal.toString());
479
480 emit timerChanged(m_iRecordingTime);
481}
482
483//=============================================================================================================
484
485void ProjectSettingsView::onRecordingTimerStateChanged(bool state)
486{
487 emit recordingTimerStateChanged(state);
488}
489
490//=============================================================================================================
491
495
496//=============================================================================================================
497
499{
500 updateFileName();
501}
502
503//=============================================================================================================
504
505void ProjectSettingsView::browseDirectories()
506{
507 QString sDir = QFileDialog::getExistingDirectory(this,
508 tr("Select Project Directory"),
509 QDir::homePath(),
510 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
511 if (!sDir.isEmpty() && !sDir.isNull()) {
512 m_sDataPath = sDir;
513 m_pUi->m_lineEditDirectory->setText(m_sDataPath);
514 scanForProjects();
515 scanForSubjects();
516 updateFileName(true);
517 }
518}
519
520//=============================================================================================================
521
523{
524 m_pUi->m_qLine->hide();
525 m_pUi->m_qLineEditFileName->hide();
526 m_pUi->m_qLabel->hide();
527}
528
529//=============================================================================================================
530
532{
533 m_pUi->m_qLine->show();
534 m_pUi->m_qLineEditFileName->show();
535 m_pUi->m_qLabel->show();
536}
537
538//=============================================================================================================
539
541{
542 m_pUi->m_qLabel_Paradigm->hide();
543 m_pUi->m_qLineEditParadigm->hide();
544}
545
546//=============================================================================================================
547
549{
550 m_pUi->m_qLabel_Paradigm->show();
551 m_pUi->m_qLineEditParadigm->show();
552}
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)