67 RawDelegate::RawDelegate(QObject *parent)
68 : QAbstractItemDelegate(parent)
70 , m_bShowSelectedEventsOnly(false)
71 , m_bActivateEvents(true)
74 m_iDefaultPlotHeight = DELEGATE_PLOT_HEIGHT;
76 m_nhlines = DELEGATE_NHLINES;
79 m_pEventView =
new QTableView(NULL);
80 m_pRawView =
new QTableView(NULL);
83 m_scaleMap[
"MEG_grad"] = 400 * 1e-15 * 100;
84 m_scaleMap[
"MEG_mag"] = 1.2 * 1e-12;
85 m_scaleMap[
"MEG_EEG"] = 30 * 1e-06;
86 m_scaleMap[
"MEG_EOG"] = 150 * 1e-06;
87 m_scaleMap[
"MEG_EMG"] = 1 * 1e-03;
88 m_scaleMap[
"MEG_ECG"] = 1 * 1e-03;
89 m_scaleMap[
"MEG_MISC"] = 1 * 1;
90 m_scaleMap[
"MEG_STIM"] = 5 * 1;
96 void RawDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
98 float t_fPlotHeight = option.rect.height();
99 switch(index.column()) {
103 painter->rotate(-90);
104 painter->drawText(QRectF(-option.rect.y()-t_fPlotHeight,0,t_fPlotHeight,20),Qt::AlignCenter,index.model()->data(index,Qt::DisplayRole).toString());
113 QVariant v = index.model()->data(index,Qt::BackgroundRole);
114 if(v.canConvert<QBrush>()) {
115 QPointF oldBO = painter->brushOrigin();
116 painter->setBrushOrigin(option.rect.topLeft());
117 painter->fillRect(option.rect, qvariant_cast<QBrush>(v));
118 painter->setBrushOrigin(oldBO);
122 QVariant variant = index.model()->data(index,Qt::DisplayRole);
123 QList<RowVectorPair> listPairs = variant.value<QList<RowVectorPair> >();
125 double channelMean = 0;
127 QModelIndex meanIndex = index.model()->index(index.row(),2);
128 QVariant channelMeanVariant = index.model()->data(meanIndex,RawModelRoles::GetChannelMean);
129 channelMean = channelMeanVariant.toDouble();
134 QPainterPath path(QPointF(option.rect.x()+t_rawModel->
relFiffCursor()-1,option.rect.y()));
137 painter->setRenderHint(QPainter::Antialiasing,
false);
138 createGridPath(path,option,listPairs);
142 pen.setStyle(Qt::DotLine);
144 painter->setPen(pen);
145 painter->drawPath(path);
149 path = QPainterPath(QPointF(option.rect.x()+t_rawModel->
relFiffCursor(), option.rect.y()));
150 createPlotPath(index, option, path, listPairs, channelMean);
152 if(option.state & QStyle::State_Selected) {
153 pen.setStyle(Qt::SolidLine);
155 pen.setColor(Qt::red);
156 painter->setPen(pen);
159 painter->translate(0,t_fPlotHeight/2);
160 painter->setRenderHint(QPainter::Antialiasing,
true);
161 painter->drawPath(path);
167 plotEvents(index, option, painter);
178 QSize RawDelegate::sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
182 switch(index.column()) {
184 size = QSize(20,option.rect.height());
187 QList<RowVectorPair> listPairs = index.model()->data(index).value<QList<RowVectorPair> >();
188 qint32 nsamples = (
static_cast<const RawModel*
>(index.model()))->lastSample()-(
static_cast<const RawModel*
>(index.model()))->firstSample();
190 size = QSize(nsamples*
m_dDx,option.rect.height());
204 m_pEventModel = eventModel;
205 m_pEventView = eventView;
206 m_pRawView = rawView;
220 void RawDelegate::createPlotPath(
const QModelIndex &index,
const QStyleOptionViewItem &option, QPainterPath& path, QList<RowVectorPair>& listPairs,
double channelMean)
const
223 qint32 kind = (
static_cast<const RawModel*
>(index.model()))->m_chInfolist[index.row()].kind;
224 double dMaxValue = 1e-9;
228 qint32 unit = (
static_cast<const RawModel*
>(index.model()))->m_pfiffIO->m_qlistRaw[0]->info.chs[index.row()].unit;
232 else if(unit == FIFF_UNIT_T)
244 case FIFFV_STIM_CH: {
252 case FIFFV_MISC_CH: {
259 double dScaleY = option.rect.height()/(2*dMaxValue);
261 double y_base = -path.currentPosition().y();
262 QPointF qSamplePosition;
264 path.moveTo(path.currentPosition().x(), -(y_base + ((*(listPairs[0].first) - channelMean)*dScaleY)));
267 for(qint8 i=0; i < listPairs.size(); ++i) {
269 for(qint32 j=0; j < listPairs[i].second; ++j)
271 double val = *(listPairs[i].first+j);
274 dValue = (val - channelMean)*dScaleY;
276 double newY = y_base+dValue;
278 qSamplePosition.setY(-newY);
279 qSamplePosition.setX(path.currentPosition().x()+
m_dDx);
281 path.lineTo(qSamplePosition);
291 void RawDelegate::createGridPath(QPainterPath& path,
const QStyleOptionViewItem &option, QList<RowVectorPair>& listPairs)
const
294 double distance = option.rect.height()/m_nhlines;
296 QPointF startpos = path.currentPosition();
297 QPointF endpoint(path.currentPosition().x()+listPairs[0].second*listPairs.size()*
m_dDx,path.currentPosition().y());
299 for(qint8 i=0; i < m_nhlines-1; ++i) {
300 endpoint.setY(endpoint.y()+distance);
301 path.moveTo(startpos.x(),endpoint.y());
302 path.lineTo(endpoint);
311 void RawDelegate::plotEvents(
const QModelIndex &index,
const QStyleOptionViewItem &option, QPainter* painter)
const
319 pen.setWidth(EVENT_MARKER_WIDTH);
326 for(
int i = 0; i<m_pEventModel->
rowCount(); i++) {
327 int sampleValue = m_pEventModel->data(m_pEventModel->index(i,0)).toInt();
328 int type = m_pEventModel->data(m_pEventModel->index(i,2)).toInt();
330 if(sampleValue>=sampleRangeLow && sampleValue<=sampleRangeHigh) {
332 pen.setColor(eventTypeColor.value(type, Qt::black));
334 colorTemp = pen.color();
335 colorTemp.setAlpha(EVENT_MARKER_OPACITY);
336 pen.setColor(colorTemp);
337 painter->setPen(pen);
340 painter->drawLine(option.rect.x() + sampleValue, option.rect.y(), option.rect.x() + sampleValue, option.rect.y() + option.rect.height() - EVENT_MARKER_WIDTH);
345 QModelIndexList indexes = m_pEventView->selectionModel()->selectedIndexes();
347 for(
int i = 0; i<indexes.size(); i++) {
348 qDebug()<<indexes.at(i).row();
349 int currentRow = indexes.at(i).row();
350 int sampleValue = m_pEventModel->data(m_pEventModel->index(currentRow,0)).toInt();
351 int type = m_pEventModel->data(m_pEventModel->index(currentRow,2)).toInt();
353 if(sampleValue>=sampleRangeLow && sampleValue<=sampleRangeHigh) {
357 pen.setColor(eventTypeColor.value(type, Qt::black));
359 colorTemp = pen.color();
360 colorTemp.setAlpha(EVENT_MARKER_OPACITY);
361 pen.setColor(colorTemp);
362 painter->setPen(pen);
365 painter->drawLine(option.rect.x() + sampleValue, option.rect.y(), option.rect.x() + sampleValue, option.rect.y() - option.rect.height() + EVENT_MARKER_WIDTH);
void setScaleMap(const QMap< QString, double > &scaleMap)
const QMap< int, QColor > & getEventTypeColors()
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
This class represents the delegate of the model/view framework of mne_browse_raw_qt application...
QMap< QString, double > m_scaleMap
qint32 relFiffCursor() const
qint32 sizeOfPreloadedData() const
bool m_bShowSelectedEventsOnly
void setModelView(EventModel *eventModel, QTableView *eventView, QTableView *rawView)