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 menu->setAttribute(Qt::WA_DeleteOnClose);
112
113 QAction* pAddSessionAction = new QAction("Add Session", this);
114 connect(pAddSessionAction, &QAction::triggered, [=, this]() {
115 bool ok;
116 QString text = QInputDialog::getText(this, tr("Adding Session"),
117 tr("Please name new session:"), QLineEdit::Normal,
118 "", &ok);
119 if (ok && !text.isEmpty()) {
120 emit onAddSession(pItem->index(), text);
121 }
122 });
123
124 pRemoveAction = new QAction("Remove Subject", this);
125
126 menu->addAction(pAddSessionAction);
127 menu->addAction(pRemoveAction);
128 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
129 break;
130 }
131 case BIDS_SESSION: {
132 QMenu* menu = new QMenu(this);
133 menu->setAttribute(Qt::WA_DeleteOnClose);
134
135 pRemoveAction = new QAction("Remove Session", this);
136
137 QMenu* pMoveMenu = new QMenu("Move Session to ...");
138
139 //Find all available subjects
140 for (int i = 0; i < pModel->rowCount(); i++) {
141 if (pModel->item(i)->index() != pItem->data(BIDS_ITEM_SUBJECT).value<QModelIndex>()) {
142 qDebug() << "Relative model index" << pModel->item(i)->index();
143 qDebug() << "Relative item index" << pItem->data(BIDS_ITEM_SUBJECT).value<QModelIndex>();
144 QAction* pTargetAction = new QAction(pModel->item(i)->text());
145 connect(pTargetAction, &QAction::triggered, [=, this]() {
146 emit onMoveSession(pModel->item(i)->index(), pItem->index());
147 });
148 pMoveMenu->addAction(pTargetAction);
149 }
150 }
151
152 if (!pMoveMenu->isEmpty()) {
153 menu->addMenu(pMoveMenu);
154 }
155 menu->addAction(pRemoveAction);
156 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
157 break;
158 }
161 case BIDS_FUNCTIONALDATA: {
162 QMenu* menu = new QMenu(this);
163 menu->setAttribute(Qt::WA_DeleteOnClose);
164
165 pRemoveAction = new QAction("Remove Data", this);
166
167 QMenu* pMoveMenu = new QMenu("Move Data to ...");
168
169 //Find all available sessions
170 for (int i = 0; i < pModel->rowCount(); i++) {
171 QMenu* pSubjectMenu = new QMenu(pModel->item(i)->text());
172 for (int j = 0; j < pModel->item(i)->rowCount(); j++) {
173 if (pModel->item(i)->child(j)->index() != pItem->data(BIDS_ITEM_SESSION).value<QModelIndex>()) {
174 QAction* pTargetAction = new QAction(pModel->item(i)->child(j)->text());
175 connect(pTargetAction, &QAction::triggered, [=, this] {
176 emit onMoveData(pModel->item(i)->child(j)->index(), pItem->index());
177 });
178 pSubjectMenu->addAction(pTargetAction);
179 }
180 }
181 if (!pSubjectMenu->isEmpty()) {
182 pMoveMenu->addMenu(pSubjectMenu);
183 }
184 }
185
186 if (!pMoveMenu->isEmpty()) {
187 menu->addMenu(pMoveMenu);
188 }
189 menu->addAction(pRemoveAction);
190 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
191 break;
192 }
193 default: {
194 qDebug() << "DataManagerControlView::customMenuRequested - default";
195 QMenu* menu = new QMenu(this);
196 menu->setAttribute(Qt::WA_DeleteOnClose);
197
198 pRemoveAction = new QAction("Remove", this);
199 menu->addAction(pRemoveAction);
200 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
201 break;
202 }
203 }
204 connect(pRemoveAction, &QAction::triggered, [=, this]() {
205 QMessageBox msgBox;
206
207 msgBox.setText("Are you sure you want to remove " + pItem->text() + "?");
208 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
209 msgBox.setDefaultButton(QMessageBox::No);
210
211 int ret = msgBox.exec();
212
213 if (ret == QMessageBox::Yes) {
214 emit removeItem(m_pUi->m_pTreeView->indexAt(pos));
215 }
216 });
217 } else {
218 QMenu* menu = new QMenu(this);
219 menu->setAttribute(Qt::WA_DeleteOnClose);
220
221 QAction* pAddSubjectAction = new QAction("Add Subject", this);
222 connect(pAddSubjectAction, &QAction::triggered, [=, this]() {
223 bool ok;
224 QString text = QInputDialog::getText(this, tr("Adding Subject"),
225 tr("Please name new subject:"), QLineEdit::Normal,
226 "", &ok);
227 if (ok && !text.isEmpty()) {
228 emit onAddSubject(text);
229 }
230 });
231
232 menu->addAction(pAddSubjectAction);
233 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
234 }
235}
236
237//=============================================================================================================
238
239void BidsView::onCurrentItemChanged(const QItemSelection& selected,
240 const QItemSelection& deselected)
241{
242 Q_UNUSED(deselected)
243 if (selected.indexes().empty()) {
244 return;
245 }
246
247 emit selectedItemChanged(selected.indexes().first());
248
249 if (QStandardItemModel* pModel = qobject_cast<QStandardItemModel*>(m_pUi->m_pTreeView->model())) {
250 if (QStandardItem* pItem = pModel->itemFromIndex(selected.indexes().first())) {
251 if (!pItem->data().isNull()) {
252 emit selectedModelChanged(pItem->data());
253 }
254 }
255 }
256}
257
258//=============================================================================================================
259
260void BidsView::onNewFileLoaded(int iSubject,
261 int iModel)
262{
263 m_pUi->m_pTreeView->selectionModel()->select(m_pUi->m_pTreeView->model()->index(iModel, 0, m_pUi->m_pTreeView->model()->index(iSubject, 0)),
264 QItemSelectionModel::ClearAndSelect);
265}
266
267//=============================================================================================================
268
269void BidsView::keyPressEvent(QKeyEvent* event)
270{
271 switch (event->key()) {
272 case Qt::Key_Delete:
273 if (m_pUi->m_pTreeView->model()->data(m_pUi->m_pTreeView->currentIndex(), Qt::ToolTipRole).toString() != "Subject item") {
274 emit removeItem(m_pUi->m_pTreeView->currentIndex());
275 }
276 break;
277
278 default:
279 QWidget::keyPressEvent(event);
280 }
281}
282
283//=============================================================================================================
284
285void BidsView::onNewItemIndex(QModelIndex itemIndex)
286{
287 m_pUi->m_pTreeView->selectionModel()->select(itemIndex, QItemSelectionModel::ClearAndSelect);
288 m_pUi->m_pTreeView->expand(itemIndex.parent());
289 // m_pUi->m_pTreeView->expandRecursively(itemIndex);
290 m_pUi->m_pTreeView->expandAll();
291}
292
293//=============================================================================================================
294
296{
297}
298
299//=============================================================================================================
300
302{
303}
304
305//=============================================================================================================
306
308{
309 switch (mode) {
311 break;
312 default: // default is research mode
313 break;
314 }
315}
316
317//=============================================================================================================
318
320{
321 switch (mode) {
323 break;
324 default: // default is realtime mode
325 break;
326 }
327}
328
329//=============================================================================================================
330
331void BidsView::onModelReset()
332{
333 m_pUi->m_pTreeView->expandAll();
334}
335
336//=============================================================================================================
337
339{
340}
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
Tree view of the BIDS dataset hierarchy backed by DISPLIB::BidsViewModel.
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:301
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:307
virtual ~BidsView()
Definition bidsview.cpp:57
virtual void saveSettings()
Definition bidsview.cpp:295
void selectedModelChanged(const QVariant &data)
virtual void updateProcessingMode(ProcessingMode mode)
Definition bidsview.cpp:319
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)