MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
channelselectionview.cpp
Go to the documentation of this file.
1//=============================================================================================================
37//=============================================================================================================
38// INCLUDES
39//=============================================================================================================
40
42#include "ui_channelselectionview.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
73using namespace DISPLIB;
74using namespace FIFFLIB;
75using namespace UTILSLIB;
76
77//=============================================================================================================
78// DEFINE MEMBER METHODS
79//=============================================================================================================
80
81ChannelSelectionView::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
118void 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
136void 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
148void 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
178void 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
192void ChannelSelectionView::initCheckBoxes()
193{
194 connect(m_pUi->m_checkBox_showBadChannelsAsRed, &QCheckBox::clicked,
196}
197
198//=============================================================================================================
199
200void 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
231void 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
254void 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
293QListWidgetItem* 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
305const QMap<QString,QPointF>& ChannelSelectionView::getLayoutMap()
306{
307 return m_layoutMap;
308}
309
310//=============================================================================================================
311
312void 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
335void 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();
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
486bool 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
570bool 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
645void 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
667void 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
689
691}
692
693//=============================================================================================================
694
695void 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
707void 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
721}
722
723//=============================================================================================================
724
725void 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
741void 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"))
758 }
759}
760
761//=============================================================================================================
762
763void 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
775void 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
784void 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
794bool 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());
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);
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}
Contains the declaration of the ChannelSelectionView class.
Contains the declaration of the SelectionScene class.
The declaration for ChannelInfoModel..
Contains the declaration of the SelectionSceneItem class.
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...
SelectionIO class declaration.
LayoutLoader class declaration.
LayoutLoader class declaration.
The AbstractView class provides the base calss for all Disp viewers.
void selectionChanged(const QList< QGraphicsItem * > &selectedChannelItems)
QListWidgetItem * getItemForChName(QListWidget *listWidget, const QString &channelName)
const QMap< QString, QPointF > & getLayoutMap()
void showSelectedChannelsOnly(QStringList selectedChannels)
void updateProcessingMode(ProcessingMode mode)
ChannelSelectionView(const QString &sSettingsPath="", QWidget *parent=0, QSharedPointer< ChannelInfoModel > pChannelInfoModel=QSharedPointer< ChannelInfoModel >(0), Qt::WindowType f=Qt::Widget)
void highlightChannels(QModelIndexList channelIndexList)
void newFiffFileLoaded(QSharedPointer< FIFFLIB::FiffInfo > &pFiffInfo)
void selectChannels(QStringList channelList)
void setCurrentlyMappedFiffChannels(const QStringList &mappedLayoutChNames)
void loadedLayoutMap(const QMap< QString, QPointF > &layoutMap)
void setCurrentLayoutFile(QString currentLayoutFile)
QSharedPointer< ChannelInfoModel > SPtr
The SelectionScene class provides a reimplemented QGraphicsScene for 2D layout plotting.
void repaintItems(const QMap< QString, QPointF > &layoutMap, QStringList badChannels)
void hideItems(QStringList visibleItems)
static bool readMNELoutFile(const QString &path, QMap< QString, QPointF > &channelData)
static bool makeLayout(const QList< QVector< float > > &inputPoints, QList< QVector< float > > &outputPoints, const QStringList &names, QFile &outFile, bool do_fit, float prad, float w, float h, bool writeFile=false, bool mirrorXAxis=false, bool mirrorYAxis=false)
static bool readBrainstormMonFile(QString path, QMultiMap< QString, QStringList > &selectionMap)
static bool writeBrainstormMonFiles(QString path, const QMultiMap< QString, QStringList > &selectionMap)
static bool readMNESelFile(QString path, QMultiMap< QString, QStringList > &selectionMap)
static bool writeMNESelFile(QString path, const QMultiMap< QString, QStringList > &selectionMap)