##// END OF EJS Templates
Drop of events on a catalogue
trabillard -
r1261:829045cd6b75
parent child
Show More
@@ -62,6 +62,12 public:
62 62
63 63 void saveAll();
64 64
65 /// Returns the MIME data associated to a list of variables
66 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
67
68 /// Returns the list of variables contained in a MIME data
69 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
70
65 71 public slots:
66 72 /// Manage init/end of the controller
67 73 void initialize();
@@ -12,6 +12,7
12 12 #include <DBTag.h>
13 13 #include <IRequestPredicate.h>
14 14
15 #include <QDataStream>
15 16 #include <QMutex>
16 17 #include <QThread>
17 18
@@ -236,6 +237,46 void CatalogueController::saveAll()
236 237 impl->savAllDB();
237 238 }
238 239
240 QByteArray
241 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
242 {
243 auto encodedData = QByteArray{};
244
245 QMap<QString, QVariantList> idsPerRepository;
246 for (auto event : events) {
247 idsPerRepository[event->getRepository()] << event->getUniqId();
248 }
249
250 QDataStream stream{&encodedData, QIODevice::WriteOnly};
251 stream << idsPerRepository;
252
253 return encodedData;
254 }
255
256 QVector<std::shared_ptr<DBEvent> >
257 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
258 {
259 auto events = QVector<std::shared_ptr<DBEvent> >{};
260 QDataStream stream{mimeData};
261
262 QMap<QString, QVariantList> idsPerRepository;
263 stream >> idsPerRepository;
264
265 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
266 auto repository = it.key();
267 auto allRepositoryEvent = retrieveEvents(repository);
268 for (auto uuid : it.value()) {
269 for (auto repositoryEvent : allRepositoryEvent) {
270 if (uuid.toUuid() == repositoryEvent->getUniqId()) {
271 events << repositoryEvent;
272 }
273 }
274 }
275 }
276
277 return events;
278 }
279
239 280 void CatalogueController::initialize()
240 281 {
241 282 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
@@ -25,6 +25,7 public:
25 25 virtual Qt::ItemFlags flags(int column) const;
26 26 virtual bool setData(int column, int role, const QVariant &value);
27 27 virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action);
28 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action);
28 29
29 30 private:
30 31 class CatalogueAbstractTreeItemPrivate;
@@ -15,6 +15,7 public:
15 15 bool setData(int column, int role, const QVariant &value) override;
16 16 Qt::ItemFlags flags(int column) const override;
17 17 bool canDropMimeData(const QMimeData *data, Qt::DropAction action) override;
18 bool dropMimeData(const QMimeData *data, Qt::DropAction action) override;
18 19
19 20 /// Returns the catalogue represented by the item
20 21 std::shared_ptr<DBCatalogue> catalogue() const;
@@ -16,6 +16,7 class CatalogueTreeModel : public QAbstractItemModel {
16 16
17 17 signals:
18 18 void itemRenamed(const QModelIndex &index);
19 void itemDropped(const QModelIndex &parentIndex);
19 20
20 21 public:
21 22 CatalogueTreeModel(QObject *parent = nullptr);
@@ -1,5 +1,6
1 1 #include "Catalogue/CatalogueEventsModel.h"
2 2
3 #include <Catalogue/CatalogueController.h>
3 4 #include <Common/DateUtils.h>
4 5 #include <Common/MimeTypesDef.h>
5 6 #include <DBEvent.h>
@@ -370,7 +371,7 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
370 371
371 372 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
372 373 {
373 return Qt::CopyAction | Qt::MoveAction;
374 return Qt::CopyAction;
374 375 }
375 376
376 377 QStringList CatalogueEventsModel::mimeTypes() const
@@ -415,9 +416,10 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
415 416 }
416 417 }
417 418
418 auto eventsEncodedData
419 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
420 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
419 if (!eventList.isEmpty() && eventProductList.isEmpty()) {
420 auto eventsEncodedData = sqpApp->catalogueController().mimeDataForEvents(eventList);
421 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
422 }
421 423
422 424 if (eventList.count() + eventProductList.count() == 1) {
423 425 // No time range MIME data if multiple events are dragged
@@ -35,6 +35,62 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
35 35 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
36 36 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
37 37 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
38
39 int selectionType(QTreeView *treeView) const
40 {
41 auto selectedItems = treeView->selectionModel()->selectedRows();
42 if (selectedItems.isEmpty()) {
43 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
44 }
45 else {
46 auto firstIndex = selectedItems.first();
47 auto firstItem = m_TreeModel->item(firstIndex);
48 if (!firstItem) {
49 Q_ASSERT(false);
50 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
51 }
52 auto selectionType = firstItem->type();
53
54 for (auto itemIndex : selectedItems) {
55 auto item = m_TreeModel->item(itemIndex);
56 if (!item || item->type() != selectionType) {
57 // Incoherent multi selection
58 selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE;
59 break;
60 }
61 }
62
63 return selectionType;
64 }
65 }
66
67 QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const
68 {
69 QVector<std::shared_ptr<DBCatalogue> > catalogues;
70 auto selectedItems = treeView->selectionModel()->selectedRows();
71 for (auto itemIndex : selectedItems) {
72 auto item = m_TreeModel->item(itemIndex);
73 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
74 catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue());
75 }
76 }
77
78 return catalogues;
79 }
80
81 QStringList selectedRepositories(QTreeView *treeView) const
82 {
83 QStringList repositories;
84 auto selectedItems = treeView->selectionModel()->selectedRows();
85 for (auto itemIndex : selectedItems) {
86 auto item = m_TreeModel->item(itemIndex);
87 if (item && item->type() == DATABASE_ITEM_TYPE) {
88 repositories.append(item->text());
89 }
90 }
91
92 return repositories;
93 }
38 94 };
39 95
40 96 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
@@ -55,63 +111,25 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
55 111
56 112 auto emitSelection = [this]() {
57 113
58 auto selectedItems = ui->treeView->selectionModel()->selectedRows();
59 if (selectedItems.isEmpty()) {
60 emit this->selectionCleared();
114 auto selectionType = impl->selectionType(ui->treeView);
115
116 switch (selectionType) {
117 case CATALOGUE_ITEM_TYPE:
118 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
119 break;
120 case DATABASE_ITEM_TYPE:
121 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
122 break;
123 case ALL_EVENT_ITEM_TYPE:
124 emit this->allEventsSelected();
125 break;
126 case TRASH_ITEM_TYPE:
127 emit this->trashSelected();
128 break;
129 default:
130 emit this->selectionCleared();
131 break;
61 132 }
62 else {
63 QVector<std::shared_ptr<DBCatalogue> > catalogues;
64 QStringList databases;
65 auto firstIndex = selectedItems.first();
66 auto firstItem = impl->m_TreeModel->item(firstIndex);
67 if (!firstItem) {
68 Q_ASSERT(false);
69 return;
70 }
71 auto selectionType = firstItem->type();
72
73 for (auto itemIndex : selectedItems) {
74 auto item = impl->m_TreeModel->item(itemIndex);
75 if (item && item->type() == selectionType) {
76 switch (selectionType) {
77 case CATALOGUE_ITEM_TYPE:
78 catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue());
79 break;
80 case DATABASE_ITEM_TYPE:
81 databases.append(item->text());
82 case ALL_EVENT_ITEM_TYPE: // fallthrough
83 case TRASH_ITEM_TYPE: // fallthrough
84 default:
85 break;
86 }
87 }
88 else {
89 // Incoherent multi selection
90 selectionType = -1;
91 break;
92 }
93 }
94
95 switch (selectionType) {
96 case CATALOGUE_ITEM_TYPE:
97 emit this->catalogueSelected(catalogues);
98 break;
99 case DATABASE_ITEM_TYPE:
100 emit this->databaseSelected(databases);
101 break;
102 case ALL_EVENT_ITEM_TYPE:
103 emit this->allEventsSelected();
104 break;
105 case TRASH_ITEM_TYPE:
106 emit this->trashSelected();
107 break;
108 default:
109 emit this->selectionCleared();
110 break;
111 }
112 }
113
114
115 133 };
116 134
117 135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
@@ -72,3 +72,10 bool CatalogueAbstractTreeItem::canDropMimeData(const QMimeData *data, Qt::DropA
72 72 Q_UNUSED(action);
73 73 return false;
74 74 }
75
76 bool CatalogueAbstractTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action)
77 {
78 Q_UNUSED(data);
79 Q_UNUSED(action);
80 return false;
81 }
@@ -79,6 +79,16 bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction ac
79 79 return data->hasFormat(MIME_TYPE_EVENT_LIST);
80 80 }
81 81
82 bool CatalogueTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action)
83 {
84 Q_ASSERT(canDropMimeData(data, action));
85
86 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
87 // impl->m_Catalogue->addEvents(events); TODO: move events in the new catalogue
88 // Warning: Check that the events aren't already in the catalogue
89 // Also check for the repository !!!
90 }
91
82 92 std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const
83 93 {
84 94 return impl->m_Catalogue;
@@ -43,7 +43,7 void CatalogueTreeModel::addChildItem(CatalogueAbstractTreeItem *child,
43 43 parentItem->addChild(child);
44 44 endInsertRows();
45 45
46 emit dataChanged(QModelIndex(), QModelIndex());
46 emit dataChanged(parentIndex, parentIndex);
47 47 }
48 48
49 49 CatalogueAbstractTreeItem *CatalogueTreeModel::item(const QModelIndex &index) const
@@ -176,7 +176,18 bool CatalogueTreeModel::canDropMimeData(const QMimeData *data, Qt::DropAction a
176 176 bool CatalogueTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
177 177 int column, const QModelIndex &parent)
178 178 {
179 return false;
179 bool result = false;
180
181 auto draggedIndex = parent;
182 auto draggedItem = item(draggedIndex);
183 if (draggedItem) {
184 result = draggedItem->dropMimeData(data, action);
185 if (result) {
186 emit itemDropped(draggedIndex);
187 }
188 }
189
190 return result;
180 191 }
181 192
182 193 Qt::DropActions CatalogueTreeModel::supportedDropActions() const
@@ -79,6 +79,9
79 79 <property name="dragDropMode">
80 80 <enum>QAbstractItemView::DragDrop</enum>
81 81 </property>
82 <property name="selectionMode">
83 <enum>QAbstractItemView::ExtendedSelection</enum>
84 </property>
82 85 <attribute name="headerVisible">
83 86 <bool>false</bool>
84 87 </attribute>
General Comments 0
You need to be logged in to leave comments. Login now