MNE-CPP  0.1.9
A Framework for Electrophysiology
channelselectionview.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "channelselectionview.h"
42 #include "ui_channelselectionview.h"
45 #include "helpers/selectionscene.h"
46 
47 #include <utils/layoutloader.h>
48 #include <utils/selectionio.h>
49 #include <utils/layoutmaker.h>
50 
51 #include <fiff/fiff.h>
52 
53 //=============================================================================================================
54 // QT INCLUDES
55 //=============================================================================================================
56 
57 #include <QDate>
58 #include <QVector3D>
59 #include <QFileDialog>
60 #include <QListWidgetItem>
61 #include <QSettings>
62 #include <QApplication>
63 #include <QKeyEvent>
64 
65 //=============================================================================================================
66 // EIGEN INCLUDES
67 //=============================================================================================================
68 
69 //=============================================================================================================
70 // USED NAMESPACES
71 //=============================================================================================================
72 
73 using namespace DISPLIB;
74 using namespace FIFFLIB;
75 using namespace UTILSLIB;
76 
77 //=============================================================================================================
78 // DEFINE MEMBER METHODS
79 //=============================================================================================================
80 
81 ChannelSelectionView::ChannelSelectionView(const QString& sSettingsPath,
82  QWidget *parent,
83  ChannelInfoModel::SPtr pChannelInfoModel,
84  Qt::WindowType f)
85 : AbstractView(parent, f)
86 , m_pUi(new Ui::ChannelSelectionViewWidget)
87 , m_pChannelInfoModel(pChannelInfoModel)
88 , m_bSetup(false)
89 {
90  m_sSettingsPath = sSettingsPath;
91  m_pUi->setupUi(this);
92 
93  //Init gui elements
94  initListWidgets();
95  initSelectionSceneView();
96  initComboBoxes();
97  initButtons();
98  initCheckBoxes();
99 
100  loadSettings();
101 
102  m_bSetup = true;
103 
104  setCurrentlyMappedFiffChannels(m_pChannelInfoModel->getMappedChannelsList());
105 }
106 
107 //=============================================================================================================
108 
110 {
111 // saveSettings();
112 
113  delete m_pUi;
114 }
115 
116 //=============================================================================================================
117 
118 void ChannelSelectionView::initListWidgets()
119 {
120  //Install event filter to receive key press events
121  m_pUi->m_listWidget_userDefined->installEventFilter(this);
122  m_pUi->m_listWidget_selectionGroups->installEventFilter(this);
123 
124  //Connect list widgets to update themselves and other list widgets when changed
125  connect(m_pUi->m_listWidget_selectionGroups, &QListWidget::currentItemChanged,
126  this, &ChannelSelectionView::updateSelectionGroupsList);
127 
128  //Update data view whenever a drag and drop item movement is performed
129  //TODO: This is inefficient because updateDataView is called everytime the list's viewport is entered
130  connect(m_pUi->m_listWidget_userDefined->model(), &QAbstractTableModel::dataChanged,
132 }
133 
134 //=============================================================================================================
135 
136 void ChannelSelectionView::initSelectionSceneView()
137 {
138  //Create layout scene and set to view
139  m_pSelectionScene = new SelectionScene(m_pUi->m_graphicsView_layoutPlot);
140  m_pUi->m_graphicsView_layoutPlot->setScene(m_pSelectionScene);
141 
142  connect(m_pSelectionScene, &QGraphicsScene::selectionChanged,
143  this, &ChannelSelectionView::updateUserDefinedChannelsList);
144 }
145 
146 //=============================================================================================================
147 
148 void ChannelSelectionView::initComboBoxes()
149 {
150  m_pUi->m_comboBox_layoutFile->clear();
151  m_pUi->m_comboBox_layoutFile->insertItems(0, QStringList()
152  << "babymeg-mag-inner-layer.lout"
153  << "babymeg-mag-outer-layer.lout"
154 // << "babymeg-mag-ref.lout"
155  << "Vectorview-grad.lout"
156  << "Vectorview-all.lout"
157  << "Vectorview-mag.lout"
158  << "standard_waveguard64_duke.lout"
159 // << "CTF-275.lout"
160 // << "magnesWH3600.lout"
161  );
162 
163  connect(m_pUi->m_comboBox_layoutFile, &QComboBox::currentTextChanged,
164  this, &ChannelSelectionView::onComboBoxLayoutChanged);
165 
166  //Initialise layout as neuromag vectorview with all channels
167  QString selectionName("Vectorview-all.lout");
168  //loadLayout(QCoreApplication::applicationDirPath() + selectionName.prepend("/../resources/general/2DLayouts/"));
169  setCurrentLayoutFile(selectionName);
170 
171  //Load selection groups again because they need to be reinitialised every time a new layout hase been loaded
172  selectionName = QString("mne_browse_raw_vv.sel");
173  loadSelectionGroups(QCoreApplication::applicationDirPath() + selectionName.prepend("/../resources/general/selectionGroups/"));
174 }
175 
176 //=============================================================================================================
177 
178 void ChannelSelectionView::initButtons()
179 {
180  connect(m_pUi->m_pushButton_saveSelection, &QPushButton::clicked,
181  this, &ChannelSelectionView::onBtnSaveUserSelection);
182 
183  connect(m_pUi->m_pushButton_loadSelection, &QPushButton::clicked,
184  this, &ChannelSelectionView::onBtnLoadUserSelection);
185 
186  connect(m_pUi->m_pushButton_addToSelectionGroups, &QPushButton::clicked,
187  this, &ChannelSelectionView::onBtnAddToSelectionGroups);
188 }
189 
190 //=============================================================================================================
191 
192 void ChannelSelectionView::initCheckBoxes()
193 {
194  connect(m_pUi->m_checkBox_showBadChannelsAsRed, &QCheckBox::clicked,
196 }
197 
198 //=============================================================================================================
199 
200 void ChannelSelectionView::setCurrentlyMappedFiffChannels(const QStringList &mappedLayoutChNames)
201 {
202  m_currentlyLoadedFiffChannels = mappedLayoutChNames;
203 
204  //Clear the visible channel list
205  m_pUi->m_listWidget_visibleChannels->clear();
206 
207  //Keep the entry All in the selection list and m_selectionGroupsMap -> delete the rest
208  m_pUi->m_listWidget_selectionGroups->clear();
209 
210  //Create group 'All' manually (because this group depends on the loaded channels from the fiff data file, not on the loaded selection file)
211  auto it = m_selectionGroupsMap.find("All");
212  if (it != m_selectionGroupsMap.end()) {
213  m_selectionGroupsMap.erase(it);
214  }
215  m_selectionGroupsMap.insert("All", m_currentlyLoadedFiffChannels);
216 
217  //Add selection groups to list widget
218  for(auto i = m_selectionGroupsMap.constBegin(); i != m_selectionGroupsMap.constEnd(); i++) {
219  m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), i.key());
220  }
221 
222  //Set group all as slected item
223  m_pUi->m_listWidget_selectionGroups->setCurrentItem(getItemForChName(m_pUi->m_listWidget_selectionGroups, "All"), QItemSelectionModel::Select);
224 
225  //Update selection
226  updateSelectionGroupsList(getItemForChName(m_pUi->m_listWidget_selectionGroups, "All"), new QListWidgetItem());
227 }
228 
229 //=============================================================================================================
230 
231 void ChannelSelectionView::highlightChannels(QModelIndexList channelIndexList)
232 {
233  QStringList channelList;
234  for(int i = 0; i < channelIndexList.size(); i++) {
235  QModelIndex nameIndex = m_pChannelInfoModel->index(channelIndexList.at(i).row(),3);
236  channelList<<m_pChannelInfoModel->data(nameIndex, ChannelInfoModelRoles::GetMappedLayoutChName).toString();
237  }
238 
239  QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
240 
241  for(int i = 0; i < allSceneItems.size(); i++) {
242  SelectionSceneItem* item = static_cast<SelectionSceneItem*>(allSceneItems.at(i));
243  if(channelList.contains(item->m_sChannelName))
244  item->m_bHighlightItem = true;
245  else
246  item->m_bHighlightItem = false;
247  }
248 
249  m_pSelectionScene->update();
250 }
251 
252 //=============================================================================================================
253 
254 void ChannelSelectionView::selectChannels(QStringList channelList)
255 {
256  QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
257 
258  for(int i = 0; i < allSceneItems.size(); i++) {
259  SelectionSceneItem* item = static_cast<SelectionSceneItem*>(allSceneItems.at(i));
260  if(channelList.contains(item->m_sChannelName))
261  item->setSelected(true);
262  else
263  item->setSelected(false);
264  }
265 
266  m_pSelectionScene->update();
267 }
268 
269 //=============================================================================================================
270 
272 {
273  //if no channels have been selected by the user -> show selected group channels
274  QListWidget* targetListWidget;
275  if(m_pUi->m_listWidget_userDefined->count()>0)
276  targetListWidget = m_pUi->m_listWidget_userDefined;
277  else
278  targetListWidget = m_pUi->m_listWidget_visibleChannels;
279 
280  //Create list of channels which are to be visible in the view
281  QStringList selectedChannels;
282 
283  for(int i = 0; i < targetListWidget->count(); i++) {
284  QListWidgetItem* item = targetListWidget->item(i);
285  selectedChannels << item->text();
286  }
287 
288  return selectedChannels;
289 }
290 
291 //=============================================================================================================
292 
293 QListWidgetItem* ChannelSelectionView::getItemForChName(QListWidget* listWidget,
294  const QString &channelName)
295 {
296  for(int i=0; i < listWidget->count(); i++)
297  if(listWidget->item(i)->text() == channelName)
298  return listWidget->item(i);
299 
300  return new QListWidgetItem();
301 }
302 
303 //=============================================================================================================
304 
305 const QMap<QString,QPointF>& ChannelSelectionView::getLayoutMap()
306 {
307  return m_layoutMap;
308 }
309 
310 //=============================================================================================================
311 
312 void ChannelSelectionView::newFiffFileLoaded(QSharedPointer<FiffInfo> &pFiffInfo)
313 {
314  Q_UNUSED(pFiffInfo);
315 
316  loadLayout(m_pUi->m_comboBox_layoutFile->currentText());
317 }
318 
319 //=============================================================================================================
320 
322 {
323  return m_pUi->m_comboBox_layoutFile->currentText();
324 }
325 
326 //=============================================================================================================
327 
329 {
330  return m_pUi->m_lineEdit_loadedFile->text();
331 }
332 
333 //=============================================================================================================
334 
335 void ChannelSelectionView::setCurrentLayoutFile(QString currentLayoutFile)
336 {
337  qDebug() << "setCurrentLayoutFile:" << currentLayoutFile;
338  m_pUi->m_comboBox_layoutFile->setCurrentText(currentLayoutFile);
339 
341 }
342 
343 //=============================================================================================================
344 
346 {
347  QStringList badChannelMappedNames;
348  QStringList badChannelList = m_pChannelInfoModel->getBadChannelList();
349 
350  if(m_pUi->m_checkBox_showBadChannelsAsRed->isChecked()) {
351  for(int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
352  QModelIndex digIndex = m_pChannelInfoModel->index(i,3);
353  QString mappedChName = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetMappedLayoutChName).toString();
354 
355  digIndex = m_pChannelInfoModel->index(i,1);
356  QString origChName = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetOrigChName).toString();
357 
358  if(badChannelList.contains(origChName)) {
359  badChannelMappedNames << mappedChName;
360  }
361  }
362  }
363 
364  m_pSelectionScene->repaintItems(m_layoutMap, badChannelMappedNames);
365  m_pSelectionScene->update();
366 
367  updateSceneItems();
368  updateDataView();
369 }
370 
371 //=============================================================================================================
372 
374 {
375  //if no channels have been selected by the user -> show selected group channels
376  QListWidget* targetListWidget;
377  if(m_pUi->m_listWidget_userDefined->count()>0)
378  targetListWidget = m_pUi->m_listWidget_userDefined;
379  else
380  targetListWidget = m_pUi->m_listWidget_visibleChannels;
381 
382  //Create list of channels which are to be visible in the view
383  QStringList selectedChannels;
384 
385  for(int i = 0; i < targetListWidget->count(); i++) {
386  QListWidgetItem* item = targetListWidget->item(i);
387  int indexTemp = m_pChannelInfoModel->getIndexFromMappedChName(item->text());
388 
389  if(indexTemp != -1) {
390  QModelIndex mappedNameIndex = m_pChannelInfoModel->index(indexTemp,1);
391  QString origChName = m_pChannelInfoModel->data(mappedNameIndex,ChannelInfoModelRoles::GetOrigChName).toString();
392 
393  selectedChannels << origChName;
394  }
395  else
396  selectedChannels << item->text();
397  }
398 
399  emit showSelectedChannelsOnly(selectedChannels);
400 
401  //emit signal that selection was changed
402  if(!m_pSelectionScene->selectedItems().empty()) {
403  emit selectionChanged(m_pSelectionScene->selectedItems());
404  } else {
405  //only return visible items (EEG or MEG channels)
406  QList<QGraphicsItem*> visibleItemList = m_pSelectionScene->items();
407  QMutableListIterator<QGraphicsItem*> i(visibleItemList);
408  while (i.hasNext()) {
409  if(!i.next()->isVisible()){
410  i.remove();
411  }
412  }
413  emit selectionChanged(visibleItemList);
414  }
415 }
416 
417 //=============================================================================================================
418 
420 {
421  if(m_sSettingsPath.isEmpty()) {
422  return;
423  }
424 
425  QSettings settings("MNECPP");
426 
427  std::cout << "saveSettings: " << getCurrentLayoutFile().toStdString();
428 
429  settings.setValue(m_sSettingsPath + QString("/ChannelSelectionView/selectedLayoutFile"), getCurrentLayoutFile());
430  settings.setValue(m_sSettingsPath + QString("/ChannelSelectionView/channelSelectionViewPos"), this->pos());
431  settings.setValue(m_sSettingsPath + QString("/ChannelSelectionView/selectedGroupFile"), getCurrentGroupFile());
432 }
433 
434 //=============================================================================================================
435 
437 {
438  if(m_sSettingsPath.isEmpty()) {
439  return;
440  }
441 
442  QSettings settings("MNECPP");
443 
444  setCurrentLayoutFile(settings.value(m_sSettingsPath + QString("/ChannelSelectionView/selectedLayoutFile"), "Vectorview-all.lout").toString());
445  loadSelectionGroups(QCoreApplication::applicationDirPath() + settings.value(m_sSettingsPath + QString("/ChannelSelectionView/selectedGroupFile"), "mne_browse_raw_vv.sel").toString().prepend("/../resources/general/selectionGroups/"));
446 
447  qDebug() << "loadSettings: " << getCurrentLayoutFile();
448 
449  QPoint pos = settings.value(m_sSettingsPath + QString("/ChannelSelectionView/channelSelectionViewPos"), QPoint(100,100)).toPoint();
450 
451  QList<QScreen*> screensList = QGuiApplication::screens();
452  if(screensList.isEmpty())
453  {
454  move(QPoint(100,100));
455  } else {
456  move(pos);
457  }
458 }
459 
460 //=============================================================================================================
461 
463 {
464  switch(mode) {
465  case GuiMode::Clinical:
466  break;
467  default: // default is research mode
468  break;
469  }
470 }
471 
472 //=============================================================================================================
473 
475 {
476  switch(mode) {
477  case ProcessingMode::Offline:
478  break;
479  default: // default is realtime mode
480  break;
481  }
482 }
483 
484 //=============================================================================================================
485 
486 bool ChannelSelectionView::loadLayout(QString path)
487 {
488  qDebug() << "loadLayout:" << path;
489  bool state = LayoutLoader::readMNELoutFile(path, m_layoutMap);
490 
491  //if no layout for EEG is specified generate from digitizer points
492  QList<QVector<float> > inputPoints;
493  QList<QVector<float> > outputPoints;
494  QStringList names;
495  QFile out("manualLayout.lout");
496 
497  for(int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
498  QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
499  QString chName = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetOrigChName).toString();
500 
501  digIndex = m_pChannelInfoModel->index(i,8);
502  QVector3D channelDig = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetChDigitizer).value<QVector3D>();
503 
504  digIndex = m_pChannelInfoModel->index(i,4);
505  int kind = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetChKind).toInt();
506 
507  if(kind == FIFFV_EEG_CH) { //FIFFV_MEG_CH
508  QVector<float> temp;
509  temp.append(channelDig.x());
510  temp.append(channelDig.y());
511  temp.append(-channelDig.z());
512  inputPoints.append(temp);
513 
514  names<<chName;
515  }
516  }
517 
518  float prad = 60.0;
519  float width = 5.0;
520  float height = 4.0;
521  int numberTries = 0;
522 
523  if(inputPoints.size() > 0) {
524  while(numberTries < 10) {
525  if(!LayoutMaker::makeLayout(inputPoints,
526  outputPoints,
527  names,
528  out,
529  true,
530  prad,
531  width,
532  height,
533  false,
534  true,
535  false)) {
536  numberTries++;
537  } else {
538  numberTries = 11;
539  }
540  }
541  }
542 
543  //Add new EEG points to Layout Map
544  for(int i = 0; i < outputPoints.size(); i++) {
545  if(!m_layoutMap.contains(names.at(i))) {
546  m_layoutMap[names.at(i)] = QPointF(outputPoints.at(i)[0],outputPoints.at(i)[1]);
547  }
548  }
549 
550  QStringList bad;
551  m_pSelectionScene->repaintItems(m_layoutMap, bad);
552  m_pSelectionScene->update();
553  updateSceneItems();
554 
555  //Fit to view
556  m_pUi->m_graphicsView_layoutPlot->fitInView(m_pSelectionScene->itemsBoundingRect(), Qt::KeepAspectRatio);
557 
558  if(state)
559  emit loadedLayoutMap(m_layoutMap);
560 
561  if(m_bSetup){
562  saveSettings();
563  }
564 
565  return state;
566 }
567 
568 //=============================================================================================================
569 
570 bool ChannelSelectionView::loadSelectionGroups(QString path)
571 {
572 
573  //Clear the visible channel list
574  m_pUi->m_listWidget_visibleChannels->clear();
575 
576  //Keep the entry All in the selection list and m_selectionGroupsMap -> delete the rest
577  m_pUi->m_listWidget_selectionGroups->clear();
578 
579  //Read selection from file and store to map
580  QString newPath = path; //QCoreApplication::applicationDirPath() + path.prepend("/../resources/general/selectionGroups/");
581 
582  m_selectionGroupsMap.clear();
583 
584  bool state;
585  if(!path.isEmpty()) {
586  if(path.contains(".sel"))
587  state = SelectionIO::readMNESelFile(newPath, m_selectionGroupsMap);
588  if(path.contains(".mon"))
589  state = SelectionIO::readBrainstormMonFile(newPath, m_selectionGroupsMap);
590  }
591 
592  //Create group 'All' and 'All EEG' manually (bcause this group depends on the loaded channels from the Info data file, not on the loaded selection file)
593  auto it = m_selectionGroupsMap.find("All");
594  if (it != m_selectionGroupsMap.end()) {
595  m_selectionGroupsMap.erase(it);
596  }
597  m_selectionGroupsMap.insert("All", m_currentlyLoadedFiffChannels);
598 
599  QStringList names;
600  for(int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
601  QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
602  QString chName = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetOrigChName).toString();
603 
604  digIndex = m_pChannelInfoModel->index(i,4);
605  int kind = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetChKind).toInt();
606 
607  if(kind == FIFFV_EEG_CH) //FIFFV_MEG_CH
608  names<<chName;
609  }
610 
611  //Add 'Add EEG' group to selection groups
612  it = m_selectionGroupsMap.find("All EEG");
613  if (it != m_selectionGroupsMap.end()) {
614  m_selectionGroupsMap.erase(it);
615  }
616  m_selectionGroupsMap.insert("All EEG", names);
617 
618  //Add selection groups to list widget
619 
620  for(auto i = m_selectionGroupsMap.constBegin(); i != m_selectionGroupsMap.constEnd(); i++) {
621  m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), i.key());
622  }
623 
624  //Update selection
625  updateSelectionGroupsList(getItemForChName(m_pUi->m_listWidget_selectionGroups, "All"), new QListWidgetItem());
626 
627  //Set group all as slected item
628  m_pUi->m_listWidget_selectionGroups->setCurrentItem(getItemForChName(m_pUi->m_listWidget_selectionGroups, "All"), QItemSelectionModel::Select);
629 
630  //Delete all MEG channels from the selection groups which are not in the loaded layout
631  //TODO: Is this needed anymore? Causes some trouble after a new selection file has been loaded
632  //cleanUpMEGChannels();
633 
634  m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
635 
636  if(m_bSetup){
637  saveSettings();
638  }
639 
640  return state;
641 }
642 
643 //=============================================================================================================
644 
645 void ChannelSelectionView::cleanUpMEGChannels()
646 {
647  //Iterate through all loaded selection groups
648  for(auto i = m_selectionGroupsMap.constBegin(); i != m_selectionGroupsMap.constEnd(); i++) {
649  QStringList channelList = i.value();
650 
651  //Search the current selection group for MEG channels which are not in the currently loaded layout file and delete them
652  QMutableStringListIterator stringListIndex(channelList);
653  while (stringListIndex.hasNext()) {
654  stringListIndex.next();
655 
656  if(!m_layoutMap.contains(stringListIndex.value()) && stringListIndex.value().contains("MEG"))
657  stringListIndex.remove();
658  }
659 
660  //Overwrite old selection groups channels
661  m_selectionGroupsMap.insert(i.key(), channelList);
662  }
663 }
664 
665 //=============================================================================================================
666 
667 void ChannelSelectionView::updateSelectionGroupsList(QListWidgetItem* current, QListWidgetItem* previous)
668 {
669  Q_UNUSED(previous);
670 
671  if(current == 0){
672  return;
673  }
674  if(current->text().contains("EEG"))
675  m_pSelectionScene->m_iChannelTypeMode = FIFFV_EEG_CH;
676  else
677  m_pSelectionScene->m_iChannelTypeMode = FIFFV_MEG_CH;
678 
679  //update visible channel list widget
680  m_pUi->m_listWidget_visibleChannels->clear();
681  auto items = m_selectionGroupsMap.find(current->text());
682  m_pUi->m_listWidget_visibleChannels->addItems(*items);
683 
684  //update scene items based o nthe new selection group
685  updateSceneItems();
686 
687  //update the channels plotted in the data view
688  updateDataView();
689 
691 }
692 
693 //=============================================================================================================
694 
695 void ChannelSelectionView::updateSceneItems()
696 {
697  QStringList visibleItems;
698 
699  for(int i = 0; i < m_pUi->m_listWidget_visibleChannels->count(); i++)
700  visibleItems << m_pUi->m_listWidget_visibleChannels->item(i)->text();
701 
702  m_pSelectionScene->hideItems(visibleItems);
703 }
704 
705 //=============================================================================================================
706 
707 void ChannelSelectionView::updateUserDefinedChannelsList()
708 {
709  QList<QGraphicsItem*> itemList = m_pSelectionScene->selectedItems();
710  QStringList userDefinedChannels;
711 
712  for(int i = 0; i < itemList.size(); i++) {
713  SelectionSceneItem* item = static_cast<SelectionSceneItem*>(itemList.at(i));
714  userDefinedChannels << item->m_sChannelName;
715  }
716 
717  m_pUi->m_listWidget_userDefined->clear();
718  m_pUi->m_listWidget_userDefined->addItems(userDefinedChannels);
719 
720  updateDataView();
721 }
722 
723 //=============================================================================================================
724 
725 void ChannelSelectionView::onBtnLoadUserSelection()
726 {
727  QString path = QFileDialog::getOpenFileName(this,
728  QString("Open selection file"),
729  QString("../resources/general/selectionGroups/"),
730  tr("Selection files (*.sel *.mon)"));
731 
732  if(path.isEmpty())
733  return;
734 
735  loadSelectionGroups(path);
736  m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
737 }
738 
739 //=============================================================================================================
740 
741 void ChannelSelectionView::onBtnSaveUserSelection()
742 {
743  QDate date;
744  QString path = QFileDialog::getSaveFileName(this,
745  "Save user channel selection",
746  QString("../resources/general/selectionGroups/%1_%2_%3_UserSelection").arg(date.currentDate().year()).arg(date.currentDate().month()).arg(date.currentDate().day()),
747  tr("MNE selection file(*.sel);; Brainstorm montage file(*.mon)"));
748 
749  QMultiMap<QString, QStringList> tempMap = m_selectionGroupsMap;
750  tempMap.remove("All");
751  tempMap.remove("All EEG");
752 
753  if(!path.isEmpty()) {
754  if(path.contains(".sel"))
755  SelectionIO::writeMNESelFile(path, tempMap);
756  if(path.contains(".mon"))
757  SelectionIO::writeBrainstormMonFiles(path, tempMap);
758  }
759 }
760 
761 //=============================================================================================================
762 
763 void ChannelSelectionView::onBtnAddToSelectionGroups()
764 {
765  QStringList temp;
766  for(int i = 0; i < m_pUi->m_listWidget_userDefined->count(); i++)
767  temp<<m_pUi->m_listWidget_userDefined->item(i)->text();
768 
769  m_selectionGroupsMap.insert(m_pUi->m_lineEdit_selectionGroupName->text(), temp);
770  m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), m_pUi->m_lineEdit_selectionGroupName->text());
771 }
772 
773 //=============================================================================================================
774 
775 void ChannelSelectionView::onComboBoxLayoutChanged()
776 {
777  QString selectionName(m_pUi->m_comboBox_layoutFile->currentText());
778  loadLayout(QCoreApplication::applicationDirPath() + selectionName.prepend("/../resources/general/2DLayouts/"));
780 }
781 
782 //=============================================================================================================
783 
784 void ChannelSelectionView::resizeEvent(QResizeEvent* event)
785 {
786  Q_UNUSED(event);
787 
788  //Fit scene in view
789  //m_pUi->m_graphicsView_layoutPlot->fitInView(m_pSelectionScene->itemsBoundingRect(), Qt::KeepAspectRatio);
790 }
791 
792 //=============================================================================================================
793 
794 bool ChannelSelectionView::eventFilter(QObject *obj, QEvent *event)
795 {
796  //Setup delete key on user defined channel list
797  if (obj == m_pUi->m_listWidget_userDefined && event->type() == QEvent::KeyRelease) {
798  QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
799 
800  if(keyEvent->key() == Qt::Key_Delete) {
801  qDeleteAll(m_pUi->m_listWidget_userDefined->selectedItems());
802  updateDataView();
803  return true;
804  }
805  else
806  return false;
807  }
808 
809  if (obj == m_pUi->m_listWidget_selectionGroups && event->type() == QEvent::KeyRelease) {
810  QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
811 
812  if(keyEvent->key() == Qt::Key_Delete) {
813  QList<QListWidgetItem *> tempSelectedList;
814 
815  for(int i = 0; i < m_pUi->m_listWidget_selectionGroups->selectedItems().size(); i++) {
816  if(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text() != "All" &&
817  m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text() != "All EEG") {
818  tempSelectedList.append(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i));
819  m_selectionGroupsMap.remove(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text());
820  }
821  }
822 
823  qDeleteAll(tempSelectedList);
824  updateDataView();
825 
826  return true;
827  }
828  else
829  return false;
830  }
831 
832  // pass the event on to the parent class
833  return QWidget::eventFilter(obj, event);
834 }
835 
836 //=============================================================================================================
837 
839 {
840  return m_pUi->viewWidget;
841 }
842 
843 //=============================================================================================================
844 
846 {
847  return m_pUi->controlWidget;
848 }
849 
850 //=============================================================================================================
851 
853 {
854  return ((m_pUi->m_listWidget_selectionGroups->currentItem()->text() == "All") && (m_pUi->m_listWidget_userDefined->count() == 0));
855 }
856 
857 //=============================================================================================================
858 
860 {
861  m_pSelectionScene->clear();
862 }
DISPLIB::ChannelSelectionView::selectionChanged
void selectionChanged(const QList< QGraphicsItem * > &selectedChannelItems)
DISPLIB::ChannelSelectionView::saveSettings
void saveSettings()
Definition: channelselectionview.cpp:419
DISPLIB::AbstractView
The AbstractView class provides the base calss for all Disp viewers.
Definition: abstractview.h:75
layoutloader.h
LayoutLoader class declaration.
DISPLIB::ChannelSelectionView::updateBadChannels
void updateBadChannels()
Definition: channelselectionview.cpp:345
DISPLIB::ChannelSelectionView::isSelectionEmpty
bool isSelectionEmpty()
Definition: channelselectionview.cpp:852
DISPLIB::ChannelSelectionView::highlightChannels
void highlightChannels(QModelIndexList channelIndexList)
Definition: channelselectionview.cpp:231
DISPLIB::ChannelSelectionView::updateGuiMode
void updateGuiMode(GuiMode mode)
Definition: channelselectionview.cpp:462
DISPLIB::ChannelSelectionView::updateDataView
void updateDataView()
Definition: channelselectionview.cpp:373
fiff.h
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...
DISPLIB::SelectionScene::repaintItems
void repaintItems(const QMap< QString, QPointF > &layoutMap, QStringList badChannels)
Definition: selectionscene.cpp:75
DISPLIB::ChannelSelectionView::updateProcessingMode
void updateProcessingMode(ProcessingMode mode)
Definition: channelselectionview.cpp:474
selectionsceneitem.h
Contains the declaration of the SelectionSceneItem class.
DISPLIB::ChannelSelectionView::setCurrentLayoutFile
void setCurrentLayoutFile(QString currentLayoutFile)
Definition: channelselectionview.cpp:335
layoutmaker.h
LayoutLoader class declaration.
DISPLIB::SelectionScene::hideItems
void hideItems(QStringList visibleItems)
Definition: selectionscene.cpp:107
DISPLIB::ChannelSelectionView::getLayoutMap
const QMap< QString, QPointF > & getLayoutMap()
Definition: channelselectionview.cpp:305
DISPLIB::ChannelSelectionView::newFiffFileLoaded
void newFiffFileLoaded(QSharedPointer< FIFFLIB::FiffInfo > &pFiffInfo)
Definition: channelselectionview.cpp:312
DISPLIB::ChannelSelectionView::ChannelSelectionView
ChannelSelectionView(const QString &sSettingsPath="", QWidget *parent=0, QSharedPointer< ChannelInfoModel > pChannelInfoModel=QSharedPointer< ChannelInfoModel >(0), Qt::WindowType f=Qt::Widget)
Definition: channelselectionview.cpp:81
DISPLIB::ChannelSelectionView::getSelectedChannels
QStringList getSelectedChannels()
Definition: channelselectionview.cpp:271
DISPLIB::ChannelSelectionView::getControlWidget
QWidget * getControlWidget()
Definition: channelselectionview.cpp:845
DISPLIB::ChannelSelectionView::clearView
void clearView()
Definition: channelselectionview.cpp:859
DISPLIB::SelectionSceneItem
Definition: selectionsceneitem.h:87
DISPLIB::ChannelSelectionView::showSelectedChannelsOnly
void showSelectedChannelsOnly(QStringList selectedChannels)
DISPLIB::SelectionSceneItem::m_bHighlightItem
bool m_bHighlightItem
Definition: selectionsceneitem.h:124
DISPLIB::SelectionScene
The SelectionScene class provides a reimplemented QGraphicsScene for 2D layout plotting.
Definition: selectionscene.h:75
DISPLIB::ChannelSelectionView::getItemForChName
QListWidgetItem * getItemForChName(QListWidget *listWidget, const QString &channelName)
Definition: channelselectionview.cpp:293
DISPLIB::ChannelSelectionView::loadedLayoutMap
void loadedLayoutMap(const QMap< QString, QPointF > &layoutMap)
DISPLIB::SelectionSceneItem::m_sChannelName
QString m_sChannelName
Definition: selectionsceneitem.h:118
channelselectionview.h
Contains the declaration of the ChannelSelectionView class.
channelinfomodel.h
The declaration for ChannelInfoModel..
DISPLIB::ChannelSelectionView::getCurrentGroupFile
QString getCurrentGroupFile()
Definition: channelselectionview.cpp:328
selectionscene.h
Contains the declaration of the SelectionScene class.
DISPLIB::ChannelSelectionView::getViewWidget
QWidget * getViewWidget()
Definition: channelselectionview.cpp:838
selectionio.h
SelectionIO class declaration.
DISPLIB::SelectionScene::m_iChannelTypeMode
int m_iChannelTypeMode
Definition: selectionscene.h:107
DISPLIB::ChannelSelectionView::~ChannelSelectionView
~ChannelSelectionView()
Definition: channelselectionview.cpp:109
DISPLIB::ChannelInfoModel::SPtr
QSharedPointer< ChannelInfoModel > SPtr
Definition: channelinfomodel.h:105
DISPLIB::ChannelSelectionView::loadSettings
void loadSettings()
Definition: channelselectionview.cpp:436
DISPLIB::ChannelSelectionView::getCurrentLayoutFile
QString getCurrentLayoutFile()
Definition: channelselectionview.cpp:321
DISPLIB::ChannelSelectionView::selectChannels
void selectChannels(QStringList channelList)
Definition: channelselectionview.cpp:254
DISPLIB::ChannelSelectionView::setCurrentlyMappedFiffChannels
void setCurrentlyMappedFiffChannels(const QStringList &mappedLayoutChNames)
Definition: channelselectionview.cpp:200