53 using namespace DISPLIB;
60 : QStandardItemModel(pParent)
74 QStandardItem* pNewItem,
78 case BIDS_FUNCTIONALDATA:
79 case BIDS_ANATOMICALDATA:
80 case BIDS_BEHAVIORALDATA: {
81 if(!selectedItem.isValid()) {
84 if (itemFromIndex(selectedItem)->data(BIDS_ITEM_TYPE).value<int>() != BIDS_SUBJECT){
85 addDataToSession(itemFromIndex(selectedItem)->data(BIDS_ITEM_SESSION).value<QModelIndex>(),
89 qDebug() <<
"[BidsViewModel::addData] Prompt user to select a session";
96 if(!selectedItem.isValid()) {
97 QStandardItem* pItem =
new QStandardItem(
"Unknown");
98 pItem->setEditable(
false);
99 pItem->setDragEnabled(
true);
103 indexFromItem(pItem),
118 const QModelIndex &parentIndex,
121 QStandardItem* selectedData = itemFromIndex(parentIndex);
122 selectedData->setChild(selectedData->rowCount(),
125 pNewAvgItem->setData(itemFromIndex(parentIndex)->data(BIDS_ITEM_SUBJECT), BIDS_ITEM_SUBJECT);
126 pNewAvgItem->setData(itemFromIndex(parentIndex)->data(BIDS_ITEM_SESSION), BIDS_ITEM_SESSION);
127 pNewAvgItem->setData(QVariant::fromValue(iDataType), BIDS_ITEM_TYPE);
137 QString sNewSubjectName;
139 if(!sSubjectName.startsWith(
"sub-")){
140 sNewSubjectName =
"sub-" + sSubjectName;
142 sNewSubjectName = sSubjectName;
145 sNewSubjectName.remove(
" ");
148 QStandardItem* pSubjectItem =
new QStandardItem(sNewSubjectName);
149 appendRow(pSubjectItem);
151 pSubjectItem->setData(QVariant::fromValue(BIDS_SUBJECT), BIDS_ITEM_TYPE);
152 pSubjectItem->setData(QVariant::fromValue(pSubjectItem->index()), BIDS_ITEM_SUBJECT);
156 return pSubjectItem->index();
162 const QString &sSessionName)
165 QString sNewSessionName;
167 if(!sSessionName.startsWith(
"ses-")){
168 sNewSessionName =
"ses-" + sSessionName;
170 sNewSessionName = sSessionName;
173 sNewSessionName.remove(
" ");
175 QList<QStandardItem*> listItems = findItems(sSubjectName);
176 bool bRepeat =
false;
179 if (listItems.size() > 1) {
180 qWarning() <<
"[BidsViewModel::addSessionToSubject] Multiple subjects with same name";
182 }
else if (listItems.size() == 0) {
183 qWarning() <<
"[BidsViewModel::addSessionToSubject] No Subject found with name:" << sSubjectName;
184 return QModelIndex();
187 QStandardItem* pNewSessionItem;
190 for (
int i = 0; i < listItems.size(); i++){
191 QStandardItem* pSubjectItem = listItems.at(i);
194 pSubjectItem->setText(pSubjectItem->text() + QString::number(i + 1));
197 pNewSessionItem =
new QStandardItem(sNewSessionName);
198 pSubjectItem->setChild(pSubjectItem->rowCount(),
201 pNewSessionItem->setData(QVariant::fromValue(BIDS_SESSION), BIDS_ITEM_TYPE);
202 pNewSessionItem->setData(QVariant::fromValue(pSubjectItem->index()), BIDS_ITEM_SUBJECT);
203 pNewSessionItem->setData(QVariant::fromValue(pNewSessionItem->index()), BIDS_ITEM_SESSION);
208 return pNewSessionItem->index();
214 const QString &sSessionName)
217 QString sNewSessionName;
219 if(!sSessionName.startsWith(
"ses-")){
220 sNewSessionName =
"ses-" + sSessionName;
222 sNewSessionName = sSessionName;
225 sNewSessionName.remove(
" ");
227 QStandardItem* pSubjectItem = itemFromIndex(subjectIndex);
228 QStandardItem* pNewSessionItem =
new QStandardItem(sNewSessionName);
229 pSubjectItem->setChild(pSubjectItem->rowCount(),
232 pNewSessionItem->setData(QVariant::fromValue(BIDS_SESSION), BIDS_ITEM_TYPE);
233 pNewSessionItem->setData(QVariant::fromValue(subjectIndex), BIDS_ITEM_SUBJECT);
234 pNewSessionItem->setData(QVariant::fromValue(pNewSessionItem->index()), BIDS_ITEM_SESSION);
238 return pNewSessionItem->index();
244 QStandardItem *pNewItem,
247 QStandardItem* pSessionItem = itemFromIndex(sessionIndex);
248 bool bFolder =
false;
254 case BIDS_FUNCTIONALDATA:
255 sFolderName =
"func";
257 case BIDS_ANATOMICALDATA:
258 sFolderName =
"anat";
260 case BIDS_BEHAVIORALDATA:
263 sFolderName =
"unknown";
266 for(iFolder = 0; iFolder < pSessionItem->rowCount(); iFolder++){
267 if (pSessionItem->child(iFolder)->text() == sFolderName){
274 QStandardItem* pFunctionalItem =
new QStandardItem(sFolderName);
275 pFunctionalItem->setData(QVariant::fromValue(BIDS_FOLDER), BIDS_ITEM_TYPE);
276 pFunctionalItem->setData(QVariant::fromValue(sessionIndex), BIDS_ITEM_SESSION);
277 pFunctionalItem->setData(itemFromIndex(sessionIndex)->data(BIDS_ITEM_SUBJECT), BIDS_ITEM_SUBJECT);
279 pSessionItem->setChild(pSessionItem->rowCount(),
281 pFunctionalItem->setChild(pFunctionalItem->rowCount(),
284 pSessionItem->child(iFolder)->setChild(pSessionItem->child(iFolder)->rowCount(),
288 pNewItem->setData(QVariant::fromValue(iDataType), BIDS_ITEM_TYPE);
289 pNewItem->setData(QVariant::fromValue(sessionIndex), BIDS_ITEM_SESSION);
290 pNewItem->setData(itemFromIndex(sessionIndex)->data(BIDS_ITEM_SUBJECT), BIDS_ITEM_SUBJECT);
294 return pNewItem->index();
300 QModelIndex sessionIndex)
304 QStandardItem* subjectItem = itemFromIndex(subjectIndex);
305 QStandardItem* sessionItem = itemFromIndex(sessionIndex);
307 sessionItem->parent()->takeRow(sessionItem->row());
309 subjectItem->setChild(subjectItem->rowCount(), sessionItem);
310 subjectItem->setData(subjectIndex, BIDS_ITEM_SUBJECT);
312 for (
int i = 0; i < sessionItem->rowCount(); i++){
313 sessionItem->child(i)->setData(subjectIndex, BIDS_ITEM_SUBJECT);
314 for (
int j = 0; j < sessionItem->child(i)->rowCount(); j++) {
315 sessionItem->child(i)->child(j)->setData(subjectIndex, BIDS_ITEM_SUBJECT);
323 return sessionItem->index();
329 QModelIndex dataIndex)
333 QStandardItem* dataItem = itemFromIndex(dataIndex);
335 if(dataItem->parent()->rowCount() < 2){
336 QStandardItem* parent = dataItem->parent();
338 dataItem->parent()->takeRow(dataItem->row()).first();
339 parent->parent()->takeRow(parent->row()).first();
341 dataItem->parent()->takeRow(dataItem->row()).first();
344 QModelIndex newIndex;
359 dataItem->data(BIDS_ITEM_TYPE).value<
int>());
373 if(!itemIndex.isValid()){
379 QStandardItem* pItem = itemFromIndex(itemIndex);
381 qInfo() <<
"Deleting" << pItem->text();
383 switch(pItem->data(BIDS_ITEM_TYPE).value<
int>()){
385 if(removeRows(itemIndex.row(), 1, itemIndex.parent())){
390 if(removeRows(itemIndex.row(), 1, itemIndex.parent())){
394 case BIDS_BEHAVIORALDATA:
395 case BIDS_ANATOMICALDATA:
396 case BIDS_FUNCTIONALDATA:
397 if(removeRows(itemIndex.row(), 1, itemIndex.parent())){
404 if(removeRows(itemIndex.row(), 1, itemIndex.parent())){
409 if(removeRows(itemIndex.row(), 1, itemIndex.parent())){