42 #include "selectionmanagerwindow.h"
61 , m_pChInfoModel(pChInfoModel)
67 initSelectionSceneView();
84 m_currentlyLoadedFiffChannels = mappedLayoutChNames;
87 ui->m_listWidget_visibleChannels->clear();
90 ui->m_listWidget_selectionGroups->clear();
93 m_selectionGroupsMap[
"All"] = m_currentlyLoadedFiffChannels;
96 QMapIterator<QString, QStringList> selectionIndex(m_selectionGroupsMap);
97 while (selectionIndex.hasNext()) {
98 selectionIndex.next();
99 ui->m_listWidget_selectionGroups->insertItem(ui->m_listWidget_selectionGroups->count(), selectionIndex.key());
103 ui->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(ui->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
106 updateSelectionGroupsList(
getItemForChName(ui->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
114 QStringList channelList;
115 for(
int i = 0; i<channelIndexList.size(); i++) {
116 QModelIndex nameIndex = m_pChInfoModel->index(channelIndexList.at(i).row(),3);
117 channelList<<m_pChInfoModel->data(nameIndex, ChInfoModelRoles::GetMappedLayoutChName).toString();
120 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
122 for(
int i = 0; i<allSceneItems.size(); i++) {
130 m_pSelectionScene->update();
138 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
140 for(
int i = 0; i<allSceneItems.size(); i++) {
143 item->setSelected(
true);
145 item->setSelected(
false);
148 m_pSelectionScene->update();
157 QListWidget* targetListWidget;
158 if(ui->m_listWidget_userDefined->count()>0)
159 targetListWidget = ui->m_listWidget_userDefined;
161 targetListWidget = ui->m_listWidget_visibleChannels;
164 QStringList selectedChannels;
166 for(
int i = 0; i<targetListWidget->count(); i++) {
167 QListWidgetItem* item = targetListWidget->item(i);
168 selectedChannels << item->text();
171 return selectedChannels;
179 for(
int i=0; i<listWidget->count(); i++)
180 if(listWidget->item(i)->text() == channelName)
181 return listWidget->item(i);
183 return new QListWidgetItem();
199 loadLayout(ui->m_comboBox_layoutFile->currentText());
205 void SelectionManagerWindow::initListWidgets()
208 ui->m_listWidget_userDefined->installEventFilter(
this);
211 connect(ui->m_listWidget_selectionGroups, &QListWidget::currentItemChanged,
212 this, &SelectionManagerWindow::updateSelectionGroupsList);
215 connect(ui->m_listWidget_userDefined->model(), &QAbstractTableModel::dataChanged,
216 this, &SelectionManagerWindow::updateDataView);
222 void SelectionManagerWindow::initSelectionSceneView()
225 m_pSelectionScene =
new SelectionScene(ui->m_graphicsView_layoutPlot);
226 ui->m_graphicsView_layoutPlot->setScene(m_pSelectionScene);
228 connect(m_pSelectionScene, &QGraphicsScene::selectionChanged,
229 this, &SelectionManagerWindow::updateUserDefinedChannelsList);
235 void SelectionManagerWindow::initComboBoxes()
237 ui->m_comboBox_layoutFile->clear();
238 ui->m_comboBox_layoutFile->insertItems(0, QStringList()
239 << QApplication::translate(
"SelectionManagerWindow",
"Vectorview-grad.lout", 0)
240 << QApplication::translate(
"SelectionManagerWindow",
"Vectorview-all.lout", 0)
241 << QApplication::translate(
"SelectionManagerWindow",
"Vectorview-mag.lout", 0)
242 << QApplication::translate(
"SelectionManagerWindow",
"babymeg-mag-inner-layer.lout", 0)
243 << QApplication::translate(
"SelectionManagerWindow",
"babymeg-mag-outer-layer.lout", 0)
244 << QApplication::translate(
"SelectionManagerWindow",
"babymeg-mag-ref.lout", 0)
248 ui->m_comboBox_selectionFiles->clear();
249 ui->m_comboBox_selectionFiles->insertItems(0, QStringList()
250 << QApplication::translate(
"SelectionManagerWindow",
"mne_browse_raw_vv.sel", 0)
251 << QApplication::translate(
"SelectionManagerWindow",
"mne_browse_raw_vv_new.sel", 0)
257 connect(ui->m_comboBox_selectionFiles, &QComboBox::currentTextChanged,
258 this, &SelectionManagerWindow::loadSelectionGroups);
260 connect(ui->m_comboBox_layoutFile, &QComboBox::currentTextChanged,
261 this, &SelectionManagerWindow::loadLayout);
264 loadLayout(
"Vectorview-grad.lout");
270 bool SelectionManagerWindow::loadLayout(QString path)
273 QString newPath = QCoreApplication::applicationDirPath() + path.prepend(
"/MNE_Browse_Raw_Resources/Templates/Layouts/");
275 bool state = LayoutLoader::readMNELoutFile(newPath, m_layoutMap);
278 loadSelectionGroups(ui->m_comboBox_selectionFiles->currentText());
281 QList<QVector<double> > inputPoints;
282 QList<QVector<double> > outputPoints;
286 for(
int i = 0; i<m_pChInfoModel->
rowCount(); i++) {
287 QModelIndex digIndex = m_pChInfoModel->index(i,1);
288 QString chName = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetOrigChName).toString();
290 digIndex = m_pChInfoModel->index(i,8);
291 QVector3D channelDig = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetChDigitizer).value<QVector3D>();
293 digIndex = m_pChInfoModel->index(i,4);
294 int kind = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetChKind).toInt();
296 if(kind == FIFFV_EEG_CH) {
297 QVector<double> temp;
298 temp.append(channelDig.x());
299 temp.append(channelDig.y());
300 temp.append(-channelDig.z());
301 inputPoints.append(temp);
312 if(inputPoints.size()>0)
313 while(numberTries<10) {
314 if(LayoutMaker::makeLayout(inputPoints,
330 for(
int i = 0; i<outputPoints.size(); i++)
331 m_layoutMap[names.at(i)] = QPointF(outputPoints.at(i)[0],outputPoints.at(i)[1]);
335 m_pSelectionScene->update();
339 ui->m_graphicsView_layoutPlot->fitInView(m_pSelectionScene->itemsBoundingRect(), Qt::KeepAspectRatio);
350 bool SelectionManagerWindow::loadSelectionGroups(QString path)
353 ui->m_listWidget_visibleChannels->clear();
356 ui->m_listWidget_selectionGroups->clear();
360 QString newPath = QCoreApplication::applicationDirPath() + path.prepend(
"/MNE_Browse_Raw_Resources/Templates/ChannelSelection/");
362 bool state = manager->
readMNESelFile(newPath, m_selectionGroupsMap);
365 m_selectionGroupsMap[
"All"] = m_currentlyLoadedFiffChannels;
368 for(
int i = 0; i<m_pChInfoModel->
rowCount(); i++) {
369 QModelIndex digIndex = m_pChInfoModel->index(i,1);
370 QString chName = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetOrigChName).toString();
372 digIndex = m_pChInfoModel->index(i,4);
373 int kind = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetChKind).toInt();
375 if(kind == FIFFV_EEG_CH)
380 m_selectionGroupsMap[
"All EEG"] = names;
383 QMapIterator<QString, QStringList> selectionIndex(m_selectionGroupsMap);
384 while (selectionIndex.hasNext()) {
385 selectionIndex.next();
386 ui->m_listWidget_selectionGroups->insertItem(ui->m_listWidget_selectionGroups->count(), selectionIndex.key());
390 updateSelectionGroupsList(
getItemForChName(ui->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
393 ui->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(ui->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
396 cleanUpMEGChannels();
404 void SelectionManagerWindow::cleanUpMEGChannels()
406 QMapIterator<QString,QStringList> selectionIndex(m_selectionGroupsMap);
409 while (selectionIndex.hasNext()) {
410 selectionIndex.next();
412 QStringList channelList = selectionIndex.value();
415 QMutableStringListIterator stringListIndex(channelList);
416 while (stringListIndex.hasNext()) {
417 stringListIndex.next();
419 if(!m_layoutMap.contains(stringListIndex.value()) && stringListIndex.value().contains(
"MEG"))
420 stringListIndex.remove();
424 m_selectionGroupsMap.insert(selectionIndex.key(), channelList);
431 void SelectionManagerWindow::updateSelectionGroupsList(QListWidgetItem* current, QListWidgetItem* previous)
438 if(current->text().contains(
"EEG"))
439 m_pSelectionScene->m_iChannelTypeMode = FIFFV_EEG_CH;
441 m_pSelectionScene->m_iChannelTypeMode = FIFFV_MEG_CH;
443 ui->m_listWidget_visibleChannels->clear();
446 ui->m_listWidget_visibleChannels->addItems(m_selectionGroupsMap[current->text()]);
458 void SelectionManagerWindow::updateSceneItems()
460 QStringList visibleItems;
462 for(
int i = 0; i<ui->m_listWidget_visibleChannels->count(); i++)
463 visibleItems << ui->m_listWidget_visibleChannels->item(i)->text();
465 m_pSelectionScene->
hideItems(visibleItems);
471 void SelectionManagerWindow::updateUserDefinedChannelsList()
473 QList<QGraphicsItem*> itemList = m_pSelectionScene->selectedItems();
474 QStringList userDefinedChannels;
476 for(
int i = 0; i<itemList.size(); i++) {
481 ui->m_listWidget_userDefined->clear();
482 ui->m_listWidget_userDefined->addItems(userDefinedChannels);
490 void SelectionManagerWindow::updateDataView()
493 QListWidget* targetListWidget;
494 if(ui->m_listWidget_userDefined->count()>0)
495 targetListWidget = ui->m_listWidget_userDefined;
497 targetListWidget = ui->m_listWidget_visibleChannels;
500 QStringList selectedChannels;
502 for(
int i = 0; i<targetListWidget->count(); i++) {
503 QListWidgetItem* item = targetListWidget->item(i);
506 if(indexTemp != -1) {
507 QModelIndex mappedNameIndex = m_pChInfoModel->index(indexTemp,1);
508 QString origChName = m_pChInfoModel->data(mappedNameIndex,ChInfoModelRoles::GetOrigChName).toString();
510 selectedChannels << origChName;
513 selectedChannels << item->text();
519 if(!m_pSelectionScene->selectedItems().empty())
524 QList<QGraphicsItem*> visibleItemList = m_pSelectionScene->items();
525 QMutableListIterator<QGraphicsItem*> i(visibleItemList);
526 while (i.hasNext()) {
527 if(!i.next()->isVisible())
538 void SelectionManagerWindow::resizeEvent(QResizeEvent* event)
549 bool SelectionManagerWindow::eventFilter(QObject *obj, QEvent *event)
552 if (obj == ui->m_listWidget_userDefined && event->type() == QEvent::KeyRelease) {
553 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
555 if(keyEvent->key() == Qt::Key_Delete) {
556 qDeleteAll(ui->m_listWidget_userDefined->selectedItems());
564 return QDockWidget::eventFilter(obj, event);
void repaintItems(const QMap< QString, QPointF > &layoutMap)
~SelectionManagerWindow()
void selectChannels(QStringList channelList)
QStringList getSelectedChannels()
The SelectionManagerWindow class provides a channel selection window.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
void selectionChanged(const QList< QGraphicsItem * > &selectedChannelItems)
The SelectionScene class provides a reimplemented QGraphicsScene for 2D layout plotting.
const QMap< QString, QPointF > & getLayoutMap()
void highlightChannels(QModelIndexList channelIndexList)
void showSelectedChannelsOnly(QStringList selectedChannels)
SelectionManagerWindow(QWidget *parent=0, ChInfoModel *pChInfoModel=0)
void hideItems(QStringList visibleItems)
The SelectionSceneItem class provides a new data structure for visualizing channels in a 2D layout...
Processes selection files (mne .sel) files which contain the chanels for each selection group...
void loadedLayoutMap(const QMap< QString, QPointF > &layoutMap)
bool readMNESelFile(QString path, QMap< QString, QStringList > &selectionMap)
QListWidgetItem * getItemForChName(QListWidget *listWidget, QString channelName)
void setCurrentlyMappedFiffChannels(const QStringList &mappedLayoutChNames)
int getIndexFromMappedChName(QString chName)