MNE-CPP  beta 1.0
realtimeevokedmodel.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 #include "realtimeevokedmodel.h"
37 
38 #include <QDebug>
39 #include <QBrush>
40 #include <QThread>
41 
42 
43 //*************************************************************************************************************
44 //=============================================================================================================
45 // USED NAMESPACES
46 //=============================================================================================================
47 
48 using namespace XDISPLIB;
49 
50 
51 //*************************************************************************************************************
52 //=============================================================================================================
53 // DEFINE MEMBER METHODS
54 //=============================================================================================================
55 
57 : QAbstractTableModel(parent)
58 , m_matData(MatrixXd(0,0))
59 , m_matDataFreeze(MatrixXd(0,0))
60 , m_fSps(1024.0f)
61 , m_bIsFreezed(false)
62 {
63 
64 }
65 
66 
67 //*************************************************************************************************************
68 //virtual functions
69 int RealTimeEvokedModel::rowCount(const QModelIndex & /*parent*/) const
70 {
71  if(!m_qMapIdxRowSelection.empty())
72  return m_qMapIdxRowSelection.size();
73  else
74  return 0;
75 }
76 
77 
78 //*************************************************************************************************************
79 
80 int RealTimeEvokedModel::columnCount(const QModelIndex & /*parent*/) const
81 {
82  return 2;
83 }
84 
85 
86 //*************************************************************************************************************
87 
88 QVariant RealTimeEvokedModel::data(const QModelIndex &index, int role) const
89 {
90  if(role != Qt::DisplayRole && role != Qt::BackgroundRole)
91  return QVariant();
92 
93  if (index.isValid()) {
94  qint32 row = m_qMapIdxRowSelection[index.row()];
95 
96  //******** first column (chname) ********
97  if(index.column() == 0 && role == Qt::DisplayRole)
98  return QVariant(m_pRTE->info().ch_names[row]);
99 
100  //******** second column (data plot) ********
101  if(index.column()==1) {
102  QVariant v;
103 
104  switch(role) {
105  case Qt::DisplayRole: {
106  //pack all adjacent (after reload) RowVectorPairs into a QList
107  RowVectorXd rowVec;
108 
109  if(m_bIsFreezed)
110  {
111  // data freeze
112  rowVec = m_matDataFreeze.row(row);
113 
114  v.setValue(rowVec);
115  }
116  else
117  {
118  // data
119  rowVec = m_matData.row(row);
120 
121  v.setValue(rowVec);
122  }
123  return v;
124  break;
125  }
126  case Qt::BackgroundRole: {
127 // if(m_fiffInfo.bads.contains(m_chInfolist[row].ch_name)) {
128 // QBrush brush;
129 // brush.setStyle(Qt::SolidPattern);
130 // // qDebug() << m_chInfolist[row].ch_name << "is marked as bad, index:" << row;
131 // brush.setColor(Qt::red);
132 // return QVariant(brush);
133 // }
134 // else
135  return QVariant();
136 
137  break;
138  }
139  } // end role switch
140  } // end column check
141 
142  } // end index.valid() check
143 
144  return QVariant();
145 }
146 
147 
148 //*************************************************************************************************************
149 
150 QVariant RealTimeEvokedModel::headerData(int section, Qt::Orientation orientation, int role) const
151 {
152  if(role != Qt::DisplayRole && role != Qt::TextAlignmentRole)
153  return QVariant();
154 
155  if(orientation == Qt::Horizontal) {
156  switch(section) {
157  case 0: //chname column
158  return QVariant();
159  case 1: //data plot column
160  return QVariant("data plot");
161  switch(role) {
162  case Qt::DisplayRole:
163  return QVariant("data plot");
164  case Qt::TextAlignmentRole:
165  return QVariant(Qt::AlignLeft);
166  }
167  }
168  }
169  else if(orientation == Qt::Vertical) {
170  QModelIndex chname = createIndex(section,0);
171  switch(role) {
172  case Qt::DisplayRole:
173  return QVariant(data(chname).toString());
174  }
175  }
176 
177  return QVariant();
178 }
179 
180 
181 //*************************************************************************************************************
182 
183 void RealTimeEvokedModel::setRTE(QSharedPointer<RealTimeEvoked> &pRTE)
184 {
185  beginResetModel();
186  m_pRTE = pRTE;
187  endResetModel();
188 
189  resetSelection();
190 }
191 
192 
193 //*************************************************************************************************************
194 
196 {
197  m_matData = m_pRTE->getValue()->data;
198  m_bIsInit = true;
199 
200  //Update data content
201  QModelIndex topLeft = this->index(0,1);
202  QModelIndex bottomRight = this->index(m_pRTE->info().nchan-1,1);
203  QVector<int> roles; roles << Qt::DisplayRole;
204  emit dataChanged(topLeft, bottomRight, roles);
205 }
206 
207 
208 //*************************************************************************************************************
209 
210 QColor RealTimeEvokedModel::getColor(qint32 row) const
211 {
212  if(row < m_qMapIdxRowSelection.size())
213  {
214  qint32 chRow = m_qMapIdxRowSelection[row];
215  return m_pRTE->chColor()[chRow];
216  }
217  else
218  return QColor();
219 }
220 
221 
222 //*************************************************************************************************************
223 
224 fiff_int_t RealTimeEvokedModel::getKind(qint32 row) const
225 {
226  if(row < m_qMapIdxRowSelection.size())
227  {
228  qint32 chRow = m_qMapIdxRowSelection[row];
229  return m_pRTE->info().chs[chRow].kind;
230  }
231  else
232  return 0;
233 }
234 
235 
236 //*************************************************************************************************************
237 
238 fiff_int_t RealTimeEvokedModel::getUnit(qint32 row) const
239 {
240  if(row < m_qMapIdxRowSelection.size())
241  {
242  qint32 chRow = m_qMapIdxRowSelection[row];
243  return m_pRTE->info().chs[chRow].unit;
244  }
245  else
246  return FIFF_UNIT_NONE;
247 }
248 
249 
250 //*************************************************************************************************************
251 
252 fiff_int_t RealTimeEvokedModel::getCoil(qint32 row) const
253 {
254  if(row < m_qMapIdxRowSelection.size())
255  {
256  qint32 chRow = m_qMapIdxRowSelection[row];
257  return m_pRTE->info().chs[chRow].coil_type;
258  }
259  else
260  return FIFFV_COIL_NONE;
261 }
262 
263 
264 //*************************************************************************************************************
265 
266 void RealTimeEvokedModel::selectRows(const QList<qint32> &selection)
267 {
268  beginResetModel();
269 
270  m_qMapIdxRowSelection.clear();
271 
272  qint32 count = 0;
273  for(qint32 i = 0; i < selection.size(); ++i)
274  {
275  if(selection[i] < m_pRTE->info().nchan)
276  {
277  m_qMapIdxRowSelection.insert(count,selection[i]);
278  ++count;
279  }
280  }
281 
282  emit newSelection(selection);
283 
284  endResetModel();
285 }
286 
287 
288 //*************************************************************************************************************
289 
291 {
292  beginResetModel();
293 
294  m_qMapIdxRowSelection.clear();
295 
296  for(qint32 i = 0; i < m_pRTE->info().nchan; ++i)
297  m_qMapIdxRowSelection.insert(i,i);
298 
299  endResetModel();
300 }
301 
302 
303 //*************************************************************************************************************
304 
305 void RealTimeEvokedModel::toggleFreeze(const QModelIndex &)
306 {
307  m_bIsFreezed = !m_bIsFreezed;
308 
309  if(m_bIsFreezed)
310  m_matDataFreeze = m_matData;
311 
312  //Update data content
313  QModelIndex topLeft = this->index(0,1);
314  QModelIndex bottomRight = this->index(m_pRTE->info().nchan-1,1);
315  QVector<int> roles; roles << Qt::DisplayRole;
316  emit dataChanged(topLeft, bottomRight, roles);
317 }
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
void newSelection(QList< qint32 > selection)
QVariant data(int row, int column, int role=Qt::DisplayRole) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
fiff_int_t getKind(qint32 row) const
QColor getColor(qint32 row) const
fiff_int_t getCoil(qint32 row) const
fiff_int_t getUnit(qint32 row) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
void toggleFreeze(const QModelIndex &index)
Declaration of the RealTimeEvokedModel Class.
void selectRows(const QList< qint32 > &selection)
void setRTE(QSharedPointer< RealTimeEvoked > &pRTE)
#define FIFFV_COIL_NONE