v2.0.0
Loading...
Searching...
No Matches
triggerdetectionview.cpp
Go to the documentation of this file.
1//=============================================================================================================
14
15//=============================================================================================================
16// INCLUDES
17//=============================================================================================================
18
20
21#include "ui_triggerdetectionview.h"
22
23#include <fiff/fiff_info.h>
24
25//=============================================================================================================
26// QT INCLUDES
27//=============================================================================================================
28
29#include <QColorDialog>
30#include <QPalette>
31#include <QSettings>
32
33//=============================================================================================================
34// EIGEN INCLUDES
35//=============================================================================================================
36
37//=============================================================================================================
38// USED NAMESPACES
39//=============================================================================================================
40
41using namespace DISPLIB;
42using namespace FIFFLIB;
43
44//=============================================================================================================
45// DEFINE MEMBER METHODS
46//=============================================================================================================
47
48TriggerDetectionView::TriggerDetectionView(const QString& sSettingsPath,
49 QWidget *parent,
50 Qt::WindowFlags f)
51: AbstractView(parent, f)
52, m_pUi(new Ui::TriggerDetectionViewWidget)
53{
54 m_sSettingsPath = sSettingsPath;
55 m_pUi->setupUi(this);
56
57 this->setWindowTitle("Trigger Detection Settings");
58 this->setMinimumWidth(330);
59 this->setMaximumWidth(330);
60
62
64}
65
66//=============================================================================================================
67
74
75//=============================================================================================================
76
78{
79 if(pFiffInfo) {
80 m_pFiffInfo = pFiffInfo;
81 //Trigger detection
82 connect(m_pUi->m_checkBox_activateTriggerDetection, &QCheckBox::checkStateChanged,
84
85 m_pUi->m_comboBox_triggerChannels->clear();
86
87 for(int i = 0; i<m_pFiffInfo->chs.size(); i++) {
88 if(m_pFiffInfo->chs[i].kind == FIFFV_STIM_CH) {
89 m_pUi->m_comboBox_triggerChannels->addItem(m_pFiffInfo->chs[i].ch_name);
90 }
91 }
92
93 connect(m_pUi->m_comboBox_triggerChannels, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged),
95
96 connect(m_pUi->m_comboBox_triggerColorType, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged),
98
99 connect(m_pUi->m_pushButton_triggerColor, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
101
102 m_pUi->m_pushButton_triggerColor->setAutoFillBackground(true);
103 m_pUi->m_pushButton_triggerColor->setFlat(true);
104 QPalette* palette1 = new QPalette();
105 palette1->setColor(QPalette::Button,QColor(177,0,0));
106 m_pUi->m_pushButton_triggerColor->setPalette(*palette1);
107 m_pUi->m_pushButton_triggerColor->update();
108
109 connect(m_pUi->m_doubleSpinBox_detectionThresholdFirst, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
111
112 connect(m_pUi->m_spinBox_detectionThresholdSecond, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
114
115 connect(m_pUi->m_pushButton_resetNumberTriggers, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
117
118 connect(m_pUi->m_pushButton_DetectTriggers, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
119 this, &TriggerDetectionView::onDetectTriggers, Qt::UniqueConnection);
120
121 loadSettings();
122 }
123}
124
125//=============================================================================================================
126
127void TriggerDetectionView::setNumberDetectedTriggersAndTypes(int numberDetections, const QMap<int,QList<QPair<int,double> > >& mapDetectedTriggers)
128{
129 //if(m_bTriggerDetection) {
130 m_pUi->m_label_numberDetectedTriggers->setText(QString("%1").arg(numberDetections));
131 //}
132
133 //Set trigger types
134 QMapIterator<int,QList<QPair<int,double> > > i(mapDetectedTriggers);
135 while (i.hasNext()) {
136 i.next();
137
138 for(int j = 0; j < i.value().size(); ++j) {
139 if(m_pUi->m_comboBox_triggerColorType->findText(QString::number(i.value().at(j).second)) == -1) {
140 m_pUi->m_comboBox_triggerColorType->addItem(QString::number(i.value().at(j).second));
141 }
142 }
143 }
144}
145
146//=============================================================================================================
147
149{
150 if(m_sSettingsPath.isEmpty()) {
151 return;
152 }
153
154 QSettings settings("MNECPP");
155
156 settings.setValue(m_sSettingsPath + QString("/TriggerDetectionView/Activated"), m_pUi->m_checkBox_activateTriggerDetection->isChecked());
157 settings.setValue(m_sSettingsPath + QString("/TriggerDetectionView/ChannelIndex"), m_pUi->m_comboBox_triggerChannels->currentIndex());
158 settings.setValue(m_sSettingsPath + QString("/TriggerDetectionView/FirstThresholdValue"), m_pUi->m_doubleSpinBox_detectionThresholdFirst->value());
159 settings.setValue(m_sSettingsPath + QString("/TriggerDetectionView/SecondThresholdValue"), m_pUi->m_spinBox_detectionThresholdSecond->value());
160
161 settings.beginGroup(m_sSettingsPath + QString("/TriggerDetectionView/Colors"));
162 QMap<double, QColor>::const_iterator i = m_qMapTriggerColor.constBegin();
163 while (i != m_qMapTriggerColor.constEnd()) {
164 settings.setValue(QString::number(i.key()), i.value());
165 ++i;
166 }
167 settings.endGroup();
168}
169
170//=============================================================================================================
171
173{
174 if(m_sSettingsPath.isEmpty()) {
175 return;
176 }
177
178 QSettings settings("MNECPP");
179
180 m_pUi->m_checkBox_activateTriggerDetection->setChecked(settings.value(m_sSettingsPath + QString("/TriggerDetectionView/Activated"), false).toBool());
181 m_pUi->m_comboBox_triggerChannels->setCurrentIndex(settings.value(m_sSettingsPath + QString("/TriggerDetectionView/ChannelIndex"), 0).toInt());
182 m_pUi->m_doubleSpinBox_detectionThresholdFirst->setValue(settings.value(m_sSettingsPath + QString("/TriggerDetectionView/FirstThresholdValue"), 0.1).toDouble());
183 m_pUi->m_spinBox_detectionThresholdSecond->setValue(settings.value(m_sSettingsPath + QString("/TriggerDetectionView/SecondThresholdValue"), -1).toInt());
184
185 settings.beginGroup(m_sSettingsPath + QString("/TriggerDetectionView/Colors"));
186 QStringList keys = settings.childKeys();
187 foreach (QString key, keys) {
188 double dKey = key.toDouble();
189 m_qMapTriggerColor[dKey] = settings.value(key).value<QColor>();
190 }
191 settings.endGroup();
192
194}
195
196//=============================================================================================================
197
199{
200 switch(mode) {
202 break;
203 default: // default is research mode
204 break;
205 }
206}
207
208//=============================================================================================================
209
211{
212 switch(mode) {
214 m_pUi->label->hide();
215 m_pUi->label_9->hide();
216 m_pUi->m_pushButton_resetNumberTriggers->hide();
217 m_pUi->m_pushButton_triggerColor->hide();
218 m_pUi->m_checkBox_activateTriggerDetection->hide();
219 m_pUi->m_comboBox_triggerColorType->hide();
220 m_pUi->m_label_numberDetectedTriggers->hide();
221 m_pUi->m_pushButton_DetectTriggers->show();
222 break;
223 default: // default is realtime mode
224 m_pUi->label->show();
225 m_pUi->label_9->show();
226 m_pUi->m_pushButton_resetNumberTriggers->show();
227 m_pUi->m_pushButton_triggerColor->show();
228 m_pUi->m_checkBox_activateTriggerDetection->show();
229 m_pUi->m_comboBox_triggerColorType->show();
230 m_pUi->m_label_numberDetectedTriggers->show();
231 m_pUi->m_pushButton_DetectTriggers->hide();
232 break;
233 }
234}
235
236//=============================================================================================================
237
239{
241 m_pUi->m_checkBox_activateTriggerDetection->isChecked(),
242 m_pUi->m_comboBox_triggerChannels->currentText(),
243 m_pUi->m_doubleSpinBox_detectionThresholdFirst->value()*pow(10, m_pUi->m_spinBox_detectionThresholdSecond->value()));
244
245 saveSettings();
246}
247
248//=============================================================================================================
249
251{
252 Q_UNUSED(state);
253
254 QColor color = QColorDialog::getColor(m_qMapTriggerColor[m_pUi->m_comboBox_triggerColorType->currentText().toDouble()], this, "Set trigger color");
255
256 //Change color of pushbutton
257 QPalette* palette1 = new QPalette();
258 palette1->setColor(QPalette::Button,color);
259 m_pUi->m_pushButton_triggerColor->setPalette(*palette1);
260 m_pUi->m_pushButton_triggerColor->update();
261
262 m_qMapTriggerColor[m_pUi->m_comboBox_triggerColorType->currentText().toDouble()] = color;
263
265}
266
267//=============================================================================================================
268
270{
271 //Change color of pushbutton
272 QPalette* palette1 = new QPalette();
273 palette1->setColor(QPalette::Button,m_qMapTriggerColor[value.toDouble()]);
274 m_pUi->m_pushButton_triggerColor->setPalette(*palette1);
275 m_pUi->m_pushButton_triggerColor->update();
276}
277
278//=============================================================================================================
279
281{
282 m_pUi->m_label_numberDetectedTriggers->setText(QString("0"));
283 m_pUi->m_comboBox_triggerColorType->clear();
284
285 emit resetTriggerCounter();
286
287 //emit updateConnectedView();
288}
289
290//=============================================================================================================
291
293{
294 if(m_pUi->m_comboBox_triggerChannels->currentText() == ""){
295 return;
296 }
297 emit detectTriggers(m_pUi->m_comboBox_triggerChannels->currentText(),
298 m_pUi->m_doubleSpinBox_detectionThresholdFirst->value()*pow(10, m_pUi->m_spinBox_detectionThresholdSecond->value()));
299}
300
301//=============================================================================================================
302
304{
305 return m_pUi->m_comboBox_triggerChannels->currentText();
306}
307
308//=============================================================================================================
309
Stim-channel chooser plus threshold spinbox for on-line trigger / event detection.
#define FIFFV_STIM_CH
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
FIFF file I/O, in-memory data structures and high-level readers/writers.
2-D display widgets and visualisation helpers (charts, topography, colour maps).
AbstractView(QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
Ui::TriggerDetectionViewWidget * m_pUi
TriggerDetectionView(const QString &sSettingsPath="", QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
QMap< double, QColor > m_qMapTriggerColor
void setNumberDetectedTriggersAndTypes(int totalNumberDetections, const QMap< int, QList< QPair< int, double > > > &mapDetectedTriggers)
QSharedPointer< FIFFLIB::FiffInfo > m_pFiffInfo
void onRealTimeTriggerColorTypeChanged(const QString &value)
void init(const QSharedPointer< FIFFLIB::FiffInfo > pFiffInfo)
void triggerInfoChanged(const QMap< double, QColor > &value, bool bActive, const QString &sTriggerCh, double dThreshold)
void updateProcessingMode(ProcessingMode mode)
void detectTriggers(const QString &sChannelName, double iThreshold)
QSharedPointer< FiffInfo > SPtr
Definition fiff_info.h:90