42 #include "ui_projectsettingsview.h"
50 #include <QInputDialog>
51 #include <QMessageBox>
54 #include <QFileDialog>
64 using namespace DISPLIB;
70 ProjectSettingsView::ProjectSettingsView(
const QString& sSettingsPath,
71 const QString& sDataPath,
72 const QString& sCurrentProject,
73 const QString& sCurrentSubject,
74 const QString& sCurrentParadigm,
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)
92 m_pUi->m_qLineEditFileName->setReadOnly(
true);
94 m_pUi->m_lineEditDirectory->setReadOnly(
true);
95 m_pUi->m_lineEditDirectory->setText(m_sDataPath);
100 m_pUi->m_label_RemainingTime->hide();
101 m_pUi->m_label_timeToGo->hide();
108 m_pUi->m_qPushButtonDeleteProject->hide();
109 m_pUi->m_qPushButtonDeleteSubject->hide();
116 void ProjectSettingsView::connectGui()
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);
122 connect(m_pUi->m_qComboBox_SubjectSelection,
static_cast<void (QComboBox::*)(
const QString&)
>(&QComboBox::currentIndexChanged),
123 this,&ProjectSettingsView::selectNewSubject);
125 connect(m_pUi->m_qComboBox_ProjectSelection,&QComboBox::currentTextChanged,
126 this,&ProjectSettingsView::selectNewProject);
128 connect(m_pUi->m_qComboBox_SubjectSelection,&QComboBox::currentTextChanged,
129 this,&ProjectSettingsView::selectNewSubject);
131 connect(m_pUi->m_qLineEditParadigm,&QLineEdit::textChanged,
132 this,&ProjectSettingsView::paradigmChanged);
134 connect(m_pUi->m_qPushButtonNewProject,&QPushButton::clicked,
135 this,&ProjectSettingsView::addProject);
137 connect(m_pUi->m_qPushButtonNewSubject,&QPushButton::clicked,
138 this,&ProjectSettingsView::addSubject);
140 connect(m_pUi->m_qPushButtonDeleteProject,&QPushButton::clicked,
141 this,&ProjectSettingsView::deleteProject);
143 connect(m_pUi->m_qPushButtonDeleteSubject,&QPushButton::clicked,
144 this,&ProjectSettingsView::deleteSubject);
146 connect(m_pUi->m_spinBox_hours,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
147 this,&ProjectSettingsView::onTimeChanged);
149 connect(m_pUi->m_spinBox_min,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
150 this,&ProjectSettingsView::onTimeChanged);
152 connect(m_pUi->m_spinBox_sec,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
153 this,&ProjectSettingsView::onTimeChanged);
155 connect(m_pUi->m_checkBox_useRecordingTimer,&QCheckBox::toggled,
156 this,&ProjectSettingsView::onRecordingTimerStateChanged);
158 connect(m_pUi->m_pushButtonDirectory, &QPushButton::released,
159 this, &ProjectSettingsView::browseDirectories);
164 ProjectSettingsView::~ProjectSettingsView()
179 QSettings settings(
"MNECPP");
191 QSettings settings(
"MNECPP");
199 case GuiMode::Clinical:
211 case ProcessingMode::Offline:
222 QTime remainingTime(0,0,0,0);
224 QTime remainingTimeFinal = remainingTime.addMSecs(m_iRecordingTime-mSecsElapsed);
226 m_pUi->m_label_timeToGo->setText(remainingTimeFinal.toString());
228 QTime passedTime(0,0,0,0);
233 if(m_iRecordingTime-mSecsElapsed < 500) {
234 mSecsElapsed = m_iRecordingTime;
237 QTime passedTimeFinal = passedTime.addMSecs(mSecsElapsed);
239 m_pUi->m_label_timePassed->setText(passedTimeFinal.toString(
"HH:mm:ss"));
254 void ProjectSettingsView::deleteSubject()
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);
265 if(msgBox.clickedButton() == keepData)
268 if(msgBox.clickedButton() == deleteData) {
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();
278 if(ret == QMessageBox::No)
281 QString dirName = m_sDataPath +
"/" + m_pUi->m_qComboBox_ProjectSelection->currentText() +
"/" + m_pUi->m_qComboBox_SubjectSelection->currentText();
285 bool result = dir.removeRecursively();
288 qDebug()<<
"Could not remove all data from the subject folder!";
290 m_pUi->m_qComboBox_SubjectSelection->removeItem(m_pUi->m_qComboBox_SubjectSelection->currentIndex());
296 void ProjectSettingsView::deleteProject()
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);
307 if(msgBox.clickedButton() == keepData)
310 if(msgBox.clickedButton() == deleteData) {
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();
320 if(ret == QMessageBox::No)
323 QString dirName = m_sDataPath +
"/" + m_pUi->m_qComboBox_ProjectSelection->currentText();
327 bool result = dir.removeRecursively();
330 qDebug()<<
"Could not remove all data from the project folder!";
332 m_pUi->m_qComboBox_ProjectSelection->removeItem(m_pUi->m_qComboBox_ProjectSelection->currentIndex());
338 void ProjectSettingsView::addProject()
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())
346 if(!QDir(m_sDataPath+
"/" + sProject).exists())
347 QDir().mkdir(m_sDataPath+
"/"+sProject);
349 m_sCurrentProject = sProject;
350 emit newProject(m_sCurrentProject);
358 void ProjectSettingsView::addSubject()
361 QString sSubject = QInputDialog::getText(
this, tr(
"Add new Subject"),
362 tr(
"Add new Subject:"), QLineEdit::Normal,
363 tr(
"NewSubject"), &ok);
365 if (ok && !sSubject.isEmpty())
367 if(!QDir(m_sDataPath +
"/" + m_sCurrentProject +
"/" + sSubject).exists())
368 QDir().mkdir(m_sDataPath +
"/" + m_sCurrentProject +
"/" + sSubject);
370 m_sCurrentSubject = sSubject;
372 emit newSubject(m_sCurrentSubject);
380 void ProjectSettingsView::paradigmChanged(
const QString &sNewParadigm)
382 m_sCurrentParadigm = sNewParadigm;
383 emit newParadigm(m_sCurrentParadigm);
389 void ProjectSettingsView::scanForProjects()
392 m_pUi->m_qComboBox_ProjectSelection->clear();
393 m_sListProjects.clear();
395 QDir t_qDirData(m_sDataPath);
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());
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));
409 void ProjectSettingsView::scanForSubjects()
412 m_pUi->m_qComboBox_SubjectSelection->clear();
413 m_sListSubjects.clear();
415 QDir t_qDirProject(m_sDataPath+
"/"+m_sCurrentProject);
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());
423 m_pUi->m_qComboBox_SubjectSelection->insertItems(0,m_sListSubjects);
425 qint32 idx = m_pUi->m_qComboBox_SubjectSelection->findText(m_sCurrentSubject);
427 m_pUi->m_qComboBox_SubjectSelection->setCurrentIndex(idx);
430 m_pUi->m_qComboBox_SubjectSelection->setCurrentIndex(0);
431 selectNewSubject(m_pUi->m_qComboBox_SubjectSelection->itemText(0));
437 void ProjectSettingsView::selectNewProject(
const QString &sNewProject)
439 m_sCurrentProject = sNewProject;
440 emit newProject(m_sCurrentProject);
448 void ProjectSettingsView::selectNewSubject(
const QString &sNewSubject)
450 m_sCurrentSubject = sNewSubject;
451 emit newSubject(m_sCurrentSubject);
458 void ProjectSettingsView::updateFileName(
bool currentTime)
460 QString sFilePath = m_sDataPath +
"/" + m_sCurrentProject +
"/" + m_sCurrentSubject;
465 sTimeStamp = QDateTime::currentDateTime().toString(
"yyMMdd_hhmmss");
467 sTimeStamp =
"<YYMMDD_HMS>";
470 if(m_sCurrentParadigm.isEmpty())
471 sFilePath.append(
"/"+ sTimeStamp +
"_" + m_sCurrentSubject +
"_raw.fif");
473 sFilePath.append(
"/"+ sTimeStamp +
"_" + m_sCurrentSubject +
"_" + m_sCurrentParadigm +
"_raw.fif");
475 m_sFileName = sFilePath;
477 m_pUi->m_qLineEditFileName->setText(m_sFileName);
479 emit fileNameChanged(m_sFileName);
484 void ProjectSettingsView::onTimeChanged()
486 m_iRecordingTime = (m_pUi->m_spinBox_hours->value()*60*60)+(m_pUi->m_spinBox_min->value()*60)+(m_pUi->m_spinBox_sec->value());
488 m_iRecordingTime*=1000;
490 QTime remainingTime(0,0,0,0);
492 QTime remainingTimeFinal = remainingTime.addMSecs(m_iRecordingTime);
494 m_pUi->m_label_timeToGo->setText(remainingTimeFinal.toString());
496 emit timerChanged(m_iRecordingTime);
501 void ProjectSettingsView::onRecordingTimerStateChanged(
bool state)
503 emit recordingTimerStateChanged(state);
522 void ProjectSettingsView::browseDirectories()
524 QString sDir = QFileDialog::getExistingDirectory(
this,
525 tr(
"Select Project Directory"),
527 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
528 if(!sDir.isEmpty() && !sDir.isNull()){
530 m_pUi->m_lineEditDirectory->setText(m_sDataPath);
533 updateFileName(
true);
541 m_pUi->m_qLine->hide();
542 m_pUi->m_qLineEditFileName->hide();
543 m_pUi->m_qLabel->hide();
550 m_pUi->m_qLine->show();
551 m_pUi->m_qLineEditFileName->show();
552 m_pUi->m_qLabel->show();
559 m_pUi->m_qLabel_Paradigm->hide();
560 m_pUi->m_qLineEditParadigm->hide();
567 m_pUi->m_qLabel_Paradigm->show();
568 m_pUi->m_qLineEditParadigm->show();