42#include "ui_channelselectionview.h"
67#include <QListWidgetItem>
69#include <QApplication>
71#include <QSignalBlocker>
94, m_pUi(new Ui::ChannelSelectionViewWidget)
95, m_pChannelInfoModel(pChannelInfoModel)
98 m_sSettingsPath = sSettingsPath;
103 initSelectionSceneView();
126void ChannelSelectionView::initListWidgets()
129 m_pUi->m_listWidget_userDefined->installEventFilter(
this);
130 m_pUi->m_listWidget_selectionGroups->installEventFilter(
this);
133 connect(m_pUi->m_listWidget_selectionGroups, &QListWidget::currentItemChanged,
134 this, &ChannelSelectionView::updateSelectionGroupsList);
138 connect(m_pUi->m_listWidget_userDefined->model(), &QAbstractTableModel::dataChanged,
144void ChannelSelectionView::initSelectionSceneView()
147 m_pSelectionScene =
new SelectionScene(m_pUi->m_graphicsView_layoutPlot);
148 m_pUi->m_graphicsView_layoutPlot->setScene(m_pSelectionScene);
150 connect(m_pSelectionScene, &QGraphicsScene::selectionChanged,
151 this, &ChannelSelectionView::updateUserDefinedChannelsList);
156void ChannelSelectionView::initComboBoxes()
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"
163 <<
"Vectorview-grad.lout"
164 <<
"Vectorview-all.lout"
165 <<
"Vectorview-mag.lout"
166 <<
"standard_waveguard64_duke.lout"
171 connect(m_pUi->m_comboBox_layoutFile, &QComboBox::currentTextChanged,
172 this, &ChannelSelectionView::onComboBoxLayoutChanged);
175 QString selectionName(
"Vectorview-all.lout");
180 selectionName = QString(
"mne_browse_raw_vv.sel");
181 loadSelectionGroups(QCoreApplication::applicationDirPath() + selectionName.prepend(
"/../resources/general/selectionGroups/"));
186void ChannelSelectionView::initButtons()
188 connect(m_pUi->m_pushButton_saveSelection, &QPushButton::clicked,
189 this, &ChannelSelectionView::onBtnSaveUserSelection);
191 connect(m_pUi->m_pushButton_loadSelection, &QPushButton::clicked,
192 this, &ChannelSelectionView::onBtnLoadUserSelection);
194 connect(m_pUi->m_pushButton_addToSelectionGroups, &QPushButton::clicked,
195 this, &ChannelSelectionView::onBtnAddToSelectionGroups);
200void ChannelSelectionView::initCheckBoxes()
202 connect(m_pUi->m_checkBox_showBadChannelsAsRed, &QCheckBox::clicked,
210 m_currentlyLoadedFiffChannels = mappedLayoutChNames;
213 m_pUi->m_listWidget_visibleChannels->clear();
216 m_pUi->m_listWidget_selectionGroups->clear();
219 auto it = m_selectionGroupsMap.find(
"All");
220 if (it != m_selectionGroupsMap.end()) {
221 m_selectionGroupsMap.erase(it);
223 m_selectionGroupsMap.insert(
"All", m_currentlyLoadedFiffChannels);
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());
231 m_pUi->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
234 updateSelectionGroupsList(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
241 QStringList channelList;
242 for(
int i = 0; i < channelIndexList.size(); i++) {
243 QModelIndex nameIndex = m_pChannelInfoModel->index(channelIndexList.at(i).row(),3);
247 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
249 for(
int i = 0; i < allSceneItems.size(); i++) {
257 m_pSelectionScene->update();
264 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
266 for(
int i = 0; i < allSceneItems.size(); i++) {
269 item->setSelected(
true);
271 item->setSelected(
false);
274 m_pSelectionScene->update();
282 QListWidget* targetListWidget;
283 if(m_pUi->m_listWidget_userDefined->count()>0)
284 targetListWidget = m_pUi->m_listWidget_userDefined;
286 targetListWidget = m_pUi->m_listWidget_visibleChannels;
289 QStringList selectedChannels;
291 for(
int i = 0; i < targetListWidget->count(); i++) {
292 QListWidgetItem* item = targetListWidget->item(i);
293 selectedChannels << item->text();
296 return selectedChannels;
302 const QString &channelName)
304 for(
int i=0; i < listWidget->count(); i++)
305 if(listWidget->item(i)->text() == channelName)
306 return listWidget->item(i);
308 return new QListWidgetItem();
324 loadLayout(resolveLayoutPath(m_pUi->m_comboBox_layoutFile->currentText()));
331 return m_pUi->m_comboBox_layoutFile->currentText();
338 return m_pUi->m_lineEdit_loadedFile->text();
345 qDebug() <<
"setCurrentLayoutFile:" << currentLayoutFile;
346 const QSignalBlocker blocker(m_pUi->m_comboBox_layoutFile);
347 m_pUi->m_comboBox_layoutFile->setCurrentText(currentLayoutFile);
349 loadLayout(resolveLayoutPath(currentLayoutFile));
357 QStringList badChannelMappedNames;
358 QStringList badChannelList = m_pChannelInfoModel->getBadChannelList();
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);
365 digIndex = m_pChannelInfoModel->index(i,1);
368 if(badChannelList.contains(origChName)) {
369 badChannelMappedNames << mappedChName;
374 m_pSelectionScene->repaintItems(m_layoutMap, badChannelMappedNames);
375 m_pSelectionScene->update();
386 QListWidget* targetListWidget;
387 if(m_pUi->m_listWidget_userDefined->count()>0)
388 targetListWidget = m_pUi->m_listWidget_userDefined;
390 targetListWidget = m_pUi->m_listWidget_visibleChannels;
393 QStringList selectedChannels;
395 for(
int i = 0; i < targetListWidget->count(); i++) {
396 QListWidgetItem* item = targetListWidget->item(i);
397 int indexTemp = m_pChannelInfoModel->getIndexFromMappedChName(item->text());
399 if(indexTemp != -1) {
400 QModelIndex mappedNameIndex = m_pChannelInfoModel->index(indexTemp,1);
403 selectedChannels << origChName;
406 selectedChannels << item->text();
412 if(!m_pSelectionScene->selectedItems().empty()) {
416 QList<QGraphicsItem*> visibleItemList = m_pSelectionScene->items();
417 QMutableListIterator<QGraphicsItem*> i(visibleItemList);
418 while (i.hasNext()) {
419 if(!i.next()->isVisible()){
431 if(m_sSettingsPath.isEmpty()) {
435 QSettings settings(
"MNECPP");
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());
448 if(m_sSettingsPath.isEmpty()) {
452 QSettings settings(
"MNECPP");
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/"));
459 QPoint pos = settings.value(m_sSettingsPath + QString(
"/ChannelSelectionView/channelSelectionViewPos"), QPoint(100,100)).toPoint();
461 QList<QScreen*> screensList = QGuiApplication::screens();
462 if(screensList.isEmpty())
464 move(QPoint(100,100));
496bool ChannelSelectionView::loadLayout(QString path)
498 qDebug() <<
"loadLayout:" << path;
502 QList<QVector<float> > inputPoints;
503 QList<QVector<float> > outputPoints;
505 QFile out(
"manualLayout.lout");
507 for(
int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
508 QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
511 digIndex = m_pChannelInfoModel->index(i,8);
514 digIndex = m_pChannelInfoModel->index(i,4);
519 temp.append(channelDig.x());
520 temp.append(channelDig.y());
521 temp.append(-channelDig.z());
522 inputPoints.append(temp);
533 if(inputPoints.size() > 0) {
534 while(numberTries < 10) {
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]);
561 m_pSelectionScene->repaintItems(m_layoutMap, bad);
562 m_pSelectionScene->update();
566 m_pUi->m_graphicsView_layoutPlot->fitInView(m_pSelectionScene->itemsBoundingRect(), Qt::KeepAspectRatio);
580QString ChannelSelectionView::resolveLayoutPath(
const QString& layoutFile)
const
582 if(layoutFile.isEmpty()) {
586 if(QFileInfo(layoutFile).isAbsolute()) {
590 return QCoreApplication::applicationDirPath()
591 + QStringLiteral(
"/../resources/general/2DLayouts/")
597bool ChannelSelectionView::loadSelectionGroups(QString path)
601 m_pUi->m_listWidget_visibleChannels->clear();
604 m_pUi->m_listWidget_selectionGroups->clear();
607 QString newPath = path;
609 m_selectionGroupsMap.clear();
612 if(!path.isEmpty()) {
613 if(path.contains(
".sel"))
615 if(path.contains(
".mon"))
620 auto it = m_selectionGroupsMap.find(
"All");
621 if (it != m_selectionGroupsMap.end()) {
622 m_selectionGroupsMap.erase(it);
624 m_selectionGroupsMap.insert(
"All", m_currentlyLoadedFiffChannels);
627 for(
int i = 0; i < m_pChannelInfoModel->rowCount(); i++) {
628 QModelIndex digIndex = m_pChannelInfoModel->index(i,1);
631 digIndex = m_pChannelInfoModel->index(i,4);
639 it = m_selectionGroupsMap.find(
"All EEG");
640 if (it != m_selectionGroupsMap.end()) {
641 m_selectionGroupsMap.erase(it);
643 m_selectionGroupsMap.insert(
"All EEG", names);
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());
652 updateSelectionGroupsList(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
655 m_pUi->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(m_pUi->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
657 m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
668void ChannelSelectionView::cleanUpMEGChannels()
671 for(
auto i = m_selectionGroupsMap.constBegin(); i != m_selectionGroupsMap.constEnd(); i++) {
672 QStringList channelList = i.value();
675 QMutableStringListIterator stringListIndex(channelList);
676 while (stringListIndex.hasNext()) {
677 stringListIndex.next();
679 if(!m_layoutMap.contains(stringListIndex.value()) && stringListIndex.value().contains(
"MEG"))
680 stringListIndex.remove();
684 m_selectionGroupsMap.insert(i.key(), channelList);
690void ChannelSelectionView::updateSelectionGroupsList(QListWidgetItem* current, QListWidgetItem* previous)
697 if(current->text().contains(
"EEG"))
703 m_pUi->m_listWidget_visibleChannels->clear();
704 auto items = m_selectionGroupsMap.find(current->text());
705 m_pUi->m_listWidget_visibleChannels->addItems(*items);
718void ChannelSelectionView::updateSceneItems()
720 QStringList visibleItems;
722 for(
int i = 0; i < m_pUi->m_listWidget_visibleChannels->count(); i++)
723 visibleItems << m_pUi->m_listWidget_visibleChannels->item(i)->text();
725 m_pSelectionScene->hideItems(visibleItems);
730void ChannelSelectionView::updateUserDefinedChannelsList()
732 QList<QGraphicsItem*> itemList = m_pSelectionScene->selectedItems();
733 QStringList userDefinedChannels;
735 for(
int i = 0; i < itemList.size(); i++) {
736 SelectionSceneItem* item =
static_cast<SelectionSceneItem*
>(itemList.at(i));
740 m_pUi->m_listWidget_userDefined->clear();
741 m_pUi->m_listWidget_userDefined->addItems(userDefinedChannels);
748void ChannelSelectionView::onBtnLoadUserSelection()
750 QString path = QFileDialog::getOpenFileName(
this,
751 QString(
"Open selection file"),
752 QString(
"../resources/general/selectionGroups/"),
753 tr(
"Selection files (*.sel *.mon)"));
758 loadSelectionGroups(path);
759 m_pUi->m_lineEdit_loadedFile->setText(QFileInfo(path).fileName());
764void ChannelSelectionView::onBtnSaveUserSelection()
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)"));
772 QMultiMap<QString, QStringList> tempMap = m_selectionGroupsMap;
773 tempMap.remove(
"All");
774 tempMap.remove(
"All EEG");
776 if(!path.isEmpty()) {
777 if(path.contains(
".sel"))
779 if(path.contains(
".mon"))
786void ChannelSelectionView::onBtnAddToSelectionGroups()
789 for(
int i = 0; i < m_pUi->m_listWidget_userDefined->count(); i++)
790 temp<<m_pUi->m_listWidget_userDefined->item(i)->text();
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());
798void ChannelSelectionView::onComboBoxLayoutChanged()
800 QString selectionName(m_pUi->m_comboBox_layoutFile->currentText());
801 loadLayout(resolveLayoutPath(selectionName));
807void ChannelSelectionView::resizeEvent(QResizeEvent* event)
817bool ChannelSelectionView::eventFilter(QObject *obj, QEvent *event)
820 if (obj == m_pUi->m_listWidget_userDefined && event->type() == QEvent::KeyRelease) {
821 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
823 if(keyEvent->key() == Qt::Key_Delete) {
824 qDeleteAll(m_pUi->m_listWidget_userDefined->selectedItems());
832 if (obj == m_pUi->m_listWidget_selectionGroups && event->type() == QEvent::KeyRelease) {
833 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
835 if(keyEvent->key() == Qt::Key_Delete) {
836 QList<QListWidgetItem *> tempSelectedList;
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());
846 qDeleteAll(tempSelectedList);
856 return QWidget::eventFilter(obj, event);
863 return m_pUi->viewWidget;
870 return m_pUi->controlWidget;
877 return ((m_pUi->m_listWidget_selectionGroups->currentItem()->text() ==
"All") && (m_pUi->m_listWidget_userDefined->count() == 0));
884 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.
LayoutLoader class declaration.
LayoutLoader class declaration.
SelectionIO class declaration.
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)
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)