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