##// END OF EJS Templates
Add init of DisplayedEvent. Add save on EventProduct modif
perrinel -
r1257:3d32d6e4f598
parent child
Show More
@@ -1,95 +1,98
1 1 #include "Catalogue/CatalogueExplorer.h"
2 2 #include "ui_CatalogueExplorer.h"
3 3
4 4 #include <Catalogue/CatalogueActionManager.h>
5 5 #include <Catalogue/CatalogueController.h>
6 6 #include <SqpApplication.h>
7 7 #include <Visualization/VisualizationWidget.h>
8 8
9 9 #include <DBCatalogue.h>
10 10 #include <DBEvent.h>
11 11
12 12 struct CatalogueExplorer::CatalogueExplorerPrivate {
13 13 CatalogueActionManager m_ActionManager;
14 14 };
15 15
16 16 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
17 17 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
18 18 ui(new Ui::CatalogueExplorer),
19 19 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()}
20 20 {
21 21 ui->setupUi(this);
22 22
23 23 impl->m_ActionManager.installSelectionZoneActions();
24 24
25 25 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
26 26 if (catalogues.count() == 1) {
27 27 ui->inspector->setCatalogue(catalogues.first());
28 28 }
29 29 else {
30 30 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
31 31 }
32 32
33 33 ui->events->populateWithCatalogues(catalogues);
34 34 });
35 35
36 36 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
37 37 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
38 38 });
39 39
40 40 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
41 41 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
42 42
43 43 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
44 44 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
45 45 ui->events->populateWithAllEvents();
46 46 });
47 47
48 48 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
49 49 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
50 50
51 51 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
52 52 if (events.count() == 1) {
53 53 ui->inspector->setEvent(events.first());
54 54 }
55 55 else {
56 56 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
57 57 }
58 58 });
59 59
60 60 connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) {
61 61 if (eventProducts.count() == 1) {
62 62 ui->inspector->setEventProduct(eventProducts.first().first,
63 63 eventProducts.first().second);
64 64 }
65 65 else {
66 66 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
67 67 }
68 68 });
69 69
70 70 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
71 71 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
72 72
73 73 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
74 74 sqpApp->catalogueController().updateCatalogue(catalogue);
75 75 ui->catalogues->setCatalogueChanges(catalogue, true);
76 76 });
77 77
78 78 connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) {
79 79 sqpApp->catalogueController().updateEvent(event);
80 80 ui->events->setEventChanges(event, true);
81 81 });
82 82
83 83 connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated,
84 [this](auto event, auto eventProduct) { ui->events->setEventChanges(event, true); });
84 [this](auto event, auto eventProduct) {
85 sqpApp->catalogueController().updateEventProduct(eventProduct);
86 ui->events->setEventChanges(event, true);
87 });
85 88 }
86 89
87 90 CatalogueExplorer::~CatalogueExplorer()
88 91 {
89 92 delete ui;
90 93 }
91 94
92 95 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization)
93 96 {
94 97 ui->events->setVisualizationWidget(visualization);
95 98 }
@@ -1,181 +1,211
1 1 #include "Catalogue/CatalogueInspectorWidget.h"
2 2 #include "ui_CatalogueInspectorWidget.h"
3 3
4 4 #include <Common/DateUtils.h>
5 5 #include <DBCatalogue.h>
6 6 #include <DBEvent.h>
7 7 #include <DBEventProduct.h>
8 8 #include <DBTag.h>
9 9
10 10 struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate {
11 11 std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr;
12 12 std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr;
13 13 std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr;
14 14
15 15 void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector,
16 16 Ui::CatalogueInspectorWidget *ui);
17 17 void connectEventUpdateSignals(CatalogueInspectorWidget *inspector,
18 18 Ui::CatalogueInspectorWidget *ui);
19 19 };
20 20
21 21 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
22 22 : QWidget(parent),
23 23 ui(new Ui::CatalogueInspectorWidget),
24 24 impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()}
25 25 {
26 26 ui->setupUi(this);
27 27 showPage(Page::Empty);
28 28
29 29 impl->connectCatalogueUpdateSignals(this, ui);
30 30 impl->connectEventUpdateSignals(this, ui);
31 31 }
32 32
33 33 CatalogueInspectorWidget::~CatalogueInspectorWidget()
34 34 {
35 35 delete ui;
36 36 }
37 37
38 38 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals(
39 39 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
40 40 {
41 41 connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() {
42 42 if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) {
43 43 m_DisplayedCatalogue->setName(ui->leCatalogueName->text());
44 44 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
45 45 }
46 46 });
47 47
48 48 connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() {
49 49 if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) {
50 50 m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text());
51 51 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
52 52 }
53 53 });
54 54 }
55 55
56 56 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals(
57 57 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
58 58 {
59 59 connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() {
60 60 if (ui->leEventName->text() != m_DisplayedEvent->getName()) {
61 61 m_DisplayedEvent->setName(ui->leEventName->text());
62 62 emit inspector->eventUpdated(m_DisplayedEvent);
63 63 }
64 64 });
65 65
66 66 connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() {
67 67 auto tags = ui->leEventTags->text().split(QRegExp("\\s+"));
68 68 std::list<QString> tagNames;
69 69 for (auto tag : tags) {
70 70 tagNames.push_back(tag);
71 71 }
72 72
73 73 if (m_DisplayedEvent->getTagsNames() != tagNames) {
74 74 m_DisplayedEvent->setTagsNames(tagNames);
75 75 emit inspector->eventUpdated(m_DisplayedEvent);
76 76 }
77 77 });
78 78
79 79 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
80 80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
81 auto oldProductId = m_DisplayedEventProduct->getProductId();
81 82 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
82 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
83
84 auto eventProducts = m_DisplayedEvent->getEventProducts();
85 for (auto &eventProduct : eventProducts) {
86 if (eventProduct.getProductId() == oldProductId) {
87 eventProduct.setProductId(m_DisplayedEventProduct->getProductId());
88 }
89 }
90 m_DisplayedEvent->setEventProducts(eventProducts);
91
92 emit inspector->eventUpdated(m_DisplayedEvent);
83 93 }
84 94 });
85 95
86 96 connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
87 97 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
88 98 if (time != m_DisplayedEventProduct->getTStart()) {
89 99 m_DisplayedEventProduct->setTStart(time);
90 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
100
101 auto eventProducts = m_DisplayedEvent->getEventProducts();
102 for (auto &eventProduct : eventProducts) {
103 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
104 eventProduct.setTStart(m_DisplayedEventProduct->getTStart());
105 }
106 }
107 m_DisplayedEvent->setEventProducts(eventProducts);
108
109 emit inspector->eventUpdated(m_DisplayedEvent);
91 110 }
92 111 });
93 112
94 113 connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
95 114 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
96 115 if (time != m_DisplayedEventProduct->getTEnd()) {
97 116 m_DisplayedEventProduct->setTEnd(time);
98 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
117
118 auto eventProducts = m_DisplayedEvent->getEventProducts();
119 for (auto &eventProduct : eventProducts) {
120 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
121 eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd());
122 }
123 }
124 m_DisplayedEvent->setEventProducts(eventProducts);
125
126 emit inspector->eventUpdated(m_DisplayedEvent);
99 127 }
100 128 });
101 129 }
102 130
103 131 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
104 132 {
105 133 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
106 134 }
107 135
108 136 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
109 137 {
110 138 return static_cast<Page>(ui->stackedWidget->currentIndex());
111 139 }
112 140
113 141 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
114 142 {
115 143 impl->m_DisplayedEvent = event;
116 144
117 145 blockSignals(true);
118 146
119 147 showPage(Page::EventProperties);
120 148 ui->leEventName->setEnabled(true);
121 149 ui->leEventName->setText(event->getName());
122 150 ui->leEventProduct->setEnabled(false);
123 151 ui->leEventProduct->setText(
124 152 QString::number(event->getEventProducts().size()).append(" product(s)"));
125 153
126 154 QString tagList;
127 155 auto tags = event->getTagsNames();
128 156 for (auto tag : tags) {
129 157 tagList += tag;
130 158 tagList += ' ';
131 159 }
132 160
133 161 ui->leEventTags->setEnabled(true);
134 162 ui->leEventTags->setText(tagList);
135 163
136 164 ui->dateTimeEventTStart->setEnabled(false);
137 165 ui->dateTimeEventTEnd->setEnabled(false);
138 166
139 167 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
140 168 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
141 169
142 170 blockSignals(false);
143 171 }
144 172
145 173 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
146 174 const std::shared_ptr<DBEventProduct> &eventProduct)
147 175 {
176
177 impl->m_DisplayedEvent = event;
148 178 impl->m_DisplayedEventProduct = eventProduct;
149 179
150 180 blockSignals(true);
151 181
152 182 showPage(Page::EventProperties);
153 183 ui->leEventName->setEnabled(false);
154 184 ui->leEventName->setText(event->getName());
155 185 ui->leEventProduct->setEnabled(true);
156 186 ui->leEventProduct->setText(eventProduct->getProductId());
157 187
158 188 ui->leEventTags->setEnabled(false);
159 189 ui->leEventTags->clear();
160 190
161 191 ui->dateTimeEventTStart->setEnabled(true);
162 192 ui->dateTimeEventTEnd->setEnabled(true);
163 193
164 194 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart()));
165 195 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd()));
166 196
167 197 blockSignals(false);
168 198 }
169 199
170 200 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
171 201 {
172 202 impl->m_DisplayedCatalogue = catalogue;
173 203
174 204 blockSignals(true);
175 205
176 206 showPage(Page::CatalogueProperties);
177 207 ui->leCatalogueName->setText(catalogue->getName());
178 208 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
179 209
180 210 blockSignals(false);
181 211 }
General Comments 0
You need to be logged in to leave comments. Login now