##// END OF EJS Templates
Merge branch 'feature/CataloguePart6' into develop
trabillard -
r1363:faf6baef791f merge
parent child
Show More
@@ -74,6 +74,13 public:
74 /// Returns the list of variables contained in a MIME data
74 /// Returns the list of variables contained in a MIME data
75 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
75 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
76
76
77 /// Returns the MIME data associated to a list of variables
78 QByteArray
79 mimeDataForCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues) const;
80
81 /// Returns the list of variables contained in a MIME data
82 QVector<std::shared_ptr<DBCatalogue> > cataloguesForMimeData(const QByteArray &mimeData) const;
83
77 public slots:
84 public slots:
78 /// Manage init/end of the controller
85 /// Manage init/end of the controller
79 void initialize();
86 void initialize();
@@ -16,6 +16,7 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_PRODUCT_LIST;
16 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_TIME_RANGE;
16 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_TIME_RANGE;
17 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_SELECTION_ZONE;
17 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_SELECTION_ZONE;
18 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_EVENT_LIST;
18 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_EVENT_LIST;
19 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_SOURCE_CATALOGUE_LIST;
19
20
20
21
21 #endif // SCIQLOP_MIMETYPESDEF_H
22 #endif // SCIQLOP_MIMETYPESDEF_H
@@ -382,6 +382,46 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
382 return events;
382 return events;
383 }
383 }
384
384
385 QByteArray CatalogueController::mimeDataForCatalogues(
386 const QVector<std::shared_ptr<DBCatalogue> > &catalogues) const
387 {
388 auto encodedData = QByteArray{};
389
390 QMap<QString, QVariantList> idsPerRepository;
391 for (auto catalogue : catalogues) {
392 idsPerRepository[catalogue->getRepository()] << catalogue->getUniqId();
393 }
394
395 QDataStream stream{&encodedData, QIODevice::WriteOnly};
396 stream << idsPerRepository;
397
398 return encodedData;
399 }
400
401 QVector<std::shared_ptr<DBCatalogue> >
402 CatalogueController::cataloguesForMimeData(const QByteArray &mimeData) const
403 {
404 auto catalogues = QVector<std::shared_ptr<DBCatalogue> >{};
405 QDataStream stream{mimeData};
406
407 QMap<QString, QVariantList> idsPerRepository;
408 stream >> idsPerRepository;
409
410 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
411 auto repository = it.key();
412 auto allRepositoryCatalogues = retrieveCatalogues(repository);
413 for (auto uuid : it.value()) {
414 for (auto repositoryCatalogues : allRepositoryCatalogues) {
415 if (uuid.toUuid() == repositoryCatalogues->getUniqId()) {
416 catalogues << repositoryCatalogues;
417 }
418 }
419 }
420 }
421
422 return catalogues;
423 }
424
385 void CatalogueController::initialize()
425 void CatalogueController::initialize()
386 {
426 {
387 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
427 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
@@ -7,3 +7,4 const QString MIME_TYPE_PRODUCT_LIST = QStringLiteral("sciqlop/product-list");
7 const QString MIME_TYPE_TIME_RANGE = QStringLiteral("sciqlop/time-range");
7 const QString MIME_TYPE_TIME_RANGE = QStringLiteral("sciqlop/time-range");
8 const QString MIME_TYPE_SELECTION_ZONE = QStringLiteral("sciqlop/selection-zone");
8 const QString MIME_TYPE_SELECTION_ZONE = QStringLiteral("sciqlop/selection-zone");
9 const QString MIME_TYPE_EVENT_LIST = QStringLiteral("sciqlop/event-list");
9 const QString MIME_TYPE_EVENT_LIST = QStringLiteral("sciqlop/event-list");
10 const QString MIME_TYPE_SOURCE_CATALOGUE_LIST = QStringLiteral("sciqlop/source-catalogue-list");
@@ -6,6 +6,7
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <unordered_set>
7 #include <unordered_set>
8
8
9 class DBCatalogue;
9 class DBEvent;
10 class DBEvent;
10 class DBEventProduct;
11 class DBEventProduct;
11
12
@@ -22,6 +23,7 public:
22
23
23 enum class Column { Name, TStart, TEnd, Tags, Product, Validation, NbColumn };
24 enum class Column { Name, TStart, TEnd, Tags, Product, Validation, NbColumn };
24
25
26 void setSourceCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
25 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events);
27 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events);
26 void addEvent(const std::shared_ptr<DBEvent> &event);
28 void addEvent(const std::shared_ptr<DBEvent> &event);
27 void removeEvent(const std::shared_ptr<DBEvent> &event);
29 void removeEvent(const std::shared_ptr<DBEvent> &event);
@@ -16,7 +16,7 class CatalogueTreeModel : public QAbstractItemModel {
16
16
17 signals:
17 signals:
18 void itemRenamed(const QModelIndex &index);
18 void itemRenamed(const QModelIndex &index);
19 void itemDropped(const QModelIndex &parentIndex);
19 void itemDropped(const QModelIndex &parentIndex, const QMimeData *data, Qt::DropAction action);
20
20
21 public:
21 public:
22 CatalogueTreeModel(QObject *parent = nullptr);
22 CatalogueTreeModel(QObject *parent = nullptr);
@@ -68,6 +68,9 public:
68 /// Returns the first graph in the zone or nullptr if there is no graph inside
68 /// Returns the first graph in the zone or nullptr if there is no graph inside
69 VisualizationGraphWidget *firstGraph() const;
69 VisualizationGraphWidget *firstGraph() const;
70
70
71 /// Closes all graphes inside the zone
72 void closeAllGraphs();
73
71 // IVisualizationWidget interface
74 // IVisualizationWidget interface
72 void accept(IVisualizationWidgetVisitor *visitor) override;
75 void accept(IVisualizationWidgetVisitor *visitor) override;
73 bool canDrop(const Variable &variable) const override;
76 bool canDrop(const Variable &variable) const override;
@@ -58,8 +58,6 struct CatalogueActionManager::CatalogueActionManagerPrivate {
58 eventProduct->setProductId(productId);
58 eventProduct->setProductId(productId);
59
59
60 productList.push_back(*eventProduct);
60 productList.push_back(*eventProduct);
61
62 m_CatalogueExplorer->addSelectionZoneItem(event, productId, zone);
63 }
61 }
64 }
62 }
65
63
@@ -24,6 +24,7 const auto EVENT_PRODUCT_ITEM_TYPE = 2;
24 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
24 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
25 QVector<std::shared_ptr<DBEvent> > m_Events;
25 QVector<std::shared_ptr<DBEvent> > m_Events;
26 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
26 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
27 QVector<std::shared_ptr<DBCatalogue> > m_SourceCatalogue;
27
28
28 QStringList columnNames()
29 QStringList columnNames()
29 {
30 {
@@ -129,6 +130,12 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
129 {
130 {
130 }
131 }
131
132
133 void CatalogueEventsModel::setSourceCatalogues(
134 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
135 {
136 impl->m_SourceCatalogue = catalogues;
137 }
138
132 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events)
139 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events)
133 {
140 {
134 beginResetModel();
141 beginResetModel();
@@ -388,12 +395,12 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
388
395
389 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
396 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
390 {
397 {
391 return Qt::CopyAction;
398 return Qt::CopyAction | Qt::MoveAction;
392 }
399 }
393
400
394 QStringList CatalogueEventsModel::mimeTypes() const
401 QStringList CatalogueEventsModel::mimeTypes() const
395 {
402 {
396 return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE};
403 return {MIME_TYPE_EVENT_LIST, MIME_TYPE_SOURCE_CATALOGUE_LIST, MIME_TYPE_TIME_RANGE};
397 }
404 }
398
405
399 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
406 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
@@ -436,6 +443,10 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
436 if (!eventList.isEmpty() && eventProductList.isEmpty()) {
443 if (!eventList.isEmpty() && eventProductList.isEmpty()) {
437 auto eventsEncodedData = sqpApp->catalogueController().mimeDataForEvents(eventList);
444 auto eventsEncodedData = sqpApp->catalogueController().mimeDataForEvents(eventList);
438 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
445 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
446
447 auto sourceCataloguesEncodedData
448 = sqpApp->catalogueController().mimeDataForCatalogues(impl->m_SourceCatalogue);
449 mimeData->setData(MIME_TYPE_SOURCE_CATALOGUE_LIST, sourceCataloguesEncodedData);
439 }
450 }
440
451
441 if (eventList.count() + eventProductList.count() == 1) {
452 if (eventList.count() + eventProductList.count() == 1) {
@@ -44,6 +44,7 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
44 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
44 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
45 {
45 {
46 widget->ui->treeView->setSortingEnabled(false);
46 widget->ui->treeView->setSortingEnabled(false);
47 m_Model->setSourceCatalogues(m_DisplayedCatalogues);
47 m_Model->setEvents(events);
48 m_Model->setEvents(events);
48 widget->ui->treeView->setSortingEnabled(true);
49 widget->ui->treeView->setSortingEnabled(true);
49
50
@@ -259,7 +260,7 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
259 return;
260 return;
260 }
261 }
261
262
262 // Close the previous graph and delete the asociated variables
263 // Closes the previous graph and delete the asociated variables
263 for (auto graph : m_CustomGraphs) {
264 for (auto graph : m_CustomGraphs) {
264 graph->close();
265 graph->close();
265 auto variables = graph->variables().toVector();
266 auto variables = graph->variables().toVector();
@@ -270,6 +271,9 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
270 }
271 }
271 m_CustomGraphs.clear();
272 m_CustomGraphs.clear();
272
273
274 // Closes the remaining graphs inside the zone
275 zone->closeAllGraphs();
276
273 // Calculates the range of each graph which will be created
277 // Calculates the range of each graph which will be created
274 auto graphRange = getGraphRanges(event);
278 auto graphRange = getGraphRanges(event);
275
279
@@ -8,11 +8,13
8 #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h>
8 #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h>
9 #include <Catalogue/CatalogueTreeModel.h>
9 #include <Catalogue/CatalogueTreeModel.h>
10 #include <CatalogueDao.h>
10 #include <CatalogueDao.h>
11 #include <Common/MimeTypesDef.h>
11 #include <ComparaisonPredicate.h>
12 #include <ComparaisonPredicate.h>
12 #include <DBCatalogue.h>
13 #include <DBCatalogue.h>
13
14
14 #include <QMenu>
15 #include <QMenu>
15 #include <QMessageBox>
16 #include <QMessageBox>
17 #include <QMimeData>
16
18
17 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
19 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
18
20
@@ -126,13 +128,26 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
126 });
128 });
127
129
128
130
129 connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped, [this](auto index) {
131 connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped,
130 auto item = impl->m_TreeModel->item(index);
132 [this](auto index, auto mimeData, auto action) {
131 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
133 auto item = impl->m_TreeModel->item(index);
132 auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
134 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
133 this->setCatalogueChanges(catalogue, true);
135 auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue();
134 }
136 this->setCatalogueChanges(catalogue, true);
135 });
137 }
138
139 if (action == Qt::MoveAction) {
140 /// Display a save button on source catalogues
141 auto sourceCatalogues = sqpApp->catalogueController().cataloguesForMimeData(
142 mimeData->data(MIME_TYPE_SOURCE_CATALOGUE_LIST));
143 for (auto catalogue : sourceCatalogues) {
144 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
145 this->setCatalogueChanges(catalogue, true);
146 }
147 }
148 }
149 });
150
136 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
151 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
137 QVector<QPair<std::shared_ptr<DBCatalogue>, CatalogueAbstractTreeItem *> >
152 QVector<QPair<std::shared_ptr<DBCatalogue>, CatalogueAbstractTreeItem *> >
138 cataloguesToItems;
153 cataloguesToItems;
@@ -344,7 +359,7 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCat
344 for (auto childItem : item->children()) {
359 for (auto childItem : item->children()) {
345 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
360 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
346 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
361 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
347 if (catalogueItem->catalogue() == catalogue) {
362 if (catalogueItem->catalogue()->getUniqId() == catalogue->getUniqId()) {
348 return catalogueItem;
363 return catalogueItem;
349 }
364 }
350 }
365 }
@@ -76,12 +76,22 Qt::ItemFlags CatalogueTreeItem::flags(int column) const
76
76
77 bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action)
77 bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action)
78 {
78 {
79 // Check that the event is not dropped on the same catalogue
80 auto sourceCatalogues = sqpApp->catalogueController().cataloguesForMimeData(
81 data->data(MIME_TYPE_SOURCE_CATALOGUE_LIST));
82 for (auto catalogue : sourceCatalogues) {
83 if (catalogue->getUniqId() == impl->m_Catalogue->getUniqId()) {
84 return false;
85 }
86 }
87
79 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
88 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
80 auto canDrop = data->hasFormat(MIME_TYPE_EVENT_LIST);
89 auto canDrop = data->hasFormat(MIME_TYPE_EVENT_LIST);
81
90
82 for (auto event : events) {
91 for (auto event : events) {
83 canDrop &= (event->getRepository() == impl->m_Catalogue->getRepository());
92 canDrop &= (event->getRepository() == impl->m_Catalogue->getRepository());
84 }
93 }
94
85 return canDrop;
95 return canDrop;
86 }
96 }
87
97
@@ -89,14 +99,28 bool CatalogueTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction actio
89 {
99 {
90 Q_ASSERT(canDropMimeData(data, action));
100 Q_ASSERT(canDropMimeData(data, action));
91 // Warning: Check that the events aren't already in the catalogue
101 // Warning: Check that the events aren't already in the catalogue
92 // Also check for the repository !!!
102 // No need to check check for the repository: inter-repository drop is forbidden in
103 // canDropMimeData
93
104
94 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
105 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
106 auto sourceCatalogues = sqpApp->catalogueController().cataloguesForMimeData(
107 data->data(MIME_TYPE_SOURCE_CATALOGUE_LIST));
95
108
96 for (auto event : events) {
109 for (auto event : events) {
110
111 if (action == Qt::MoveAction) {
112 for (auto catalogue : sourceCatalogues) {
113 catalogue->removeEvent(event->getUniqId());
114 }
115 }
116
97 impl->m_Catalogue->addEvent(event->getUniqId());
117 impl->m_Catalogue->addEvent(event->getUniqId());
98 sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
99 }
118 }
119
120 for (auto catalogue : sourceCatalogues) {
121 sqpApp->catalogueController().updateCatalogue(catalogue);
122 }
123 sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
100 }
124 }
101
125
102 std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const
126 std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const
@@ -178,6 +178,7 bool CatalogueTreeModel::setData(const QModelIndex &index, const QVariant &value
178
178
179 return false;
179 return false;
180 }
180 }
181
181 bool CatalogueTreeModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row,
182 bool CatalogueTreeModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row,
182 int column, const QModelIndex &parent) const
183 int column, const QModelIndex &parent) const
183 {
184 {
@@ -200,7 +201,7 bool CatalogueTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction acti
200 if (draggedItem) {
201 if (draggedItem) {
201 result = draggedItem->dropMimeData(data, action);
202 result = draggedItem->dropMimeData(data, action);
202 if (result) {
203 if (result) {
203 emit itemDropped(draggedIndex);
204 emit itemDropped(draggedIndex, data, action);
204 }
205 }
205 }
206 }
206
207
@@ -214,5 +215,5 Qt::DropActions CatalogueTreeModel::supportedDropActions() const
214
215
215 QStringList CatalogueTreeModel::mimeTypes() const
216 QStringList CatalogueTreeModel::mimeTypes() const
216 {
217 {
217 return {MIME_TYPE_EVENT_LIST};
218 return {MIME_TYPE_EVENT_LIST, MIME_TYPE_SOURCE_CATALOGUE_LIST};
218 }
219 }
@@ -336,6 +336,12 VisualizationGraphWidget *VisualizationZoneWidget::firstGraph() const
336 return firstGraph;
336 return firstGraph;
337 }
337 }
338
338
339 void VisualizationZoneWidget::closeAllGraphs()
340 {
341 processGraphs(*ui->dragDropContainer->layout(),
342 [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); });
343 }
344
339 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
345 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
340 {
346 {
341 if (visitor) {
347 if (visitor) {
General Comments 0
You need to be logged in to leave comments. Login now