##// END OF EJS Templates
Updates model after an event has been created through the colored zone
trabillard -
r1286:073d4af7c849
parent child
Show More
@@ -1,17 +1,19
1 #ifndef SCIQLOP_CATALOGUEACTIONMANAGER_H
1 #ifndef SCIQLOP_CATALOGUEACTIONMANAGER_H
2 #define SCIQLOP_CATALOGUEACTIONMANAGER_H
2 #define SCIQLOP_CATALOGUEACTIONMANAGER_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 class CatalogueExplorer;
7
6 class CatalogueActionManager {
8 class CatalogueActionManager {
7 public:
9 public:
8 CatalogueActionManager();
10 CatalogueActionManager(CatalogueExplorer *catalogueExplorer);
9
11
10 void installSelectionZoneActions();
12 void installSelectionZoneActions();
11
13
12 private:
14 private:
13 class CatalogueActionManagerPrivate;
15 class CatalogueActionManagerPrivate;
14 spimpl::unique_impl_ptr<CatalogueActionManagerPrivate> impl;
16 spimpl::unique_impl_ptr<CatalogueActionManagerPrivate> impl;
15 };
17 };
16
18
17 #endif // SCIQLOP_CATALOGUEACTIONMANAGER_H
19 #endif // SCIQLOP_CATALOGUEACTIONMANAGER_H
@@ -1,48 +1,54
1 #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H
1 #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H
2 #define SCIQLOP_CATALOGUEEVENTSWIDGET_H
2 #define SCIQLOP_CATALOGUEEVENTSWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QLoggingCategory>
5 #include <QLoggingCategory>
6 #include <QWidget>
6 #include <QWidget>
7
7
8 class DBCatalogue;
8 class DBCatalogue;
9 class DBEvent;
9 class DBEvent;
10 class DBEventProduct;
10 class DBEventProduct;
11 class VisualizationWidget;
11 class VisualizationWidget;
12
12
13 namespace Ui {
13 namespace Ui {
14 class CatalogueEventsWidget;
14 class CatalogueEventsWidget;
15 }
15 }
16
16
17 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget)
17 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget)
18
18
19 class CatalogueEventsWidget : public QWidget {
19 class CatalogueEventsWidget : public QWidget {
20 Q_OBJECT
20 Q_OBJECT
21
21
22 signals:
22 signals:
23 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
23 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
24 void eventProductsSelected(
24 void eventProductsSelected(
25 const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > >
25 const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > >
26 &eventproducts);
26 &eventproducts);
27 void selectionCleared();
27 void selectionCleared();
28
28
29 public:
29 public:
30 explicit CatalogueEventsWidget(QWidget *parent = 0);
30 explicit CatalogueEventsWidget(QWidget *parent = 0);
31 virtual ~CatalogueEventsWidget();
31 virtual ~CatalogueEventsWidget();
32
32
33 void setVisualizationWidget(VisualizationWidget *visualization);
33 void setVisualizationWidget(VisualizationWidget *visualization);
34
34
35 void addEvent(const std::shared_ptr<DBEvent> &event);
35 void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges);
36 void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges);
36
37
38 QVector<std::shared_ptr<DBCatalogue> > displayedCatalogues() const;
39 bool isAllEventsDisplayed() const;
40 bool isEventDisplayed(const std::shared_ptr<DBEvent> &event) const;
41
37 public slots:
42 public slots:
38 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
43 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
39 void populateWithAllEvents();
44 void populateWithAllEvents();
45 void refresh();
40
46
41 private:
47 private:
42 Ui::CatalogueEventsWidget *ui;
48 Ui::CatalogueEventsWidget *ui;
43
49
44 class CatalogueEventsWidgetPrivate;
50 class CatalogueEventsWidgetPrivate;
45 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
51 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
46 };
52 };
47
53
48 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
54 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
@@ -1,29 +1,35
1 #ifndef SCIQLOP_CATALOGUEEXPLORER_H
1 #ifndef SCIQLOP_CATALOGUEEXPLORER_H
2 #define SCIQLOP_CATALOGUEEXPLORER_H
2 #define SCIQLOP_CATALOGUEEXPLORER_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QDialog>
5 #include <QDialog>
6
6
7 namespace Ui {
7 namespace Ui {
8 class CatalogueExplorer;
8 class CatalogueExplorer;
9 }
9 }
10
10
11 class CatalogueEventsWidget;
12 class CatalogueSideBarWidget;
13
11 class VisualizationWidget;
14 class VisualizationWidget;
12
15
13 class CatalogueExplorer : public QDialog {
16 class CatalogueExplorer : public QDialog {
14 Q_OBJECT
17 Q_OBJECT
15
18
16 public:
19 public:
17 explicit CatalogueExplorer(QWidget *parent = 0);
20 explicit CatalogueExplorer(QWidget *parent = 0);
18 virtual ~CatalogueExplorer();
21 virtual ~CatalogueExplorer();
19
22
20 void setVisualizationWidget(VisualizationWidget *visualization);
23 void setVisualizationWidget(VisualizationWidget *visualization);
21
24
25 CatalogueEventsWidget &eventsWidget() const;
26 CatalogueSideBarWidget &sideBarWidget() const;
27
22 private:
28 private:
23 Ui::CatalogueExplorer *ui;
29 Ui::CatalogueExplorer *ui;
24
30
25 class CatalogueExplorerPrivate;
31 class CatalogueExplorerPrivate;
26 spimpl::unique_impl_ptr<CatalogueExplorerPrivate> impl;
32 spimpl::unique_impl_ptr<CatalogueExplorerPrivate> impl;
27 };
33 };
28
34
29 #endif // SCIQLOP_CATALOGUEEXPLORER_H
35 #endif // SCIQLOP_CATALOGUEEXPLORER_H
@@ -1,43 +1,46
1 #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H
1 #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QLoggingCategory>
5 #include <QLoggingCategory>
6 #include <QTreeWidgetItem>
6 #include <QTreeWidgetItem>
7 #include <QWidget>
7 #include <QWidget>
8
8
9 class DBCatalogue;
9 class DBCatalogue;
10
10
11 namespace Ui {
11 namespace Ui {
12 class CatalogueSideBarWidget;
12 class CatalogueSideBarWidget;
13 }
13 }
14
14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget)
15 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget)
16
16
17 class CatalogueSideBarWidget : public QWidget {
17 class CatalogueSideBarWidget : public QWidget {
18 Q_OBJECT
18 Q_OBJECT
19
19
20 signals:
20 signals:
21 void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
21 void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
22 void databaseSelected(const QStringList &databases);
22 void databaseSelected(const QStringList &databases);
23 void allEventsSelected();
23 void allEventsSelected();
24 void trashSelected();
24 void trashSelected();
25 void selectionCleared();
25 void selectionCleared();
26
26
27 public:
27 public:
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
29 virtual ~CatalogueSideBarWidget();
29 virtual ~CatalogueSideBarWidget();
30
30
31 void addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, const QString &repository);
31 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32
33
34 QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
35
33 private:
36 private:
34 Ui::CatalogueSideBarWidget *ui;
37 Ui::CatalogueSideBarWidget *ui;
35
38
36 class CatalogueSideBarWidgetPrivate;
39 class CatalogueSideBarWidgetPrivate;
37 spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl;
40 spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl;
38
41
39 private slots:
42 private slots:
40 void onContextMenuRequested(const QPoint &pos);
43 void onContextMenuRequested(const QPoint &pos);
41 };
44 };
42
45
43 #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H
46 #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H
@@ -1,35 +1,36
1 #ifndef SCIQLOP_CREATEEVENTDIALOG_H
1 #ifndef SCIQLOP_CREATEEVENTDIALOG_H
2 #define SCIQLOP_CREATEEVENTDIALOG_H
2 #define SCIQLOP_CREATEEVENTDIALOG_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QDialog>
5 #include <QDialog>
6 #include <memory>
6 #include <memory>
7
7
8 namespace Ui {
8 namespace Ui {
9 class CreateEventDialog;
9 class CreateEventDialog;
10 }
10 }
11
11
12 class DBCatalogue;
12 class DBCatalogue;
13
13
14 class CreateEventDialog : public QDialog {
14 class CreateEventDialog : public QDialog {
15 Q_OBJECT
15 Q_OBJECT
16
16
17 public:
17 public:
18 explicit CreateEventDialog(QWidget *parent = 0);
18 explicit CreateEventDialog(const QVector<std::shared_ptr<DBCatalogue> > &catalogues,
19 QWidget *parent = 0);
19 virtual ~CreateEventDialog();
20 virtual ~CreateEventDialog();
20
21
21 void hideCatalogueChoice();
22 void hideCatalogueChoice();
22
23
23 QString eventName() const;
24 QString eventName() const;
24
25
25 std::shared_ptr<DBCatalogue> selectedCatalogue() const;
26 std::shared_ptr<DBCatalogue> selectedCatalogue() const;
26 QString catalogueName() const;
27 QString catalogueName() const;
27
28
28 private:
29 private:
29 Ui::CreateEventDialog *ui;
30 Ui::CreateEventDialog *ui;
30
31
31 class CreateEventDialogPrivate;
32 class CreateEventDialogPrivate;
32 spimpl::unique_impl_ptr<CreateEventDialogPrivate> impl;
33 spimpl::unique_impl_ptr<CreateEventDialogPrivate> impl;
33 };
34 };
34
35
35 #endif // SCIQLOP_CREATEEVENTDIALOG_H
36 #endif // SCIQLOP_CREATEEVENTDIALOG_H
@@ -1,107 +1,133
1 #include "Catalogue/CatalogueActionManager.h"
1 #include "Catalogue/CatalogueActionManager.h"
2
2
3 #include <Actions/ActionsGuiController.h>
3 #include <Actions/ActionsGuiController.h>
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <SqpApplication.h>
5 #include <SqpApplication.h>
6 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
7 #include <Visualization/VisualizationGraphWidget.h>
7 #include <Visualization/VisualizationGraphWidget.h>
8 #include <Visualization/VisualizationSelectionZoneItem.h>
8 #include <Visualization/VisualizationSelectionZoneItem.h>
9
9
10 #include <Catalogue/CatalogueEventsWidget.h>
11 #include <Catalogue/CatalogueExplorer.h>
12 #include <Catalogue/CatalogueSideBarWidget.h>
10 #include <Catalogue/CreateEventDialog.h>
13 #include <Catalogue/CreateEventDialog.h>
11
14
12 #include <DBCatalogue.h>
15 #include <DBCatalogue.h>
13 #include <DBEvent.h>
16 #include <DBEvent.h>
14 #include <DBEventProduct.h>
17 #include <DBEventProduct.h>
15
18
16 #include <QBoxLayout>
19 #include <QBoxLayout>
17 #include <QComboBox>
20 #include <QComboBox>
18 #include <QDialog>
21 #include <QDialog>
19 #include <QDialogButtonBox>
22 #include <QDialogButtonBox>
20 #include <QLineEdit>
23 #include <QLineEdit>
21 #include <memory>
24 #include <memory>
22
25
23 struct CatalogueActionManager::CatalogueActionManagerPrivate {
26 struct CatalogueActionManager::CatalogueActionManagerPrivate {
27
28 CatalogueExplorer *m_CatalogueExplorer = nullptr;
29
30 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
31 : m_CatalogueExplorer(catalogueExplorer)
32 {
33 }
34
24 void createEventFromZones(const QString &eventName,
35 void createEventFromZones(const QString &eventName,
25 const QVector<VisualizationSelectionZoneItem *> &zones,
36 const QVector<VisualizationSelectionZoneItem *> &zones,
26 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
37 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
27 {
38 {
28 auto event = std::make_shared<DBEvent>();
39 auto event = std::make_shared<DBEvent>();
29 event->setName(eventName);
40 event->setName(eventName);
30
41
31 std::list<DBEventProduct> productList;
42 std::list<DBEventProduct> productList;
32 for (auto zone : zones) {
43 for (auto zone : zones) {
33 auto graph = zone->parentGraphWidget();
44 auto graph = zone->parentGraphWidget();
34 for (auto var : graph->variables()) {
45 for (auto var : graph->variables()) {
35 auto eventProduct = std::make_shared<DBEventProduct>();
46 auto eventProduct = std::make_shared<DBEventProduct>();
36 eventProduct->setEvent(*event);
47 eventProduct->setEvent(*event);
37
48
38 auto zoneRange = zone->range();
49 auto zoneRange = zone->range();
39 eventProduct->setTStart(zoneRange.m_TStart);
50 eventProduct->setTStart(zoneRange.m_TStart);
40 eventProduct->setTEnd(zoneRange.m_TEnd);
51 eventProduct->setTEnd(zoneRange.m_TEnd);
41
52
42 eventProduct->setProductId(var->metadata().value("id", "TODO").toString()); // todo
53 eventProduct->setProductId(var->metadata().value("id", "TODO").toString()); // todo
43
54
44 productList.push_back(*eventProduct);
55 productList.push_back(*eventProduct);
45 }
56 }
46 }
57 }
47
58
48 event->setEventProducts(productList);
59 event->setEventProducts(productList);
49
60
50 sqpApp->catalogueController().addEvent(event);
61 sqpApp->catalogueController().addEvent(event);
51
62
63
52 if (catalogue) {
64 if (catalogue) {
53 // TODO
65 // TODO
54 // catalogue->addEvent(event);
66 // catalogue->addEvent(event);
67 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
68 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
69 m_CatalogueExplorer->eventsWidget().addEvent(event);
70 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
71 }
72 }
73 else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) {
74 m_CatalogueExplorer->eventsWidget().addEvent(event);
75 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
55 }
76 }
56 }
77 }
57 };
78 };
58
79
59 CatalogueActionManager::CatalogueActionManager()
80 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
60 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>()}
81 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
61 {
82 {
62 }
83 }
63
84
64 void CatalogueActionManager::installSelectionZoneActions()
85 void CatalogueActionManager::installSelectionZoneActions()
65 {
86 {
66 auto &actionController = sqpApp->actionsGuiController();
87 auto &actionController = sqpApp->actionsGuiController();
67
88
68 auto createEventEnableFuntion = [](auto zones) {
89 auto createEventEnableFuntion = [](auto zones) {
69 QSet<VisualizationGraphWidget *> usedGraphs;
90 QSet<VisualizationGraphWidget *> usedGraphs;
70 for (auto zone : zones) {
91 for (auto zone : zones) {
71 auto graph = zone->parentGraphWidget();
92 auto graph = zone->parentGraphWidget();
72 if (!usedGraphs.contains(graph)) {
93 if (!usedGraphs.contains(graph)) {
73 usedGraphs.insert(graph);
94 usedGraphs.insert(graph);
74 }
95 }
75 else {
96 else {
76 return false;
97 return false;
77 }
98 }
78 }
99 }
79
100
80 return true;
101 return true;
81 };
102 };
82
103
83 auto createEventAction = actionController.addSectionZoneAction(
104 auto createEventAction = actionController.addSectionZoneAction(
84 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
105 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
85 CreateEventDialog dialog;
106 CreateEventDialog dialog(
107 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues("Default"));
86 dialog.hideCatalogueChoice();
108 dialog.hideCatalogueChoice();
87 if (dialog.exec() == QDialog::Accepted) {
109 if (dialog.exec() == QDialog::Accepted) {
88 impl->createEventFromZones(dialog.eventName(), zones);
110 impl->createEventFromZones(dialog.eventName(), zones);
89 }
111 }
90 });
112 });
91 createEventAction->setEnableFunction(createEventEnableFuntion);
113 createEventAction->setEnableFunction(createEventEnableFuntion);
92
114
93 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
115 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
94 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
116 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
95 CreateEventDialog dialog;
117 CreateEventDialog dialog(
118 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues("Default"));
96 if (dialog.exec() == QDialog::Accepted) {
119 if (dialog.exec() == QDialog::Accepted) {
97 auto selectedCatalogue = dialog.selectedCatalogue();
120 auto selectedCatalogue = dialog.selectedCatalogue();
98 if (!selectedCatalogue) {
121 if (!selectedCatalogue) {
99 selectedCatalogue = std::make_shared<DBCatalogue>();
122 selectedCatalogue = std::make_shared<DBCatalogue>();
100 selectedCatalogue->setName(dialog.catalogueName());
123 selectedCatalogue->setName(dialog.catalogueName());
124 // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO
125 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
126 "Default");
101 }
127 }
102
128
103 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
129 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
104 }
130 }
105 });
131 });
106 createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
132 createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
107 }
133 }
@@ -1,364 +1,399
1 #include "Catalogue/CatalogueEventsWidget.h"
1 #include "Catalogue/CatalogueEventsWidget.h"
2 #include "ui_CatalogueEventsWidget.h"
2 #include "ui_CatalogueEventsWidget.h"
3
3
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueEventsModel.h>
5 #include <Catalogue/CatalogueEventsModel.h>
6 #include <Catalogue/CatalogueExplorerHelper.h>
6 #include <Catalogue/CatalogueExplorerHelper.h>
7 #include <CatalogueDao.h>
7 #include <CatalogueDao.h>
8 #include <DBCatalogue.h>
8 #include <DBCatalogue.h>
9 #include <SqpApplication.h>
9 #include <SqpApplication.h>
10 #include <Visualization/VisualizationTabWidget.h>
10 #include <Visualization/VisualizationTabWidget.h>
11 #include <Visualization/VisualizationWidget.h>
11 #include <Visualization/VisualizationWidget.h>
12 #include <Visualization/VisualizationZoneWidget.h>
12 #include <Visualization/VisualizationZoneWidget.h>
13
13
14 #include <QDialog>
14 #include <QDialog>
15 #include <QDialogButtonBox>
15 #include <QDialogButtonBox>
16 #include <QListWidget>
16 #include <QListWidget>
17
17
18 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
18 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19
19
20 /// Fixed size of the validation column
20 /// Fixed size of the validation column
21 const auto VALIDATION_COLUMN_SIZE = 35;
21 const auto VALIDATION_COLUMN_SIZE = 35;
22
22
23 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
23 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
24
24
25 CatalogueEventsModel *m_Model = nullptr;
25 CatalogueEventsModel *m_Model = nullptr;
26 QStringList m_ZonesForTimeMode;
26 QStringList m_ZonesForTimeMode;
27 QString m_ZoneForGraphMode;
27 QString m_ZoneForGraphMode;
28 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
28
29
29 VisualizationWidget *m_VisualizationWidget = nullptr;
30 VisualizationWidget *m_VisualizationWidget = nullptr;
30
31
31 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
32 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
32 {
33 {
33 treeView->setSortingEnabled(false);
34 treeView->setSortingEnabled(false);
34 m_Model->setEvents(events);
35 m_Model->setEvents(events);
35 treeView->setSortingEnabled(true);
36 treeView->setSortingEnabled(true);
36 }
37 }
37
38
38 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
39 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
39 {
40 {
40 treeView->setSortingEnabled(false);
41 treeView->setSortingEnabled(false);
41 m_Model->addEvent(event);
42 m_Model->addEvent(event);
42 treeView->setSortingEnabled(true);
43 treeView->setSortingEnabled(true);
43 }
44 }
44
45
45 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
46 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
46 {
47 {
47 treeView->setSortingEnabled(false);
48 treeView->setSortingEnabled(false);
48 m_Model->removeEvent(event);
49 m_Model->removeEvent(event);
49 treeView->setSortingEnabled(true);
50 treeView->setSortingEnabled(true);
50 }
51 }
51
52
52 QStringList getAvailableVisualizationZoneList() const
53 QStringList getAvailableVisualizationZoneList() const
53 {
54 {
54 if (m_VisualizationWidget) {
55 if (m_VisualizationWidget) {
55 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
56 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
56 return tab->availableZoneWidgets();
57 return tab->availableZoneWidgets();
57 }
58 }
58 }
59 }
59
60
60 return QStringList{};
61 return QStringList{};
61 }
62 }
62
63
63 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
64 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
64 bool allowMultiSelection, const QPoint &location)
65 bool allowMultiSelection, const QPoint &location)
65 {
66 {
66 auto availableZones = getAvailableVisualizationZoneList();
67 auto availableZones = getAvailableVisualizationZoneList();
67 if (availableZones.isEmpty()) {
68 if (availableZones.isEmpty()) {
68 return QStringList{};
69 return QStringList{};
69 }
70 }
70
71
71 QDialog d(parent, Qt::Tool);
72 QDialog d(parent, Qt::Tool);
72 d.setWindowTitle("Choose a zone");
73 d.setWindowTitle("Choose a zone");
73 auto layout = new QVBoxLayout{&d};
74 auto layout = new QVBoxLayout{&d};
74 layout->setContentsMargins(0, 0, 0, 0);
75 layout->setContentsMargins(0, 0, 0, 0);
75 auto listWidget = new QListWidget{&d};
76 auto listWidget = new QListWidget{&d};
76 layout->addWidget(listWidget);
77 layout->addWidget(listWidget);
77
78
78 QSet<QListWidgetItem *> checkedItems;
79 QSet<QListWidgetItem *> checkedItems;
79 for (auto zone : availableZones) {
80 for (auto zone : availableZones) {
80 auto item = new QListWidgetItem{zone};
81 auto item = new QListWidgetItem{zone};
81 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
82 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
82 if (selectedZones.contains(zone)) {
83 if (selectedZones.contains(zone)) {
83 item->setCheckState(Qt::Checked);
84 item->setCheckState(Qt::Checked);
84 checkedItems << item;
85 checkedItems << item;
85 }
86 }
86 else {
87 else {
87 item->setCheckState(Qt::Unchecked);
88 item->setCheckState(Qt::Unchecked);
88 }
89 }
89
90
90 listWidget->addItem(item);
91 listWidget->addItem(item);
91 }
92 }
92
93
93 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
94 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
94 layout->addWidget(buttonBox);
95 layout->addWidget(buttonBox);
95
96
96 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
97 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
97 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
98 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
98
99
99 QObject::connect(listWidget, &QListWidget::itemChanged,
100 QObject::connect(listWidget, &QListWidget::itemChanged,
100 [&checkedItems, allowMultiSelection, listWidget](auto item) {
101 [&checkedItems, allowMultiSelection, listWidget](auto item) {
101 if (item->checkState() == Qt::Checked) {
102 if (item->checkState() == Qt::Checked) {
102 if (!allowMultiSelection) {
103 if (!allowMultiSelection) {
103 for (auto checkedItem : checkedItems) {
104 for (auto checkedItem : checkedItems) {
104 listWidget->blockSignals(true);
105 listWidget->blockSignals(true);
105 checkedItem->setCheckState(Qt::Unchecked);
106 checkedItem->setCheckState(Qt::Unchecked);
106 listWidget->blockSignals(false);
107 listWidget->blockSignals(false);
107 }
108 }
108
109
109 checkedItems.clear();
110 checkedItems.clear();
110 }
111 }
111 checkedItems << item;
112 checkedItems << item;
112 }
113 }
113 else {
114 else {
114 checkedItems.remove(item);
115 checkedItems.remove(item);
115 }
116 }
116 });
117 });
117
118
118 QStringList result;
119 QStringList result;
119
120
120 d.setMinimumWidth(120);
121 d.setMinimumWidth(120);
121 d.resize(d.minimumSizeHint());
122 d.resize(d.minimumSizeHint());
122 d.move(location);
123 d.move(location);
123 if (d.exec() == QDialog::Accepted) {
124 if (d.exec() == QDialog::Accepted) {
124 for (auto item : checkedItems) {
125 for (auto item : checkedItems) {
125 result += item->text();
126 result += item->text();
126 }
127 }
127 }
128 }
128 else {
129 else {
129 result = selectedZones;
130 result = selectedZones;
130 }
131 }
131
132
132 return result;
133 return result;
133 }
134 }
134
135
135 void updateForTimeMode(QTreeView *treeView)
136 void updateForTimeMode(QTreeView *treeView)
136 {
137 {
137 auto selectedRows = treeView->selectionModel()->selectedRows();
138 auto selectedRows = treeView->selectionModel()->selectedRows();
138
139
139 if (selectedRows.count() == 1) {
140 if (selectedRows.count() == 1) {
140 auto event = m_Model->getEvent(selectedRows.first());
141 auto event = m_Model->getEvent(selectedRows.first());
141 if (event) {
142 if (event) {
142 if (m_VisualizationWidget) {
143 if (m_VisualizationWidget) {
143 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
144 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
144
145
145 for (auto zoneName : m_ZonesForTimeMode) {
146 for (auto zoneName : m_ZonesForTimeMode) {
146 if (auto zone = tab->getZoneWithName(zoneName)) {
147 if (auto zone = tab->getZoneWithName(zoneName)) {
147 SqpRange eventRange;
148 SqpRange eventRange;
148 eventRange.m_TStart = event->getTStart();
149 eventRange.m_TStart = event->getTStart();
149 eventRange.m_TEnd = event->getTEnd();
150 eventRange.m_TEnd = event->getTEnd();
150 zone->setZoneRange(eventRange);
151 zone->setZoneRange(eventRange);
151 }
152 }
152 }
153 }
153 }
154 }
154 else {
155 else {
155 qCWarning(LOG_CatalogueEventsWidget())
156 qCWarning(LOG_CatalogueEventsWidget())
156 << "updateTimeZone: no tab found in the visualization";
157 << "updateTimeZone: no tab found in the visualization";
157 }
158 }
158 }
159 }
159 else {
160 else {
160 qCWarning(LOG_CatalogueEventsWidget())
161 qCWarning(LOG_CatalogueEventsWidget())
161 << "updateTimeZone: visualization widget not found";
162 << "updateTimeZone: visualization widget not found";
162 }
163 }
163 }
164 }
164 }
165 }
165 else {
166 else {
166 qCWarning(LOG_CatalogueEventsWidget())
167 qCWarning(LOG_CatalogueEventsWidget())
167 << "updateTimeZone: not compatible with multiple events selected";
168 << "updateTimeZone: not compatible with multiple events selected";
168 }
169 }
169 }
170 }
170
171
171 void updateForGraphMode(QTreeView *treeView)
172 void updateForGraphMode(QTreeView *treeView)
172 {
173 {
173 auto selectedRows = treeView->selectionModel()->selectedRows();
174 auto selectedRows = treeView->selectionModel()->selectedRows();
174
175
175 if (selectedRows.count() == 1) {
176 if (selectedRows.count() == 1) {
176 auto event = m_Model->getEvent(selectedRows.first());
177 auto event = m_Model->getEvent(selectedRows.first());
177 if (m_VisualizationWidget) {
178 if (m_VisualizationWidget) {
178 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
179 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
179 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
180 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
180 // TODO
181 // TODO
181 }
182 }
182 }
183 }
183 else {
184 else {
184 qCWarning(LOG_CatalogueEventsWidget())
185 qCWarning(LOG_CatalogueEventsWidget())
185 << "updateGraphMode: no tab found in the visualization";
186 << "updateGraphMode: no tab found in the visualization";
186 }
187 }
187 }
188 }
188 else {
189 else {
189 qCWarning(LOG_CatalogueEventsWidget())
190 qCWarning(LOG_CatalogueEventsWidget())
190 << "updateGraphMode: visualization widget not found";
191 << "updateGraphMode: visualization widget not found";
191 }
192 }
192 }
193 }
193 else {
194 else {
194 qCWarning(LOG_CatalogueEventsWidget())
195 qCWarning(LOG_CatalogueEventsWidget())
195 << "updateGraphMode: not compatible with multiple events selected";
196 << "updateGraphMode: not compatible with multiple events selected";
196 }
197 }
197 }
198 }
198 };
199 };
199
200
200 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
201 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
201 : QWidget(parent),
202 : QWidget(parent),
202 ui(new Ui::CatalogueEventsWidget),
203 ui(new Ui::CatalogueEventsWidget),
203 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
204 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
204 {
205 {
205 ui->setupUi(this);
206 ui->setupUi(this);
206
207
207 impl->m_Model = new CatalogueEventsModel{this};
208 impl->m_Model = new CatalogueEventsModel{this};
208 ui->treeView->setModel(impl->m_Model);
209 ui->treeView->setModel(impl->m_Model);
209
210
210 ui->treeView->setSortingEnabled(true);
211 ui->treeView->setSortingEnabled(true);
211 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
212 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
212 ui->treeView->setDragEnabled(true);
213 ui->treeView->setDragEnabled(true);
213
214
214 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
215 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
215 if (checked) {
216 if (checked) {
216 ui->btnChart->setChecked(false);
217 ui->btnChart->setChecked(false);
217 impl->m_ZonesForTimeMode
218 impl->m_ZonesForTimeMode
218 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
219 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
219 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
220 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
220
221
221 impl->updateForTimeMode(ui->treeView);
222 impl->updateForTimeMode(ui->treeView);
222 }
223 }
223 });
224 });
224
225
225 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
226 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
226 if (checked) {
227 if (checked) {
227 ui->btnTime->setChecked(false);
228 ui->btnTime->setChecked(false);
228 impl->m_ZoneForGraphMode
229 impl->m_ZoneForGraphMode
229 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
230 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
230 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
231 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
231 .value(0);
232 .value(0);
232
233
233 impl->updateForGraphMode(ui->treeView);
234 impl->updateForGraphMode(ui->treeView);
234 }
235 }
235 });
236 });
236
237
237 auto emitSelection = [this]() {
238 auto emitSelection = [this]() {
238 QVector<std::shared_ptr<DBEvent> > events;
239 QVector<std::shared_ptr<DBEvent> > events;
239 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
240 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
240
241
241 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
242 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
242
243
243 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
244 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
244 if (itemType == CatalogueEventsModel::ItemType::Event) {
245 if (itemType == CatalogueEventsModel::ItemType::Event) {
245 events << impl->m_Model->getEvent(rowIndex);
246 events << impl->m_Model->getEvent(rowIndex);
246 }
247 }
247 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
248 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
248 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
249 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
249 impl->m_Model->getEventProduct(rowIndex));
250 impl->m_Model->getEventProduct(rowIndex));
250 }
251 }
251 }
252 }
252
253
253 if (!events.isEmpty() && eventProducts.isEmpty()) {
254 if (!events.isEmpty() && eventProducts.isEmpty()) {
254 emit this->eventsSelected(events);
255 emit this->eventsSelected(events);
255 }
256 }
256 else if (events.isEmpty() && !eventProducts.isEmpty()) {
257 else if (events.isEmpty() && !eventProducts.isEmpty()) {
257 emit this->eventProductsSelected(eventProducts);
258 emit this->eventProductsSelected(eventProducts);
258 }
259 }
259 else {
260 else {
260 emit this->selectionCleared();
261 emit this->selectionCleared();
261 }
262 }
262 };
263 };
263
264
264 connect(ui->treeView, &QTreeView::clicked, emitSelection);
265 connect(ui->treeView, &QTreeView::clicked, emitSelection);
265 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
266 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
266
267
267 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
268 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
268 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
269 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
269 ui->btnChart->setEnabled(isNotMultiSelection);
270 ui->btnChart->setEnabled(isNotMultiSelection);
270 ui->btnTime->setEnabled(isNotMultiSelection);
271 ui->btnTime->setEnabled(isNotMultiSelection);
271
272
272 if (isNotMultiSelection && ui->btnTime->isChecked()) {
273 if (isNotMultiSelection && ui->btnTime->isChecked()) {
273 impl->updateForTimeMode(ui->treeView);
274 impl->updateForTimeMode(ui->treeView);
274 }
275 }
275 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
276 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
276 impl->updateForGraphMode(ui->treeView);
277 impl->updateForGraphMode(ui->treeView);
277 }
278 }
278 });
279 });
279
280
280 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
281 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
281 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
282 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
282 QHeaderView::Stretch);
283 QHeaderView::Stretch);
283 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
284 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
284 QHeaderView::Fixed);
285 QHeaderView::Fixed);
285 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
286 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
286 VALIDATION_COLUMN_SIZE);
287 VALIDATION_COLUMN_SIZE);
287 ui->treeView->header()->setSortIndicatorShown(true);
288 ui->treeView->header()->setSortIndicatorShown(true);
288
289
289 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
290 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
290 auto allEvents = impl->m_Model->events();
291 auto allEvents = impl->m_Model->events();
291 for (auto event : allEvents) {
292 for (auto event : allEvents) {
292 setEventChanges(event, impl->m_Model->eventsHasChanges(event));
293 setEventChanges(event, impl->m_Model->eventsHasChanges(event));
293 }
294 }
294 });
295 });
295 }
296 }
296
297
297 CatalogueEventsWidget::~CatalogueEventsWidget()
298 CatalogueEventsWidget::~CatalogueEventsWidget()
298 {
299 {
299 delete ui;
300 delete ui;
300 }
301 }
301
302
302 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
303 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
303 {
304 {
304 impl->m_VisualizationWidget = visualization;
305 impl->m_VisualizationWidget = visualization;
305 }
306 }
306
307
308 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
309 {
310 impl->addEvent(event, ui->treeView);
311 }
312
307 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
313 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
308 {
314 {
309 impl->m_Model->refreshEvent(event);
315 impl->m_Model->refreshEvent(event);
310
316
311 auto eventIndex = impl->m_Model->indexOf(event);
317 auto eventIndex = impl->m_Model->indexOf(event);
312 auto validationIndex
318 auto validationIndex
313 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
319 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
314
320
315 if (hasChanges) {
321 if (hasChanges) {
316 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
322 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
323 auto widget = CatalogueExplorerHelper::buildValidationWidget(
318 ui->treeView,
324 ui->treeView,
319 [this, event]() {
325 [this, event]() {
320 sqpApp->catalogueController().saveEvent(event);
326 sqpApp->catalogueController().saveEvent(event);
321 setEventChanges(event, false);
327 setEventChanges(event, false);
322 },
328 },
323 [this, event]() { setEventChanges(event, false); });
329 [this, event]() { setEventChanges(event, false); });
324 ui->treeView->setIndexWidget(validationIndex, widget);
330 ui->treeView->setIndexWidget(validationIndex, widget);
325 }
331 }
332
333 impl->m_Model->setEventHasChanges(event, hasChanges);
326 }
334 }
327 else {
335 else {
328 // Note: the widget is destroyed
336 qCWarning(LOG_CatalogueEventsWidget())
329 ui->treeView->setIndexWidget(validationIndex, nullptr);
337 << "setEventChanges: the event is not displayed in the model.";
330 }
338 }
339 }
340
341 QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
342 {
343 return impl->m_DisplayedCatalogues;
344 }
345
346 bool CatalogueEventsWidget::isAllEventsDisplayed() const
347 {
348 return impl->m_DisplayedCatalogues.isEmpty();
349 }
331
350
332 impl->m_Model->setEventHasChanges(event, hasChanges);
351 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
352 {
353 return impl->m_Model->indexOf(event).isValid();
333 }
354 }
334
355
335 void CatalogueEventsWidget::populateWithCatalogues(
356 void CatalogueEventsWidget::populateWithCatalogues(
336 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
357 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
337 {
358 {
359 impl->m_DisplayedCatalogues = catalogues;
360
338 QSet<QUuid> eventIds;
361 QSet<QUuid> eventIds;
339 QVector<std::shared_ptr<DBEvent> > events;
362 QVector<std::shared_ptr<DBEvent> > events;
340
363
341 for (auto catalogue : catalogues) {
364 for (auto catalogue : catalogues) {
342 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
365 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
343 for (auto event : catalogueEvents) {
366 for (auto event : catalogueEvents) {
344 if (!eventIds.contains(event->getUniqId())) {
367 if (!eventIds.contains(event->getUniqId())) {
345 events << event;
368 events << event;
346 eventIds.insert(event->getUniqId());
369 eventIds.insert(event->getUniqId());
347 }
370 }
348 }
371 }
349 }
372 }
350
373
351 impl->setEvents(events, ui->treeView);
374 impl->setEvents(events, ui->treeView);
352 }
375 }
353
376
354 void CatalogueEventsWidget::populateWithAllEvents()
377 void CatalogueEventsWidget::populateWithAllEvents()
355 {
378 {
379 impl->m_DisplayedCatalogues.clear();
380
356 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
381 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
357
382
358 QVector<std::shared_ptr<DBEvent> > events;
383 QVector<std::shared_ptr<DBEvent> > events;
359 for (auto event : allEvents) {
384 for (auto event : allEvents) {
360 events << event;
385 events << event;
361 }
386 }
362
387
363 impl->setEvents(events, ui->treeView);
388 impl->setEvents(events, ui->treeView);
364 }
389 }
390
391 void CatalogueEventsWidget::refresh()
392 {
393 if (impl->m_DisplayedCatalogues.isEmpty()) {
394 populateWithAllEvents();
395 }
396 else {
397 populateWithCatalogues(impl->m_DisplayedCatalogues);
398 }
399 }
@@ -1,98 +1,113
1 #include "Catalogue/CatalogueExplorer.h"
1 #include "Catalogue/CatalogueExplorer.h"
2 #include "ui_CatalogueExplorer.h"
2 #include "ui_CatalogueExplorer.h"
3
3
4 #include <Catalogue/CatalogueActionManager.h>
4 #include <Catalogue/CatalogueActionManager.h>
5 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueController.h>
6 #include <SqpApplication.h>
6 #include <SqpApplication.h>
7 #include <Visualization/VisualizationWidget.h>
7 #include <Visualization/VisualizationWidget.h>
8
8
9 #include <DBCatalogue.h>
9 #include <DBCatalogue.h>
10 #include <DBEvent.h>
10 #include <DBEvent.h>
11
11
12 struct CatalogueExplorer::CatalogueExplorerPrivate {
12 struct CatalogueExplorer::CatalogueExplorerPrivate {
13 CatalogueActionManager m_ActionManager;
13 CatalogueActionManager m_ActionManager;
14
15 CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer)
16 : m_ActionManager(catalogueExplorer)
17 {
18 }
14 };
19 };
15
20
16 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
21 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
17 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
22 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
18 ui(new Ui::CatalogueExplorer),
23 ui(new Ui::CatalogueExplorer),
19 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()}
24 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>(this)}
20 {
25 {
21 ui->setupUi(this);
26 ui->setupUi(this);
22
27
23 impl->m_ActionManager.installSelectionZoneActions();
28 impl->m_ActionManager.installSelectionZoneActions();
24
29
25 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
30 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
26 if (catalogues.count() == 1) {
31 if (catalogues.count() == 1) {
27 ui->inspector->setCatalogue(catalogues.first());
32 ui->inspector->setCatalogue(catalogues.first());
28 }
33 }
29 else {
34 else {
30 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
35 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
31 }
36 }
32
37
33 ui->events->populateWithCatalogues(catalogues);
38 ui->events->populateWithCatalogues(catalogues);
34 });
39 });
35
40
36 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
41 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
37 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
42 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
38 });
43 });
39
44
40 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
45 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
41 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
46 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
42
47
43 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
48 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
44 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
49 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
45 ui->events->populateWithAllEvents();
50 ui->events->populateWithAllEvents();
46 });
51 });
47
52
48 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
53 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
49 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
54 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
50
55
51 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
56 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
52 if (events.count() == 1) {
57 if (events.count() == 1) {
53 ui->inspector->setEvent(events.first());
58 ui->inspector->setEvent(events.first());
54 }
59 }
55 else {
60 else {
56 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
61 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
57 }
62 }
58 });
63 });
59
64
60 connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) {
65 connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) {
61 if (eventProducts.count() == 1) {
66 if (eventProducts.count() == 1) {
62 ui->inspector->setEventProduct(eventProducts.first().first,
67 ui->inspector->setEventProduct(eventProducts.first().first,
63 eventProducts.first().second);
68 eventProducts.first().second);
64 }
69 }
65 else {
70 else {
66 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
71 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
67 }
72 }
68 });
73 });
69
74
70 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
75 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
71 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
76 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
72
77
73 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
78 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
74 sqpApp->catalogueController().updateCatalogue(catalogue);
79 sqpApp->catalogueController().updateCatalogue(catalogue);
75 ui->catalogues->setCatalogueChanges(catalogue, true);
80 ui->catalogues->setCatalogueChanges(catalogue, true);
76 });
81 });
77
82
78 connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) {
83 connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) {
79 sqpApp->catalogueController().updateEvent(event);
84 sqpApp->catalogueController().updateEvent(event);
80 ui->events->setEventChanges(event, true);
85 ui->events->setEventChanges(event, true);
81 });
86 });
82
87
83 connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated,
88 connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated,
84 [this](auto event, auto eventProduct) {
89 [this](auto event, auto eventProduct) {
85 sqpApp->catalogueController().updateEventProduct(eventProduct);
90 sqpApp->catalogueController().updateEventProduct(eventProduct);
86 ui->events->setEventChanges(event, true);
91 ui->events->setEventChanges(event, true);
87 });
92 });
88 }
93 }
89
94
90 CatalogueExplorer::~CatalogueExplorer()
95 CatalogueExplorer::~CatalogueExplorer()
91 {
96 {
92 delete ui;
97 delete ui;
93 }
98 }
94
99
95 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization)
100 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization)
96 {
101 {
97 ui->events->setVisualizationWidget(visualization);
102 ui->events->setVisualizationWidget(visualization);
98 }
103 }
104
105 CatalogueEventsWidget &CatalogueExplorer::eventsWidget() const
106 {
107 return *ui->events;
108 }
109
110 CatalogueSideBarWidget &CatalogueExplorer::sideBarWidget() const
111 {
112 return *ui->catalogues;
113 }
@@ -1,313 +1,338
1 #include "Catalogue/CatalogueSideBarWidget.h"
1 #include "Catalogue/CatalogueSideBarWidget.h"
2 #include "ui_CatalogueSideBarWidget.h"
2 #include "ui_CatalogueSideBarWidget.h"
3 #include <SqpApplication.h>
3 #include <SqpApplication.h>
4
4
5 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueController.h>
6 #include <Catalogue/CatalogueExplorerHelper.h>
6 #include <Catalogue/CatalogueExplorerHelper.h>
7 #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h>
7 #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h>
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 <ComparaisonPredicate.h>
11 #include <ComparaisonPredicate.h>
12 #include <DBCatalogue.h>
12 #include <DBCatalogue.h>
13
13
14 #include <QMenu>
14 #include <QMenu>
15
15
16 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
16 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
17
17
18
18
19 constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1;
19 constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1;
20 constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2;
20 constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2;
21 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
21 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
22 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
22 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
23
23
24
24
25 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
25 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
26
26
27 CatalogueTreeModel *m_TreeModel = nullptr;
27 CatalogueTreeModel *m_TreeModel = nullptr;
28
28
29 void configureTreeWidget(QTreeView *treeView);
29 void configureTreeWidget(QTreeView *treeView);
30 QModelIndex addDatabaseItem(const QString &name);
30 QModelIndex addDatabaseItem(const QString &name);
31 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
31 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
32 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
32 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
33 const QModelIndex &databaseIndex);
33 const QModelIndex &databaseIndex);
34
34
35 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
35 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
36 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
36 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
37 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
37 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
38
38
39 int selectionType(QTreeView *treeView) const
39 int selectionType(QTreeView *treeView) const
40 {
40 {
41 auto selectedItems = treeView->selectionModel()->selectedRows();
41 auto selectedItems = treeView->selectionModel()->selectedRows();
42 if (selectedItems.isEmpty()) {
42 if (selectedItems.isEmpty()) {
43 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
43 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
44 }
44 }
45 else {
45 else {
46 auto firstIndex = selectedItems.first();
46 auto firstIndex = selectedItems.first();
47 auto firstItem = m_TreeModel->item(firstIndex);
47 auto firstItem = m_TreeModel->item(firstIndex);
48 if (!firstItem) {
48 if (!firstItem) {
49 Q_ASSERT(false);
49 Q_ASSERT(false);
50 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
50 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
51 }
51 }
52 auto selectionType = firstItem->type();
52 auto selectionType = firstItem->type();
53
53
54 for (auto itemIndex : selectedItems) {
54 for (auto itemIndex : selectedItems) {
55 auto item = m_TreeModel->item(itemIndex);
55 auto item = m_TreeModel->item(itemIndex);
56 if (!item || item->type() != selectionType) {
56 if (!item || item->type() != selectionType) {
57 // Incoherent multi selection
57 // Incoherent multi selection
58 selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE;
58 selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE;
59 break;
59 break;
60 }
60 }
61 }
61 }
62
62
63 return selectionType;
63 return selectionType;
64 }
64 }
65 }
65 }
66
66
67 QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const
67 QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const
68 {
68 {
69 QVector<std::shared_ptr<DBCatalogue> > catalogues;
69 QVector<std::shared_ptr<DBCatalogue> > catalogues;
70 auto selectedItems = treeView->selectionModel()->selectedRows();
70 auto selectedItems = treeView->selectionModel()->selectedRows();
71 for (auto itemIndex : selectedItems) {
71 for (auto itemIndex : selectedItems) {
72 auto item = m_TreeModel->item(itemIndex);
72 auto item = m_TreeModel->item(itemIndex);
73 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
73 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
74 catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue());
74 catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue());
75 }
75 }
76 }
76 }
77
77
78 return catalogues;
78 return catalogues;
79 }
79 }
80
80
81 QStringList selectedRepositories(QTreeView *treeView) const
81 QStringList selectedRepositories(QTreeView *treeView) const
82 {
82 {
83 QStringList repositories;
83 QStringList repositories;
84 auto selectedItems = treeView->selectionModel()->selectedRows();
84 auto selectedItems = treeView->selectionModel()->selectedRows();
85 for (auto itemIndex : selectedItems) {
85 for (auto itemIndex : selectedItems) {
86 auto item = m_TreeModel->item(itemIndex);
86 auto item = m_TreeModel->item(itemIndex);
87 if (item && item->type() == DATABASE_ITEM_TYPE) {
87 if (item && item->type() == DATABASE_ITEM_TYPE) {
88 repositories.append(item->text());
88 repositories.append(item->text());
89 }
89 }
90 }
90 }
91
91
92 return repositories;
92 return repositories;
93 }
93 }
94 };
94 };
95
95
96 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
96 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
97 : QWidget(parent),
97 : QWidget(parent),
98 ui(new Ui::CatalogueSideBarWidget),
98 ui(new Ui::CatalogueSideBarWidget),
99 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
99 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
100 {
100 {
101 ui->setupUi(this);
101 ui->setupUi(this);
102
102
103 impl->m_TreeModel = new CatalogueTreeModel(this);
103 impl->m_TreeModel = new CatalogueTreeModel(this);
104 ui->treeView->setModel(impl->m_TreeModel);
104 ui->treeView->setModel(impl->m_TreeModel);
105
105
106 impl->configureTreeWidget(ui->treeView);
106 impl->configureTreeWidget(ui->treeView);
107
107
108 ui->treeView->header()->setStretchLastSection(false);
108 ui->treeView->header()->setStretchLastSection(false);
109 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
109 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
110 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
110 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
111
111
112 auto emitSelection = [this]() {
112 auto emitSelection = [this]() {
113
113
114 auto selectionType = impl->selectionType(ui->treeView);
114 auto selectionType = impl->selectionType(ui->treeView);
115
115
116 switch (selectionType) {
116 switch (selectionType) {
117 case CATALOGUE_ITEM_TYPE:
117 case CATALOGUE_ITEM_TYPE:
118 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
118 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
119 break;
119 break;
120 case DATABASE_ITEM_TYPE:
120 case DATABASE_ITEM_TYPE:
121 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
121 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
122 break;
122 break;
123 case ALL_EVENT_ITEM_TYPE:
123 case ALL_EVENT_ITEM_TYPE:
124 emit this->allEventsSelected();
124 emit this->allEventsSelected();
125 break;
125 break;
126 case TRASH_ITEM_TYPE:
126 case TRASH_ITEM_TYPE:
127 emit this->trashSelected();
127 emit this->trashSelected();
128 break;
128 break;
129 default:
129 default:
130 emit this->selectionCleared();
130 emit this->selectionCleared();
131 break;
131 break;
132 }
132 }
133 };
133 };
134
134
135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
136 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
136 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
137 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
137 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
138 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
138 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
139 if (selectedIndexes.contains(index)) {
139 if (selectedIndexes.contains(index)) {
140 emitSelection();
140 emitSelection();
141 }
141 }
142
142
143 auto item = impl->m_TreeModel->item(index);
143 auto item = impl->m_TreeModel->item(index);
144 impl->setHasChanges(true, index, ui->treeView);
144 impl->setHasChanges(true, index, ui->treeView);
145 });
145 });
146
146
147 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
147 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
148 connect(ui->treeView, &QTreeView::customContextMenuRequested, this,
148 connect(ui->treeView, &QTreeView::customContextMenuRequested, this,
149 &CatalogueSideBarWidget::onContextMenuRequested);
149 &CatalogueSideBarWidget::onContextMenuRequested);
150 }
150 }
151
151
152 CatalogueSideBarWidget::~CatalogueSideBarWidget()
152 CatalogueSideBarWidget::~CatalogueSideBarWidget()
153 {
153 {
154 delete ui;
154 delete ui;
155 }
155 }
156
156
157 void CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue,
158 const QString &repository)
159 {
160 auto repositoryItem = impl->getDatabaseItem(repository);
161 impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem));
162 }
163
157 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
164 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
158 bool hasChanges)
165 bool hasChanges)
159 {
166 {
160 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
167 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
161 auto index = impl->m_TreeModel->indexOf(catalogueItem);
168 auto index = impl->m_TreeModel->indexOf(catalogueItem);
162 impl->setHasChanges(hasChanges, index, ui->treeView);
169 impl->setHasChanges(hasChanges, index, ui->treeView);
163 // catalogueItem->refresh();
170 // catalogueItem->refresh();
164 }
171 }
165 }
172 }
166
173
174 QVector<std::shared_ptr<DBCatalogue> >
175 CatalogueSideBarWidget::getCatalogues(const QString &repository) const
176 {
177 QVector<std::shared_ptr<DBCatalogue> > result;
178 auto repositoryItem = impl->getDatabaseItem(repository);
179 for (auto child : repositoryItem->children()) {
180 if (child->type() == CATALOGUE_ITEM_TYPE) {
181 auto catalogueItem = static_cast<CatalogueTreeItem *>(child);
182 result << catalogueItem->catalogue();
183 }
184 else {
185 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogues: invalid structure";
186 }
187 }
188
189 return result;
190 }
191
167 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
192 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
168 {
193 {
169 QMenu menu{this};
194 QMenu menu{this};
170
195
171 auto currentIndex = ui->treeView->currentIndex();
196 auto currentIndex = ui->treeView->currentIndex();
172 auto currentItem = impl->m_TreeModel->item(currentIndex);
197 auto currentItem = impl->m_TreeModel->item(currentIndex);
173 if (!currentItem) {
198 if (!currentItem) {
174 return;
199 return;
175 }
200 }
176
201
177 switch (currentItem->type()) {
202 switch (currentItem->type()) {
178 case CATALOGUE_ITEM_TYPE:
203 case CATALOGUE_ITEM_TYPE:
179 menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); });
204 menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); });
180 break;
205 break;
181 case DATABASE_ITEM_TYPE:
206 case DATABASE_ITEM_TYPE:
182 break;
207 break;
183 case ALL_EVENT_ITEM_TYPE:
208 case ALL_EVENT_ITEM_TYPE:
184 break;
209 break;
185 case TRASH_ITEM_TYPE:
210 case TRASH_ITEM_TYPE:
186 menu.addAction("Empty Trash", []() {
211 menu.addAction("Empty Trash", []() {
187 // TODO
212 // TODO
188 });
213 });
189 break;
214 break;
190 default:
215 default:
191 break;
216 break;
192 }
217 }
193
218
194 if (!menu.isEmpty()) {
219 if (!menu.isEmpty()) {
195 menu.exec(ui->treeView->mapToGlobal(pos));
220 menu.exec(ui->treeView->mapToGlobal(pos));
196 }
221 }
197 }
222 }
198
223
199 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView)
224 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView)
200 {
225 {
201 auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events",
226 auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events",
202 ALL_EVENT_ITEM_TYPE};
227 ALL_EVENT_ITEM_TYPE};
203 m_TreeModel->addTopLevelItem(allEventsItem);
228 m_TreeModel->addTopLevelItem(allEventsItem);
204
229
205 auto trashItem
230 auto trashItem
206 = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE};
231 = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE};
207 m_TreeModel->addTopLevelItem(trashItem);
232 m_TreeModel->addTopLevelItem(trashItem);
208
233
209 auto separator = new QFrame{treeView};
234 auto separator = new QFrame{treeView};
210 separator->setFrameShape(QFrame::HLine);
235 separator->setFrameShape(QFrame::HLine);
211 auto separatorItem
236 auto separatorItem
212 = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE};
237 = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE};
213 separatorItem->setEnabled(false);
238 separatorItem->setEnabled(false);
214 auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem);
239 auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem);
215 treeView->setIndexWidget(separatorIndex, separator);
240 treeView->setIndexWidget(separatorIndex, separator);
216
241
217 auto repositories = sqpApp->catalogueController().getRepositories();
242 auto repositories = sqpApp->catalogueController().getRepositories();
218 for (auto dbname : repositories) {
243 for (auto dbname : repositories) {
219 auto dbIndex = addDatabaseItem(dbname);
244 auto dbIndex = addDatabaseItem(dbname);
220 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
245 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
221 for (auto catalogue : catalogues) {
246 for (auto catalogue : catalogues) {
222 addCatalogueItem(catalogue, dbIndex);
247 addCatalogueItem(catalogue, dbIndex);
223 }
248 }
224 }
249 }
225
250
226 treeView->expandAll();
251 treeView->expandAll();
227 }
252 }
228
253
229 QModelIndex
254 QModelIndex
230 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name)
255 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name)
231 {
256 {
232 auto databaseItem
257 auto databaseItem
233 = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE};
258 = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE};
234 auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem);
259 auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem);
235
260
236 return databaseIndex;
261 return databaseIndex;
237 }
262 }
238
263
239 CatalogueAbstractTreeItem *
264 CatalogueAbstractTreeItem *
240 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name)
265 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name)
241 {
266 {
242 for (auto item : m_TreeModel->topLevelItems()) {
267 for (auto item : m_TreeModel->topLevelItems()) {
243 if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) {
268 if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) {
244 return item;
269 return item;
245 }
270 }
246 }
271 }
247
272
248 return nullptr;
273 return nullptr;
249 }
274 }
250
275
251 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
276 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
252 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
277 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
253 {
278 {
254 auto catalogueItem
279 auto catalogueItem
255 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
280 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
256 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
281 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
257 }
282 }
258
283
259 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
284 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
260 const std::shared_ptr<DBCatalogue> &catalogue) const
285 const std::shared_ptr<DBCatalogue> &catalogue) const
261 {
286 {
262 for (auto item : m_TreeModel->topLevelItems()) {
287 for (auto item : m_TreeModel->topLevelItems()) {
263 if (item->type() == DATABASE_ITEM_TYPE) {
288 if (item->type() == DATABASE_ITEM_TYPE) {
264 for (auto childItem : item->children()) {
289 for (auto childItem : item->children()) {
265 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
290 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
266 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
291 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
267 if (catalogueItem->catalogue() == catalogue) {
292 if (catalogueItem->catalogue() == catalogue) {
268 return catalogueItem;
293 return catalogueItem;
269 }
294 }
270 }
295 }
271 else {
296 else {
272 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree "
297 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree "
273 "structure. A database item should "
298 "structure. A database item should "
274 "only contain catalogues.";
299 "only contain catalogues.";
275 Q_ASSERT(false);
300 Q_ASSERT(false);
276 }
301 }
277 }
302 }
278 }
303 }
279 }
304 }
280
305
281 return nullptr;
306 return nullptr;
282 }
307 }
283
308
284 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
309 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
285 const QModelIndex &index,
310 const QModelIndex &index,
286 QTreeView *treeView)
311 QTreeView *treeView)
287 {
312 {
288 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
313 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
289 if (value) {
314 if (value) {
290 if (!hasChanges(validationIndex, treeView)) {
315 if (!hasChanges(validationIndex, treeView)) {
291 auto widget = CatalogueExplorerHelper::buildValidationWidget(
316 auto widget = CatalogueExplorerHelper::buildValidationWidget(
292 treeView,
317 treeView,
293 [this, validationIndex, treeView]() {
318 [this, validationIndex, treeView]() {
294 setHasChanges(false, validationIndex, treeView);
319 setHasChanges(false, validationIndex, treeView);
295 },
320 },
296 [this, validationIndex, treeView]() {
321 [this, validationIndex, treeView]() {
297 setHasChanges(false, validationIndex, treeView);
322 setHasChanges(false, validationIndex, treeView);
298 });
323 });
299 treeView->setIndexWidget(validationIndex, widget);
324 treeView->setIndexWidget(validationIndex, widget);
300 }
325 }
301 }
326 }
302 else {
327 else {
303 // Note: the widget is destroyed
328 // Note: the widget is destroyed
304 treeView->setIndexWidget(validationIndex, nullptr);
329 treeView->setIndexWidget(validationIndex, nullptr);
305 }
330 }
306 }
331 }
307
332
308 bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index,
333 bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index,
309 QTreeView *treeView)
334 QTreeView *treeView)
310 {
335 {
311 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
336 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
312 return treeView->indexWidget(validationIndex) != nullptr;
337 return treeView->indexWidget(validationIndex) != nullptr;
313 }
338 }
@@ -1,59 +1,59
1 #include "Catalogue/CreateEventDialog.h"
1 #include "Catalogue/CreateEventDialog.h"
2 #include "ui_CreateEventDialog.h"
2 #include "ui_CreateEventDialog.h"
3
3
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <SqpApplication.h>
5 #include <SqpApplication.h>
6
6
7 #include <DBCatalogue.h>
7 #include <DBCatalogue.h>
8
8
9 struct CreateEventDialog::CreateEventDialogPrivate {
9 struct CreateEventDialog::CreateEventDialogPrivate {
10 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
10 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
11 };
11 };
12
12
13 CreateEventDialog::CreateEventDialog(QWidget *parent)
13 CreateEventDialog::CreateEventDialog(const QVector<std::shared_ptr<DBCatalogue> > &catalogues,
14 QWidget *parent)
14 : QDialog(parent),
15 : QDialog(parent),
15 ui(new Ui::CreateEventDialog),
16 ui(new Ui::CreateEventDialog),
16 impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()}
17 impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()}
17 {
18 {
18 ui->setupUi(this);
19 ui->setupUi(this);
19
20
20 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
21 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
21 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
22 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
22
23
23 auto catalogues = sqpApp->catalogueController().retrieveCatalogues();
24 impl->m_DisplayedCatalogues = catalogues;
24 for (auto cat : catalogues) {
25 for (auto cat : impl->m_DisplayedCatalogues) {
25 ui->cbCatalogue->addItem(cat->getName());
26 ui->cbCatalogue->addItem(cat->getName());
26 impl->m_DisplayedCatalogues << cat;
27 }
27 }
28 }
28 }
29
29
30 CreateEventDialog::~CreateEventDialog()
30 CreateEventDialog::~CreateEventDialog()
31 {
31 {
32 delete ui;
32 delete ui;
33 }
33 }
34
34
35 void CreateEventDialog::hideCatalogueChoice()
35 void CreateEventDialog::hideCatalogueChoice()
36 {
36 {
37 ui->cbCatalogue->hide();
37 ui->cbCatalogue->hide();
38 ui->lblCatalogue->hide();
38 ui->lblCatalogue->hide();
39 }
39 }
40
40
41 QString CreateEventDialog::eventName() const
41 QString CreateEventDialog::eventName() const
42 {
42 {
43 return ui->leEvent->text();
43 return ui->leEvent->text();
44 }
44 }
45
45
46 std::shared_ptr<DBCatalogue> CreateEventDialog::selectedCatalogue() const
46 std::shared_ptr<DBCatalogue> CreateEventDialog::selectedCatalogue() const
47 {
47 {
48 auto catalogue = impl->m_DisplayedCatalogues.value(ui->cbCatalogue->currentIndex());
48 auto catalogue = impl->m_DisplayedCatalogues.value(ui->cbCatalogue->currentIndex());
49 if (!catalogue || catalogue->getName() != catalogueName()) {
49 if (!catalogue || catalogue->getName() != catalogueName()) {
50 return nullptr;
50 return nullptr;
51 }
51 }
52
52
53 return catalogue;
53 return catalogue;
54 }
54 }
55
55
56 QString CreateEventDialog::catalogueName() const
56 QString CreateEventDialog::catalogueName() const
57 {
57 {
58 return ui->cbCatalogue->currentText();
58 return ui->cbCatalogue->currentText();
59 }
59 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now