14 #include <QListWidgetItem> 16 #include <QHBoxLayout> 36 mPatientModelService(patientModelService)
40 this->setSelectionBehavior(QAbstractItemView::SelectItems);
41 this->setSelectionMode(QAbstractItemView::SingleSelection);
43 connect(
this, SIGNAL(itemSelectionChanged()),
this, SLOT(itemSelectionChangedSlot()));
46 this->setSizePolicy(QSizePolicy::Expanding, this->sizePolicy().verticalPolicy());
73 foreach(QString data, dataUids)
80 void DataListWidget::itemSelectionChangedSlot()
82 QList<QListWidgetItem*> items = this->selectedItems();
89 activeData->setActive(data);
99 QListWidgetItem* item =
new QListWidgetItem(data->getName());
100 item->setData(Qt::UserRole, uid);
103 item->setText(
" " + item->text());
105 item->setIcon(data->getIcon());
109 std::cout <<
"set " << item->text() <<
" before: " << after->text() <<
" " << this->currentRow() << std::endl;
110 this->setCurrentItem(after);
111 this->insertItem(this->currentRow(), item);
112 this->setCurrentItem(item);
119 item->setToolTip(item->text());
132 this->setDropIndicatorShown(
false);
133 this->setDragEnabled(
true);
135 connect(
mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()),
this, SLOT(populateAllDataList()));
136 this->populateAllDataList();
144 QListWidget::mousePressEvent(event);
149 QListWidget::mouseMoveEvent(event);
152 void AllDataListWidget::populateAllDataList()
158 QString lastDataActionUid =
"________________________";
159 for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
161 QString uid = (*iter)->getUid();
163 if (uid.contains(lastDataActionUid))
170 lastDataActionUid = uid;
188 this->setContextMenuPolicy(Qt::CustomContextMenu);
190 this->setDropIndicatorShown(
true);
191 this->setDragEnabled(
true);
192 this->setAcceptDrops(
true);
193 this->viewport()->setAcceptDrops(
true);
194 this->setDragDropOverwriteMode(
true);
197 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint &)),
this, SLOT(contextMenuSlot(
const QPoint &)));
208 QStringList data = this->
getData();
209 std::reverse(data.begin(), data.end());
211 mViewGroupData->clearData();
212 for (
int i=0; i<data.size(); ++i)
217 mViewGroupData->addData(current->getUid());
221 void SelectedDataListWidget::keyPressEvent(QKeyEvent* event)
223 if (event->matches(QKeySequence::Delete) ||
event->matches(QKeySequence::Back))
225 QList<QListWidgetItem*> items = this->selectedItems();
226 for (
int i=0; i<items.size(); ++i)
239 QMap<int, QVariant> v;
240 if (!mimeData->hasFormat(
"application/x-qabstractitemmodeldatalist"))
243 QByteArray itemData = mimeData->data(
"application/x-qabstractitemmodeldatalist");
244 QDataStream stream(&itemData, QIODevice::ReadOnly);
247 stream >> r >> c >> v;
262 if (event->source()==
this)
264 std::cout <<
"drop this: " <<
event->mimeData()->formats().join(
",") << std::endl;
265 event->setDropAction(Qt::MoveAction);
270 if (sourceData.contains(Qt::UserRole))
271 sourceUid = sourceData[Qt::UserRole].toString();
291 QListWidgetItem* itemToDelete = 0;
292 for(
int i=0; i < this->count(); ++i)
294 QListWidgetItem* item = this->item(i);
295 if (item->data(Qt::UserRole)==sourceUid)
304 QListWidget::dropEvent(event);
305 if (event->source()!=
this)
316 for(
int i=0; i < this->count(); ++i)
318 QListWidgetItem* item = this->item(i);
319 retval << item->data(Qt::UserRole).toString();
325 void SelectedDataListWidget::deleteSlot()
332 this->deleteItemSlot(mItemToDelete);
335 void SelectedDataListWidget::deleteItemSlot(QListWidgetItem* item)
342 void SelectedDataListWidget::contextMenuSlot(
const QPoint& point)
344 QWidget* sender =
dynamic_cast<QWidget*
>(this->sender());
345 QPoint pointGlobal = sender->mapToGlobal(point);
346 QMenu contextMenu(sender);
348 QAction* action =
new QAction(
"Remove", &contextMenu);
350 QListWidgetItem* item = this->itemAt(point);
355 mItemToDelete = item;
357 connect(action, SIGNAL(triggered()),
this, SLOT(deleteSlot()));
358 contextMenu.addAction(action);
360 contextMenu.exec(pointGlobal);
367 std::vector<DataPtr> sorted = mViewGroupData->getData();
368 std::reverse(sorted.begin(), sorted.end());
369 for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
371 QString uid = (*iter)->getUid();
386 mViewGroupData = viewGroupData;
413 if (event->source()==
this)
415 std::cout <<
"drop this: " <<
event->mimeData()->formats().join(
",") << std::endl;
416 event->setDropAction(Qt::MoveAction);
420 if (event->mimeData()->hasFormat(
"application/x-qabstractitemmodeldatalist"))
422 QByteArray itemData =
event->mimeData()->data(
"application/x-qabstractitemmodeldatalist");
423 QDataStream stream(&itemData, QIODevice::ReadOnly);
425 QMap<int, QVariant> v;
426 stream >> r >> c >> v;
427 std::cout <<
"var: " << r <<
" " << c <<
" " << v.size() << std::endl;
430 std::cout <<
"v: " <<
" " << v.begin()->typeName() <<
" " << v.begin()->toString() << std::endl;
431 newUid = v.begin()->toString();
435 QListWidgetItem* itemToDelete = 0;
436 for(
int i=0; i < this->count(); ++i)
438 QListWidgetItem* item = this->item(i);
439 if (item->text()==newUid)
447 std::cout <<
"dropaction " <<
event->dropAction() << std::endl;
448 QListWidget::dropEvent(event);
449 if (event->source()!=
this)
463 event->setDropAction(Qt::MoveAction);
464 event->acceptProposedAction();
471 mViewService(viewService)
474 QHBoxLayout* layout =
new QHBoxLayout(
this);
480 test->addItem(
"test1");
481 test->addItem(
"test2");
482 test->addItem(
"test3");
483 test->addItem(
"test4");
485 test->setDropIndicatorShown(
false);
486 test->setDragEnabled(
true);
487 test->setAcceptDrops(
true);
490 abra->addItem(
"abra1");
491 abra->addItem(
"abra2");
492 abra->addItem(
"abra3");
493 abra->addItem(
"abra4");
495 abra->setDropIndicatorShown(
true);
496 abra->setDragEnabled(
true);
497 abra->setAcceptDrops(
true);
498 abra->viewport()->setAcceptDrops(
true);
499 abra->setDragDropOverwriteMode(
true);
501 layout->addWidget(test);
502 layout->addWidget(abra);
505 QVBoxLayout* selLayout =
new QVBoxLayout;
506 mVisibleLabel =
new QLabel(
"Visible",
this);
507 selLayout->addWidget(mVisibleLabel);
508 selLayout->addWidget(mSelectedDataListWidget);
509 layout->addLayout(selLayout);
511 QVBoxLayout* allLayout =
new QVBoxLayout;
512 allLayout->addWidget(
new QLabel(
"All"));
513 allLayout->addWidget(mAllDataListWidget);
514 layout->addLayout(allLayout);
516 connect(mViewService.get(), SIGNAL(activeViewChanged()),
this, SLOT(viewGroupChangedSlot()));
517 this->viewGroupChangedSlot();
520 void DataViewSelectionWidget::viewGroupChangedSlot()
522 int vg = mViewService->getActiveGroupId();
530 mVisibleLabel->setText(
"Visible in group "+
qstring_cast(vg));
QString qstring_cast(const T &val)
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
TestClass(QWidget *parent)
boost::shared_ptr< class Data > DataPtr
std::vector< T > sortOnGroupsAndAcquisitionTime(std::map< QString, T > input)
AbraClass(QWidget *parent)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void dropEvent(QDropEvent *event)
void dropEvent(QDropEvent *event)
void dataViewPropertiesChanged(QString uid)
void reportDebug(QString msg)
Namespace for all CustusX production code.