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 XDISPLIB;
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("Position");
135  break;
136 
137  case 8:
138  return QString("%1").arg("Digitizer (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  switch(role) {
270  case Qt::DisplayRole:
271  return v;
272 
273  case ChInfoModelRoles::GetMEGType:
274  return v;
275 
276  case Qt::TextAlignmentRole:
277  return Qt::AlignHCenter + Qt::AlignVCenter;
278  }
279  }//end column check
280 
281  //******** seventh column (channel unit) ********
282  if(index.column()==6) {
283  QVariant v;
284 
285  switch(role) {
286  case Qt::DisplayRole:
287  v.setValue(QString("%1").arg(m_fiffInfo.chs.at(index.row()).unit));
288  return v;
289 
290  case ChInfoModelRoles::GetChUnit:
291  v.setValue(m_fiffInfo.chs.at(index.row()).unit);
292  return v;
293 
294  case Qt::TextAlignmentRole:
295  return Qt::AlignHCenter + Qt::AlignVCenter;
296  }
297  }//end column check
298 
299  //******** eigth column (channel layout position) ********
300  if(index.column()==7) {
301  QVariant v;
302 
303  QPointF point = m_layoutMap[m_mappedLayoutChNames.at(index.row())];
304 
305  switch(role) {
306  case Qt::DisplayRole:
307  v.setValue(QString("(%1|%2)").arg(point.x()).arg(point.y()));
308  return v;
309 
310  case ChInfoModelRoles::GetChPosition:
311  v.setValue(point);
312  return v;
313 
314  case Qt::TextAlignmentRole:
315  return Qt::AlignHCenter + Qt::AlignVCenter;
316  }
317  }//end column check
318 
319  //******** ninth column (channel digitizer position) ********
320  if(index.column()==8) {
321  QVariant v;
322 
323  QVector3D point3D(m_fiffInfo.chs.at(index.row()).loc(0,0) * 100, //convert to cm
324  m_fiffInfo.chs.at(index.row()).loc(1,0) * 100,
325  m_fiffInfo.chs.at(index.row()).loc(2,0) * 100);
326 
327  switch(role) {
328  case Qt::DisplayRole:
329  v.setValue(QString("(%1|%2|%3)").arg(point3D.x()).arg(point3D.y()).arg(point3D.z()));
330  return v;
331 
332  case ChInfoModelRoles::GetChDigitizer:
333  v.setValue(point3D);
334  return v;
335 
336  case Qt::TextAlignmentRole:
337  return Qt::AlignHCenter + Qt::AlignVCenter;
338  }
339  }//end column check
340 
341  //******** tenth column (active channel filter type) ********
342  if(index.column()==9) {
343  QVariant v;
344 
345 // //Check if mne operator is a filter operator
346 // QSharedPointer<MNEOperator> operatorPtr = m_assignedOperators.value(index.row(), QSharedPointer<MNEOperator>(new MNEOperator()));
347 // QSharedPointer<FilterOperator> filterOperator;
348 
349  switch(role) {
350  case Qt::DisplayRole: {
351  return v;
352  }
353 // if(operatorPtr->m_OperatorType == MNEOperator::FILTER) {
354 // filterOperator = operatorPtr.staticCast<FilterOperator>();
355 // }
356 // else {
357 // v.setValue(QString("%1").arg("none"));
358 // return v;
359 // }
360 
361 // switch(filterOperator->m_Type) {
362 // case FilterOperator::LPF: {
363 // v.setValue(QString("%1 | %2").arg("LP").arg(filterOperator->m_dCenterFreq*m_fiffInfo.sfreq/2));
364 // return v;
365 // }
366 
367 // case FilterOperator::HPF: {
368 // v.setValue(QString("%1 | %2").arg("HP").arg(filterOperator->m_dCenterFreq*m_fiffInfo.sfreq/2));
369 // return v;
370 // }
371 
372 // case FilterOperator::BPF: {
373 // double fsample = m_fiffInfo.sfreq;
374 // 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
375 // double high = (filterOperator->m_dCenterFreq*fsample/2) + (filterOperator->m_dBandwidth*fsample/4);
376 // v.setValue(QString("%1 | %2 | %3").arg("BP").arg(low).arg(high));
377 // return v;
378 // }
379 
380 // case FilterOperator::NOTCH: {
381 // double fsample = m_fiffInfo.sfreq;
382 // double low = (filterOperator->m_dCenterFreq*fsample/2) - (filterOperator->m_dBandwidth*fsample/4);
383 // double high = (filterOperator->m_dCenterFreq*fsample/2) + (filterOperator->m_dBandwidth*fsample/4);
384 // v.setValue(QString("%1 | %2 | %3").arg("NOTCH").arg(low).arg(high));
385 // return v;
386 // }
387 // }
388 // }
389 
390 // case ChInfoModelRoles::GetChActiveFilter: {
391 // if(operatorPtr->m_OperatorType == MNEOperator::FILTER) {
392 // filterOperator = operatorPtr.staticCast<FilterOperator>();
393 // }
394 // else {
395 // v.setValue(QString("%1").arg("none"));
396 // return v;
397 // }
398 
399 // v.setValue(operatorPtr);
400 // return v;
401 // }
402 
403  case Qt::TextAlignmentRole:
404  return Qt::AlignHCenter + Qt::AlignVCenter;
405  }
406 
407  //******** eleventh column (coil type) ********
408  if(index.column()==10) {
409  QVariant v;
410 
411  switch(role) {
412  case Qt::DisplayRole:
413  v.setValue(QString("%1").arg(m_fiffInfo.chs.at(index.row()).coil_type));
414  return v;
415 
416  case ChInfoModelRoles::GetChCoilType:
417  v.setValue(m_fiffInfo.chs.at(index.row()).coil_type);
418  return v;
419 
420  case Qt::TextAlignmentRole:
421  return Qt::AlignHCenter + Qt::AlignVCenter;
422  }
423  }//end column check
424  }//end column check
425  } // end index.valid() check
426 
427  return QVariant();
428 }
429 
430 
431 //*************************************************************************************************************
432 
433 bool ChInfoModel::insertRows(int position, int span, const QModelIndex & parent)
434 {
435  Q_UNUSED(position);
436  Q_UNUSED(span);
437  Q_UNUSED(parent);
438 
439  return true;
440 }
441 
442 
443 //*************************************************************************************************************
444 
445 bool ChInfoModel::removeRows(int position, int span, const QModelIndex & parent)
446 {
447  Q_UNUSED(position);
448  Q_UNUSED(span);
449  Q_UNUSED(parent);
450 
451  return true;
452 }
453 
454 
455 //*************************************************************************************************************
456 
457 Qt::ItemFlags ChInfoModel::flags(const QModelIndex & index) const
458 {
459  Q_UNUSED(index);
460  return Qt::ItemIsEnabled | Qt::ItemIsSelectable /*| Qt::ItemIsEditable*/;
461 }
462 
463 
464 //*************************************************************************************************************
465 
466 bool ChInfoModel::setData(const QModelIndex &index, const QVariant &value, int role)
467 {
468  Q_UNUSED(index);
469  Q_UNUSED(value);
470  Q_UNUSED(role);
471 
472  return true;
473 }
474 
475 
476 //*************************************************************************************************************
477 
479 {
480  beginResetModel();
481 
482  m_fiffInfo = fiffInfo;
485 
487 
488  endResetModel();
489 
490  emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
491 }
492 
493 
494 //*************************************************************************************************************
495 
496 //void ChInfoModel::assignedOperatorsChanged(const QMap<int,QSharedPointer<MNEOperator> > &assignedOperators)
497 //{
498 // beginResetModel();
499 
500 // m_assignedOperators = assignedOperators;
501 
502 // endResetModel();
503 
504 // emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
505 //}
506 
507 
508 //*************************************************************************************************************
509 
510 void ChInfoModel::layoutChanged(const QMap<QString,QPointF> &layoutMap)
511 {
512  beginResetModel();
513 
514  m_layoutMap = layoutMap;
517 
519 
520  endResetModel();
521 
522  emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
523 }
524 
525 
526 //*************************************************************************************************************
527 
529 {
530 
531  return m_mappedLayoutChNames;
532 }
533 
534 
535 //*************************************************************************************************************
536 
538 {
539  return m_fiffInfo.ch_names.indexOf(chName);
540 }
541 
542 
543 //*************************************************************************************************************
544 
546 {
547  return m_mappedLayoutChNames.indexOf(chName);
548 }
549 
550 
551 //*************************************************************************************************************
552 
554 {
555  //TODO: Move this to layout loader in MNE-CPP Utils?
556  //Map channels to layout
557  QList<FiffChInfo> channelList = m_fiffInfo.chs;
558  for(int i = 0; i<channelList.size(); i++) {
559  //Get current channel information
560  FiffChInfo chInfo = channelList.at(i);
561  QString chName = chInfo.ch_name;
562  QRegExp regExpRemove;
563  bool flagOk = false;
564 
565  switch(chInfo.kind) {
566  case FIFFV_MEG_CH:
567  //Scan for MEG string and other characters
568  regExpRemove = QRegExp("(MEG|-|_|/|\| )");
569  chName.remove(regExpRemove);
570 
571  //After cleaning the string try to convert the residual to an int number
572  flagOk = false;
573  m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("MEG").arg(chName));
574 
575  break;
576 
577  case FIFFV_EEG_CH: {
578  //Scan for EEG string and other characters
579  regExpRemove = QRegExp("(EEG|-|_|/|\| )");
580  chName.remove(regExpRemove);
581 
582  //After cleaning the string try to convert the residual to an int number
583  flagOk = false;
584  m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("EEG").arg(chName));
585 
586  break;
587  }
588  }
589  } //end fiff chs
590 
592 }
593 
594 
595 //*************************************************************************************************************
596 
598 {
599  beginResetModel();
600 
601  m_fiffInfo = FiffInfo();
602  m_layoutMap.clear();
603  m_aliasNames.clear();
604  m_mappedLayoutChNames.clear();
605 
606  endResetModel();
607 
608  qDebug("ChInfoModel cleared.");
609 }
void fiffInfoChanged(const FiffInfo &fiffInfo)
FIFF measurement file information.
Definition: fiff_info.h:96
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)
#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)