MNE-CPP  beta 1.0
babymegprojectdialog.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "babymegprojectdialog.h"
43 #include "ui_babymegprojectdialog.h"
44 
45 #include "../babymeg.h"
46 
47 
48 //*************************************************************************************************************
49 //=============================================================================================================
50 // Qt INCLUDES
51 //=============================================================================================================
52 
53 #include <QFileDialog>
54 #include <QString>
55 #include <QDir>
56 #include <QDebug>
57 #include <QSettings>
58 #include <QInputDialog>
59 
60 
61 //*************************************************************************************************************
62 //=============================================================================================================
63 // USED NAMESPACES
64 //=============================================================================================================
65 
66 using namespace BabyMEGPlugin;
67 
68 
69 //*************************************************************************************************************
70 //=============================================================================================================
71 // DEFINE MEMBER METHODS
72 //=============================================================================================================
73 
74 BabyMEGProjectDialog::BabyMEGProjectDialog(BabyMEG* p_pBabyMEG, QWidget *parent)
75 : m_pBabyMEG(p_pBabyMEG)
76 , QDialog(parent)
77 , ui(new Ui::BabyMEGProjectDialog)
78 {
79  ui->setupUi(this);
80 
81  scanForProjects();
82  scanForSubjects();
83 
84  connect(ui->m_qComboBox_ProjectSelection,static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
85  this,&BabyMEGProjectDialog::selectNewProject);
86 
87  connect(ui->m_qComboBox_SubjectSelection,static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
88  this,&BabyMEGProjectDialog::selectNewSubject);
89 
90  connect(ui->m_qLineEditParadigm,&QLineEdit::textChanged,
91  this,&BabyMEGProjectDialog::paradigmChanged);
92 
93  connect(ui->m_qPushButtonNewProject,&QPushButton::clicked,
94  this,&BabyMEGProjectDialog::addProject);
95 
96  connect(ui->m_qPushButtonNewSubject,&QPushButton::clicked,
97  this,&BabyMEGProjectDialog::addSubject);
98 
99  ui->m_qLineEditFileName->setReadOnly(true);
100 
101  updateFileName();
102 
103 
104 
105 
106 // QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
107 // tr("User name:"), QLineEdit::Normal,
108 // QDir::home().dirName(), &ok);
109 }
110 
111 
112 //*************************************************************************************************************
113 
114 BabyMEGProjectDialog::~BabyMEGProjectDialog()
115 {
116  delete ui;
117 }
118 
119 
120 //*************************************************************************************************************
121 
122 void BabyMEGProjectDialog::addProject()
123 {
124  bool ok;
125  QString sProject = QInputDialog::getText(this, tr("Add new Project"),
126  tr("Add new Project:"), QLineEdit::Normal,
127  tr("NewProject"), &ok);
128  if (ok && !sProject.isEmpty())
129  {
130  if(!QDir(m_pBabyMEG->m_sBabyMEGDataPath+"/" + sProject).exists())
131  QDir().mkdir(m_pBabyMEG->m_sBabyMEGDataPath+"/"+sProject);
132 
133  m_pBabyMEG->m_sCurrentProject = sProject;
134 
135  scanForProjects();
136  }
137 }
138 
139 
140 //*************************************************************************************************************
141 
142 void BabyMEGProjectDialog::addSubject()
143 {
144  bool ok;
145  QString sSubject = QInputDialog::getText(this, tr("Add new Subject"),
146  tr("Add new Subject:"), QLineEdit::Normal,
147  tr("NewSubject"), &ok);
148 
149  if (ok && !sSubject.isEmpty())
150  {
151  if(!QDir(m_pBabyMEG->m_sBabyMEGDataPath + "/" + m_pBabyMEG->m_sCurrentProject + "/" + sSubject).exists())
152  QDir().mkdir(m_pBabyMEG->m_sBabyMEGDataPath + "/" + m_pBabyMEG->m_sCurrentProject + "/" + sSubject);
153 
154  m_pBabyMEG->m_sCurrentSubject = sSubject;
155 
156  scanForSubjects();
157  }
158 }
159 
160 
161 //*************************************************************************************************************
162 
163 void BabyMEGProjectDialog::paradigmChanged(const QString &newParadigm)
164 {
165  m_pBabyMEG->m_sCurrentParadigm = newParadigm;
166  updateFileName();
167 }
168 
169 
170 //*************************************************************************************************************
171 
172 void BabyMEGProjectDialog::scanForProjects()
173 {
174  //clear
175  ui->m_qComboBox_ProjectSelection->clear();
176  m_sListProjects.clear();
177 
178  QDir t_qDirData(m_pBabyMEG->m_sBabyMEGDataPath);
179 
180  QFileInfoList t_qFileInfoList = t_qDirData.entryInfoList();
181  QFileInfoList::const_iterator it;
182  for (it = t_qFileInfoList.constBegin(); it != t_qFileInfoList.constEnd(); ++it)
183  if(it->isDir() && it->fileName() != "." && it->fileName() != "..")
184  m_sListProjects.append(it->fileName());
185 
186  ui->m_qComboBox_ProjectSelection->insertItems(0,m_sListProjects);
187  ui->m_qComboBox_ProjectSelection->setCurrentIndex(ui->m_qComboBox_ProjectSelection->findText(m_pBabyMEG->m_sCurrentProject));
188 }
189 
190 
191 //*************************************************************************************************************
192 
193 void BabyMEGProjectDialog::scanForSubjects()
194 {
195  //clear
196  ui->m_qComboBox_SubjectSelection->clear();
197  m_sListSubjects.clear();
198 
199  QDir t_qDirProject(m_pBabyMEG->m_sBabyMEGDataPath+"/"+m_pBabyMEG->m_sCurrentProject);
200 
201  QFileInfoList t_qFileInfoList = t_qDirProject.entryInfoList();
202  QFileInfoList::const_iterator it;
203  for (it = t_qFileInfoList.constBegin(); it != t_qFileInfoList.constEnd(); ++it)
204  if(it->isDir() && it->fileName() != "." && it->fileName() != "..")
205  m_sListSubjects.append(it->fileName());
206 
207  ui->m_qComboBox_SubjectSelection->insertItems(0,m_sListSubjects);
208 
209  qint32 idx = ui->m_qComboBox_SubjectSelection->findText(m_pBabyMEG->m_sCurrentSubject);
210  if(idx >= 0)
211  ui->m_qComboBox_SubjectSelection->setCurrentIndex(idx);
212  else
213  {
214  ui->m_qComboBox_SubjectSelection->setCurrentIndex(0);
215  selectNewSubject(ui->m_qComboBox_SubjectSelection->itemText(0));
216  }
217 }
218 
219 
220 //*************************************************************************************************************
221 
222 void BabyMEGProjectDialog::selectNewProject(const QString &newProject)
223 {
224  m_pBabyMEG->m_sCurrentProject = newProject;
225 
226  scanForSubjects();
227  updateFileName();
228 }
229 
230 
231 //*************************************************************************************************************
232 
233 void BabyMEGProjectDialog::selectNewSubject(const QString &newSubject)
234 {
235  m_pBabyMEG->m_sCurrentSubject = newSubject;
236 
237  updateFileName();
238 }
239 
240 
241 //*************************************************************************************************************
242 
243 void BabyMEGProjectDialog::updateFileName()
244 {
245  ui->m_qLineEditFileName->setText(m_pBabyMEG->getFilePath());
246 }
Definition: aboutwindow.h:52
The BabyMEG class provides a Fiff data simulator.
Definition: babymeg.h:101
QString getFilePath(bool currentTime=false) const
Definition: babymeg.cpp:144