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  QRect rect = m_pAverageLayoutView->frameRect();
195  QPixmap pixMap = QWidget::grab(rect);
196  pixMap.save(fileName);
197  }
198 }
199 
200 //=============================================================================================================
201 
202 void AverageLayoutView::setScaleMap(const QMap<qint32,float> &scaleMap)
203 {
204  if(!m_pAverageScene) {
205  qDebug() << "AverageLayoutView::setScaleMap - m_pAverageScene is NULL. Returning. ";
206  return;
207  }
208 
209  m_scaleMap = scaleMap;
210 
211  m_pAverageScene->setScaleMap(scaleMap);
212 
213  updateData();
214 }
215 
216 //=============================================================================================================
217 
218 QSharedPointer<QMap<QString, QColor> > AverageLayoutView::getAverageColor() const
219 {
220  return m_qMapAverageColor;
221 }
222 
223 //=============================================================================================================
224 
225 QSharedPointer<QMap<QString, bool> > AverageLayoutView::getAverageActivation() const
226 {
228 }
229 
230 //=============================================================================================================
231 
232 void AverageLayoutView::setAverageColor(const QSharedPointer<QMap<QString, QColor> > qMapAverageColor)
233 {
234  if(!m_pAverageScene) {
235  qDebug() << "AverageLayoutView::setAverageColor - m_pAverageScene is NULL. Returning. ";
236  return;
237  }
238 
239  m_qMapAverageColor = qMapAverageColor;
240  m_pAverageScene->setColorPerAverage(m_qMapAverageColor);
241 }
242 
243 //=============================================================================================================
244 
245 void AverageLayoutView::setSingleAverageColor(const QColor& avgColor)
246 {
247  for (QString mapKey : m_qMapAverageColor->keys()){
248  m_qMapAverageColor->insert(mapKey, avgColor);
249  }
250 
251  m_pAverageScene->setColorPerAverage(m_qMapAverageColor);
252  m_pAverageScene->setSignalItemColor(avgColor);
253 }
254 
255 //=============================================================================================================
256 
257 void AverageLayoutView::setAverageActivation(const QSharedPointer<QMap<QString, bool> > qMapAverageActivation)
258 {
259  if(!m_pAverageScene) {
260  qDebug() << "AverageLayoutView::setAverageActivation - m_pAverageScene is NULL. Returning. ";
261  return;
262  }
263 
264  m_qMapAverageActivation = qMapAverageActivation;
265  m_pAverageScene->setActivationPerAverage(qMapAverageActivation);
266 }
267 
268 //=============================================================================================================
269 
270 void AverageLayoutView::channelSelectionManagerChanged(const QList<QGraphicsItem*> &selectedChannelItems)
271 {
272  if(!m_pAverageScene) {
273  qDebug() << "AverageLayoutView::channelSelectionManagerChanged - m_pAverageScene is NULL. Returning. ";
274  return;
275  }
276  //Repaint the average items in the average scene based on the input parameter selectedChannelItems and update them with current data
277  m_pAverageScene->repaintItems(selectedChannelItems);
281  updateData();
282 }
283 
284 //=============================================================================================================
285 
287 {
288  if(!m_pAverageScene) {
289  qDebug() << "AverageLayoutView::channelSelectionManagerChanged - m_pAverageScene is NULL. Returning. ";
290  return;
291  }
292 
293  SelectionItem* pSelectionItem = data.value<DISPLIB::SelectionItem*>();
294 
295  //Repaint the average items in the average scene based on the input parameter selectedChannelItems and update them with current data
296  m_pAverageScene->repaintSelectionItems(*pSelectionItem);
300  updateData();
301 }
302 
303 //=============================================================================================================
304 
306 {
307  if(m_pFiffInfo) {
308  QList<QGraphicsItem *> currentAverageSceneItems = m_pAverageScene->items();
309 
310  //Set new data for all averageSceneItems
311  for(int i = 0; i < currentAverageSceneItems.size(); i++) {
312  AverageSceneItem* averageSceneItemTemp = static_cast<AverageSceneItem*>(currentAverageSceneItems.at(i));
313 
314  averageSceneItemTemp->m_lAverageData.clear();
315 
316  if (m_pEvokedSetModel){
317  //Get only the necessary data from the average model (use column 2)
318  QList<QPair<QString, DISPLIB::RowVectorPair> > averageData = m_pEvokedSetModel->data(0, 2, EvokedSetModelRoles::GetAverageData).value<QList<QPair<QString, DISPLIB::RowVectorPair> > >();
319 
320  //Get the averageScenItem specific data row
321  int channelNumber = averageSceneItemTemp->m_iChannelNumber;
322 
323  if(channelNumber != -1) {
324  averageSceneItemTemp->m_iChannelKind = m_pFiffInfo->chs.at(channelNumber).kind;
325  averageSceneItemTemp->m_iChannelUnit = m_pFiffInfo->chs.at(channelNumber).unit;
326  averageSceneItemTemp->m_firstLastSample.first = (-1)*m_pEvokedSetModel->getNumPreStimSamples();
327 
328  if(!averageData.isEmpty()) {
329  averageSceneItemTemp->m_firstLastSample.second = averageData.first().second.second - m_pEvokedSetModel->getNumPreStimSamples();
330  }
331 
332  averageSceneItemTemp->m_iTotalNumberChannels = m_pEvokedSetModel->rowCount();
333  averageSceneItemTemp->m_lAverageData = averageData;
334  averageSceneItemTemp->m_bIsBad = m_pEvokedSetModel->getIsChannelBad(channelNumber);
335  }
336  }
337  }
338 
339  m_pAverageScene->updateScene();
340  return;
341  }
342 
344  qDebug() << "AverageLayoutView::updateData - m_pAverageScene, m_pEvokedSetModel or m_pChannelInfoModel are NULL. Returning. ";
345  return;
346  }
347  //Get current items from the average scene
348  QList<QGraphicsItem *> currentAverageSceneItems = m_pAverageScene->items();
349 
350  //Set new data for all averageSceneItems
351  for(int i = 0; i < currentAverageSceneItems.size(); i++) {
352  AverageSceneItem* averageSceneItemTemp = static_cast<AverageSceneItem*>(currentAverageSceneItems.at(i));
353 
354  averageSceneItemTemp->m_lAverageData.clear();
355 
356  //Get only the necessary data from the average model (use column 2)
357  QList<QPair<QString, DISPLIB::RowVectorPair> > averageData = m_pEvokedSetModel->data(0, 2, EvokedSetModelRoles::GetAverageData).value<QList<QPair<QString, DISPLIB::RowVectorPair> > >();
358 
359  //Get the averageScenItem specific data row
360  int channelNumber = m_pChannelInfoModel->getIndexFromMappedChName(averageSceneItemTemp->m_sChannelName);
361 
362  if(channelNumber != -1) {
363  //qDebug() << "Change data for" << channelNumber << "" << averageSceneItemTemp->m_sChannelName;
364 
365  averageSceneItemTemp->m_iChannelKind = m_pChannelInfoModel->data(m_pChannelInfoModel->index(channelNumber, 4), ChannelInfoModelRoles::GetChKind).toInt();
366  averageSceneItemTemp->m_iChannelUnit = m_pChannelInfoModel->data(m_pChannelInfoModel->index(channelNumber, 6), ChannelInfoModelRoles::GetChUnit).toInt();
367  averageSceneItemTemp->m_firstLastSample.first = (-1)*m_pEvokedSetModel->getNumPreStimSamples();
368 
369  if(!averageData.isEmpty()) {
370  averageSceneItemTemp->m_firstLastSample.second = averageData.first().second.second - m_pEvokedSetModel->getNumPreStimSamples();
371  }
372 
373  averageSceneItemTemp->m_iChannelNumber = channelNumber;
374  averageSceneItemTemp->m_iTotalNumberChannels = m_pEvokedSetModel->rowCount();
375  averageSceneItemTemp->m_lAverageData = averageData;
376  averageSceneItemTemp->m_bIsBad = m_pEvokedSetModel->getIsChannelBad(channelNumber);
377  }
378  }
379 
380  m_pAverageScene->updateScene();
381 }
382 
383 //=============================================================================================================
384 
386 {
387  if(m_sSettingsPath.isEmpty()) {
388  return;
389  }
390 
391  QSettings settings("MNECPP");
392 }
393 
394 //=============================================================================================================
395 
397 {
398  if(m_sSettingsPath.isEmpty()) {
399  return;
400  }
401 
402  QSettings settings("MNECPP");
403 }
404 
405 //=============================================================================================================
406 
408 {
409  switch(mode) {
410  case GuiMode::Clinical:
411  break;
412  default: // default is research mode
413  break;
414  }
415 }
416 
417 //=============================================================================================================
418 
420 {
421  switch(mode) {
422  case ProcessingMode::Offline:
423  break;
424  default: // default is realtime mode
425  break;
426  }
427 }
428 
429 //=============================================================================================================
430 
431 void AverageLayoutView::setFiffInfo(const QSharedPointer<FIFFLIB::FiffInfo> pFiffInfo)
432 {
433  m_pFiffInfo = pFiffInfo;
434 }
435 
436 //=============================================================================================================
437 
438 QSharedPointer<EvokedSetModel> AverageLayoutView::getEvokedSetModel()
439 {
440  return m_pEvokedSetModel;
441 }
442 
443 //=============================================================================================================
444 
446 {
447  setEvokedSetModel(Q_NULLPTR);
448  updateData();
449 }
DISPLIB::AverageLayoutView::loadSettings
void loadSettings()
Definition: averagelayoutview.cpp:396
DISPLIB::AverageLayoutView::setAverageColor
void setAverageColor(const QSharedPointer< QMap< QString, QColor > > qMapAverageColor)
Definition: averagelayoutview.cpp:232
DISPLIB::AbstractView
The AbstractView class provides the base calss for all Disp viewers.
Definition: abstractview.h:75
DISPLIB::AverageLayoutView::setScaleMap
void setScaleMap(const QMap< qint32, float > &scaleMap)
Definition: averagelayoutview.cpp:202
DISPLIB::AverageLayoutView::m_pAverageScene
QSharedPointer< AverageScene > m_pAverageScene
Definition: averagelayoutview.h:277
DISPLIB::AverageLayoutView::m_pEvokedSetModel
QSharedPointer< DISPLIB::EvokedSetModel > m_pEvokedSetModel
Definition: averagelayoutview.h:278
DISPLIB::AverageLayoutView::setSingleAverageColor
void setSingleAverageColor(const QColor &avgColor)
Definition: averagelayoutview.cpp:245
DISPLIB::AverageLayoutView::updateData
void updateData()
Definition: averagelayoutview.cpp:305
DISPLIB::AverageLayoutView::updateProcessingMode
void updateProcessingMode(ProcessingMode mode)
Definition: averagelayoutview.cpp:419
DISPLIB::AverageSceneItem
The AverageSceneItem class provides a new data structure for visualizing averages in a 2D layout.
Definition: averagesceneitem.h:79
DISPLIB::AverageLayoutView::clearView
void clearView()
Definition: averagelayoutview.cpp:445
averagesceneitem.h
Contains the declaration of the AverageSceneItem class.
DISPLIB::SelectionItem
The SelectionSceneItem class provides a new data structure for visualizing channels in a 2D layout.
Definition: selectionsceneitem.h:72
DISPLIB::AverageLayoutView::m_scaleMap
QMap< qint32, float > m_scaleMap
Definition: averagelayoutview.h:287
DISPLIB::AverageSceneItem::m_bIsBad
bool m_bIsBad
Definition: averagesceneitem.h:121
DISPLIB::AverageSceneItem::m_lAverageData
QList< QPair< QString, RowVectorPair > > m_lAverageData
Definition: averagesceneitem.h:124
DISPLIB::AverageScene::SPtr
QSharedPointer< AverageScene > SPtr
Definition: averagescene.h:80
DISPLIB::AverageLayoutView::channelSelectionChanged
void channelSelectionChanged(const QVariant &data)
Definition: averagelayoutview.cpp:286
DISPLIB::AverageLayoutView::m_qMapAverageColor
QSharedPointer< QMap< QString, QColor > > m_qMapAverageColor
Definition: averagelayoutview.h:285
DISPLIB::AverageLayoutView::m_pAverageLayoutView
QPointer< QGraphicsView > m_pAverageLayoutView
Definition: averagelayoutview.h:283
selectionsceneitem.h
Contains the declaration of the SelectionSceneItem class.
DISPLIB::AverageSceneItem::m_iChannelKind
int m_iChannelKind
Definition: averagesceneitem.h:114
DISPLIB::AverageLayoutView::getBackgroundColor
QColor getBackgroundColor()
Definition: averagelayoutview.cpp:161
DISPLIB::AverageSceneItem::m_sChannelName
QString m_sChannelName
Definition: averagesceneitem.h:112
DISPLIB::AverageLayoutView::getEvokedSetModel
QSharedPointer< EvokedSetModel > getEvokedSetModel()
Definition: averagelayoutview.cpp:438
DISPLIB::AverageLayoutView::m_pFiffInfo
QSharedPointer< FIFFLIB::FiffInfo > m_pFiffInfo
Definition: averagelayoutview.h:281
DISPLIB::AverageLayoutView::setAverageActivation
void setAverageActivation(const QSharedPointer< QMap< QString, bool > > qMapAverageActivation)
Definition: averagelayoutview.cpp:257
DISPLIB::AverageLayoutView::setEvokedSetModel
void setEvokedSetModel(QSharedPointer< EvokedSetModel > pEvokedSetModel)
Definition: averagelayoutview.cpp:135
DISPLIB::AverageLayoutView::AverageLayoutView
AverageLayoutView(const QString &sSettingsPath="", QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
Definition: averagelayoutview.cpp:76
DISPLIB::AverageLayoutView::saveSettings
void saveSettings()
Definition: averagelayoutview.cpp:385
DISPLIB::AverageLayoutView::setBackgroundColor
void setBackgroundColor(const QColor &backgroundColor)
Definition: averagelayoutview.cpp:147
DISPLIB::AverageLayoutView::setChannelInfoModel
void setChannelInfoModel(QSharedPointer< ChannelInfoModel > &pChannelInfoModel)
Definition: averagelayoutview.cpp:128
DISPLIB::AverageLayoutView::getAverageColor
QSharedPointer< QMap< QString, QColor > > getAverageColor() const
Definition: averagelayoutview.cpp:218
DISPLIB::AbstractView::m_sSettingsPath
QString m_sSettingsPath
Definition: abstractview.h:169
DISPLIB::AverageLayoutView::setFiffInfo
void setFiffInfo(const QSharedPointer< FIFFLIB::FiffInfo > pFiffInfo)
Definition: averagelayoutview.cpp:431
fiff_info.h
FiffInfo class declaration.
DISPLIB::AverageLayoutView::updateOpenGLViewport
void updateOpenGLViewport()
Definition: averagelayoutview.cpp:117
DISPLIB::AverageLayoutView::updateGuiMode
void updateGuiMode(GuiMode mode)
Definition: averagelayoutview.cpp:407
DISPLIB::AverageLayoutView::takeScreenshot
void takeScreenshot(const QString &fileName)
Definition: averagelayoutview.cpp:173
DISPLIB::AverageLayoutView::m_qMapAverageActivation
QSharedPointer< QMap< QString, bool > > m_qMapAverageActivation
Definition: averagelayoutview.h:286
DISPLIB::AverageSceneItem::m_iChannelUnit
int m_iChannelUnit
Definition: averagesceneitem.h:115
DISPLIB::AverageScene
The AverageScene class provides a reimplemented QGraphicsScene for 2D layout plotting.
Definition: averagescene.h:75
averagelayoutview.h
Declaration of the AverageLayoutView Class.
DISPLIB::AverageLayoutView::m_pChannelInfoModel
QSharedPointer< DISPLIB::ChannelInfoModel > m_pChannelInfoModel
Definition: averagelayoutview.h:279
DISPLIB::AverageLayoutView::~AverageLayoutView
~AverageLayoutView()
Definition: averagelayoutview.cpp:110
DISPLIB::AverageLayoutView::channelSelectionManagerChanged
void channelSelectionManagerChanged(const QList< QGraphicsItem * > &selectedChannelItems)
Definition: averagelayoutview.cpp:270
channelinfomodel.h
The declaration for ChannelInfoModel..
DISPLIB::AverageSceneItem::m_firstLastSample
QPair< int, int > m_firstLastSample
Definition: averagesceneitem.h:126
averagescene.h
Contains the declaration of the AverageScene class.
DISPLIB::AverageLayoutView::getAverageActivation
QSharedPointer< QMap< QString, bool > > getAverageActivation() const
Definition: averagelayoutview.cpp:225
evokedsetmodel.h
Declaration of the EvokedSetModel Class.
DISPLIB::AverageSceneItem::m_iChannelNumber
int m_iChannelNumber
Definition: averagesceneitem.h:113
DISPLIB::AverageSceneItem::m_iTotalNumberChannels
int m_iTotalNumberChannels
Definition: averagesceneitem.h:116