##// END OF EJS Templates
small gui improvements
trabillard -
r1293:7c4b1f434cd6
parent child
Show More
@@ -1,418 +1,420
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 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
29
29
30 VisualizationWidget *m_VisualizationWidget = nullptr;
30 VisualizationWidget *m_VisualizationWidget = nullptr;
31
31
32 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
32 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
33 {
33 {
34 widget->ui->treeView->setSortingEnabled(false);
34 widget->ui->treeView->setSortingEnabled(false);
35 m_Model->setEvents(events);
35 m_Model->setEvents(events);
36 widget->ui->treeView->setSortingEnabled(true);
36 widget->ui->treeView->setSortingEnabled(true);
37
37
38 for (auto event : events) {
38 for (auto event : events) {
39 if (sqpApp->catalogueController().eventHasChanges(event)) {
39 if (sqpApp->catalogueController().eventHasChanges(event)) {
40 auto index = m_Model->indexOf(event);
40 auto index = m_Model->indexOf(event);
41 widget->setEventChanges(event, true);
41 widget->setEventChanges(event, true);
42 }
42 }
43 }
43 }
44 }
44 }
45
45
46 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
46 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
47 {
47 {
48 treeView->setSortingEnabled(false);
48 treeView->setSortingEnabled(false);
49 m_Model->addEvent(event);
49 m_Model->addEvent(event);
50 treeView->setSortingEnabled(true);
50 treeView->setSortingEnabled(true);
51 }
51 }
52
52
53 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
53 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
54 {
54 {
55 treeView->setSortingEnabled(false);
55 treeView->setSortingEnabled(false);
56 m_Model->removeEvent(event);
56 m_Model->removeEvent(event);
57 treeView->setSortingEnabled(true);
57 treeView->setSortingEnabled(true);
58 }
58 }
59
59
60 QStringList getAvailableVisualizationZoneList() const
60 QStringList getAvailableVisualizationZoneList() const
61 {
61 {
62 if (m_VisualizationWidget) {
62 if (m_VisualizationWidget) {
63 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
63 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
64 return tab->availableZoneWidgets();
64 return tab->availableZoneWidgets();
65 }
65 }
66 }
66 }
67
67
68 return QStringList{};
68 return QStringList{};
69 }
69 }
70
70
71 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
71 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
72 bool allowMultiSelection, const QPoint &location)
72 bool allowMultiSelection, const QPoint &location)
73 {
73 {
74 auto availableZones = getAvailableVisualizationZoneList();
74 auto availableZones = getAvailableVisualizationZoneList();
75 if (availableZones.isEmpty()) {
75 if (availableZones.isEmpty()) {
76 return QStringList{};
76 return QStringList{};
77 }
77 }
78
78
79 QDialog d(parent, Qt::Tool);
79 QDialog d(parent, Qt::Tool);
80 d.setWindowTitle("Choose a zone");
80 d.setWindowTitle("Choose a zone");
81 auto layout = new QVBoxLayout{&d};
81 auto layout = new QVBoxLayout{&d};
82 layout->setContentsMargins(0, 0, 0, 0);
82 layout->setContentsMargins(0, 0, 0, 0);
83 auto listWidget = new QListWidget{&d};
83 auto listWidget = new QListWidget{&d};
84 layout->addWidget(listWidget);
84 layout->addWidget(listWidget);
85
85
86 QSet<QListWidgetItem *> checkedItems;
86 QSet<QListWidgetItem *> checkedItems;
87 for (auto zone : availableZones) {
87 for (auto zone : availableZones) {
88 auto item = new QListWidgetItem{zone};
88 auto item = new QListWidgetItem{zone};
89 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
89 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
90 if (selectedZones.contains(zone)) {
90 if (selectedZones.contains(zone)) {
91 item->setCheckState(Qt::Checked);
91 item->setCheckState(Qt::Checked);
92 checkedItems << item;
92 checkedItems << item;
93 }
93 }
94 else {
94 else {
95 item->setCheckState(Qt::Unchecked);
95 item->setCheckState(Qt::Unchecked);
96 }
96 }
97
97
98 listWidget->addItem(item);
98 listWidget->addItem(item);
99 }
99 }
100
100
101 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
101 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
102 layout->addWidget(buttonBox);
102 layout->addWidget(buttonBox);
103
103
104 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
104 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
105 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
105 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
106
106
107 QObject::connect(listWidget, &QListWidget::itemChanged,
107 QObject::connect(listWidget, &QListWidget::itemChanged,
108 [&checkedItems, allowMultiSelection, listWidget](auto item) {
108 [&checkedItems, allowMultiSelection, listWidget](auto item) {
109 if (item->checkState() == Qt::Checked) {
109 if (item->checkState() == Qt::Checked) {
110 if (!allowMultiSelection) {
110 if (!allowMultiSelection) {
111 for (auto checkedItem : checkedItems) {
111 for (auto checkedItem : checkedItems) {
112 listWidget->blockSignals(true);
112 listWidget->blockSignals(true);
113 checkedItem->setCheckState(Qt::Unchecked);
113 checkedItem->setCheckState(Qt::Unchecked);
114 listWidget->blockSignals(false);
114 listWidget->blockSignals(false);
115 }
115 }
116
116
117 checkedItems.clear();
117 checkedItems.clear();
118 }
118 }
119 checkedItems << item;
119 checkedItems << item;
120 }
120 }
121 else {
121 else {
122 checkedItems.remove(item);
122 checkedItems.remove(item);
123 }
123 }
124 });
124 });
125
125
126 QStringList result;
126 QStringList result;
127
127
128 d.setMinimumWidth(120);
128 d.setMinimumWidth(120);
129 d.resize(d.minimumSizeHint());
129 d.resize(d.minimumSizeHint());
130 d.move(location);
130 d.move(location);
131 if (d.exec() == QDialog::Accepted) {
131 if (d.exec() == QDialog::Accepted) {
132 for (auto item : checkedItems) {
132 for (auto item : checkedItems) {
133 result += item->text();
133 result += item->text();
134 }
134 }
135 }
135 }
136 else {
136 else {
137 result = selectedZones;
137 result = selectedZones;
138 }
138 }
139
139
140 return result;
140 return result;
141 }
141 }
142
142
143 void updateForTimeMode(QTreeView *treeView)
143 void updateForTimeMode(QTreeView *treeView)
144 {
144 {
145 auto selectedRows = treeView->selectionModel()->selectedRows();
145 auto selectedRows = treeView->selectionModel()->selectedRows();
146
146
147 if (selectedRows.count() == 1) {
147 if (selectedRows.count() == 1) {
148 auto event = m_Model->getEvent(selectedRows.first());
148 auto event = m_Model->getEvent(selectedRows.first());
149 if (event) {
149 if (event) {
150 if (m_VisualizationWidget) {
150 if (m_VisualizationWidget) {
151 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
151 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
152
152
153 for (auto zoneName : m_ZonesForTimeMode) {
153 for (auto zoneName : m_ZonesForTimeMode) {
154 if (auto zone = tab->getZoneWithName(zoneName)) {
154 if (auto zone = tab->getZoneWithName(zoneName)) {
155 SqpRange eventRange;
155 SqpRange eventRange;
156 eventRange.m_TStart = event->getTStart();
156 eventRange.m_TStart = event->getTStart();
157 eventRange.m_TEnd = event->getTEnd();
157 eventRange.m_TEnd = event->getTEnd();
158 zone->setZoneRange(eventRange);
158 zone->setZoneRange(eventRange);
159 }
159 }
160 }
160 }
161 }
161 }
162 else {
162 else {
163 qCWarning(LOG_CatalogueEventsWidget())
163 qCWarning(LOG_CatalogueEventsWidget())
164 << "updateTimeZone: no tab found in the visualization";
164 << "updateTimeZone: no tab found in the visualization";
165 }
165 }
166 }
166 }
167 else {
167 else {
168 qCWarning(LOG_CatalogueEventsWidget())
168 qCWarning(LOG_CatalogueEventsWidget())
169 << "updateTimeZone: visualization widget not found";
169 << "updateTimeZone: visualization widget not found";
170 }
170 }
171 }
171 }
172 }
172 }
173 else {
173 else {
174 qCWarning(LOG_CatalogueEventsWidget())
174 qCWarning(LOG_CatalogueEventsWidget())
175 << "updateTimeZone: not compatible with multiple events selected";
175 << "updateTimeZone: not compatible with multiple events selected";
176 }
176 }
177 }
177 }
178
178
179 void updateForGraphMode(QTreeView *treeView)
179 void updateForGraphMode(QTreeView *treeView)
180 {
180 {
181 auto selectedRows = treeView->selectionModel()->selectedRows();
181 auto selectedRows = treeView->selectionModel()->selectedRows();
182
182
183 if (selectedRows.count() == 1) {
183 if (selectedRows.count() == 1) {
184 auto event = m_Model->getEvent(selectedRows.first());
184 auto event = m_Model->getEvent(selectedRows.first());
185 if (m_VisualizationWidget) {
185 if (m_VisualizationWidget) {
186 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
186 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
187 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
187 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
188 // TODO
188 // TODO
189 }
189 }
190 }
190 }
191 else {
191 else {
192 qCWarning(LOG_CatalogueEventsWidget())
192 qCWarning(LOG_CatalogueEventsWidget())
193 << "updateGraphMode: no tab found in the visualization";
193 << "updateGraphMode: no tab found in the visualization";
194 }
194 }
195 }
195 }
196 else {
196 else {
197 qCWarning(LOG_CatalogueEventsWidget())
197 qCWarning(LOG_CatalogueEventsWidget())
198 << "updateGraphMode: visualization widget not found";
198 << "updateGraphMode: visualization widget not found";
199 }
199 }
200 }
200 }
201 else {
201 else {
202 qCWarning(LOG_CatalogueEventsWidget())
202 qCWarning(LOG_CatalogueEventsWidget())
203 << "updateGraphMode: not compatible with multiple events selected";
203 << "updateGraphMode: not compatible with multiple events selected";
204 }
204 }
205 }
205 }
206 };
206 };
207
207
208 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
208 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
209 : QWidget(parent),
209 : QWidget(parent),
210 ui(new Ui::CatalogueEventsWidget),
210 ui(new Ui::CatalogueEventsWidget),
211 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
211 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
212 {
212 {
213 ui->setupUi(this);
213 ui->setupUi(this);
214
214
215 impl->m_Model = new CatalogueEventsModel{this};
215 impl->m_Model = new CatalogueEventsModel{this};
216 ui->treeView->setModel(impl->m_Model);
216 ui->treeView->setModel(impl->m_Model);
217
217
218 ui->treeView->setSortingEnabled(true);
218 ui->treeView->setSortingEnabled(true);
219 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
219 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
220 ui->treeView->setDragEnabled(true);
220 ui->treeView->setDragEnabled(true);
221
221
222 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
222 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
223 if (checked) {
223 if (checked) {
224 ui->btnChart->setChecked(false);
224 ui->btnChart->setChecked(false);
225 impl->m_ZonesForTimeMode
225 impl->m_ZonesForTimeMode
226 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
226 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
227 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
227 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
228
228
229 impl->updateForTimeMode(ui->treeView);
229 impl->updateForTimeMode(ui->treeView);
230 }
230 }
231 });
231 });
232
232
233 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
233 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
234 if (checked) {
234 if (checked) {
235 ui->btnTime->setChecked(false);
235 ui->btnTime->setChecked(false);
236 impl->m_ZoneForGraphMode
236 impl->m_ZoneForGraphMode
237 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
237 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
238 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
238 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
239 .value(0);
239 .value(0);
240
240
241 impl->updateForGraphMode(ui->treeView);
241 impl->updateForGraphMode(ui->treeView);
242 }
242 }
243 });
243 });
244
244
245 auto emitSelection = [this]() {
245 auto emitSelection = [this]() {
246 QVector<std::shared_ptr<DBEvent> > events;
246 QVector<std::shared_ptr<DBEvent> > events;
247 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
247 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
248
248
249 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
249 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
250
250
251 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
251 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
252 if (itemType == CatalogueEventsModel::ItemType::Event) {
252 if (itemType == CatalogueEventsModel::ItemType::Event) {
253 events << impl->m_Model->getEvent(rowIndex);
253 events << impl->m_Model->getEvent(rowIndex);
254 }
254 }
255 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
255 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
256 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
256 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
257 impl->m_Model->getEventProduct(rowIndex));
257 impl->m_Model->getEventProduct(rowIndex));
258 }
258 }
259 }
259 }
260
260
261 if (!events.isEmpty() && eventProducts.isEmpty()) {
261 if (!events.isEmpty() && eventProducts.isEmpty()) {
262 emit this->eventsSelected(events);
262 emit this->eventsSelected(events);
263 }
263 }
264 else if (events.isEmpty() && !eventProducts.isEmpty()) {
264 else if (events.isEmpty() && !eventProducts.isEmpty()) {
265 emit this->eventProductsSelected(eventProducts);
265 emit this->eventProductsSelected(eventProducts);
266 }
266 }
267 else {
267 else {
268 emit this->selectionCleared();
268 emit this->selectionCleared();
269 }
269 }
270 };
270 };
271
271
272 connect(ui->treeView, &QTreeView::clicked, emitSelection);
272 connect(ui->treeView, &QTreeView::clicked, emitSelection);
273 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
273 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
274
274
275 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
275 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
276 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
276 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
277 ui->btnChart->setEnabled(isNotMultiSelection);
277 ui->btnChart->setEnabled(isNotMultiSelection);
278 ui->btnTime->setEnabled(isNotMultiSelection);
278 ui->btnTime->setEnabled(isNotMultiSelection);
279
279
280 if (isNotMultiSelection && ui->btnTime->isChecked()) {
280 if (isNotMultiSelection && ui->btnTime->isChecked()) {
281 impl->updateForTimeMode(ui->treeView);
281 impl->updateForTimeMode(ui->treeView);
282 }
282 }
283 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
283 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
284 impl->updateForGraphMode(ui->treeView);
284 impl->updateForGraphMode(ui->treeView);
285 }
285 }
286 });
286 });
287
287
288 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
288 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
289 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
289 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags,
290 QHeaderView::Stretch);
290 QHeaderView::Stretch);
291 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
291 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
292 QHeaderView::Fixed);
292 QHeaderView::Fixed);
293 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
294 QHeaderView::Interactive);
293 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
295 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
294 VALIDATION_COLUMN_SIZE);
296 VALIDATION_COLUMN_SIZE);
295 ui->treeView->header()->setSortIndicatorShown(true);
297 ui->treeView->header()->setSortIndicatorShown(true);
296
298
297 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
299 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
298 auto allEvents = impl->m_Model->events();
300 auto allEvents = impl->m_Model->events();
299 for (auto event : allEvents) {
301 for (auto event : allEvents) {
300 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
302 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
301 }
303 }
302 });
304 });
303
305
304 populateWithAllEvents();
306 populateWithAllEvents();
305 }
307 }
306
308
307 CatalogueEventsWidget::~CatalogueEventsWidget()
309 CatalogueEventsWidget::~CatalogueEventsWidget()
308 {
310 {
309 delete ui;
311 delete ui;
310 }
312 }
311
313
312 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
314 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
313 {
315 {
314 impl->m_VisualizationWidget = visualization;
316 impl->m_VisualizationWidget = visualization;
315 }
317 }
316
318
317 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
319 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
318 {
320 {
319 impl->addEvent(event, ui->treeView);
321 impl->addEvent(event, ui->treeView);
320 }
322 }
321
323
322 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
324 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
323 {
325 {
324 impl->m_Model->refreshEvent(event);
326 impl->m_Model->refreshEvent(event);
325
327
326 auto eventIndex = impl->m_Model->indexOf(event);
328 auto eventIndex = impl->m_Model->indexOf(event);
327 auto validationIndex
329 auto validationIndex
328 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
330 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
329
331
330 if (validationIndex.isValid()) {
332 if (validationIndex.isValid()) {
331 if (hasChanges) {
333 if (hasChanges) {
332 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
334 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
333 auto widget = CatalogueExplorerHelper::buildValidationWidget(
335 auto widget = CatalogueExplorerHelper::buildValidationWidget(
334 ui->treeView,
336 ui->treeView,
335 [this, event]() {
337 [this, event]() {
336 sqpApp->catalogueController().saveEvent(event);
338 sqpApp->catalogueController().saveEvent(event);
337 setEventChanges(event, false);
339 setEventChanges(event, false);
338 },
340 },
339 [this, event]() { setEventChanges(event, false); });
341 [this, event]() { setEventChanges(event, false); });
340 ui->treeView->setIndexWidget(validationIndex, widget);
342 ui->treeView->setIndexWidget(validationIndex, widget);
341 }
343 }
342 }
344 }
343 else {
345 else {
344 // Note: the widget is destroyed
346 // Note: the widget is destroyed
345 ui->treeView->setIndexWidget(validationIndex, nullptr);
347 ui->treeView->setIndexWidget(validationIndex, nullptr);
346 }
348 }
347 }
349 }
348 else {
350 else {
349 qCWarning(LOG_CatalogueEventsWidget())
351 qCWarning(LOG_CatalogueEventsWidget())
350 << "setEventChanges: the event is not displayed in the model.";
352 << "setEventChanges: the event is not displayed in the model.";
351 }
353 }
352 }
354 }
353
355
354 QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
356 QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
355 {
357 {
356 return impl->m_DisplayedCatalogues;
358 return impl->m_DisplayedCatalogues;
357 }
359 }
358
360
359 bool CatalogueEventsWidget::isAllEventsDisplayed() const
361 bool CatalogueEventsWidget::isAllEventsDisplayed() const
360 {
362 {
361 return impl->m_DisplayedCatalogues.isEmpty() && !impl->m_Model->events().isEmpty();
363 return impl->m_DisplayedCatalogues.isEmpty() && !impl->m_Model->events().isEmpty();
362 }
364 }
363
365
364 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
366 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
365 {
367 {
366 return impl->m_Model->indexOf(event).isValid();
368 return impl->m_Model->indexOf(event).isValid();
367 }
369 }
368
370
369 void CatalogueEventsWidget::populateWithCatalogues(
371 void CatalogueEventsWidget::populateWithCatalogues(
370 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
372 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
371 {
373 {
372 impl->m_DisplayedCatalogues = catalogues;
374 impl->m_DisplayedCatalogues = catalogues;
373
375
374 QSet<QUuid> eventIds;
376 QSet<QUuid> eventIds;
375 QVector<std::shared_ptr<DBEvent> > events;
377 QVector<std::shared_ptr<DBEvent> > events;
376
378
377 for (auto catalogue : catalogues) {
379 for (auto catalogue : catalogues) {
378 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
380 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
379 for (auto event : catalogueEvents) {
381 for (auto event : catalogueEvents) {
380 if (!eventIds.contains(event->getUniqId())) {
382 if (!eventIds.contains(event->getUniqId())) {
381 events << event;
383 events << event;
382 eventIds.insert(event->getUniqId());
384 eventIds.insert(event->getUniqId());
383 }
385 }
384 }
386 }
385 }
387 }
386
388
387 impl->setEvents(events, this);
389 impl->setEvents(events, this);
388 }
390 }
389
391
390 void CatalogueEventsWidget::populateWithAllEvents()
392 void CatalogueEventsWidget::populateWithAllEvents()
391 {
393 {
392 impl->m_DisplayedCatalogues.clear();
394 impl->m_DisplayedCatalogues.clear();
393
395
394 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
396 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
395
397
396 QVector<std::shared_ptr<DBEvent> > events;
398 QVector<std::shared_ptr<DBEvent> > events;
397 for (auto event : allEvents) {
399 for (auto event : allEvents) {
398 events << event;
400 events << event;
399 }
401 }
400
402
401 impl->setEvents(events, this);
403 impl->setEvents(events, this);
402 }
404 }
403
405
404 void CatalogueEventsWidget::clear()
406 void CatalogueEventsWidget::clear()
405 {
407 {
406 impl->m_DisplayedCatalogues.clear();
408 impl->m_DisplayedCatalogues.clear();
407 impl->setEvents({}, this);
409 impl->setEvents({}, this);
408 }
410 }
409
411
410 void CatalogueEventsWidget::refresh()
412 void CatalogueEventsWidget::refresh()
411 {
413 {
412 if (impl->m_DisplayedCatalogues.isEmpty()) {
414 if (impl->m_DisplayedCatalogues.isEmpty()) {
413 populateWithAllEvents();
415 populateWithAllEvents();
414 }
416 }
415 else {
417 else {
416 populateWithCatalogues(impl->m_DisplayedCatalogues);
418 populateWithCatalogues(impl->m_DisplayedCatalogues);
417 }
419 }
418 }
420 }
@@ -1,211 +1,211
1 #include "Catalogue/CatalogueInspectorWidget.h"
1 #include "Catalogue/CatalogueInspectorWidget.h"
2 #include "ui_CatalogueInspectorWidget.h"
2 #include "ui_CatalogueInspectorWidget.h"
3
3
4 #include <Common/DateUtils.h>
4 #include <Common/DateUtils.h>
5 #include <DBCatalogue.h>
5 #include <DBCatalogue.h>
6 #include <DBEvent.h>
6 #include <DBEvent.h>
7 #include <DBEventProduct.h>
7 #include <DBEventProduct.h>
8 #include <DBTag.h>
8 #include <DBTag.h>
9
9
10 struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate {
10 struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate {
11 std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr;
11 std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr;
12 std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr;
12 std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr;
13 std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr;
13 std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr;
14
14
15 void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector,
15 void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector,
16 Ui::CatalogueInspectorWidget *ui);
16 Ui::CatalogueInspectorWidget *ui);
17 void connectEventUpdateSignals(CatalogueInspectorWidget *inspector,
17 void connectEventUpdateSignals(CatalogueInspectorWidget *inspector,
18 Ui::CatalogueInspectorWidget *ui);
18 Ui::CatalogueInspectorWidget *ui);
19 };
19 };
20
20
21 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
21 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
22 : QWidget(parent),
22 : QWidget(parent),
23 ui(new Ui::CatalogueInspectorWidget),
23 ui(new Ui::CatalogueInspectorWidget),
24 impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()}
24 impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()}
25 {
25 {
26 ui->setupUi(this);
26 ui->setupUi(this);
27 showPage(Page::Empty);
27 showPage(Page::Empty);
28
28
29 impl->connectCatalogueUpdateSignals(this, ui);
29 impl->connectCatalogueUpdateSignals(this, ui);
30 impl->connectEventUpdateSignals(this, ui);
30 impl->connectEventUpdateSignals(this, ui);
31 }
31 }
32
32
33 CatalogueInspectorWidget::~CatalogueInspectorWidget()
33 CatalogueInspectorWidget::~CatalogueInspectorWidget()
34 {
34 {
35 delete ui;
35 delete ui;
36 }
36 }
37
37
38 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals(
38 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals(
39 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
39 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
40 {
40 {
41 connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() {
41 connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() {
42 if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) {
42 if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) {
43 m_DisplayedCatalogue->setName(ui->leCatalogueName->text());
43 m_DisplayedCatalogue->setName(ui->leCatalogueName->text());
44 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
44 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
45 }
45 }
46 });
46 });
47
47
48 connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() {
48 connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() {
49 if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) {
49 if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) {
50 m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text());
50 m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text());
51 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
51 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
52 }
52 }
53 });
53 });
54 }
54 }
55
55
56 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals(
56 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals(
57 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
57 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
58 {
58 {
59 connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() {
59 connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() {
60 if (ui->leEventName->text() != m_DisplayedEvent->getName()) {
60 if (ui->leEventName->text() != m_DisplayedEvent->getName()) {
61 m_DisplayedEvent->setName(ui->leEventName->text());
61 m_DisplayedEvent->setName(ui->leEventName->text());
62 emit inspector->eventUpdated(m_DisplayedEvent);
62 emit inspector->eventUpdated(m_DisplayedEvent);
63 }
63 }
64 });
64 });
65
65
66 connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() {
66 connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() {
67 auto tags = ui->leEventTags->text().split(QRegExp("\\s+"));
67 auto tags = ui->leEventTags->text().split(QRegExp("\\s+"));
68 std::list<QString> tagNames;
68 std::list<QString> tagNames;
69 for (auto tag : tags) {
69 for (auto tag : tags) {
70 tagNames.push_back(tag);
70 tagNames.push_back(tag);
71 }
71 }
72
72
73 if (m_DisplayedEvent->getTagsNames() != tagNames) {
73 if (m_DisplayedEvent->getTagsNames() != tagNames) {
74 m_DisplayedEvent->setTagsNames(tagNames);
74 m_DisplayedEvent->setTagsNames(tagNames);
75 emit inspector->eventUpdated(m_DisplayedEvent);
75 emit inspector->eventUpdated(m_DisplayedEvent);
76 }
76 }
77 });
77 });
78
78
79 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
79 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
81 auto oldProductId = m_DisplayedEventProduct->getProductId();
81 auto oldProductId = m_DisplayedEventProduct->getProductId();
82 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
82 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
83
83
84 auto eventProducts = m_DisplayedEvent->getEventProducts();
84 auto eventProducts = m_DisplayedEvent->getEventProducts();
85 for (auto &eventProduct : eventProducts) {
85 for (auto &eventProduct : eventProducts) {
86 if (eventProduct.getProductId() == oldProductId) {
86 if (eventProduct.getProductId() == oldProductId) {
87 eventProduct.setProductId(m_DisplayedEventProduct->getProductId());
87 eventProduct.setProductId(m_DisplayedEventProduct->getProductId());
88 }
88 }
89 }
89 }
90 m_DisplayedEvent->setEventProducts(eventProducts);
90 m_DisplayedEvent->setEventProducts(eventProducts);
91
91
92 emit inspector->eventUpdated(m_DisplayedEvent);
92 emit inspector->eventUpdated(m_DisplayedEvent);
93 }
93 }
94 });
94 });
95
95
96 connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
96 connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
97 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
97 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
98 if (time != m_DisplayedEventProduct->getTStart()) {
98 if (time != m_DisplayedEventProduct->getTStart()) {
99 m_DisplayedEventProduct->setTStart(time);
99 m_DisplayedEventProduct->setTStart(time);
100
100
101 auto eventProducts = m_DisplayedEvent->getEventProducts();
101 auto eventProducts = m_DisplayedEvent->getEventProducts();
102 for (auto &eventProduct : eventProducts) {
102 for (auto &eventProduct : eventProducts) {
103 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
103 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
104 eventProduct.setTStart(m_DisplayedEventProduct->getTStart());
104 eventProduct.setTStart(m_DisplayedEventProduct->getTStart());
105 }
105 }
106 }
106 }
107 m_DisplayedEvent->setEventProducts(eventProducts);
107 m_DisplayedEvent->setEventProducts(eventProducts);
108
108
109 emit inspector->eventUpdated(m_DisplayedEvent);
109 emit inspector->eventUpdated(m_DisplayedEvent);
110 }
110 }
111 });
111 });
112
112
113 connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
113 connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
114 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
114 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
115 if (time != m_DisplayedEventProduct->getTEnd()) {
115 if (time != m_DisplayedEventProduct->getTEnd()) {
116 m_DisplayedEventProduct->setTEnd(time);
116 m_DisplayedEventProduct->setTEnd(time);
117
117
118 auto eventProducts = m_DisplayedEvent->getEventProducts();
118 auto eventProducts = m_DisplayedEvent->getEventProducts();
119 for (auto &eventProduct : eventProducts) {
119 for (auto &eventProduct : eventProducts) {
120 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
120 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
121 eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd());
121 eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd());
122 }
122 }
123 }
123 }
124 m_DisplayedEvent->setEventProducts(eventProducts);
124 m_DisplayedEvent->setEventProducts(eventProducts);
125
125
126 emit inspector->eventUpdated(m_DisplayedEvent);
126 emit inspector->eventUpdated(m_DisplayedEvent);
127 }
127 }
128 });
128 });
129 }
129 }
130
130
131 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
131 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
132 {
132 {
133 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
133 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
134 }
134 }
135
135
136 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
136 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
137 {
137 {
138 return static_cast<Page>(ui->stackedWidget->currentIndex());
138 return static_cast<Page>(ui->stackedWidget->currentIndex());
139 }
139 }
140
140
141 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
141 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
142 {
142 {
143 impl->m_DisplayedEvent = event;
143 impl->m_DisplayedEvent = event;
144
144
145 blockSignals(true);
145 blockSignals(true);
146
146
147 showPage(Page::EventProperties);
147 showPage(Page::EventProperties);
148 ui->leEventName->setEnabled(true);
148 ui->leEventName->setEnabled(true);
149 ui->leEventName->setText(event->getName());
149 ui->leEventName->setText(event->getName());
150 ui->leEventProduct->setEnabled(false);
150 ui->leEventProduct->setEnabled(false);
151 ui->leEventProduct->setText(
151 ui->leEventProduct->setText(
152 QString::number(event->getEventProducts().size()).append(" product(s)"));
152 QString::number(event->getEventProducts().size()).append(" product(s)"));
153
153
154 QString tagList;
154 QString tagList;
155 auto tags = event->getTagsNames();
155 auto tags = event->getTagsNames();
156 for (auto tag : tags) {
156 for (auto tag : tags) {
157 tagList += tag;
157 tagList += tag;
158 tagList += ' ';
158 tagList += ' ';
159 }
159 }
160
160
161 ui->leEventTags->setEnabled(true);
161 ui->leEventTags->setEnabled(true);
162 ui->leEventTags->setText(tagList);
162 ui->leEventTags->setText(tagList);
163
163
164 ui->dateTimeEventTStart->setEnabled(false);
164 ui->dateTimeEventTStart->setEnabled(false);
165 ui->dateTimeEventTEnd->setEnabled(false);
165 ui->dateTimeEventTEnd->setEnabled(false);
166
166
167 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
167 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
168 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
168 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
169
169
170 blockSignals(false);
170 blockSignals(false);
171 }
171 }
172
172
173 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
173 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
174 const std::shared_ptr<DBEventProduct> &eventProduct)
174 const std::shared_ptr<DBEventProduct> &eventProduct)
175 {
175 {
176
176
177 impl->m_DisplayedEvent = event;
177 impl->m_DisplayedEvent = event;
178 impl->m_DisplayedEventProduct = eventProduct;
178 impl->m_DisplayedEventProduct = eventProduct;
179
179
180 blockSignals(true);
180 blockSignals(true);
181
181
182 showPage(Page::EventProperties);
182 showPage(Page::EventProperties);
183 ui->leEventName->setEnabled(false);
183 ui->leEventName->setEnabled(false);
184 ui->leEventName->setText(event->getName());
184 ui->leEventName->setText(event->getName());
185 ui->leEventProduct->setEnabled(true);
185 ui->leEventProduct->setEnabled(false);
186 ui->leEventProduct->setText(eventProduct->getProductId());
186 ui->leEventProduct->setText(eventProduct->getProductId());
187
187
188 ui->leEventTags->setEnabled(false);
188 ui->leEventTags->setEnabled(false);
189 ui->leEventTags->clear();
189 ui->leEventTags->clear();
190
190
191 ui->dateTimeEventTStart->setEnabled(true);
191 ui->dateTimeEventTStart->setEnabled(true);
192 ui->dateTimeEventTEnd->setEnabled(true);
192 ui->dateTimeEventTEnd->setEnabled(true);
193
193
194 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart()));
194 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart()));
195 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd()));
195 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd()));
196
196
197 blockSignals(false);
197 blockSignals(false);
198 }
198 }
199
199
200 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
200 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
201 {
201 {
202 impl->m_DisplayedCatalogue = catalogue;
202 impl->m_DisplayedCatalogue = catalogue;
203
203
204 blockSignals(true);
204 blockSignals(true);
205
205
206 showPage(Page::CatalogueProperties);
206 showPage(Page::CatalogueProperties);
207 ui->leCatalogueName->setText(catalogue->getName());
207 ui->leCatalogueName->setText(catalogue->getName());
208 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
208 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
209
209
210 blockSignals(false);
210 blockSignals(false);
211 }
211 }
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