MNE-CPP  beta 1.0
eventwindow.cpp
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "eventwindow.h"
43 
44 
45 //*************************************************************************************************************
46 //=============================================================================================================
47 // USED NAMESPACES
48 //=============================================================================================================
49 
50 using namespace MNEBrowseRawQt;
51 
52 
53 //*************************************************************************************************************
54 //=============================================================================================================
55 // DEFINE MEMBER METHODS
56 //=============================================================================================================
57 
58 EventWindow::EventWindow(QWidget *parent)
59 : QDockWidget(parent)
60 , ui(new Ui::EventWindowDockWidget)
61 , m_pMainWindow(static_cast<MainWindow*>(parent))
62 , m_pColordialog(new QColorDialog(this))
63 {
64  ui->setupUi(this);
65 
66  //hide the color dialog
67  m_pColordialog->hide();
68 
69  //------------------------
70  //--- Setup data model ---
71  //------------------------
72  if(m_pMainWindow->m_qEventFile.exists())
73  m_pEventModel = new EventModel(m_pMainWindow->m_qEventFile, this);
74  else
75  m_pEventModel = new EventModel(this);
76 }
77 
78 
79 //*************************************************************************************************************
80 
82 {
83  delete ui;
84 }
85 
86 
87 //*************************************************************************************************************
88 
90 {
91  initMVCSettings();
92  initCheckBoxes();
93  initComboBoxes();
94  initToolButtons();
95  initPushButtons();
96 }
97 
98 
99 //*************************************************************************************************************
100 
102 {
103  return ui->m_tableView_eventTableView;
104 }
105 
106 
107 //*************************************************************************************************************
108 
110 {
111  return m_pEventModel;
112 }
113 
114 
115 //*************************************************************************************************************
116 
118 {
119  return m_pEventDelegate;
120 }
121 
122 
123 //*************************************************************************************************************
124 
125 void EventWindow::initMVCSettings()
126 {
127  //Set fiffInfo and first/last sample in the event model
128  m_pEventModel->setFiffInfo(m_pMainWindow->m_pDataWindow->getDataModel()->m_fiffInfo);
129  m_pEventModel->setFirstLastSample(m_pMainWindow->m_pDataWindow->getDataModel()->firstSample(),
130  m_pMainWindow->m_pDataWindow->getDataModel()->lastSample());
131 
132  //set MVC model
133  ui->m_tableView_eventTableView->setModel(m_pEventModel);
134 
135  //set MVC delegate
136  m_pEventDelegate = new EventDelegate(this);
137  ui->m_tableView_eventTableView->setItemDelegate(m_pEventDelegate);
138 
139  //Resize columns to contents
140  ui->m_tableView_eventTableView->resizeColumnsToContents();
141  ui->m_tableView_eventTableView->adjustSize();
142 
143  //Connect selection in event window to jumpEvent slot
144  connect(ui->m_tableView_eventTableView->selectionModel(),&QItemSelectionModel::currentRowChanged,
146 
147  //Update the data views whenever the data in the event model changes
148  connect(m_pEventModel,&EventModel::dataChanged,
149  m_pMainWindow->m_pDataWindow,&DataWindow::updateDataTableViews);
150 }
151 
152 
153 //*************************************************************************************************************
154 
155 void EventWindow::initCheckBoxes()
156 {
157  connect(ui->m_checkBox_activateEvents,&QCheckBox::stateChanged, [=](int state){
158  m_pMainWindow->m_pDataWindow->getDataDelegate()->m_bActivateEvents = state;
159  jumpToEvent(ui->m_tableView_eventTableView->selectionModel()->currentIndex(), QModelIndex());
160  m_pMainWindow->m_pDataWindow->updateDataTableViews();
161  });
162 
163  connect(ui->m_checkBox_showSelectedEventsOnly,&QCheckBox::stateChanged, [=](int state){
164  m_pMainWindow->m_pDataWindow->getDataDelegate()->m_bShowSelectedEventsOnly = state;
165  jumpToEvent(ui->m_tableView_eventTableView->selectionModel()->currentIndex(), QModelIndex());
166  m_pMainWindow->m_pDataWindow->updateDataTableViews();
167  });
168 }
169 
170 
171 //*************************************************************************************************************
172 
173 void EventWindow::initComboBoxes()
174 {
175  ui->m_comboBox_filterTypes->addItem("All");
176  ui->m_comboBox_filterTypes->addItems(m_pEventModel->getEventTypeList());
177  ui->m_comboBox_filterTypes->setCurrentText("All");
178 
179  //Connect filter types to event model
180  connect(ui->m_comboBox_filterTypes, &QComboBox::currentTextChanged,[=](QString string){
181  m_pEventModel->setEventFilterType(string);
182  m_pMainWindow->m_pDataWindow->updateDataTableViews();
183  });
184 
185  connect(m_pEventModel,&EventModel::updateEventTypes,
186  this, &EventWindow::updateComboBox);
187 }
188 
189 
190 //*************************************************************************************************************
191 
192 void EventWindow::initToolButtons()
193 {
194  QToolBar *toolBar = new QToolBar(this);
195  toolBar->setOrientation(Qt::Vertical);
196  toolBar->setMovable(false);
197 
198  //Add event
199  QAction* addEventAction = new QAction(QIcon(":/Resources/Images/addEvent.png"),tr("Add event"), this);
200  addEventAction->setStatusTip(tr("Add an event to the event list"));
201  toolBar->addAction(addEventAction);
202  connect(addEventAction, &QAction::triggered,
204 
205  //Remove event
206  QAction* removeEvent = new QAction(QIcon(":/Resources/Images/removeEvent.png"),tr("Remove event"), this);
207  removeEvent->setStatusTip(tr("Remove an event from the event list"));
208  toolBar->addAction(removeEvent);
209  connect(removeEvent, &QAction::triggered,
211 
212  ui->m_gridLayout_Main->addWidget(toolBar,0,1,1,1);
213 }
214 
215 
216 //*************************************************************************************************************
217 
218 void EventWindow::initPushButtons()
219 {
220  connect(ui->m_pushButton_addEventType, &QPushButton::clicked,
222 }
223 
224 
225 //*************************************************************************************************************
226 
227 void EventWindow::updateComboBox(const QString &currentEventType)
228 {
229  ui->m_comboBox_filterTypes->clear();
230  ui->m_comboBox_filterTypes->addItem("All");
231  ui->m_comboBox_filterTypes->addItems(m_pEventModel->getEventTypeList());
232  if(m_pEventModel->getEventTypeList().contains(currentEventType))
233  ui->m_comboBox_filterTypes->setCurrentText(currentEventType);
234 }
235 
236 
237 //*************************************************************************************************************
238 
239 bool EventWindow::event(QEvent * event)
240 {
241  //On resize event center marker again
242  if(event->type() == QEvent::Resize) {
243  qDebug()<<"resize";
244  jumpToEvent(ui->m_tableView_eventTableView->selectionModel()->currentIndex(), QModelIndex());
245  }
246 
247  //Delete selected row on delete key press event
248  if(event->type() == QEvent::KeyPress && ui->m_tableView_eventTableView->hasFocus()) {
249  QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
250  if(keyEvent->key() == Qt::Key_Delete)
252  }
253 
254  return QDockWidget::event(event);
255 }
256 
257 
258 //*************************************************************************************************************
259 
260 void EventWindow::jumpToEvent(const QModelIndex & current, const QModelIndex & previous)
261 {
262  Q_UNUSED(previous);
263 
264  if(ui->m_checkBox_activateEvents->isChecked()) {
265  //Always get the first column 0 (sample) of the model - Note: Need to map index from sorting model back to source model
266  QModelIndex index = m_pEventModel->index(current.row(), 0);
267 
268  //Get the sample value
269  int sample = m_pEventModel->data(index, Qt::DisplayRole).toInt();
270 
271  //Jump to sample - put sample in the middle of the view - the viewport holds the width of the are which is changed through scrolling
272  int rawTableViewColumnWidth = m_pMainWindow->m_pDataWindow->getDataTableView()->viewport()->width();
273 
274  if(sample-rawTableViewColumnWidth/2 < rawTableViewColumnWidth/2) //events lie in the first half of the data window at the beginning of the loaded data -> cannot centralize view on event
275  m_pMainWindow->m_pDataWindow->getDataTableView()->horizontalScrollBar()->setValue(0);
276  else if(sample+rawTableViewColumnWidth/2 > m_pMainWindow->m_pDataWindow->getDataModel()->lastSample()-rawTableViewColumnWidth/2) //events lie in the last half of the data window at the end of the loaded data -> cannot centralize view on event
277  m_pMainWindow->m_pDataWindow->getDataTableView()->horizontalScrollBar()->setValue(m_pMainWindow->m_pDataWindow->getDataTableView()->maximumWidth());
278  else //centralize view on event
279  m_pMainWindow->m_pDataWindow->getDataTableView()->horizontalScrollBar()->setValue(sample-rawTableViewColumnWidth/2);
280 
281  qDebug()<<"Jumping to Event at sample "<<sample<<"rawTableViewColumnWidth"<<rawTableViewColumnWidth;
282 
283  m_pMainWindow->m_pDataWindow->updateDataTableViews();
284  }
285 }
286 
287 
288 //*************************************************************************************************************
289 
291 {
292  QModelIndexList indexList = ui->m_tableView_eventTableView->selectionModel()->selectedIndexes();
293 
294  for(int i = 0; i<indexList.size(); i++)
295  m_pEventModel->removeRow(indexList.at(i).row() - i); // - i because the internal data structure gets smaller by one with each succession in this for statement
296 }
297 
298 
299 //*************************************************************************************************************
300 
302 {
303  m_pEventModel->insertRow(0, QModelIndex());
304 }
305 
306 
307 //*************************************************************************************************************
308 
310 {
311  //Open add event type dialog
312  m_pEventModel->addNewEventType(QString().number(ui->m_spinBox_addEventType->value()), m_pColordialog->getColor(Qt::black, this));
313  m_pEventModel->setEventFilterType(QString().number(ui->m_spinBox_addEventType->value()));
314  m_pMainWindow->m_pDataWindow->updateDataTableViews();
315 }
Definition: aboutwindow.h:52
void setFirstLastSample(int firstSample, int lastSample)
Definition: eventmodel.cpp:423
Contains the implementation of the EventWindow class.
QStringList getEventTypeList() const
Definition: eventmodel.cpp:490
QTableView * getDataTableView()
Definition: datawindow.cpp:99
void addNewEventType(const QString &eventType, const QColor &typeColor)
Definition: eventmodel.cpp:528
EventWindow(QWidget *parent=0)
Definition: eventwindow.cpp:58
void setEventFilterType(const QString eventType)
Definition: eventmodel.cpp:458
qint32 firstSample() const
Definition: rawmodel.h:512
void jumpToEvent(const QModelIndex &current, const QModelIndex &previous)
void updateEventTypes(const QString &currentFilterType)
void setFiffInfo(FiffInfo &fiffInfo)
Definition: eventmodel.cpp:415
EventDelegate * getEventDelegate()
qint32 lastSample() const
Definition: rawmodel.h:521
QTableView * getEventTableView()