MNE-CPP  0.1.9
A Framework for Electrophysiology
averageselectionview.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //=============================================================================================================
37 // INCLUDES
38 //=============================================================================================================
39 
40 #include "averageselectionview.h"
41 
42 #include <fiff/fiff_evoked_set.h>
43 
44 //=============================================================================================================
45 // QT INCLUDES
46 //=============================================================================================================
47 
48 #include <QGridLayout>
49 #include <QCheckBox>
50 #include <QColorDialog>
51 #include <QPalette>
52 #include <QPushButton>
53 #include <QDebug>
54 #include <QSettings>
55 #include <QPointer>
56 
57 //=============================================================================================================
58 // EIGEN INCLUDES
59 //=============================================================================================================
60 
61 #include<Eigen/Core>
62 
63 //=============================================================================================================
64 // USED NAMESPACES
65 //=============================================================================================================
66 
67 using namespace DISPLIB;
68 using namespace Eigen;
69 
70 //=============================================================================================================
71 // DEFINE MEMBER METHODS
72 //=============================================================================================================
73 
74 AverageSelectionView::AverageSelectionView(const QString& sSettingsPath,
75  QWidget *parent,
76  Qt::WindowFlags f)
77 : AbstractView(parent, f)
78 , m_iMaxNumAverages(10)
79 , m_qMapAverageColor(QSharedPointer<QMap<QString, QColor> >::create())
80 , m_qMapAverageActivation(QSharedPointer<QMap<QString, bool> >::create())
81 {
82  m_sSettingsPath = sSettingsPath;
83  this->setWindowTitle("Average Selection");
84  this->setMinimumWidth(330);
85  this->setMaximumWidth(330);
86 
87  loadSettings();
88  redrawGUI();
89 }
90 
91 //=============================================================================================================
92 
94 {
95  saveSettings();
96 }
97 
98 //=============================================================================================================
99 
100 QSharedPointer<QMap<QString, QColor> > AverageSelectionView::getAverageColor() const
101 {
102  return m_qMapAverageColor;
103 }
104 
105 //=============================================================================================================
106 
107 QSharedPointer<QMap<QString, bool> > AverageSelectionView::getAverageActivation() const
108 {
110 }
111 
112 //=============================================================================================================
113 
114 void AverageSelectionView::setAverageColor(const QSharedPointer<QMap<QString, QColor> > qMapAverageColor)
115 {
116  m_qMapAverageColor = qMapAverageColor;
117  redrawGUI();
118 }
119 
120 //=============================================================================================================
121 
122 void AverageSelectionView::setAverageActivation(const QSharedPointer<QMap<QString, bool> > qMapAverageActivation)
123 {
124  m_qMapAverageActivation = qMapAverageActivation;
125  redrawGUI();
126 }
127 
128 //=============================================================================================================
129 
131 {
132  if(m_sSettingsPath.isEmpty()) {
133  return;
134  }
135 
136  QSettings settings("MNECPP");
137 
138  settings.beginGroup(m_sSettingsPath + QString("/AverageSelectionView/averageColorMap"));
139  QMap<QString, QColor>::const_iterator iColor = m_qMapAverageColor->constBegin();
140  while (iColor != m_qMapAverageColor->constEnd()) {
141  settings.setValue(iColor.key(), iColor.value());
142  ++iColor;
143  }
144  settings.endGroup();
145 
146  settings.beginGroup(m_sSettingsPath + QString("/AverageSelectionView/averageActivationMap"));
147  QMap<QString, bool>::const_iterator iActivation = m_qMapAverageActivation->constBegin();
148  while (iActivation != m_qMapAverageActivation->constEnd()) {
149  settings.setValue(iActivation.key(), iActivation.value());
150  ++iActivation;
151  }
152  settings.endGroup();
153 }
154 
155 //=============================================================================================================
156 
158 {
159  if(m_sSettingsPath.isEmpty()) {
160  return;
161  }
162 
163  QSettings settings("MNECPP");
164 
165  settings.beginGroup(m_sSettingsPath + QString("/AverageSelectionView/averageColorMap"));
166  QStringList keys = settings.childKeys();
167  foreach (QString key, keys) {
168  m_qMapAverageColor->insert(key, settings.value(key).value<QColor>());
169  }
170  settings.endGroup();
171 
172  settings.beginGroup(m_sSettingsPath + QString("/AverageSelectionView/averageActivationMap"));
173  keys = settings.childKeys();
174  foreach (QString key, keys) {
175  m_qMapAverageActivation->insert(key, settings.value(key).toBool());
176  }
177  settings.endGroup();
178 }
179 
180 //=============================================================================================================
181 
183 {
184  switch(mode) {
185  case GuiMode::Clinical:
186  break;
187  default: // default is research mode
188  break;
189  }
190 }
191 
192 //=============================================================================================================
193 
195 {
196  switch(mode) {
197  case ProcessingMode::Offline:
198  break;
199  default: // default is realtime mode
200  break;
201  }
202 }
203 
204 //=============================================================================================================
205 
207 {
208  if(m_qMapAverageColor->size() != m_qMapAverageActivation->size()) {
209  qDebug() << "AverageSelectionView::update - m_qMapAverageColor and m_qMapAverageActivation do not match in size. Returning.";
210  return;
211  }
212 
213  //Delete all widgets in the averages layout
214  QGridLayout* topLayout = static_cast<QGridLayout*>(this->layout());
215  if(!topLayout) {
216  topLayout = new QGridLayout();
217  }
218 
219  QLayoutItem *child;
220  while ((child = topLayout->takeAt(0)) != 0) {
221  delete child->widget();
222  delete child;
223  }
224 
225  // Create new GUI elements
226  QMapIterator<QString, QColor> itr(*m_qMapAverageColor);
227  int count = 0;
228  while(itr.hasNext()) {
229  if(count >= m_iMaxNumAverages) {
230  break;
231  }
232 
233  itr.next();
234 
235  //Create average active checkbox
236  QPointer<QCheckBox> pCheckBox = new QCheckBox(itr.key());
237  pCheckBox->setChecked(m_qMapAverageActivation->value(itr.key()));
238  pCheckBox->setObjectName(itr.key());
239  topLayout->addWidget(pCheckBox, count, 0);
240  connect(pCheckBox.data(), &QCheckBox::clicked,
242 
243  //Create average color pushbutton
244  QColor color = itr.value();
245  QPointer<QPushButton> pButton = new QPushButton("Click to change");
246  pButton->setObjectName(itr.key());
247  pButton->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(color.red()).arg(color.green()).arg(color.blue()));
248  topLayout->addWidget(pButton, count, 1);
249  connect(pButton.data(), &QPushButton::clicked,
251 
252  ++count;
253  }
254 
255  this->setLayout(topLayout);
256 }
257 
258 //=============================================================================================================
259 
261 {
262  //Change color for average
263  if(QPointer<QPushButton> button = qobject_cast<QPushButton*>(sender())) {
264  QString sObjectName = button->objectName();
265 
266  QColor color = QColorDialog::getColor(m_qMapAverageColor->value(sObjectName), this, "Set average color");
267 
268  if(button) {
269  QPalette palette(QPalette::Button,color);
270  button->setPalette(palette);
271  button->update();
272 
273  //Set color of button new new scene color
274  button->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(color.red()).arg(color.green()).arg(color.blue()));
275  }
276 
277  m_qMapAverageColor->insert(sObjectName, color);
278 
280  }
281 
282  //Change color for average
283  if(QPointer<QCheckBox> checkBox = qobject_cast<QCheckBox*>(sender())) {
284  QString sObjectName = checkBox->objectName();
285 
286  m_qMapAverageActivation->insert(sObjectName, checkBox->isChecked());
287 
289  }
290 
291  saveSettings();
292 }
293 
294 //=============================================================================================================
295 
297 {
298 
299 }
void newAverageColorMap(const QSharedPointer< QMap< QString, QColor > > qMapAverageColor)
void newAverageActivationMap(const QSharedPointer< QMap< QString, bool > > qMapAverageActivation)
FiffEvokedSet class declaration.
QSharedPointer< QMap< QString, bool > > m_qMapAverageActivation
QSharedPointer< QMap< QString, QColor > > m_qMapAverageColor
void setAverageColor(const QSharedPointer< QMap< QString, QColor > > qMapAverageColor)
AverageSelectionView(const QString &sSettingsPath="", QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
void setAverageActivation(const QSharedPointer< QMap< QString, bool > > qMapAverageActivation)
QSharedPointer< QMap< QString, bool > > getAverageActivation() const
Declaration of the AverageSelectionView Class.
The AbstractView class provides the base calss for all Disp viewers.
Definition: abstractview.h:75
QSharedPointer< QMap< QString, QColor > > getAverageColor() const
void updateProcessingMode(ProcessingMode mode)