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