MNE-CPP  0.1.9
A Framework for Electrophysiology
averagelayoutview.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //=============================================================================================================
37 // INCLUDES
38 //=============================================================================================================
39 
40 #include "averagelayoutview.h"
41 
42 #include "helpers/averagescene.h"
43 #include "helpers/evokedsetmodel.h"
47 
48 #include <fiff/fiff_info.h>
49 
50 //=============================================================================================================
51 // QT INCLUDES
52 //=============================================================================================================
53 
54 #include <QLabel>
55 #include <QVBoxLayout>
56 #include <QGraphicsView>
57 #include <QSvgGenerator>
58 #include <QDebug>
59 #include <QGraphicsItem>
60 #include <QSettings>
61 #if !defined(NO_QOPENGLWIDGET)
62  #include <QOpenGLWidget>
63 #endif
64 
65 //=============================================================================================================
66 // USED NAMESPACES
67 //=============================================================================================================
68 
69 using namespace DISPLIB;
70 using namespace FIFFLIB;
71 
72 //=============================================================================================================
73 // DEFINE MEMBER METHODS
74 //=============================================================================================================
75 
76 AverageLayoutView::AverageLayoutView(const QString& sSettingsPath,
77  QWidget *parent,
78  Qt::WindowFlags f)
79 : AbstractView(parent, f)
80 , m_qMapAverageColor(QSharedPointer<QMap<QString, QColor> >::create())
81 , m_qMapAverageActivation(QSharedPointer<QMap<QString, bool> >::create())
82 {
83  m_sSettingsPath = sSettingsPath;
84  this->setWindowTitle("Average Layout");
85 
86  m_pAverageLayoutView = new QGraphicsView();
87 
88 #if !defined(NO_QOPENGLWIDGET)
89  m_pAverageLayoutView->setViewport(new QOpenGLWidget);
90 #endif
91 
92  m_pAverageLayoutView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
93  m_pAverageLayoutView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
94 
96  m_pAverageScene->setBackgroundBrush(QBrush(Qt::white));
97 
98  m_pAverageLayoutView->setScene(m_pAverageScene.data());
99 
100  //set layouts
101  QVBoxLayout *neLayout = new QVBoxLayout(this);
102  neLayout->setContentsMargins(0,0,0,0);
103  neLayout->addWidget(m_pAverageLayoutView);
104  this->setLayout(neLayout);
105  loadSettings();
106 }
107 
108 //=============================================================================================================
109 
111 {
112  saveSettings();
113 }
114 
115 //=============================================================================================================
116 
118 {
119 #if !defined(NO_QOPENGLWIDGET)
121  m_pAverageLayoutView->setViewport(new QOpenGLWidget);
122  }
123 #endif
124 }
125 
126 //=============================================================================================================
127 
128 void AverageLayoutView::setChannelInfoModel(QSharedPointer<ChannelInfoModel> &pChannelInfoModel)
129 {
130  m_pChannelInfoModel = pChannelInfoModel;
131 }
132 
133 //=============================================================================================================
134 
135 void AverageLayoutView::setEvokedSetModel(QSharedPointer<EvokedSetModel> pEvokedSetModel)
136 {
137  if (pEvokedSetModel){
138  connect(pEvokedSetModel.data(), &EvokedSetModel::dataChanged,
139  this, &AverageLayoutView::updateData, Qt::UniqueConnection);
140  }
141 
142  m_pEvokedSetModel = pEvokedSetModel;
143 }
144 
145 //=============================================================================================================
146 
147 void AverageLayoutView::setBackgroundColor(const QColor& backgroundColor)
148 {
149  if(!m_pAverageScene) {
150  qDebug() << "AverageLayoutView::setBackgroundColor - m_pAverageScene is NULL. Returning. ";
151  return;
152  }
153 
154  QBrush backgroundBrush = m_pAverageScene->backgroundBrush();
155  backgroundBrush.setColor(backgroundColor);
156  m_pAverageScene->setBackgroundBrush(backgroundBrush);
157 }
158 
159 //=============================================================================================================
160 
162 {
163  if(!m_pAverageScene) {
164  qDebug() << "AverageLayoutView::getBackgroundColor - m_pAverageScene is NULL. Returning. ";
165  return QColor();
166  }
167 
168  return m_pAverageScene->backgroundBrush().color();
169 }
170 
171 //=============================================================================================================
172 
173 void AverageLayoutView::takeScreenshot(const QString& fileName)
174 {
175  if(!m_pAverageScene) {
176  qDebug() << "AverageLayoutView::takeScreenshot - m_pAverageScene is NULL. Returning. ";
177  return;
178  }
179 
180  if(fileName.contains(".svg", Qt::CaseInsensitive))
181  {
182  // Generate screenshot
183  QSvgGenerator svgGen;
184  svgGen.setFileName(fileName);
185  QRectF rect = m_pAverageScene->itemsBoundingRect();
186  svgGen.setSize(QSize(rect.width(), rect.height()));
187 
188  QPainter painter(&svgGen);
189  m_pAverageScene->render(&painter);
190  }
191 
192  if(fileName.contains(".png", Qt::CaseInsensitive))
193  {
194  QPixmap pixMap = QPixmap::grabWidget(m_pAverageLayoutView);
195  pixMap.save(fileName);
196  }
197 }
198 
199 //=============================================================================================================
200 
201 void AverageLayoutView::setScaleMap(const QMap<qint32,float> &scaleMap)
202 {
203  if(!m_pAverageScene) {
204  qDebug() << "AverageLayoutView::setScaleMap - m_pAverageScene is NULL. Returning. ";
205  return;
206  }
207 
208  m_scaleMap = scaleMap;
209 
210  m_pAverageScene->setScaleMap(scaleMap);
211 
212  updateData();
213 }
214 
215 //=============================================================================================================
216 
217 QSharedPointer<QMap<QString, QColor> > AverageLayoutView::getAverageColor() const
218 {
219  return m_qMapAverageColor;
220 }
221 
222 //=============================================================================================================
223 
224 QSharedPointer<QMap<QString, bool> > AverageLayoutView::getAverageActivation() const
225 {
227 }
228 
229 //=============================================================================================================
230 
231 void AverageLayoutView::setAverageColor(const QSharedPointer<QMap<QString, QColor> > qMapAverageColor)
232 {
233  if(!m_pAverageScene) {
234  qDebug() << "AverageLayoutView::setAverageColor - m_pAverageScene is NULL. Returning. ";
235  return;
236  }
237 
238  m_qMapAverageColor = qMapAverageColor;
239  m_pAverageScene->setColorPerAverage(m_qMapAverageColor);
240 }
241 
242 //=============================================================================================================
243 
244 void AverageLayoutView::setSingleAverageColor(const QColor& avgColor)
245 {
246  for (QString mapKey : m_qMapAverageColor->keys()){
247  m_qMapAverageColor->insert(mapKey, avgColor);
248  }
249 
250  m_pAverageScene->setColorPerAverage(m_qMapAverageColor);
251  m_pAverageScene->setSignalItemColor(avgColor);
252 }
253 
254 //=============================================================================================================
255 
256 void AverageLayoutView::setAverageActivation(const QSharedPointer<QMap<QString, bool> > qMapAverageActivation)
257 {
258  if(!m_pAverageScene) {
259  qDebug() << "AverageLayoutView::setAverageActivation - m_pAverageScene is NULL. Returning. ";
260  return;
261  }
262 
263  m_qMapAverageActivation = qMapAverageActivation;
264  m_pAverageScene->setActivationPerAverage(qMapAverageActivation);
265 }
266 
267 //=============================================================================================================
268 
269 void AverageLayoutView::channelSelectionManagerChanged(const QList<QGraphicsItem*> &selectedChannelItems)
270 {
271  if(!m_pAverageScene) {
272  qDebug() << "AverageLayoutView::channelSelectionManagerChanged - m_pAverageScene is NULL. Returning. ";
273  return;
274  }
275  //Repaint the average items in the average scene based on the input parameter selectedChannelItems and update them with current data
276  m_pAverageScene->repaintItems(selectedChannelItems);
280  updateData();
281 }
282 
283 //=============================================================================================================
284 
286 {
287  if(!m_pAverageScene) {
288  qDebug() << "AverageLayoutView::channelSelectionManagerChanged - m_pAverageScene is NULL. Returning. ";
289  return;
290  }
291 
292  SelectionItem* pSelectionItem = data.value<DISPLIB::SelectionItem*>();
293 
294  //Repaint the average items in the average scene based on the input parameter selectedChannelItems and update them with current data
295  m_pAverageScene->repaintSelectionItems(*pSelectionItem);
299  updateData();
300 }
301 
302 //=============================================================================================================
303 
305 {
306  if(m_pFiffInfo) {
307  QList<QGraphicsItem *> currentAverageSceneItems = m_pAverageScene->items();
308 
309  //Set new data for all averageSceneItems
310  for(int i = 0; i < currentAverageSceneItems.size(); i++) {
311  AverageSceneItem* averageSceneItemTemp = static_cast<AverageSceneItem*>(currentAverageSceneItems.at(i));
312 
313  averageSceneItemTemp->m_lAverageData.clear();
314 
315  if (m_pEvokedSetModel){
316  //Get only the necessary data from the average model (use column 2)
317  QList<QPair<QString, DISPLIB::RowVectorPair> > averageData = m_pEvokedSetModel->data(0, 2, EvokedSetModelRoles::GetAverageData).value<QList<QPair<QString, DISPLIB::RowVectorPair> > >();
318 
319  //Get the averageScenItem specific data row
320  int channelNumber = averageSceneItemTemp->m_iChannelNumber;
321 
322  if(channelNumber != -1) {
323  averageSceneItemTemp->m_iChannelKind = m_pFiffInfo->chs.at(channelNumber).kind;
324  averageSceneItemTemp->m_iChannelUnit = m_pFiffInfo->chs.at(channelNumber).unit;
325  averageSceneItemTemp->m_firstLastSample.first = (-1)*m_pEvokedSetModel->getNumPreStimSamples();
326 
327  if(!averageData.isEmpty()) {
328  averageSceneItemTemp->m_firstLastSample.second = averageData.first().second.second - m_pEvokedSetModel->getNumPreStimSamples();
329  }
330 
331  averageSceneItemTemp->m_iTotalNumberChannels = m_pEvokedSetModel->rowCount();
332  averageSceneItemTemp->m_lAverageData = averageData;
333  averageSceneItemTemp->m_bIsBad = m_pEvokedSetModel->getIsChannelBad(channelNumber);
334  }
335  }
336  }
337 
338  m_pAverageScene->updateScene();
339  return;
340  }
341 
343  qDebug() << "AverageLayoutView::updateData - m_pAverageScene, m_pEvokedSetModel or m_pChannelInfoModel are NULL. Returning. ";
344  return;
345  }
346  //Get current items from the average scene
347  QList<QGraphicsItem *> currentAverageSceneItems = m_pAverageScene->items();
348 
349  //Set new data for all averageSceneItems
350  for(int i = 0; i < currentAverageSceneItems.size(); i++) {
351  AverageSceneItem* averageSceneItemTemp = static_cast<AverageSceneItem*>(currentAverageSceneItems.at(i));
352 
353  averageSceneItemTemp->m_lAverageData.clear();
354 
355  //Get only the necessary data from the average model (use column 2)
356  QList<QPair<QString, DISPLIB::RowVectorPair> > averageData = m_pEvokedSetModel->data(0, 2, EvokedSetModelRoles::GetAverageData).value<QList<QPair<QString, DISPLIB::RowVectorPair> > >();
357 
358  //Get the averageScenItem specific data row
359  int channelNumber = m_pChannelInfoModel->getIndexFromMappedChName(averageSceneItemTemp->m_sChannelName);
360 
361  if(channelNumber != -1) {
362  //qDebug() << "Change data for" << channelNumber << "" << averageSceneItemTemp->m_sChannelName;
363 
364  averageSceneItemTemp->m_iChannelKind = m_pChannelInfoModel->data(m_pChannelInfoModel->index(channelNumber, 4), ChannelInfoModelRoles::GetChKind).toInt();
365  averageSceneItemTemp->m_iChannelUnit = m_pChannelInfoModel->data(m_pChannelInfoModel->index(channelNumber, 6), ChannelInfoModelRoles::GetChUnit).toInt();
366  averageSceneItemTemp->m_firstLastSample.first = (-1)*m_pEvokedSetModel->getNumPreStimSamples();
367 
368  if(!averageData.isEmpty()) {
369  averageSceneItemTemp->m_firstLastSample.second = averageData.first().second.second - m_pEvokedSetModel->getNumPreStimSamples();
370  }
371 
372  averageSceneItemTemp->m_iChannelNumber = channelNumber;
373  averageSceneItemTemp->m_iTotalNumberChannels = m_pEvokedSetModel->rowCount();
374  averageSceneItemTemp->m_lAverageData = averageData;
375  averageSceneItemTemp->m_bIsBad = m_pEvokedSetModel->getIsChannelBad(channelNumber);
376  }
377  }
378 
379  m_pAverageScene->updateScene();
380 }
381 
382 //=============================================================================================================
383 
385 {
386  if(m_sSettingsPath.isEmpty()) {
387  return;
388  }
389 
390  QSettings settings("MNECPP");
391 }
392 
393 //=============================================================================================================
394 
396 {
397  if(m_sSettingsPath.isEmpty()) {
398  return;
399  }
400 
401  QSettings settings("MNECPP");
402 }
403 
404 //=============================================================================================================
405 
407 {
408  switch(mode) {
409  case GuiMode::Clinical:
410  break;
411  default: // default is research mode
412  break;
413  }
414 }
415 
416 //=============================================================================================================
417 
419 {
420  switch(mode) {
421  case ProcessingMode::Offline:
422  break;
423  default: // default is realtime mode
424  break;
425  }
426 }
427 
428 //=============================================================================================================
429 
430 void AverageLayoutView::setFiffInfo(const QSharedPointer<FIFFLIB::FiffInfo> pFiffInfo)
431 {
432  m_pFiffInfo = pFiffInfo;
433 }
434 
435 //=============================================================================================================
436 
437 QSharedPointer<EvokedSetModel> AverageLayoutView::getEvokedSetModel()
438 {
439  return m_pEvokedSetModel;
440 }
441 
442 //=============================================================================================================
443 
445 {
446  setEvokedSetModel(Q_NULLPTR);
447  updateData();
448 }
QSharedPointer< EvokedSetModel > getEvokedSetModel()
void setBackgroundColor(const QColor &backgroundColor)
QSharedPointer< DISPLIB::ChannelInfoModel > m_pChannelInfoModel
void updateProcessingMode(ProcessingMode mode)
Declaration of the AverageLayoutView Class.
void setChannelInfoModel(QSharedPointer< ChannelInfoModel > &pChannelInfoModel)
void setAverageColor(const QSharedPointer< QMap< QString, QColor > > qMapAverageColor)
The AverageScene class provides a reimplemented QGraphicsScene for 2D layout plotting.
Definition: averagescene.h:75
QSharedPointer< FIFFLIB::FiffInfo > m_pFiffInfo
QSharedPointer< QMap< QString, bool > > m_qMapAverageActivation
void setAverageActivation(const QSharedPointer< QMap< QString, bool > > qMapAverageActivation)
AverageLayoutView(const QString &sSettingsPath="", QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
QMap< qint32, float > m_scaleMap
Contains the declaration of the AverageScene class.
QPointer< QGraphicsView > m_pAverageLayoutView
QList< QPair< QString, RowVectorPair > > m_lAverageData
The declaration for ChannelInfoModel..
void setScaleMap(const QMap< qint32, float > &scaleMap)
The SelectionSceneItem class provides a new data structure for visualizing channels in a 2D layout...
void setEvokedSetModel(QSharedPointer< EvokedSetModel > pEvokedSetModel)
QSharedPointer< QMap< QString, QColor > > getAverageColor() const
Contains the declaration of the AverageSceneItem class.
void updateGuiMode(GuiMode mode)
void setSingleAverageColor(const QColor &avgColor)
QSharedPointer< QMap< QString, QColor > > m_qMapAverageColor
QSharedPointer< QMap< QString, bool > > getAverageActivation() const
Contains the declaration of the SelectionSceneItem class.
QPair< int, int > m_firstLastSample
void takeScreenshot(const QString &fileName)
QSharedPointer< AverageScene > m_pAverageScene
QSharedPointer< DISPLIB::EvokedSetModel > m_pEvokedSetModel
void channelSelectionManagerChanged(const QList< QGraphicsItem *> &selectedChannelItems)
The AverageSceneItem class provides a new data structure for visualizing averages in a 2D layout...
FiffInfo class declaration.
Declaration of the EvokedSetModel Class.
void channelSelectionChanged(const QVariant &data)
void setFiffInfo(const QSharedPointer< FIFFLIB::FiffInfo > pFiffInfo)
The AbstractView class provides the base calss for all Disp viewers.
Definition: abstractview.h:75
QSharedPointer< AverageScene > SPtr
Definition: averagescene.h:80