@@ -1,470 +1,498 | |||
|
1 | 1 | #include "Catalogue/CatalogueEventsWidget.h" |
|
2 | 2 | #include "ui_CatalogueEventsWidget.h" |
|
3 | 3 | |
|
4 | 4 | #include <Catalogue/CatalogueController.h> |
|
5 | 5 | #include <Catalogue/CatalogueEventsModel.h> |
|
6 | 6 | #include <Catalogue/CatalogueExplorerHelper.h> |
|
7 | 7 | #include <CatalogueDao.h> |
|
8 | 8 | #include <DBCatalogue.h> |
|
9 | #include <DBEventProduct.h> | |
|
10 | #include <DataSource/DataSourceController.h> | |
|
9 | 11 | #include <SqpApplication.h> |
|
12 | #include <Variable/Variable.h> | |
|
13 | #include <Variable/VariableController.h> | |
|
10 | 14 | #include <Visualization/VisualizationTabWidget.h> |
|
11 | 15 | #include <Visualization/VisualizationWidget.h> |
|
12 | 16 | #include <Visualization/VisualizationZoneWidget.h> |
|
17 | #include <Visualization/VisualizationGraphWidget.h> | |
|
13 | 18 | |
|
14 | 19 | #include <QDialog> |
|
15 | 20 | #include <QDialogButtonBox> |
|
16 | 21 | #include <QListWidget> |
|
17 | 22 | #include <QMessageBox> |
|
18 | 23 | |
|
19 | 24 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") |
|
20 | 25 | |
|
21 | 26 | /// Fixed size of the validation column |
|
22 | 27 | const auto VALIDATION_COLUMN_SIZE = 35; |
|
23 | 28 | |
|
24 | 29 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { |
|
25 | 30 | |
|
26 | 31 | CatalogueEventsModel *m_Model = nullptr; |
|
27 | 32 | QStringList m_ZonesForTimeMode; |
|
28 | 33 | QString m_ZoneForGraphMode; |
|
29 | 34 | QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues; |
|
30 | 35 | bool m_AllEventDisplayed = false; |
|
36 | QVector<VisualizationGraphWidget *> m_CustomGraphs; | |
|
31 | 37 | |
|
32 | 38 | VisualizationWidget *m_VisualizationWidget = nullptr; |
|
33 | 39 | |
|
34 | 40 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget) |
|
35 | 41 | { |
|
36 | 42 | widget->ui->treeView->setSortingEnabled(false); |
|
37 | 43 | m_Model->setEvents(events); |
|
38 | 44 | widget->ui->treeView->setSortingEnabled(true); |
|
39 | 45 | |
|
40 | 46 | for (auto event : events) { |
|
41 | 47 | if (sqpApp->catalogueController().eventHasChanges(event)) { |
|
42 | 48 | auto index = m_Model->indexOf(event); |
|
43 | 49 | widget->setEventChanges(event, true); |
|
44 | 50 | } |
|
45 | 51 | } |
|
46 | 52 | } |
|
47 | 53 | |
|
48 | 54 | void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) |
|
49 | 55 | { |
|
50 | 56 | treeView->setSortingEnabled(false); |
|
51 | 57 | m_Model->addEvent(event); |
|
52 | 58 | treeView->setSortingEnabled(true); |
|
53 | 59 | } |
|
54 | 60 | |
|
55 | 61 | void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) |
|
56 | 62 | { |
|
57 | 63 | treeView->setSortingEnabled(false); |
|
58 | 64 | m_Model->removeEvent(event); |
|
59 | 65 | treeView->setSortingEnabled(true); |
|
60 | 66 | } |
|
61 | 67 | |
|
62 | 68 | QStringList getAvailableVisualizationZoneList() const |
|
63 | 69 | { |
|
64 | 70 | if (m_VisualizationWidget) { |
|
65 | 71 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
66 | 72 | return tab->availableZoneWidgets(); |
|
67 | 73 | } |
|
68 | 74 | } |
|
69 | 75 | |
|
70 | 76 | return QStringList{}; |
|
71 | 77 | } |
|
72 | 78 | |
|
73 | 79 | QStringList selectZone(QWidget *parent, const QStringList &selectedZones, |
|
74 | 80 | bool allowMultiSelection, const QPoint &location) |
|
75 | 81 | { |
|
76 | 82 | auto availableZones = getAvailableVisualizationZoneList(); |
|
77 | 83 | if (availableZones.isEmpty()) { |
|
78 | 84 | return QStringList{}; |
|
79 | 85 | } |
|
80 | 86 | |
|
81 | 87 | QDialog d(parent, Qt::Tool); |
|
82 | 88 | d.setWindowTitle("Choose a zone"); |
|
83 | 89 | auto layout = new QVBoxLayout{&d}; |
|
84 | 90 | layout->setContentsMargins(0, 0, 0, 0); |
|
85 | 91 | auto listWidget = new QListWidget{&d}; |
|
86 | 92 | layout->addWidget(listWidget); |
|
87 | 93 | |
|
88 | 94 | QSet<QListWidgetItem *> checkedItems; |
|
89 | 95 | for (auto zone : availableZones) { |
|
90 | 96 | auto item = new QListWidgetItem{zone}; |
|
91 | 97 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); |
|
92 | 98 | if (selectedZones.contains(zone)) { |
|
93 | 99 | item->setCheckState(Qt::Checked); |
|
94 | 100 | checkedItems << item; |
|
95 | 101 | } |
|
96 | 102 | else { |
|
97 | 103 | item->setCheckState(Qt::Unchecked); |
|
98 | 104 | } |
|
99 | 105 | |
|
100 | 106 | listWidget->addItem(item); |
|
101 | 107 | } |
|
102 | 108 | |
|
103 | 109 | auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d}; |
|
104 | 110 | layout->addWidget(buttonBox); |
|
105 | 111 | |
|
106 | 112 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept); |
|
107 | 113 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject); |
|
108 | 114 | |
|
109 | 115 | QObject::connect(listWidget, &QListWidget::itemChanged, |
|
110 | 116 | [&checkedItems, allowMultiSelection, listWidget](auto item) { |
|
111 | 117 | if (item->checkState() == Qt::Checked) { |
|
112 | 118 | if (!allowMultiSelection) { |
|
113 | 119 | for (auto checkedItem : checkedItems) { |
|
114 | 120 | listWidget->blockSignals(true); |
|
115 | 121 | checkedItem->setCheckState(Qt::Unchecked); |
|
116 | 122 | listWidget->blockSignals(false); |
|
117 | 123 | } |
|
118 | 124 | |
|
119 | 125 | checkedItems.clear(); |
|
120 | 126 | } |
|
121 | 127 | checkedItems << item; |
|
122 | 128 | } |
|
123 | 129 | else { |
|
124 | 130 | checkedItems.remove(item); |
|
125 | 131 | } |
|
126 | 132 | }); |
|
127 | 133 | |
|
128 | 134 | QStringList result; |
|
129 | 135 | |
|
130 | 136 | d.setMinimumWidth(120); |
|
131 | 137 | d.resize(d.minimumSizeHint()); |
|
132 | 138 | d.move(location); |
|
133 | 139 | if (d.exec() == QDialog::Accepted) { |
|
134 | 140 | for (auto item : checkedItems) { |
|
135 | 141 | result += item->text(); |
|
136 | 142 | } |
|
137 | 143 | } |
|
138 | 144 | else { |
|
139 | 145 | result = selectedZones; |
|
140 | 146 | } |
|
141 | 147 | |
|
142 | 148 | return result; |
|
143 | 149 | } |
|
144 | 150 | |
|
145 | 151 | void updateForTimeMode(QTreeView *treeView) |
|
146 | 152 | { |
|
147 | 153 | auto selectedRows = treeView->selectionModel()->selectedRows(); |
|
148 | 154 | |
|
149 | 155 | if (selectedRows.count() == 1) { |
|
150 | 156 | auto event = m_Model->getEvent(selectedRows.first()); |
|
151 | 157 | if (event) { |
|
152 | 158 | if (m_VisualizationWidget) { |
|
153 | 159 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
154 | 160 | |
|
155 | 161 | for (auto zoneName : m_ZonesForTimeMode) { |
|
156 | 162 | if (auto zone = tab->getZoneWithName(zoneName)) { |
|
157 | 163 | SqpRange eventRange; |
|
158 | 164 | eventRange.m_TStart = event->getTStart(); |
|
159 | 165 | eventRange.m_TEnd = event->getTEnd(); |
|
160 | 166 | zone->setZoneRange(eventRange); |
|
161 | 167 | } |
|
162 | 168 | } |
|
163 | 169 | } |
|
164 | 170 | else { |
|
165 | 171 | qCWarning(LOG_CatalogueEventsWidget()) |
|
166 | 172 | << "updateTimeZone: no tab found in the visualization"; |
|
167 | 173 | } |
|
168 | 174 | } |
|
169 | 175 | else { |
|
170 | 176 | qCWarning(LOG_CatalogueEventsWidget()) |
|
171 | 177 | << "updateTimeZone: visualization widget not found"; |
|
172 | 178 | } |
|
173 | 179 | } |
|
174 | 180 | } |
|
175 | 181 | else { |
|
176 | 182 | qCWarning(LOG_CatalogueEventsWidget()) |
|
177 | 183 | << "updateTimeZone: not compatible with multiple events selected"; |
|
178 | 184 | } |
|
179 | 185 | } |
|
180 | 186 | |
|
181 | 187 | void updateForGraphMode(QTreeView *treeView) |
|
182 | 188 | { |
|
183 | 189 | auto selectedRows = treeView->selectionModel()->selectedRows(); |
|
184 | 190 | |
|
185 | 191 | if (selectedRows.count() == 1) { |
|
186 | 192 | auto event = m_Model->getEvent(selectedRows.first()); |
|
187 | 193 | if (m_VisualizationWidget) { |
|
188 | 194 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
189 | 195 | if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { |
|
190 | // TODO | |
|
196 | ||
|
197 | for (auto graph : m_CustomGraphs) { | |
|
198 | graph->close(); | |
|
199 | } | |
|
200 | m_CustomGraphs.clear(); | |
|
201 | ||
|
202 | for (auto eventProduct : event->getEventProducts()) { | |
|
203 | auto productId = eventProduct.getProductId(); | |
|
204 | ||
|
205 | auto context = new QObject{treeView}; | |
|
206 | QObject::connect(&sqpApp->variableController(), | |
|
207 | &VariableController::variableAdded, context, | |
|
208 | [this, zone, context](auto variable) { | |
|
209 | auto graph = zone->createGraph(variable); | |
|
210 | m_CustomGraphs << graph; | |
|
211 | delete context; // removes the connection | |
|
212 | }, | |
|
213 | Qt::QueuedConnection); | |
|
214 | ||
|
215 | QMetaObject::invokeMethod( | |
|
216 | &sqpApp->dataSourceController(), "requestVariableFromProductIdKey", | |
|
217 | Qt::QueuedConnection, Q_ARG(QString, productId)); | |
|
218 | } | |
|
191 | 219 | } |
|
192 | 220 | } |
|
193 | 221 | else { |
|
194 | 222 | qCWarning(LOG_CatalogueEventsWidget()) |
|
195 | 223 | << "updateGraphMode: no tab found in the visualization"; |
|
196 | 224 | } |
|
197 | 225 | } |
|
198 | 226 | else { |
|
199 | 227 | qCWarning(LOG_CatalogueEventsWidget()) |
|
200 | 228 | << "updateGraphMode: visualization widget not found"; |
|
201 | 229 | } |
|
202 | 230 | } |
|
203 | 231 | else { |
|
204 | 232 | qCWarning(LOG_CatalogueEventsWidget()) |
|
205 | 233 | << "updateGraphMode: not compatible with multiple events selected"; |
|
206 | 234 | } |
|
207 | 235 | } |
|
208 | 236 | |
|
209 | 237 | void getSelectedItems( |
|
210 | 238 | QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events, |
|
211 | 239 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts) |
|
212 | 240 | { |
|
213 | 241 | for (auto rowIndex : treeView->selectionModel()->selectedRows()) { |
|
214 | 242 | auto itemType = m_Model->itemTypeOf(rowIndex); |
|
215 | 243 | if (itemType == CatalogueEventsModel::ItemType::Event) { |
|
216 | 244 | events << m_Model->getEvent(rowIndex); |
|
217 | 245 | } |
|
218 | 246 | else if (itemType == CatalogueEventsModel::ItemType::EventProduct) { |
|
219 | 247 | eventProducts << qMakePair(m_Model->getParentEvent(rowIndex), |
|
220 | 248 | m_Model->getEventProduct(rowIndex)); |
|
221 | 249 | } |
|
222 | 250 | } |
|
223 | 251 | } |
|
224 | 252 | }; |
|
225 | 253 | |
|
226 | 254 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) |
|
227 | 255 | : QWidget(parent), |
|
228 | 256 | ui(new Ui::CatalogueEventsWidget), |
|
229 | 257 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} |
|
230 | 258 | { |
|
231 | 259 | ui->setupUi(this); |
|
232 | 260 | |
|
233 | 261 | impl->m_Model = new CatalogueEventsModel{this}; |
|
234 | 262 | ui->treeView->setModel(impl->m_Model); |
|
235 | 263 | |
|
236 | 264 | ui->treeView->setSortingEnabled(true); |
|
237 | 265 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); |
|
238 | 266 | ui->treeView->setDragEnabled(true); |
|
239 | 267 | |
|
240 | 268 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { |
|
241 | 269 | if (checked) { |
|
242 | 270 | ui->btnChart->setChecked(false); |
|
243 | 271 | impl->m_ZonesForTimeMode |
|
244 | 272 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, |
|
245 | 273 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); |
|
246 | 274 | |
|
247 | 275 | impl->updateForTimeMode(ui->treeView); |
|
248 | 276 | } |
|
249 | 277 | }); |
|
250 | 278 | |
|
251 | 279 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { |
|
252 | 280 | if (checked) { |
|
253 | 281 | ui->btnTime->setChecked(false); |
|
254 | 282 | impl->m_ZoneForGraphMode |
|
255 | 283 | = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, |
|
256 | 284 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) |
|
257 | 285 | .value(0); |
|
258 | 286 | |
|
259 | 287 | impl->updateForGraphMode(ui->treeView); |
|
260 | 288 | } |
|
261 | 289 | }); |
|
262 | 290 | |
|
263 | 291 | connect(ui->btnRemove, &QToolButton::clicked, [this]() { |
|
264 | 292 | QVector<std::shared_ptr<DBEvent> > events; |
|
265 | 293 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; |
|
266 | 294 | impl->getSelectedItems(ui->treeView, events, eventProducts); |
|
267 | 295 | |
|
268 | 296 | if (!events.isEmpty() && eventProducts.isEmpty()) { |
|
269 | 297 | |
|
270 | 298 | if (QMessageBox::warning(this, tr("Remove Event(s)"), |
|
271 | 299 | tr("The selected event(s) will be permanently removed " |
|
272 | 300 | "from the repository!\nAre you sure you want to continue?"), |
|
273 | 301 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) |
|
274 | 302 | == QMessageBox::Yes) { |
|
275 | 303 | |
|
276 | 304 | for (auto event : events) { |
|
277 | 305 | sqpApp->catalogueController().removeEvent(event); |
|
278 | 306 | impl->removeEvent(event, ui->treeView); |
|
279 | 307 | } |
|
280 | 308 | } |
|
281 | 309 | } |
|
282 | 310 | }); |
|
283 | 311 | |
|
284 | 312 | connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection); |
|
285 | 313 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, |
|
286 | 314 | &CatalogueEventsWidget::emitSelection); |
|
287 | 315 | |
|
288 | 316 | ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected |
|
289 | 317 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { |
|
290 | 318 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; |
|
291 | 319 | ui->btnChart->setEnabled(isNotMultiSelection); |
|
292 | 320 | ui->btnTime->setEnabled(isNotMultiSelection); |
|
293 | 321 | |
|
294 | 322 | if (isNotMultiSelection && ui->btnTime->isChecked()) { |
|
295 | 323 | impl->updateForTimeMode(ui->treeView); |
|
296 | 324 | } |
|
297 | 325 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { |
|
298 | 326 | impl->updateForGraphMode(ui->treeView); |
|
299 | 327 | } |
|
300 | 328 | |
|
301 | 329 | QVector<std::shared_ptr<DBEvent> > events; |
|
302 | 330 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; |
|
303 | 331 | impl->getSelectedItems(ui->treeView, events, eventProducts); |
|
304 | 332 | ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty()); |
|
305 | 333 | }); |
|
306 | 334 | |
|
307 | 335 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
308 | 336 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags, |
|
309 | 337 | QHeaderView::Stretch); |
|
310 | 338 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation, |
|
311 | 339 | QHeaderView::Fixed); |
|
312 | 340 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name, |
|
313 | 341 | QHeaderView::Interactive); |
|
314 | 342 | ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation, |
|
315 | 343 | VALIDATION_COLUMN_SIZE); |
|
316 | 344 | ui->treeView->header()->setSortIndicatorShown(true); |
|
317 | 345 | |
|
318 | 346 | connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() { |
|
319 | 347 | auto allEvents = impl->m_Model->events(); |
|
320 | 348 | for (auto event : allEvents) { |
|
321 | 349 | setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event)); |
|
322 | 350 | } |
|
323 | 351 | }); |
|
324 | 352 | |
|
325 | 353 | populateWithAllEvents(); |
|
326 | 354 | } |
|
327 | 355 | |
|
328 | 356 | CatalogueEventsWidget::~CatalogueEventsWidget() |
|
329 | 357 | { |
|
330 | 358 | delete ui; |
|
331 | 359 | } |
|
332 | 360 | |
|
333 | 361 | void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization) |
|
334 | 362 | { |
|
335 | 363 | impl->m_VisualizationWidget = visualization; |
|
336 | 364 | } |
|
337 | 365 | |
|
338 | 366 | void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event) |
|
339 | 367 | { |
|
340 | 368 | impl->addEvent(event, ui->treeView); |
|
341 | 369 | } |
|
342 | 370 | |
|
343 | 371 | void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges) |
|
344 | 372 | { |
|
345 | 373 | impl->m_Model->refreshEvent(event); |
|
346 | 374 | |
|
347 | 375 | auto eventIndex = impl->m_Model->indexOf(event); |
|
348 | 376 | auto validationIndex |
|
349 | 377 | = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation); |
|
350 | 378 | |
|
351 | 379 | if (validationIndex.isValid()) { |
|
352 | 380 | if (hasChanges) { |
|
353 | 381 | if (ui->treeView->indexWidget(validationIndex) == nullptr) { |
|
354 | 382 | auto widget = CatalogueExplorerHelper::buildValidationWidget( |
|
355 | 383 | ui->treeView, |
|
356 | 384 | [this, event]() { |
|
357 | 385 | sqpApp->catalogueController().saveEvent(event); |
|
358 | 386 | setEventChanges(event, false); |
|
359 | 387 | }, |
|
360 | 388 | [this, event]() { |
|
361 | 389 | bool removed = false; |
|
362 | 390 | sqpApp->catalogueController().discardEvent(event, removed); |
|
363 | 391 | if (removed) { |
|
364 | 392 | impl->m_Model->removeEvent(event); |
|
365 | 393 | } |
|
366 | 394 | else { |
|
367 | 395 | setEventChanges(event, false); |
|
368 | 396 | impl->m_Model->refreshEvent(event, true); |
|
369 | 397 | } |
|
370 | 398 | emitSelection(); |
|
371 | 399 | }); |
|
372 | 400 | ui->treeView->setIndexWidget(validationIndex, widget); |
|
373 | 401 | } |
|
374 | 402 | } |
|
375 | 403 | else { |
|
376 | 404 | // Note: the widget is destroyed |
|
377 | 405 | ui->treeView->setIndexWidget(validationIndex, nullptr); |
|
378 | 406 | } |
|
379 | 407 | } |
|
380 | 408 | else { |
|
381 | 409 | qCWarning(LOG_CatalogueEventsWidget()) |
|
382 | 410 | << "setEventChanges: the event is not displayed in the model."; |
|
383 | 411 | } |
|
384 | 412 | } |
|
385 | 413 | |
|
386 | 414 | QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const |
|
387 | 415 | { |
|
388 | 416 | return impl->m_DisplayedCatalogues; |
|
389 | 417 | } |
|
390 | 418 | |
|
391 | 419 | bool CatalogueEventsWidget::isAllEventsDisplayed() const |
|
392 | 420 | { |
|
393 | 421 | return impl->m_AllEventDisplayed; |
|
394 | 422 | } |
|
395 | 423 | |
|
396 | 424 | bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const |
|
397 | 425 | { |
|
398 | 426 | return impl->m_Model->indexOf(event).isValid(); |
|
399 | 427 | } |
|
400 | 428 | |
|
401 | 429 | void CatalogueEventsWidget::populateWithCatalogues( |
|
402 | 430 | const QVector<std::shared_ptr<DBCatalogue> > &catalogues) |
|
403 | 431 | { |
|
404 | 432 | impl->m_DisplayedCatalogues = catalogues; |
|
405 | 433 | impl->m_AllEventDisplayed = false; |
|
406 | 434 | |
|
407 | 435 | QSet<QUuid> eventIds; |
|
408 | 436 | QVector<std::shared_ptr<DBEvent> > events; |
|
409 | 437 | |
|
410 | 438 | for (auto catalogue : catalogues) { |
|
411 | 439 | auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue); |
|
412 | 440 | for (auto event : catalogueEvents) { |
|
413 | 441 | if (!eventIds.contains(event->getUniqId())) { |
|
414 | 442 | events << event; |
|
415 | 443 | eventIds.insert(event->getUniqId()); |
|
416 | 444 | } |
|
417 | 445 | } |
|
418 | 446 | } |
|
419 | 447 | |
|
420 | 448 | impl->setEvents(events, this); |
|
421 | 449 | } |
|
422 | 450 | |
|
423 | 451 | void CatalogueEventsWidget::populateWithAllEvents() |
|
424 | 452 | { |
|
425 | 453 | impl->m_DisplayedCatalogues.clear(); |
|
426 | 454 | impl->m_AllEventDisplayed = true; |
|
427 | 455 | |
|
428 | 456 | auto allEvents = sqpApp->catalogueController().retrieveAllEvents(); |
|
429 | 457 | |
|
430 | 458 | QVector<std::shared_ptr<DBEvent> > events; |
|
431 | 459 | for (auto event : allEvents) { |
|
432 | 460 | events << event; |
|
433 | 461 | } |
|
434 | 462 | |
|
435 | 463 | impl->setEvents(events, this); |
|
436 | 464 | } |
|
437 | 465 | |
|
438 | 466 | void CatalogueEventsWidget::clear() |
|
439 | 467 | { |
|
440 | 468 | impl->m_DisplayedCatalogues.clear(); |
|
441 | 469 | impl->m_AllEventDisplayed = false; |
|
442 | 470 | impl->setEvents({}, this); |
|
443 | 471 | } |
|
444 | 472 | |
|
445 | 473 | void CatalogueEventsWidget::refresh() |
|
446 | 474 | { |
|
447 | 475 | if (isAllEventsDisplayed()) { |
|
448 | 476 | populateWithAllEvents(); |
|
449 | 477 | } |
|
450 | 478 | else if (!impl->m_DisplayedCatalogues.isEmpty()) { |
|
451 | 479 | populateWithCatalogues(impl->m_DisplayedCatalogues); |
|
452 | 480 | } |
|
453 | 481 | } |
|
454 | 482 | |
|
455 | 483 | void CatalogueEventsWidget::emitSelection() |
|
456 | 484 | { |
|
457 | 485 | QVector<std::shared_ptr<DBEvent> > events; |
|
458 | 486 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; |
|
459 | 487 | impl->getSelectedItems(ui->treeView, events, eventProducts); |
|
460 | 488 | |
|
461 | 489 | if (!events.isEmpty() && eventProducts.isEmpty()) { |
|
462 | 490 | emit eventsSelected(events); |
|
463 | 491 | } |
|
464 | 492 | else if (events.isEmpty() && !eventProducts.isEmpty()) { |
|
465 | 493 | emit eventProductsSelected(eventProducts); |
|
466 | 494 | } |
|
467 | 495 | else { |
|
468 | 496 | emit selectionCleared(); |
|
469 | 497 | } |
|
470 | 498 | } |
@@ -1,148 +1,145 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>CatalogueEventsWidget</class> |
|
4 | 4 | <widget class="QWidget" name="CatalogueEventsWidget"> |
|
5 | 5 | <property name="geometry"> |
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 | 9 | <width>566</width> |
|
10 | 10 | <height>258</height> |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="windowTitle"> |
|
14 | 14 | <string>Form</string> |
|
15 | 15 | </property> |
|
16 | 16 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
17 | 17 | <property name="leftMargin"> |
|
18 | 18 | <number>0</number> |
|
19 | 19 | </property> |
|
20 | 20 | <property name="topMargin"> |
|
21 | 21 | <number>0</number> |
|
22 | 22 | </property> |
|
23 | 23 | <property name="rightMargin"> |
|
24 | 24 | <number>0</number> |
|
25 | 25 | </property> |
|
26 | 26 | <property name="bottomMargin"> |
|
27 | 27 | <number>0</number> |
|
28 | 28 | </property> |
|
29 | 29 | <item> |
|
30 | 30 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
31 | 31 | <item> |
|
32 | 32 | <widget class="QToolButton" name="btnAdd"> |
|
33 | 33 | <property name="enabled"> |
|
34 | 34 | <bool>false</bool> |
|
35 | 35 | </property> |
|
36 | 36 | <property name="text"> |
|
37 | 37 | <string>+</string> |
|
38 | 38 | </property> |
|
39 | 39 | <property name="icon"> |
|
40 | 40 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
41 | 41 | <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset> |
|
42 | 42 | </property> |
|
43 | 43 | <property name="autoRaise"> |
|
44 | 44 | <bool>true</bool> |
|
45 | 45 | </property> |
|
46 | 46 | </widget> |
|
47 | 47 | </item> |
|
48 | 48 | <item> |
|
49 | 49 | <widget class="QToolButton" name="btnRemove"> |
|
50 | 50 | <property name="text"> |
|
51 | 51 | <string> - </string> |
|
52 | 52 | </property> |
|
53 | 53 | <property name="icon"> |
|
54 | 54 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
55 | 55 | <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset> |
|
56 | 56 | </property> |
|
57 | 57 | <property name="autoRaise"> |
|
58 | 58 | <bool>true</bool> |
|
59 | 59 | </property> |
|
60 | 60 | </widget> |
|
61 | 61 | </item> |
|
62 | 62 | <item> |
|
63 | 63 | <widget class="Line" name="line"> |
|
64 | 64 | <property name="orientation"> |
|
65 | 65 | <enum>Qt::Vertical</enum> |
|
66 | 66 | </property> |
|
67 | 67 | </widget> |
|
68 | 68 | </item> |
|
69 | 69 | <item> |
|
70 | 70 | <widget class="QToolButton" name="btnTime"> |
|
71 | 71 | <property name="text"> |
|
72 | 72 | <string>T</string> |
|
73 | 73 | </property> |
|
74 | 74 | <property name="icon"> |
|
75 | 75 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
76 | 76 | <normaloff>:/icones/time.png</normaloff>:/icones/time.png</iconset> |
|
77 | 77 | </property> |
|
78 | 78 | <property name="checkable"> |
|
79 | 79 | <bool>true</bool> |
|
80 | 80 | </property> |
|
81 | 81 | <property name="autoRaise"> |
|
82 | 82 | <bool>true</bool> |
|
83 | 83 | </property> |
|
84 | 84 | </widget> |
|
85 | 85 | </item> |
|
86 | 86 | <item> |
|
87 | 87 | <widget class="QToolButton" name="btnChart"> |
|
88 | <property name="enabled"> | |
|
89 | <bool>false</bool> | |
|
90 | </property> | |
|
91 | 88 | <property name="text"> |
|
92 | 89 | <string>G</string> |
|
93 | 90 | </property> |
|
94 | 91 | <property name="icon"> |
|
95 | 92 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
96 | 93 | <normaloff>:/icones/chart.png</normaloff>:/icones/chart.png</iconset> |
|
97 | 94 | </property> |
|
98 | 95 | <property name="checkable"> |
|
99 | 96 | <bool>true</bool> |
|
100 | 97 | </property> |
|
101 | 98 | <property name="autoRaise"> |
|
102 | 99 | <bool>true</bool> |
|
103 | 100 | </property> |
|
104 | 101 | </widget> |
|
105 | 102 | </item> |
|
106 | 103 | <item> |
|
107 | 104 | <widget class="Line" name="line_2"> |
|
108 | 105 | <property name="orientation"> |
|
109 | 106 | <enum>Qt::Vertical</enum> |
|
110 | 107 | </property> |
|
111 | 108 | </widget> |
|
112 | 109 | </item> |
|
113 | 110 | <item> |
|
114 | 111 | <widget class="QLineEdit" name="lineEdit"> |
|
115 | 112 | <property name="enabled"> |
|
116 | 113 | <bool>false</bool> |
|
117 | 114 | </property> |
|
118 | 115 | </widget> |
|
119 | 116 | </item> |
|
120 | 117 | </layout> |
|
121 | 118 | </item> |
|
122 | 119 | <item> |
|
123 | 120 | <widget class="QTreeView" name="treeView"> |
|
124 | 121 | <property name="dragEnabled"> |
|
125 | 122 | <bool>true</bool> |
|
126 | 123 | </property> |
|
127 | 124 | <property name="dragDropMode"> |
|
128 | 125 | <enum>QAbstractItemView::DragDrop</enum> |
|
129 | 126 | </property> |
|
130 | 127 | <property name="selectionMode"> |
|
131 | 128 | <enum>QAbstractItemView::ExtendedSelection</enum> |
|
132 | 129 | </property> |
|
133 | 130 | <property name="selectionBehavior"> |
|
134 | 131 | <enum>QAbstractItemView::SelectRows</enum> |
|
135 | 132 | </property> |
|
136 | 133 | <attribute name="headerStretchLastSection"> |
|
137 | 134 | <bool>false</bool> |
|
138 | 135 | </attribute> |
|
139 | 136 | </widget> |
|
140 | 137 | </item> |
|
141 | 138 | </layout> |
|
142 | 139 | </widget> |
|
143 | 140 | <resources> |
|
144 | 141 | <include location="../../resources/sqpguiresources.qrc"/> |
|
145 | 142 | <include location="../../resources/sqpguiresources.qrc"/> |
|
146 | 143 | </resources> |
|
147 | 144 | <connections/> |
|
148 | 145 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now