##// END OF EJS Templates
Merge branch 'feature/CatalogueGuiPart2' into develop
trabillard -
r1155:17cb73ee00c8 merge
parent child
Show More
@@ -0,0 +1,381
1 #include "Catalogue/CatalogueEventsModel.h"
2
3 #include <Common/DateUtils.h>
4 #include <Common/MimeTypesDef.h>
5 #include <DBEvent.h>
6 #include <DBEventProduct.h>
7 #include <DBTag.h>
8 #include <Data/SqpRange.h>
9 #include <SqpApplication.h>
10 #include <Time/TimeController.h>
11
12 #include <list>
13 #include <unordered_map>
14
15 #include <QHash>
16 #include <QMimeData>
17
18 const auto EVENT_ITEM_TYPE = 1;
19 const auto EVENT_PRODUCT_ITEM_TYPE = 2;
20
21 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
22 QVector<std::shared_ptr<DBEvent> > m_Events;
23 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
24
25 enum class Column { Name, TStart, TEnd, Tags, Product, NbColumn };
26 QStringList columnNames()
27 {
28 return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")};
29 }
30
31 QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const
32 {
33 switch (static_cast<Column>(col)) {
34 case Column::Name:
35 return event->getName();
36 case Column::TStart:
37 return DateUtils::dateTime(event->getTStart());
38 case Column::TEnd:
39 return DateUtils::dateTime(event->getTEnd());
40 case Column::Product: {
41 auto eventProductsIt = m_EventProducts.find(event.get());
42 if (eventProductsIt != m_EventProducts.cend()) {
43 return QString::number(m_EventProducts.at(event.get()).count()) + " product(s)";
44 }
45 else {
46 return "0 product";
47 }
48 }
49 case Column::Tags: {
50 QString tagList;
51 auto tags = event->getTags();
52 for (auto tag : tags) {
53 tagList += tag.getName();
54 tagList += ' ';
55 }
56
57 return tagList;
58 }
59 default:
60 break;
61 }
62
63 Q_ASSERT(false);
64 return QStringLiteral("Unknown Data");
65 }
66
67 void parseEventProduct(const std::shared_ptr<DBEvent> &event)
68 {
69 for (auto product : event->getEventProducts()) {
70 m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product));
71 }
72 }
73
74 QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const
75 {
76 switch (static_cast<Column>(col)) {
77 case Column::Name:
78 return eventProduct->getProductId();
79 case Column::TStart:
80 return DateUtils::dateTime(eventProduct->getTStart());
81 case Column::TEnd:
82 return DateUtils::dateTime(eventProduct->getTEnd());
83 case Column::Product:
84 return eventProduct->getProductId();
85 case Column::Tags: {
86 return QString();
87 }
88 default:
89 break;
90 }
91
92 Q_ASSERT(false);
93 return QStringLiteral("Unknown Data");
94 }
95 };
96
97 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
98 : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()}
99 {
100 }
101
102 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events)
103 {
104 beginResetModel();
105
106 impl->m_Events = events;
107 impl->m_EventProducts.clear();
108 for (auto event : events) {
109 impl->parseEventProduct(event);
110 }
111
112 endResetModel();
113 }
114
115 std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const
116 {
117 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) {
118 return impl->m_Events.value(index.row());
119 }
120 else {
121 return nullptr;
122 }
123 }
124
125 std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const
126 {
127 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) {
128 return getEvent(index.parent());
129 }
130 else {
131 return nullptr;
132 }
133 }
134
135 std::shared_ptr<DBEventProduct>
136 CatalogueEventsModel::getEventProduct(const QModelIndex &index) const
137 {
138 if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) {
139 auto event = static_cast<DBEvent *>(index.internalPointer());
140 return impl->m_EventProducts.at(event).value(index.row());
141 }
142 else {
143 return nullptr;
144 }
145 }
146
147 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
148 {
149 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
150 impl->m_Events.append(event);
151 impl->parseEventProduct(event);
152 endInsertRows();
153 }
154
155 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
156 {
157 auto index = impl->m_Events.indexOf(event);
158 if (index >= 0) {
159 beginRemoveRows(QModelIndex(), index, index);
160 impl->m_Events.removeAt(index);
161 impl->m_EventProducts.erase(event.get());
162 endRemoveRows();
163 }
164 }
165
166 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event)
167 {
168 auto i = impl->m_Events.indexOf(event);
169 if (i >= 0) {
170 auto eventIndex = index(i, 0);
171 auto colCount = columnCount();
172 emit dataChanged(eventIndex, index(i, colCount));
173
174 auto childCount = rowCount(eventIndex);
175 emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex));
176 }
177 }
178
179 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
180 {
181 if (!hasIndex(row, column, parent)) {
182 return QModelIndex();
183 }
184
185 switch (itemTypeOf(parent)) {
186 case CatalogueEventsModel::ItemType::Root:
187 return createIndex(row, column);
188 case CatalogueEventsModel::ItemType::Event: {
189 auto event = getEvent(parent);
190 return createIndex(row, column, event.get());
191 }
192 case CatalogueEventsModel::ItemType::EventProduct:
193 break;
194 default:
195 break;
196 }
197
198 return QModelIndex();
199 }
200
201 QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const
202 {
203 switch (itemTypeOf(index)) {
204 case CatalogueEventsModel::ItemType::EventProduct: {
205 auto parentEvent = static_cast<DBEvent *>(index.internalPointer());
206 auto it
207 = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(),
208 [parentEvent](auto event) { return event.get() == parentEvent; });
209
210 if (it != impl->m_Events.cend()) {
211 return createIndex(it - impl->m_Events.cbegin(), 0);
212 }
213 else {
214 return QModelIndex();
215 }
216 }
217 case CatalogueEventsModel::ItemType::Root:
218 break;
219 case CatalogueEventsModel::ItemType::Event:
220 break;
221 default:
222 break;
223 }
224
225 return QModelIndex();
226 }
227
228 int CatalogueEventsModel::rowCount(const QModelIndex &parent) const
229 {
230 if (parent.column() > 0) {
231 return 0;
232 }
233
234 switch (itemTypeOf(parent)) {
235 case CatalogueEventsModel::ItemType::Root:
236 return impl->m_Events.count();
237 case CatalogueEventsModel::ItemType::Event: {
238 auto event = getEvent(parent);
239 return impl->m_EventProducts[event.get()].count();
240 }
241 case CatalogueEventsModel::ItemType::EventProduct:
242 break;
243 default:
244 break;
245 }
246
247 return 0;
248 }
249
250 int CatalogueEventsModel::columnCount(const QModelIndex &parent) const
251 {
252 return static_cast<int>(CatalogueEventsModelPrivate::Column::NbColumn);
253 }
254
255 Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const
256 {
257 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
258 }
259
260 QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const
261 {
262 if (index.isValid()) {
263
264 auto type = itemTypeOf(index);
265 if (type == CatalogueEventsModel::ItemType::Event) {
266 auto event = getEvent(index);
267 switch (role) {
268 case Qt::DisplayRole:
269 return impl->eventData(index.column(), event);
270 break;
271 }
272 }
273 else if (type == CatalogueEventsModel::ItemType::EventProduct) {
274 auto product = getEventProduct(index);
275 switch (role) {
276 case Qt::DisplayRole:
277 return impl->eventProductData(index.column(), product);
278 break;
279 }
280 }
281 }
282
283 return QVariant{};
284 }
285
286 QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const
287 {
288 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
289 return impl->columnNames().value(section);
290 }
291
292 return QVariant();
293 }
294
295 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
296 {
297 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
298 [this, column, order](auto e1, auto e2) {
299 auto data1 = impl->eventData(column, e1);
300 auto data2 = impl->eventData(column, e2);
301
302 auto result = data1.toString() < data2.toString();
303
304 return order == Qt::AscendingOrder ? result : !result;
305 });
306
307 emit dataChanged(QModelIndex(), QModelIndex());
308 }
309
310 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
311 {
312 return Qt::CopyAction | Qt::MoveAction;
313 }
314
315 QStringList CatalogueEventsModel::mimeTypes() const
316 {
317 return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE};
318 }
319
320 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
321 {
322 auto mimeData = new QMimeData;
323
324 bool isFirst = true;
325
326 QVector<std::shared_ptr<DBEvent> > eventList;
327 QVector<std::shared_ptr<DBEventProduct> > eventProductList;
328
329 SqpRange firstTimeRange;
330 for (const auto &index : indexes) {
331 if (index.column() == 0) { // only the first column
332
333 auto type = itemTypeOf(index);
334 if (type == ItemType::Event) {
335 auto event = getEvent(index);
336 eventList << event;
337
338 if (isFirst) {
339 isFirst = false;
340 firstTimeRange.m_TStart = event->getTStart();
341 firstTimeRange.m_TEnd = event->getTEnd();
342 }
343 }
344 else if (type == ItemType::EventProduct) {
345 auto product = getEventProduct(index);
346 eventProductList << product;
347
348 if (isFirst) {
349 isFirst = false;
350 firstTimeRange.m_TStart = product->getTStart();
351 firstTimeRange.m_TEnd = product->getTEnd();
352 }
353 }
354 }
355 }
356
357 auto eventsEncodedData
358 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
359 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
360
361 if (eventList.count() + eventProductList.count() == 1) {
362 // No time range MIME data if multiple events are dragged
363 auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange);
364 mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData);
365 }
366
367 return mimeData;
368 }
369
370 CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const
371 {
372 if (!index.isValid()) {
373 return ItemType::Root;
374 }
375 else if (index.internalPointer() == nullptr) {
376 return ItemType::Event;
377 }
378 else {
379 return ItemType::EventProduct;
380 }
381 }
@@ -1,22 +1,31
1 #ifndef SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
1 #ifndef SCIQLOP_CATALOGUEEVENTSMODEL_H
2 #define SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
2 #define SCIQLOP_CATALOGUEEVENTSMODEL_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QAbstractTableModel>
5 #include <QAbstractItemModel>
6
6
7 class DBEvent;
7 class DBEvent;
8 class DBEventProduct;
8
9
9 class CatalogueEventsTableModel : public QAbstractTableModel {
10 class CatalogueEventsModel : public QAbstractItemModel {
10 public:
11 public:
11 CatalogueEventsTableModel(QObject *parent = nullptr);
12 CatalogueEventsModel(QObject *parent = nullptr);
12
13
13 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events);
14 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events);
14 std::shared_ptr<DBEvent> getEvent(int row) const;
15 void addEvent(const std::shared_ptr<DBEvent> &event);
16 void removeEvent(const std::shared_ptr<DBEvent> &event);
15
17
16 void addEvent(const std::shared_ptr<DBEvent> &events);
18 enum class ItemType { Root, Event, EventProduct };
17 void removeEvent(const std::shared_ptr<DBEvent> &events);
19 ItemType itemTypeOf(const QModelIndex &index) const;
20 std::shared_ptr<DBEvent> getEvent(const QModelIndex &index) const;
21 std::shared_ptr<DBEvent> getParentEvent(const QModelIndex &index) const;
22 std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const;
23
24 void refreshEvent(const std::shared_ptr<DBEvent> &event);
18
25
19 // Model
26 // Model
27 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
28 QModelIndex parent(const QModelIndex &index) const;
20 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
29 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
21 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
30 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
22 Qt::ItemFlags flags(const QModelIndex &index) const override;
31 Qt::ItemFlags flags(const QModelIndex &index) const override;
@@ -29,10 +38,9 public:
29 QStringList mimeTypes() const override;
38 QStringList mimeTypes() const override;
30 QMimeData *mimeData(const QModelIndexList &indexes) const override;
39 QMimeData *mimeData(const QModelIndexList &indexes) const override;
31
40
32
33 private:
41 private:
34 class CatalogueEventsTableModelPrivate;
42 class CatalogueEventsModelPrivate;
35 spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl;
43 spimpl::unique_impl_ptr<CatalogueEventsModelPrivate> impl;
36 };
44 };
37
45
38 #endif // SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
46 #endif // SCIQLOP_CATALOGUEEVENTSMODEL_H
@@ -7,6 +7,7
7
7
8 class DBCatalogue;
8 class DBCatalogue;
9 class DBEvent;
9 class DBEvent;
10 class DBEventProduct;
10 class VisualizationWidget;
11 class VisualizationWidget;
11
12
12 namespace Ui {
13 namespace Ui {
@@ -20,6 +21,10 class CatalogueEventsWidget : public QWidget {
20
21
21 signals:
22 signals:
22 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
23 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
24 void eventProductsSelected(
25 const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > >
26 &eventproducts);
27 void selectionCleared();
23
28
24 public:
29 public:
25 explicit CatalogueEventsWidget(QWidget *parent = 0);
30 explicit CatalogueEventsWidget(QWidget *parent = 0);
@@ -27,6 +32,8 public:
27
32
28 void setVisualizationWidget(VisualizationWidget *visualization);
33 void setVisualizationWidget(VisualizationWidget *visualization);
29
34
35 void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges);
36
30 public slots:
37 public slots:
31 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
38 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
32
39
@@ -1,6 +1,7
1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <QWidget>
5 #include <QWidget>
5 #include <memory>
6 #include <memory>
6
7
@@ -10,10 +11,17 class CatalogueInspectorWidget;
10
11
11 class DBCatalogue;
12 class DBCatalogue;
12 class DBEvent;
13 class DBEvent;
14 class DBEventProduct;
13
15
14 class CatalogueInspectorWidget : public QWidget {
16 class CatalogueInspectorWidget : public QWidget {
15 Q_OBJECT
17 Q_OBJECT
16
18
19 signals:
20 void catalogueUpdated(const std::shared_ptr<DBCatalogue> &catalogue);
21 void eventUpdated(const std::shared_ptr<DBEvent> &event);
22 void eventProductUpdated(const std::shared_ptr<DBEvent> &event,
23 const std::shared_ptr<DBEventProduct> &eventProduct);
24
17 public:
25 public:
18 explicit CatalogueInspectorWidget(QWidget *parent = 0);
26 explicit CatalogueInspectorWidget(QWidget *parent = 0);
19 virtual ~CatalogueInspectorWidget();
27 virtual ~CatalogueInspectorWidget();
@@ -24,6 +32,8 public:
24 Page currentPage() const;
32 Page currentPage() const;
25
33
26 void setEvent(const std::shared_ptr<DBEvent> &event);
34 void setEvent(const std::shared_ptr<DBEvent> &event);
35 void setEventProduct(const std::shared_ptr<DBEvent> &event,
36 const std::shared_ptr<DBEventProduct> &eventProduct);
27 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
37 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
28
38
29 public slots:
39 public slots:
@@ -31,6 +41,9 public slots:
31
41
32 private:
42 private:
33 Ui::CatalogueInspectorWidget *ui;
43 Ui::CatalogueInspectorWidget *ui;
44
45 class CatalogueInspectorWidgetPrivate;
46 spimpl::unique_impl_ptr<CatalogueInspectorWidgetPrivate> impl;
34 };
47 };
35
48
36 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
49 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
@@ -2,6 +2,7
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QLoggingCategory>
5 #include <QTreeWidgetItem>
6 #include <QTreeWidgetItem>
6 #include <QWidget>
7 #include <QWidget>
7
8
@@ -11,6 +12,8 namespace Ui {
11 class CatalogueSideBarWidget;
12 class CatalogueSideBarWidget;
12 }
13 }
13
14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget)
16
14 class CatalogueSideBarWidget : public QWidget {
17 class CatalogueSideBarWidget : public QWidget {
15 Q_OBJECT
18 Q_OBJECT
16
19
@@ -25,6 +28,8 public:
25 explicit CatalogueSideBarWidget(QWidget *parent = 0);
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
26 virtual ~CatalogueSideBarWidget();
29 virtual ~CatalogueSideBarWidget();
27
30
31 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32
28 private:
33 private:
29 Ui::CatalogueSideBarWidget *ui;
34 Ui::CatalogueSideBarWidget *ui;
30
35
@@ -18,8 +18,13 public:
18 /// Returns the catalogue represented by the item
18 /// Returns the catalogue represented by the item
19 std::shared_ptr<DBCatalogue> catalogue() const;
19 std::shared_ptr<DBCatalogue> catalogue() const;
20
20
21 /// Displays or hides the save and cancel buttons indicating that the catalogue has unsaved
22 /// changes
21 void setHasChanges(bool value);
23 void setHasChanges(bool value);
22
24
25 /// Refreshes the data displayed by the item from the catalogue
26 void refresh();
27
23 private:
28 private:
24 class CatalogueTreeWidgetItemPrivate;
29 class CatalogueTreeWidgetItemPrivate;
25 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
30 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
@@ -15,7 +15,7 class VisualizationMultiZoneSelectionDialog : public QDialog {
15
15
16 public:
16 public:
17 explicit VisualizationMultiZoneSelectionDialog(QWidget *parent = 0);
17 explicit VisualizationMultiZoneSelectionDialog(QWidget *parent = 0);
18 ~VisualizationMultiZoneSelectionDialog();
18 virtual ~VisualizationMultiZoneSelectionDialog();
19
19
20 void setZones(const QVector<VisualizationSelectionZoneItem *> &zones);
20 void setZones(const QVector<VisualizationSelectionZoneItem *> &zones);
21 QMap<VisualizationSelectionZoneItem *, bool> selectedZones() const;
21 QMap<VisualizationSelectionZoneItem *, bool> selectedZones() const;
@@ -108,7 +108,7 gui_sources = [
108 'src/Catalogue/CatalogueSideBarWidget.cpp',
108 'src/Catalogue/CatalogueSideBarWidget.cpp',
109 'src/Catalogue/CatalogueInspectorWidget.cpp',
109 'src/Catalogue/CatalogueInspectorWidget.cpp',
110 'src/Catalogue/CatalogueTreeWidgetItem.cpp',
110 'src/Catalogue/CatalogueTreeWidgetItem.cpp',
111 'src/Catalogue/CatalogueEventsTableModel.cpp'
111 'src/Catalogue/CatalogueEventsModel.cpp'
112 ]
112 ]
113
113
114 gui_inc = include_directories(['include'])
114 gui_inc = include_directories(['include'])
@@ -2,7 +2,7
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/CatalogueEventsTableModel.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>
@@ -21,31 +21,31 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
21
21
22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
23
23
24 CatalogueEventsTableModel *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, QTableView *tableView)
30 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
31 {
31 {
32 tableView->setSortingEnabled(false);
32 treeView->setSortingEnabled(false);
33 m_Model->setEvents(events);
33 m_Model->setEvents(events);
34 tableView->setSortingEnabled(true);
34 treeView->setSortingEnabled(true);
35 }
35 }
36
36
37 void addEvent(const std::shared_ptr<DBEvent> &event, QTableView *tableView)
37 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
38 {
38 {
39 tableView->setSortingEnabled(false);
39 treeView->setSortingEnabled(false);
40 m_Model->addEvent(event);
40 m_Model->addEvent(event);
41 tableView->setSortingEnabled(true);
41 treeView->setSortingEnabled(true);
42 }
42 }
43
43
44 void removeEvent(const std::shared_ptr<DBEvent> &event, QTableView *tableView)
44 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
45 {
45 {
46 tableView->setSortingEnabled(false);
46 treeView->setSortingEnabled(false);
47 m_Model->removeEvent(event);
47 m_Model->removeEvent(event);
48 tableView->setSortingEnabled(true);
48 treeView->setSortingEnabled(true);
49 }
49 }
50
50
51 QStringList getAvailableVisualizationZoneList() const
51 QStringList getAvailableVisualizationZoneList() const
@@ -131,33 +131,35 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
131 return result;
131 return result;
132 }
132 }
133
133
134 void updateForTimeMode(QTableView *tableView)
134 void updateForTimeMode(QTreeView *treeView)
135 {
135 {
136 auto selectedRows = tableView->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().row());
139 auto event = m_Model->getEvent(selectedRows.first());
140 if (m_VisualizationWidget) {
140 if (event) {
141 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
141 if (m_VisualizationWidget) {
142
142 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
143 for (auto zoneName : m_ZonesForTimeMode) {
143
144 if (auto zone = tab->getZoneWithName(zoneName)) {
144 for (auto zoneName : m_ZonesForTimeMode) {
145 SqpRange eventRange;
145 if (auto zone = tab->getZoneWithName(zoneName)) {
146 eventRange.m_TStart = event->getTStart();
146 SqpRange eventRange;
147 eventRange.m_TEnd = event->getTEnd();
147 eventRange.m_TStart = event->getTStart();
148 zone->setZoneRange(eventRange);
148 eventRange.m_TEnd = event->getTEnd();
149 zone->setZoneRange(eventRange);
150 }
149 }
151 }
150 }
152 }
153 else {
154 qCWarning(LOG_CatalogueEventsWidget())
155 << "updateTimeZone: no tab found in the visualization";
156 }
151 }
157 }
152 else {
158 else {
153 qCWarning(LOG_CatalogueEventsWidget())
159 qCWarning(LOG_CatalogueEventsWidget())
154 << "updateTimeZone: no tab found in the visualization";
160 << "updateTimeZone: visualization widget not found";
155 }
161 }
156 }
162 }
157 else {
158 qCWarning(LOG_CatalogueEventsWidget())
159 << "updateTimeZone: visualization widget not found";
160 }
161 }
163 }
162 else {
164 else {
163 qCWarning(LOG_CatalogueEventsWidget())
165 qCWarning(LOG_CatalogueEventsWidget())
@@ -165,12 +167,12 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
165 }
167 }
166 }
168 }
167
169
168 void updateForGraphMode(QTableView *tableView)
170 void updateForGraphMode(QTreeView *treeView)
169 {
171 {
170 auto selectedRows = tableView->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().row());
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)) {
@@ -201,12 +203,12 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
201 {
203 {
202 ui->setupUi(this);
204 ui->setupUi(this);
203
205
204 impl->m_Model = new CatalogueEventsTableModel{this};
206 impl->m_Model = new CatalogueEventsModel{this};
205 ui->tableView->setModel(impl->m_Model);
207 ui->treeView->setModel(impl->m_Model);
206
208
207 ui->tableView->setSortingEnabled(true);
209 ui->treeView->setSortingEnabled(true);
208 ui->tableView->setDragDropMode(QAbstractItemView::DragDrop);
210 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
209 ui->tableView->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) {
@@ -215,7 +217,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
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->tableView);
220 impl->updateForTimeMode(ui->treeView);
219 }
221 }
220 });
222 });
221
223
@@ -227,38 +229,56 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
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->tableView);
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 for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) {
238 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
237 events << impl->m_Model->getEvent(rowIndex.row());
239
240 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
241
242 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
243 if (itemType == CatalogueEventsModel::ItemType::Event) {
244 events << impl->m_Model->getEvent(rowIndex);
245 }
246 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
247 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
248 impl->m_Model->getEventProduct(rowIndex));
249 }
238 }
250 }
239
251
240 emit this->eventsSelected(events);
252 if (!events.isEmpty() && eventProducts.isEmpty()) {
253 emit this->eventsSelected(events);
254 }
255 else if (events.isEmpty() && !eventProducts.isEmpty()) {
256 emit this->eventProductsSelected(eventProducts);
257 }
258 else {
259 emit this->selectionCleared();
260 }
241 };
261 };
242
262
243 connect(ui->tableView, &QTableView::clicked, emitSelection);
263 connect(ui->treeView, &QTreeView::clicked, emitSelection);
244 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
264 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
245
265
246 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
266 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
247 auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1;
267 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
248 ui->btnChart->setEnabled(isNotMultiSelection);
268 ui->btnChart->setEnabled(isNotMultiSelection);
249 ui->btnTime->setEnabled(isNotMultiSelection);
269 ui->btnTime->setEnabled(isNotMultiSelection);
250
270
251 if (isNotMultiSelection && ui->btnTime->isChecked()) {
271 if (isNotMultiSelection && ui->btnTime->isChecked()) {
252 impl->updateForTimeMode(ui->tableView);
272 impl->updateForTimeMode(ui->treeView);
253 }
273 }
254 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
274 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
255 impl->updateForGraphMode(ui->tableView);
275 impl->updateForGraphMode(ui->treeView);
256 }
276 }
257 });
277 });
258
278
259 ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
279 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
260 ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
280 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
261 ui->tableView->horizontalHeader()->setSortIndicatorShown(true);
281 ui->treeView->header()->setSortIndicatorShown(true);
262 }
282 }
263
283
264 CatalogueEventsWidget::~CatalogueEventsWidget()
284 CatalogueEventsWidget::~CatalogueEventsWidget()
@@ -271,6 +291,11 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualiz
271 impl->m_VisualizationWidget = visualization;
291 impl->m_VisualizationWidget = visualization;
272 }
292 }
273
293
294 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
295 {
296 impl->m_Model->refreshEvent(event);
297 }
298
274 void CatalogueEventsWidget::populateWithCatalogues(
299 void CatalogueEventsWidget::populateWithCatalogues(
275 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
300 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
276 {
301 {
@@ -287,5 +312,5 void CatalogueEventsWidget::populateWithCatalogues(
287 }
312 }
288 }
313 }
289
314
290 impl->setEvents(events, ui->tableView);
315 impl->setEvents(events, ui->treeView);
291 }
316 }
@@ -48,6 +48,28 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
48 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
48 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
49 }
49 }
50 });
50 });
51
52 connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) {
53 if (eventProducts.count() == 1) {
54 ui->inspector->setEventProduct(eventProducts.first().first,
55 eventProducts.first().second);
56 }
57 else {
58 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
59 }
60 });
61
62 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
63 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
64
65 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated,
66 [this](auto catalogue) { ui->catalogues->setCatalogueChanges(catalogue, true); });
67
68 connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated,
69 [this](auto event) { ui->events->setEventChanges(event, true); });
70
71 connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated,
72 [this](auto event, auto eventProduct) { ui->events->setEventChanges(event, true); });
51 }
73 }
52
74
53 CatalogueExplorer::~CatalogueExplorer()
75 CatalogueExplorer::~CatalogueExplorer()
@@ -4,13 +4,30
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 <DBTag.h>
8 #include <DBTag.h>
8
9
10 struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate {
11 std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr;
12 std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr;
13 std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr;
14
15 void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector,
16 Ui::CatalogueInspectorWidget *ui);
17 void connectEventUpdateSignals(CatalogueInspectorWidget *inspector,
18 Ui::CatalogueInspectorWidget *ui);
19 };
20
9 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
21 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
10 : QWidget(parent), ui(new Ui::CatalogueInspectorWidget)
22 : QWidget(parent),
23 ui(new Ui::CatalogueInspectorWidget),
24 impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()}
11 {
25 {
12 ui->setupUi(this);
26 ui->setupUi(this);
13 showPage(Page::Empty);
27 showPage(Page::Empty);
28
29 impl->connectCatalogueUpdateSignals(this, ui);
30 impl->connectEventUpdateSignals(this, ui);
14 }
31 }
15
32
16 CatalogueInspectorWidget::~CatalogueInspectorWidget()
33 CatalogueInspectorWidget::~CatalogueInspectorWidget()
@@ -18,6 +35,71 CatalogueInspectorWidget::~CatalogueInspectorWidget()
18 delete ui;
35 delete ui;
19 }
36 }
20
37
38 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals(
39 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
40 {
41 connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() {
42 if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) {
43 m_DisplayedCatalogue->setName(ui->leCatalogueName->text());
44 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
45 }
46 });
47
48 connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() {
49 if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) {
50 m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text());
51 emit inspector->catalogueUpdated(m_DisplayedCatalogue);
52 }
53 });
54 }
55
56 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals(
57 CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui)
58 {
59 connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() {
60 if (ui->leEventName->text() != m_DisplayedEvent->getName()) {
61 m_DisplayedEvent->setName(ui->leEventName->text());
62 emit inspector->eventUpdated(m_DisplayedEvent);
63 }
64 });
65
66 connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() {
67 auto tags = ui->leEventTags->text().split(QRegExp("\\s+"));
68 std::list<QString> tagNames;
69 for (auto tag : tags) {
70 tagNames.push_back(tag);
71 }
72
73 if (m_DisplayedEvent->getTagsNames() != tagNames) {
74 m_DisplayedEvent->setTagsNames(tagNames);
75 emit inspector->eventUpdated(m_DisplayedEvent);
76 }
77 });
78
79 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
81 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
82 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
83 }
84 });
85
86 connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
87 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
88 if (time != m_DisplayedEventProduct->getTStart()) {
89 m_DisplayedEventProduct->setTStart(time);
90 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
91 }
92 });
93
94 connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() {
95 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
96 if (time != m_DisplayedEventProduct->getTEnd()) {
97 m_DisplayedEventProduct->setTEnd(time);
98 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
99 }
100 });
101 }
102
21 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
103 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
22 {
104 {
23 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
105 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
@@ -30,27 +112,70 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
30
112
31 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
113 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
32 {
114 {
115 impl->m_DisplayedEvent = event;
116
117 blockSignals(true);
118
33 showPage(Page::EventProperties);
119 showPage(Page::EventProperties);
120 ui->leEventName->setEnabled(true);
34 ui->leEventName->setText(event->getName());
121 ui->leEventName->setText(event->getName());
35 ui->leEventMission->setText(event->getMission());
122 ui->leEventProduct->setEnabled(false);
36 ui->leEventProduct->setText(event->getProduct());
123 ui->leEventProduct->setText(
124 QString::number(event->getEventProducts().size()).append(" product(s)"));
37
125
38 QString tagList;
126 QString tagList;
39 auto tags = event->getTags();
127 auto tags = event->getTagsNames();
40 for (auto tag : tags) {
128 for (auto tag : tags) {
41 tagList += tag.getName();
129 tagList += tag;
42 tagList += ' ';
130 tagList += ' ';
43 }
131 }
44
132
133 ui->leEventTags->setEnabled(true);
45 ui->leEventTags->setText(tagList);
134 ui->leEventTags->setText(tagList);
46
135
136 ui->dateTimeEventTStart->setEnabled(false);
137 ui->dateTimeEventTEnd->setEnabled(false);
138
47 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
139 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
48 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
140 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
141
142 blockSignals(false);
143 }
144
145 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
146 const std::shared_ptr<DBEventProduct> &eventProduct)
147 {
148 impl->m_DisplayedEventProduct = eventProduct;
149
150 blockSignals(true);
151
152 showPage(Page::EventProperties);
153 ui->leEventName->setEnabled(false);
154 ui->leEventName->setText(event->getName());
155 ui->leEventProduct->setEnabled(true);
156 ui->leEventProduct->setText(eventProduct->getProductId());
157
158 ui->leEventTags->setEnabled(false);
159 ui->leEventTags->clear();
160
161 ui->dateTimeEventTStart->setEnabled(true);
162 ui->dateTimeEventTEnd->setEnabled(true);
163
164 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart()));
165 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd()));
166
167 blockSignals(false);
49 }
168 }
50
169
51 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
170 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
52 {
171 {
172 impl->m_DisplayedCatalogue = catalogue;
173
174 blockSignals(true);
175
53 showPage(Page::CatalogueProperties);
176 showPage(Page::CatalogueProperties);
54 ui->leCatalogueName->setText(catalogue->getName());
177 ui->leCatalogueName->setText(catalogue->getName());
55 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
178 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
179
180 blockSignals(false);
56 }
181 }
@@ -10,6 +10,8
10
10
11 #include <QMenu>
11 #include <QMenu>
12
12
13 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
14
13
15
14 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
16 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
15 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
17 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
@@ -24,6 +26,9 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
24 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
26 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
25 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
27 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
26 QTreeWidgetItem *parentDatabaseItem);
28 QTreeWidgetItem *parentDatabaseItem);
29
30 CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
31 QTreeWidget *treeWidget) const;
27 };
32 };
28
33
29 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
34 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
@@ -97,6 +102,14 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
97
102
98 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
103 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
99 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
104 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
105 connect(ui->treeWidget, &QTreeWidget::itemChanged,
106 [emitSelection, this](auto item, auto column) {
107 auto selectedItems = ui->treeWidget->selectedItems();
108 qDebug() << "ITEM CHANGED" << column;
109 if (selectedItems.contains(item) && column == 0) {
110 emitSelection();
111 }
112 });
100
113
101 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
114 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
102 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
115 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
@@ -108,6 +121,15 CatalogueSideBarWidget::~CatalogueSideBarWidget()
108 delete ui;
121 delete ui;
109 }
122 }
110
123
124 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
125 bool hasChanges)
126 {
127 if (auto catalogueItem = impl->getCatalogueItem(catalogue, ui->treeWidget)) {
128 catalogueItem->setHasChanges(hasChanges);
129 catalogueItem->refresh();
130 }
131 }
132
111 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
133 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
112 {
134 {
113 QMenu menu{this};
135 QMenu menu{this};
@@ -196,3 +218,30 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
196 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
218 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
197 parentDatabaseItem->addChild(catalogueItem);
219 parentDatabaseItem->addChild(catalogueItem);
198 }
220 }
221
222 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
223 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidget *treeWidget) const
224 {
225 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
226 auto item = treeWidget->topLevelItem(i);
227 if (item->type() == DATABASE_ITEM_TYPE) {
228 for (auto j = 0; j < item->childCount(); ++j) {
229 auto childItem = item->child(j);
230 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
231 auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem);
232 if (catalogueItem->catalogue() == catalogue) {
233 return catalogueItem;
234 }
235 }
236 else {
237 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree "
238 "structure. A database item should "
239 "only contain catalogues.";
240 Q_ASSERT(false);
241 }
242 }
243 }
244 }
245
246 return nullptr;
247 }
@@ -8,6 +8,9
8
8
9 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
9 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
10
10
11 /// Column in the tree widget where the apply and cancel buttons must appear
12 const auto APPLY_CANCEL_BUTTONS_COLUMN = 1;
13
11 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
14 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
12
15
13 std::shared_ptr<DBCatalogue> m_Catalogue;
16 std::shared_ptr<DBCatalogue> m_Catalogue;
@@ -63,31 +66,38 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
63 void CatalogueTreeWidgetItem::setHasChanges(bool value)
66 void CatalogueTreeWidgetItem::setHasChanges(bool value)
64 {
67 {
65 if (value) {
68 if (value) {
66 auto widet = new QWidget{treeWidget()};
69 if (treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) == nullptr) {
67
70 auto widet = new QWidget{treeWidget()};
68 auto layout = new QHBoxLayout{widet};
71
69 layout->setContentsMargins(0, 0, 0, 0);
72 auto layout = new QHBoxLayout{widet};
70 layout->setSpacing(0);
73 layout->setContentsMargins(0, 0, 0, 0);
71
74 layout->setSpacing(0);
72 auto btnValid = new QToolButton{widet};
75
73 btnValid->setIcon(QIcon{":/icones/save"});
76 auto btnValid = new QToolButton{widet};
74 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
77 btnValid->setIcon(QIcon{":/icones/save"});
75 btnValid->setAutoRaise(true);
78 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
76 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
79 btnValid->setAutoRaise(true);
77 layout->addWidget(btnValid);
80 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
78
81 layout->addWidget(btnValid);
79 auto btnDiscard = new QToolButton{widet};
82
80 btnDiscard->setIcon(QIcon{":/icones/discard"});
83 auto btnDiscard = new QToolButton{widet};
81 btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
84 btnDiscard->setIcon(QIcon{":/icones/discard"});
82 btnDiscard->setAutoRaise(true);
85 btnDiscard->setIconSize(
83 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
86 QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
84 layout->addWidget(btnDiscard);
87 btnDiscard->setAutoRaise(true);
85
88 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
86 treeWidget()->setItemWidget(this, 1, {widet});
89 layout->addWidget(btnDiscard);
87 treeWidget()->resizeColumnToContents(1);
90
91 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, {widet});
92 }
88 }
93 }
89 else {
94 else {
90 // Note: the widget is destroyed
95 // Note: the widget is destroyed
91 treeWidget()->setItemWidget(this, 1, nullptr);
96 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
92 }
97 }
93 }
98 }
99
100 void CatalogueTreeWidgetItem::refresh()
101 {
102 emitDataChanged();
103 }
@@ -114,32 +114,20
114 </layout>
114 </layout>
115 </item>
115 </item>
116 <item>
116 <item>
117 <widget class="QTableView" name="tableView">
117 <widget class="QTreeView" name="treeView">
118 <property name="dragEnabled">
118 <property name="dragEnabled">
119 <bool>true</bool>
119 <bool>true</bool>
120 </property>
120 </property>
121 <property name="dragDropMode">
121 <property name="dragDropMode">
122 <enum>QAbstractItemView::DragDrop</enum>
122 <enum>QAbstractItemView::DragDrop</enum>
123 </property>
123 </property>
124 <property name="selectionMode">
125 <enum>QAbstractItemView::ExtendedSelection</enum>
126 </property>
124 <property name="selectionBehavior">
127 <property name="selectionBehavior">
125 <enum>QAbstractItemView::SelectRows</enum>
128 <enum>QAbstractItemView::SelectRows</enum>
126 </property>
129 </property>
127 <attribute name="horizontalHeaderVisible">
130 <attribute name="headerStretchLastSection">
128 <bool>true</bool>
129 </attribute>
130 <attribute name="horizontalHeaderHighlightSections">
131 <bool>false</bool>
132 </attribute>
133 <attribute name="horizontalHeaderShowSortIndicator" stdset="0">
134 <bool>true</bool>
135 </attribute>
136 <attribute name="verticalHeaderVisible">
137 <bool>false</bool>
138 </attribute>
139 <attribute name="verticalHeaderDefaultSectionSize">
140 <number>25</number>
141 </attribute>
142 <attribute name="verticalHeaderHighlightSections">
143 <bool>false</bool>
131 <bool>false</bool>
144 </attribute>
132 </attribute>
145 </widget>
133 </widget>
@@ -53,7 +53,7
53 <item>
53 <item>
54 <widget class="QStackedWidget" name="stackedWidget">
54 <widget class="QStackedWidget" name="stackedWidget">
55 <property name="currentIndex">
55 <property name="currentIndex">
56 <number>1</number>
56 <number>2</number>
57 </property>
57 </property>
58 <widget class="QWidget" name="emptyPage"/>
58 <widget class="QWidget" name="emptyPage"/>
59 <widget class="QWidget" name="catalogueInspectorPage">
59 <widget class="QWidget" name="catalogueInspectorPage">
@@ -113,53 +113,20
113 </widget>
113 </widget>
114 <widget class="QWidget" name="eventInspectorPage">
114 <widget class="QWidget" name="eventInspectorPage">
115 <layout class="QGridLayout" name="gridLayout">
115 <layout class="QGridLayout" name="gridLayout">
116 <item row="5" column="1">
117 <widget class="QDateTimeEdit" name="dateTimeEventTEnd"/>
118 </item>
119 <item row="4" column="0">
116 <item row="4" column="0">
120 <widget class="QLabel" name="label_4">
121 <property name="text">
122 <string>TStart</string>
123 </property>
124 </widget>
125 </item>
126 <item row="6" column="0">
127 <widget class="QLabel" name="label_6">
128 <property name="text">
129 <string>Tags</string>
130 </property>
131 </widget>
132 </item>
133 <item row="3" column="0">
134 <widget class="QLabel" name="label_3">
117 <widget class="QLabel" name="label_3">
135 <property name="text">
118 <property name="text">
136 <string>Product</string>
119 <string>Product</string>
137 </property>
120 </property>
138 </widget>
121 </widget>
139 </item>
122 </item>
140 <item row="3" column="1">
141 <widget class="QLineEdit" name="leEventProduct"/>
142 </item>
143 <item row="5" column="0">
123 <item row="5" column="0">
144 <widget class="QLabel" name="label_5">
124 <widget class="QLabel" name="label_4">
145 <property name="text">
146 <string>Tend</string>
147 </property>
148 </widget>
149 </item>
150 <item row="4" column="1">
151 <widget class="QDateTimeEdit" name="dateTimeEventTStart"/>
152 </item>
153 <item row="2" column="0">
154 <widget class="QLabel" name="label_2">
155 <property name="text">
125 <property name="text">
156 <string>Mission</string>
126 <string>TStart</string>
157 </property>
127 </property>
158 </widget>
128 </widget>
159 </item>
129 </item>
160 <item row="1" column="1">
161 <widget class="QLineEdit" name="leEventName"/>
162 </item>
163 <item row="1" column="0">
130 <item row="1" column="0">
164 <widget class="QLabel" name="label">
131 <widget class="QLabel" name="label">
165 <property name="text">
132 <property name="text">
@@ -167,13 +134,21
167 </property>
134 </property>
168 </widget>
135 </widget>
169 </item>
136 </item>
170 <item row="2" column="1">
137 <item row="0" column="0" colspan="2">
171 <widget class="QLineEdit" name="leEventMission"/>
138 <widget class="QLabel" name="label_10">
172 </item>
139 <property name="font">
173 <item row="6" column="1">
140 <font>
174 <widget class="QLineEdit" name="leEventTags"/>
141 <pointsize>10</pointsize>
142 <weight>75</weight>
143 <bold>true</bold>
144 </font>
145 </property>
146 <property name="text">
147 <string>Event Properties</string>
148 </property>
149 </widget>
175 </item>
150 </item>
176 <item row="7" column="1">
151 <item row="8" column="1">
177 <spacer name="verticalSpacer">
152 <spacer name="verticalSpacer">
178 <property name="orientation">
153 <property name="orientation">
179 <enum>Qt::Vertical</enum>
154 <enum>Qt::Vertical</enum>
@@ -186,17 +161,47
186 </property>
161 </property>
187 </spacer>
162 </spacer>
188 </item>
163 </item>
189 <item row="0" column="0" colspan="2">
164 <item row="1" column="1">
190 <widget class="QLabel" name="label_10">
165 <widget class="QLineEdit" name="leEventName"/>
191 <property name="font">
166 </item>
192 <font>
167 <item row="5" column="1">
193 <pointsize>10</pointsize>
168 <widget class="QDateTimeEdit" name="dateTimeEventTStart">
194 <weight>75</weight>
169 <property name="timeSpec">
195 <bold>true</bold>
170 <enum>Qt::UTC</enum>
196 </font>
171 </property>
172 </widget>
173 </item>
174 <item row="4" column="1">
175 <widget class="QLineEdit" name="leEventProduct"/>
176 </item>
177 <item row="6" column="0">
178 <widget class="QLabel" name="label_5">
179 <property name="text">
180 <string>Tend</string>
197 </property>
181 </property>
182 </widget>
183 </item>
184 <item row="6" column="1">
185 <widget class="QDateTimeEdit" name="dateTimeEventTEnd">
186 <property name="timeSpec">
187 <enum>Qt::UTC</enum>
188 </property>
189 </widget>
190 </item>
191 <item row="2" column="1">
192 <widget class="QLineEdit" name="leEventTags"/>
193 </item>
194 <item row="2" column="0">
195 <widget class="QLabel" name="label_6">
198 <property name="text">
196 <property name="text">
199 <string>Event Properties</string>
197 <string>Tags</string>
198 </property>
199 </widget>
200 </item>
201 <item row="3" column="0" colspan="2">
202 <widget class="Line" name="line">
203 <property name="orientation">
204 <enum>Qt::Horizontal</enum>
200 </property>
205 </property>
201 </widget>
206 </widget>
202 </item>
207 </item>
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now