Skip to content

Commit

Permalink
MAINT,DOC: Adjust organization of adding models, simplifing switch st…
Browse files Browse the repository at this point in the history
…atments, updating documentation and images
  • Loading branch information
gabrielbmotta authored and LorenzE committed Oct 26, 2020
1 parent ad068c6 commit c232db5
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ QStandardItem* AnalyzeData::addSubject(const QString &sSubjectName)

void AnalyzeData::newSelection(const QModelIndex &index)
{
switch(m_pData->itemFromIndex(index)->data(ITEM_TYPE).value<int>()){
case FUNCTIONALDATA:
m_SelectedData = index;
switch(m_pData->itemFromIndex(index)->data(BIDS_ITEM_TYPE).value<int>()){
case BIDS_FUNCTIONALDATA:
m_SelectedFunctionalData = index;
m_SelectedItem = index;
break;
default:
Expand Down
121 changes: 45 additions & 76 deletions applications/mne_analyze/libs/anShared/Management/analyzedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,75 +204,44 @@ class ANSHAREDSHARED_EXPORT AnalyzeData : public QObject
QSharedPointer<AbstractModel> temp = qSharedPointerCast<AbstractModel>(sm);
temp->setModelPath(sPath);

switch(temp->getType()){
case ANSHAREDLIB_FIFFRAW_MODEL: {
if(temp->isInit()) {
// add to record, and tell others about the new model
QStandardItem* pItem = new QStandardItem(temp->getModelName());
pItem->setEditable(false);
pItem->setDragEnabled(true);
pItem->setToolTip(temp->getModelPath());

QVariant data;
data.setValue(temp);
pItem->setData(data);
m_pData->addData(m_SelectedItem,
pItem,
FUNCTIONALDATA);
return sm;
} else {
return Q_NULLPTR;
}
}
case ANSHAREDLIB_ANNOTATION_MODEL: {
QStandardItem* pItem = new QStandardItem("Events - " + temp->getModelName());
pItem->setEditable(false);
pItem->setDragEnabled(true);
pItem->setToolTip(temp->getModelPath());

QVariant data;
data.setValue(temp);
pItem->setData(data);
m_pData->addData(m_SelectedItem,
pItem,
ANNOTATION);

return sm;
}
case ANSHAREDLIB_AVERAGING_MODEL: {
QStandardItem* pItem = new QStandardItem("Average - " + temp->getModelName());
pItem->setEditable(false);
pItem->setDragEnabled(true);
pItem->setToolTip(temp->getModelPath());

QVariant data;
data.setValue(temp);
pItem->setData(data);
m_pData->addData(m_SelectedItem,
pItem,
AVERAGE);

return sm;
}
case ANSHAREDLIB_BEMDATA_MODEL: {
QStandardItem* pItem = new QStandardItem(temp->getModelName());
pItem->setEditable(false);
pItem->setDragEnabled(true);
pItem->setToolTip(temp->getModelPath());

QVariant data;
data.setValue(temp);
pItem->setData(data);
int iType;
QModelIndex index;

m_pData->addData(m_SelectedItem,
pItem,
ANATOMYDATA);
return sm;
}
default: {
qDebug() << "[AnalyzData::loadModel] Model Type not supported";
}
switch(temp->getType()){
case ANSHAREDLIB_FIFFRAW_MODEL:
iType = BIDS_FUNCTIONALDATA;
index = m_SelectedItem;
break;
case ANSHAREDLIB_BEMDATA_MODEL:
iType = BIDS_ANATOMICALDATA;
index = m_SelectedItem;
break;
case ANSHAREDLIB_ANNOTATION_MODEL:
iType = BIDS_ANNOTATION;
index = m_SelectedFunctionalData;
break;
case ANSHAREDLIB_AVERAGING_MODEL:
iType = BIDS_AVERAGE;
index = m_SelectedFunctionalData;
break;
default:
iType = BIDS_UNKNOWN;
index = m_SelectedItem;
}

QStandardItem* pItem = new QStandardItem(temp->getModelName());
pItem->setEditable(false);
pItem->setDragEnabled(true);
pItem->setToolTip(temp->getModelPath());

QVariant data;
data.setValue(temp);
pItem->setData(data);
m_pData->addData(index,
pItem,
iType);
return sm;

}

//=========================================================================================================
Expand All @@ -291,17 +260,17 @@ class ANSHAREDSHARED_EXPORT AnalyzeData : public QObject
switch(temp->getType()){
case ANSHAREDLIB_AVERAGING_MODEL:
pItem->setData(data);
pItem->setData(QVariant::fromValue(AVERAGE), ITEM_TYPE);
pItem->setData(QVariant::fromValue(BIDS_AVERAGE), BIDS_ITEM_TYPE);
m_pData->addToData(pItem,
m_SelectedData,
AVERAGE);
m_SelectedFunctionalData,
BIDS_AVERAGE);
break;
case ANSHAREDLIB_ANNOTATION_MODEL:
pItem->setData(data);
pItem->setData(QVariant::fromValue(ANNOTATION), ITEM_TYPE);
pItem->setData(QVariant::fromValue(BIDS_ANNOTATION), BIDS_ITEM_TYPE);
m_pData->addToData(pItem,
m_SelectedData,
ANNOTATION);
m_SelectedFunctionalData,
BIDS_ANNOTATION);
break;
default:
qWarning() << "[AnalyzeData::addModel] Model type not supported";
Expand All @@ -311,10 +280,10 @@ class ANSHAREDSHARED_EXPORT AnalyzeData : public QObject
}

private:
QPointer<DISPLIB::BidsViewModel> m_pData; /**< The BidsViewModel that holds all the subject, session, and data items. */
QPointer<DISPLIB::BidsViewModel> m_pData; /**< The BidsViewModel that holds all the subject, session, and data items. */

QModelIndex m_SelectedItem; /**< Index of currently selected item */
QModelIndex m_SelectedData; /**< Index of currently selected data item */
QModelIndex m_SelectedItem; /**< Index of currently selected item */
QModelIndex m_SelectedFunctionalData; /**< Index of currently selected data item */

signals:
//=========================================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void CoRegistration::handleEvent(QSharedPointer<Event> e)
break;
case SELECTED_MODEL_CHANGED:
onModelChanged(e->getData().value<QSharedPointer<ANSHAREDLIB::AbstractModel> >());
break;
default:
qWarning() << "[CoRegistration::handleEvent] received an Event that is not handled by switch-cases";
break;
Expand Down
Binary file modified doc/gh-pages/images/analyze/mne_an_datamanager_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/gh-pages/images/analyze/mne_an_datamanager_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions doc/gh-pages/pages/development/analyze_datamodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ Return an appropriate value depending on how you are organizing or representing
### columnCount()

Return an appropriate value depending on how you are organizing or representing your data. The Annotation Model, for example, returns the number of columns of data it has to display.

## Loading/Adding to Data Loader and Data Manager

If your data model will be loading data from a file, make sure that file type is included in DataLoader::loadFilePath() so the user can load in that file type. To save to a file, implement the function saveToFile() from the AbstractModel, and ensure that your file type is included in DataLoader::onSaveFilePressed().

To add your model to the data manager, add it to either addModel or loadModel in AnalyzeData.h, depending on whether you will be loading data from inside the application or from a file. You need to define the type of data your model corresponds to, bidsviewmodel.h for possible types, or add a new one.
12 changes: 5 additions & 7 deletions doc/gh-pages/pages/learn/analyze_datamanager.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ nav_order: 2
---
# Data Manager

The Data Manager keeps track of the files and other types of data in MNE Analyze.
The Data Manager keeps track of and organizes files data in MNE Analyze.

![](../../images/analyze/mne_an_datamanager_1.png)

Loaded files from the Data Loader, and averages from the Averaging plugin, will be added here. These are grouped into subjects, which can be renamed by double clicking the name and inputting a new one.

![](../../images/analyze/mne_an_datamanager_2.png)

Items can be removed by right clicking and selecting `Remove`.
Any data loaded from files, or generated within the application will appear here. The organization follows [BIDS](https://bids.neuroimaging.io/) formatting, separating data into subjects and sessions. Any data derived from other data will appear as sub item, like events or averages that correspond to a file.

![](../../images/analyze/mne_an_datamanager_3.png)

You can select between fif files to pick which one to display in the [Data Viewer](analyze_rawdataviewer.md), and averages to pick which will be displayed in [Averaging](analyze_average.md).
Items can be removed by right clicking and selecting `Remove`, and can be moved into other available sessions or subjects.

You can select between .fif files and events to pick which one to display in the [Data Viewer](analyze_rawdataviewer.md), and averages to pick which will be displayed in [Averaging](analyze_average.md).
18 changes: 9 additions & 9 deletions libraries/disp/viewers/bidsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ void BidsView::customMenuRequested(QPoint pos)
if(m_pUi->m_pTreeView->indexAt(pos).isValid()){
QStandardItem* pItem = pModel->itemFromIndex(m_pUi->m_pTreeView->indexAt(pos));

switch (pItem->data(ITEM_TYPE).value<int>()){
case SUBJECT: {
switch (pItem->data(BIDS_ITEM_TYPE).value<int>()){
case BIDS_SUBJECT: {
QMenu *menu = new QMenu(this);

QAction* pAddSessionAction = new QAction("Add Session", this);
Expand All @@ -152,7 +152,7 @@ void BidsView::customMenuRequested(QPoint pos)
menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
break;
}
case SESSION: {
case BIDS_SESSION: {
QMenu *menu = new QMenu(this);

pRemoveAction = new QAction("Remove Session", this);
Expand All @@ -161,9 +161,9 @@ void BidsView::customMenuRequested(QPoint pos)

//Find all available subjects
for(int i = 0; i < pModel->rowCount(); i++){
if(pModel->item(i)->index() != pItem->data(ITEM_SUBJECT).value<QModelIndex>()){
if(pModel->item(i)->index() != pItem->data(BIDS_ITEM_SUBJECT).value<QModelIndex>()){
qDebug() << "Relative model index" << pModel->item(i)->index();
qDebug() << "Relative item index" << pItem->data(ITEM_SUBJECT).value<QModelIndex>();
qDebug() << "Relative item index" << pItem->data(BIDS_ITEM_SUBJECT).value<QModelIndex>();
QAction* pTargetAction = new QAction(pModel->item(i)->text());
connect(pTargetAction, &QAction::triggered, [=] () {
emit onMoveSession(pModel->item(i)->index(), pItem->index());
Expand All @@ -179,9 +179,9 @@ void BidsView::customMenuRequested(QPoint pos)
menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
break;
}
case BEHAVIORALDATA:
case ANATOMYDATA:
case FUNCTIONALDATA: {
case BIDS_BEHAVIORALDATA:
case BIDS_ANATOMICALDATA:
case BIDS_FUNCTIONALDATA: {
QMenu *menu = new QMenu(this);

pRemoveAction = new QAction("Remove Data", this);
Expand All @@ -192,7 +192,7 @@ void BidsView::customMenuRequested(QPoint pos)
for(int i = 0; i < pModel->rowCount(); i++){
QMenu* pSubjectMenu = new QMenu(pModel->item(i)->text());
for (int j = 0; j < pModel->item(i)->rowCount(); j++){
if(pModel->item(i)->child(j)->index() != pItem->data(ITEM_SESSION).value<QModelIndex>()){
if(pModel->item(i)->child(j)->index() != pItem->data(BIDS_ITEM_SESSION).value<QModelIndex>()){
QAction* pTargetAction = new QAction(pModel->item(i)->child(j)->text());
connect(pTargetAction, &QAction::triggered, [=] {
emit onMoveData(pModel->item(i)->child(j)->index(), pItem->index());
Expand Down
Loading

0 comments on commit c232db5

Please sign in to comment.