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