42#include "ui_channelselectionview.h"
66#include <QListWidgetItem>
68#include <QApplication>
92, m_pUi(new Ui::ChannelSelectionViewWidget)
93, m_pChannelInfoModel(pChannelInfoModel)
96 m_sSettingsPath = sSettingsPath;
101 initSelectionSceneView();
124void ChannelSelectionView::initListWidgets()
127 m_pUi->m_listWidget_userDefined->installEventFilter(
this);
128 m_pUi->m_listWidget_selectionGroups->installEventFilter(
this);
131 connect(m_pUi->m_listWidget_selectionGroups, &QListWidget::currentItemChanged,
132 this, &ChannelSelectionView::updateSelectionGroupsList);
136 connect(m_pUi->m_listWidget_userDefined->model(), &QAbstractTableModel::dataChanged,
142void ChannelSelectionView::initSelectionSceneView()
145 m_pSelectionScene =
new SelectionScene(m_pUi->m_graphicsView_layoutPlot);
146 m_pUi->m_graphicsView_layoutPlot->setScene(m_pSelectionScene);
148 connect(m_pSelectionScene, &QGraphicsScene::selectionChanged,
149 this, &ChannelSelectionView::updateUserDefinedChannelsList);
154void ChannelSelectionView::initComboBoxes()
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"
161 <<
"Vectorview-grad.lout"
162 <<
"Vectorview-all.lout"
163 <<
"Vectorview-mag.lout"
164 <<
"standard_waveguard64_duke.lout"
169 connect(m_pUi->m_comboBox_layoutFile, &QComboBox::currentTextChanged,
170 this, &ChannelSelectionView::onComboBoxLayoutChanged);
173 QString selectionName(
"Vectorview-all.lout");
178 selectionName = QString(
"mne_browse_raw_vv.sel");
179 loadSelectionGroups(QCoreApplication::applicationDirPath() + selectionName.prepend(
"/../resources/general/selectionGroups/"));
184void ChannelSelectionView::initButtons()
186 connect(m_pUi->m_pushButton_saveSelection, &QPushButton::clicked,
187 this, &ChannelSelectionView::onBtnSaveUserSelection);
189 connect(m_pUi->m_pushButton_loadSelection, &QPushButton::clicked,
190 this, &ChannelSelectionView::onBtnLoadUserSelection);
192 connect(m_pUi->m_pushButton_addToSelectionGroups, &QPushButton::clicked,
193 this, &ChannelSelectionView::onBtnAddToSelectionGroups);
198void ChannelSelectionView::initCheckBoxes()
200 connect(m_pUi->m_checkBox_showBadChannelsAsRed, &QCheckBox::clicked,
208 m_currentlyLoadedFiffChannels = mappedLayoutChNames;
211 m_pUi->m_listWidget_visibleChannels->clear();
214 m_pUi->m_listWidget_selectionGroups->clear();
217 auto it = m_selectionGroupsMap.find(
"All");
218 if (it != m_selectionGroupsMap.end()) {
219 m_selectionGroupsMap.erase(it);
221 m_selectionGroupsMap.insert(
"All", m_currentlyLoadedFiffChannels);
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());
229 m_pUi->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
232 updateSelectionGroupsList(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
239 QStringList channelList;
240 for(
int i = 0; i < channelIndexList.size(); i++) {
241 QModelIndex nameIndex = m_pChannelInfoModel->index(channelIndexList.at(i).row(),3);
245 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
247 for(
int i = 0; i < allSceneItems.size(); i++) {
255 m_pSelectionScene->update();
262 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
264 for(
int i = 0; i < allSceneItems.size(); i++) {
267 item->setSelected(
true);
269 item->setSelected(
false);
272 m_pSelectionScene->update();
280 QListWidget* targetListWidget;
281 if(m_pUi->m_listWidget_userDefined->count()>0)
282 targetListWidget = m_pUi->m_listWidget_userDefined;
284 targetListWidget = m_pUi->m_listWidget_visibleChannels;
287 QStringList selectedChannels;
289 for(
int i = 0; i < targetListWidget->count(); i++) {
290 QListWidgetItem* item = targetListWidget->item(i);
291 selectedChannels << item->text();
294 return selectedChannels;
300 const QString &channelName)
302 for(
int i=0; i < listWidget->count(); i++)
303 if(listWidget->item(i)->text() == channelName)
304 return listWidget->item(i);
306 return new QListWidgetItem();
322 loadLayout(m_pUi->m_comboBox_layoutFile->currentText());
329 return m_pUi->m_comboBox_layoutFile->currentText();
336 return m_pUi->m_lineEdit_loadedFile->text();
343 qDebug() <<
"setCurrentLayoutFile:" << currentLayoutFile;
344 m_pUi->m_comboBox_layoutFile->setCurrentText(currentLayoutFile);
353 QStringList badChannelMappedNames;
354 QStringList badChannelList = m_pChannelInfoModel->getBadChannelList();
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);
361 digIndex = m_pChannelInfoModel->index(i,1);
364 if(badChannelList.contains(origChName)) {
365 badChannelMappedNames << mappedChName;
370 m_pSelectionScene->repaintItems(m_layoutMap, badChannelMappedNames);
371 m_pSelectionScene->update();
382 QListWidget* targetListWidget;
383 if(m_pUi->m_listWidget_userDefined->count()>0)
384 targetListWidget = m_pUi->m_listWidget_userDefined;
386 targetListWidget = m_pUi->m_listWidget_visibleChannels;
389 QStringList selectedChannels;
391 for(
int i = 0; i < targetListWidget->count(); i++) {
392 QListWidgetItem* item = targetListWidget->item(i);
393 int indexTemp = m_pChannelInfoModel->getIndexFromMappedChName(item->text());
395 if(indexTemp != -1) {
396 QModelIndex mappedNameIndex = m_pChannelInfoModel->index(indexTemp,1);
399 selectedChannels << origChName;
402 selectedChannels << item->text();
408 if(!m_pSelectionScene->selectedItems().empty()) {
412 QList<QGraphicsItem*> visibleItemList = m_pSelectionScene->items();
413 QMutableListIterator<QGraphicsItem*> i(visibleItemList);
414 while (i.hasNext()) {
415 if(!i.next()->isVisible()){
427 if(m_sSettingsPath.isEmpty()) {
431 QSettings settings(
"MNECPP");
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());
444 if(m_sSettingsPath.isEmpty()) {
448 QSettings settings(
"MNECPP");
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/"));
455 QPoint pos = settings.value(m_sSettingsPath + QString(
"/ChannelSelectionView/channelSelectionViewPos"), QPoint(100,100)).toPoint();
457 QList<QScreen*> screensList = QGuiApplication::screens();
458 if(screensList.isEmpty())
460 move(QPoint(100,100));
492bool ChannelSelectionView::loadLayout(QString path)
494 qDebug() <<
"loadLayout:" << path;
498 QList<QVector<float> > inputPoints;
499 QList<QVector<float> > outputPoints;
501 QFile out(
"manualLayout.lout");
503 for(
int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
504 QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
507 digIndex = m_pChannelInfoModel->index(i,8);
510 digIndex = m_pChannelInfoModel->index(i,4);
515 temp.append(channelDig.x());
516 temp.append(channelDig.y());
517 temp.append(-channelDig.z());
518 inputPoints.append(temp);
529 if(inputPoints.size() > 0) {
530 while(numberTries < 10) {
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]);
557 m_pSelectionScene->repaintItems(m_layoutMap, bad);
558 m_pSelectionScene->update();
562 m_pUi->m_graphicsView_layoutPlot->fitInView(m_pSelectionScene->itemsBoundingRect(), Qt::KeepAspectRatio);
576bool ChannelSelectionView::loadSelectionGroups(QString path)
580 m_pUi->m_listWidget_visibleChannels->clear();
583 m_pUi->m_listWidget_selectionGroups->clear();
586 QString newPath = path;
588 m_selectionGroupsMap.clear();
591 if(!path.isEmpty()) {
592 if(path.contains(
".sel"))
594 if(path.contains(
".mon"))
599 auto it = m_selectionGroupsMap.find(
"All");
600 if (it != m_selectionGroupsMap.end()) {
601 m_selectionGroupsMap.erase(it);
603 m_selectionGroupsMap.insert(
"All", m_currentlyLoadedFiffChannels);
606 for(
int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
607 QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
610 digIndex = m_pChannelInfoModel->index(i,4);
618 it = m_selectionGroupsMap.find(
"All EEG");
619 if (it != m_selectionGroupsMap.end()) {
620 m_selectionGroupsMap.erase(it);
622 m_selectionGroupsMap.insert(
"All EEG", names);
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());
631 updateSelectionGroupsList(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
634 m_pUi->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
640 m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
651void ChannelSelectionView::cleanUpMEGChannels()
654 for(
auto i = m_selectionGroupsMap.constBegin(); i != m_selectionGroupsMap.constEnd(); i++) {
655 QStringList channelList = i.value();
658 QMutableStringListIterator stringListIndex(channelList);
659 while (stringListIndex.hasNext()) {
660 stringListIndex.next();
662 if(!m_layoutMap.contains(stringListIndex.value()) && stringListIndex.value().contains(
"MEG"))
663 stringListIndex.remove();
667 m_selectionGroupsMap.insert(i.key(), channelList);
673void ChannelSelectionView::updateSelectionGroupsList(QListWidgetItem* current, QListWidgetItem* previous)
680 if(current->text().contains(
"EEG"))
686 m_pUi->m_listWidget_visibleChannels->clear();
687 auto items = m_selectionGroupsMap.find(current->text());
688 m_pUi->m_listWidget_visibleChannels->addItems(*items);
701void ChannelSelectionView::updateSceneItems()
703 QStringList visibleItems;
705 for(
int i = 0; i < m_pUi->m_listWidget_visibleChannels->count(); i++)
706 visibleItems << m_pUi->m_listWidget_visibleChannels->item(i)->text();
708 m_pSelectionScene->hideItems(visibleItems);
713void ChannelSelectionView::updateUserDefinedChannelsList()
715 QList<QGraphicsItem*> itemList = m_pSelectionScene->selectedItems();
716 QStringList userDefinedChannels;
718 for(
int i = 0; i < itemList.size(); i++) {
719 SelectionSceneItem* item =
static_cast<SelectionSceneItem*
>(itemList.at(i));
723 m_pUi->m_listWidget_userDefined->clear();
724 m_pUi->m_listWidget_userDefined->addItems(userDefinedChannels);
731void ChannelSelectionView::onBtnLoadUserSelection()
733 QString path = QFileDialog::getOpenFileName(
this,
734 QString(
"Open selection file"),
735 QString(
"../resources/general/selectionGroups/"),
736 tr(
"Selection files (*.sel *.mon)"));
741 loadSelectionGroups(path);
742 m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
747void ChannelSelectionView::onBtnSaveUserSelection()
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)"));
755 QMultiMap<QString, QStringList> tempMap = m_selectionGroupsMap;
756 tempMap.remove(
"All");
757 tempMap.remove(
"All EEG");
759 if(!path.isEmpty()) {
760 if(path.contains(
".sel"))
762 if(path.contains(
".mon"))
769void ChannelSelectionView::onBtnAddToSelectionGroups()
772 for(
int i = 0; i < m_pUi->m_listWidget_userDefined->count(); i++)
773 temp<<m_pUi->m_listWidget_userDefined->item(i)->text();
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());
781void ChannelSelectionView::onComboBoxLayoutChanged()
783 QString selectionName(m_pUi->m_comboBox_layoutFile->currentText());
784 loadLayout(QCoreApplication::applicationDirPath() + selectionName.prepend(
"/../resources/general/2DLayouts/"));
790void ChannelSelectionView::resizeEvent(QResizeEvent* event)
800bool ChannelSelectionView::eventFilter(QObject *obj, QEvent *event)
803 if (obj == m_pUi->m_listWidget_userDefined && event->type() == QEvent::KeyRelease) {
804 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
806 if(keyEvent->key() == Qt::Key_Delete) {
807 qDeleteAll(m_pUi->m_listWidget_userDefined->selectedItems());
815 if (obj == m_pUi->m_listWidget_selectionGroups && event->type() == QEvent::KeyRelease) {
816 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
818 if(keyEvent->key() == Qt::Key_Delete) {
819 QList<QListWidgetItem *> tempSelectedList;
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());
829 qDeleteAll(tempSelectedList);
839 return QWidget::eventFilter(obj, event);
846 return m_pUi->viewWidget;
853 return m_pUi->controlWidget;
860 return ((m_pUi->m_listWidget_selectionGroups->currentItem()->text() ==
"All") && (m_pUi->m_listWidget_userDefined->count() == 0));
867 m_pSelectionScene->clear();
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.
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)
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
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)