MNE-CPP  beta 1.0
eventdelegate.cpp
Go to the documentation of this file.
1 //=============================================================================================================
38 //*************************************************************************************************************
39 //=============================================================================================================
40 // INCLUDES
41 //=============================================================================================================
42 
43 #include "eventdelegate.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 EventDelegate::EventDelegate(QObject *parent)
60 : QItemDelegate(parent)
61 {
62 }
63 
64 
65 //*************************************************************************************************************
66 
67 QWidget *EventDelegate::createEditor(QWidget *parent,
68  const QStyleOptionViewItem &/* option */,
69  const QModelIndex & index) const
70 {
71  const EventModel* pEventModel = static_cast<const EventModel*>(index.model());
72 
73  switch(index.column()) {
74  case 0: {
75  QSpinBox *editor = new QSpinBox(parent);
76  editor->setMinimum(0);
77  editor->setMaximum(pEventModel->getFirstLastSample().second);
78  return editor;
79  }
80 
81  case 1: {
82  QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
83  editor->setMinimum(0.0);
84  editor->setMaximum(pEventModel->getFirstLastSample().second / pEventModel->getFiffInfo().sfreq);
85  editor->setSingleStep(0.01);
86  return editor;
87  }
88 
89  case 2: {
90  QComboBox *editor = new QComboBox(parent);
91  editor->addItems(pEventModel->getEventTypeList());
92  return editor;
93  }
94  }
95 
96  QWidget *returnWidget = new QWidget();
97  return returnWidget;
98 }
99 
100 
101 //*************************************************************************************************************
102 
103 void EventDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
104 {
105  switch(index.column()) {
106  case 0: {
107  int value = index.model()->data(index, Qt::DisplayRole).toInt();
108  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
109  spinBox->setValue(value);
110  break;
111  }
112 
113  case 1: {
114  double value = index.model()->data(index, Qt::DisplayRole).toDouble();
115  QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
116  spinBox->setValue(value);
117  break;
118  }
119 
120  case 2: {
121  int value = index.model()->data(index, Qt::DisplayRole).toInt();
122  QComboBox *spinBox = static_cast<QComboBox*>(editor);
123  spinBox->setCurrentText(QString().number(value));
124  break;
125  }
126  }
127 }
128 
129 
130 //*************************************************************************************************************
131 
132 void EventDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
133  const QModelIndex &index) const
134 {
135  switch(index.column()) {
136  case 0: {
137  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
138  spinBox->interpretText();
139  int value = spinBox->value();
140 
141  model->setData(index, value, Qt::EditRole);
142  break;
143  }
144 
145  case 1: {
146  QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
147  spinBox->interpretText();
148  double value = spinBox->value();
149 
150  model->setData(index, value, Qt::EditRole);
151  break;
152  }
153 
154  case 2: {
155  QComboBox *spinBox = static_cast<QComboBox*>(editor);
156  QString value = spinBox->currentText();
157 
158  model->setData(index, value.toInt(), Qt::EditRole);
159  break;
160  }
161  }
162 }
163 
164 
165 //*************************************************************************************************************
166 
167 void EventDelegate::updateEditorGeometry(QWidget *editor,
168  const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
169 {
170  editor->setGeometry(option.rect);
171 }
QStringList getEventTypeList() const
Definition: eventmodel.cpp:490
Contains the declaration of the EventDelegate class.
QPair< int, int > getFirstLastSample() const
Definition: eventmodel.cpp:449
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
FiffInfo getFiffInfo() const
Definition: eventmodel.cpp:441