14 #include <QListWidgetItem> 16 #include <QHBoxLayout> 37 mPatientModelService(patientModelService)
41 this->setSelectionBehavior(QAbstractItemView::SelectItems);
42 this->setSelectionMode(QAbstractItemView::SingleSelection);
44 connect(
this, SIGNAL(itemSelectionChanged()),
this, SLOT(itemSelectionChangedSlot()));
47 this->setSizePolicy(QSizePolicy::Expanding, this->sizePolicy().verticalPolicy());
74 foreach(QString data, dataUids)
81 void DataListWidget::itemSelectionChangedSlot()
83 QList<QListWidgetItem*> items = this->selectedItems();
90 activeData->setActive(data);
100 QListWidgetItem* item =
new QListWidgetItem(data->getName());
101 item->setData(Qt::UserRole, uid);
104 item->setText(
" " + item->text());
106 item->setIcon(data->getIcon());
110 std::cout <<
"set " << item->text() <<
" before: " << after->text() <<
" " << this->currentRow() << std::endl;
111 this->setCurrentItem(after);
112 this->insertItem(this->currentRow(), item);
113 this->setCurrentItem(item);
120 item->setToolTip(item->text());
133 this->setDropIndicatorShown(
false);
134 this->setDragEnabled(
true);
136 connect(
mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()),
this, SLOT(populateAllDataList()));
137 this->populateAllDataList();
145 QListWidget::mousePressEvent(event);
150 QListWidget::mouseMoveEvent(event);
153 void AllDataListWidget::populateAllDataList()
159 QString lastDataActionUid =
"________________________";
160 for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
162 QString uid = (*iter)->getUid();
164 if (uid.contains(lastDataActionUid))
171 lastDataActionUid = uid;
189 this->setContextMenuPolicy(Qt::CustomContextMenu);
191 this->setDropIndicatorShown(
true);
192 this->setDragEnabled(
true);
193 this->setAcceptDrops(
true);
194 this->viewport()->setAcceptDrops(
true);
195 this->setDragDropOverwriteMode(
true);
198 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint &)),
this, SLOT(contextMenuSlot(
const QPoint &)));
209 QStringList data = this->
getData();
210 std::reverse(data.begin(), data.end());
212 mViewGroupData->clearData();
213 for (
int i=0; i<data.size(); ++i)
218 mViewGroupData->addData(current->getUid());
222 void SelectedDataListWidget::keyPressEvent(QKeyEvent* event)
224 if (event->matches(QKeySequence::Delete) ||
event->matches(QKeySequence::Back))
226 QList<QListWidgetItem*> items = this->selectedItems();
227 for (
int i=0; i<items.size(); ++i)
240 QMap<int, QVariant> v;
241 if (!mimeData->hasFormat(
"application/x-qabstractitemmodeldatalist"))
244 QByteArray itemData = mimeData->data(
"application/x-qabstractitemmodeldatalist");
245 QDataStream stream(&itemData, QIODevice::ReadOnly);
248 stream >> r >> c >> v;
263 if (event->source()==
this)
265 std::cout <<
"drop this: " <<
event->mimeData()->formats().join(
",") << std::endl;
266 event->setDropAction(Qt::MoveAction);
271 if (sourceData.contains(Qt::UserRole))
272 sourceUid = sourceData[Qt::UserRole].
toString();
292 QListWidgetItem* itemToDelete = 0;
293 for(
int i=0; i < this->count(); ++i)
295 QListWidgetItem* item = this->item(i);
296 if (item->data(Qt::UserRole)==sourceUid)
305 QListWidget::dropEvent(event);
306 if (event->source()!=
this)
317 for(
int i=0; i < this->count(); ++i)
319 QListWidgetItem* item = this->item(i);
320 retval << item->data(Qt::UserRole).toString();
326 void SelectedDataListWidget::deleteSlot()
333 this->deleteItemSlot(mItemToDelete);
336 void SelectedDataListWidget::deleteItemSlot(QListWidgetItem* item)
343 void SelectedDataListWidget::contextMenuSlot(
const QPoint& point)
345 QWidget* sender =
dynamic_cast<QWidget*
>(this->sender());
346 QPoint pointGlobal = sender->mapToGlobal(point);
347 QMenu contextMenu(sender);
349 QAction* action =
new QAction(
"Remove", &contextMenu);
351 QListWidgetItem* item = this->itemAt(point);
356 mItemToDelete = item;
358 connect(action, SIGNAL(triggered()),
this, SLOT(deleteSlot()));
359 contextMenu.addAction(action);
361 contextMenu.exec(pointGlobal);
368 std::vector<DataPtr> sorted = mViewGroupData->getData();
369 std::reverse(sorted.begin(), sorted.end());
370 for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
372 QString uid = (*iter)->getUid();
387 mViewGroupData = viewGroupData;
414 if (event->source()==
this)
416 std::cout <<
"drop this: " <<
event->mimeData()->formats().join(
",") << std::endl;
417 event->setDropAction(Qt::MoveAction);
421 if (event->mimeData()->hasFormat(
"application/x-qabstractitemmodeldatalist"))
423 QByteArray itemData =
event->mimeData()->data(
"application/x-qabstractitemmodeldatalist");
424 QDataStream stream(&itemData, QIODevice::ReadOnly);
426 QMap<int, QVariant> v;
427 stream >> r >> c >> v;
428 std::cout <<
"var: " << r <<
" " << c <<
" " << v.size() << std::endl;
431 std::cout <<
"v: " <<
" " << v.begin()->typeName() <<
" " << v.begin()->toString() << std::endl;
432 newUid = v.begin()->toString();
436 QListWidgetItem* itemToDelete = 0;
437 for(
int i=0; i < this->count(); ++i)
439 QListWidgetItem* item = this->item(i);
440 if (item->text()==newUid)
448 std::cout <<
"dropaction " <<
event->dropAction() << std::endl;
449 QListWidget::dropEvent(event);
450 if (event->source()!=
this)
464 event->setDropAction(Qt::MoveAction);
465 event->acceptProposedAction();
472 mViewService(viewService)
475 QHBoxLayout* layout =
new QHBoxLayout(
this);
481 test->addItem(
"test1");
482 test->addItem(
"test2");
483 test->addItem(
"test3");
484 test->addItem(
"test4");
486 test->setDropIndicatorShown(
false);
487 test->setDragEnabled(
true);
488 test->setAcceptDrops(
true);
491 abra->addItem(
"abra1");
492 abra->addItem(
"abra2");
493 abra->addItem(
"abra3");
494 abra->addItem(
"abra4");
496 abra->setDropIndicatorShown(
true);
497 abra->setDragEnabled(
true);
498 abra->setAcceptDrops(
true);
499 abra->viewport()->setAcceptDrops(
true);
500 abra->setDragDropOverwriteMode(
true);
502 layout->addWidget(test);
503 layout->addWidget(abra);
506 QVBoxLayout* selLayout =
new QVBoxLayout;
507 mVisibleLabel =
new QLabel(
"Visible",
this);
508 selLayout->addWidget(mVisibleLabel);
509 selLayout->addWidget(mSelectedDataListWidget);
510 layout->addLayout(selLayout);
512 QVBoxLayout* allLayout =
new QVBoxLayout;
513 allLayout->addWidget(
new QLabel(
"All"));
514 allLayout->addWidget(mAllDataListWidget);
515 layout->addLayout(allLayout);
517 connect(mViewService.get(), SIGNAL(activeViewChanged()),
this, SLOT(viewGroupChangedSlot()));
518 this->viewGroupChangedSlot();
521 void DataViewSelectionWidget::viewGroupChangedSlot()
523 int vg = mViewService->getActiveGroupId();
531 mVisibleLabel->setText(
"Visible in group "+
qstring_cast(vg));
QString qstring_cast(const T &val)
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
std::string toString(T const &value)
converts any type to a string
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.