Auto status change to "Under Review"
@@ -1,381 +1,387 | |||||
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 DateUtils::dateTime(event->getTStart()) |
|
37 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTStart()) | |
|
38 | : QVariant{}; | |||
38 | case Column::TEnd: |
|
39 | case Column::TEnd: | |
39 |
return DateUtils::dateTime(event->getTEnd()) |
|
40 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTEnd()) | |
40 | case Column::Product: { |
|
41 | : QVariant{}; | |
41 | auto eventProductsIt = m_EventProducts.find(event.get()); |
|
42 | case Column::Product: | |
42 | if (eventProductsIt != m_EventProducts.cend()) { |
|
43 | return QString::number(nbEventProducts(event)) + " product(s)"; | |
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: { |
|
44 | case Column::Tags: { | |
50 | QString tagList; |
|
45 | QString tagList; | |
51 | auto tags = event->getTags(); |
|
46 | auto tags = event->getTags(); | |
52 | for (auto tag : tags) { |
|
47 | for (auto tag : tags) { | |
53 | tagList += tag.getName(); |
|
48 | tagList += tag.getName(); | |
54 | tagList += ' '; |
|
49 | tagList += ' '; | |
55 | } |
|
50 | } | |
56 |
|
51 | |||
57 | return tagList; |
|
52 | return tagList; | |
58 | } |
|
53 | } | |
59 | default: |
|
54 | default: | |
60 | break; |
|
55 | break; | |
61 | } |
|
56 | } | |
62 |
|
57 | |||
63 | Q_ASSERT(false); |
|
58 | Q_ASSERT(false); | |
64 | return QStringLiteral("Unknown Data"); |
|
59 | return QStringLiteral("Unknown Data"); | |
65 | } |
|
60 | } | |
66 |
|
61 | |||
67 | void parseEventProduct(const std::shared_ptr<DBEvent> &event) |
|
62 | void parseEventProduct(const std::shared_ptr<DBEvent> &event) | |
68 | { |
|
63 | { | |
69 | for (auto product : event->getEventProducts()) { |
|
64 | for (auto product : event->getEventProducts()) { | |
70 | m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product)); |
|
65 | m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product)); | |
71 | } |
|
66 | } | |
72 | } |
|
67 | } | |
73 |
|
68 | |||
|
69 | int nbEventProducts(const std::shared_ptr<DBEvent> &event) const | |||
|
70 | { | |||
|
71 | auto eventProductsIt = m_EventProducts.find(event.get()); | |||
|
72 | if (eventProductsIt != m_EventProducts.cend()) { | |||
|
73 | return m_EventProducts.at(event.get()).count(); | |||
|
74 | } | |||
|
75 | else { | |||
|
76 | return 0; | |||
|
77 | } | |||
|
78 | } | |||
|
79 | ||||
74 | QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const |
|
80 | QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const | |
75 | { |
|
81 | { | |
76 | switch (static_cast<Column>(col)) { |
|
82 | switch (static_cast<Column>(col)) { | |
77 | case Column::Name: |
|
83 | case Column::Name: | |
78 | return eventProduct->getProductId(); |
|
84 | return eventProduct->getProductId(); | |
79 | case Column::TStart: |
|
85 | case Column::TStart: | |
80 | return DateUtils::dateTime(eventProduct->getTStart()); |
|
86 | return DateUtils::dateTime(eventProduct->getTStart()); | |
81 | case Column::TEnd: |
|
87 | case Column::TEnd: | |
82 | return DateUtils::dateTime(eventProduct->getTEnd()); |
|
88 | return DateUtils::dateTime(eventProduct->getTEnd()); | |
83 | case Column::Product: |
|
89 | case Column::Product: | |
84 | return eventProduct->getProductId(); |
|
90 | return eventProduct->getProductId(); | |
85 | case Column::Tags: { |
|
91 | case Column::Tags: { | |
86 | return QString(); |
|
92 | return QString(); | |
87 | } |
|
93 | } | |
88 | default: |
|
94 | default: | |
89 | break; |
|
95 | break; | |
90 | } |
|
96 | } | |
91 |
|
97 | |||
92 | Q_ASSERT(false); |
|
98 | Q_ASSERT(false); | |
93 | return QStringLiteral("Unknown Data"); |
|
99 | return QStringLiteral("Unknown Data"); | |
94 | } |
|
100 | } | |
95 | }; |
|
101 | }; | |
96 |
|
102 | |||
97 | CatalogueEventsModel::CatalogueEventsModel(QObject *parent) |
|
103 | CatalogueEventsModel::CatalogueEventsModel(QObject *parent) | |
98 | : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()} |
|
104 | : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()} | |
99 | { |
|
105 | { | |
100 | } |
|
106 | } | |
101 |
|
107 | |||
102 | void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events) |
|
108 | void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events) | |
103 | { |
|
109 | { | |
104 | beginResetModel(); |
|
110 | beginResetModel(); | |
105 |
|
111 | |||
106 | impl->m_Events = events; |
|
112 | impl->m_Events = events; | |
107 | impl->m_EventProducts.clear(); |
|
113 | impl->m_EventProducts.clear(); | |
108 | for (auto event : events) { |
|
114 | for (auto event : events) { | |
109 | impl->parseEventProduct(event); |
|
115 | impl->parseEventProduct(event); | |
110 | } |
|
116 | } | |
111 |
|
117 | |||
112 | endResetModel(); |
|
118 | endResetModel(); | |
113 | } |
|
119 | } | |
114 |
|
120 | |||
115 | std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const |
|
121 | std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const | |
116 | { |
|
122 | { | |
117 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) { |
|
123 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) { | |
118 | return impl->m_Events.value(index.row()); |
|
124 | return impl->m_Events.value(index.row()); | |
119 | } |
|
125 | } | |
120 | else { |
|
126 | else { | |
121 | return nullptr; |
|
127 | return nullptr; | |
122 | } |
|
128 | } | |
123 | } |
|
129 | } | |
124 |
|
130 | |||
125 | std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const |
|
131 | std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const | |
126 | { |
|
132 | { | |
127 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { |
|
133 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { | |
128 | return getEvent(index.parent()); |
|
134 | return getEvent(index.parent()); | |
129 | } |
|
135 | } | |
130 | else { |
|
136 | else { | |
131 | return nullptr; |
|
137 | return nullptr; | |
132 | } |
|
138 | } | |
133 | } |
|
139 | } | |
134 |
|
140 | |||
135 | std::shared_ptr<DBEventProduct> |
|
141 | std::shared_ptr<DBEventProduct> | |
136 | CatalogueEventsModel::getEventProduct(const QModelIndex &index) const |
|
142 | CatalogueEventsModel::getEventProduct(const QModelIndex &index) const | |
137 | { |
|
143 | { | |
138 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { |
|
144 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { | |
139 | auto event = static_cast<DBEvent *>(index.internalPointer()); |
|
145 | auto event = static_cast<DBEvent *>(index.internalPointer()); | |
140 | return impl->m_EventProducts.at(event).value(index.row()); |
|
146 | return impl->m_EventProducts.at(event).value(index.row()); | |
141 | } |
|
147 | } | |
142 | else { |
|
148 | else { | |
143 | return nullptr; |
|
149 | return nullptr; | |
144 | } |
|
150 | } | |
145 | } |
|
151 | } | |
146 |
|
152 | |||
147 | void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event) |
|
153 | void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event) | |
148 | { |
|
154 | { | |
149 | beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1); |
|
155 | beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1); | |
150 | impl->m_Events.append(event); |
|
156 | impl->m_Events.append(event); | |
151 | impl->parseEventProduct(event); |
|
157 | impl->parseEventProduct(event); | |
152 | endInsertRows(); |
|
158 | endInsertRows(); | |
153 | } |
|
159 | } | |
154 |
|
160 | |||
155 | void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event) |
|
161 | void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event) | |
156 | { |
|
162 | { | |
157 | auto index = impl->m_Events.indexOf(event); |
|
163 | auto index = impl->m_Events.indexOf(event); | |
158 | if (index >= 0) { |
|
164 | if (index >= 0) { | |
159 | beginRemoveRows(QModelIndex(), index, index); |
|
165 | beginRemoveRows(QModelIndex(), index, index); | |
160 | impl->m_Events.removeAt(index); |
|
166 | impl->m_Events.removeAt(index); | |
161 | impl->m_EventProducts.erase(event.get()); |
|
167 | impl->m_EventProducts.erase(event.get()); | |
162 | endRemoveRows(); |
|
168 | endRemoveRows(); | |
163 | } |
|
169 | } | |
164 | } |
|
170 | } | |
165 |
|
171 | |||
166 | void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event) |
|
172 | void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event) | |
167 | { |
|
173 | { | |
168 | auto i = impl->m_Events.indexOf(event); |
|
174 | auto i = impl->m_Events.indexOf(event); | |
169 | if (i >= 0) { |
|
175 | if (i >= 0) { | |
170 | auto eventIndex = index(i, 0); |
|
176 | auto eventIndex = index(i, 0); | |
171 | auto colCount = columnCount(); |
|
177 | auto colCount = columnCount(); | |
172 | emit dataChanged(eventIndex, index(i, colCount)); |
|
178 | emit dataChanged(eventIndex, index(i, colCount)); | |
173 |
|
179 | |||
174 | auto childCount = rowCount(eventIndex); |
|
180 | auto childCount = rowCount(eventIndex); | |
175 | emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex)); |
|
181 | emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex)); | |
176 | } |
|
182 | } | |
177 | } |
|
183 | } | |
178 |
|
184 | |||
179 | QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const |
|
185 | QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const | |
180 | { |
|
186 | { | |
181 | if (!hasIndex(row, column, parent)) { |
|
187 | if (!hasIndex(row, column, parent)) { | |
182 | return QModelIndex(); |
|
188 | return QModelIndex(); | |
183 | } |
|
189 | } | |
184 |
|
190 | |||
185 | switch (itemTypeOf(parent)) { |
|
191 | switch (itemTypeOf(parent)) { | |
186 | case CatalogueEventsModel::ItemType::Root: |
|
192 | case CatalogueEventsModel::ItemType::Root: | |
187 | return createIndex(row, column); |
|
193 | return createIndex(row, column); | |
188 | case CatalogueEventsModel::ItemType::Event: { |
|
194 | case CatalogueEventsModel::ItemType::Event: { | |
189 | auto event = getEvent(parent); |
|
195 | auto event = getEvent(parent); | |
190 | return createIndex(row, column, event.get()); |
|
196 | return createIndex(row, column, event.get()); | |
191 | } |
|
197 | } | |
192 | case CatalogueEventsModel::ItemType::EventProduct: |
|
198 | case CatalogueEventsModel::ItemType::EventProduct: | |
193 | break; |
|
199 | break; | |
194 | default: |
|
200 | default: | |
195 | break; |
|
201 | break; | |
196 | } |
|
202 | } | |
197 |
|
203 | |||
198 | return QModelIndex(); |
|
204 | return QModelIndex(); | |
199 | } |
|
205 | } | |
200 |
|
206 | |||
201 | QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const |
|
207 | QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const | |
202 | { |
|
208 | { | |
203 | switch (itemTypeOf(index)) { |
|
209 | switch (itemTypeOf(index)) { | |
204 | case CatalogueEventsModel::ItemType::EventProduct: { |
|
210 | case CatalogueEventsModel::ItemType::EventProduct: { | |
205 | auto parentEvent = static_cast<DBEvent *>(index.internalPointer()); |
|
211 | auto parentEvent = static_cast<DBEvent *>(index.internalPointer()); | |
206 | auto it |
|
212 | auto it | |
207 | = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(), |
|
213 | = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(), | |
208 | [parentEvent](auto event) { return event.get() == parentEvent; }); |
|
214 | [parentEvent](auto event) { return event.get() == parentEvent; }); | |
209 |
|
215 | |||
210 | if (it != impl->m_Events.cend()) { |
|
216 | if (it != impl->m_Events.cend()) { | |
211 | return createIndex(it - impl->m_Events.cbegin(), 0); |
|
217 | return createIndex(it - impl->m_Events.cbegin(), 0); | |
212 | } |
|
218 | } | |
213 | else { |
|
219 | else { | |
214 | return QModelIndex(); |
|
220 | return QModelIndex(); | |
215 | } |
|
221 | } | |
216 | } |
|
222 | } | |
217 | case CatalogueEventsModel::ItemType::Root: |
|
223 | case CatalogueEventsModel::ItemType::Root: | |
218 | break; |
|
224 | break; | |
219 | case CatalogueEventsModel::ItemType::Event: |
|
225 | case CatalogueEventsModel::ItemType::Event: | |
220 | break; |
|
226 | break; | |
221 | default: |
|
227 | default: | |
222 | break; |
|
228 | break; | |
223 | } |
|
229 | } | |
224 |
|
230 | |||
225 | return QModelIndex(); |
|
231 | return QModelIndex(); | |
226 | } |
|
232 | } | |
227 |
|
233 | |||
228 | int CatalogueEventsModel::rowCount(const QModelIndex &parent) const |
|
234 | int CatalogueEventsModel::rowCount(const QModelIndex &parent) const | |
229 | { |
|
235 | { | |
230 | if (parent.column() > 0) { |
|
236 | if (parent.column() > 0) { | |
231 | return 0; |
|
237 | return 0; | |
232 | } |
|
238 | } | |
233 |
|
239 | |||
234 | switch (itemTypeOf(parent)) { |
|
240 | switch (itemTypeOf(parent)) { | |
235 | case CatalogueEventsModel::ItemType::Root: |
|
241 | case CatalogueEventsModel::ItemType::Root: | |
236 | return impl->m_Events.count(); |
|
242 | return impl->m_Events.count(); | |
237 | case CatalogueEventsModel::ItemType::Event: { |
|
243 | case CatalogueEventsModel::ItemType::Event: { | |
238 | auto event = getEvent(parent); |
|
244 | auto event = getEvent(parent); | |
239 | return impl->m_EventProducts[event.get()].count(); |
|
245 | return impl->m_EventProducts[event.get()].count(); | |
240 | } |
|
246 | } | |
241 | case CatalogueEventsModel::ItemType::EventProduct: |
|
247 | case CatalogueEventsModel::ItemType::EventProduct: | |
242 | break; |
|
248 | break; | |
243 | default: |
|
249 | default: | |
244 | break; |
|
250 | break; | |
245 | } |
|
251 | } | |
246 |
|
252 | |||
247 | return 0; |
|
253 | return 0; | |
248 | } |
|
254 | } | |
249 |
|
255 | |||
250 | int CatalogueEventsModel::columnCount(const QModelIndex &parent) const |
|
256 | int CatalogueEventsModel::columnCount(const QModelIndex &parent) const | |
251 | { |
|
257 | { | |
252 | return static_cast<int>(CatalogueEventsModelPrivate::Column::NbColumn); |
|
258 | return static_cast<int>(CatalogueEventsModelPrivate::Column::NbColumn); | |
253 | } |
|
259 | } | |
254 |
|
260 | |||
255 | Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const |
|
261 | Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const | |
256 | { |
|
262 | { | |
257 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; |
|
263 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; | |
258 | } |
|
264 | } | |
259 |
|
265 | |||
260 | QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const |
|
266 | QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const | |
261 | { |
|
267 | { | |
262 | if (index.isValid()) { |
|
268 | if (index.isValid()) { | |
263 |
|
269 | |||
264 | auto type = itemTypeOf(index); |
|
270 | auto type = itemTypeOf(index); | |
265 | if (type == CatalogueEventsModel::ItemType::Event) { |
|
271 | if (type == CatalogueEventsModel::ItemType::Event) { | |
266 | auto event = getEvent(index); |
|
272 | auto event = getEvent(index); | |
267 | switch (role) { |
|
273 | switch (role) { | |
268 | case Qt::DisplayRole: |
|
274 | case Qt::DisplayRole: | |
269 | return impl->eventData(index.column(), event); |
|
275 | return impl->eventData(index.column(), event); | |
270 | break; |
|
276 | break; | |
271 | } |
|
277 | } | |
272 | } |
|
278 | } | |
273 | else if (type == CatalogueEventsModel::ItemType::EventProduct) { |
|
279 | else if (type == CatalogueEventsModel::ItemType::EventProduct) { | |
274 | auto product = getEventProduct(index); |
|
280 | auto product = getEventProduct(index); | |
275 | switch (role) { |
|
281 | switch (role) { | |
276 | case Qt::DisplayRole: |
|
282 | case Qt::DisplayRole: | |
277 | return impl->eventProductData(index.column(), product); |
|
283 | return impl->eventProductData(index.column(), product); | |
278 | break; |
|
284 | break; | |
279 | } |
|
285 | } | |
280 | } |
|
286 | } | |
281 | } |
|
287 | } | |
282 |
|
288 | |||
283 | return QVariant{}; |
|
289 | return QVariant{}; | |
284 | } |
|
290 | } | |
285 |
|
291 | |||
286 | QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
292 | QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const | |
287 | { |
|
293 | { | |
288 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
|
294 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | |
289 | return impl->columnNames().value(section); |
|
295 | return impl->columnNames().value(section); | |
290 | } |
|
296 | } | |
291 |
|
297 | |||
292 | return QVariant(); |
|
298 | return QVariant(); | |
293 | } |
|
299 | } | |
294 |
|
300 | |||
295 | void CatalogueEventsModel::sort(int column, Qt::SortOrder order) |
|
301 | void CatalogueEventsModel::sort(int column, Qt::SortOrder order) | |
296 | { |
|
302 | { | |
297 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), |
|
303 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), | |
298 | [this, column, order](auto e1, auto e2) { |
|
304 | [this, column, order](auto e1, auto e2) { | |
299 | auto data1 = impl->eventData(column, e1); |
|
305 | auto data1 = impl->eventData(column, e1); | |
300 | auto data2 = impl->eventData(column, e2); |
|
306 | auto data2 = impl->eventData(column, e2); | |
301 |
|
307 | |||
302 | auto result = data1.toString() < data2.toString(); |
|
308 | auto result = data1.toString() < data2.toString(); | |
303 |
|
309 | |||
304 | return order == Qt::AscendingOrder ? result : !result; |
|
310 | return order == Qt::AscendingOrder ? result : !result; | |
305 | }); |
|
311 | }); | |
306 |
|
312 | |||
307 | emit dataChanged(QModelIndex(), QModelIndex()); |
|
313 | emit dataChanged(QModelIndex(), QModelIndex()); | |
308 | } |
|
314 | } | |
309 |
|
315 | |||
310 | Qt::DropActions CatalogueEventsModel::supportedDragActions() const |
|
316 | Qt::DropActions CatalogueEventsModel::supportedDragActions() const | |
311 | { |
|
317 | { | |
312 | return Qt::CopyAction | Qt::MoveAction; |
|
318 | return Qt::CopyAction | Qt::MoveAction; | |
313 | } |
|
319 | } | |
314 |
|
320 | |||
315 | QStringList CatalogueEventsModel::mimeTypes() const |
|
321 | QStringList CatalogueEventsModel::mimeTypes() const | |
316 | { |
|
322 | { | |
317 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; |
|
323 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; | |
318 | } |
|
324 | } | |
319 |
|
325 | |||
320 | QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const |
|
326 | QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const | |
321 | { |
|
327 | { | |
322 | auto mimeData = new QMimeData; |
|
328 | auto mimeData = new QMimeData; | |
323 |
|
329 | |||
324 | bool isFirst = true; |
|
330 | bool isFirst = true; | |
325 |
|
331 | |||
326 | QVector<std::shared_ptr<DBEvent> > eventList; |
|
332 | QVector<std::shared_ptr<DBEvent> > eventList; | |
327 | QVector<std::shared_ptr<DBEventProduct> > eventProductList; |
|
333 | QVector<std::shared_ptr<DBEventProduct> > eventProductList; | |
328 |
|
334 | |||
329 | SqpRange firstTimeRange; |
|
335 | SqpRange firstTimeRange; | |
330 | for (const auto &index : indexes) { |
|
336 | for (const auto &index : indexes) { | |
331 | if (index.column() == 0) { // only the first column |
|
337 | if (index.column() == 0) { // only the first column | |
332 |
|
338 | |||
333 | auto type = itemTypeOf(index); |
|
339 | auto type = itemTypeOf(index); | |
334 | if (type == ItemType::Event) { |
|
340 | if (type == ItemType::Event) { | |
335 | auto event = getEvent(index); |
|
341 | auto event = getEvent(index); | |
336 | eventList << event; |
|
342 | eventList << event; | |
337 |
|
343 | |||
338 | if (isFirst) { |
|
344 | if (isFirst) { | |
339 | isFirst = false; |
|
345 | isFirst = false; | |
340 | firstTimeRange.m_TStart = event->getTStart(); |
|
346 | firstTimeRange.m_TStart = event->getTStart(); | |
341 | firstTimeRange.m_TEnd = event->getTEnd(); |
|
347 | firstTimeRange.m_TEnd = event->getTEnd(); | |
342 | } |
|
348 | } | |
343 | } |
|
349 | } | |
344 | else if (type == ItemType::EventProduct) { |
|
350 | else if (type == ItemType::EventProduct) { | |
345 | auto product = getEventProduct(index); |
|
351 | auto product = getEventProduct(index); | |
346 | eventProductList << product; |
|
352 | eventProductList << product; | |
347 |
|
353 | |||
348 | if (isFirst) { |
|
354 | if (isFirst) { | |
349 | isFirst = false; |
|
355 | isFirst = false; | |
350 | firstTimeRange.m_TStart = product->getTStart(); |
|
356 | firstTimeRange.m_TStart = product->getTStart(); | |
351 | firstTimeRange.m_TEnd = product->getTEnd(); |
|
357 | firstTimeRange.m_TEnd = product->getTEnd(); | |
352 | } |
|
358 | } | |
353 | } |
|
359 | } | |
354 | } |
|
360 | } | |
355 | } |
|
361 | } | |
356 |
|
362 | |||
357 | auto eventsEncodedData |
|
363 | auto eventsEncodedData | |
358 | = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO |
|
364 | = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO | |
359 | mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData); |
|
365 | mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData); | |
360 |
|
366 | |||
361 | if (eventList.count() + eventProductList.count() == 1) { |
|
367 | if (eventList.count() + eventProductList.count() == 1) { | |
362 | // No time range MIME data if multiple events are dragged |
|
368 | // No time range MIME data if multiple events are dragged | |
363 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); |
|
369 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); | |
364 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); |
|
370 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); | |
365 | } |
|
371 | } | |
366 |
|
372 | |||
367 | return mimeData; |
|
373 | return mimeData; | |
368 | } |
|
374 | } | |
369 |
|
375 | |||
370 | CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const |
|
376 | CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const | |
371 | { |
|
377 | { | |
372 | if (!index.isValid()) { |
|
378 | if (!index.isValid()) { | |
373 | return ItemType::Root; |
|
379 | return ItemType::Root; | |
374 | } |
|
380 | } | |
375 | else if (index.internalPointer() == nullptr) { |
|
381 | else if (index.internalPointer() == nullptr) { | |
376 | return ItemType::Event; |
|
382 | return ItemType::Event; | |
377 | } |
|
383 | } | |
378 | else { |
|
384 | else { | |
379 | return ItemType::EventProduct; |
|
385 | return ItemType::EventProduct; | |
380 | } |
|
386 | } | |
381 | } |
|
387 | } |
General Comments 4
Pull request updated. Auto status change to "Under Review"
Changed commits: * 1 added * 0 removed Changed files: * M app/src/Main.cpp * M core/include/Catalogue/CatalogueController.h * M core/src/Catalogue/CatalogueController.cpp * M core/src/Plugin/PluginManager.cpp * M core/tests/Data/TestDataSeriesUtils.cpp * M gui/include/Catalogue/CatalogueEventsModel.h * M gui/include/Catalogue/CatalogueEventsWidget.h * M gui/include/Catalogue/CatalogueTreeWidgetItem.h * M gui/meson.build * M gui/src/Catalogue/CatalogueEventsModel.cpp * M gui/src/Catalogue/CatalogueEventsWidget.cpp * M gui/src/Catalogue/CatalogueExplorer.cpp * M gui/src/Catalogue/CatalogueSideBarWidget.cpp * M gui/src/Catalogue/CatalogueTreeWidgetItem.cpp * M gui/src/Visualization/VisualizationActionManager.cpp * M gui/src/Visualization/VisualizationGraphWidget.cpp * M gui/src/Visualization/VisualizationSelectionZoneItem.cpp * M plugins/amda/tests/TestAmdaResultParser.cpp * R cmake/FindCatalogueAPI.cmake * R core/include/Common/MimeTypesDef.h * R core/include/Data/DataSeriesUtils.h * R core/include/Data/OptionalAxis.h * R core/include/Data/SpectrogramSeries.h * R core/include/Data/Unit.h * R core/include/DataSource/DataSourceItemMergeHelper.h * R core/include/Variable/VariableCacheStrategyFactory.h * R core/include/Variable/VariableSingleThresholdCacheStrategy.h * R core/src/Common/MimeTypesDef.cpp * R core/src/Data/DataSeriesUtils.cpp * R core/src/Data/OptionalAxis.cpp * R core/src/Data/SpectrogramSeries.cpp * R core/src/DataSource/DataSourceItemMergeHelper.cpp * R core/tests-resources/TestDataSeriesUtils/TestThresholds.txt * R core/tests/Data/DataSeriesBuilders.cpp * R core/tests/Data/DataSeriesBuilders.h * R core/tests/Data/DataSeriesTestsUtils.cpp * R core/tests/Data/DataSeriesTestsUtils.h * R core/tests/Data/TestOptionalAxis.cpp * R core/tests/Data/TestScalarSeries.cpp * R core/tests/Data/TestSpectrogramSeries.cpp * R core/tests/Data/TestVectorSeries.cpp * R core/tests/DataSource/DataSourceItemBuilder.cpp * R core/tests/DataSource/DataSourceItemBuilder.h * R core/tests/DataSource/TestDataSourceItem.cpp * R core/tests/Variable/TestVariableSync.cpp * R extern/CatalogueAPI.cmake * R gui/include/Actions/ActionsGuiController.h * R gui/include/Actions/SelectionZoneAction.h * R gui/include/Catalogue/CatalogueExplorer.h * R gui/include/Catalogue/CatalogueInspectorWidget.h * R gui/include/Catalogue/CatalogueSideBarWidget.h * R gui/include/Common/VisualizationDef.h * R gui/include/DataSource/DataSourceTreeWidget.h * R gui/include/DragAndDrop/DragDropGuiController.h * R gui/include/DragAndDrop/DragDropScroller.h * R gui/include/DragAndDrop/DragDropTabSwitcher.h * R gui/include/Variable/VariableInspectorTableView.h * R gui/include/Visualization/AxisRenderingUtils.h * R gui/include/Visualization/ColorScaleEditor.h * R gui/include/Visualization/MacScrollBarStyle.h * R gui/include/Visualization/PlottablesRenderingUtils.h * R gui/include/Visualization/QCPColorMapIterator.h * R gui/include/Visualization/SqpColorScale.h * R gui/include/Visualization/VisualizationActionManager.h * R gui/include/Visualization/VisualizationCursorItem.h * R gui/include/Visualization/VisualizationDragDropContainer.h * R gui/include/Visualization/VisualizationDragWidget.h * R gui/include/Visualization/VisualizationMultiZoneSelectionDialog.h * R gui/include/Visualization/VisualizationSelectionZoneItem.h * R gui/include/Visualization/VisualizationSelectionZoneManager.h * R gui/resources/icones/add.png * R gui/resources/icones/allEvents.png * R gui/resources/icones/catalogue.png * R gui/resources/icones/chart.png * R gui/resources/icones/cursor.png * R gui/resources/icones/database.png * R gui/resources/icones/discard.png * R gui/resources/icones/drag.png * R gui/resources/icones/pointer.png * R gui/resources/icones/rectangle.png * R gui/resources/icones/remove.png * R gui/resources/icones/save.png * R gui/resources/icones/time.png * R gui/resources/icones/trash.png * R gui/resources/icones/zoom.png * R gui/src/Actions/ActionsGuiController.cpp * R gui/src/Actions/SelectionZoneAction.cpp * R gui/src/Catalogue/CatalogueInspectorWidget.cpp * R gui/src/Common/VisualizationDef.cpp * R gui/src/DataSource/DataSourceTreeWidget.cpp * R gui/src/DragAndDrop/DragDropGuiController.cpp * R gui/src/DragAndDrop/DragDropScroller.cpp * R gui/src/DragAndDrop/DragDropTabSwitcher.cpp * R gui/src/Variable/VariableInspectorTableView.cpp * R gui/src/Visualization/AxisRenderingUtils.cpp * R gui/src/Visualization/ColorScaleEditor.cpp * R gui/src/Visualization/MacScrollBarStyle.cpp * R gui/src/Visualization/PlottablesRenderingUtils.cpp * R gui/src/Visualization/QCPColorMapIterator.cpp * R gui/src/Visualization/SqpColorScale.cpp * R gui/src/Visualization/VisualizationCursorItem.cpp * R gui/src/Visualization/VisualizationDragDropContainer.cpp * R gui/src/Visualization/VisualizationDragWidget.cpp * R gui/src/Visualization/VisualizationMultiZoneSelectionDialog.cpp * R gui/src/Visualization/VisualizationSelectionZoneManager.cpp * R gui/ui/Catalogue/CatalogueEventsWidget.ui * R gui/ui/Catalogue/CatalogueExplorer.ui * R gui/ui/Catalogue/CatalogueInspectorWidget.ui * R gui/ui/Catalogue/CatalogueSideBarWidget.ui * R gui/ui/Visualization/ColorScaleEditor.ui * R gui/ui/Visualization/VisualizationMultiZoneSelectionDialog.ui * R plugins/amda/include/AmdaResultParserDefs.h * R plugins/amda/include/AmdaResultParserHelper.h * R plugins/amda/include/AmdaServer.h * R plugins/amda/resources/samples/AmdaSampleV3.json * R plugins/amda/src/AmdaResultParserDefs.cpp * R plugins/amda/src/AmdaResultParserHelper.cpp * R plugins/amda/src/AmdaServer.cpp * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/FileNotFound.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/NaNValue.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/NaNX.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/NoUnit.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/TooManyValues.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/ValidScalar1.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/ValidVector1.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/WrongDate.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/WrongUnit.txt * R plugins/amda/tests-resources/TestAmdaResultParser/amdaV2/WrongValue.txt * R plugins/amda/tests-resources/TestAmdaResultParser/spectro/InvalidSpectrogramWrongBands.txt * R plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram1.txt * R plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram2.txt * R plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram3.txt * R plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramDataHoles.txt * R plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramDataHoles2.txt * R plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramFillValues.txt * R plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramNaNValues.txt * R plugins/amda/vera-exclusions/exclusions.txt * R plugins/mockplugin/include/MockDefs.h * R plugins/mockplugin/src/MockDefs.cpp * R subprojects/CatalogueAPI.wrap * R subprojects/QxOrm.wrap * R .gitignore * R CMakeLists.txt * R app/src/MainWindow.cpp * R app/ui/MainWindow.ui * R cmake/sciqlop_applications.cmake * R cmake/sciqlop_package_qt.cmake * R core/CMakeLists.txt * R core/cmake/Findsciqlop-core.cmake * R core/include/Common/SortUtils.h * R core/include/Data/ArrayData.h * R core/include/Data/DataSeries.h * R core/include/Data/DataSeriesIterator.h * R core/include/Data/IDataSeries.h * R core/include/Data/VariableRequest.h * R core/include/DataSource/DataSourceController.h * R core/include/DataSource/DataSourceItem.h * R core/include/DataSource/DataSourceItemAction.h * R core/include/Plugin/PluginManager.h * R core/include/Time/TimeController.h * R core/include/Variable/Variable.h * R core/include/Variable/VariableCacheStrategy.h * R core/include/Variable/VariableController.h * R core/include/Variable/VariableModel.h * R core/meson.build * R core/src/Data/DataSeriesIterator.cpp * R core/src/Data/VectorSeries.cpp * R core/src/DataSource/DataSourceController.cpp * R core/src/DataSource/DataSourceItem.cpp * R core/src/DataSource/DataSourceItemAction.cpp * R core/src/Time/TimeController.cpp * R core/src/Variable/Variable.cpp * R core/src/Variable/VariableAcquisitionWorker.cpp * R core/src/Variable/VariableController.cpp * R core/src/Variable/VariableModel.cpp * R core/tests/Data/TestTwoDimArrayData.cpp * R core/tests/Variable/TestVariable.cpp * R core/tests/meson.build * R gui/CMakeLists.txt * R gui/cmake/Findsciqlop-gui.cmake * R gui/include/DataSource/DataSourceWidget.h * R gui/include/SqpApplication.h * R gui/include/TimeWidget/TimeWidget.h * R gui/include/Visualization/VisualizationGraphHelper.h * R gui/include/Visualization/VisualizationGraphRenderingDelegate.h * R gui/include/Visualization/VisualizationGraphWidget.h * R gui/include/Visualization/VisualizationTabWidget.h * R gui/include/Visualization/VisualizationWidget.h * R gui/include/Visualization/VisualizationZoneWidget.h * R gui/resources/sqpguiresources.qrc * R gui/src/DataSource/DataSourceTreeWidgetItem.cpp * R gui/src/DataSource/DataSourceWidget.cpp * R gui/src/SqpApplication.cpp * R gui/src/TimeWidget/TimeWidget.cpp * R gui/src/Variable/VariableInspectorWidget.cpp * R gui/src/Visualization/VisualizationGraphHelper.cpp * R gui/src/Visualization/VisualizationGraphRenderingDelegate.cpp * R gui/src/Visualization/VisualizationTabWidget.cpp * R gui/src/Visualization/VisualizationWidget.cpp * R gui/src/Visualization/VisualizationZoneWidget.cpp * R gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp * R gui/src/Visualization/operations/RescaleAxeOperation.cpp * R gui/ui/DataSource/DataSourceWidget.ui * R gui/ui/TimeWidget/TimeWidget.ui * R gui/ui/Variable/VariableInspectorWidget.ui * R gui/ui/Visualization/VisualizationTabWidget.ui * R gui/ui/Visualization/VisualizationZoneWidget.ui * R gui/vera-exclusions/exclusions.txt * R meson.build * R plugins/amda/CMakeLists.txt * R plugins/amda/cmake/Findsciqlop-amda.cmake * R plugins/amda/include/AmdaDefs.h * R plugins/amda/include/AmdaPlugin.h * R plugins/amda/include/AmdaProvider.h * R plugins/amda/include/AmdaResultParser.h * R plugins/amda/meson.build * R plugins/amda/resources/amdaresources.qrc * R plugins/amda/src/AmdaDefs.cpp * R plugins/amda/src/AmdaPlugin.cpp * R plugins/amda/src/AmdaProvider.cpp * R plugins/amda/src/AmdaResultParser.cpp * R plugins/amda/tests/TestAmdaAcquisition.cpp * R plugins/mockplugin/cmake/Findsciqlop-mockplugin.cmake * R plugins/mockplugin/include/CosinusProvider.h * R plugins/mockplugin/meson.build * R plugins/mockplugin/src/CosinusProvider.cpp * R plugins/mockplugin/src/MockPlugin.cpp * R plugins/mockplugin/tests/TestCosinusAcquisition.cpp * R core/src/Variable/VariableCacheStrategy.cpp * R core/tests/Data/TestDataSeries.cpp
Status change > Approved
You need to be logged in to leave comments.
Login now