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 <QGraphicsItem>
62 #include <QSettings>
63 #include <QApplication>
64 #include <QDesktopWidget>
65 #include <QKeyEvent>
66 
67 //=============================================================================================================
68 // EIGEN INCLUDES
69 //=============================================================================================================
70 
71 //=============================================================================================================
72 // USED NAMESPACES
73 //=============================================================================================================
74 
75 using namespace DISPLIB;
76 using namespace FIFFLIB;
77 using namespace UTILSLIB;
78 
79 //=============================================================================================================
80 // DEFINE MEMBER METHODS
81 //=============================================================================================================
82 
83 ChannelSelectionView::ChannelSelectionView(const QString& sSettingsPath,
84  QWidget *parent,
85  ChannelInfoModel::SPtr pChannelInfoModel,
86  Qt::WindowType f)
87 : AbstractView(parent, f)
88 , m_pUi(new Ui::ChannelSelectionViewWidget)
89 , m_pChannelInfoModel(pChannelInfoModel)
90 , m_bSetup(false)
91 {
92  m_sSettingsPath = sSettingsPath;
93  m_pUi->setupUi(this);
94 
95  //Init gui elements
96  initListWidgets();
97  initSelectionSceneView();
98  initComboBoxes();
99  initButtons();
100  initCheckBoxes();
101 
102  loadSettings();
103 
104  m_bSetup = true;
105 
106  setCurrentlyMappedFiffChannels(m_pChannelInfoModel->getMappedChannelsList());
107 }
108 
109 //=============================================================================================================
110 
112 {
113 // saveSettings();
114 
115  delete m_pUi;
116 }
117 
118 //=============================================================================================================
119 
120 void ChannelSelectionView::initListWidgets()
121 {
122  //Install event filter to receive key press events
123  m_pUi->m_listWidget_userDefined->installEventFilter(this);
124  m_pUi->m_listWidget_selectionGroups->installEventFilter(this);
125 
126  //Connect list widgets to update themselves and other list widgets when changed
127  connect(m_pUi->m_listWidget_selectionGroups, &QListWidget::currentItemChanged,
128  this, &ChannelSelectionView::updateSelectionGroupsList);
129 
130  //Update data view whenever a drag and drop item movement is performed
131  //TODO: This is inefficient because updateDataView is called everytime the list's viewport is entered
132  connect(m_pUi->m_listWidget_userDefined->model(), &QAbstractTableModel::dataChanged,
134 }
135 
136 //=============================================================================================================
137 
138 void ChannelSelectionView::initSelectionSceneView()
139 {
140  //Create layout scene and set to view
141  m_pSelectionScene = new SelectionScene(m_pUi->m_graphicsView_layoutPlot);
142  m_pUi->m_graphicsView_layoutPlot->setScene(m_pSelectionScene);
143 
144  connect(m_pSelectionScene, &QGraphicsScene::selectionChanged,
145  this, &ChannelSelectionView::updateUserDefinedChannelsList);
146 }
147 
148 //=============================================================================================================
149 
150 void ChannelSelectionView::initComboBoxes()
151 {
152  m_pUi->m_comboBox_layoutFile->clear();
153  m_pUi->m_comboBox_layoutFile->insertItems(0, QStringList()
154  << "babymeg-mag-inner-layer.lout"
155  << "babymeg-mag-outer-layer.lout"
156 // << "babymeg-mag-ref.lout"
157  << "Vectorview-grad.lout"
158  << "Vectorview-all.lout"
159  << "Vectorview-mag.lout"
160  << "standard_waveguard64_duke.lout"
161 // << "CTF-275.lout"
162 // << "magnesWH3600.lout"
163  );
164 
165  connect(m_pUi->m_comboBox_layoutFile, &QComboBox::currentTextChanged,
166  this, &ChannelSelectionView::onComboBoxLayoutChanged);
167 
168  //Initialise layout as neuromag vectorview with all channels
169  QString selectionName("Vectorview-all.lout");
170  //loadLayout(QCoreApplication::applicationDirPath() + selectionName.prepend("/resources/general/2DLayouts/"));
171  setCurrentLayoutFile(selectionName);
172 
173  //Load selection groups again because they need to be reinitialised every time a new layout hase been loaded
174  selectionName = QString("mne_browse_raw_vv.sel");
175  loadSelectionGroups(QCoreApplication::applicationDirPath() + selectionName.prepend("/resources/general/selectionGroups/"));
176 }
177 
178 //=============================================================================================================
179 
180 void ChannelSelectionView::initButtons()
181 {
182  connect(m_pUi->m_pushButton_saveSelection, &QPushButton::clicked,
183  this, &ChannelSelectionView::onBtnSaveUserSelection);
184 
185  connect(m_pUi->m_pushButton_loadSelection, &QPushButton::clicked,
186  this, &ChannelSelectionView::onBtnLoadUserSelection);
187 
188  connect(m_pUi->m_pushButton_addToSelectionGroups, &QPushButton::clicked,
189  this, &ChannelSelectionView::onBtnAddToSelectionGroups);
190 }
191 
192 //=============================================================================================================
193 
194 void ChannelSelectionView::initCheckBoxes()
195 {
196  connect(m_pUi->m_checkBox_showBadChannelsAsRed, &QCheckBox::clicked,
198 }
199 
200 //=============================================================================================================
201 
202 void ChannelSelectionView::setCurrentlyMappedFiffChannels(const QStringList &mappedLayoutChNames)
203 {
204  m_currentlyLoadedFiffChannels = mappedLayoutChNames;
205 
206  //Clear the visible channel list
207  m_pUi->m_listWidget_visibleChannels->clear();
208 
209  //Keep the entry All in the selection list and m_selectionGroupsMap -> delete the rest
210  m_pUi->m_listWidget_selectionGroups->clear();
211 
212  //Create group 'All' manually (because this group depends on the loaded channels from the fiff data file, not on the loaded selection file)
213  m_selectionGroupsMap["All"] = m_currentlyLoadedFiffChannels;
214 
215  //Add selection groups to list widget
216  QMapIterator<QString, QStringList> selectionIndex(m_selectionGroupsMap);
217  while (selectionIndex.hasNext()) {
218  selectionIndex.next();
219  m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), selectionIndex.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  m_selectionGroupsMap["All"] = m_currentlyLoadedFiffChannels;
594 
595  QStringList names;
596  for(int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
597  QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
598  QString chName = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetOrigChName).toString();
599 
600  digIndex = m_pChannelInfoModel->index(i,4);
601  int kind = m_pChannelInfoModel->data(digIndex,ChannelInfoModelRoles::GetChKind).toInt();
602 
603  if(kind == FIFFV_EEG_CH) //FIFFV_MEG_CH
604  names<<chName;
605  }
606 
607  //Add 'Add EEG' group to selection groups
608  m_selectionGroupsMap["All EEG"] = names;
609 
610  //Add selection groups to list widget
611  QMapIterator<QString, QStringList> selectionIndex(m_selectionGroupsMap);
612  while (selectionIndex.hasNext()) {
613  selectionIndex.next();
614  m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), selectionIndex.key());
615  }
616 
617  //Update selection
618  updateSelectionGroupsList(getItemForChName(m_pUi->m_listWidget_selectionGroups, "All"), new QListWidgetItem());
619 
620  //Set group all as slected item
621  m_pUi->m_listWidget_selectionGroups->setCurrentItem(getItemForChName(m_pUi->m_listWidget_selectionGroups, "All"), QItemSelectionModel::Select);
622 
623  //Delete all MEG channels from the selection groups which are not in the loaded layout
624  //TODO: Is this needed anymore? Causes some trouble after a new selection file has been loaded
625  //cleanUpMEGChannels();
626 
627  m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
628 
629 
630  if(m_bSetup){
631  saveSettings();
632  }
633 
634  return state;
635 }
636 
637 //=============================================================================================================
638 
639 void ChannelSelectionView::cleanUpMEGChannels()
640 {
641  QMapIterator<QString,QStringList> selectionIndex(m_selectionGroupsMap);
642 
643  //Iterate through all loaded selection groups
644  while(selectionIndex.hasNext()) {
645  selectionIndex.next();
646 
647  QStringList channelList = selectionIndex.value();
648 
649  //Search the current selection group for MEG channels which are not in the currently loaded layout file and delete them
650  QMutableStringListIterator stringListIndex(channelList);
651  while (stringListIndex.hasNext()) {
652  stringListIndex.next();
653 
654  if(!m_layoutMap.contains(stringListIndex.value()) && stringListIndex.value().contains("MEG"))
655  stringListIndex.remove();
656  }
657 
658  //Overwrite old selection groups channels
659  m_selectionGroupsMap.insert(selectionIndex.key(), channelList);
660  }
661 }
662 
663 //=============================================================================================================
664 
665 void ChannelSelectionView::updateSelectionGroupsList(QListWidgetItem* current, QListWidgetItem* previous)
666 {
667  Q_UNUSED(previous);
668 
669  if(current == 0){
670  return;
671  }
672  if(current->text().contains("EEG"))
673  m_pSelectionScene->m_iChannelTypeMode = FIFFV_EEG_CH;
674  else
675  m_pSelectionScene->m_iChannelTypeMode = FIFFV_MEG_CH;
676 
677  //update visible channel list widget
678  m_pUi->m_listWidget_visibleChannels->clear();
679  m_pUi->m_listWidget_visibleChannels->addItems(m_selectionGroupsMap[current->text()]);
680 
681  //update scene items based o nthe new selection group
682  updateSceneItems();
683 
684  //update the channels plotted in the data view
685  updateDataView();
686 
688 }
689 
690 //=============================================================================================================
691 
692 void ChannelSelectionView::updateSceneItems()
693 {
694  QStringList visibleItems;
695 
696  for(int i = 0; i < m_pUi->m_listWidget_visibleChannels->count(); i++)
697  visibleItems << m_pUi->m_listWidget_visibleChannels->item(i)->text();
698 
699  m_pSelectionScene->hideItems(visibleItems);
700 }
701 
702 //=============================================================================================================
703 
704 void ChannelSelectionView::updateUserDefinedChannelsList()
705 {
706  QList<QGraphicsItem*> itemList = m_pSelectionScene->selectedItems();
707  QStringList userDefinedChannels;
708 
709  for(int i = 0; i < itemList.size(); i++) {
710  SelectionSceneItem* item = static_cast<SelectionSceneItem*>(itemList.at(i));
711  userDefinedChannels << item->m_sChannelName;
712  }
713 
714  m_pUi->m_listWidget_userDefined->clear();
715  m_pUi->m_listWidget_userDefined->addItems(userDefinedChannels);
716 
717  updateDataView();
718 }
719 
720 //=============================================================================================================
721 
722 void ChannelSelectionView::onBtnLoadUserSelection()
723 {
724  QString path = QFileDialog::getOpenFileName(this,
725  QString("Open selection file"),
726  QString("./general/resources/selectionGroups/"),
727  tr("Selection files (*.sel *.mon)"));
728 
729  if(path.isEmpty())
730  return;
731 
732  loadSelectionGroups(path);
733  m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
734 }
735 
736 //=============================================================================================================
737 
738 void ChannelSelectionView::onBtnSaveUserSelection()
739 {
740  QDate date;
741  QString path = QFileDialog::getSaveFileName(this,
742  "Save user channel selection",
743  QString("./general/resources/selectionGroups/%1_%2_%3_UserSelection").arg(date.currentDate().year()).arg(date.currentDate().month()).arg(date.currentDate().day()),
744  tr("MNE selection file(*.sel);; Brainstorm montage file(*.mon)"));
745 
746  QMap<QString, QStringList> tempMap = m_selectionGroupsMap;
747  tempMap.remove("All");
748  tempMap.remove("All EEG");
749 
750  if(!path.isEmpty()) {
751  if(path.contains(".sel"))
752  SelectionIO::writeMNESelFile(path, tempMap);
753  if(path.contains(".mon"))
754  SelectionIO::writeBrainstormMonFiles(path, tempMap);
755  }
756 }
757 
758 //=============================================================================================================
759 
760 void ChannelSelectionView::onBtnAddToSelectionGroups()
761 {
762  QStringList temp;
763  for(int i = 0; i < m_pUi->m_listWidget_userDefined->count(); i++)
764  temp<<m_pUi->m_listWidget_userDefined->item(i)->text();
765 
766  m_selectionGroupsMap.insertMulti(m_pUi->m_lineEdit_selectionGroupName->text(), temp);
767  m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), m_pUi->m_lineEdit_selectionGroupName->text());
768 }
769 
770 //=============================================================================================================
771 
772 void ChannelSelectionView::onComboBoxLayoutChanged()
773 {
774  QString selectionName(m_pUi->m_comboBox_layoutFile->currentText());
775  loadLayout(QCoreApplication::applicationDirPath() + selectionName.prepend("/resources/general/2DLayouts/"));
777 }
778 
779 //=============================================================================================================
780 
781 void ChannelSelectionView::resizeEvent(QResizeEvent* event)
782 {
783  Q_UNUSED(event);
784 
785  //Fit scene in view
786  //m_pUi->m_graphicsView_layoutPlot->fitInView(m_pSelectionScene->itemsBoundingRect(), Qt::KeepAspectRatio);
787 }
788 
789 //=============================================================================================================
790 
791 bool ChannelSelectionView::eventFilter(QObject *obj, QEvent *event)
792 {
793  //Setup delete key on user defined channel list
794  if (obj == m_pUi->m_listWidget_userDefined && event->type() == QEvent::KeyRelease) {
795  QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
796 
797  if(keyEvent->key() == Qt::Key_Delete) {
798  qDeleteAll(m_pUi->m_listWidget_userDefined->selectedItems());
799  updateDataView();
800  return true;
801  }
802  else
803  return false;
804  }
805 
806  if (obj == m_pUi->m_listWidget_selectionGroups && event->type() == QEvent::KeyRelease) {
807  QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
808 
809  if(keyEvent->key() == Qt::Key_Delete) {
810  QList<QListWidgetItem *> tempSelectedList;
811 
812  for(int i = 0; i < m_pUi->m_listWidget_selectionGroups->selectedItems().size(); i++) {
813  if(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text() != "All" &&
814  m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text() != "All EEG") {
815  tempSelectedList.append(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i));
816  m_selectionGroupsMap.remove(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text());
817  }
818  }
819 
820  qDeleteAll(tempSelectedList);
821  updateDataView();
822 
823  return true;
824  }
825  else
826  return false;
827  }
828 
829  // pass the event on to the parent class
830  return QWidget::eventFilter(obj, event);
831 }
832 
833 //=============================================================================================================
834 
836 {
837  return m_pUi->viewWidget;
838 }
839 
840 //=============================================================================================================
841 
843 {
844  return m_pUi->controlWidget;
845 }
846 
847 //=============================================================================================================
848 
850 {
851  return ((m_pUi->m_listWidget_selectionGroups->currentItem()->text() == "All") && (m_pUi->m_listWidget_userDefined->count() == 0));
852 }
853 
854 //=============================================================================================================
855 
857 {
858  m_pSelectionScene->clear();
859 }
QListWidgetItem * getItemForChName(QListWidget *listWidget, const QString &channelName)
LayoutLoader class declaration.
void loadedLayoutMap(const QMap< QString, QPointF > &layoutMap)
void selectionChanged(const QList< QGraphicsItem *> &selectedChannelItems)
LayoutLoader class declaration.
The declaration for ChannelInfoModel..
SelectionIO class declaration.
Definition: applytoview.h:58
QSharedPointer< ChannelInfoModel > SPtr
void highlightChannels(QModelIndexList channelIndexList)
The SelectionScene class provides a reimplemented QGraphicsScene for 2D layout plotting.
void setCurrentlyMappedFiffChannels(const QStringList &mappedLayoutChNames)
Contains the declaration of the SelectionSceneItem class.
void setCurrentLayoutFile(QString currentLayoutFile)
Contains the declaration of the ChannelSelectionView class.
void repaintItems(const QMap< QString, QPointF > &layoutMap, QStringList badChannels)
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...
void hideItems(QStringList visibleItems)
const QMap< QString, QPointF > & getLayoutMap()
void updateProcessingMode(ProcessingMode mode)
ChannelSelectionView(const QString &sSettingsPath="", QWidget *parent=0, QSharedPointer< ChannelInfoModel > pChannelInfoModel=QSharedPointer< ChannelInfoModel >(0), Qt::WindowType f=Qt::Widget)
void showSelectedChannelsOnly(QStringList selectedChannels)
void selectChannels(QStringList channelList)
The AbstractView class provides the base calss for all Disp viewers.
Definition: abstractview.h:75
void newFiffFileLoaded(QSharedPointer< FIFFLIB::FiffInfo > &pFiffInfo)
Contains the declaration of the SelectionScene class.