##// END OF EJS Templates
Updates model after an event has been created through the colored zone
trabillard -
r1286:073d4af7c849
parent child
Show More
@@ -1,17 +1,19
1 1 #ifndef SCIQLOP_CATALOGUEACTIONMANAGER_H
2 2 #define SCIQLOP_CATALOGUEACTIONMANAGER_H
3 3
4 4 #include <Common/spimpl.h>
5 5
6 class CatalogueExplorer;
7
6 8 class CatalogueActionManager {
7 9 public:
8 CatalogueActionManager();
10 CatalogueActionManager(CatalogueExplorer *catalogueExplorer);
9 11
10 12 void installSelectionZoneActions();
11 13
12 14 private:
13 15 class CatalogueActionManagerPrivate;
14 16 spimpl::unique_impl_ptr<CatalogueActionManagerPrivate> impl;
15 17 };
16 18
17 19 #endif // SCIQLOP_CATALOGUEACTIONMANAGER_H
@@ -1,48 +1,54
1 1 #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H
2 2 #define SCIQLOP_CATALOGUEEVENTSWIDGET_H
3 3
4 4 #include <Common/spimpl.h>
5 5 #include <QLoggingCategory>
6 6 #include <QWidget>
7 7
8 8 class DBCatalogue;
9 9 class DBEvent;
10 10 class DBEventProduct;
11 11 class VisualizationWidget;
12 12
13 13 namespace Ui {
14 14 class CatalogueEventsWidget;
15 15 }
16 16
17 17 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget)
18 18
19 19 class CatalogueEventsWidget : public QWidget {
20 20 Q_OBJECT
21 21
22 22 signals:
23 23 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
24 24 void eventProductsSelected(
25 25 const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > >
26 26 &eventproducts);
27 27 void selectionCleared();
28 28
29 29 public:
30 30 explicit CatalogueEventsWidget(QWidget *parent = 0);
31 31 virtual ~CatalogueEventsWidget();
32 32
33 33 void setVisualizationWidget(VisualizationWidget *visualization);
34 34
35 void addEvent(const std::shared_ptr<DBEvent> &event);
35 36 void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges);
36 37
38 QVector<std::shared_ptr<DBCatalogue> > displayedCatalogues() const;
39 bool isAllEventsDisplayed() const;
40 bool isEventDisplayed(const std::shared_ptr<DBEvent> &event) const;
41
37 42 public slots:
38 43 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
39 44 void populateWithAllEvents();
45 void refresh();
40 46
41 47 private:
42 48 Ui::CatalogueEventsWidget *ui;
43 49
44 50 class CatalogueEventsWidgetPrivate;
45 51 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
46 52 };
47 53
48 54 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
@@ -1,29 +1,35
1 1 #ifndef SCIQLOP_CATALOGUEEXPLORER_H
2 2 #define SCIQLOP_CATALOGUEEXPLORER_H
3 3
4 4 #include <Common/spimpl.h>
5 5 #include <QDialog>
6 6
7 7 namespace Ui {
8 8 class CatalogueExplorer;
9 9 }
10 10
11 class CatalogueEventsWidget;
12 class CatalogueSideBarWidget;
13
11 14 class VisualizationWidget;
12 15
13 16 class CatalogueExplorer : public QDialog {
14 17 Q_OBJECT
15 18
16 19 public:
17 20 explicit CatalogueExplorer(QWidget *parent = 0);
18 21 virtual ~CatalogueExplorer();
19 22
20 23 void setVisualizationWidget(VisualizationWidget *visualization);
21 24
25 CatalogueEventsWidget &eventsWidget() const;
26 CatalogueSideBarWidget &sideBarWidget() const;
27
22 28 private:
23 29 Ui::CatalogueExplorer *ui;
24 30
25 31 class CatalogueExplorerPrivate;
26 32 spimpl::unique_impl_ptr<CatalogueExplorerPrivate> impl;
27 33 };
28 34
29 35 #endif // SCIQLOP_CATALOGUEEXPLORER_H
@@ -1,43 +1,46
1 1 #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
3 3
4 4 #include <Common/spimpl.h>
5 5 #include <QLoggingCategory>
6 6 #include <QTreeWidgetItem>
7 7 #include <QWidget>
8 8
9 9 class DBCatalogue;
10 10
11 11 namespace Ui {
12 12 class CatalogueSideBarWidget;
13 13 }
14 14
15 15 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget)
16 16
17 17 class CatalogueSideBarWidget : public QWidget {
18 18 Q_OBJECT
19 19
20 20 signals:
21 21 void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
22 22 void databaseSelected(const QStringList &databases);
23 23 void allEventsSelected();
24 24 void trashSelected();
25 25 void selectionCleared();
26 26
27 27 public:
28 28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
29 29 virtual ~CatalogueSideBarWidget();
30 30
31 void addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, const QString &repository);
31 32 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32 33
34 QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
35
33 36 private:
34 37 Ui::CatalogueSideBarWidget *ui;
35 38
36 39 class CatalogueSideBarWidgetPrivate;
37 40 spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl;
38 41
39 42 private slots:
40 43 void onContextMenuRequested(const QPoint &pos);
41 44 };
42 45
43 46 #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H
@@ -1,35 +1,36
1 1 #ifndef SCIQLOP_CREATEEVENTDIALOG_H
2 2 #define SCIQLOP_CREATEEVENTDIALOG_H
3 3
4 4 #include <Common/spimpl.h>
5 5 #include <QDialog>
6 6 #include <memory>
7 7
8 8 namespace Ui {
9 9 class CreateEventDialog;
10 10 }
11 11
12 12 class DBCatalogue;
13 13
14 14 class CreateEventDialog : public QDialog {
15 15 Q_OBJECT
16 16
17 17 public:
18 explicit CreateEventDialog(QWidget *parent = 0);
18 explicit CreateEventDialog(const QVector<std::shared_ptr<DBCatalogue> > &catalogues,
19 QWidget *parent = 0);
19 20 virtual ~CreateEventDialog();
20 21
21 22 void hideCatalogueChoice();
22 23
23 24 QString eventName() const;
24 25
25 26 std::shared_ptr<DBCatalogue> selectedCatalogue() const;
26 27 QString catalogueName() const;
27 28
28 29 private:
29 30 Ui::CreateEventDialog *ui;
30 31
31 32 class CreateEventDialogPrivate;
32 33 spimpl::unique_impl_ptr<CreateEventDialogPrivate> impl;
33 34 };
34 35
35 36 #endif // SCIQLOP_CREATEEVENTDIALOG_H
@@ -1,107 +1,133
1 1 #include "Catalogue/CatalogueActionManager.h"
2 2
3 3 #include <Actions/ActionsGuiController.h>
4 4 #include <Catalogue/CatalogueController.h>
5 5 #include <SqpApplication.h>
6 6 #include <Variable/Variable.h>
7 7 #include <Visualization/VisualizationGraphWidget.h>
8 8 #include <Visualization/VisualizationSelectionZoneItem.h>
9 9
10 #include <Catalogue/CatalogueEventsWidget.h>
11 #include <Catalogue/CatalogueExplorer.h>
12 #include <Catalogue/CatalogueSideBarWidget.h>
10 13 #include <Catalogue/CreateEventDialog.h>
11 14
12 15 #include <DBCatalogue.h>
13 16 #include <DBEvent.h>
14 17 #include <DBEventProduct.h>
15 18
16 19 #include <QBoxLayout>
17 20 #include <QComboBox>
18 21 #include <QDialog>
19 22 #include <QDialogButtonBox>
20 23 #include <QLineEdit>
21 24 #include <memory>
22 25
23 26 struct CatalogueActionManager::CatalogueActionManagerPrivate {
27
28 CatalogueExplorer *m_CatalogueExplorer = nullptr;
29
30 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
31 : m_CatalogueExplorer(catalogueExplorer)
32 {
33 }
34
24 35 void createEventFromZones(const QString &eventName,
25 36 const QVector<VisualizationSelectionZoneItem *> &zones,
26 37 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
27 38 {
28 39 auto event = std::make_shared<DBEvent>();
29 40 event->setName(eventName);
30 41
31 42 std::list<DBEventProduct> productList;
32 43 for (auto zone : zones) {
33 44 auto graph = zone->parentGraphWidget();
34 45 for (auto var : graph->variables()) {
35 46 auto eventProduct = std::make_shared<DBEventProduct>();
36 47 eventProduct->setEvent(*event);
37 48
38 49 auto zoneRange = zone->range();
39 50 eventProduct->setTStart(zoneRange.m_TStart);
40 51 eventProduct->setTEnd(zoneRange.m_TEnd);
41 52
42 53 eventProduct->setProductId(var->metadata().value("id", "TODO").toString()); // todo
43 54
44 55 productList.push_back(*eventProduct);
45 56 }
46 57 }
47 58
48 59 event->setEventProducts(productList);
49 60
50 61 sqpApp->catalogueController().addEvent(event);
51 62
63
52 64 if (catalogue) {
53 65 // TODO
54 66 // catalogue->addEvent(event);
67 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
68 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
69 m_CatalogueExplorer->eventsWidget().addEvent(event);
70 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
71 }
72 }
73 else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) {
74 m_CatalogueExplorer->eventsWidget().addEvent(event);
75 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
55 76 }
56 77 }
57 78 };
58 79
59 CatalogueActionManager::CatalogueActionManager()
60 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>()}
80 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
81 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
61 82 {
62 83 }
63 84
64 85 void CatalogueActionManager::installSelectionZoneActions()
65 86 {
66 87 auto &actionController = sqpApp->actionsGuiController();
67 88
68 89 auto createEventEnableFuntion = [](auto zones) {
69 90 QSet<VisualizationGraphWidget *> usedGraphs;
70 91 for (auto zone : zones) {
71 92 auto graph = zone->parentGraphWidget();
72 93 if (!usedGraphs.contains(graph)) {
73 94 usedGraphs.insert(graph);
74 95 }
75 96 else {
76 97 return false;
77 98 }
78 99 }
79 100
80 101 return true;
81 102 };
82 103
83 104 auto createEventAction = actionController.addSectionZoneAction(
84 105 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
85 CreateEventDialog dialog;
106 CreateEventDialog dialog(
107 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues("Default"));
86 108 dialog.hideCatalogueChoice();
87 109 if (dialog.exec() == QDialog::Accepted) {
88 110 impl->createEventFromZones(dialog.eventName(), zones);
89 111 }
90 112 });
91 113 createEventAction->setEnableFunction(createEventEnableFuntion);
92 114
93 115 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
94 116 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
95 CreateEventDialog dialog;
117 CreateEventDialog dialog(
118 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues("Default"));
96 119 if (dialog.exec() == QDialog::Accepted) {
97 120 auto selectedCatalogue = dialog.selectedCatalogue();
98 121 if (!selectedCatalogue) {
99 122 selectedCatalogue = std::make_shared<DBCatalogue>();
100 123 selectedCatalogue->setName(dialog.catalogueName());
124 // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO
125 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
126 "Default");
101 127 }
102 128
103 129 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
104 130 }
105 131 });
106 132 createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
107 133 }
@@ -1,364 +1,399
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 9 #include <SqpApplication.h>
10 10 #include <Visualization/VisualizationTabWidget.h>
11 11 #include <Visualization/VisualizationWidget.h>
12 12 #include <Visualization/VisualizationZoneWidget.h>
13 13
14 14 #include <QDialog>
15 15 #include <QDialogButtonBox>
16 16 #include <QListWidget>
17 17
18 18 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19 19
20 20 /// Fixed size of the validation column
21 21 const auto VALIDATION_COLUMN_SIZE = 35;
22 22
23 23 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
24 24
25 25 CatalogueEventsModel *m_Model = nullptr;
26 26 QStringList m_ZonesForTimeMode;
27 27 QString m_ZoneForGraphMode;
28 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
28 29
29 30 VisualizationWidget *m_VisualizationWidget = nullptr;
30 31
31 32 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
32 33 {
33 34 treeView->setSortingEnabled(false);
34 35 m_Model->setEvents(events);
35 36 treeView->setSortingEnabled(true);
36 37 }
37 38
38 39 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
39 40 {
40 41 treeView->setSortingEnabled(false);
41 42 m_Model->addEvent(event);
42 43 treeView->setSortingEnabled(true);
43 44 }
44 45
45 46 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
46 47 {
47 48 treeView->setSortingEnabled(false);
48 49 m_Model->removeEvent(event);
49 50 treeView->setSortingEnabled(true);
50 51 }
51 52
52 53 QStringList getAvailableVisualizationZoneList() const
53 54 {
54 55 if (m_VisualizationWidget) {
55 56 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
56 57 return tab->availableZoneWidgets();
57 58 }
58 59 }
59 60
60 61 return QStringList{};
61 62 }
62 63
63 64 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
64 65 bool allowMultiSelection, const QPoint &location)
65 66 {
66 67 auto availableZones = getAvailableVisualizationZoneList();
67 68 if (availableZones.isEmpty()) {
68 69 return QStringList{};
69 70 }
70 71
71 72 QDialog d(parent, Qt::Tool);
72 73 d.setWindowTitle("Choose a zone");
73 74 auto layout = new QVBoxLayout{&d};
74 75 layout->setContentsMargins(0, 0, 0, 0);
75 76 auto listWidget = new QListWidget{&d};
76 77 layout->addWidget(listWidget);
77 78
78 79 QSet<QListWidgetItem *> checkedItems;
79 80 for (auto zone : availableZones) {
80 81 auto item = new QListWidgetItem{zone};
81 82 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
82 83 if (selectedZones.contains(zone)) {
83 84 item->setCheckState(Qt::Checked);
84 85 checkedItems << item;
85 86 }
86 87 else {
87 88 item->setCheckState(Qt::Unchecked);
88 89 }
89 90
90 91 listWidget->addItem(item);
91 92 }
92 93
93 94 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
94 95 layout->addWidget(buttonBox);
95 96
96 97 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
97 98 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
98 99
99 100 QObject::connect(listWidget, &QListWidget::itemChanged,
100 101 [&checkedItems, allowMultiSelection, listWidget](auto item) {
101 102 if (item->checkState() == Qt::Checked) {
102 103 if (!allowMultiSelection) {
103 104 for (auto checkedItem : checkedItems) {
104 105 listWidget->blockSignals(true);
105 106 checkedItem->setCheckState(Qt::Unchecked);
106 107 listWidget->blockSignals(false);
107 108 }
108 109
109 110 checkedItems.clear();
110 111 }
111 112 checkedItems << item;
112 113 }
113 114 else {
114 115 checkedItems.remove(item);
115 116 }
116 117 });
117 118
118 119 QStringList result;
119 120
120 121 d.setMinimumWidth(120);
121 122 d.resize(d.minimumSizeHint());
122 123 d.move(location);
123 124 if (d.exec() == QDialog::Accepted) {
124 125 for (auto item : checkedItems) {
125 126 result += item->text();
126 127 }
127 128 }
128 129 else {
129 130 result = selectedZones;
130 131 }
131 132
132 133 return result;
133 134 }
134 135
135 136 void updateForTimeMode(QTreeView *treeView)
136 137 {
137 138 auto selectedRows = treeView->selectionModel()->selectedRows();
138 139
139 140 if (selectedRows.count() == 1) {
140 141 auto event = m_Model->getEvent(selectedRows.first());
141 142 if (event) {
142 143 if (m_VisualizationWidget) {
143 144 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
144 145
145 146 for (auto zoneName : m_ZonesForTimeMode) {
146 147 if (auto zone = tab->getZoneWithName(zoneName)) {
147 148 SqpRange eventRange;
148 149 eventRange.m_TStart = event->getTStart();
149 150 eventRange.m_TEnd = event->getTEnd();
150 151 zone->setZoneRange(eventRange);
151 152 }
152 153 }
153 154 }
154 155 else {
155 156 qCWarning(LOG_CatalogueEventsWidget())
156 157 << "updateTimeZone: no tab found in the visualization";
157 158 }
158 159 }
159 160 else {
160 161 qCWarning(LOG_CatalogueEventsWidget())
161 162 << "updateTimeZone: visualization widget not found";
162 163 }
163 164 }
164 165 }
165 166 else {
166 167 qCWarning(LOG_CatalogueEventsWidget())
167 168 << "updateTimeZone: not compatible with multiple events selected";
168 169 }
169 170 }
170 171
171 172 void updateForGraphMode(QTreeView *treeView)
172 173 {
173 174 auto selectedRows = treeView->selectionModel()->selectedRows();
174 175
175 176 if (selectedRows.count() == 1) {
176 177 auto event = m_Model->getEvent(selectedRows.first());
177 178 if (m_VisualizationWidget) {
178 179 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
179 180 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
180 181 // TODO
181 182 }
182 183 }
183 184 else {
184 185 qCWarning(LOG_CatalogueEventsWidget())
185 186 << "updateGraphMode: no tab found in the visualization";
186 187 }
187 188 }
188 189 else {
189 190 qCWarning(LOG_CatalogueEventsWidget())
190 191 << "updateGraphMode: visualization widget not found";
191 192 }
192 193 }
193 194 else {
194 195 qCWarning(LOG_CatalogueEventsWidget())
195 196 << "updateGraphMode: not compatible with multiple events selected";
196 197 }
197 198 }
198 199 };
199 200
200 201 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
201 202 : QWidget(parent),
202 203 ui(new Ui::CatalogueEventsWidget),
203 204 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
204 205 {
205 206 ui->setupUi(this);
206 207
207 208 impl->m_Model = new CatalogueEventsModel{this};
208 209 ui->treeView->setModel(impl->m_Model);
209 210
210 211 ui->treeView->setSortingEnabled(true);
211 212 ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
212 213 ui->treeView->setDragEnabled(true);
213 214
214 215 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
215 216 if (checked) {
216 217 ui->btnChart->setChecked(false);
217 218 impl->m_ZonesForTimeMode
218 219 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
219 220 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
220 221
221 222 impl->updateForTimeMode(ui->treeView);
222 223 }
223 224 });
224 225
225 226 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
226 227 if (checked) {
227 228 ui->btnTime->setChecked(false);
228 229 impl->m_ZoneForGraphMode
229 230 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
230 231 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
231 232 .value(0);
232 233
233 234 impl->updateForGraphMode(ui->treeView);
234 235 }
235 236 });
236 237
237 238 auto emitSelection = [this]() {
238 239 QVector<std::shared_ptr<DBEvent> > events;
239 240 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
240 241
241 242 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
242 243
243 244 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
244 245 if (itemType == CatalogueEventsModel::ItemType::Event) {
245 246 events << impl->m_Model->getEvent(rowIndex);
246 247 }
247 248 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
248 249 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
249 250 impl->m_Model->getEventProduct(rowIndex));
250 251 }
251 252 }
252 253
253 254 if (!events.isEmpty() && eventProducts.isEmpty()) {
254 255 emit this->eventsSelected(events);
255 256 }
256 257 else if (events.isEmpty() && !eventProducts.isEmpty()) {
257 258 emit this->eventProductsSelected(eventProducts);
258 259 }
259 260 else {
260 261 emit this->selectionCleared();
261 262 }
262 263 };
263 264
264 265 connect(ui->treeView, &QTreeView::clicked, emitSelection);
265 266 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
266 267
267 268 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
268 269 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
269 270 ui->btnChart->setEnabled(isNotMultiSelection);
270 271 ui->btnTime->setEnabled(isNotMultiSelection);
271 272
272 273 if (isNotMultiSelection && ui->btnTime->isChecked()) {
273 274 impl->updateForTimeMode(ui->treeView);
274 275 }
275 276 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
276 277 impl->updateForGraphMode(ui->treeView);
277 278 }
278 279 });
279 280
280 281 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
281 282 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
282 283 QHeaderView::Stretch);
283 284 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
284 285 QHeaderView::Fixed);
285 286 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
286 287 VALIDATION_COLUMN_SIZE);
287 288 ui->treeView->header()->setSortIndicatorShown(true);
288 289
289 290 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
290 291 auto allEvents = impl->m_Model->events();
291 292 for (auto event : allEvents) {
292 293 setEventChanges(event, impl->m_Model->eventsHasChanges(event));
293 294 }
294 295 });
295 296 }
296 297
297 298 CatalogueEventsWidget::~CatalogueEventsWidget()
298 299 {
299 300 delete ui;
300 301 }
301 302
302 303 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
303 304 {
304 305 impl->m_VisualizationWidget = visualization;
305 306 }
306 307
308 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
309 {
310 impl->addEvent(event, ui->treeView);
311 }
312
307 313 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
308 314 {
309 315 impl->m_Model->refreshEvent(event);
310 316
311 317 auto eventIndex = impl->m_Model->indexOf(event);
312 318 auto validationIndex
313 319 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
314 320
315 321 if (hasChanges) {
316 322 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
317 323 auto widget = CatalogueExplorerHelper::buildValidationWidget(
318 324 ui->treeView,
319 325 [this, event]() {
320 326 sqpApp->catalogueController().saveEvent(event);
321 327 setEventChanges(event, false);
322 328 },
323 329 [this, event]() { setEventChanges(event, false); });
324 330 ui->treeView->setIndexWidget(validationIndex, widget);
325 331 }
332
333 impl->m_Model->setEventHasChanges(event, hasChanges);
326 334 }
327 335 else {
328 // Note: the widget is destroyed
329 ui->treeView->setIndexWidget(validationIndex, nullptr);
336 qCWarning(LOG_CatalogueEventsWidget())
337 << "setEventChanges: the event is not displayed in the model.";
330 338 }
339 }
340
341 QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
342 {
343 return impl->m_DisplayedCatalogues;
344 }
345
346 bool CatalogueEventsWidget::isAllEventsDisplayed() const
347 {
348 return impl->m_DisplayedCatalogues.isEmpty();
349 }
331 350
332 impl->m_Model->setEventHasChanges(event, hasChanges);
351 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
352 {
353 return impl->m_Model->indexOf(event).isValid();
333 354 }
334 355
335 356 void CatalogueEventsWidget::populateWithCatalogues(
336 357 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
337 358 {
359 impl->m_DisplayedCatalogues = catalogues;
360
338 361 QSet<QUuid> eventIds;
339 362 QVector<std::shared_ptr<DBEvent> > events;
340 363
341 364 for (auto catalogue : catalogues) {
342 365 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
343 366 for (auto event : catalogueEvents) {
344 367 if (!eventIds.contains(event->getUniqId())) {
345 368 events << event;
346 369 eventIds.insert(event->getUniqId());
347 370 }
348 371 }
349 372 }
350 373
351 374 impl->setEvents(events, ui->treeView);
352 375 }
353 376
354 377 void CatalogueEventsWidget::populateWithAllEvents()
355 378 {
379 impl->m_DisplayedCatalogues.clear();
380
356 381 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
357 382
358 383 QVector<std::shared_ptr<DBEvent> > events;
359 384 for (auto event : allEvents) {
360 385 events << event;
361 386 }
362 387
363 388 impl->setEvents(events, ui->treeView);
364 389 }
390
391 void CatalogueEventsWidget::refresh()
392 {
393 if (impl->m_DisplayedCatalogues.isEmpty()) {
394 populateWithAllEvents();
395 }
396 else {
397 populateWithCatalogues(impl->m_DisplayedCatalogues);
398 }
399 }
@@ -1,98 +1,113
1 1 #include "Catalogue/CatalogueExplorer.h"
2 2 #include "ui_CatalogueExplorer.h"
3 3
4 4 #include <Catalogue/CatalogueActionManager.h>
5 5 #include <Catalogue/CatalogueController.h>
6 6 #include <SqpApplication.h>
7 7 #include <Visualization/VisualizationWidget.h>
8 8
9 9 #include <DBCatalogue.h>
10 10 #include <DBEvent.h>
11 11
12 12 struct CatalogueExplorer::CatalogueExplorerPrivate {
13 13 CatalogueActionManager m_ActionManager;
14
15 CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer)
16 : m_ActionManager(catalogueExplorer)
17 {
18 }
14 19 };
15 20
16 21 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
17 22 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
18 23 ui(new Ui::CatalogueExplorer),
19 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()}
24 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>(this)}
20 25 {
21 26 ui->setupUi(this);
22 27
23 28 impl->m_ActionManager.installSelectionZoneActions();
24 29
25 30 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
26 31 if (catalogues.count() == 1) {
27 32 ui->inspector->setCatalogue(catalogues.first());
28 33 }
29 34 else {
30 35 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
31 36 }
32 37
33 38 ui->events->populateWithCatalogues(catalogues);
34 39 });
35 40
36 41 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
37 42 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
38 43 });
39 44
40 45 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
41 46 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
42 47
43 48 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
44 49 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
45 50 ui->events->populateWithAllEvents();
46 51 });
47 52
48 53 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
49 54 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
50 55
51 56 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
52 57 if (events.count() == 1) {
53 58 ui->inspector->setEvent(events.first());
54 59 }
55 60 else {
56 61 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
57 62 }
58 63 });
59 64
60 65 connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) {
61 66 if (eventProducts.count() == 1) {
62 67 ui->inspector->setEventProduct(eventProducts.first().first,
63 68 eventProducts.first().second);
64 69 }
65 70 else {
66 71 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
67 72 }
68 73 });
69 74
70 75 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
71 76 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
72 77
73 78 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
74 79 sqpApp->catalogueController().updateCatalogue(catalogue);
75 80 ui->catalogues->setCatalogueChanges(catalogue, true);
76 81 });
77 82
78 83 connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) {
79 84 sqpApp->catalogueController().updateEvent(event);
80 85 ui->events->setEventChanges(event, true);
81 86 });
82 87
83 88 connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated,
84 89 [this](auto event, auto eventProduct) {
85 90 sqpApp->catalogueController().updateEventProduct(eventProduct);
86 91 ui->events->setEventChanges(event, true);
87 92 });
88 93 }
89 94
90 95 CatalogueExplorer::~CatalogueExplorer()
91 96 {
92 97 delete ui;
93 98 }
94 99
95 100 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization)
96 101 {
97 102 ui->events->setVisualizationWidget(visualization);
98 103 }
104
105 CatalogueEventsWidget &CatalogueExplorer::eventsWidget() const
106 {
107 return *ui->events;
108 }
109
110 CatalogueSideBarWidget &CatalogueExplorer::sideBarWidget() const
111 {
112 return *ui->catalogues;
113 }
@@ -1,313 +1,338
1 1 #include "Catalogue/CatalogueSideBarWidget.h"
2 2 #include "ui_CatalogueSideBarWidget.h"
3 3 #include <SqpApplication.h>
4 4
5 5 #include <Catalogue/CatalogueController.h>
6 6 #include <Catalogue/CatalogueExplorerHelper.h>
7 7 #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h>
8 8 #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h>
9 9 #include <Catalogue/CatalogueTreeModel.h>
10 10 #include <CatalogueDao.h>
11 11 #include <ComparaisonPredicate.h>
12 12 #include <DBCatalogue.h>
13 13
14 14 #include <QMenu>
15 15
16 16 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
17 17
18 18
19 19 constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1;
20 20 constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2;
21 21 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
22 22 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
23 23
24 24
25 25 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
26 26
27 27 CatalogueTreeModel *m_TreeModel = nullptr;
28 28
29 29 void configureTreeWidget(QTreeView *treeView);
30 30 QModelIndex addDatabaseItem(const QString &name);
31 31 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
32 32 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
33 33 const QModelIndex &databaseIndex);
34 34
35 35 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
36 36 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
37 37 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
38 38
39 39 int selectionType(QTreeView *treeView) const
40 40 {
41 41 auto selectedItems = treeView->selectionModel()->selectedRows();
42 42 if (selectedItems.isEmpty()) {
43 43 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
44 44 }
45 45 else {
46 46 auto firstIndex = selectedItems.first();
47 47 auto firstItem = m_TreeModel->item(firstIndex);
48 48 if (!firstItem) {
49 49 Q_ASSERT(false);
50 50 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
51 51 }
52 52 auto selectionType = firstItem->type();
53 53
54 54 for (auto itemIndex : selectedItems) {
55 55 auto item = m_TreeModel->item(itemIndex);
56 56 if (!item || item->type() != selectionType) {
57 57 // Incoherent multi selection
58 58 selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE;
59 59 break;
60 60 }
61 61 }
62 62
63 63 return selectionType;
64 64 }
65 65 }
66 66
67 67 QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const
68 68 {
69 69 QVector<std::shared_ptr<DBCatalogue> > catalogues;
70 70 auto selectedItems = treeView->selectionModel()->selectedRows();
71 71 for (auto itemIndex : selectedItems) {
72 72 auto item = m_TreeModel->item(itemIndex);
73 73 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
74 74 catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue());
75 75 }
76 76 }
77 77
78 78 return catalogues;
79 79 }
80 80
81 81 QStringList selectedRepositories(QTreeView *treeView) const
82 82 {
83 83 QStringList repositories;
84 84 auto selectedItems = treeView->selectionModel()->selectedRows();
85 85 for (auto itemIndex : selectedItems) {
86 86 auto item = m_TreeModel->item(itemIndex);
87 87 if (item && item->type() == DATABASE_ITEM_TYPE) {
88 88 repositories.append(item->text());
89 89 }
90 90 }
91 91
92 92 return repositories;
93 93 }
94 94 };
95 95
96 96 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
97 97 : QWidget(parent),
98 98 ui(new Ui::CatalogueSideBarWidget),
99 99 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
100 100 {
101 101 ui->setupUi(this);
102 102
103 103 impl->m_TreeModel = new CatalogueTreeModel(this);
104 104 ui->treeView->setModel(impl->m_TreeModel);
105 105
106 106 impl->configureTreeWidget(ui->treeView);
107 107
108 108 ui->treeView->header()->setStretchLastSection(false);
109 109 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
110 110 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
111 111
112 112 auto emitSelection = [this]() {
113 113
114 114 auto selectionType = impl->selectionType(ui->treeView);
115 115
116 116 switch (selectionType) {
117 117 case CATALOGUE_ITEM_TYPE:
118 118 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
119 119 break;
120 120 case DATABASE_ITEM_TYPE:
121 121 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
122 122 break;
123 123 case ALL_EVENT_ITEM_TYPE:
124 124 emit this->allEventsSelected();
125 125 break;
126 126 case TRASH_ITEM_TYPE:
127 127 emit this->trashSelected();
128 128 break;
129 129 default:
130 130 emit this->selectionCleared();
131 131 break;
132 132 }
133 133 };
134 134
135 135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
136 136 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
137 137 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
138 138 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
139 139 if (selectedIndexes.contains(index)) {
140 140 emitSelection();
141 141 }
142 142
143 143 auto item = impl->m_TreeModel->item(index);
144 144 impl->setHasChanges(true, index, ui->treeView);
145 145 });
146 146
147 147 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
148 148 connect(ui->treeView, &QTreeView::customContextMenuRequested, this,
149 149 &CatalogueSideBarWidget::onContextMenuRequested);
150 150 }
151 151
152 152 CatalogueSideBarWidget::~CatalogueSideBarWidget()
153 153 {
154 154 delete ui;
155 155 }
156 156
157 void CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue,
158 const QString &repository)
159 {
160 auto repositoryItem = impl->getDatabaseItem(repository);
161 impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem));
162 }
163
157 164 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
158 165 bool hasChanges)
159 166 {
160 167 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
161 168 auto index = impl->m_TreeModel->indexOf(catalogueItem);
162 169 impl->setHasChanges(hasChanges, index, ui->treeView);
163 170 // catalogueItem->refresh();
164 171 }
165 172 }
166 173
174 QVector<std::shared_ptr<DBCatalogue> >
175 CatalogueSideBarWidget::getCatalogues(const QString &repository) const
176 {
177 QVector<std::shared_ptr<DBCatalogue> > result;
178 auto repositoryItem = impl->getDatabaseItem(repository);
179 for (auto child : repositoryItem->children()) {
180 if (child->type() == CATALOGUE_ITEM_TYPE) {
181 auto catalogueItem = static_cast<CatalogueTreeItem *>(child);
182 result << catalogueItem->catalogue();
183 }
184 else {
185 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogues: invalid structure";
186 }
187 }
188
189 return result;
190 }
191
167 192 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
168 193 {
169 194 QMenu menu{this};
170 195
171 196 auto currentIndex = ui->treeView->currentIndex();
172 197 auto currentItem = impl->m_TreeModel->item(currentIndex);
173 198 if (!currentItem) {
174 199 return;
175 200 }
176 201
177 202 switch (currentItem->type()) {
178 203 case CATALOGUE_ITEM_TYPE:
179 204 menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); });
180 205 break;
181 206 case DATABASE_ITEM_TYPE:
182 207 break;
183 208 case ALL_EVENT_ITEM_TYPE:
184 209 break;
185 210 case TRASH_ITEM_TYPE:
186 211 menu.addAction("Empty Trash", []() {
187 212 // TODO
188 213 });
189 214 break;
190 215 default:
191 216 break;
192 217 }
193 218
194 219 if (!menu.isEmpty()) {
195 220 menu.exec(ui->treeView->mapToGlobal(pos));
196 221 }
197 222 }
198 223
199 224 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView)
200 225 {
201 226 auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events",
202 227 ALL_EVENT_ITEM_TYPE};
203 228 m_TreeModel->addTopLevelItem(allEventsItem);
204 229
205 230 auto trashItem
206 231 = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE};
207 232 m_TreeModel->addTopLevelItem(trashItem);
208 233
209 234 auto separator = new QFrame{treeView};
210 235 separator->setFrameShape(QFrame::HLine);
211 236 auto separatorItem
212 237 = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE};
213 238 separatorItem->setEnabled(false);
214 239 auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem);
215 240 treeView->setIndexWidget(separatorIndex, separator);
216 241
217 242 auto repositories = sqpApp->catalogueController().getRepositories();
218 243 for (auto dbname : repositories) {
219 244 auto dbIndex = addDatabaseItem(dbname);
220 245 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
221 246 for (auto catalogue : catalogues) {
222 247 addCatalogueItem(catalogue, dbIndex);
223 248 }
224 249 }
225 250
226 251 treeView->expandAll();
227 252 }
228 253
229 254 QModelIndex
230 255 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name)
231 256 {
232 257 auto databaseItem
233 258 = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE};
234 259 auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem);
235 260
236 261 return databaseIndex;
237 262 }
238 263
239 264 CatalogueAbstractTreeItem *
240 265 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name)
241 266 {
242 267 for (auto item : m_TreeModel->topLevelItems()) {
243 268 if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) {
244 269 return item;
245 270 }
246 271 }
247 272
248 273 return nullptr;
249 274 }
250 275
251 276 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
252 277 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
253 278 {
254 279 auto catalogueItem
255 280 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
256 281 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
257 282 }
258 283
259 284 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
260 285 const std::shared_ptr<DBCatalogue> &catalogue) const
261 286 {
262 287 for (auto item : m_TreeModel->topLevelItems()) {
263 288 if (item->type() == DATABASE_ITEM_TYPE) {
264 289 for (auto childItem : item->children()) {
265 290 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
266 291 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
267 292 if (catalogueItem->catalogue() == catalogue) {
268 293 return catalogueItem;
269 294 }
270 295 }
271 296 else {
272 297 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree "
273 298 "structure. A database item should "
274 299 "only contain catalogues.";
275 300 Q_ASSERT(false);
276 301 }
277 302 }
278 303 }
279 304 }
280 305
281 306 return nullptr;
282 307 }
283 308
284 309 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
285 310 const QModelIndex &index,
286 311 QTreeView *treeView)
287 312 {
288 313 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
289 314 if (value) {
290 315 if (!hasChanges(validationIndex, treeView)) {
291 316 auto widget = CatalogueExplorerHelper::buildValidationWidget(
292 317 treeView,
293 318 [this, validationIndex, treeView]() {
294 319 setHasChanges(false, validationIndex, treeView);
295 320 },
296 321 [this, validationIndex, treeView]() {
297 322 setHasChanges(false, validationIndex, treeView);
298 323 });
299 324 treeView->setIndexWidget(validationIndex, widget);
300 325 }
301 326 }
302 327 else {
303 328 // Note: the widget is destroyed
304 329 treeView->setIndexWidget(validationIndex, nullptr);
305 330 }
306 331 }
307 332
308 333 bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index,
309 334 QTreeView *treeView)
310 335 {
311 336 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
312 337 return treeView->indexWidget(validationIndex) != nullptr;
313 338 }
@@ -1,59 +1,59
1 1 #include "Catalogue/CreateEventDialog.h"
2 2 #include "ui_CreateEventDialog.h"
3 3
4 4 #include <Catalogue/CatalogueController.h>
5 5 #include <SqpApplication.h>
6 6
7 7 #include <DBCatalogue.h>
8 8
9 9 struct CreateEventDialog::CreateEventDialogPrivate {
10 10 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
11 11 };
12 12
13 CreateEventDialog::CreateEventDialog(QWidget *parent)
13 CreateEventDialog::CreateEventDialog(const QVector<std::shared_ptr<DBCatalogue> > &catalogues,
14 QWidget *parent)
14 15 : QDialog(parent),
15 16 ui(new Ui::CreateEventDialog),
16 17 impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()}
17 18 {
18 19 ui->setupUi(this);
19 20
20 21 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
21 22 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
22 23
23 auto catalogues = sqpApp->catalogueController().retrieveCatalogues();
24 for (auto cat : catalogues) {
24 impl->m_DisplayedCatalogues = catalogues;
25 for (auto cat : impl->m_DisplayedCatalogues) {
25 26 ui->cbCatalogue->addItem(cat->getName());
26 impl->m_DisplayedCatalogues << cat;
27 27 }
28 28 }
29 29
30 30 CreateEventDialog::~CreateEventDialog()
31 31 {
32 32 delete ui;
33 33 }
34 34
35 35 void CreateEventDialog::hideCatalogueChoice()
36 36 {
37 37 ui->cbCatalogue->hide();
38 38 ui->lblCatalogue->hide();
39 39 }
40 40
41 41 QString CreateEventDialog::eventName() const
42 42 {
43 43 return ui->leEvent->text();
44 44 }
45 45
46 46 std::shared_ptr<DBCatalogue> CreateEventDialog::selectedCatalogue() const
47 47 {
48 48 auto catalogue = impl->m_DisplayedCatalogues.value(ui->cbCatalogue->currentIndex());
49 49 if (!catalogue || catalogue->getName() != catalogueName()) {
50 50 return nullptr;
51 51 }
52 52
53 53 return catalogue;
54 54 }
55 55
56 56 QString CreateEventDialog::catalogueName() const
57 57 {
58 58 return ui->cbCatalogue->currentText();
59 59 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

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