43 #include "ui_bidsview.h"
52 #include <QStandardItemModel>
56 #include <QMessageBox>
57 #include <QInputDialog>
63 using namespace DISPLIB;
71 , m_pUi(new Ui::BidsViewWidget)
74 m_pUi->m_pTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
75 connect(m_pUi->m_pTreeView, &QTreeView::customContextMenuRequested,
76 this, &BidsView::customMenuRequested, Qt::UniqueConnection);
90 m_pUi->m_pTreeView->setModel(pModel);
92 connect(m_pUi->m_pTreeView->selectionModel(), &QItemSelectionModel::selectionChanged,
93 this, &BidsView::onCurrentItemChanged, Qt::UniqueConnection);
97 this, &BidsView::onNewItemIndex);
105 connect(
this, SIGNAL(
onAddSession(QModelIndex,
const QString&)),
106 pBidsModel, SLOT(addSessionToSubject(QModelIndex,
const QString&)));
115 connect(pBidsModel, &BidsViewModel::modelReset,
116 this, &BidsView::onModelReset);
121 void BidsView::customMenuRequested(QPoint pos)
123 QString sToolTip = m_pUi->m_pTreeView->model()->data(m_pUi->m_pTreeView->indexAt(pos), Qt::ToolTipRole).toString();
127 QAction* pRemoveAction;
129 if(m_pUi->m_pTreeView->indexAt(pos).isValid()){
130 QStandardItem* pItem = pModel->itemFromIndex(m_pUi->m_pTreeView->indexAt(pos));
132 switch (pItem->data(BIDS_ITEM_TYPE).value<
int>()){
134 QMenu *menu =
new QMenu(
this);
136 QAction* pAddSessionAction =
new QAction(
"Add Session",
this);
137 connect(pAddSessionAction, &QAction::triggered, [=]() {
139 QString text = QInputDialog::getText(
this, tr(
"Adding Session"),
140 tr(
"Please name new session:"), QLineEdit::Normal,
142 if (ok && !text.isEmpty()){
147 pRemoveAction =
new QAction(
"Remove Subject",
this);
149 menu->addAction(pAddSessionAction);
150 menu->addAction(pRemoveAction);
151 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
155 QMenu *menu =
new QMenu(
this);
157 pRemoveAction =
new QAction(
"Remove Session",
this);
159 QMenu* pMoveMenu =
new QMenu(
"Move Session to ...");
162 for(
int i = 0; i < pModel->rowCount(); i++){
163 if(pModel->item(i)->index() != pItem->data(BIDS_ITEM_SUBJECT).value<QModelIndex>()){
164 qDebug() <<
"Relative model index" << pModel->item(i)->index();
165 qDebug() <<
"Relative item index" << pItem->data(BIDS_ITEM_SUBJECT).value<QModelIndex>();
166 QAction* pTargetAction =
new QAction(pModel->item(i)->text());
167 connect(pTargetAction, &QAction::triggered, [=] () {
168 emit
onMoveSession(pModel->item(i)->index(), pItem->index());
170 pMoveMenu->addAction(pTargetAction);
174 if (!pMoveMenu->isEmpty()){
175 menu->addMenu(pMoveMenu);
177 menu->addAction(pRemoveAction);
178 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
181 case BIDS_BEHAVIORALDATA:
182 case BIDS_ANATOMICALDATA:
183 case BIDS_FUNCTIONALDATA: {
184 QMenu *menu =
new QMenu(
this);
186 pRemoveAction =
new QAction(
"Remove Data",
this);
188 QMenu* pMoveMenu =
new QMenu(
"Move Data to ...");
191 for(
int i = 0; i < pModel->rowCount(); i++){
192 QMenu* pSubjectMenu =
new QMenu(pModel->item(i)->text());
193 for (
int j = 0; j < pModel->item(i)->rowCount(); j++){
194 if(pModel->item(i)->child(j)->index() != pItem->data(BIDS_ITEM_SESSION).value<QModelIndex>()){
195 QAction* pTargetAction =
new QAction(pModel->item(i)->child(j)->text());
196 connect(pTargetAction, &QAction::triggered, [=] {
197 emit
onMoveData(pModel->item(i)->child(j)->index(), pItem->index());
199 pSubjectMenu->addAction(pTargetAction);
202 if(!pSubjectMenu->isEmpty()){
203 pMoveMenu->addMenu(pSubjectMenu);
207 if (!pMoveMenu->isEmpty()){
208 menu->addMenu(pMoveMenu);
210 menu->addAction(pRemoveAction);
211 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
215 qDebug() <<
"DataManagerControlView::customMenuRequested - default";
216 QMenu *menu =
new QMenu(
this);
218 pRemoveAction =
new QAction(
"Remove",
this);
219 menu->addAction(pRemoveAction);
220 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
224 connect(pRemoveAction, &QAction::triggered, [=]() {
227 msgBox.setText(
"Are you sure you want to remove " + pItem->text() +
"?");
228 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
229 msgBox.setDefaultButton(QMessageBox::No);
231 int ret = msgBox.exec();
233 if(ret == QMessageBox::Yes) {
234 emit removeItem(m_pUi->m_pTreeView->indexAt(pos));
238 QMenu *menu =
new QMenu(
this);
240 QAction* pAddSubjectAction =
new QAction(
"Add Subject",
this);
241 connect(pAddSubjectAction, &QAction::triggered, [=]() {
243 QString text = QInputDialog::getText(
this, tr(
"Adding Subject"),
244 tr(
"Please name new subject:"), QLineEdit::Normal,
246 if (ok && !text.isEmpty()){
251 menu->addAction(pAddSubjectAction);
252 menu->popup(m_pUi->m_pTreeView->viewport()->mapToGlobal(pos));
258 void BidsView::onCurrentItemChanged(
const QItemSelection &selected,
259 const QItemSelection &deselected)
262 if(selected.indexes().empty()) {
268 if(QStandardItemModel *pModel = qobject_cast<QStandardItemModel *>(m_pUi->m_pTreeView->model())) {
269 if(QStandardItem* pItem = pModel->itemFromIndex(selected.indexes().first())) {
270 if(!pItem->data().isNull()) {
279 void BidsView::onNewFileLoaded(
int iSubject,
282 m_pUi->m_pTreeView->selectionModel()->select(m_pUi->m_pTreeView->model()->index(iModel, 0, m_pUi->m_pTreeView->model()->index(iSubject, 0)),
283 QItemSelectionModel::ClearAndSelect);
288 void BidsView::keyPressEvent(QKeyEvent *event)
290 switch (event->key()) {
292 if(m_pUi->m_pTreeView->model()->data(m_pUi->m_pTreeView->currentIndex(), Qt::ToolTipRole).toString() !=
"Subject item") {
293 emit
removeItem(m_pUi->m_pTreeView->currentIndex());
298 QWidget::keyPressEvent(event);
304 void BidsView::onNewItemIndex(QModelIndex itemIndex)
306 m_pUi->m_pTreeView->selectionModel()->select(itemIndex, QItemSelectionModel::ClearAndSelect);
307 m_pUi->m_pTreeView->expand(itemIndex.parent());
309 m_pUi->m_pTreeView->expandAll();
331 case GuiMode::Clinical:
343 case ProcessingMode::Offline:
352 void BidsView::onModelReset()
354 m_pUi->m_pTreeView->expandAll();