MNE-CPP  beta 1.0
chinfomodel.cpp
1 //=============================================================================================================
38 //*************************************************************************************************************
39 //=============================================================================================================
40 // INCLUDES
41 //=============================================================================================================
42 
43 #include "chinfomodel.h"
44 
45 
46 //*************************************************************************************************************
47 //=============================================================================================================
48 // USED NAMESPACES
49 //=============================================================================================================
50 
51 using namespace MNEBrowseRawQt;
52 
53 
54 //*************************************************************************************************************
55 //=============================================================================================================
56 // DEFINE MEMBER METHODS
57 //=============================================================================================================
58 
59 ChInfoModel::ChInfoModel(QObject *parent)
60 : QAbstractTableModel(parent)
61 {
62 }
63 
64 
65 //*************************************************************************************************************
66 //virtual functions
67 int ChInfoModel::rowCount(const QModelIndex & /*parent*/) const
68 {
69  //Return number of stored evoked sets
70  if(!m_fiffInfo.chs.size()==0)
71  return m_fiffInfo.chs.size();
72  else
73  return 0;
74 }
75 
76 
77 //*************************************************************************************************************
78 
79 int ChInfoModel::columnCount(const QModelIndex & /*parent*/) const
80 {
81  return 11;
82 }
83 
84 
85 //*************************************************************************************************************
86 
87 QVariant ChInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
88 {
89  if(role != Qt::DisplayRole && role != Qt::TextAlignmentRole)
90  return QVariant();
91 
92  switch(role) {
93  case Qt::TextAlignmentRole:
94  return Qt::AlignHCenter + Qt::AlignVCenter;
95 
96  case Qt::DisplayRole: {
97  //Return the number and description/comment of the fiff evoked data in the set as vertical header
98  if(orientation == Qt::Vertical)
99  if(section<m_fiffInfo.chs.size())
100  return QString("Ch %1").arg(section);
101 
102  //Return the horizontal header
103  if(orientation == Qt::Horizontal) {
104  switch(section) {
105  case 0:
106  return QString("%1").arg("Data number");
107  break;
108 
109  case 1:
110  return QString("%1").arg("Original name");
111  break;
112 
113  case 2:
114  return QString("%1").arg("Alias");
115  break;
116 
117  case 3:
118  return QString("%1").arg("Mapped layout name");
119  break;
120 
121  case 4:
122  return QString("%1").arg("Channel kind");
123  break;
124 
125  case 5:
126  return QString("%1").arg("MEG type");
127  break;
128 
129  case 6:
130  return QString("%1").arg("Unit");
131  break;
132 
133  case 7:
134  return QString("%1").arg("2D loc (cm)");
135  break;
136 
137  case 8:
138  return QString("%1").arg("3D loc (cm)");
139  break;
140 
141  case 9:
142  return QString("%1").arg("Active filter");
143  break;
144 
145  case 10:
146  return QString("%1").arg("Coil Type");
147  break;
148  }
149  }
150  }
151  }
152 
153  return QVariant();
154 }
155 
156 
157 //*************************************************************************************************************
158 
159 QVariant ChInfoModel::data(const QModelIndex &index, int role) const
160 {
161  if(index.row() >= m_fiffInfo.chs.size())
162  return QVariant();
163 
164  if (index.isValid()) {
165  //******** first column (channel number - corresponds to row in fiff data matrix) ********
166  if(index.column()==0) {
167  QVariant v;
168 
169  switch(role) {
170  case Qt::DisplayRole:
171  v.setValue(index.row());
172  return v;
173 
174  case ChInfoModelRoles::GetChNumber:
175  v.setValue(index.row());
176  return v;
177 
178  case Qt::TextAlignmentRole:
179  return Qt::AlignHCenter + Qt::AlignVCenter;
180  }
181  }//end column check
182 
183  //******** second column (original channel name) ********
184  if(index.column()==1) {
185  QVariant v;
186 
187  switch(role) {
188  case Qt::DisplayRole:
189  v.setValue(QString("%1").arg(m_fiffInfo.chs.at(index.row()).ch_name));
190  return v;
191 
192  case ChInfoModelRoles::GetOrigChName:
193  v.setValue(QString("%1").arg(m_fiffInfo.chs.at(index.row()).ch_name));
194  return v;
195 
196  case Qt::TextAlignmentRole:
197  return Qt::AlignHCenter + Qt::AlignVCenter;
198  }
199  }//end column check
200 
201  //******** third column (channel alias) ********
202  if(index.column()==2) {
203  QVariant v;
204 
205  switch(role) {
206  case Qt::DisplayRole:
207  v.setValue(QString("%1").arg(m_aliasNames.at(index.row())));
208  return v;
209 
210  case ChInfoModelRoles::GetChAlias:
211  v.setValue(m_aliasNames.at(index.row()));
212  return v;
213 
214  case Qt::TextAlignmentRole:
215  return Qt::AlignHCenter + Qt::AlignVCenter;
216  }
217  }//end column check
218 
219  //******** fourth column (mapped layout channel name) ********
220  if(index.column()==3) {
221  QVariant v;
222 
223  switch(role) {
224  case Qt::DisplayRole:
225  v.setValue(QString("%1").arg(m_mappedLayoutChNames.at(index.row())));
226  return v;
227 
228  case ChInfoModelRoles::GetMappedLayoutChName:
229  v.setValue(QString("%1").arg(m_mappedLayoutChNames.at(index.row())));
230  return v;
231 
232  case Qt::TextAlignmentRole:
233  return Qt::AlignHCenter + Qt::AlignVCenter;
234  }
235  }//end column check
236 
237  //******** fifth column (channel kind - MEG, EEG, etc) ********
238  if(index.column()==4) {
239  QVariant v;
240 
241  switch(role) {
242  case Qt::DisplayRole:
243  v.setValue(QString("%1").arg(m_fiffInfo.chs.at(index.row()).kind));
244  return v;
245 
246  case ChInfoModelRoles::GetChKind:
247  v.setValue(m_fiffInfo.chs.at(index.row()).kind);
248  return v;
249 
250  case Qt::TextAlignmentRole:
251  return Qt::AlignHCenter + Qt::AlignVCenter;
252  }
253  }//end column check
254 
255  //******** sixth column (MEG type) ********
256  if(index.column()==5) {
257  QVariant v;
258 
259  v.setValue(QString("%1").arg("non_MEG"));
260 
261  if(m_fiffInfo.chs.at(index.row()).kind == FIFFV_MEG_CH) {
262  qint32 unit = m_fiffInfo.chs.at(index.row()).unit;
263  if(unit == FIFF_UNIT_T_M)
264  v.setValue(QString("MEG_grad"));
265  else if(unit == FIFF_UNIT_T)
266  v.setValue(QString("MEG_mag"));
267  }
268 
269  if(m_fiffInfo.chs.at(index.row()).kind == FIFFV_REF_MEG_CH) {
270  qint32 unit = m_fiffInfo.chs.at(index.row()).unit;
271  if(unit == FIFF_UNIT_T_M)
272  v.setValue(QString("MEG_grad_ref"));
273  else if(unit == FIFF_UNIT_T)
274  v.setValue(QString("MEG_mag_ref"));
275  }
276 
277  switch(role) {
278  case Qt::DisplayRole:
279  return v;
280 
281  case ChInfoModelRoles::GetMEGType:
282  return v;
283 
284  case Qt::TextAlignmentRole:
285  return Qt::AlignHCenter + Qt::AlignVCenter;
286  }
287  }//end column check
288 
289  //******** seventh column (channel unit) ********
290  if(index.column()==6) {
291  QVariant v;
292 
293  switch(role) {
294  case Qt::DisplayRole:
295  v.setValue(QString("%1").arg(m_fiffInfo.chs.at(index.row()).unit));
296  return v;
297 
298  case ChInfoModelRoles::GetChUnit:
299  v.setValue(m_fiffInfo.chs.at(index.row()).unit);
300  return v;
301 
302  case Qt::TextAlignmentRole:
303  return Qt::AlignHCenter + Qt::AlignVCenter;
304  }
305  }//end column check
306 
307  //******** eigth column (channel layout position) ********
308  if(index.column()==7) {
309  QVariant v;
310 
311  QPointF point = m_layoutMap[m_mappedLayoutChNames.at(index.row())];
312 
313  switch(role) {
314  case Qt::DisplayRole:
315  v.setValue(QString("(%1|%2)").arg(point.x()).arg(point.y()));
316  return v;
317 
318  case ChInfoModelRoles::GetChPosition:
319  v.setValue(point);
320  return v;
321 
322  case Qt::TextAlignmentRole:
323  return Qt::AlignHCenter + Qt::AlignVCenter;
324  }
325  }//end column check
326 
327  //******** ninth column (channel digitizer position) ********
328  if(index.column()==8) {
329  QVariant v;
330 
331  QVector3D point3D(m_fiffInfo.chs.at(index.row()).loc(0,0) * 100, //convert to cm
332  m_fiffInfo.chs.at(index.row()).loc(1,0) * 100,
333  m_fiffInfo.chs.at(index.row()).loc(2,0) * 100);
334 
335  switch(role) {
336  case Qt::DisplayRole:
337  v.setValue(QString("(%1|%2|%3)").arg(point3D.x()).arg(point3D.y()).arg(point3D.z()));
338  return v;
339 
340  case ChInfoModelRoles::GetChDigitizer:
341  v.setValue(point3D);
342  return v;
343 
344  case Qt::TextAlignmentRole:
345  return Qt::AlignHCenter + Qt::AlignVCenter;
346  }
347  }//end column check
348 
349  //******** tenth column (active channel filter type) ********
350  if(index.column()==9) {
351  QVariant v;
352 
353  //Check if mne operator is a filter operator
354  QSharedPointer<MNEOperator> operatorPtr = m_assignedOperators.value(index.row(), QSharedPointer<MNEOperator>(new MNEOperator()));
355  QSharedPointer<FilterOperator> filterOperator;
356 
357  switch(role) {
358  case Qt::DisplayRole: {
359  if(operatorPtr->m_OperatorType == MNEOperator::FILTER) {
360  filterOperator = operatorPtr.staticCast<FilterOperator>();
361  }
362  else {
363  v.setValue(QString("%1").arg("none"));
364  return v;
365  }
366 
367  switch(filterOperator->m_Type) {
368  case FilterOperator::LPF: {
369  v.setValue(QString("%1 | %2").arg("LP").arg(filterOperator->m_dCenterFreq*m_fiffInfo.sfreq/2));
370  return v;
371  }
372 
373  case FilterOperator::HPF: {
374  v.setValue(QString("%1 | %2").arg("HP").arg(filterOperator->m_dCenterFreq*m_fiffInfo.sfreq/2));
375  return v;
376  }
377 
378  case FilterOperator::BPF: {
379  double fsample = m_fiffInfo.sfreq;
380  double low = (filterOperator->m_dCenterFreq*fsample/2) - (filterOperator->m_dBandwidth*fsample/4); // /4 because we also need to devide by 2 to get the nyquist freq
381  double high = (filterOperator->m_dCenterFreq*fsample/2) + (filterOperator->m_dBandwidth*fsample/4);
382  v.setValue(QString("%1 | %2 | %3").arg("BP").arg(low).arg(high));
383  return v;
384  }
385 
386  case FilterOperator::NOTCH: {
387  double fsample = m_fiffInfo.sfreq;
388  double low = (filterOperator->m_dCenterFreq*fsample/2) - (filterOperator->m_dBandwidth*fsample/4);
389  double high = (filterOperator->m_dCenterFreq*fsample/2) + (filterOperator->m_dBandwidth*fsample/4);
390  v.setValue(QString("%1 | %2 | %3").arg("NOTCH").arg(low).arg(high));
391  return v;
392  }
393  }
394  }
395 
396  case ChInfoModelRoles::GetChActiveFilter: {
397  if(operatorPtr->m_OperatorType == MNEOperator::FILTER) {
398  filterOperator = operatorPtr.staticCast<FilterOperator>();
399  }
400  else {
401  v.setValue(QString("%1").arg("none"));
402  return v;
403  }
404 
405  v.setValue(operatorPtr);
406  return v;
407  }
408 
409  case Qt::TextAlignmentRole:
410  return Qt::AlignHCenter + Qt::AlignVCenter;
411  }
412  }//end column check
413 
414  //******** eleventh column (coil type) ********
415  if(index.column()==10) {
416  QVariant v;
417 
418  switch(role) {
419  case Qt::DisplayRole:
420  v.setValue(QString("%1").arg(m_fiffInfo.chs.at(index.row()).coil_type));
421  return v;
422 
423  case ChInfoModelRoles::GetChCoilType:
424  v.setValue(m_fiffInfo.chs.at(index.row()).coil_type);
425  return v;
426 
427  case Qt::TextAlignmentRole:
428  return Qt::AlignHCenter + Qt::AlignVCenter;
429  }
430  }//end column check
431  } // end index.valid() check
432 
433  return QVariant();
434 }
435 
436 
437 //*************************************************************************************************************
438 
439 bool ChInfoModel::insertRows(int position, int span, const QModelIndex & parent)
440 {
441  Q_UNUSED(position);
442  Q_UNUSED(span);
443  Q_UNUSED(parent);
444 
445  return true;
446 }
447 
448 
449 //*************************************************************************************************************
450 
451 bool ChInfoModel::removeRows(int position, int span, const QModelIndex & parent)
452 {
453  Q_UNUSED(position);
454  Q_UNUSED(span);
455  Q_UNUSED(parent);
456 
457  return true;
458 }
459 
460 
461 //*************************************************************************************************************
462 
463 Qt::ItemFlags ChInfoModel::flags(const QModelIndex & index) const
464 {
465  Q_UNUSED(index);
466  return Qt::ItemIsEnabled | Qt::ItemIsSelectable /*| Qt::ItemIsEditable*/;
467 }
468 
469 
470 //*************************************************************************************************************
471 
472 bool ChInfoModel::setData(const QModelIndex &index, const QVariant &value, int role)
473 {
474  Q_UNUSED(index);
475  Q_UNUSED(value);
476  Q_UNUSED(role);
477 
478  return true;
479 }
480 
481 
482 //*************************************************************************************************************
483 
485 {
486  beginResetModel();
487 
488  m_fiffInfo = fiffInfo;
491 
493 
494  endResetModel();
495 
496  emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
497 }
498 
499 
500 //*************************************************************************************************************
501 
502 void ChInfoModel::assignedOperatorsChanged(const QMap<int,QSharedPointer<MNEOperator> > &assignedOperators)
503 {
504  beginResetModel();
505 
506  m_assignedOperators = assignedOperators;
507 
508  endResetModel();
509 
510  emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
511 }
512 
513 
514 //*************************************************************************************************************
515 
516 void ChInfoModel::layoutChanged(const QMap<QString,QPointF> &layoutMap)
517 {
518  beginResetModel();
519 
520  m_layoutMap = layoutMap;
523 
525 
526  endResetModel();
527 
528  emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
529 }
530 
531 
532 //*************************************************************************************************************
533 
535 {
536 
537  return m_mappedLayoutChNames;
538 }
539 
540 
541 //*************************************************************************************************************
542 
544 {
545  return m_fiffInfo.ch_names.indexOf(chName);
546 }
547 
548 
549 //*************************************************************************************************************
550 
552 {
553  return m_mappedLayoutChNames.indexOf(chName);
554 }
555 
556 
557 //*************************************************************************************************************
558 
560 {
561  //TODO: Move this to layout loader in MNE-CPP Utils?
562  //Map channels to layout
563  QList<FiffChInfo> channelList = m_fiffInfo.chs;
564  for(int i = 0; i<channelList.size(); i++) {
565  //Get current channel information
566  FiffChInfo chInfo = channelList.at(i);
567  QString chName = chInfo.ch_name;
568  QRegExp regExpRemove;
569  bool flagOk = false;
570 
571  switch(chInfo.kind) {
572  case FIFFV_MEG_CH:
573  //Scan for MEG string and other characters
574  regExpRemove = QRegExp("(MEG|-|_|/|\| )");
575  chName.remove(regExpRemove);
576 
577  //After cleaning the string try to convert the residual to an int number
578  flagOk = false;
579  m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("MEG").arg(chName));
580 
581  break;
582 
583  case FIFFV_REF_MEG_CH:
584  //Scan for MEG string and other characters
585  regExpRemove = QRegExp("(MEG|-|_|/|\| )");
586  chName.remove(regExpRemove);
587 
588  //After cleaning the string try to convert the residual to an int number
589  flagOk = false;
590  m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("MEG").arg(chName));
591 
592  break;
593 
594  case FIFFV_EEG_CH: {
595  //Scan for EEG string and other characters
596  regExpRemove = QRegExp("(EEG|-|_|/|\| )");
597  chName.remove(regExpRemove);
598 
599  //After cleaning the string try to convert the residual to an int number
600  flagOk = false;
601  m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("EEG").arg(chName));
602 
603  break;
604  }
605  }
606  } //end fiff chs
607 
609 }
610 
611 
612 //*************************************************************************************************************
613 
615 {
616  beginResetModel();
617 
618  m_fiffInfo = FiffInfo();
619  m_layoutMap.clear();
620  m_aliasNames.clear();
621  m_mappedLayoutChNames.clear();
622 
623  endResetModel();
624 
625  qDebug("ChInfoModel cleared.");
626 }
void fiffInfoChanged(const FiffInfo &fiffInfo)
FIFF measurement file information.
Definition: fiff_info.h:96
QMap< int, QSharedPointer< MNEOperator > > m_assignedOperators
Definition: chinfomodel.h:194
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: chinfomodel.cpp:67
QMap< QString, QPointF > m_layoutMap
Definition: chinfomodel.h:191
void layoutChanged(const QMap< QString, QPointF > &layoutMap)
void assignedOperatorsChanged(const QMap< int, QSharedPointer< MNEOperator > > &assignedOperators)
#define FIFF_UNIT_T_M
Channel info descriptor.
Definition: fiff_ch_info.h:87
QList< FiffChInfo > chs
const QStringList & getMappedChannelsList()
void channelsMappedToLayout(const QStringList &mappedLayoutChNames)
QStringList m_mappedLayoutChNames
Definition: chinfomodel.h:193
int getIndexFromMappedChName(QString chName)
int getIndexFromOrigChName(QString chName)