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(std::make_unique<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
72
73//=============================================================================================================
74
76{
77 if (pFiffInfo) {
78 m_pFiffInfo = pFiffInfo;
79 //Trigger detection
80 connect(m_pUi->m_checkBox_activateTriggerDetection, &QCheckBox::checkStateChanged,
81 this, &TriggerDetectionView::onTriggerInfoChanged, Qt::UniqueConnection);
82
83 m_pUi->m_comboBox_triggerChannels->clear();
84
85 for (int i = 0; i < m_pFiffInfo->chs.size(); i++) {
86 if (m_pFiffInfo->chs[i].kind == FIFFV_STIM_CH) {
87 m_pUi->m_comboBox_triggerChannels->addItem(m_pFiffInfo->chs[i].ch_name);
88 }
89 }
90
91 connect(m_pUi->m_comboBox_triggerChannels, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged),
92 this, &TriggerDetectionView::onTriggerInfoChanged, Qt::UniqueConnection);
93
94 connect(m_pUi->m_comboBox_triggerColorType, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged),
96
97 connect(m_pUi->m_pushButton_triggerColor, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
98 this, &TriggerDetectionView::onRealTimeTriggerColorChanged, Qt::UniqueConnection);
99
100 m_pUi->m_pushButton_triggerColor->setAutoFillBackground(true);
101 m_pUi->m_pushButton_triggerColor->setFlat(true);
102 QPalette palette = m_pUi->m_pushButton_triggerColor->palette();
103 palette.setColor(QPalette::Button, QColor(177, 0, 0));
104 m_pUi->m_pushButton_triggerColor->setPalette(palette);
105 m_pUi->m_pushButton_triggerColor->update();
106
107 connect(m_pUi->m_doubleSpinBox_detectionThresholdFirst, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
108 this, &TriggerDetectionView::onTriggerInfoChanged, Qt::UniqueConnection);
109
110 connect(m_pUi->m_spinBox_detectionThresholdSecond, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
111 this, &TriggerDetectionView::onTriggerInfoChanged, Qt::UniqueConnection);
112
113 connect(m_pUi->m_pushButton_resetNumberTriggers, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
114 this, &TriggerDetectionView::onResetTriggerNumbers, Qt::UniqueConnection);
115
116 connect(m_pUi->m_pushButton_DetectTriggers, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
117 this, &TriggerDetectionView::onDetectTriggers, Qt::UniqueConnection);
118
119 loadSettings();
120 }
121}
122
123//=============================================================================================================
124
125void TriggerDetectionView::setNumberDetectedTriggersAndTypes(int numberDetections, const QMap<int, QList<QPair<int, double>>>& mapDetectedTriggers)
126{
127 //if(m_bTriggerDetection) {
128 m_pUi->m_label_numberDetectedTriggers->setText(QString("%1").arg(numberDetections));
129 //}
130
131 //Set trigger types
132 QMapIterator<int, QList<QPair<int, double>>> i(mapDetectedTriggers);
133 while (i.hasNext()) {
134 i.next();
135
136 for (int j = 0; j < i.value().size(); ++j) {
137 if (m_pUi->m_comboBox_triggerColorType->findText(QString::number(i.value().at(j).second)) == -1) {
138 m_pUi->m_comboBox_triggerColorType->addItem(QString::number(i.value().at(j).second));
139 }
140 }
141 }
142}
143
144//=============================================================================================================
145
147{
148 if (m_sSettingsPath.isEmpty()) {
149 return;
150 }
151
152 QSettings settings("MNECPP");
153
154 settings.setValue(m_sSettingsPath + QString("/TriggerDetectionView/Activated"), m_pUi->m_checkBox_activateTriggerDetection->isChecked());
155 settings.setValue(m_sSettingsPath + QString("/TriggerDetectionView/ChannelIndex"), m_pUi->m_comboBox_triggerChannels->currentIndex());
156 settings.setValue(m_sSettingsPath + QString("/TriggerDetectionView/FirstThresholdValue"), m_pUi->m_doubleSpinBox_detectionThresholdFirst->value());
157 settings.setValue(m_sSettingsPath + QString("/TriggerDetectionView/SecondThresholdValue"), m_pUi->m_spinBox_detectionThresholdSecond->value());
158
159 settings.beginGroup(m_sSettingsPath + QString("/TriggerDetectionView/Colors"));
160 QMap<double, QColor>::const_iterator i = m_qMapTriggerColor.constBegin();
161 while (i != m_qMapTriggerColor.constEnd()) {
162 settings.setValue(QString::number(i.key()), i.value());
163 ++i;
164 }
165 settings.endGroup();
166}
167
168//=============================================================================================================
169
171{
172 if (m_sSettingsPath.isEmpty()) {
173 return;
174 }
175
176 QSettings settings("MNECPP");
177
178 m_pUi->m_checkBox_activateTriggerDetection->setChecked(settings.value(m_sSettingsPath + QString("/TriggerDetectionView/Activated"), false).toBool());
179 m_pUi->m_comboBox_triggerChannels->setCurrentIndex(settings.value(m_sSettingsPath + QString("/TriggerDetectionView/ChannelIndex"), 0).toInt());
180 m_pUi->m_doubleSpinBox_detectionThresholdFirst->setValue(settings.value(m_sSettingsPath + QString("/TriggerDetectionView/FirstThresholdValue"), 0.1).toDouble());
181 m_pUi->m_spinBox_detectionThresholdSecond->setValue(settings.value(m_sSettingsPath + QString("/TriggerDetectionView/SecondThresholdValue"), -1).toInt());
182
183 settings.beginGroup(m_sSettingsPath + QString("/TriggerDetectionView/Colors"));
184 QStringList keys = settings.childKeys();
185 foreach (QString key, keys) {
186 double dKey = key.toDouble();
187 m_qMapTriggerColor[dKey] = settings.value(key).value<QColor>();
188 }
189 settings.endGroup();
190
192}
193
194//=============================================================================================================
195
197{
198 switch (mode) {
200 break;
201 default: // default is research mode
202 break;
203 }
204}
205
206//=============================================================================================================
207
209{
210 switch (mode) {
212 m_pUi->label->hide();
213 m_pUi->label_9->hide();
214 m_pUi->m_pushButton_resetNumberTriggers->hide();
215 m_pUi->m_pushButton_triggerColor->hide();
216 m_pUi->m_checkBox_activateTriggerDetection->hide();
217 m_pUi->m_comboBox_triggerColorType->hide();
218 m_pUi->m_label_numberDetectedTriggers->hide();
219 m_pUi->m_pushButton_DetectTriggers->show();
220 break;
221 default: // default is realtime mode
222 m_pUi->label->show();
223 m_pUi->label_9->show();
224 m_pUi->m_pushButton_resetNumberTriggers->show();
225 m_pUi->m_pushButton_triggerColor->show();
226 m_pUi->m_checkBox_activateTriggerDetection->show();
227 m_pUi->m_comboBox_triggerColorType->show();
228 m_pUi->m_label_numberDetectedTriggers->show();
229 m_pUi->m_pushButton_DetectTriggers->hide();
230 break;
231 }
232}
233
234//=============================================================================================================
235
237{
239 m_pUi->m_checkBox_activateTriggerDetection->isChecked(),
240 m_pUi->m_comboBox_triggerChannels->currentText(),
241 m_pUi->m_doubleSpinBox_detectionThresholdFirst->value() * pow(10, m_pUi->m_spinBox_detectionThresholdSecond->value()));
242
243 saveSettings();
244}
245
246//=============================================================================================================
247
249{
250 Q_UNUSED(state);
251
252 QColor color = QColorDialog::getColor(m_qMapTriggerColor[m_pUi->m_comboBox_triggerColorType->currentText().toDouble()], this, "Set trigger color");
253 // Cancelled: getColor() returns an invalid colour
254 if (!color.isValid()) {
255 return;
256 }
257
258 //Change color of pushbutton
259 QPalette palette = m_pUi->m_pushButton_triggerColor->palette();
260 palette.setColor(QPalette::Button, color);
261 m_pUi->m_pushButton_triggerColor->setPalette(palette);
262 m_pUi->m_pushButton_triggerColor->update();
263
264 m_qMapTriggerColor[m_pUi->m_comboBox_triggerColorType->currentText().toDouble()] = color;
265
267}
268
269//=============================================================================================================
270
272{
273 //Change color of pushbutton
274 QPalette palette = m_pUi->m_pushButton_triggerColor->palette();
275 palette.setColor(QPalette::Button, m_qMapTriggerColor[value.toDouble()]);
276 m_pUi->m_pushButton_triggerColor->setPalette(palette);
277 m_pUi->m_pushButton_triggerColor->update();
278}
279
280//=============================================================================================================
281
283{
284 m_pUi->m_label_numberDetectedTriggers->setText(QString("0"));
285 m_pUi->m_comboBox_triggerColorType->clear();
286
287 emit resetTriggerCounter();
288
289 //emit updateConnectedView();
290}
291
292//=============================================================================================================
293
295{
296 if (m_pUi->m_comboBox_triggerChannels->currentText() == "") {
297 return;
298 }
299 emit detectTriggers(m_pUi->m_comboBox_triggerChannels->currentText(),
300 m_pUi->m_doubleSpinBox_detectionThresholdFirst->value() * pow(10, m_pUi->m_spinBox_detectionThresholdSecond->value()));
301}
302
303//=============================================================================================================
304
306{
307 return m_pUi->m_comboBox_triggerChannels->currentText();
308}
309
310//=============================================================================================================
311
constexpr auto FIFFV_STIM_CH
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
Stim-channel chooser plus threshold spinbox for on-line trigger / event detection.
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)
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)
std::unique_ptr< Ui::TriggerDetectionViewWidget > m_pUi
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:92