v2.0.0
Loading...
Searching...
No Matches
bidsview.cpp
Go to the documentation of this file.
1//=============================================================================================================
13
14//=============================================================================================================
15// INCLUDES
16//=============================================================================================================
17
18#include "bidsview.h"
19#include "ui_bidsview.h"
20
22
23//=============================================================================================================
24// QT INCLUDES
25//=============================================================================================================
26
27#include <QTreeView>
28#include <QStandardItemModel>
29#include <QDebug>
30#include <QMenu>
31#include <QKeyEvent>
32#include <QMessageBox>
33#include <QInputDialog>
34
35//=============================================================================================================
36// USED NAMESPACES
37//=============================================================================================================
38
39using namespace DISPLIB;
40
41//=============================================================================================================
42// DEFINE MEMBER METHODS
43//=============================================================================================================
44
45BidsView::BidsView(QWidget *parent)
46: AbstractView(parent)
47, m_pUi(new Ui::BidsViewWidget)
48{
49 m_pUi->setupUi(this);
50 m_pUi->m_pTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
51 connect(m_pUi->m_pTreeView, &QTreeView::customContextMenuRequested,
52 this, &BidsView::customMenuRequested, Qt::UniqueConnection);
53}
54
55//=============================================================================================================
56
58{
59 delete m_pUi;
60}
61
62//=============================================================================================================
63
64void BidsView::setModel(QAbstractItemModel *pModel)
65{
66 m_pUi->m_pTreeView->setModel(pModel);
67
68 connect(m_pUi->m_pTreeView->selectionModel(), &QItemSelectionModel::selectionChanged,
69 this, &BidsView::onCurrentItemChanged, Qt::UniqueConnection);
70// connect(static_cast<ANSHAREDLIB::AnalyzeDataModel*>(pModel), &ANSHAREDLIB::AnalyzeDataModel::newFileAdded,
71// this, &DataManagerControlView::onNewFileLoaded);
73 this, &BidsView::onNewItemIndex);
74
75 //Connect BIDS Model Functions
76 DISPLIB::BidsViewModel *pBidsModel = qobject_cast<DISPLIB::BidsViewModel *>(pModel);
77
78 //Adding
79 connect(this, &BidsView::onAddSubject,
80 pBidsModel, &BidsViewModel::addSubject);
81 connect(this, SIGNAL(onAddSession(QModelIndex, const QString&)),
82 pBidsModel, SLOT(addSessionToSubject(QModelIndex, const QString&)));
83
84 //Moving
85 connect(this, &BidsView::onMoveSession,
87 connect(this, &BidsView::onMoveData,
89
90 //Updating
91 connect(pBidsModel, &BidsViewModel::modelReset,
92 this, &BidsView::onModelReset);
93}
94
95//=============================================================================================================
96
97void BidsView::customMenuRequested(QPoint pos)
98{
99 QString sToolTip = m_pUi->m_pTreeView->model()->data(m_pUi->m_pTreeView->indexAt(pos), Qt::ToolTipRole).toString();
100
101 DISPLIB::BidsViewModel *pModel = qobject_cast<DISPLIB::BidsViewModel *>(m_pUi->m_pTreeView->model());
102
103 QAction* pRemoveAction;
104
105 if(m_pUi->m_pTreeView->indexAt(pos).isValid()){
106 QStandardItem* pItem = pModel->itemFromIndex(m_pUi->m_pTreeView->indexAt(pos));
107
108 switch (pItem->data(BIDS_ITEM_TYPE).value<int>()){
109 case BIDS_SUBJECT: {
110 QMenu *menu = new QMenu(this);
111
112 QAction* pAddSessionAction = new QAction("Add Session", this);
113 connect(pAddSessionAction, &QAction::triggered, [=, this]() {
114 bool ok;
115 QString text = QInputDialog::getText(this, tr("Adding Session"),
116 tr("Please name new session:"), QLineEdit::Normal,
117 "", &ok);
118 if (ok && !text.isEmpty()){
119 emit onAddSession(pItem->index(), text);
120 }
121 });
122
123 pRemoveAction = new QAction("Remove Subject", this);
124
125 menu->addAction(pAddSessionAction);
126 menu->addAction(pRemoveAction);
127 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
128 break;
129 }
130 case BIDS_SESSION: {
131 QMenu *menu = new QMenu(this);
132
133 pRemoveAction = new QAction("Remove Session", this);
134
135 QMenu* pMoveMenu = new QMenu("Move Session to ...");
136
137 //Find all available subjects
138 for(int i = 0; i < pModel->rowCount(); i++){
139 if(pModel->item(i)->index() != pItem->data(BIDS_ITEM_SUBJECT).value<QModelIndex>()){
140 qDebug() << "Relative model index" << pModel->item(i)->index();
141 qDebug() << "Relative item index" << pItem->data(BIDS_ITEM_SUBJECT).value<QModelIndex>();
142 QAction* pTargetAction = new QAction(pModel->item(i)->text());
143 connect(pTargetAction, &QAction::triggered, [=, this] () {
144 emit onMoveSession(pModel->item(i)->index(), pItem->index());
145 });
146 pMoveMenu->addAction(pTargetAction);
147 }
148 }
149
150 if (!pMoveMenu->isEmpty()){
151 menu->addMenu(pMoveMenu);
152 }
153 menu->addAction(pRemoveAction);
154 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
155 break;
156 }
159 case BIDS_FUNCTIONALDATA: {
160 QMenu *menu = new QMenu(this);
161
162 pRemoveAction = new QAction("Remove Data", this);
163
164 QMenu* pMoveMenu = new QMenu("Move Data to ...");
165
166 //Find all available sessions
167 for(int i = 0; i < pModel->rowCount(); i++){
168 QMenu* pSubjectMenu = new QMenu(pModel->item(i)->text());
169 for (int j = 0; j < pModel->item(i)->rowCount(); j++){
170 if(pModel->item(i)->child(j)->index() != pItem->data(BIDS_ITEM_SESSION).value<QModelIndex>()){
171 QAction* pTargetAction = new QAction(pModel->item(i)->child(j)->text());
172 connect(pTargetAction, &QAction::triggered, [=, this] {
173 emit onMoveData(pModel->item(i)->child(j)->index(), pItem->index());
174 });
175 pSubjectMenu->addAction(pTargetAction);
176 }
177 }
178 if(!pSubjectMenu->isEmpty()){
179 pMoveMenu->addMenu(pSubjectMenu);
180 }
181 }
182
183 if (!pMoveMenu->isEmpty()){
184 menu->addMenu(pMoveMenu);
185 }
186 menu->addAction(pRemoveAction);
187 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
188 break;
189 }
190 default:{
191 qDebug() << "DataManagerControlView::customMenuRequested - default";
192 QMenu *menu = new QMenu(this);
193
194 pRemoveAction = new QAction("Remove", this);
195 menu->addAction(pRemoveAction);
196 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
197 break;
198 }
199 }
200 connect(pRemoveAction, &QAction::triggered, [=, this]() {
201 QMessageBox msgBox;
202
203 msgBox.setText("Are you sure you want to remove " + pItem->text() + "?");
204 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
205 msgBox.setDefaultButton(QMessageBox::No);
206
207 int ret = msgBox.exec();
208
209 if(ret == QMessageBox::Yes) {
210 emit removeItem(m_pUi->m_pTreeView->indexAt(pos));
211 }
212 });
213 } else {
214 QMenu *menu = new QMenu(this);
215
216 QAction* pAddSubjectAction = new QAction("Add Subject", this);
217 connect(pAddSubjectAction, &QAction::triggered, [=, this]() {
218 bool ok;
219 QString text = QInputDialog::getText(this, tr("Adding Subject"),
220 tr("Please name new subject:"), QLineEdit::Normal,
221 "", &ok);
222 if (ok && !text.isEmpty()){
223 emit onAddSubject(text);
224 }
225 });
226
227 menu->addAction(pAddSubjectAction);
228 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
229 }
230}
231
232//=============================================================================================================
233
234void BidsView::onCurrentItemChanged(const QItemSelection &selected,
235 const QItemSelection &deselected)
236{
237 Q_UNUSED(deselected)
238 if(selected.indexes().empty()) {
239 return;
240 }
241
242 emit selectedItemChanged(selected.indexes().first());
243
244 if(QStandardItemModel *pModel = qobject_cast<QStandardItemModel *>(m_pUi->m_pTreeView->model())) {
245 if(QStandardItem* pItem = pModel->itemFromIndex(selected.indexes().first())) {
246 if(!pItem->data().isNull()) {
247 emit selectedModelChanged(pItem->data());
248 }
249 }
250 }
251}
252
253//=============================================================================================================
254
255void BidsView::onNewFileLoaded(int iSubject,
256 int iModel)
257{
258 m_pUi->m_pTreeView->selectionModel()->select(m_pUi->m_pTreeView->model()->index(iModel, 0, m_pUi->m_pTreeView->model()->index(iSubject, 0)),
259 QItemSelectionModel::ClearAndSelect);
260}
261
262//=============================================================================================================
263
264void BidsView::keyPressEvent(QKeyEvent *event)
265{
266 switch (event->key()) {
267 case Qt::Key_Delete:
268 if(m_pUi->m_pTreeView->model()->data(m_pUi->m_pTreeView->currentIndex(), Qt::ToolTipRole).toString() != "Subject item") {
269 emit removeItem(m_pUi->m_pTreeView->currentIndex());
270 }
271 break;
272
273 default:
274 QWidget::keyPressEvent(event);
275 }
276}
277
278//=============================================================================================================
279
280void BidsView::onNewItemIndex(QModelIndex itemIndex)
281{
282 m_pUi->m_pTreeView->selectionModel()->select(itemIndex, QItemSelectionModel::ClearAndSelect);
283 m_pUi->m_pTreeView->expand(itemIndex.parent());
284// m_pUi->m_pTreeView->expandRecursively(itemIndex);
285 m_pUi->m_pTreeView->expandAll();
286}
287
288//=============================================================================================================
289
291{
292
293}
294
295//=============================================================================================================
296
298{
299
300}
301
302//=============================================================================================================
303
305{
306 switch(mode) {
308 break;
309 default: // default is research mode
310 break;
311 }
312}
313
314//=============================================================================================================
315
317{
318 switch(mode) {
320 break;
321 default: // default is realtime mode
322 break;
323 }
324}
325
326//=============================================================================================================
327
328void BidsView::onModelReset()
329{
330 m_pUi->m_pTreeView->expandAll();
331}
332
333//=============================================================================================================
334
336{
337
338}
Tree view of the BIDS dataset hierarchy backed by BidsViewModel.
QStandardItemModel mirroring the BIDS dataset hierarchy (subjects / sessions / runs / derivatives).
#define BIDS_ITEM_SESSION
#define BIDS_ITEM_SUBJECT
#define BIDS_ITEM_TYPE
#define BIDS_BEHAVIORALDATA
#define BIDS_FUNCTIONALDATA
#define BIDS_SUBJECT
#define BIDS_SESSION
#define BIDS_ANATOMICALDATA
2-D display widgets and visualisation helpers (charts, topography, colour maps).
AbstractView(QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
void onAddSession(QModelIndex subjectIndex, const QString &sSessionName)
void onAddSubject(const QString &sSubjectName)
virtual void loadSettings()
Definition bidsview.cpp:297
void onMoveSession(QModelIndex subjectIndex, QModelIndex sessionIndex)
void selectedItemChanged(const QModelIndex &pIndex)
BidsView(QWidget *parent=0)
Definition bidsview.cpp:45
void onMoveData(QModelIndex sessionIndex, QModelIndex dataIndex)
void setModel(QAbstractItemModel *pModel)
Definition bidsview.cpp:64
virtual void updateGuiMode(GuiMode mode)
Definition bidsview.cpp:304
virtual ~BidsView()
Definition bidsview.cpp:57
virtual void saveSettings()
Definition bidsview.cpp:290
void selectedModelChanged(const QVariant &data)
virtual void updateProcessingMode(ProcessingMode mode)
Definition bidsview.cpp:316
void removeItem(const QModelIndex &pIndex)
QStandardItemModel mirroring the BIDS dataset hierarchy (subjects / sessions / runs / derivatives).
QModelIndex moveSessionToSubject(QModelIndex subjectIndex, QModelIndex sessionIndex)
void newItemIndex(QModelIndex itemIndex)
QModelIndex moveDataToSession(QModelIndex sessionIndex, QModelIndex dataIndex)
QModelIndex addSubject(const QString &sSubjectName)