22#include "ui_channelselectionview.h"
47#include <QListWidgetItem>
49#include <QApplication>
51#include <QSignalBlocker>
74, m_pUi(new Ui::ChannelSelectionViewWidget)
75, m_pChannelInfoModel(pChannelInfoModel)
78 m_sSettingsPath = sSettingsPath;
83 initSelectionSceneView();
106void ChannelSelectionView::initListWidgets()
109 m_pUi->m_listWidget_userDefined->installEventFilter(
this);
110 m_pUi->m_listWidget_selectionGroups->installEventFilter(
this);
113 connect(m_pUi->m_listWidget_selectionGroups, &QListWidget::currentItemChanged,
114 this, &ChannelSelectionView::updateSelectionGroupsList);
118 connect(m_pUi->m_listWidget_userDefined->model(), &QAbstractTableModel::dataChanged,
124void ChannelSelectionView::initSelectionSceneView()
127 m_pSelectionScene =
new SelectionScene(m_pUi->m_graphicsView_layoutPlot);
128 m_pUi->m_graphicsView_layoutPlot->setScene(m_pSelectionScene);
130 connect(m_pSelectionScene, &QGraphicsScene::selectionChanged,
131 this, &ChannelSelectionView::updateUserDefinedChannelsList);
136void ChannelSelectionView::initComboBoxes()
138 m_pUi->m_comboBox_layoutFile->clear();
139 m_pUi->m_comboBox_layoutFile->insertItems(0, QStringList()
140 <<
"babymeg-mag-inner-layer.lout"
141 <<
"babymeg-mag-outer-layer.lout"
143 <<
"Vectorview-grad.lout"
144 <<
"Vectorview-all.lout"
145 <<
"Vectorview-mag.lout"
146 <<
"standard_waveguard64_duke.lout"
151 connect(m_pUi->m_comboBox_layoutFile, &QComboBox::currentTextChanged,
152 this, &ChannelSelectionView::onComboBoxLayoutChanged);
155 QString selectionName(
"Vectorview-all.lout");
160 selectionName = QString(
"mne_browse_raw_vv.sel");
161 loadSelectionGroups(QCoreApplication::applicationDirPath() + selectionName.prepend(
"/../resources/general/selectionGroups/"));
166void ChannelSelectionView::initButtons()
168 connect(m_pUi->m_pushButton_saveSelection, &QPushButton::clicked,
169 this, &ChannelSelectionView::onBtnSaveUserSelection);
171 connect(m_pUi->m_pushButton_loadSelection, &QPushButton::clicked,
172 this, &ChannelSelectionView::onBtnLoadUserSelection);
174 connect(m_pUi->m_pushButton_addToSelectionGroups, &QPushButton::clicked,
175 this, &ChannelSelectionView::onBtnAddToSelectionGroups);
180void ChannelSelectionView::initCheckBoxes()
182 connect(m_pUi->m_checkBox_showBadChannelsAsRed, &QCheckBox::clicked,
190 m_currentlyLoadedFiffChannels = mappedLayoutChNames;
193 m_pUi->m_listWidget_visibleChannels->clear();
196 m_pUi->m_listWidget_selectionGroups->clear();
199 auto it = m_selectionGroupsMap.find(
"All");
200 if (it != m_selectionGroupsMap.end()) {
201 m_selectionGroupsMap.erase(it);
203 m_selectionGroupsMap.insert(
"All", m_currentlyLoadedFiffChannels);
206 for(
auto i = m_selectionGroupsMap.constBegin(); i != m_selectionGroupsMap.constEnd(); i++) {
207 m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), i.key());
211 m_pUi->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
214 updateSelectionGroupsList(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
221 QStringList channelList;
222 for(
int i = 0; i < channelIndexList.size(); i++) {
223 QModelIndex nameIndex = m_pChannelInfoModel->index(channelIndexList.at(i).row(),3);
227 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
229 for(
int i = 0; i < allSceneItems.size(); i++) {
237 m_pSelectionScene->update();
244 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
246 for(
int i = 0; i < allSceneItems.size(); i++) {
249 item->setSelected(
true);
251 item->setSelected(
false);
254 m_pSelectionScene->update();
262 QListWidget* targetListWidget;
263 if(m_pUi->m_listWidget_userDefined->count()>0)
264 targetListWidget = m_pUi->m_listWidget_userDefined;
266 targetListWidget = m_pUi->m_listWidget_visibleChannels;
269 QStringList selectedChannels;
271 for(
int i = 0; i < targetListWidget->count(); i++) {
272 QListWidgetItem* item = targetListWidget->item(i);
273 selectedChannels << item->text();
276 return selectedChannels;
282 const QString &channelName)
284 for(
int i=0; i < listWidget->count(); i++)
285 if(listWidget->item(i)->text() == channelName)
286 return listWidget->item(i);
288 return new QListWidgetItem();
304 loadLayout(resolveLayoutPath(m_pUi->m_comboBox_layoutFile->currentText()));
311 return m_pUi->m_comboBox_layoutFile->currentText();
318 return m_pUi->m_lineEdit_loadedFile->text();
325 qDebug() <<
"setCurrentLayoutFile:" << currentLayoutFile;
326 const QSignalBlocker blocker(m_pUi->m_comboBox_layoutFile);
327 m_pUi->m_comboBox_layoutFile->setCurrentText(currentLayoutFile);
329 loadLayout(resolveLayoutPath(currentLayoutFile));
337 QStringList badChannelMappedNames;
338 QStringList badChannelList = m_pChannelInfoModel->getBadChannelList();
340 if(m_pUi->m_checkBox_showBadChannelsAsRed->isChecked()) {
341 for(
int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
342 QModelIndex digIndex = m_pChannelInfoModel->index(i,3);
345 digIndex = m_pChannelInfoModel->index(i,1);
348 if(badChannelList.contains(origChName)) {
349 badChannelMappedNames << mappedChName;
354 m_pSelectionScene->repaintItems(m_layoutMap, badChannelMappedNames);
355 m_pSelectionScene->update();
366 QListWidget* targetListWidget;
367 if(m_pUi->m_listWidget_userDefined->count()>0)
368 targetListWidget = m_pUi->m_listWidget_userDefined;
370 targetListWidget = m_pUi->m_listWidget_visibleChannels;
373 QStringList selectedChannels;
375 for(
int i = 0; i < targetListWidget->count(); i++) {
376 QListWidgetItem* item = targetListWidget->item(i);
377 int indexTemp = m_pChannelInfoModel->getIndexFromMappedChName(item->text());
379 if(indexTemp != -1) {
380 QModelIndex mappedNameIndex = m_pChannelInfoModel->index(indexTemp,1);
383 selectedChannels << origChName;
386 selectedChannels << item->text();
392 if(!m_pSelectionScene->selectedItems().empty()) {
396 QList<QGraphicsItem*> visibleItemList = m_pSelectionScene->items();
397 QMutableListIterator<QGraphicsItem*> i(visibleItemList);
398 while (i.hasNext()) {
399 if(!i.next()->isVisible()){
411 if(m_sSettingsPath.isEmpty()) {
415 QSettings settings(
"MNECPP");
419 settings.setValue(m_sSettingsPath + QString(
"/ChannelSelectionView/selectedLayoutFile"),
getCurrentLayoutFile());
420 settings.setValue(m_sSettingsPath + QString(
"/ChannelSelectionView/channelSelectionViewPos"), this->pos());
421 settings.setValue(m_sSettingsPath + QString(
"/ChannelSelectionView/selectedGroupFile"),
getCurrentGroupFile());
428 if(m_sSettingsPath.isEmpty()) {
432 QSettings settings(
"MNECPP");
434 setCurrentLayoutFile(settings.value(m_sSettingsPath + QString(
"/ChannelSelectionView/selectedLayoutFile"),
"Vectorview-all.lout").toString());
435 loadSelectionGroups(QCoreApplication::applicationDirPath() + settings.value(m_sSettingsPath + QString(
"/ChannelSelectionView/selectedGroupFile"),
"mne_browse_raw_vv.sel").toString().prepend(
"/../resources/general/selectionGroups/"));
439 QPoint pos = settings.value(m_sSettingsPath + QString(
"/ChannelSelectionView/channelSelectionViewPos"), QPoint(100,100)).toPoint();
441 QList<QScreen*> screensList = QGuiApplication::screens();
442 if(screensList.isEmpty())
444 move(QPoint(100,100));
476bool ChannelSelectionView::loadLayout(QString path)
478 qDebug() <<
"loadLayout:" << path;
482 QList<QVector<float> > inputPoints;
483 QList<QVector<float> > outputPoints;
485 QFile out(
"manualLayout.lout");
487 for(
int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
488 QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
491 digIndex = m_pChannelInfoModel->index(i,8);
494 digIndex = m_pChannelInfoModel->index(i,4);
499 temp.append(channelDig.x());
500 temp.append(channelDig.y());
501 temp.append(-channelDig.z());
502 inputPoints.append(temp);
513 if(inputPoints.size() > 0) {
514 while(numberTries < 10) {
534 for(
int i = 0; i < outputPoints.size(); i++) {
535 if(!m_layoutMap.contains(names.at(i))) {
536 m_layoutMap[names.at(i)] = QPointF(outputPoints.at(i)[0],outputPoints.at(i)[1]);
541 m_pSelectionScene->repaintItems(m_layoutMap, bad);
542 m_pSelectionScene->update();
546 m_pUi->m_graphicsView_layoutPlot->fitInView(m_pSelectionScene->itemsBoundingRect(), Qt::KeepAspectRatio);
560QString ChannelSelectionView::resolveLayoutPath(
const QString& layoutFile)
const
562 if(layoutFile.isEmpty()) {
566 if(QFileInfo(layoutFile).isAbsolute()) {
570 return QCoreApplication::applicationDirPath()
571 + QStringLiteral(
"/../resources/general/2DLayouts/")
577bool ChannelSelectionView::loadSelectionGroups(QString path)
581 m_pUi->m_listWidget_visibleChannels->clear();
584 m_pUi->m_listWidget_selectionGroups->clear();
587 QString newPath = path;
589 m_selectionGroupsMap.clear();
592 if(!path.isEmpty()) {
593 if(path.contains(
".sel"))
595 if(path.contains(
".mon"))
600 auto it = m_selectionGroupsMap.find(
"All");
601 if (it != m_selectionGroupsMap.end()) {
602 m_selectionGroupsMap.erase(it);
604 m_selectionGroupsMap.insert(
"All", m_currentlyLoadedFiffChannels);
607 for(
int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
608 QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
611 digIndex = m_pChannelInfoModel->index(i,4);
619 it = m_selectionGroupsMap.find(
"All EEG");
620 if (it != m_selectionGroupsMap.end()) {
621 m_selectionGroupsMap.erase(it);
623 m_selectionGroupsMap.insert(
"All EEG", names);
627 for(
auto i = m_selectionGroupsMap.constBegin(); i != m_selectionGroupsMap.constEnd(); i++) {
628 m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), i.key());
632 updateSelectionGroupsList(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
635 m_pUi->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
637 m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
648void ChannelSelectionView::cleanUpMEGChannels()
651 for(
auto i = m_selectionGroupsMap.constBegin(); i != m_selectionGroupsMap.constEnd(); i++) {
652 QStringList channelList = i.value();
655 QMutableStringListIterator stringListIndex(channelList);
656 while (stringListIndex.hasNext()) {
657 stringListIndex.next();
659 if(!m_layoutMap.contains(stringListIndex.value()) && stringListIndex.value().contains(
"MEG"))
660 stringListIndex.remove();
664 m_selectionGroupsMap.insert(i.key(), channelList);
670void ChannelSelectionView::updateSelectionGroupsList(QListWidgetItem* current, QListWidgetItem* previous)
677 if(current->text().contains(
"EEG"))
683 m_pUi->m_listWidget_visibleChannels->clear();
684 auto items = m_selectionGroupsMap.find(current->text());
685 m_pUi->m_listWidget_visibleChannels->addItems(*items);
698void ChannelSelectionView::updateSceneItems()
700 QStringList visibleItems;
702 for(
int i = 0; i < m_pUi->m_listWidget_visibleChannels->count(); i++)
703 visibleItems << m_pUi->m_listWidget_visibleChannels->item(i)->text();
705 m_pSelectionScene->hideItems(visibleItems);
710void ChannelSelectionView::updateUserDefinedChannelsList()
712 QList<QGraphicsItem*> itemList = m_pSelectionScene->selectedItems();
713 QStringList userDefinedChannels;
715 for(
int i = 0; i < itemList.size(); i++) {
716 SelectionSceneItem* item =
static_cast<SelectionSceneItem*
>(itemList.at(i));
720 m_pUi->m_listWidget_userDefined->clear();
721 m_pUi->m_listWidget_userDefined->addItems(userDefinedChannels);
728void ChannelSelectionView::onBtnLoadUserSelection()
730 QString path = QFileDialog::getOpenFileName(
this,
731 QString(
"Open selection file"),
732 QString(
"../resources/general/selectionGroups/"),
733 tr(
"Selection files (*.sel *.mon)"));
738 loadSelectionGroups(path);
739 m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
744void ChannelSelectionView::onBtnSaveUserSelection()
747 QString path = QFileDialog::getSaveFileName(
this,
748 "Save user channel selection",
749 QString(
"../resources/general/selectionGroups/%1_%2_%3_UserSelection").arg(date.currentDate().year()).arg(date.currentDate().month()).arg(date.currentDate().day()),
750 tr(
"MNE selection file(*.sel);; Brainstorm montage file(*.mon)"));
752 QMultiMap<QString, QStringList> tempMap = m_selectionGroupsMap;
753 tempMap.remove(
"All");
754 tempMap.remove(
"All EEG");
756 if(!path.isEmpty()) {
757 if(path.contains(
".sel"))
759 if(path.contains(
".mon"))
766void ChannelSelectionView::onBtnAddToSelectionGroups()
769 for(
int i = 0; i < m_pUi->m_listWidget_userDefined->count(); i++)
770 temp<<m_pUi->m_listWidget_userDefined->item(i)->text();
772 m_selectionGroupsMap.insert(m_pUi->m_lineEdit_selectionGroupName->text(), temp);
773 m_pUi->m_listWidget_selectionGroups->insertItem(m_pUi->m_listWidget_selectionGroups->count(), m_pUi->m_lineEdit_selectionGroupName->text());
778void ChannelSelectionView::onComboBoxLayoutChanged()
780 QString selectionName(m_pUi->m_comboBox_layoutFile->currentText());
781 loadLayout(resolveLayoutPath(selectionName));
787void ChannelSelectionView::resizeEvent(QResizeEvent* event)
797bool ChannelSelectionView::eventFilter(QObject *obj, QEvent *event)
800 if (obj == m_pUi->m_listWidget_userDefined && event->type() == QEvent::KeyRelease) {
801 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
803 if(keyEvent->key() == Qt::Key_Delete) {
804 qDeleteAll(m_pUi->m_listWidget_userDefined->selectedItems());
812 if (obj == m_pUi->m_listWidget_selectionGroups && event->type() == QEvent::KeyRelease) {
813 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
815 if(keyEvent->key() == Qt::Key_Delete) {
816 QList<QListWidgetItem *> tempSelectedList;
818 for(
int i = 0; i < m_pUi->m_listWidget_selectionGroups->selectedItems().size(); i++) {
819 if(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text() !=
"All" &&
820 m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text() !=
"All EEG") {
821 tempSelectedList.append(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i));
822 m_selectionGroupsMap.remove(m_pUi->m_listWidget_selectionGroups->selectedItems().at(i)->text());
826 qDeleteAll(tempSelectedList);
836 return QWidget::eventFilter(obj, event);
843 return m_pUi->viewWidget;
850 return m_pUi->controlWidget;
857 return ((m_pUi->m_listWidget_selectionGroups->currentItem()->text() ==
"All") && (m_pUi->m_listWidget_userDefined->count() == 0));
864 m_pSelectionScene->clear();
Reader for ANT .elc electrode files and MNE .lout 2-D channel layouts used by the topographic plottin...
Reader / writer for MNE .sel channel-selection files and Brainstorm .mon montage files.
Generator that projects 3-D electrode positions onto a 2-D .lout topographic layout via least-squares...
QAbstractTableModel exposing per-channel FIFF metadata (name, type, unit, position,...
Channel-selection group descriptor (SelectionItem) and the matching QGraphicsItem (SelectionSceneItem...
QGraphicsScene of the sensor-layout dots used by ChannelSelectionView for interactive channel picking...
Interactive 2-D sensor-layout picker for building and saving channel groups.
Static MATLAB-style FIFF facade: thin wrapper functions kept for parity with the historical mne-matla...
FIFF file I/O, in-memory data structures and high-level readers/writers.
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)
QString getCurrentLayoutFile()
const QMap< QString, QPointF > & getLayoutMap()
void showSelectedChannelsOnly(QStringList selectedChannels)
QStringList getSelectedChannels()
QWidget * getViewWidget()
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)
QString getCurrentGroupFile()
void setCurrentLayoutFile(QString currentLayoutFile)
void updateGuiMode(GuiMode mode)
QWidget * getControlWidget()
QSharedPointer< ChannelInfoModel > SPtr
QGraphicsScene of sensor-layout dots used by ChannelSelectionView for interactive channel picking.
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)