##// END OF EJS Templates
Displays TStart & TEnd for events
trabillard -
r1185:2ad912431473
parent child
Show More
@@ -1,381 +1,381
1 #include "Catalogue/CatalogueEventsModel.h"
1 #include "Catalogue/CatalogueEventsModel.h"
2
2
3 #include <Common/DateUtils.h>
3 #include <Common/DateUtils.h>
4 #include <Common/MimeTypesDef.h>
4 #include <Common/MimeTypesDef.h>
5 #include <DBEvent.h>
5 #include <DBEvent.h>
6 #include <DBEventProduct.h>
6 #include <DBEventProduct.h>
7 #include <DBTag.h>
7 #include <DBTag.h>
8 #include <Data/SqpRange.h>
8 #include <Data/SqpRange.h>
9 #include <SqpApplication.h>
9 #include <SqpApplication.h>
10 #include <Time/TimeController.h>
10 #include <Time/TimeController.h>
11
11
12 #include <list>
12 #include <list>
13 #include <unordered_map>
13 #include <unordered_map>
14
14
15 #include <QHash>
15 #include <QHash>
16 #include <QMimeData>
16 #include <QMimeData>
17
17
18 const auto EVENT_ITEM_TYPE = 1;
18 const auto EVENT_ITEM_TYPE = 1;
19 const auto EVENT_PRODUCT_ITEM_TYPE = 2;
19 const auto EVENT_PRODUCT_ITEM_TYPE = 2;
20
20
21 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
21 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
22 QVector<std::shared_ptr<DBEvent> > m_Events;
22 QVector<std::shared_ptr<DBEvent> > m_Events;
23 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
23 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
24
24
25 enum class Column { Name, TStart, TEnd, Tags, Product, NbColumn };
25 enum class Column { Name, TStart, TEnd, Tags, Product, NbColumn };
26 QStringList columnNames()
26 QStringList columnNames()
27 {
27 {
28 return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")};
28 return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")};
29 }
29 }
30
30
31 QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const
31 QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const
32 {
32 {
33 switch (static_cast<Column>(col)) {
33 switch (static_cast<Column>(col)) {
34 case Column::Name:
34 case Column::Name:
35 return event->getName();
35 return event->getName();
36 case Column::TStart:
36 case Column::TStart:
37 return "Oo"; // DateUtils::dateTime(event->getTStart());
37 return DateUtils::dateTime(event->getTStart());
38 case Column::TEnd:
38 case Column::TEnd:
39 return "oO"; // DateUtils::dateTime(event->getTEnd());
39 return DateUtils::dateTime(event->getTEnd());
40 case Column::Product: {
40 case Column::Product: {
41 auto eventProductsIt = m_EventProducts.find(event.get());
41 auto eventProductsIt = m_EventProducts.find(event.get());
42 if (eventProductsIt != m_EventProducts.cend()) {
42 if (eventProductsIt != m_EventProducts.cend()) {
43 return QString::number(m_EventProducts.at(event.get()).count()) + " product(s)";
43 return QString::number(m_EventProducts.at(event.get()).count()) + " product(s)";
44 }
44 }
45 else {
45 else {
46 return "0 product";
46 return "0 product";
47 }
47 }
48 }
48 }
49 case Column::Tags: {
49 case Column::Tags: {
50 QString tagList;
50 QString tagList;
51 auto tags = event->getTags();
51 auto tags = event->getTags();
52 for (auto tag : tags) {
52 for (auto tag : tags) {
53 tagList += tag.getName();
53 tagList += tag.getName();
54 tagList += ' ';
54 tagList += ' ';
55 }
55 }
56
56
57 return tagList;
57 return tagList;
58 }
58 }
59 default:
59 default:
60 break;
60 break;
61 }
61 }
62
62
63 Q_ASSERT(false);
63 Q_ASSERT(false);
64 return QStringLiteral("Unknown Data");
64 return QStringLiteral("Unknown Data");
65 }
65 }
66
66
67 void parseEventProduct(const std::shared_ptr<DBEvent> &event)
67 void parseEventProduct(const std::shared_ptr<DBEvent> &event)
68 {
68 {
69 for (auto product : event->getEventProducts()) {
69 for (auto product : event->getEventProducts()) {
70 m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product));
70 m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product));
71 }
71 }
72 }
72 }
73
73
74 QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const
74 QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const
75 {
75 {
76 switch (static_cast<Column>(col)) {
76 switch (static_cast<Column>(col)) {
77 case Column::Name:
77 case Column::Name:
78 return eventProduct->getProductId();
78 return eventProduct->getProductId();
79 case Column::TStart:
79 case Column::TStart:
80 return DateUtils::dateTime(eventProduct->getTStart());
80 return DateUtils::dateTime(eventProduct->getTStart());
81 case Column::TEnd:
81 case Column::TEnd:
82 return DateUtils::dateTime(eventProduct->getTEnd());
82 return DateUtils::dateTime(eventProduct->getTEnd());
83 case Column::Product:
83 case Column::Product:
84 return eventProduct->getProductId();
84 return eventProduct->getProductId();
85 case Column::Tags: {
85 case Column::Tags: {
86 return QString();
86 return QString();
87 }
87 }
88 default:
88 default:
89 break;
89 break;
90 }
90 }
91
91
92 Q_ASSERT(false);
92 Q_ASSERT(false);
93 return QStringLiteral("Unknown Data");
93 return QStringLiteral("Unknown Data");
94 }
94 }
95 };
95 };
96
96
97 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
97 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
98 : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()}
98 : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()}
99 {
99 {
100 }
100 }
101
101
102 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events)
102 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events)
103 {
103 {
104 beginResetModel();
104 beginResetModel();
105
105
106 impl->m_Events = events;
106 impl->m_Events = events;
107 impl->m_EventProducts.clear();
107 impl->m_EventProducts.clear();
108 for (auto event : events) {
108 for (auto event : events) {
109 impl->parseEventProduct(event);
109 impl->parseEventProduct(event);
110 }
110 }
111
111
112 endResetModel();
112 endResetModel();
113 }
113 }
114
114
115 std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const
115 std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const
116 {
116 {
117 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) {
117 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) {
118 return impl->m_Events.value(index.row());
118 return impl->m_Events.value(index.row());
119 }
119 }
120 else {
120 else {
121 return nullptr;
121 return nullptr;
122 }
122 }
123 }
123 }
124
124
125 std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const
125 std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const
126 {
126 {
127 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) {
127 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) {
128 return getEvent(index.parent());
128 return getEvent(index.parent());
129 }
129 }
130 else {
130 else {
131 return nullptr;
131 return nullptr;
132 }
132 }
133 }
133 }
134
134
135 std::shared_ptr<DBEventProduct>
135 std::shared_ptr<DBEventProduct>
136 CatalogueEventsModel::getEventProduct(const QModelIndex &index) const
136 CatalogueEventsModel::getEventProduct(const QModelIndex &index) const
137 {
137 {
138 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) {
138 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) {
139 auto event = static_cast<DBEvent *>(index.internalPointer());
139 auto event = static_cast<DBEvent *>(index.internalPointer());
140 return impl->m_EventProducts.at(event).value(index.row());
140 return impl->m_EventProducts.at(event).value(index.row());
141 }
141 }
142 else {
142 else {
143 return nullptr;
143 return nullptr;
144 }
144 }
145 }
145 }
146
146
147 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
147 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
148 {
148 {
149 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
149 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
150 impl->m_Events.append(event);
150 impl->m_Events.append(event);
151 impl->parseEventProduct(event);
151 impl->parseEventProduct(event);
152 endInsertRows();
152 endInsertRows();
153 }
153 }
154
154
155 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
155 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
156 {
156 {
157 auto index = impl->m_Events.indexOf(event);
157 auto index = impl->m_Events.indexOf(event);
158 if (index >= 0) {
158 if (index >= 0) {
159 beginRemoveRows(QModelIndex(), index, index);
159 beginRemoveRows(QModelIndex(), index, index);
160 impl->m_Events.removeAt(index);
160 impl->m_Events.removeAt(index);
161 impl->m_EventProducts.erase(event.get());
161 impl->m_EventProducts.erase(event.get());
162 endRemoveRows();
162 endRemoveRows();
163 }
163 }
164 }
164 }
165
165
166 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event)
166 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event)
167 {
167 {
168 auto i = impl->m_Events.indexOf(event);
168 auto i = impl->m_Events.indexOf(event);
169 if (i >= 0) {
169 if (i >= 0) {
170 auto eventIndex = index(i, 0);
170 auto eventIndex = index(i, 0);
171 auto colCount = columnCount();
171 auto colCount = columnCount();
172 emit dataChanged(eventIndex, index(i, colCount));
172 emit dataChanged(eventIndex, index(i, colCount));
173
173
174 auto childCount = rowCount(eventIndex);
174 auto childCount = rowCount(eventIndex);
175 emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex));
175 emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex));
176 }
176 }
177 }
177 }
178
178
179 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
179 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
180 {
180 {
181 if (!hasIndex(row, column, parent)) {
181 if (!hasIndex(row, column, parent)) {
182 return QModelIndex();
182 return QModelIndex();
183 }
183 }
184
184
185 switch (itemTypeOf(parent)) {
185 switch (itemTypeOf(parent)) {
186 case CatalogueEventsModel::ItemType::Root:
186 case CatalogueEventsModel::ItemType::Root:
187 return createIndex(row, column);
187 return createIndex(row, column);
188 case CatalogueEventsModel::ItemType::Event: {
188 case CatalogueEventsModel::ItemType::Event: {
189 auto event = getEvent(parent);
189 auto event = getEvent(parent);
190 return createIndex(row, column, event.get());
190 return createIndex(row, column, event.get());
191 }
191 }
192 case CatalogueEventsModel::ItemType::EventProduct:
192 case CatalogueEventsModel::ItemType::EventProduct:
193 break;
193 break;
194 default:
194 default:
195 break;
195 break;
196 }
196 }
197
197
198 return QModelIndex();
198 return QModelIndex();
199 }
199 }
200
200
201 QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const
201 QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const
202 {
202 {
203 switch (itemTypeOf(index)) {
203 switch (itemTypeOf(index)) {
204 case CatalogueEventsModel::ItemType::EventProduct: {
204 case CatalogueEventsModel::ItemType::EventProduct: {
205 auto parentEvent = static_cast<DBEvent *>(index.internalPointer());
205 auto parentEvent = static_cast<DBEvent *>(index.internalPointer());
206 auto it
206 auto it
207 = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(),
207 = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(),
208 [parentEvent](auto event) { return event.get() == parentEvent; });
208 [parentEvent](auto event) { return event.get() == parentEvent; });
209
209
210 if (it != impl->m_Events.cend()) {
210 if (it != impl->m_Events.cend()) {
211 return createIndex(it - impl->m_Events.cbegin(), 0);
211 return createIndex(it - impl->m_Events.cbegin(), 0);
212 }
212 }
213 else {
213 else {
214 return QModelIndex();
214 return QModelIndex();
215 }
215 }
216 }
216 }
217 case CatalogueEventsModel::ItemType::Root:
217 case CatalogueEventsModel::ItemType::Root:
218 break;
218 break;
219 case CatalogueEventsModel::ItemType::Event:
219 case CatalogueEventsModel::ItemType::Event:
220 break;
220 break;
221 default:
221 default:
222 break;
222 break;
223 }
223 }
224
224
225 return QModelIndex();
225 return QModelIndex();
226 }
226 }
227
227
228 int CatalogueEventsModel::rowCount(const QModelIndex &parent) const
228 int CatalogueEventsModel::rowCount(const QModelIndex &parent) const
229 {
229 {
230 if (parent.column() > 0) {
230 if (parent.column() > 0) {
231 return 0;
231 return 0;
232 }
232 }
233
233
234 switch (itemTypeOf(parent)) {
234 switch (itemTypeOf(parent)) {
235 case CatalogueEventsModel::ItemType::Root:
235 case CatalogueEventsModel::ItemType::Root:
236 return impl->m_Events.count();
236 return impl->m_Events.count();
237 case CatalogueEventsModel::ItemType::Event: {
237 case CatalogueEventsModel::ItemType::Event: {
238 auto event = getEvent(parent);
238 auto event = getEvent(parent);
239 return impl->m_EventProducts[event.get()].count();
239 return impl->m_EventProducts[event.get()].count();
240 }
240 }
241 case CatalogueEventsModel::ItemType::EventProduct:
241 case CatalogueEventsModel::ItemType::EventProduct:
242 break;
242 break;
243 default:
243 default:
244 break;
244 break;
245 }
245 }
246
246
247 return 0;
247 return 0;
248 }
248 }
249
249
250 int CatalogueEventsModel::columnCount(const QModelIndex &parent) const
250 int CatalogueEventsModel::columnCount(const QModelIndex &parent) const
251 {
251 {
252 return static_cast<int>(CatalogueEventsModelPrivate::Column::NbColumn);
252 return static_cast<int>(CatalogueEventsModelPrivate::Column::NbColumn);
253 }
253 }
254
254
255 Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const
255 Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const
256 {
256 {
257 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
257 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
258 }
258 }
259
259
260 QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const
260 QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const
261 {
261 {
262 if (index.isValid()) {
262 if (index.isValid()) {
263
263
264 auto type = itemTypeOf(index);
264 auto type = itemTypeOf(index);
265 if (type == CatalogueEventsModel::ItemType::Event) {
265 if (type == CatalogueEventsModel::ItemType::Event) {
266 auto event = getEvent(index);
266 auto event = getEvent(index);
267 switch (role) {
267 switch (role) {
268 case Qt::DisplayRole:
268 case Qt::DisplayRole:
269 return impl->eventData(index.column(), event);
269 return impl->eventData(index.column(), event);
270 break;
270 break;
271 }
271 }
272 }
272 }
273 else if (type == CatalogueEventsModel::ItemType::EventProduct) {
273 else if (type == CatalogueEventsModel::ItemType::EventProduct) {
274 auto product = getEventProduct(index);
274 auto product = getEventProduct(index);
275 switch (role) {
275 switch (role) {
276 case Qt::DisplayRole:
276 case Qt::DisplayRole:
277 return impl->eventProductData(index.column(), product);
277 return impl->eventProductData(index.column(), product);
278 break;
278 break;
279 }
279 }
280 }
280 }
281 }
281 }
282
282
283 return QVariant{};
283 return QVariant{};
284 }
284 }
285
285
286 QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const
286 QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const
287 {
287 {
288 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
288 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
289 return impl->columnNames().value(section);
289 return impl->columnNames().value(section);
290 }
290 }
291
291
292 return QVariant();
292 return QVariant();
293 }
293 }
294
294
295 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
295 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
296 {
296 {
297 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
297 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
298 [this, column, order](auto e1, auto e2) {
298 [this, column, order](auto e1, auto e2) {
299 auto data1 = impl->eventData(column, e1);
299 auto data1 = impl->eventData(column, e1);
300 auto data2 = impl->eventData(column, e2);
300 auto data2 = impl->eventData(column, e2);
301
301
302 auto result = data1.toString() < data2.toString();
302 auto result = data1.toString() < data2.toString();
303
303
304 return order == Qt::AscendingOrder ? result : !result;
304 return order == Qt::AscendingOrder ? result : !result;
305 });
305 });
306
306
307 emit dataChanged(QModelIndex(), QModelIndex());
307 emit dataChanged(QModelIndex(), QModelIndex());
308 }
308 }
309
309
310 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
310 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
311 {
311 {
312 return Qt::CopyAction | Qt::MoveAction;
312 return Qt::CopyAction | Qt::MoveAction;
313 }
313 }
314
314
315 QStringList CatalogueEventsModel::mimeTypes() const
315 QStringList CatalogueEventsModel::mimeTypes() const
316 {
316 {
317 return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE};
317 return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE};
318 }
318 }
319
319
320 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
320 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
321 {
321 {
322 auto mimeData = new QMimeData;
322 auto mimeData = new QMimeData;
323
323
324 bool isFirst = true;
324 bool isFirst = true;
325
325
326 QVector<std::shared_ptr<DBEvent> > eventList;
326 QVector<std::shared_ptr<DBEvent> > eventList;
327 QVector<std::shared_ptr<DBEventProduct> > eventProductList;
327 QVector<std::shared_ptr<DBEventProduct> > eventProductList;
328
328
329 SqpRange firstTimeRange;
329 SqpRange firstTimeRange;
330 for (const auto &index : indexes) {
330 for (const auto &index : indexes) {
331 if (index.column() == 0) { // only the first column
331 if (index.column() == 0) { // only the first column
332
332
333 auto type = itemTypeOf(index);
333 auto type = itemTypeOf(index);
334 if (type == ItemType::Event) {
334 if (type == ItemType::Event) {
335 auto event = getEvent(index);
335 auto event = getEvent(index);
336 eventList << event;
336 eventList << event;
337
337
338 if (isFirst) {
338 if (isFirst) {
339 isFirst = false;
339 isFirst = false;
340 // firstTimeRange.m_TStart = event->getTStart();
340 firstTimeRange.m_TStart = event->getTStart();
341 // firstTimeRange.m_TEnd = event->getTEnd();
341 firstTimeRange.m_TEnd = event->getTEnd();
342 }
342 }
343 }
343 }
344 else if (type == ItemType::EventProduct) {
344 else if (type == ItemType::EventProduct) {
345 auto product = getEventProduct(index);
345 auto product = getEventProduct(index);
346 eventProductList << product;
346 eventProductList << product;
347
347
348 if (isFirst) {
348 if (isFirst) {
349 isFirst = false;
349 isFirst = false;
350 firstTimeRange.m_TStart = product->getTStart();
350 firstTimeRange.m_TStart = product->getTStart();
351 firstTimeRange.m_TEnd = product->getTEnd();
351 firstTimeRange.m_TEnd = product->getTEnd();
352 }
352 }
353 }
353 }
354 }
354 }
355 }
355 }
356
356
357 auto eventsEncodedData
357 auto eventsEncodedData
358 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
358 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
359 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
359 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
360
360
361 if (eventList.count() + eventProductList.count() == 1) {
361 if (eventList.count() + eventProductList.count() == 1) {
362 // No time range MIME data if multiple events are dragged
362 // No time range MIME data if multiple events are dragged
363 auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange);
363 auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange);
364 mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData);
364 mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData);
365 }
365 }
366
366
367 return mimeData;
367 return mimeData;
368 }
368 }
369
369
370 CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const
370 CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const
371 {
371 {
372 if (!index.isValid()) {
372 if (!index.isValid()) {
373 return ItemType::Root;
373 return ItemType::Root;
374 }
374 }
375 else if (index.internalPointer() == nullptr) {
375 else if (index.internalPointer() == nullptr) {
376 return ItemType::Event;
376 return ItemType::Event;
377 }
377 }
378 else {
378 else {
379 return ItemType::EventProduct;
379 return ItemType::EventProduct;
380 }
380 }
381 }
381 }
@@ -1,314 +1,316
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 <CatalogueDao.h>
6 #include <CatalogueDao.h>
7 #include <DBCatalogue.h>
7 #include <DBCatalogue.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Visualization/VisualizationTabWidget.h>
9 #include <Visualization/VisualizationTabWidget.h>
10 #include <Visualization/VisualizationWidget.h>
10 #include <Visualization/VisualizationWidget.h>
11 #include <Visualization/VisualizationZoneWidget.h>
11 #include <Visualization/VisualizationZoneWidget.h>
12
12
13 #include <QDialog>
13 #include <QDialog>
14 #include <QDialogButtonBox>
14 #include <QDialogButtonBox>
15 #include <QListWidget>
15 #include <QListWidget>
16
16
17 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
17 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
18
18
19 /// Format of the dates appearing in the label of a cursor
19 /// Format of the dates appearing in the label of a cursor
20 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
20 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
21
21
22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
23
23
24 CatalogueEventsModel *m_Model = nullptr;
24 CatalogueEventsModel *m_Model = nullptr;
25 QStringList m_ZonesForTimeMode;
25 QStringList m_ZonesForTimeMode;
26 QString m_ZoneForGraphMode;
26 QString m_ZoneForGraphMode;
27
27
28 VisualizationWidget *m_VisualizationWidget = nullptr;
28 VisualizationWidget *m_VisualizationWidget = nullptr;
29
29
30 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
30 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
31 {
31 {
32 treeView->setSortingEnabled(false);
32 treeView->setSortingEnabled(false);
33 m_Model->setEvents(events);
33 m_Model->setEvents(events);
34 treeView->setSortingEnabled(true);
34 treeView->setSortingEnabled(true);
35 }
35 }
36
36
37 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
37 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
38 {
38 {
39 treeView->setSortingEnabled(false);
39 treeView->setSortingEnabled(false);
40 m_Model->addEvent(event);
40 m_Model->addEvent(event);
41 treeView->setSortingEnabled(true);
41 treeView->setSortingEnabled(true);
42 }
42 }
43
43
44 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
44 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
45 {
45 {
46 treeView->setSortingEnabled(false);
46 treeView->setSortingEnabled(false);
47 m_Model->removeEvent(event);
47 m_Model->removeEvent(event);
48 treeView->setSortingEnabled(true);
48 treeView->setSortingEnabled(true);
49 }
49 }
50
50
51 QStringList getAvailableVisualizationZoneList() const
51 QStringList getAvailableVisualizationZoneList() const
52 {
52 {
53 if (m_VisualizationWidget) {
53 if (m_VisualizationWidget) {
54 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
54 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
55 return tab->availableZoneWidgets();
55 return tab->availableZoneWidgets();
56 }
56 }
57 }
57 }
58
58
59 return QStringList{};
59 return QStringList{};
60 }
60 }
61
61
62 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
62 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
63 bool allowMultiSelection, const QPoint &location)
63 bool allowMultiSelection, const QPoint &location)
64 {
64 {
65 auto availableZones = getAvailableVisualizationZoneList();
65 auto availableZones = getAvailableVisualizationZoneList();
66 if (availableZones.isEmpty()) {
66 if (availableZones.isEmpty()) {
67 return QStringList{};
67 return QStringList{};
68 }
68 }
69
69
70 QDialog d(parent, Qt::Tool);
70 QDialog d(parent, Qt::Tool);
71 d.setWindowTitle("Choose a zone");
71 d.setWindowTitle("Choose a zone");
72 auto layout = new QVBoxLayout{&d};
72 auto layout = new QVBoxLayout{&d};
73 layout->setContentsMargins(0, 0, 0, 0);
73 layout->setContentsMargins(0, 0, 0, 0);
74 auto listWidget = new QListWidget{&d};
74 auto listWidget = new QListWidget{&d};
75 layout->addWidget(listWidget);
75 layout->addWidget(listWidget);
76
76
77 QSet<QListWidgetItem *> checkedItems;
77 QSet<QListWidgetItem *> checkedItems;
78 for (auto zone : availableZones) {
78 for (auto zone : availableZones) {
79 auto item = new QListWidgetItem{zone};
79 auto item = new QListWidgetItem{zone};
80 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
80 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
81 if (selectedZones.contains(zone)) {
81 if (selectedZones.contains(zone)) {
82 item->setCheckState(Qt::Checked);
82 item->setCheckState(Qt::Checked);
83 checkedItems << item;
83 checkedItems << item;
84 }
84 }
85 else {
85 else {
86 item->setCheckState(Qt::Unchecked);
86 item->setCheckState(Qt::Unchecked);
87 }
87 }
88
88
89 listWidget->addItem(item);
89 listWidget->addItem(item);
90 }
90 }
91
91
92 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
92 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
93 layout->addWidget(buttonBox);
93 layout->addWidget(buttonBox);
94
94
95 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
95 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
96 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
96 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
97
97
98 QObject::connect(listWidget, &QListWidget::itemChanged,
98 QObject::connect(listWidget, &QListWidget::itemChanged,
99 [&checkedItems, allowMultiSelection, listWidget](auto item) {
99 [&checkedItems, allowMultiSelection, listWidget](auto item) {
100 if (item->checkState() == Qt::Checked) {
100 if (item->checkState() == Qt::Checked) {
101 if (!allowMultiSelection) {
101 if (!allowMultiSelection) {
102 for (auto checkedItem : checkedItems) {
102 for (auto checkedItem : checkedItems) {
103 listWidget->blockSignals(true);
103 listWidget->blockSignals(true);
104 checkedItem->setCheckState(Qt::Unchecked);
104 checkedItem->setCheckState(Qt::Unchecked);
105 listWidget->blockSignals(false);
105 listWidget->blockSignals(false);
106 }
106 }
107
107
108 checkedItems.clear();
108 checkedItems.clear();
109 }
109 }
110 checkedItems << item;
110 checkedItems << item;
111 }
111 }
112 else {
112 else {
113 checkedItems.remove(item);
113 checkedItems.remove(item);
114 }
114 }
115 });
115 });
116
116
117 QStringList result;
117 QStringList result;
118
118
119 d.setMinimumWidth(120);
119 d.setMinimumWidth(120);
120 d.resize(d.minimumSizeHint());
120 d.resize(d.minimumSizeHint());
121 d.move(location);
121 d.move(location);
122 if (d.exec() == QDialog::Accepted) {
122 if (d.exec() == QDialog::Accepted) {
123 for (auto item : checkedItems) {
123 for (auto item : checkedItems) {
124 result += item->text();
124 result += item->text();
125 }
125 }
126 }
126 }
127 else {
127 else {
128 result = selectedZones;
128 result = selectedZones;
129 }
129 }
130
130
131 return result;
131 return result;
132 }
132 }
133
133
134 void updateForTimeMode(QTreeView *treeView)
134 void updateForTimeMode(QTreeView *treeView)
135 {
135 {
136 auto selectedRows = treeView->selectionModel()->selectedRows();
136 auto selectedRows = treeView->selectionModel()->selectedRows();
137
137
138 if (selectedRows.count() == 1) {
138 if (selectedRows.count() == 1) {
139 auto event = m_Model->getEvent(selectedRows.first());
139 auto event = m_Model->getEvent(selectedRows.first());
140 if (event) {
140 if (m_VisualizationWidget) {
141 if (m_VisualizationWidget) {
141 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
142 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
142
143
143 for (auto zoneName : m_ZonesForTimeMode) {
144 for (auto zoneName : m_ZonesForTimeMode) {
144 if (auto zone = tab->getZoneWithName(zoneName)) {
145 if (auto zone = tab->getZoneWithName(zoneName)) {
145 SqpRange eventRange;
146 SqpRange eventRange;
146 // eventRange.m_TStart = event->getTStart();
147 eventRange.m_TStart = event->getTStart();
147 // eventRange.m_TEnd = event->getTEnd();
148 eventRange.m_TEnd = event->getTEnd();
148 zone->setZoneRange(eventRange);
149 zone->setZoneRange(eventRange);
149 }
150 }
150 }
151 }
151 }
152 }
152 else {
153 else {
153 qCWarning(LOG_CatalogueEventsWidget())
154 qCWarning(LOG_CatalogueEventsWidget())
154 << "updateTimeZone: no tab found in the visualization";
155 << "updateTimeZone: no tab found in the visualization";
155 }
156 }
156 }
157 }
157 else {
158 else {
158 qCWarning(LOG_CatalogueEventsWidget())
159 qCWarning(LOG_CatalogueEventsWidget())
159 << "updateTimeZone: visualization widget not found";
160 << "updateTimeZone: visualization widget not found";
160 }
161 }
161 }
162 }
163 }
162 else {
164 else {
163 qCWarning(LOG_CatalogueEventsWidget())
165 qCWarning(LOG_CatalogueEventsWidget())
164 << "updateTimeZone: not compatible with multiple events selected";
166 << "updateTimeZone: not compatible with multiple events selected";
165 }
167 }
166 }
168 }
167
169
168 void updateForGraphMode(QTreeView *treeView)
170 void updateForGraphMode(QTreeView *treeView)
169 {
171 {
170 auto selectedRows = treeView->selectionModel()->selectedRows();
172 auto selectedRows = treeView->selectionModel()->selectedRows();
171
173
172 if (selectedRows.count() == 1) {
174 if (selectedRows.count() == 1) {
173 auto event = m_Model->getEvent(selectedRows.first());
175 auto event = m_Model->getEvent(selectedRows.first());
174 if (m_VisualizationWidget) {
176 if (m_VisualizationWidget) {
175 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
177 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
176 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
178 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
177 // TODO
179 // TODO
178 }
180 }
179 }
181 }
180 else {
182 else {
181 qCWarning(LOG_CatalogueEventsWidget())
183 qCWarning(LOG_CatalogueEventsWidget())
182 << "updateGraphMode: no tab found in the visualization";
184 << "updateGraphMode: no tab found in the visualization";
183 }
185 }
184 }
186 }
185 else {
187 else {
186 qCWarning(LOG_CatalogueEventsWidget())
188 qCWarning(LOG_CatalogueEventsWidget())
187 << "updateGraphMode: visualization widget not found";
189 << "updateGraphMode: visualization widget not found";
188 }
190 }
189 }
191 }
190 else {
192 else {
191 qCWarning(LOG_CatalogueEventsWidget())
193 qCWarning(LOG_CatalogueEventsWidget())
192 << "updateGraphMode: not compatible with multiple events selected";
194 << "updateGraphMode: not compatible with multiple events selected";
193 }
195 }
194 }
196 }
195 };
197 };
196
198
197 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
199 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
198 : QWidget(parent),
200 : QWidget(parent),
199 ui(new Ui::CatalogueEventsWidget),
201 ui(new Ui::CatalogueEventsWidget),
200 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
202 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
201 {
203 {
202 ui->setupUi(this);
204 ui->setupUi(this);
203
205
204 impl->m_Model = new CatalogueEventsModel{this};
206 impl->m_Model = new CatalogueEventsModel{this};
205 ui->treeView->setModel(impl->m_Model);
207 ui->treeView->setModel(impl->m_Model);
206
208
207 ui->treeView->setSortingEnabled(true);
209 ui->treeView->setSortingEnabled(true);
208 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
210 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
209 ui->treeView->setDragEnabled(true);
211 ui->treeView->setDragEnabled(true);
210
212
211 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
213 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
212 if (checked) {
214 if (checked) {
213 ui->btnChart->setChecked(false);
215 ui->btnChart->setChecked(false);
214 impl->m_ZonesForTimeMode
216 impl->m_ZonesForTimeMode
215 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
217 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
216 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
218 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
217
219
218 impl->updateForTimeMode(ui->treeView);
220 impl->updateForTimeMode(ui->treeView);
219 }
221 }
220 });
222 });
221
223
222 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
224 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
223 if (checked) {
225 if (checked) {
224 ui->btnTime->setChecked(false);
226 ui->btnTime->setChecked(false);
225 impl->m_ZoneForGraphMode
227 impl->m_ZoneForGraphMode
226 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
228 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
227 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
229 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
228 .value(0);
230 .value(0);
229
231
230 impl->updateForGraphMode(ui->treeView);
232 impl->updateForGraphMode(ui->treeView);
231 }
233 }
232 });
234 });
233
235
234 auto emitSelection = [this]() {
236 auto emitSelection = [this]() {
235 QVector<std::shared_ptr<DBEvent> > events;
237 QVector<std::shared_ptr<DBEvent> > events;
236 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
238 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
237
239
238 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
240 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
239
241
240 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
242 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
241 if (itemType == CatalogueEventsModel::ItemType::Event) {
243 if (itemType == CatalogueEventsModel::ItemType::Event) {
242 events << impl->m_Model->getEvent(rowIndex);
244 events << impl->m_Model->getEvent(rowIndex);
243 }
245 }
244 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
246 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
245 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
247 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
246 impl->m_Model->getEventProduct(rowIndex));
248 impl->m_Model->getEventProduct(rowIndex));
247 }
249 }
248 }
250 }
249
251
250 if (!events.isEmpty() && eventProducts.isEmpty()) {
252 if (!events.isEmpty() && eventProducts.isEmpty()) {
251 emit this->eventsSelected(events);
253 emit this->eventsSelected(events);
252 }
254 }
253 else if (events.isEmpty() && !eventProducts.isEmpty()) {
255 else if (events.isEmpty() && !eventProducts.isEmpty()) {
254 emit this->eventProductsSelected(eventProducts);
256 emit this->eventProductsSelected(eventProducts);
255 }
257 }
256 else {
258 else {
257 emit this->selectionCleared();
259 emit this->selectionCleared();
258 }
260 }
259 };
261 };
260
262
261 connect(ui->treeView, &QTreeView::clicked, emitSelection);
263 connect(ui->treeView, &QTreeView::clicked, emitSelection);
262 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
264 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
263
265
264 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
266 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
265 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
267 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
266 ui->btnChart->setEnabled(isNotMultiSelection);
268 ui->btnChart->setEnabled(isNotMultiSelection);
267 ui->btnTime->setEnabled(isNotMultiSelection);
269 ui->btnTime->setEnabled(isNotMultiSelection);
268
270
269 if (isNotMultiSelection && ui->btnTime->isChecked()) {
271 if (isNotMultiSelection && ui->btnTime->isChecked()) {
270 impl->updateForTimeMode(ui->treeView);
272 impl->updateForTimeMode(ui->treeView);
271 }
273 }
272 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
274 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
273 impl->updateForGraphMode(ui->treeView);
275 impl->updateForGraphMode(ui->treeView);
274 }
276 }
275 });
277 });
276
278
277 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
279 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
278 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
280 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
279 ui->treeView->header()->setSortIndicatorShown(true);
281 ui->treeView->header()->setSortIndicatorShown(true);
280 }
282 }
281
283
282 CatalogueEventsWidget::~CatalogueEventsWidget()
284 CatalogueEventsWidget::~CatalogueEventsWidget()
283 {
285 {
284 delete ui;
286 delete ui;
285 }
287 }
286
288
287 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
289 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
288 {
290 {
289 impl->m_VisualizationWidget = visualization;
291 impl->m_VisualizationWidget = visualization;
290 }
292 }
291
293
292 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
294 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
293 {
295 {
294 impl->m_Model->refreshEvent(event);
296 impl->m_Model->refreshEvent(event);
295 }
297 }
296
298
297 void CatalogueEventsWidget::populateWithCatalogues(
299 void CatalogueEventsWidget::populateWithCatalogues(
298 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
300 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
299 {
301 {
300 QSet<QUuid> eventIds;
302 QSet<QUuid> eventIds;
301 QVector<std::shared_ptr<DBEvent> > events;
303 QVector<std::shared_ptr<DBEvent> > events;
302
304
303 for (auto catalogue : catalogues) {
305 for (auto catalogue : catalogues) {
304 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
306 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
305 for (auto event : catalogueEvents) {
307 for (auto event : catalogueEvents) {
306 if (!eventIds.contains(event->getUniqId())) {
308 if (!eventIds.contains(event->getUniqId())) {
307 events << event;
309 events << event;
308 eventIds.insert(event->getUniqId());
310 eventIds.insert(event->getUniqId());
309 }
311 }
310 }
312 }
311 }
313 }
312
314
313 impl->setEvents(events, ui->treeView);
315 impl->setEvents(events, ui->treeView);
314 }
316 }
@@ -1,172 +1,172
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->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
66 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
67 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
67 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
68 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
68 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
69 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
69 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
70 }
70 }
71 });
71 });
72
72
73 connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() {
73 connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() {
74 // TODO
74 // TODO
75 });
75 });
76
76
77 connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
77 connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
78 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
78 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
79 if (time != m_DisplayedEventProduct->getTStart()) {
79 if (time != m_DisplayedEventProduct->getTStart()) {
80 m_DisplayedEventProduct->setTStart(time);
80 m_DisplayedEventProduct->setTStart(time);
81 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
81 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
82 }
82 }
83 });
83 });
84
84
85 connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
85 connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
86 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
86 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
87 if (time != m_DisplayedEventProduct->getTEnd()) {
87 if (time != m_DisplayedEventProduct->getTEnd()) {
88 m_DisplayedEventProduct->setTEnd(time);
88 m_DisplayedEventProduct->setTEnd(time);
89 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
89 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
90 }
90 }
91 });
91 });
92 }
92 }
93
93
94 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
94 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
95 {
95 {
96 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
96 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
97 }
97 }
98
98
99 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
99 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
100 {
100 {
101 return static_cast<Page>(ui->stackedWidget->currentIndex());
101 return static_cast<Page>(ui->stackedWidget->currentIndex());
102 }
102 }
103
103
104 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
104 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
105 {
105 {
106 impl->m_DisplayedEvent = event;
106 impl->m_DisplayedEvent = event;
107
107
108 blockSignals(true);
108 blockSignals(true);
109
109
110 showPage(Page::EventProperties);
110 showPage(Page::EventProperties);
111 ui->leEventName->setEnabled(true);
111 ui->leEventName->setEnabled(true);
112 ui->leEventName->setText(event->getName());
112 ui->leEventName->setText(event->getName());
113 ui->leEventProduct->setEnabled(false);
113 ui->leEventProduct->setEnabled(false);
114 ui->leEventProduct->setText(
114 ui->leEventProduct->setText(
115 QString::number(event->getEventProducts().size()).append(" product(s)"));
115 QString::number(event->getEventProducts().size()).append(" product(s)"));
116
116
117 QString tagList;
117 QString tagList;
118 auto tags = event->getTags();
118 auto tags = event->getTags();
119 for (auto tag : tags) {
119 for (auto tag : tags) {
120 tagList += tag.getName();
120 tagList += tag.getName();
121 tagList += ' ';
121 tagList += ' ';
122 }
122 }
123
123
124 ui->leEventTags->setEnabled(true);
124 ui->leEventTags->setEnabled(true);
125 ui->leEventTags->setText(tagList);
125 ui->leEventTags->setText(tagList);
126
126
127 ui->dateTimeEventTStart->setEnabled(false);
127 ui->dateTimeEventTStart->setEnabled(false);
128 ui->dateTimeEventTEnd->setEnabled(false);
128 ui->dateTimeEventTEnd->setEnabled(false);
129
129
130 // ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
130 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
131 // ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
131 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
132
132
133 blockSignals(false);
133 blockSignals(false);
134 }
134 }
135
135
136 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
136 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
137 const std::shared_ptr<DBEventProduct> &eventProduct)
137 const std::shared_ptr<DBEventProduct> &eventProduct)
138 {
138 {
139 impl->m_DisplayedEventProduct = eventProduct;
139 impl->m_DisplayedEventProduct = eventProduct;
140
140
141 blockSignals(true);
141 blockSignals(true);
142
142
143 showPage(Page::EventProperties);
143 showPage(Page::EventProperties);
144 ui->leEventName->setEnabled(false);
144 ui->leEventName->setEnabled(false);
145 ui->leEventName->setText(event->getName());
145 ui->leEventName->setText(event->getName());
146 ui->leEventProduct->setEnabled(true);
146 ui->leEventProduct->setEnabled(true);
147 ui->leEventProduct->setText(eventProduct->getProductId());
147 ui->leEventProduct->setText(eventProduct->getProductId());
148
148
149 ui->leEventTags->setEnabled(false);
149 ui->leEventTags->setEnabled(false);
150 ui->leEventTags->clear();
150 ui->leEventTags->clear();
151
151
152 ui->dateTimeEventTStart->setEnabled(true);
152 ui->dateTimeEventTStart->setEnabled(true);
153 ui->dateTimeEventTEnd->setEnabled(true);
153 ui->dateTimeEventTEnd->setEnabled(true);
154
154
155 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart()));
155 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart()));
156 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd()));
156 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd()));
157
157
158 blockSignals(false);
158 blockSignals(false);
159 }
159 }
160
160
161 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
161 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
162 {
162 {
163 impl->m_DisplayedCatalogue = catalogue;
163 impl->m_DisplayedCatalogue = catalogue;
164
164
165 blockSignals(true);
165 blockSignals(true);
166
166
167 showPage(Page::CatalogueProperties);
167 showPage(Page::CatalogueProperties);
168 ui->leCatalogueName->setText(catalogue->getName());
168 ui->leCatalogueName->setText(catalogue->getName());
169 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
169 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
170
170
171 blockSignals(false);
171 blockSignals(false);
172 }
172 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

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