35 #include <QListWidgetItem>
37 #include <QHBoxLayout>
64 this->setSelectionBehavior(QAbstractItemView::SelectItems);
65 this->setSelectionMode(QAbstractItemView::SingleSelection);
67 connect(
this, SIGNAL(itemSelectionChanged()),
this, SLOT(itemSelectionChangedSlot()));
70 this->setSizePolicy(QSizePolicy::Expanding, this->sizePolicy().verticalPolicy());
97 foreach(QString data, dataUids)
104 void DataListWidget::itemSelectionChangedSlot()
106 QList<QListWidgetItem*> items = this->selectedItems();
121 QListWidgetItem* item =
new QListWidgetItem(data->getName());
122 item->setData(Qt::UserRole, uid);
125 item->setText(
" " + item->text());
127 if (boost::dynamic_pointer_cast<Image>(data))
128 item->setIcon(QIcon(
":/icons/volume.png"));
130 item->setIcon(QIcon(
":/icons/surface.png"));
134 std::cout <<
"set " << item->text() <<
" before: " << after->text() <<
" " << this->currentRow() << std::endl;
135 this->setCurrentItem(after);
136 this->insertItem(this->currentRow(), item);
137 this->setCurrentItem(item);
144 item->setToolTip(item->text());
157 this->setDropIndicatorShown(
false);
158 this->setDragEnabled(
true);
160 connect(
patientService().
get(), SIGNAL(dataAddedOrRemoved()),
this, SLOT(populateAllDataList()));
168 QListWidget::mousePressEvent(event);
173 QListWidget::mouseMoveEvent(event);
176 void AllDataListWidget::populateAllDataList()
182 QString lastDataActionUid =
"________________________";
183 for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
185 QString uid = (*iter)->getUid();
187 if (uid.contains(lastDataActionUid))
194 lastDataActionUid = uid;
212 this->setContextMenuPolicy(Qt::CustomContextMenu);
214 this->setDropIndicatorShown(
true);
215 this->setDragEnabled(
true);
216 this->setAcceptDrops(
true);
217 this->viewport()->setAcceptDrops(
true);
218 this->setDragDropOverwriteMode(
true);
221 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint &)),
this, SLOT(contextMenuSlot(
const QPoint &)));
232 QStringList data = this->
getData();
233 std::reverse(data.begin(), data.end());
235 mViewGroupData->clearData();
236 for (
int i=0; i<data.size(); ++i)
241 mViewGroupData->addData(current->getUid());
245 void SelectedDataListWidget::keyPressEvent(QKeyEvent* event)
247 if (event->matches(QKeySequence::Delete) ||
event->matches(QKeySequence::Back))
249 QList<QListWidgetItem*> items = this->selectedItems();
250 for (
int i=0; i<items.size(); ++i)
263 QMap<int, QVariant> v;
264 if (!mimeData->hasFormat(
"application/x-qabstractitemmodeldatalist"))
267 QByteArray itemData = mimeData->data(
"application/x-qabstractitemmodeldatalist");
268 QDataStream stream(&itemData, QIODevice::ReadOnly);
271 stream >> r >> c >> v;
286 if (event->source()==
this)
288 std::cout <<
"drop this: " <<
event->mimeData()->formats().join(
",") << std::endl;
289 event->setDropAction(Qt::MoveAction);
294 if (sourceData.contains(Qt::UserRole))
295 sourceUid = sourceData[Qt::UserRole].toString();
315 QListWidgetItem* itemToDelete = 0;
316 for(
int i=0; i < this->count(); ++i)
318 QListWidgetItem* item = this->item(i);
319 if (item->data(Qt::UserRole)==sourceUid)
328 QListWidget::dropEvent(event);
329 if (event->source()!=
this)
340 for(
int i=0; i < this->count(); ++i)
342 QListWidgetItem* item = this->item(i);
343 retval << item->data(Qt::UserRole).toString();
349 void SelectedDataListWidget::deleteSlot()
356 this->deleteItemSlot(mItemToDelete);
359 void SelectedDataListWidget::deleteItemSlot(QListWidgetItem* item)
366 void SelectedDataListWidget::contextMenuSlot(
const QPoint& point)
368 QWidget* sender =
dynamic_cast<QWidget*
>(this->sender());
369 QPoint pointGlobal = sender->mapToGlobal(point);
370 QMenu contextMenu(sender);
372 QAction* action =
new QAction(
"Remove", &contextMenu);
374 QListWidgetItem* item = this->itemAt(point);
379 mItemToDelete = item;
381 connect(action, SIGNAL(triggered()),
this, SLOT(deleteSlot()));
382 contextMenu.addAction(action);
384 contextMenu.exec(pointGlobal);
391 std::vector<DataPtr> sorted = mViewGroupData->getData();
392 std::reverse(sorted.begin(), sorted.end());
393 for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
395 QString uid = (*iter)->getUid();
406 disconnect(mViewGroupData.get(), SIGNAL(initialized()),
this, SLOT(
populateList()));
407 disconnect(mViewGroupData.get(), SIGNAL(dataViewPropertiesChanged(QString)),
this, SLOT(
populateList()));
410 mViewGroupData = viewGroupData;
414 connect(mViewGroupData.get(), SIGNAL(initialized()),
this, SLOT(
populateList()));
415 connect(mViewGroupData.get(), SIGNAL(dataViewPropertiesChanged(QString)),
this, SLOT(
populateList()));
437 if (event->source()==
this)
439 std::cout <<
"drop this: " <<
event->mimeData()->formats().join(
",") << std::endl;
440 event->setDropAction(Qt::MoveAction);
444 if (event->mimeData()->hasFormat(
"application/x-qabstractitemmodeldatalist"))
446 QByteArray itemData =
event->mimeData()->data(
"application/x-qabstractitemmodeldatalist");
447 QDataStream stream(&itemData, QIODevice::ReadOnly);
449 QMap<int, QVariant> v;
450 stream >> r >> c >> v;
451 std::cout <<
"var: " << r <<
" " << c <<
" " << v.size() << std::endl;
454 std::cout <<
"v: " <<
" " << v.begin()->typeName() <<
" " << v.begin()->toString() << std::endl;
455 newUid = v.begin()->toString();
459 QListWidgetItem* itemToDelete = 0;
460 for(
int i=0; i < this->count(); ++i)
462 QListWidgetItem* item = this->item(i);
463 if (item->text()==newUid)
471 std::cout <<
"dropaction " <<
event->dropAction() << std::endl;
472 QListWidget::dropEvent(event);
473 if (event->source()!=
this)
487 event->setDropAction(Qt::MoveAction);
488 event->acceptProposedAction();
497 QHBoxLayout* layout =
new QHBoxLayout(
this);
503 test->addItem(
"test1");
504 test->addItem(
"test2");
505 test->addItem(
"test3");
506 test->addItem(
"test4");
508 test->setDropIndicatorShown(
false);
509 test->setDragEnabled(
true);
510 test->setAcceptDrops(
true);
513 abra->addItem(
"abra1");
514 abra->addItem(
"abra2");
515 abra->addItem(
"abra3");
516 abra->addItem(
"abra4");
518 abra->setDropIndicatorShown(
true);
519 abra->setDragEnabled(
true);
520 abra->setAcceptDrops(
true);
521 abra->viewport()->setAcceptDrops(
true);
522 abra->setDragDropOverwriteMode(
true);
524 layout->addWidget(test);
525 layout->addWidget(abra);
528 QVBoxLayout* selLayout =
new QVBoxLayout;
529 mVisibleLabel =
new QLabel(
"Visible",
this);
530 selLayout->addWidget(mVisibleLabel);
531 selLayout->addWidget(mSelectedDataListWidget);
532 layout->addLayout(selLayout);
534 QVBoxLayout* allLayout =
new QVBoxLayout;
535 allLayout->addWidget(
new QLabel(
"All"));
536 allLayout->addWidget(mAllDataListWidget);
537 layout->addLayout(allLayout);
539 connect(
viewService().
get(), SIGNAL(activeViewChanged()),
this, SLOT(viewGroupChangedSlot()));
540 this->viewGroupChangedSlot();
543 void DataViewSelectionWidget::viewGroupChangedSlot()
553 mVisibleLabel->setText(
"Visible in group "+
qstring_cast(vg));
QString qstring_cast(const T &val)
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
boost::shared_ptr< class Image > ImagePtr
TestClass(QWidget *parent)
boost::shared_ptr< class Data > DataPtr
std::vector< T > sortOnGroupsAndAcquisitionTime(std::map< QString, T > input)
AbraClass(QWidget *parent)
void dropEvent(QDropEvent *event)
void dropEvent(QDropEvent *event)
cxLogicManager_EXPORT ViewServicePtr viewService()
cxLogicManager_EXPORT PatientModelServicePtr patientService()
void reportDebug(QString msg)