35 #include <QListWidgetItem>
37 #include <QHBoxLayout>
58 mPatientModelService(patientModelService)
62 this->setSelectionBehavior(QAbstractItemView::SelectItems);
63 this->setSelectionMode(QAbstractItemView::SingleSelection);
65 connect(
this, SIGNAL(itemSelectionChanged()),
this, SLOT(itemSelectionChangedSlot()));
68 this->setSizePolicy(QSizePolicy::Expanding, this->sizePolicy().verticalPolicy());
95 foreach(QString data, dataUids)
102 void DataListWidget::itemSelectionChangedSlot()
104 QList<QListWidgetItem*> items = this->selectedItems();
111 activeData->setActive(data);
121 QListWidgetItem* item =
new QListWidgetItem(data->getName());
122 item->setData(Qt::UserRole, uid);
125 item->setText(
" " + item->text());
127 item->setIcon(data->getIcon());
131 std::cout <<
"set " << item->text() <<
" before: " << after->text() <<
" " << this->currentRow() << std::endl;
132 this->setCurrentItem(after);
133 this->insertItem(this->currentRow(), item);
134 this->setCurrentItem(item);
141 item->setToolTip(item->text());
154 this->setDropIndicatorShown(
false);
155 this->setDragEnabled(
true);
157 connect(
mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()),
this, SLOT(populateAllDataList()));
158 this->populateAllDataList();
166 QListWidget::mousePressEvent(event);
171 QListWidget::mouseMoveEvent(event);
174 void AllDataListWidget::populateAllDataList()
180 QString lastDataActionUid =
"________________________";
181 for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
183 QString uid = (*iter)->getUid();
185 if (uid.contains(lastDataActionUid))
192 lastDataActionUid = uid;
210 this->setContextMenuPolicy(Qt::CustomContextMenu);
212 this->setDropIndicatorShown(
true);
213 this->setDragEnabled(
true);
214 this->setAcceptDrops(
true);
215 this->viewport()->setAcceptDrops(
true);
216 this->setDragDropOverwriteMode(
true);
219 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint &)),
this, SLOT(contextMenuSlot(
const QPoint &)));
230 QStringList data = this->
getData();
231 std::reverse(data.begin(), data.end());
233 mViewGroupData->clearData();
234 for (
int i=0; i<data.size(); ++i)
239 mViewGroupData->addData(current->getUid());
243 void SelectedDataListWidget::keyPressEvent(QKeyEvent* event)
245 if (event->matches(QKeySequence::Delete) ||
event->matches(QKeySequence::Back))
247 QList<QListWidgetItem*> items = this->selectedItems();
248 for (
int i=0; i<items.size(); ++i)
261 QMap<int, QVariant> v;
262 if (!mimeData->hasFormat(
"application/x-qabstractitemmodeldatalist"))
265 QByteArray itemData = mimeData->data(
"application/x-qabstractitemmodeldatalist");
266 QDataStream stream(&itemData, QIODevice::ReadOnly);
269 stream >> r >> c >> v;
284 if (event->source()==
this)
286 std::cout <<
"drop this: " <<
event->mimeData()->formats().join(
",") << std::endl;
287 event->setDropAction(Qt::MoveAction);
292 if (sourceData.contains(Qt::UserRole))
293 sourceUid = sourceData[Qt::UserRole].toString();
313 QListWidgetItem* itemToDelete = 0;
314 for(
int i=0; i < this->count(); ++i)
316 QListWidgetItem* item = this->item(i);
317 if (item->data(Qt::UserRole)==sourceUid)
326 QListWidget::dropEvent(event);
327 if (event->source()!=
this)
338 for(
int i=0; i < this->count(); ++i)
340 QListWidgetItem* item = this->item(i);
341 retval << item->data(Qt::UserRole).toString();
347 void SelectedDataListWidget::deleteSlot()
354 this->deleteItemSlot(mItemToDelete);
357 void SelectedDataListWidget::deleteItemSlot(QListWidgetItem* item)
364 void SelectedDataListWidget::contextMenuSlot(
const QPoint& point)
366 QWidget* sender =
dynamic_cast<QWidget*
>(this->sender());
367 QPoint pointGlobal = sender->mapToGlobal(point);
368 QMenu contextMenu(sender);
370 QAction* action =
new QAction(
"Remove", &contextMenu);
372 QListWidgetItem* item = this->itemAt(point);
377 mItemToDelete = item;
379 connect(action, SIGNAL(triggered()),
this, SLOT(deleteSlot()));
380 contextMenu.addAction(action);
382 contextMenu.exec(pointGlobal);
389 std::vector<DataPtr> sorted = mViewGroupData->getData();
390 std::reverse(sorted.begin(), sorted.end());
391 for (std::vector<DataPtr>::iterator iter=sorted.begin(); iter!=sorted.end(); ++iter)
393 QString uid = (*iter)->getUid();
408 mViewGroupData = viewGroupData;
435 if (event->source()==
this)
437 std::cout <<
"drop this: " <<
event->mimeData()->formats().join(
",") << std::endl;
438 event->setDropAction(Qt::MoveAction);
442 if (event->mimeData()->hasFormat(
"application/x-qabstractitemmodeldatalist"))
444 QByteArray itemData =
event->mimeData()->data(
"application/x-qabstractitemmodeldatalist");
445 QDataStream stream(&itemData, QIODevice::ReadOnly);
447 QMap<int, QVariant> v;
448 stream >> r >> c >> v;
449 std::cout <<
"var: " << r <<
" " << c <<
" " << v.size() << std::endl;
452 std::cout <<
"v: " <<
" " << v.begin()->typeName() <<
" " << v.begin()->toString() << std::endl;
453 newUid = v.begin()->toString();
457 QListWidgetItem* itemToDelete = 0;
458 for(
int i=0; i < this->count(); ++i)
460 QListWidgetItem* item = this->item(i);
461 if (item->text()==newUid)
469 std::cout <<
"dropaction " <<
event->dropAction() << std::endl;
470 QListWidget::dropEvent(event);
471 if (event->source()!=
this)
485 event->setDropAction(Qt::MoveAction);
486 event->acceptProposedAction();
493 mViewService(viewService)
496 QHBoxLayout* layout =
new QHBoxLayout(
this);
502 test->addItem(
"test1");
503 test->addItem(
"test2");
504 test->addItem(
"test3");
505 test->addItem(
"test4");
507 test->setDropIndicatorShown(
false);
508 test->setDragEnabled(
true);
509 test->setAcceptDrops(
true);
512 abra->addItem(
"abra1");
513 abra->addItem(
"abra2");
514 abra->addItem(
"abra3");
515 abra->addItem(
"abra4");
517 abra->setDropIndicatorShown(
true);
518 abra->setDragEnabled(
true);
519 abra->setAcceptDrops(
true);
520 abra->viewport()->setAcceptDrops(
true);
521 abra->setDragDropOverwriteMode(
true);
523 layout->addWidget(test);
524 layout->addWidget(abra);
527 QVBoxLayout* selLayout =
new QVBoxLayout;
528 mVisibleLabel =
new QLabel(
"Visible",
this);
529 selLayout->addWidget(mVisibleLabel);
530 selLayout->addWidget(mSelectedDataListWidget);
531 layout->addLayout(selLayout);
533 QVBoxLayout* allLayout =
new QVBoxLayout;
534 allLayout->addWidget(
new QLabel(
"All"));
535 allLayout->addWidget(mAllDataListWidget);
536 layout->addLayout(allLayout);
538 connect(mViewService.get(), SIGNAL(activeViewChanged()),
this, SLOT(viewGroupChangedSlot()));
539 this->viewGroupChangedSlot();
542 void DataViewSelectionWidget::viewGroupChangedSlot()
544 int vg = mViewService->getActiveGroupId();
552 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)
cxLogicManager_EXPORT ViewServicePtr viewService()
void reportDebug(QString msg)