##// END OF EJS Templates
Adaptation to the shared pointers of catalogue controller
trabillard -
r1176:20294bb49a24
parent child
Show More
@@ -41,8 +41,7 public:
41 41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 43 std::list<std::shared_ptr<DBEvent> >
44 retrieveEventsFromCatalogue(const QString &repository,
45 std::shared_ptr<DBCatalogue> catalogue) const;
44 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
46 45 // void updateEvent(std::shared_ptr<DBEvent> event);
47 46 // void trashEvent(std::shared_ptr<DBEvent> event);
48 47 // void removeEvent(std::shared_ptr<DBEvent> event);
@@ -103,8 +103,7 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() co
103 103 }
104 104
105 105 std::list<std::shared_ptr<DBEvent> >
106 CatalogueController::retrieveEventsFromCatalogue(const QString &repository,
107 std::shared_ptr<DBCatalogue> catalogue) const
106 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
108 107 {
109 108 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
110 109 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
@@ -4,17 +4,17
4 4 #include <Common/spimpl.h>
5 5 #include <QAbstractTableModel>
6 6
7 #include <DBEvent.h>
7 class DBEvent;
8 8
9 9 class CatalogueEventsTableModel : public QAbstractTableModel {
10 10 public:
11 11 CatalogueEventsTableModel(QObject *parent = nullptr);
12 12
13 void setEvents(const QVector<DBEvent> &events);
14 DBEvent getEvent(int row) const;
13 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events);
14 std::shared_ptr<DBEvent> getEvent(int row) const;
15 15
16 void addEvent(const DBEvent &events);
17 void removeEvent(const DBEvent &events);
16 void addEvent(const std::shared_ptr<DBEvent> &events);
17 void removeEvent(const std::shared_ptr<DBEvent> &events);
18 18
19 19 // Model
20 20 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
@@ -19,7 +19,7 class CatalogueEventsWidget : public QWidget {
19 19 Q_OBJECT
20 20
21 21 signals:
22 void eventsSelected(const QVector<DBEvent> &event);
22 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
23 23
24 24 public:
25 25 explicit CatalogueEventsWidget(QWidget *parent = 0);
@@ -28,7 +28,7 public:
28 28 void setVisualizationWidget(VisualizationWidget *visualization);
29 29
30 30 public slots:
31 void populateWithCatalogues(const QVector<DBCatalogue> &catalogues);
31 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
32 32
33 33 private:
34 34 Ui::CatalogueEventsWidget *ui;
@@ -2,6 +2,7
2 2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
3 3
4 4 #include <QWidget>
5 #include <memory>
5 6
6 7 namespace Ui {
7 8 class CatalogueInspectorWidget;
@@ -22,8 +23,8 public:
22 23
23 24 Page currentPage() const;
24 25
25 void setEvent(const DBEvent &event);
26 void setCatalogue(const DBCatalogue &catalogue);
26 void setEvent(const std::shared_ptr<DBEvent> &event);
27 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
27 28
28 29 public slots:
29 30 void showPage(Page page);
@@ -5,7 +5,7
5 5 #include <QTreeWidgetItem>
6 6 #include <QWidget>
7 7
8 #include <DBCatalogue.h>
8 class DBCatalogue;
9 9
10 10 namespace Ui {
11 11 class CatalogueSideBarWidget;
@@ -15,7 +15,7 class CatalogueSideBarWidget : public QWidget {
15 15 Q_OBJECT
16 16
17 17 signals:
18 void catalogueSelected(const QVector<DBCatalogue> &catalogues);
18 void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
19 19 void databaseSelected(const QStringList &databases);
20 20 void allEventsSelected();
21 21 void trashSelected();
@@ -4,18 +4,19
4 4 #include <Common/spimpl.h>
5 5 #include <QTreeWidgetItem>
6 6
7 #include <DBCatalogue.h>
7 class DBCatalogue;
8 8
9 9
10 10 class CatalogueTreeWidgetItem : public QTreeWidgetItem {
11 11 public:
12 CatalogueTreeWidgetItem(DBCatalogue catalogue, int type = QTreeWidgetItem::Type);
12 CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue,
13 int type = QTreeWidgetItem::Type);
13 14
14 15 QVariant data(int column, int role) const override;
15 16 void setData(int column, int role, const QVariant &value) override;
16 17
17 18 /// Returns the catalogue represented by the item
18 DBCatalogue catalogue() const;
19 std::shared_ptr<DBCatalogue> catalogue() const;
19 20
20 21 void setHasChanges(bool value);
21 22
@@ -10,7 +10,7
10 10 #include <Time/TimeController.h>
11 11
12 12 struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate {
13 QVector<DBEvent> m_Events;
13 QVector<std::shared_ptr<DBEvent> > m_Events;
14 14
15 15 enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn };
16 16 QStringList columnNames()
@@ -18,20 +18,20 struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate {
18 18 return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")};
19 19 }
20 20
21 QVariant eventData(int col, const DBEvent &event) const
21 QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const
22 22 {
23 23 switch (static_cast<Column>(col)) {
24 24 case Column::Event:
25 return event.getName();
25 return event->getName();
26 26 case Column::TStart:
27 return DateUtils::dateTime(event.getTStart());
27 return DateUtils::dateTime(event->getTStart());
28 28 case Column::TEnd:
29 return DateUtils::dateTime(event.getTEnd());
29 return DateUtils::dateTime(event->getTEnd());
30 30 case Column::Product:
31 return event.getProduct();
31 return event->getProduct();
32 32 case Column::Tags: {
33 33 QString tagList;
34 auto tags = const_cast<DBEvent *>(&event)->getTags();
34 auto tags = event->getTags();
35 35 for (auto tag : tags) {
36 36 tagList += tag.getName();
37 37 tagList += ' ';
@@ -54,26 +54,26 CatalogueEventsTableModel::CatalogueEventsTableModel(QObject *parent)
54 54 {
55 55 }
56 56
57 void CatalogueEventsTableModel::setEvents(const QVector<DBEvent> &events)
57 void CatalogueEventsTableModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events)
58 58 {
59 59 beginResetModel();
60 60 impl->m_Events = events;
61 61 endResetModel();
62 62 }
63 63
64 DBEvent CatalogueEventsTableModel::getEvent(int row) const
64 std::shared_ptr<DBEvent> CatalogueEventsTableModel::getEvent(int row) const
65 65 {
66 66 return impl->m_Events.value(row);
67 67 }
68 68
69 void CatalogueEventsTableModel::addEvent(const DBEvent &events)
69 void CatalogueEventsTableModel::addEvent(const std::shared_ptr<DBEvent> &events)
70 70 {
71 71 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
72 72 // impl->m_Events.append(event); TODO
73 73 endInsertRows();
74 74 }
75 75
76 void CatalogueEventsTableModel::removeEvent(const DBEvent &events)
76 void CatalogueEventsTableModel::removeEvent(const std::shared_ptr<DBEvent> &events)
77 77 {
78 78 // TODO
79 79 auto index = -1; // impl->m_Events.indexOf(event);
@@ -155,7 +155,7 QMimeData *CatalogueEventsTableModel::mimeData(const QModelIndexList &indexes) c
155 155 {
156 156 auto mimeData = new QMimeData;
157 157
158 QVector<DBEvent> eventList;
158 QVector<std::shared_ptr<DBEvent> > eventList;
159 159
160 160 SqpRange firstTimeRange;
161 161 for (const auto &index : indexes) {
@@ -163,8 +163,8 QMimeData *CatalogueEventsTableModel::mimeData(const QModelIndexList &indexes) c
163 163 auto event = getEvent(index.row());
164 164 if (eventList.isEmpty()) {
165 165 // Gets the range of the first variable
166 firstTimeRange.m_TStart = event.getTStart();
167 firstTimeRange.m_TEnd = event.getTEnd();
166 firstTimeRange.m_TStart = event->getTStart();
167 firstTimeRange.m_TEnd = event->getTEnd();
168 168 }
169 169
170 170 eventList << event;
@@ -27,21 +27,21 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
27 27
28 28 VisualizationWidget *m_VisualizationWidget = nullptr;
29 29
30 void setEvents(const QVector<DBEvent> &events, QTableView *tableView)
30 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTableView *tableView)
31 31 {
32 32 tableView->setSortingEnabled(false);
33 33 m_Model->setEvents(events);
34 34 tableView->setSortingEnabled(true);
35 35 }
36 36
37 void addEvent(const DBEvent &event, QTableView *tableView)
37 void addEvent(const std::shared_ptr<DBEvent> &event, QTableView *tableView)
38 38 {
39 39 tableView->setSortingEnabled(false);
40 40 m_Model->addEvent(event);
41 41 tableView->setSortingEnabled(true);
42 42 }
43 43
44 void removeEvent(const DBEvent &event, QTableView *tableView)
44 void removeEvent(const std::shared_ptr<DBEvent> &event, QTableView *tableView)
45 45 {
46 46 tableView->setSortingEnabled(false);
47 47 m_Model->removeEvent(event);
@@ -143,8 +143,8 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
143 143 for (auto zoneName : m_ZonesForTimeMode) {
144 144 if (auto zone = tab->getZoneWithName(zoneName)) {
145 145 SqpRange eventRange;
146 eventRange.m_TStart = event.getTStart();
147 eventRange.m_TEnd = event.getTEnd();
146 eventRange.m_TStart = event->getTStart();
147 eventRange.m_TEnd = event->getTEnd();
148 148 zone->setZoneRange(eventRange);
149 149 }
150 150 }
@@ -232,7 +232,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
232 232 });
233 233
234 234 auto emitSelection = [this]() {
235 QVector<DBEvent> events;
235 QVector<std::shared_ptr<DBEvent> > events;
236 236 for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) {
237 237 events << impl->m_Model->getEvent(rowIndex.row());
238 238 }
@@ -271,19 +271,18 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualiz
271 271 impl->m_VisualizationWidget = visualization;
272 272 }
273 273
274 void CatalogueEventsWidget::populateWithCatalogues(const QVector<DBCatalogue> &catalogues)
274 void CatalogueEventsWidget::populateWithCatalogues(
275 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
275 276 {
276 auto &dao = sqpApp->catalogueController().getDao();
277
278 277 QSet<QUuid> eventIds;
279 QVector<DBEvent> events;
278 QVector<std::shared_ptr<DBEvent> > events;
280 279
281 280 for (auto catalogue : catalogues) {
282 auto catalogueEvents = dao.getCatalogueEvents(catalogue);
281 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
283 282 for (auto event : catalogueEvents) {
284 if (!eventIds.contains(event.getUniqId())) {
283 if (!eventIds.contains(event->getUniqId())) {
285 284 events << event;
286 eventIds.insert(event.getUniqId());
285 eventIds.insert(event->getUniqId());
287 286 }
288 287 }
289 288 }
@@ -28,15 +28,15 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
28 28 return static_cast<Page>(ui->stackedWidget->currentIndex());
29 29 }
30 30
31 void CatalogueInspectorWidget::setEvent(const DBEvent &event)
31 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
32 32 {
33 33 showPage(Page::EventProperties);
34 ui->leEventName->setText(event.getName());
35 ui->leEventMission->setText(event.getMission());
36 ui->leEventProduct->setText(event.getProduct());
34 ui->leEventName->setText(event->getName());
35 ui->leEventMission->setText(event->getMission());
36 ui->leEventProduct->setText(event->getProduct());
37 37
38 38 QString tagList;
39 auto tags = const_cast<DBEvent *>(&event)->getTags();
39 auto tags = event->getTags();
40 40 for (auto tag : tags) {
41 41 tagList += tag.getName();
42 42 tagList += ' ';
@@ -44,13 +44,13 void CatalogueInspectorWidget::setEvent(const DBEvent &event)
44 44
45 45 ui->leEventTags->setText(tagList);
46 46
47 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event.getTStart()));
48 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event.getTEnd()));
47 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
48 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
49 49 }
50 50
51 void CatalogueInspectorWidget::setCatalogue(const DBCatalogue &catalogue)
51 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
52 52 {
53 53 showPage(Page::CatalogueProperties);
54 ui->leCatalogueName->setText(catalogue.getName());
55 ui->leCatalogueAuthor->setText(catalogue.getAuthor());
54 ui->leCatalogueName->setText(catalogue->getName());
55 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
56 56 }
@@ -19,12 +19,11 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
19 19
20 20 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
21 21
22 QHash<QTreeWidgetItem *, DBCatalogue> m_CatalogueMap;
23
24 22 void configureTreeWidget(QTreeWidget *treeWidget);
25 23 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
26 24 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
27 void addCatalogueItem(const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem);
25 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
26 QTreeWidgetItem *parentDatabaseItem);
28 27 };
29 28
30 29 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
@@ -47,7 +46,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
47 46 emit this->selectionCleared();
48 47 }
49 48 else {
50 QVector<DBCatalogue> catalogues;
49 QVector<std::shared_ptr<DBCatalogue> > catalogues;
51 50 QStringList databases;
52 51 int selectionType = selectedItems.first()->type();
53 52
@@ -155,13 +154,9 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
155 154 treeWidget->addTopLevelItem(separatorItem);
156 155 treeWidget->setItemWidget(separatorItem, 0, separator);
157 156
158 auto &dao = sqpApp->catalogueController().getDao();
159 auto allPredicate = std::make_shared<ComparaisonPredicate>(QString{"uniqId"}, "-1",
160 ComparaisonOperation::DIFFERENT);
161
162 157 auto db = addDatabaseItem("Default", treeWidget);
163 158
164 auto catalogues = dao.getCatalogues(allPredicate);
159 auto catalogues = sqpApp->catalogueController().getCatalogues("Default");
165 160 for (auto catalogue : catalogues) {
166 161 addCatalogueItem(catalogue, db);
167 162 }
@@ -195,7 +190,7 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QSt
195 190 }
196 191
197 192 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
198 const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem)
193 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem)
199 194 {
200 195 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
201 196 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
@@ -2,6 +2,7
2 2
3 3 #include <memory>
4 4
5 #include <DBCatalogue.h>
5 6 #include <QBoxLayout>
6 7 #include <QToolButton>
7 8
@@ -9,13 +10,15 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
9 10
10 11 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
11 12
12 DBCatalogue m_Catalogue;
13 std::shared_ptr<DBCatalogue> m_Catalogue;
13 14
14 CatalogueTreeWidgetItemPrivate(DBCatalogue catalogue) : m_Catalogue(catalogue) {}
15 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
16 {
17 }
15 18 };
16 19
17 20
18 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(DBCatalogue catalogue, int type)
21 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
19 22 : QTreeWidgetItem(type),
20 23 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
21 24 {
@@ -28,7 +31,7 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
28 31 switch (role) {
29 32 case Qt::EditRole: // fallthrough
30 33 case Qt::DisplayRole:
31 return impl->m_Catalogue.getName();
34 return impl->m_Catalogue->getName();
32 35 default:
33 36 break;
34 37 }
@@ -41,9 +44,9 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &valu
41 44 {
42 45 if (role == Qt::EditRole && column == 0) {
43 46 auto newName = value.toString();
44 if (newName != impl->m_Catalogue.getName()) {
47 if (newName != impl->m_Catalogue->getName()) {
45 48 setText(0, newName);
46 impl->m_Catalogue.setName(newName);
49 impl->m_Catalogue->setName(newName);
47 50 setHasChanges(true);
48 51 }
49 52 }
@@ -52,7 +55,7 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &valu
52 55 }
53 56 }
54 57
55 DBCatalogue CatalogueTreeWidgetItem::catalogue() const
58 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
56 59 {
57 60 return impl->m_Catalogue;
58 61 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

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