42 #include "selectionmanagerwindow.h"
59 : QDockWidget(parent,Qt::Window)
61 , m_pChInfoModel(pChInfoModel)
67 initSelectionSceneView();
84 std::cout<<
"SelectionManagerWindow::setCurrentlyMappedFiffChannels"<<std::endl;
85 m_currentlyLoadedFiffChannels = mappedLayoutChNames;
88 ui->m_listWidget_visibleChannels->clear();
91 ui->m_listWidget_selectionGroups->clear();
94 m_selectionGroupsMap[
"All"] = m_currentlyLoadedFiffChannels;
97 QMapIterator<QString, QStringList> selectionIndex(m_selectionGroupsMap);
98 while (selectionIndex.hasNext()) {
99 selectionIndex.next();
100 ui->m_listWidget_selectionGroups->insertItem(ui->m_listWidget_selectionGroups->count(), selectionIndex.key());
104 ui->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(ui->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
107 updateSelectionGroupsList(
getItemForChName(ui->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
115 QStringList channelList;
116 for(
int i = 0; i<channelIndexList.size(); i++) {
117 QModelIndex nameIndex = m_pChInfoModel->index(channelIndexList.at(i).row(),3);
118 channelList<<m_pChInfoModel->data(nameIndex, ChInfoModelRoles::GetMappedLayoutChName).toString();
121 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
123 for(
int i = 0; i<allSceneItems.size(); i++) {
131 m_pSelectionScene->update();
139 QList<QGraphicsItem *> allSceneItems = m_pSelectionScene->items();
141 for(
int i = 0; i<allSceneItems.size(); i++) {
144 item->setSelected(
true);
146 item->setSelected(
false);
149 m_pSelectionScene->update();
158 QListWidget* targetListWidget;
159 if(ui->m_listWidget_userDefined->count()>0)
160 targetListWidget = ui->m_listWidget_userDefined;
162 targetListWidget = ui->m_listWidget_visibleChannels;
165 QStringList selectedChannels;
167 for(
int i = 0; i<targetListWidget->count(); i++) {
168 QListWidgetItem* item = targetListWidget->item(i);
169 selectedChannels << item->text();
172 return selectedChannels;
180 for(
int i=0; i<listWidget->count(); i++)
181 if(listWidget->item(i)->text() == channelName)
182 return listWidget->item(i);
184 return new QListWidgetItem();
200 loadLayout(ui->m_comboBox_layoutFile->currentText());
206 void SelectionManagerWindow::initListWidgets()
209 ui->m_listWidget_userDefined->installEventFilter(
this);
212 connect(ui->m_listWidget_selectionGroups, &QListWidget::currentItemChanged,
213 this, &SelectionManagerWindow::updateSelectionGroupsList);
216 connect(ui->m_listWidget_userDefined->model(), &QAbstractTableModel::dataChanged,
217 this, &SelectionManagerWindow::updateDataView);
223 void SelectionManagerWindow::initSelectionSceneView()
226 m_pSelectionScene =
new SelectionScene(ui->m_graphicsView_layoutPlot);
227 ui->m_graphicsView_layoutPlot->setScene(m_pSelectionScene);
229 connect(m_pSelectionScene, &QGraphicsScene::selectionChanged,
230 this, &SelectionManagerWindow::updateUserDefinedChannelsList);
236 void SelectionManagerWindow::initComboBoxes()
238 ui->m_comboBox_layoutFile->clear();
239 ui->m_comboBox_layoutFile->insertItems(0, QStringList()
240 << QApplication::translate(
"SelectionManagerWindow",
"Vectorview-grad.lout", 0)
241 << QApplication::translate(
"SelectionManagerWindow",
"Vectorview-all.lout", 0)
242 << QApplication::translate(
"SelectionManagerWindow",
"Vectorview-mag.lout", 0)
243 << QApplication::translate(
"SelectionManagerWindow",
"babymeg-mag-inner-layer.lout", 0)
244 << QApplication::translate(
"SelectionManagerWindow",
"babymeg-mag-outer-layer.lout", 0)
245 << QApplication::translate(
"SelectionManagerWindow",
"babymeg-mag-ref.lout", 0)
249 ui->m_comboBox_selectionFiles->clear();
250 ui->m_comboBox_selectionFiles->insertItems(0, QStringList()
251 << QApplication::translate(
"SelectionManagerWindow",
"mne_browse_raw_vv.sel", 0)
252 << QApplication::translate(
"SelectionManagerWindow",
"mne_browse_raw_vv_new.sel", 0)
258 connect(ui->m_comboBox_selectionFiles, &QComboBox::currentTextChanged,
259 this, &SelectionManagerWindow::loadSelectionGroups);
261 connect(ui->m_comboBox_layoutFile, &QComboBox::currentTextChanged,
262 this, &SelectionManagerWindow::loadLayout);
265 loadLayout(
"Vectorview-grad.lout");
271 bool SelectionManagerWindow::loadLayout(QString path)
274 QString newPath = QCoreApplication::applicationDirPath() + path.prepend(
"/MNE_Browse_Raw_Resources/Templates/Layouts/");
279 loadSelectionGroups(ui->m_comboBox_selectionFiles->currentText());
282 QList<QVector<double> > inputPoints;
283 QList<QVector<double> > outputPoints;
287 for(
int i = 0; i<m_pChInfoModel->
rowCount(); i++) {
288 QModelIndex digIndex = m_pChInfoModel->index(i,1);
289 QString chName = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetOrigChName).toString();
291 digIndex = m_pChInfoModel->index(i,8);
292 QVector3D channelDig = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetChDigitizer).value<QVector3D>();
294 digIndex = m_pChInfoModel->index(i,4);
295 int kind = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetChKind).toInt();
297 if(kind == FIFFV_EEG_CH) {
298 QVector<double> temp;
299 temp.append(channelDig.x());
300 temp.append(channelDig.y());
301 temp.append(-channelDig.z());
302 inputPoints.append(temp);
313 if(inputPoints.size()>0)
314 while(numberTries<10) {
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 m_selectionGroupsMap.clear();
363 bool state = manager->
readMNESelFile(newPath, m_selectionGroupsMap);
366 m_selectionGroupsMap[
"All"] = m_currentlyLoadedFiffChannels;
369 for(
int i = 0; i<m_pChInfoModel->
rowCount(); i++) {
370 QModelIndex digIndex = m_pChInfoModel->index(i,1);
371 QString chName = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetOrigChName).toString();
373 digIndex = m_pChInfoModel->index(i,4);
374 int kind = m_pChInfoModel->data(digIndex,ChInfoModelRoles::GetChKind).toInt();
376 if(kind == FIFFV_EEG_CH)
381 m_selectionGroupsMap[
"All EEG"] = names;
384 QMapIterator<QString, QStringList> selectionIndex(m_selectionGroupsMap);
385 while (selectionIndex.hasNext()) {
386 selectionIndex.next();
387 ui->m_listWidget_selectionGroups->insertItem(ui->m_listWidget_selectionGroups->count(), selectionIndex.key());
391 updateSelectionGroupsList(
getItemForChName(ui->m_listWidget_selectionGroups,
"All"),
new QListWidgetItem());
394 ui->m_listWidget_selectionGroups->setCurrentItem(
getItemForChName(ui->m_listWidget_selectionGroups,
"All"), QItemSelectionModel::Select);
397 cleanUpMEGChannels();
405 void SelectionManagerWindow::cleanUpMEGChannels()
407 QMapIterator<QString,QStringList> selectionIndex(m_selectionGroupsMap);
410 while (selectionIndex.hasNext()) {
411 selectionIndex.next();
413 QStringList channelList = selectionIndex.value();
416 QMutableStringListIterator stringListIndex(channelList);
417 while (stringListIndex.hasNext()) {
418 stringListIndex.next();
420 if(!m_layoutMap.contains(stringListIndex.value()) && stringListIndex.value().contains(
"MEG"))
421 stringListIndex.remove();
425 m_selectionGroupsMap.insert(selectionIndex.key(), channelList);
432 void SelectionManagerWindow::updateSelectionGroupsList(QListWidgetItem* current, QListWidgetItem* previous)
439 if(current->text().contains(
"EEG"))
440 m_pSelectionScene->m_iChannelTypeMode = FIFFV_EEG_CH;
442 m_pSelectionScene->m_iChannelTypeMode = FIFFV_MEG_CH;
444 ui->m_listWidget_visibleChannels->clear();
447 ui->m_listWidget_visibleChannels->addItems(m_selectionGroupsMap[current->text()]);
459 void SelectionManagerWindow::updateSceneItems()
461 QStringList visibleItems;
463 for(
int i = 0; i<ui->m_listWidget_visibleChannels->count(); i++)
464 visibleItems << ui->m_listWidget_visibleChannels->item(i)->text();
466 m_pSelectionScene->
hideItems(visibleItems);
472 void SelectionManagerWindow::updateUserDefinedChannelsList()
474 QList<QGraphicsItem*> itemList = m_pSelectionScene->selectedItems();
475 QStringList userDefinedChannels;
477 for(
int i = 0; i<itemList.size(); i++) {
482 ui->m_listWidget_userDefined->clear();
483 ui->m_listWidget_userDefined->addItems(userDefinedChannels);
491 void SelectionManagerWindow::updateDataView()
494 QListWidget* targetListWidget;
495 if(ui->m_listWidget_userDefined->count()>0)
496 targetListWidget = ui->m_listWidget_userDefined;
498 targetListWidget = ui->m_listWidget_visibleChannels;
501 QStringList selectedChannels;
503 for(
int i = 0; i<targetListWidget->count(); i++) {
504 QListWidgetItem* item = targetListWidget->item(i);
507 if(indexTemp != -1) {
508 QModelIndex mappedNameIndex = m_pChInfoModel->index(indexTemp,1);
509 QString origChName = m_pChInfoModel->data(mappedNameIndex,ChInfoModelRoles::GetOrigChName).toString();
511 selectedChannels << origChName;
514 selectedChannels << item->text();
520 if(!m_pSelectionScene->selectedItems().empty())
525 QList<QGraphicsItem*> visibleItemList = m_pSelectionScene->items();
526 QMutableListIterator<QGraphicsItem*> i(visibleItemList);
527 while (i.hasNext()) {
528 if(!i.next()->isVisible())
539 void SelectionManagerWindow::resizeEvent(QResizeEvent* event)
550 bool SelectionManagerWindow::eventFilter(QObject *obj, QEvent *event)
553 if (obj == ui->m_listWidget_userDefined && event->type() == QEvent::KeyRelease) {
554 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
556 if(keyEvent->key() == Qt::Key_Delete) {
557 qDeleteAll(ui->m_listWidget_userDefined->selectedItems());
565 return QDockWidget::eventFilter(obj, event);
void selectChannels(QStringList channelList)
void setCurrentlyMappedFiffChannels(const QStringList &mappedLayoutChNames)
QStringList getSelectedChannels()
int getIndexFromMappedChName(QString chName)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
static bool readMNELoutFile(QString path, QMap< QString, QPointF > &channelData)
void showSelectedChannelsOnly(QStringList selectedChannels)
The SelectionManagerWindow class provides a channel selection window.
void loadedLayoutMap(const QMap< QString, QPointF > &layoutMap)
The SelectionScene class provides a reimplemented QGraphicsScene for 2D layout plotting.
static bool makeLayout(const QList< QVector< double > > &inputPoints, QList< QVector< double > > &outputPoints, const QStringList &names, QFile &outFile, bool do_fit, float prad, float w, float h, bool writeFile=false)
void highlightChannels(QModelIndexList channelIndexList)
const QMap< QString, QPointF > & getLayoutMap()
void hideItems(QStringList visibleItems)
SelectionManagerWindow(QWidget *parent=0, ChInfoModel *pChInfoModel=0)
void selectionChanged(const QList< QGraphicsItem * > &selectedChannelItems)
void repaintItems(const QMap< QString, QPointF > &layoutMap)
Processes selection files (mne .sel) files which contain the chanels for each selection group...
bool readMNESelFile(QString path, QMap< QString, QStringList > &selectionMap)
~SelectionManagerWindow()
QListWidgetItem * getItemForChName(QListWidget *listWidget, QString channelName)
The SelectionSceneItem class provides a new data structure for visualizing channels in a 2D layout...