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