MNE-CPP  0.1.9
A Framework for Electrophysiology
averagingsettingsview.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //=============================================================================================================
37 // INCLUDES
38 //=============================================================================================================
39 
40 #include "averagingsettingsview.h"
41 #include "ui_averagingsettingsview.h"
42 
43 #include <fiff/fiff_evoked_set.h>
44 
45 //=============================================================================================================
46 // QT INCLUDES
47 //=============================================================================================================
48 
49 #include <QSettings>
50 
51 //=============================================================================================================
52 // EIGEN INCLUDES
53 //=============================================================================================================
54 
55 //=============================================================================================================
56 // USED NAMESPACES
57 //=============================================================================================================
58 
59 using namespace DISPLIB;
60 using namespace FIFFLIB;
61 
62 //=============================================================================================================
63 // DEFINE MEMBER METHODS
64 //=============================================================================================================
65 
66 AveragingSettingsView::AveragingSettingsView(const QString& sSettingsPath,
67  const QMap<QString, int> &mapStimChsIndexNames,
68  QWidget *parent)
69 : AbstractView(parent)
70 , m_pUi(new Ui::AverageSettingsViewWidget)
71 , m_mapStimChsIndexNames(mapStimChsIndexNames)
72 {
73  m_sSettingsPath = sSettingsPath;
74  m_pUi->setupUi(this);
75 
76  this->setWindowTitle("Averaging Settings");
77  this->setMinimumWidth(330);
78  //this->setMaximumWidth(330);
79 
80  loadSettings();
81  redrawGUI();
82 }
83 
84 //=============================================================================================================
85 
87 {
88  saveSettings();
89  delete m_pUi;
90 }
91 
92 //=============================================================================================================
93 
94 void AveragingSettingsView::setStimChannels(const QMap<QString,int>& mapStimChsIndexNames)
95 {
96  if(!mapStimChsIndexNames.isEmpty()) {
97  m_mapStimChsIndexNames = mapStimChsIndexNames;
98 
99  m_pUi->m_pComboBoxChSelection->clear();
100 
101  QMapIterator<QString, int> i(mapStimChsIndexNames);
102  while (i.hasNext()) {
103  i.next();
104  m_pUi->m_pComboBoxChSelection->insertItem(m_pUi->m_pComboBoxChSelection->count(),i.key());
105  }
106 
107  m_pUi->m_pComboBoxChSelection->setCurrentText(m_sCurrentStimChan);
108 
109  connect(m_pUi->m_pComboBoxChSelection, &QComboBox::currentTextChanged,
110  this, &AveragingSettingsView::onChangeStimChannel);
111  }
112 }
113 
114 //=============================================================================================================
115 
116 QString AveragingSettingsView::getCurrentStimCh()
117 {
118  return m_sCurrentStimChan;
119 }
120 
121 //=============================================================================================================
122 
123 bool AveragingSettingsView::getDoBaselineCorrection()
124 {
125  return m_bDoBaselineCorrection;
126 }
127 
128 //=============================================================================================================
129 
130 int AveragingSettingsView::getNumAverages()
131 {
132  return m_iNumAverages;
133 }
134 
135 //=============================================================================================================
136 
137 int AveragingSettingsView::getBaselineFromSeconds()
138 {
139  return m_iBaselineFromSeconds;
140 }
141 
142 //=============================================================================================================
143 
144 int AveragingSettingsView::getBaselineToSeconds()
145 {
146  return m_iBaselineToSeconds;
147 }
148 
149 //=============================================================================================================
150 
151 int AveragingSettingsView::getPreStimMSeconds()
152 {
153  return m_iPreStimSeconds;
154 }
155 
156 //=============================================================================================================
157 
158 int AveragingSettingsView::getPostStimMSeconds()
159 {
160  return m_iPostStimSeconds;
161 }
162 
163 //=============================================================================================================
164 
165 int AveragingSettingsView::getStimChannelIdx()
166 {
167  return m_pUi->m_pComboBoxChSelection->currentData().toInt();
168 }
169 
170 //=============================================================================================================
171 
173 {
174  if(!m_mapStimChsIndexNames.isEmpty()) {
175  m_pUi->m_pComboBoxChSelection->clear();
176 
177  QMapIterator<QString, int> i(m_mapStimChsIndexNames);
178  while (i.hasNext()) {
179  i.next();
180  m_pUi->m_pComboBoxChSelection->insertItem(m_pUi->m_pComboBoxChSelection->count(),i.key());
181  }
182 
183  m_pUi->m_pComboBoxChSelection->setCurrentText(m_sCurrentStimChan);
184 
185  connect(m_pUi->m_pComboBoxChSelection, &QComboBox::currentTextChanged,
186  this, &AveragingSettingsView::changeStimChannel);
187  }
188 
189  m_pUi->m_pSpinBoxNumAverages->setValue(m_iNumAverages);
190  connect(m_pUi->m_pSpinBoxNumAverages, static_cast<void (QSpinBox::*)()>(&QSpinBox::editingFinished),
191  this, &AveragingSettingsView::onChangeNumAverages);
192 
193  //Pre Post stimulus
194  m_pUi->m_pSpinBoxPreStimMSeconds->setValue(m_iPreStimSeconds);
195  connect(m_pUi->m_pSpinBoxPreStimMSeconds, static_cast<void (QSpinBox::*)()>(&QSpinBox::editingFinished),
196  this, &AveragingSettingsView::onChangePreStim);
197 
198  m_pUi->m_pSpinBoxPostStimMSeconds->setValue(m_iPostStimSeconds);
199  connect(m_pUi->m_pSpinBoxPostStimMSeconds, static_cast<void (QSpinBox::*)()>(&QSpinBox::editingFinished),
200  this, &AveragingSettingsView::onChangePostStim);
201 
202  //Baseline Correction
203  m_pUi->m_pcheckBoxBaselineCorrection->setChecked(m_bDoBaselineCorrection);
204  connect(m_pUi->m_pcheckBoxBaselineCorrection, &QCheckBox::clicked,
205  this, &AveragingSettingsView::changeBaselineActive);
206 
207  m_pUi->m_pSpinBoxBaselineFromMSeconds->setMinimum(m_pUi->m_pSpinBoxPreStimMSeconds->value()*-1);
208  m_pUi->m_pSpinBoxBaselineFromMSeconds->setMaximum(m_pUi->m_pSpinBoxPostStimMSeconds->value());
209  m_pUi->m_pSpinBoxBaselineFromMSeconds->setValue(m_iBaselineFromSeconds);
210  connect(m_pUi->m_pSpinBoxBaselineFromMSeconds, static_cast<void (QSpinBox::*)()>(&QSpinBox::editingFinished),
211  this, &AveragingSettingsView::onChangeBaselineFrom);
212 
213  m_pUi->m_pSpinBoxBaselineToMSeconds->setMinimum(m_pUi->m_pSpinBoxPreStimMSeconds->value()*-1);
214  m_pUi->m_pSpinBoxBaselineToMSeconds->setMaximum(m_pUi->m_pSpinBoxPostStimMSeconds->value());
215  m_pUi->m_pSpinBoxBaselineToMSeconds->setValue(m_iBaselineToSeconds);
216  connect(m_pUi->m_pSpinBoxBaselineToMSeconds, static_cast<void (QSpinBox::*)()>(&QSpinBox::editingFinished),
217  this, &AveragingSettingsView::onChangeBaselineTo);
218 
219  connect(m_pUi->m_pushButton_reset, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
220  this, &AveragingSettingsView::resetAverage);
221 
222  connect(m_pUi->m_pushButton_compute, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
223  this, &AveragingSettingsView::calculateAverage);
224  connect(m_pUi->m_checkBox_reject, &QCheckBox::clicked,
225  this, &AveragingSettingsView::changeDropActive);
226 
227  connect(m_pUi->checkBox_autoCompute, &QCheckBox::clicked,
228  this, &AveragingSettingsView::setAutoCompute);
229 
230  m_pUi->m_pushButton_compute->hide();
231  m_pUi->m_checkBox_reject->hide();
232  m_pUi->m_pushButton_compute->hide();
233 
234  setWindowFlags(Qt::WindowStaysOnTopHint);
235 
236  m_pUi->m_groupBox_detectedTrials->hide();
237 }
238 
239 //=============================================================================================================
240 
241 void AveragingSettingsView::setDetectedEpochs(const FiffEvokedSet& evokedSet)
242 {
243  if(evokedSet.evoked.isEmpty()) {
244  m_pUi->m_groupBox_detectedTrials->hide();
245  return;
246  } else {
247  m_pUi->m_groupBox_detectedTrials->show();
248  }
249 
250  QGridLayout* topLayout = static_cast<QGridLayout*>(m_pUi->m_groupBox_detectedTrials->layout());
251  if(!topLayout) {
252  topLayout = new QGridLayout();
253  }
254 
255  QLayoutItem *child;
256  while ((child = topLayout->takeAt(0)) != 0) {
257  delete child->widget();
258  delete child;
259  }
260 
261  topLayout->addWidget(new QLabel("Type"),0,0);
262  topLayout->addWidget(new QLabel("#"),0,1);
263 
264  for(int i = 0; i < evokedSet.evoked.size(); i++) {
265  if(i < 10) {
266  // Show only a maximum of 10 average types
267  topLayout->addWidget(new QLabel(evokedSet.evoked.at(i).comment),i+1,0);
268  topLayout->addWidget(new QLabel(QString::number(evokedSet.evoked.at(i).nave)),i+1,1);
269  }
270  }
271 
272  //Find Filter tab and add current layout
273  m_pUi->m_groupBox_detectedTrials->setLayout(topLayout);
274 }
275 
276 //=============================================================================================================
277 
279 {
280  if(m_sSettingsPath.isEmpty()) {
281  return;
282  }
283 
284  // Save Settings
285  QSettings settings("MNECPP");
286 
287  settings.setValue(m_sSettingsPath + QString("/AveragingSettingsView/preStimSeconds"), m_iPreStimSeconds);
288  settings.setValue(m_sSettingsPath + QString("/AveragingSettingsView/postStimSeconds"), m_iPostStimSeconds);
289  settings.setValue(m_sSettingsPath + QString("/AveragingSettingsView/numAverages"), m_iNumAverages);
290  settings.setValue(m_sSettingsPath + QString("/AveragingSettingsView/currentStimChannel"), m_sCurrentStimChan);
291  settings.setValue(m_sSettingsPath + QString("/AveragingSettingsView/baselineFromSeconds"), m_iBaselineFromSeconds);
292  settings.setValue(m_sSettingsPath + QString("/AveragingSettingsView/baselineToSeconds"), m_iBaselineToSeconds);
293  settings.setValue(m_sSettingsPath + QString("/AveragingSettingsView/doBaselineCorrection"), m_bDoBaselineCorrection);
294 }
295 
296 //=============================================================================================================
297 
299 {
300  if(m_sSettingsPath.isEmpty()) {
301  return;
302  }
303 
304  // Load Settings
305  QSettings settings("MNECPP");
306 
307  m_iPreStimSeconds = settings.value(m_sSettingsPath + QString("/AveragingSettingsView/preStimSeconds"), 100).toInt();
308  m_iPostStimSeconds = settings.value(m_sSettingsPath + QString("/AveragingSettingsView/postStimSeconds"), 400).toInt();
309  m_iBaselineFromSeconds = settings.value(m_sSettingsPath + QString("/AveragingSettingsView/baselineFromSeconds"), 0).toInt();
310  m_iBaselineToSeconds = settings.value(m_sSettingsPath + QString("/AveragingSettingsView/baselineToSeconds"), 0).toInt();
311 
312  if(m_iBaselineFromSeconds < -1 * m_iPreStimSeconds || m_iBaselineFromSeconds > m_iPostStimSeconds) {
313  m_iBaselineFromSeconds = -1 * m_iPreStimSeconds;
314  }
315 
316  if(m_iBaselineToSeconds > m_iPostStimSeconds || m_iBaselineToSeconds < m_iPreStimSeconds) {
317  m_iBaselineToSeconds = 0;
318  }
319 
320  m_iNumAverages = settings.value(m_sSettingsPath + QString("/AveragingSettingsView/numAverages"), 10).toInt();
321  m_sCurrentStimChan = settings.value(m_sSettingsPath + QString("/AveragingSettingsView/currentStimChannel"), "STI014").toString();
322  m_bDoBaselineCorrection = settings.value(m_sSettingsPath + QString("/AveragingSettingsView/doBaselineCorrection"), false).toBool();
323 }
324 
325 //=============================================================================================================
326 
328 {
329  switch(mode) {
330  case GuiMode::Clinical:
331  break;
332  default: // default is research mode
333  break;
334  }
335 }
336 
337 //=============================================================================================================
338 
340 {
341  switch(mode) {
342  case ProcessingMode::Offline:
343  m_pUi->m_pSpinBoxNumAverages->hide();
344  m_pUi->m_pComboBoxChSelection->hide();
345  m_pUi->m_pushButton_reset->hide();
346  m_pUi->label->hide();
347  m_pUi->m_label_numberAverages->hide();
348  m_pUi->m_pushButton_compute->show();
349  m_pUi->m_checkBox_reject->show();
350  m_pUi->checkBox_autoCompute->show();
351  break;
352  default: // default is realtime mode
353  m_pUi->m_pSpinBoxNumAverages->show();
354  m_pUi->m_pComboBoxChSelection->show();
355  m_pUi->m_pushButton_reset->show();
356  m_pUi->label->show();
357  m_pUi->m_label_numberAverages->show();
358  m_pUi->m_pushButton_compute->hide();
359  m_pUi->m_checkBox_reject->hide();
360  m_pUi->checkBox_autoCompute->hide();
361  break;
362  }
363 }
364 //=============================================================================================================
365 
366 void AveragingSettingsView::onChangePreStim()
367 {
368  qint32 mSeconds = m_pUi->m_pSpinBoxPreStimMSeconds->value();
369  m_pUi->m_pSpinBoxBaselineToMSeconds->setMinimum(m_pUi->m_pSpinBoxPreStimMSeconds->value()*-1);
370  m_pUi->m_pSpinBoxBaselineFromMSeconds->setMinimum(m_pUi->m_pSpinBoxPreStimMSeconds->value()*-1);
371 
372  m_iPreStimSeconds = mSeconds;
373 
374  emit changePreStim(mSeconds);
375 
376  saveSettings();
377 }
378 
379 //=============================================================================================================
380 
381 void AveragingSettingsView::onChangePostStim()
382 {
383  qint32 mSeconds = m_pUi->m_pSpinBoxPostStimMSeconds->value();
384  m_pUi->m_pSpinBoxBaselineToMSeconds->setMaximum(m_pUi->m_pSpinBoxPostStimMSeconds->value());
385  m_pUi->m_pSpinBoxBaselineFromMSeconds->setMaximum(m_pUi->m_pSpinBoxPostStimMSeconds->value());
386 
387  m_iPostStimSeconds = mSeconds;
388 
389  emit changePostStim(mSeconds);
390 
391  saveSettings();
392 }
393 
394 //=============================================================================================================
395 
396 void AveragingSettingsView::onChangeBaselineFrom()
397 {
398  qint32 mSeconds = m_pUi->m_pSpinBoxBaselineFromMSeconds->value();
399  m_pUi->m_pSpinBoxBaselineToMSeconds->setMinimum(mSeconds);
400 
401  m_iBaselineFromSeconds = mSeconds;
402 
403  emit changeBaselineFrom(mSeconds);
404 
405  saveSettings();
406 }
407 
408 //=============================================================================================================
409 
410 void AveragingSettingsView::onChangeBaselineTo()
411 {
412  qint32 mSeconds = m_pUi->m_pSpinBoxBaselineToMSeconds->value();
413  m_pUi->m_pSpinBoxBaselineFromMSeconds->setMaximum(mSeconds);
414 
415  m_iBaselineToSeconds = mSeconds;
416 
417  emit changeBaselineTo(mSeconds);
418 
419  saveSettings();
420 }
421 
422 //=============================================================================================================
423 
424 void AveragingSettingsView::onChangeNumAverages()
425 {
426  m_iNumAverages = m_pUi->m_pSpinBoxNumAverages->value();
427 
428  emit changeNumAverages(m_pUi->m_pSpinBoxNumAverages->value());
429 
430  saveSettings();
431 }
432 
433 //=============================================================================================================
434 
435 void AveragingSettingsView::onChangeStimChannel()
436 {
437  m_sCurrentStimChan = m_pUi->m_pComboBoxChSelection->currentText();
438 
439  emit changeStimChannel(m_sCurrentStimChan);
440 
441  saveSettings();
442 }
443 
444 //=============================================================================================================
445 
447 {
448 
449 }
450 
451 //=============================================================================================================
452 
453 bool AveragingSettingsView::getAutoComputeStatus()
454 {
455  return m_pUi->checkBox_autoCompute->isChecked();
456 }
DISPLIB::AveragingSettingsView::m_pUi
Ui::AverageSettingsViewWidget * m_pUi
Definition: averagingsettingsview.h:177
DISPLIB::AverageSelectionView::redrawGUI
void redrawGUI()
Definition: averageselectionview.cpp:206
fiff_evoked_set.h
FiffEvokedSet class declaration.
DISPLIB::AbstractView
The AbstractView class provides the base calss for all Disp viewers.
Definition: abstractview.h:75
DISPLIB::AveragingSettingsView::updateProcessingMode
void updateProcessingMode(ProcessingMode mode)
Definition: averagingsettingsview.cpp:339
FIFFLIB::FiffEvokedSet
evoked data set
Definition: fiff_evoked_set.h:76
DISPLIB::AveragingSettingsView::~AveragingSettingsView
~AveragingSettingsView()
Definition: averagingsettingsview.cpp:86
DISPLIB::AveragingSettingsView::redrawGUI
void redrawGUI()
Definition: averagingsettingsview.cpp:172
DISPLIB::AverageSelectionView::loadSettings
void loadSettings()
Definition: averageselectionview.cpp:157
DISPLIB::AveragingSettingsView::saveSettings
void saveSettings()
Definition: averagingsettingsview.cpp:278
DISPLIB::AveragingSettingsView::updateGuiMode
void updateGuiMode(GuiMode mode)
Definition: averagingsettingsview.cpp:327
averagingsettingsview.h
Contains the declaration of the AveragingSettingsView class.
DISPLIB::AbstractView::m_sSettingsPath
QString m_sSettingsPath
Definition: abstractview.h:169
FIFFLIB::FiffEvokedSet::evoked
QList< FiffEvoked > evoked
Definition: fiff_evoked_set.h:190
DISPLIB::AveragingSettingsView::loadSettings
void loadSettings()
Definition: averagingsettingsview.cpp:298
DISPLIB::AveragingSettingsView::clearView
void clearView()
Definition: averagingsettingsview.cpp:446