##// END OF EJS Templates
Merge branch 'feature/CatalogueDevelop' into develop
perrinel -
r1301:73a314ea66d5 merge
parent child
Show More
@@ -0,0 +1,35
1 #ifndef SCIQLOP_CATALOGUEABSTRACTTREEITEM_H
2 #define SCIQLOP_CATALOGUEABSTRACTTREEITEM_H
3
4 #include <Common/spimpl.h>
5 #include <QVariant>
6 #include <QVector>
7
8 class QMimeData;
9
10 class CatalogueAbstractTreeItem {
11 public:
12 constexpr static const int DEFAULT_TYPE = -1;
13
14 CatalogueAbstractTreeItem(int type = DEFAULT_TYPE);
15 virtual ~CatalogueAbstractTreeItem();
16
17 void addChild(CatalogueAbstractTreeItem *child);
18 QVector<CatalogueAbstractTreeItem *> children() const;
19 CatalogueAbstractTreeItem *parent() const;
20
21 int type() const;
22 QString text(int column = 0) const;
23
24 virtual QVariant data(int column, int role) const;
25 virtual Qt::ItemFlags flags(int column) const;
26 virtual bool setData(int column, int role, const QVariant &value);
27 virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action);
28 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action);
29
30 private:
31 class CatalogueAbstractTreeItemPrivate;
32 spimpl::unique_impl_ptr<CatalogueAbstractTreeItemPrivate> impl;
33 };
34
35 #endif // SCIQLOP_CATALOGUEABSTRACTTREEITEM_H
@@ -0,0 +1,23
1 #ifndef SCIQLOP_CATALOGUETEXTTREEITEM_H
2 #define SCIQLOP_CATALOGUETEXTTREEITEM_H
3
4 #include <Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h>
5 #include <Common/spimpl.h>
6
7 class CatalogueTextTreeItem : public CatalogueAbstractTreeItem {
8 public:
9 CatalogueTextTreeItem(const QIcon &icon, const QString &text, int type);
10
11 QVariant data(int column, int role) const override;
12 Qt::ItemFlags flags(int column) const override;
13
14 QString text() const;
15
16 void setEnabled(bool value);
17
18 private:
19 class CatalogueTextTreeItemPrivate;
20 spimpl::unique_impl_ptr<CatalogueTextTreeItemPrivate> impl;
21 };
22
23 #endif // SCIQLOP_CATALOGUETEXTTREEITEM_H
@@ -0,0 +1,28
1 #ifndef SCIQLOP_CATALOGUETREEITEM_H
2 #define SCIQLOP_CATALOGUETREEITEM_H
3
4 #include <Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h>
5 #include <Common/spimpl.h>
6
7 class DBCatalogue;
8
9
10 class CatalogueTreeItem : public CatalogueAbstractTreeItem {
11 public:
12 CatalogueTreeItem(std::shared_ptr<DBCatalogue> catalogue, const QIcon &icon, int type);
13
14 QVariant data(int column, int role) const override;
15 bool setData(int column, int role, const QVariant &value) override;
16 Qt::ItemFlags flags(int column) const override;
17 bool canDropMimeData(const QMimeData *data, Qt::DropAction action) override;
18 bool dropMimeData(const QMimeData *data, Qt::DropAction action) override;
19
20 /// Returns the catalogue represented by the item
21 std::shared_ptr<DBCatalogue> catalogue() const;
22
23 private:
24 class CatalogueTreeItemPrivate;
25 spimpl::unique_impl_ptr<CatalogueTreeItemPrivate> impl;
26 };
27
28 #endif // SCIQLOP_CATALOGUETREEITEM_H
@@ -0,0 +1,56
1 #ifndef SCIQLOP_CATALOGUETREEMODEL_H
2 #define SCIQLOP_CATALOGUETREEMODEL_H
3
4 #include <Common/spimpl.h>
5 #include <QAbstractItemModel>
6
7 class CatalogueAbstractTreeItem;
8
9 /**
10 * @brief Model to display catalogue items based on QTreeWidgetItem
11 * @warning Do not use the method QTreeWidgetItem::treeWidget for an item added to this model or the
12 * application will crash
13 */
14 class CatalogueTreeModel : public QAbstractItemModel {
15 Q_OBJECT
16
17 signals:
18 void itemRenamed(const QModelIndex &index);
19 void itemDropped(const QModelIndex &parentIndex);
20
21 public:
22 CatalogueTreeModel(QObject *parent = nullptr);
23
24 enum class Column { Name, Validation, Count };
25
26 QModelIndex addTopLevelItem(CatalogueAbstractTreeItem *item);
27 QVector<CatalogueAbstractTreeItem *> topLevelItems() const;
28
29 void addChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex);
30
31 CatalogueAbstractTreeItem *item(const QModelIndex &index) const;
32 QModelIndex indexOf(CatalogueAbstractTreeItem *item, int column = 0) const;
33
34 // model
35 QModelIndex index(int row, int column,
36 const QModelIndex &parent = QModelIndex()) const override;
37 QModelIndex parent(const QModelIndex &index) const override;
38 int rowCount(const QModelIndex &parent) const override;
39 int columnCount(const QModelIndex &parent) const override;
40 Qt::ItemFlags flags(const QModelIndex &index) const override;
41 QVariant data(const QModelIndex &index, int role) const override;
42 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
43
44 bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
45 const QModelIndex &parent) const override;
46 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
47 const QModelIndex &parent) override;
48 Qt::DropActions supportedDropActions() const;
49 QStringList mimeTypes() const;
50
51 private:
52 class CatalogueTreeModelPrivate;
53 spimpl::unique_impl_ptr<CatalogueTreeModelPrivate> impl;
54 };
55
56 #endif // CATALOGUETREEMODEL_H
@@ -0,0 +1,81
1 #include "Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h"
2
3 struct CatalogueAbstractTreeItem::CatalogueAbstractTreeItemPrivate {
4 int m_Type;
5 QVector<CatalogueAbstractTreeItem *> m_Children;
6 CatalogueAbstractTreeItem *m_Parent = nullptr;
7
8 CatalogueAbstractTreeItemPrivate(int type) : m_Type(type) {}
9 };
10
11 CatalogueAbstractTreeItem::CatalogueAbstractTreeItem(int type)
12 : impl{spimpl::make_unique_impl<CatalogueAbstractTreeItemPrivate>(type)}
13 {
14 }
15
16 CatalogueAbstractTreeItem::~CatalogueAbstractTreeItem()
17 {
18 qDeleteAll(impl->m_Children);
19 }
20
21 void CatalogueAbstractTreeItem::addChild(CatalogueAbstractTreeItem *child)
22 {
23 impl->m_Children << child;
24 child->impl->m_Parent = this;
25 }
26
27 QVector<CatalogueAbstractTreeItem *> CatalogueAbstractTreeItem::children() const
28 {
29 return impl->m_Children;
30 }
31
32 CatalogueAbstractTreeItem *CatalogueAbstractTreeItem::parent() const
33 {
34 return impl->m_Parent;
35 }
36
37 int CatalogueAbstractTreeItem::type() const
38 {
39 return impl->m_Type;
40 }
41
42 QString CatalogueAbstractTreeItem::text(int column) const
43 {
44 return data(0, Qt::DisplayRole).toString();
45 }
46
47 QVariant CatalogueAbstractTreeItem::data(int column, int role) const
48 {
49 Q_UNUSED(column);
50 Q_UNUSED(role);
51 return QVariant();
52 }
53
54 Qt::ItemFlags CatalogueAbstractTreeItem::flags(int column) const
55 {
56 Q_UNUSED(column);
57 return Qt::NoItemFlags;
58 }
59
60 bool CatalogueAbstractTreeItem::setData(int column, int role, const QVariant &value)
61 {
62 Q_UNUSED(column);
63 Q_UNUSED(role);
64 Q_UNUSED(value);
65
66 return false;
67 }
68
69 bool CatalogueAbstractTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action)
70 {
71 Q_UNUSED(data);
72 Q_UNUSED(action);
73 return false;
74 }
75
76 bool CatalogueAbstractTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action)
77 {
78 Q_UNUSED(data);
79 Q_UNUSED(action);
80 return false;
81 }
@@ -0,0 +1,59
1 #include "Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h"
2
3 #include <QIcon>
4
5 struct CatalogueTextTreeItem::CatalogueTextTreeItemPrivate {
6
7 QString m_Text;
8 QIcon m_Icon;
9 bool m_IsEnabled = true;
10
11 CatalogueTextTreeItemPrivate(const QIcon &icon, const QString &text)
12 : m_Text(text), m_Icon(icon)
13 {
14 }
15 };
16
17
18 CatalogueTextTreeItem::CatalogueTextTreeItem(const QIcon &icon, const QString &text, int type)
19 : CatalogueAbstractTreeItem(type),
20 impl{spimpl::make_unique_impl<CatalogueTextTreeItemPrivate>(icon, text)}
21 {
22 }
23
24 QVariant CatalogueTextTreeItem::data(int column, int role) const
25 {
26 if (column > 0) {
27 return QVariant();
28 }
29
30 switch (role) {
31 case Qt::DisplayRole:
32 return impl->m_Text;
33 case Qt::DecorationRole:
34 return impl->m_Icon;
35 }
36
37 return QVariant();
38 }
39
40 Qt::ItemFlags CatalogueTextTreeItem::flags(int column) const
41 {
42 Q_UNUSED(column);
43
44 if (!impl->m_IsEnabled) {
45 return Qt::NoItemFlags;
46 }
47
48 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
49 }
50
51 QString CatalogueTextTreeItem::text() const
52 {
53 return impl->m_Text;
54 }
55
56 void CatalogueTextTreeItem::setEnabled(bool value)
57 {
58 impl->m_IsEnabled = value;
59 }
@@ -0,0 +1,201
1 #include "Catalogue/CatalogueTreeModel.h"
2 #include <Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h>
3
4 #include <QMimeData>
5 #include <memory>
6
7 #include <Common/MimeTypesDef.h>
8
9 struct CatalogueTreeModel::CatalogueTreeModelPrivate {
10 std::unique_ptr<CatalogueAbstractTreeItem> m_RootItem = nullptr;
11
12 CatalogueTreeModelPrivate() : m_RootItem{std::make_unique<CatalogueAbstractTreeItem>()} {}
13 };
14
15 CatalogueTreeModel::CatalogueTreeModel(QObject *parent)
16 : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueTreeModelPrivate>()}
17 {
18 }
19
20 QModelIndex CatalogueTreeModel::addTopLevelItem(CatalogueAbstractTreeItem *item)
21 {
22 auto nbTopLevelItems = impl->m_RootItem->children().count();
23 beginInsertRows(QModelIndex(), nbTopLevelItems, nbTopLevelItems);
24 impl->m_RootItem->addChild(item);
25 endInsertRows();
26
27 emit dataChanged(QModelIndex(), QModelIndex());
28
29 return index(nbTopLevelItems, 0);
30 }
31
32 QVector<CatalogueAbstractTreeItem *> CatalogueTreeModel::topLevelItems() const
33 {
34 return impl->m_RootItem->children();
35 }
36
37 void CatalogueTreeModel::addChildItem(CatalogueAbstractTreeItem *child,
38 const QModelIndex &parentIndex)
39 {
40 auto parentItem = item(parentIndex);
41 int c = parentItem->children().count();
42 beginInsertRows(parentIndex, c, c);
43 parentItem->addChild(child);
44 endInsertRows();
45
46 emit dataChanged(parentIndex, parentIndex);
47 }
48
49 CatalogueAbstractTreeItem *CatalogueTreeModel::item(const QModelIndex &index) const
50 {
51 return static_cast<CatalogueAbstractTreeItem *>(index.internalPointer());
52 }
53
54 QModelIndex CatalogueTreeModel::indexOf(CatalogueAbstractTreeItem *item, int column) const
55 {
56 auto parentItem = item->parent();
57 if (!parentItem) {
58 return QModelIndex();
59 }
60
61 auto row = parentItem->children().indexOf(item);
62 return createIndex(row, column, item);
63 }
64
65 QModelIndex CatalogueTreeModel::index(int row, int column, const QModelIndex &parent) const
66 {
67 if (column > 0) {
68 int a = 0;
69 }
70
71 if (!hasIndex(row, column, parent)) {
72 return QModelIndex();
73 }
74
75 CatalogueAbstractTreeItem *parentItem = nullptr;
76
77 if (!parent.isValid()) {
78 parentItem = impl->m_RootItem.get();
79 }
80 else {
81 parentItem = item(parent);
82 }
83
84 auto childItem = parentItem->children().value(row);
85 if (childItem) {
86 return createIndex(row, column, childItem);
87 }
88
89 return QModelIndex();
90 }
91
92
93 QModelIndex CatalogueTreeModel::parent(const QModelIndex &index) const
94 {
95 if (!index.isValid()) {
96 return QModelIndex();
97 }
98
99 auto childItem = item(index);
100 auto parentItem = childItem->parent();
101
102 if (parentItem == nullptr || parentItem->parent() == nullptr) {
103 return QModelIndex();
104 }
105
106 auto row = parentItem->parent()->children().indexOf(parentItem);
107 return createIndex(row, 0, parentItem);
108 }
109
110 int CatalogueTreeModel::rowCount(const QModelIndex &parent) const
111 {
112 CatalogueAbstractTreeItem *parentItem = nullptr;
113
114 if (!parent.isValid()) {
115 parentItem = impl->m_RootItem.get();
116 }
117 else {
118 parentItem = item(parent);
119 }
120
121 return parentItem->children().count();
122 }
123
124 int CatalogueTreeModel::columnCount(const QModelIndex &parent) const
125 {
126 return (int)Column::Count;
127 }
128
129 Qt::ItemFlags CatalogueTreeModel::flags(const QModelIndex &index) const
130 {
131 auto treeItem = item(index);
132 if (treeItem) {
133 return treeItem->flags(index.column());
134 }
135
136 return Qt::NoItemFlags;
137 }
138
139 QVariant CatalogueTreeModel::data(const QModelIndex &index, int role) const
140 {
141 auto treeItem = item(index);
142 if (treeItem) {
143 return treeItem->data(index.column(), role);
144 }
145
146 return QModelIndex();
147 }
148
149 bool CatalogueTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
150 {
151 auto treeItem = item(index);
152 if (treeItem) {
153 auto result = treeItem->setData(index.column(), role, value);
154
155 if (result && index.column() == (int)Column::Name) {
156 emit itemRenamed(index);
157 }
158
159 return result;
160 }
161
162 return false;
163 }
164 bool CatalogueTreeModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row,
165 int column, const QModelIndex &parent) const
166 {
167 auto draggedIndex = parent;
168 auto draggedItem = item(draggedIndex);
169 if (draggedItem) {
170 return draggedItem->canDropMimeData(data, action);
171 }
172
173 return false;
174 }
175
176 bool CatalogueTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
177 int column, const QModelIndex &parent)
178 {
179 bool result = false;
180
181 auto draggedIndex = parent;
182 auto draggedItem = item(draggedIndex);
183 if (draggedItem) {
184 result = draggedItem->dropMimeData(data, action);
185 if (result) {
186 emit itemDropped(draggedIndex);
187 }
188 }
189
190 return result;
191 }
192
193 Qt::DropActions CatalogueTreeModel::supportedDropActions() const
194 {
195 return Qt::CopyAction | Qt::MoveAction;
196 }
197
198 QStringList CatalogueTreeModel::mimeTypes() const
199 {
200 return {MIME_TYPE_EVENT_LIST};
201 }
@@ -52,6 +52,7 public slots:
52 52
53 53 protected:
54 54 void changeEvent(QEvent *e);
55 void closeEvent(QCloseEvent *event);
55 56
56 57 private:
57 58 std::unique_ptr<Ui::MainWindow> m_Ui;
@@ -49,10 +49,12 int main(int argc, char *argv[])
49 49 #endif
50 50 Q_INIT_RESOURCE(sqpguiresources);
51 51
52 SqpApplication a{argc, argv};
53 52 SqpApplication::setOrganizationName("LPP");
54 53 SqpApplication::setOrganizationDomain("lpp.fr");
55 54 SqpApplication::setApplicationName("SciQLop");
55
56 SqpApplication a{argc, argv};
57
56 58 MainWindow w;
57 59 w.show();
58 60
@@ -22,6 +22,7
22 22 #include "MainWindow.h"
23 23 #include "ui_MainWindow.h"
24 24
25 #include <Catalogue/CatalogueController.h>
25 26 #include <Catalogue/CatalogueExplorer.h>
26 27 #include <DataSource/DataSourceController.h>
27 28 #include <DataSource/DataSourceWidget.h>
@@ -36,9 +37,11
36 37 #include <Visualization/VisualizationController.h>
37 38
38 39 #include <QAction>
40 #include <QCloseEvent>
39 41 #include <QDate>
40 42 #include <QDir>
41 43 #include <QFileDialog>
44 #include <QMessageBox>
42 45 #include <QToolBar>
43 46 #include <QToolButton>
44 47 #include <memory.h>
@@ -74,6 +77,8 public:
74 77 SqpSettingsDialog *m_SettingsDialog;
75 78 /// Catalogue dialog. MainWindow has the ownership
76 79 CatalogueExplorer *m_CatalogExplorer;
80
81 bool checkDataToSave(QWidget *parentWidget);
77 82 };
78 83
79 84 MainWindow::MainWindow(QWidget *parent)
@@ -364,3 +369,37 void MainWindow::changeEvent(QEvent *e)
364 369 break;
365 370 }
366 371 }
372
373 void MainWindow::closeEvent(QCloseEvent *event)
374 {
375 if (!impl->checkDataToSave(this)) {
376 event->ignore();
377 }
378 else {
379 event->accept();
380 }
381 }
382
383 bool MainWindow::MainWindowPrivate::checkDataToSave(QWidget *parentWidget)
384 {
385 auto hasChanges = sqpApp->catalogueController().hasChanges();
386 if (hasChanges) {
387 // There are some unsaved changes
388 switch (QMessageBox::question(
389 parentWidget, "Save changes",
390 tr("The catalogue controller unsaved changes.\nDo you want to save them ?"),
391 QMessageBox::SaveAll | QMessageBox::Discard | QMessageBox::Cancel,
392 QMessageBox::SaveAll)) {
393 case QMessageBox::SaveAll:
394 sqpApp->catalogueController().saveAll();
395 break;
396 case QMessageBox::Discard:
397 break;
398 case QMessageBox::Cancel:
399 default:
400 return false;
401 }
402 }
403
404 return true;
405 }
@@ -15,6 +15,7
15 15
16 16 class DBCatalogue;
17 17 class DBEvent;
18 class DBEventProduct;
18 19
19 20 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20 21
@@ -44,10 +45,13 public:
44 45 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
45 46 void addEvent(std::shared_ptr<DBEvent> event);
46 47 void updateEvent(std::shared_ptr<DBEvent> event);
48 void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
47 49 void removeEvent(std::shared_ptr<DBEvent> event);
48 50 // void trashEvent(std::shared_ptr<DBEvent> event);
49 // void restore(QUuid eventId);
51 // void restore(std::shared_ptr<DBEvent> event);
50 52 void saveEvent(std::shared_ptr<DBEvent> event);
53 void discardEvent(std::shared_ptr<DBEvent> event);
54 bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
51 55
52 56 // Catalogue
53 57 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
@@ -59,15 +63,19 public:
59 63 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
60 64
61 65 void saveAll();
66 bool hasChanges() const;
67
68 /// Returns the MIME data associated to a list of variables
69 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
70
71 /// Returns the list of variables contained in a MIME data
72 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
62 73
63 74 public slots:
64 75 /// Manage init/end of the controller
65 76 void initialize();
66 void finalize();
67 77
68 78 private:
69 void waitForFinish();
70
71 79 class CatalogueControllerPrivate;
72 80 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
73 81 };
@@ -27,6 +27,8 public:
27 27 static const QString NAME_DATA_KEY;
28 28 /// Key associated with the plugin of the item
29 29 static const QString PLUGIN_DATA_KEY;
30 /// Key associated with a unique id of the plugin
31 static const QString ID_DATA_KEY;
30 32
31 33 explicit DataSourceItem(DataSourceItemType type, const QString &name);
32 34 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
@@ -12,6 +12,7
12 12 #include <DBTag.h>
13 13 #include <IRequestPredicate.h>
14 14
15 #include <QDataStream>
15 16 #include <QMutex>
16 17 #include <QThread>
17 18
@@ -22,8 +23,8 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
22 23
23 24 namespace {
24 25
25 static QString REPOSITORY_WORK_SUFFIX = QString{"work"};
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"trash"};
26 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
27 28 }
28 29
29 30 class CatalogueController::CatalogueControllerPrivate {
@@ -31,15 +32,22 class CatalogueController::CatalogueControllerPrivate {
31 32 public:
32 33 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33 34
34 QMutex m_WorkingMutex;
35 35 CatalogueDao m_CatalogueDao;
36 36
37 37 QStringList m_RepositoryList;
38 38 CatalogueController *m_Q;
39 39
40 QSet<QString> m_EventKeysWithChanges;
41
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
43
40 44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
41 45 QString toWorkRepository(QString repository);
42 46 QString toSyncRepository(QString repository);
47 void savAllDB();
48
49 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
50 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
43 51 };
44 52
45 53 CatalogueController::CatalogueController(QObject *parent)
@@ -53,7 +61,6 CatalogueController::~CatalogueController()
53 61 {
54 62 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
55 63 << QThread::currentThread();
56 this->waitForFinish();
57 64 }
58 65
59 66 QStringList CatalogueController::getRepositories() const
@@ -132,11 +139,19 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> ca
132 139
133 140 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
134 141 {
135 event->setRepository(impl->toSyncRepository(event->getRepository()));
142 event->setRepository(impl->toWorkRepository(event->getRepository()));
143
144 auto uniqueId = impl->eventUniqueKey(event);
145 impl->m_EventKeysWithChanges.insert(uniqueId);
136 146
137 147 impl->m_CatalogueDao.updateEvent(*event);
138 148 }
139 149
150 void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct)
151 {
152 impl->m_CatalogueDao.updateEventProduct(*eventProduct);
153 }
154
140 155 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
141 156 {
142 157 // Remove it from both repository and repository_work
@@ -144,24 +159,72 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
144 159 impl->m_CatalogueDao.removeEvent(*event);
145 160 event->setRepository(impl->toSyncRepository(event->getRepository()));
146 161 impl->m_CatalogueDao.removeEvent(*event);
162 impl->savAllDB();
147 163 }
148 164
149 165 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
150 166 {
151 167 event->setRepository(impl->toWorkRepository(event->getRepository()));
152 168
153 impl->m_CatalogueDao.addEvent(*event);
169 auto eventTemp = *event;
170 impl->m_CatalogueDao.addEvent(eventTemp);
154 171
155 172 // Call update is necessary at the creation of add Event if it has some tags or some event
156 173 // products
157 174 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
158 impl->m_CatalogueDao.updateEvent(*event);
175
176 auto eventProductsTemp = eventTemp.getEventProducts();
177 auto eventProductTempUpdated = std::list<DBEventProduct>{};
178 for (auto eventProductTemp : eventProductsTemp) {
179 eventProductTemp.setEvent(eventTemp);
180 eventProductTempUpdated.push_back(eventProductTemp);
181 }
182 eventTemp.setEventProducts(eventProductTempUpdated);
183
184 impl->m_CatalogueDao.updateEvent(eventTemp);
159 185 }
160 186 }
161 187
162 188 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
163 189 {
164 impl->m_CatalogueDao.moveEvent(*event, impl->toSyncRepository(event->getRepository()), true);
190 impl->saveEvent(event, true);
191 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
192 }
193
194 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event)
195 {
196 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
197 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
198
199 auto syncRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
200 QString{"repository"}, impl->toSyncRepository(event->getRepository()),
201 ComparaisonOperation::EQUALEQUAL);
202
203 auto syncPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
204 syncPred->AddRequestPredicate(uniqIdPredicate);
205 syncPred->AddRequestPredicate(syncRepositoryPredicate);
206
207
208 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
209 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
210 ComparaisonOperation::EQUALEQUAL);
211
212 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
213 workPred->AddRequestPredicate(uniqIdPredicate);
214 workPred->AddRequestPredicate(workRepositoryPredicate);
215
216
217 auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
218 impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()), true);
219
220 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
221 *event = workEvent;
222 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
223 }
224
225 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
226 {
227 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
165 228 }
166 229
167 230 std::list<std::shared_ptr<DBCatalogue> >
@@ -179,7 +242,7 CatalogueController::retrieveCatalogues(const QString &repository) const
179 242
180 243 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
181 244 {
182 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
245 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
183 246
184 247 impl->m_CatalogueDao.updateCatalogue(*catalogue);
185 248 }
@@ -195,8 +258,7 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue
195 258
196 259 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
197 260 {
198 impl->m_CatalogueDao.moveCatalogue(*catalogue,
199 impl->toSyncRepository(catalogue->getRepository()), true);
261 impl->saveCatalogue(catalogue, true);
200 262 }
201 263
202 264 void CatalogueController::saveAll()
@@ -205,22 +267,70 void CatalogueController::saveAll()
205 267 // Save Event
206 268 auto events = this->retrieveEvents(repository);
207 269 for (auto event : events) {
208 this->saveEvent(event);
270 impl->saveEvent(event, false);
209 271 }
210 272
211 273 // Save Catalogue
212 274 auto catalogues = this->retrieveCatalogues(repository);
213 275 for (auto catalogue : catalogues) {
214 this->saveCatalogue(catalogue);
276 impl->saveCatalogue(catalogue, false);
277 }
278 }
279
280 impl->savAllDB();
281 impl->m_EventKeysWithChanges.clear();
282 }
283
284 bool CatalogueController::hasChanges() const
285 {
286 return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues
287 }
288
289 QByteArray
290 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
291 {
292 auto encodedData = QByteArray{};
293
294 QMap<QString, QVariantList> idsPerRepository;
295 for (auto event : events) {
296 idsPerRepository[event->getRepository()] << event->getUniqId();
297 }
298
299 QDataStream stream{&encodedData, QIODevice::WriteOnly};
300 stream << idsPerRepository;
301
302 return encodedData;
303 }
304
305 QVector<std::shared_ptr<DBEvent> >
306 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
307 {
308 auto events = QVector<std::shared_ptr<DBEvent> >{};
309 QDataStream stream{mimeData};
310
311 QMap<QString, QVariantList> idsPerRepository;
312 stream >> idsPerRepository;
313
314 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
315 auto repository = it.key();
316 auto allRepositoryEvent = retrieveEvents(repository);
317 for (auto uuid : it.value()) {
318 for (auto repositoryEvent : allRepositoryEvent) {
319 if (uuid.toUuid() == repositoryEvent->getUniqId()) {
320 events << repositoryEvent;
321 }
322 }
215 323 }
216 324 }
325
326 return events;
217 327 }
218 328
219 329 void CatalogueController::initialize()
220 330 {
221 331 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
222 332 << QThread::currentThread();
223 impl->m_WorkingMutex.lock();
333
224 334 impl->m_CatalogueDao.initialize();
225 335 auto defaultRepositoryLocation
226 336 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
@@ -242,37 +352,24 void CatalogueController::initialize()
242 352 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
243 353 }
244 354
245 void CatalogueController::finalize()
246 {
247 impl->m_WorkingMutex.unlock();
248 }
249
250 void CatalogueController::waitForFinish()
355 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
356 const std::shared_ptr<DBEvent> &event) const
251 357 {
252 QMutexLocker locker{&impl->m_WorkingMutex};
358 return event->getUniqId().toString().append(event->getRepository());
253 359 }
254 360
255 361 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
256 362 const QString &dbTo)
257 363 {
258 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
364 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
259 365 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
366 auto events = m_CatalogueDao.getEvents(dbFrom);
260 367 for (auto catalogue : catalogues) {
261 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
368 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
262 369 }
263 370
264 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
265 auto events = m_CatalogueDao.getEvents(dbFrom);
266 371 for (auto event : events) {
267 eventsShared.push_back(std::make_shared<DBEvent>(event));
268 }
269
270 for (auto catalogue : cataloguesShared) {
271 m_CatalogueDao.copyCatalogue(*catalogue, dbTo, true);
272 }
273
274 for (auto event : eventsShared) {
275 m_CatalogueDao.copyEvent(*event, dbTo, true);
372 m_CatalogueDao.copyEvent(event, dbTo, true);
276 373 }
277 374 }
278 375
@@ -280,7 +377,7 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QStrin
280 377 {
281 378 auto syncRepository = toSyncRepository(repository);
282 379
283 return QString("%1_%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
380 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
284 381 }
285 382
286 383 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
@@ -294,3 +391,30 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QStrin
294 391 }
295 392 return syncRepository;
296 393 }
394
395 void CatalogueController::CatalogueControllerPrivate::savAllDB()
396 {
397 for (auto repository : m_RepositoryList) {
398 auto defaultRepositoryLocation
399 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
400 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
401 }
402 }
403
404 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
405 bool persist)
406 {
407 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
408 if (persist) {
409 savAllDB();
410 }
411 }
412
413 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
414 std::shared_ptr<DBCatalogue> catalogue, bool persist)
415 {
416 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
417 if (persist) {
418 savAllDB();
419 }
420 }
@@ -6,6 +6,7
6 6
7 7 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
8 8 const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin");
9 const QString DataSourceItem::ID_DATA_KEY = QStringLiteral("uuid");
9 10
10 11 struct DataSourceItem::DataSourceItemPrivate {
11 12 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
@@ -3,9 +3,11
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
@@ -34,7 +34,7 public:
34 34 std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const;
35 35
36 36 /// Refresh the data for the specified event
37 void refreshEvent(const std::shared_ptr<DBEvent> &event);
37 void refreshEvent(const std::shared_ptr<DBEvent> &event, bool refreshEventProducts = false);
38 38
39 39 /// Returns a QModelIndex which represent the specified event
40 40 QModelIndex indexOf(const std::shared_ptr<DBEvent> &event) const;
@@ -32,17 +32,27 public:
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 clear();
46 void refresh();
40 47
41 48 private:
42 49 Ui::CatalogueEventsWidget *ui;
43 50
44 51 class CatalogueEventsWidgetPrivate;
45 52 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
53
54 private slots:
55 void emitSelection();
46 56 };
47 57
48 58 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
@@ -8,6 +8,9 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 {
@@ -19,6 +22,9 public:
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
@@ -28,8 +28,11 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
@@ -15,7 +15,8 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();
@@ -27,7 +27,8 gui_moc_headers = [
27 27 'include/Catalogue/CatalogueSideBarWidget.h',
28 28 'include/Catalogue/CatalogueInspectorWidget.h',
29 29 'include/Catalogue/CatalogueEventsModel.h',
30 'include/Catalogue/CreateEventDialog.h'
30 'include/Catalogue/CreateEventDialog.h',
31 'include/Catalogue/CatalogueTreeModel.h'
31 32 ]
32 33
33 34 gui_ui_files = [
@@ -118,11 +119,14 gui_sources = [
118 119 'src/Catalogue/CatalogueEventsWidget.cpp',
119 120 'src/Catalogue/CatalogueSideBarWidget.cpp',
120 121 'src/Catalogue/CatalogueInspectorWidget.cpp',
121 'src/Catalogue/CatalogueTreeWidgetItem.cpp',
122 'src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp',
123 'src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp',
124 'src/Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.cpp',
122 125 'src/Catalogue/CatalogueEventsModel.cpp',
123 126 'src/Catalogue/CatalogueExplorerHelper.cpp',
124 127 'src/Catalogue/CatalogueActionManager.cpp',
125 'src/Catalogue/CreateEventDialog.cpp'
128 'src/Catalogue/CreateEventDialog.cpp',
129 'src/Catalogue/CatalogueTreeModel.cpp'
126 130 ]
127 131
128 132 gui_inc = include_directories(['include'])
@@ -2,13 +2,18
2 2
3 3 #include <Actions/ActionsGuiController.h>
4 4 #include <Catalogue/CatalogueController.h>
5 #include <DataSource/DataSourceItem.h>
5 6 #include <SqpApplication.h>
6 7 #include <Variable/Variable.h>
7 8 #include <Visualization/VisualizationGraphWidget.h>
8 9 #include <Visualization/VisualizationSelectionZoneItem.h>
9 10
11 #include <Catalogue/CatalogueEventsWidget.h>
12 #include <Catalogue/CatalogueExplorer.h>
13 #include <Catalogue/CatalogueSideBarWidget.h>
10 14 #include <Catalogue/CreateEventDialog.h>
11 15
16 #include <CatalogueDao.h>
12 17 #include <DBCatalogue.h>
13 18 #include <DBEvent.h>
14 19 #include <DBEventProduct.h>
@@ -21,6 +26,14
21 26 #include <memory>
22 27
23 28 struct CatalogueActionManager::CatalogueActionManagerPrivate {
29
30 CatalogueExplorer *m_CatalogueExplorer = nullptr;
31
32 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
33 : m_CatalogueExplorer(catalogueExplorer)
34 {
35 }
36
24 37 void createEventFromZones(const QString &eventName,
25 38 const QVector<VisualizationSelectionZoneItem *> &zones,
26 39 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
@@ -39,7 +52,8 struct CatalogueActionManager::CatalogueActionManagerPrivate {
39 52 eventProduct->setTStart(zoneRange.m_TStart);
40 53 eventProduct->setTEnd(zoneRange.m_TEnd);
41 54
42 eventProduct->setProductId(var->metadata().value("id", "TODO").toString()); // todo
55 eventProduct->setProductId(
56 var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString());
43 57
44 58 productList.push_back(*eventProduct);
45 59 }
@@ -49,15 +63,25 struct CatalogueActionManager::CatalogueActionManagerPrivate {
49 63
50 64 sqpApp->catalogueController().addEvent(event);
51 65
66
52 67 if (catalogue) {
53 68 // TODO
54 69 // catalogue->addEvent(event);
70 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
71 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
72 m_CatalogueExplorer->eventsWidget().addEvent(event);
73 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
74 }
75 }
76 else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) {
77 m_CatalogueExplorer->eventsWidget().addEvent(event);
78 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
55 79 }
56 80 }
57 81 };
58 82
59 CatalogueActionManager::CatalogueActionManager()
60 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>()}
83 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
84 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
61 85 {
62 86 }
63 87
@@ -82,7 +106,8 void CatalogueActionManager::installSelectionZoneActions()
82 106
83 107 auto createEventAction = actionController.addSectionZoneAction(
84 108 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
85 CreateEventDialog dialog;
109 CreateEventDialog dialog(
110 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
86 111 dialog.hideCatalogueChoice();
87 112 if (dialog.exec() == QDialog::Accepted) {
88 113 impl->createEventFromZones(dialog.eventName(), zones);
@@ -92,12 +117,16 void CatalogueActionManager::installSelectionZoneActions()
92 117
93 118 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
94 119 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
95 CreateEventDialog dialog;
120 CreateEventDialog dialog(
121 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
96 122 if (dialog.exec() == QDialog::Accepted) {
97 123 auto selectedCatalogue = dialog.selectedCatalogue();
98 124 if (!selectedCatalogue) {
99 125 selectedCatalogue = std::make_shared<DBCatalogue>();
100 126 selectedCatalogue->setName(dialog.catalogueName());
127 // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO
128 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
129 REPOSITORY_DEFAULT);
101 130 }
102 131
103 132 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
@@ -1,5 +1,6
1 1 #include "Catalogue/CatalogueEventsModel.h"
2 2
3 #include <Catalogue/CatalogueController.h>
3 4 #include <Common/DateUtils.h>
4 5 #include <Common/MimeTypesDef.h>
5 6 #include <DBEvent.h>
@@ -23,7 +24,6 const auto EVENT_PRODUCT_ITEM_TYPE = 2;
23 24 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
24 25 QVector<std::shared_ptr<DBEvent> > m_Events;
25 26 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
26 std::unordered_set<std::shared_ptr<DBEvent> > m_EventsWithChanges;
27 27
28 28 QStringList columnNames()
29 29 {
@@ -34,8 +34,8 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
34 34 QVariant sortData(int col, const std::shared_ptr<DBEvent> &event) const
35 35 {
36 36 if (col == (int)CatalogueEventsModel::Column::Validation) {
37 return m_EventsWithChanges.find(event) != m_EventsWithChanges.cend() ? true
38 : QVariant();
37 auto hasChanges = sqpApp->catalogueController().eventHasChanges(event);
38 return hasChanges ? true : QVariant();
39 39 }
40 40
41 41 return eventData(col, event);
@@ -114,6 +114,14 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
114 114 Q_ASSERT(false);
115 115 return QStringLiteral("Unknown Data");
116 116 }
117
118 void refreshChildrenOfIndex(CatalogueEventsModel *model, const QModelIndex &index) const
119 {
120 auto childCount = model->rowCount(index);
121 auto colCount = model->columnCount();
122 emit model->dataChanged(model->index(0, 0, index),
123 model->index(childCount, colCount, index));
124 }
117 125 };
118 126
119 127 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
@@ -127,7 +135,6 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &e
127 135
128 136 impl->m_Events = events;
129 137 impl->m_EventProducts.clear();
130 impl->m_EventsWithChanges.clear();
131 138 for (auto event : events) {
132 139 impl->parseEventProduct(event);
133 140 }
@@ -169,10 +176,14 CatalogueEventsModel::getEventProduct(const QModelIndex &index) const
169 176
170 177 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
171 178 {
172 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
179 beginInsertRows(QModelIndex(), impl->m_Events.count(), impl->m_Events.count());
173 180 impl->m_Events.append(event);
174 181 impl->parseEventProduct(event);
175 182 endInsertRows();
183
184 // Also refreshes its children event products
185 auto eventIndex = index(impl->m_Events.count(), 0);
186 impl->refreshChildrenOfIndex(this, eventIndex);
176 187 }
177 188
178 189 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
@@ -182,7 +193,6 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
182 193 beginRemoveRows(QModelIndex(), index, index);
183 194 impl->m_Events.removeAt(index);
184 195 impl->m_EventProducts.erase(event.get());
185 impl->m_EventsWithChanges.erase(event);
186 196 endRemoveRows();
187 197 }
188 198 }
@@ -192,18 +202,41 QVector<std::shared_ptr<DBEvent> > CatalogueEventsModel::events() const
192 202 return impl->m_Events;
193 203 }
194 204
195 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event)
205 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event,
206 bool refreshEventProducts)
196 207 {
197 208 auto eventIndex = indexOf(event);
198 209 if (eventIndex.isValid()) {
199 210
211 if (refreshEventProducts) {
212 // Reparse the associated event products
213
214 auto nbEventProducts = impl->nbEventProducts(event);
215 auto newNbOfEventProducts = event->getEventProducts().size();
216 if (newNbOfEventProducts < nbEventProducts) {
217 beginRemoveRows(eventIndex, newNbOfEventProducts, nbEventProducts - 1);
218 impl->m_EventProducts.erase(event.get());
219 impl->parseEventProduct(event);
220 endRemoveRows();
221 }
222 else if (newNbOfEventProducts > nbEventProducts) {
223 beginInsertRows(eventIndex, nbEventProducts, newNbOfEventProducts - 1);
224 impl->m_EventProducts.erase(event.get());
225 impl->parseEventProduct(event);
226 endInsertRows();
227 }
228 else { // newNbOfEventProducts == nbEventProducts
229 impl->m_EventProducts.erase(event.get());
230 impl->parseEventProduct(event);
231 }
232 }
233
200 234 // Refreshes the event line
201 235 auto colCount = columnCount();
202 236 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
203 237
204 238 // Also refreshes its children event products
205 auto childCount = rowCount(eventIndex);
206 emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex));
239 impl->refreshChildrenOfIndex(this, eventIndex);
207 240 }
208 241 else {
209 242 qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found.";
@@ -220,22 +253,6 QModelIndex CatalogueEventsModel::indexOf(const std::shared_ptr<DBEvent> &event)
220 253 return QModelIndex();
221 254 }
222 255
223 void CatalogueEventsModel::setEventHasChanges(const std::shared_ptr<DBEvent> &event,
224 bool hasChanges)
225 {
226 if (hasChanges) {
227 impl->m_EventsWithChanges.insert(event);
228 }
229 else {
230 impl->m_EventsWithChanges.erase(event);
231 }
232 }
233
234 bool CatalogueEventsModel::eventsHasChanges(const std::shared_ptr<DBEvent> &event) const
235 {
236 return impl->m_EventsWithChanges.find(event) != impl->m_EventsWithChanges.cend();
237 }
238
239 256 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
240 257 {
241 258 if (!hasIndex(row, column, parent)) {
@@ -354,6 +371,7 QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientati
354 371
355 372 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
356 373 {
374 beginResetModel();
357 375 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
358 376 [this, column, order](auto e1, auto e2) {
359 377 auto data1 = impl->sortData(column, e1);
@@ -364,13 +382,13 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
364 382 return order == Qt::AscendingOrder ? result : !result;
365 383 });
366 384
367 emit dataChanged(QModelIndex(), QModelIndex());
385 endResetModel();
368 386 emit modelSorted();
369 387 }
370 388
371 389 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
372 390 {
373 return Qt::CopyAction | Qt::MoveAction;
391 return Qt::CopyAction;
374 392 }
375 393
376 394 QStringList CatalogueEventsModel::mimeTypes() const
@@ -415,9 +433,10 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
415 433 }
416 434 }
417 435
418 auto eventsEncodedData
419 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
420 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
436 if (!eventList.isEmpty() && eventProductList.isEmpty()) {
437 auto eventsEncodedData = sqpApp->catalogueController().mimeDataForEvents(eventList);
438 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
439 }
421 440
422 441 if (eventList.count() + eventProductList.count() == 1) {
423 442 // No time range MIME data if multiple events are dragged
@@ -14,6 +14,7
14 14 #include <QDialog>
15 15 #include <QDialogButtonBox>
16 16 #include <QListWidget>
17 #include <QMessageBox>
17 18
18 19 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19 20
@@ -25,14 +26,22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
25 26 CatalogueEventsModel *m_Model = nullptr;
26 27 QStringList m_ZonesForTimeMode;
27 28 QString m_ZoneForGraphMode;
29 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
28 30
29 31 VisualizationWidget *m_VisualizationWidget = nullptr;
30 32
31 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
33 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
32 34 {
33 treeView->setSortingEnabled(false);
35 widget->ui->treeView->setSortingEnabled(false);
34 36 m_Model->setEvents(events);
35 treeView->setSortingEnabled(true);
37 widget->ui->treeView->setSortingEnabled(true);
38
39 for (auto event : events) {
40 if (sqpApp->catalogueController().eventHasChanges(event)) {
41 auto index = m_Model->indexOf(event);
42 widget->setEventChanges(event, true);
43 }
44 }
36 45 }
37 46
38 47 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
@@ -195,6 +204,22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
195 204 << "updateGraphMode: not compatible with multiple events selected";
196 205 }
197 206 }
207
208 void getSelectedItems(
209 QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events,
210 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts)
211 {
212 for (auto rowIndex : treeView->selectionModel()->selectedRows()) {
213 auto itemType = m_Model->itemTypeOf(rowIndex);
214 if (itemType == CatalogueEventsModel::ItemType::Event) {
215 events << m_Model->getEvent(rowIndex);
216 }
217 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
218 eventProducts << qMakePair(m_Model->getParentEvent(rowIndex),
219 m_Model->getEventProduct(rowIndex));
220 }
221 }
222 }
198 223 };
199 224
200 225 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
@@ -234,36 +259,32 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
234 259 }
235 260 });
236 261
237 auto emitSelection = [this]() {
262 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
238 263 QVector<std::shared_ptr<DBEvent> > events;
239 264 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
265 impl->getSelectedItems(ui->treeView, events, eventProducts);
240 266
241 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
267 if (!events.isEmpty() && eventProducts.isEmpty()) {
242 268
243 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
244 if (itemType == CatalogueEventsModel::ItemType::Event) {
245 events << impl->m_Model->getEvent(rowIndex);
246 }
247 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
248 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
249 impl->m_Model->getEventProduct(rowIndex));
250 }
251 }
269 if (QMessageBox::warning(this, tr("Remove Event(s)"),
270 tr("The selected event(s) will be completly removed "
271 "from the repository!\nAre you sure you want to continue?"),
272 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
273 == QMessageBox::Yes) {
252 274
253 if (!events.isEmpty() && eventProducts.isEmpty()) {
254 emit this->eventsSelected(events);
255 }
256 else if (events.isEmpty() && !eventProducts.isEmpty()) {
257 emit this->eventProductsSelected(eventProducts);
258 }
259 else {
260 emit this->selectionCleared();
275 for (auto event : events) {
276 sqpApp->catalogueController().removeEvent(event);
277 impl->removeEvent(event, ui->treeView);
278 }
279 }
261 280 }
262 };
281 });
263 282
264 connect(ui->treeView, &QTreeView::clicked, emitSelection);
265 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
283 connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection);
284 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
285 &CatalogueEventsWidget::emitSelection);
266 286
287 ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected
267 288 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
268 289 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
269 290 ui->btnChart->setEnabled(isNotMultiSelection);
@@ -275,13 +296,20 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
275 296 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
276 297 impl->updateForGraphMode(ui->treeView);
277 298 }
299
300 QVector<std::shared_ptr<DBEvent> > events;
301 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
302 impl->getSelectedItems(ui->treeView, events, eventProducts);
303 ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty());
278 304 });
279 305
280 306 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
281 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
307 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags,
282 308 QHeaderView::Stretch);
283 309 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
284 310 QHeaderView::Fixed);
311 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
312 QHeaderView::Interactive);
285 313 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
286 314 VALIDATION_COLUMN_SIZE);
287 315 ui->treeView->header()->setSortIndicatorShown(true);
@@ -289,9 +317,11 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
289 317 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
290 318 auto allEvents = impl->m_Model->events();
291 319 for (auto event : allEvents) {
292 setEventChanges(event, impl->m_Model->eventsHasChanges(event));
320 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
293 321 }
294 322 });
323
324 populateWithAllEvents();
295 325 }
296 326
297 327 CatalogueEventsWidget::~CatalogueEventsWidget()
@@ -304,6 +334,11 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualiz
304 334 impl->m_VisualizationWidget = visualization;
305 335 }
306 336
337 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
338 {
339 impl->addEvent(event, ui->treeView);
340 }
341
307 342 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
308 343 {
309 344 impl->m_Model->refreshEvent(event);
@@ -312,25 +347,55 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &even
312 347 auto validationIndex
313 348 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
314 349
315 if (hasChanges) {
316 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
318 ui->treeView, [this, event]() { setEventChanges(event, false); },
319 [this, event]() { setEventChanges(event, false); });
320 ui->treeView->setIndexWidget(validationIndex, widget);
350 if (validationIndex.isValid()) {
351 if (hasChanges) {
352 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
353 auto widget = CatalogueExplorerHelper::buildValidationWidget(
354 ui->treeView,
355 [this, event]() {
356 sqpApp->catalogueController().saveEvent(event);
357 setEventChanges(event, false);
358 },
359 [this, event]() {
360 sqpApp->catalogueController().discardEvent(event);
361 setEventChanges(event, false);
362 impl->m_Model->refreshEvent(event, true);
363 emitSelection();
364 });
365 ui->treeView->setIndexWidget(validationIndex, widget);
366 }
367 }
368 else {
369 // Note: the widget is destroyed
370 ui->treeView->setIndexWidget(validationIndex, nullptr);
321 371 }
322 372 }
323 373 else {
324 // Note: the widget is destroyed
325 ui->treeView->setIndexWidget(validationIndex, nullptr);
374 qCWarning(LOG_CatalogueEventsWidget())
375 << "setEventChanges: the event is not displayed in the model.";
326 376 }
377 }
327 378
328 impl->m_Model->setEventHasChanges(event, hasChanges);
379 QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
380 {
381 return impl->m_DisplayedCatalogues;
382 }
383
384 bool CatalogueEventsWidget::isAllEventsDisplayed() const
385 {
386 return impl->m_DisplayedCatalogues.isEmpty() && !impl->m_Model->events().isEmpty();
387 }
388
389 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
390 {
391 return impl->m_Model->indexOf(event).isValid();
329 392 }
330 393
331 394 void CatalogueEventsWidget::populateWithCatalogues(
332 395 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
333 396 {
397 impl->m_DisplayedCatalogues = catalogues;
398
334 399 QSet<QUuid> eventIds;
335 400 QVector<std::shared_ptr<DBEvent> > events;
336 401
@@ -344,11 +409,13 void CatalogueEventsWidget::populateWithCatalogues(
344 409 }
345 410 }
346 411
347 impl->setEvents(events, ui->treeView);
412 impl->setEvents(events, this);
348 413 }
349 414
350 415 void CatalogueEventsWidget::populateWithAllEvents()
351 416 {
417 impl->m_DisplayedCatalogues.clear();
418
352 419 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
353 420
354 421 QVector<std::shared_ptr<DBEvent> > events;
@@ -356,5 +423,38 void CatalogueEventsWidget::populateWithAllEvents()
356 423 events << event;
357 424 }
358 425
359 impl->setEvents(events, ui->treeView);
426 impl->setEvents(events, this);
427 }
428
429 void CatalogueEventsWidget::clear()
430 {
431 impl->m_DisplayedCatalogues.clear();
432 impl->setEvents({}, this);
433 }
434
435 void CatalogueEventsWidget::refresh()
436 {
437 if (impl->m_DisplayedCatalogues.isEmpty()) {
438 populateWithAllEvents();
439 }
440 else {
441 populateWithCatalogues(impl->m_DisplayedCatalogues);
442 }
443 }
444
445 void CatalogueEventsWidget::emitSelection()
446 {
447 QVector<std::shared_ptr<DBEvent> > events;
448 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
449 impl->getSelectedItems(ui->treeView, events, eventProducts);
450
451 if (!events.isEmpty() && eventProducts.isEmpty()) {
452 emit eventsSelected(events);
453 }
454 else if (events.isEmpty() && !eventProducts.isEmpty()) {
455 emit eventProductsSelected(eventProducts);
456 }
457 else {
458 emit selectionCleared();
459 }
360 460 }
@@ -11,12 +11,17
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
@@ -37,16 +42,29 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
37 42 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
38 43 });
39 44
40 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
41 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
45 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, [this]() {
46 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
47 ui->events->clear();
48 });
42 49
43 50 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
44 51 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
45 52 ui->events->populateWithAllEvents();
46 53 });
47 54
48 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
49 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
55 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databaseList) {
56 QVector<std::shared_ptr<DBCatalogue> > catalogueList;
57 for (auto database : databaseList) {
58 catalogueList.append(ui->catalogues->getCatalogues(database));
59 }
60 ui->events->populateWithCatalogues(catalogueList);
61 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
62 });
63
64 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, [this]() {
65 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
66 ui->events->clear();
67 });
50 68
51 69 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
52 70 if (events.count() == 1) {
@@ -81,7 +99,10 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
81 99 });
82 100
83 101 connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated,
84 [this](auto event, auto eventProduct) { ui->events->setEventChanges(event, true); });
102 [this](auto event, auto eventProduct) {
103 sqpApp->catalogueController().updateEventProduct(eventProduct);
104 ui->events->setEventChanges(event, true);
105 });
85 106 }
86 107
87 108 CatalogueExplorer::~CatalogueExplorer()
@@ -93,3 +114,13 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualizatio
93 114 {
94 115 ui->events->setVisualizationWidget(visualization);
95 116 }
117
118 CatalogueEventsWidget &CatalogueExplorer::eventsWidget() const
119 {
120 return *ui->events;
121 }
122
123 CatalogueSideBarWidget &CatalogueExplorer::sideBarWidget() const
124 {
125 return *ui->catalogues;
126 }
@@ -78,8 +78,18 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpda
78 78
79 79 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
80 80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
81 auto oldProductId = m_DisplayedEventProduct->getProductId();
81 82 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
82 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
83
84 auto eventProducts = m_DisplayedEvent->getEventProducts();
85 for (auto &eventProduct : eventProducts) {
86 if (eventProduct.getProductId() == oldProductId) {
87 eventProduct.setProductId(m_DisplayedEventProduct->getProductId());
88 }
89 }
90 m_DisplayedEvent->setEventProducts(eventProducts);
91
92 emit inspector->eventUpdated(m_DisplayedEvent);
83 93 }
84 94 });
85 95
@@ -87,7 +97,16 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpda
87 97 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
88 98 if (time != m_DisplayedEventProduct->getTStart()) {
89 99 m_DisplayedEventProduct->setTStart(time);
90 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
100
101 auto eventProducts = m_DisplayedEvent->getEventProducts();
102 for (auto &eventProduct : eventProducts) {
103 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
104 eventProduct.setTStart(m_DisplayedEventProduct->getTStart());
105 }
106 }
107 m_DisplayedEvent->setEventProducts(eventProducts);
108
109 emit inspector->eventUpdated(m_DisplayedEvent);
91 110 }
92 111 });
93 112
@@ -95,7 +114,16 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpda
95 114 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
96 115 if (time != m_DisplayedEventProduct->getTEnd()) {
97 116 m_DisplayedEventProduct->setTEnd(time);
98 emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct);
117
118 auto eventProducts = m_DisplayedEvent->getEventProducts();
119 for (auto &eventProduct : eventProducts) {
120 if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) {
121 eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd());
122 }
123 }
124 m_DisplayedEvent->setEventProducts(eventProducts);
125
126 emit inspector->eventUpdated(m_DisplayedEvent);
99 127 }
100 128 });
101 129 }
@@ -145,6 +173,8 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
145 173 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
146 174 const std::shared_ptr<DBEventProduct> &eventProduct)
147 175 {
176
177 impl->m_DisplayedEvent = event;
148 178 impl->m_DisplayedEventProduct = eventProduct;
149 179
150 180 blockSignals(true);
@@ -152,7 +182,7 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &e
152 182 showPage(Page::EventProperties);
153 183 ui->leEventName->setEnabled(false);
154 184 ui->leEventName->setText(event->getName());
155 ui->leEventProduct->setEnabled(true);
185 ui->leEventProduct->setEnabled(false);
156 186 ui->leEventProduct->setText(eventProduct->getProductId());
157 187
158 188 ui->leEventTags->setEnabled(false);
@@ -3,7 +3,10
3 3 #include <SqpApplication.h>
4 4
5 5 #include <Catalogue/CatalogueController.h>
6 #include <Catalogue/CatalogueTreeWidgetItem.h>
6 #include <Catalogue/CatalogueExplorerHelper.h>
7 #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h>
8 #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h>
9 #include <Catalogue/CatalogueTreeModel.h>
7 10 #include <CatalogueDao.h>
8 11 #include <ComparaisonPredicate.h>
9 12 #include <DBCatalogue.h>
@@ -13,22 +16,81
13 16 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
14 17
15 18
16 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
17 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
18 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
19 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
19 constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1;
20 constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2;
21 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
22 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
20 23
21 24
22 25 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
23 26
24 void configureTreeWidget(QTreeWidget *treeWidget);
25 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
26 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
27 CatalogueTreeModel *m_TreeModel = nullptr;
28
29 void configureTreeWidget(QTreeView *treeView);
30 QModelIndex addDatabaseItem(const QString &name);
31 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
27 32 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
28 QTreeWidgetItem *parentDatabaseItem);
33 const QModelIndex &databaseIndex);
34
35 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
36 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
37 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
38
39 int selectionType(QTreeView *treeView) const
40 {
41 auto selectedItems = treeView->selectionModel()->selectedRows();
42 if (selectedItems.isEmpty()) {
43 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
44 }
45 else {
46 auto firstIndex = selectedItems.first();
47 auto firstItem = m_TreeModel->item(firstIndex);
48 if (!firstItem) {
49 Q_ASSERT(false);
50 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
51 }
52 auto selectionType = firstItem->type();
53
54 for (auto itemIndex : selectedItems) {
55 auto item = m_TreeModel->item(itemIndex);
56 if (!item || item->type() != selectionType) {
57 // Incoherent multi selection
58 selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE;
59 break;
60 }
61 }
62
63 return selectionType;
64 }
65 }
66
67 QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const
68 {
69 QVector<std::shared_ptr<DBCatalogue> > catalogues;
70 auto selectedItems = treeView->selectionModel()->selectedRows();
71 for (auto itemIndex : selectedItems) {
72 auto item = m_TreeModel->item(itemIndex);
73 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
74 catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue());
75 }
76 }
29 77
30 CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
31 QTreeWidget *treeWidget) const;
78 return catalogues;
79 }
80
81 QStringList selectedRepositories(QTreeView *treeView) const
82 {
83 QStringList repositories;
84 auto selectedItems = treeView->selectionModel()->selectedRows();
85 for (auto itemIndex : selectedItems) {
86 auto item = m_TreeModel->item(itemIndex);
87 if (item && item->type() == DATABASE_ITEM_TYPE) {
88 repositories.append(item->text());
89 }
90 }
91
92 return repositories;
93 }
32 94 };
33 95
34 96 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
@@ -37,82 +99,53 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
37 99 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
38 100 {
39 101 ui->setupUi(this);
40 impl->configureTreeWidget(ui->treeWidget);
41 102
42 ui->treeWidget->setColumnCount(2);
43 ui->treeWidget->header()->setStretchLastSection(false);
44 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
45 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
103 impl->m_TreeModel = new CatalogueTreeModel(this);
104 ui->treeView->setModel(impl->m_TreeModel);
105
106 impl->configureTreeWidget(ui->treeView);
107
108 ui->treeView->header()->setStretchLastSection(false);
109 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
110 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
46 111
47 112 auto emitSelection = [this]() {
48 113
49 auto selectedItems = ui->treeWidget->selectedItems();
50 if (selectedItems.isEmpty()) {
51 emit this->selectionCleared();
114 auto selectionType = impl->selectionType(ui->treeView);
115
116 switch (selectionType) {
117 case CATALOGUE_ITEM_TYPE:
118 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
119 break;
120 case DATABASE_ITEM_TYPE:
121 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
122 break;
123 case ALL_EVENT_ITEM_TYPE:
124 emit this->allEventsSelected();
125 break;
126 case TRASH_ITEM_TYPE:
127 emit this->trashSelected();
128 break;
129 default:
130 emit this->selectionCleared();
131 break;
52 132 }
53 else {
54 QVector<std::shared_ptr<DBCatalogue> > catalogues;
55 QStringList databases;
56 int selectionType = selectedItems.first()->type();
57
58 for (auto item : ui->treeWidget->selectedItems()) {
59 if (item->type() == selectionType) {
60 switch (selectionType) {
61 case CATALOGUE_ITEM_TYPE:
62 catalogues.append(
63 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
64 break;
65 case DATABASE_ITEM_TYPE:
66 selectionType = DATABASE_ITEM_TYPE;
67 databases.append(item->text(0));
68 case ALL_EVENT_ITEM_TYPE: // fallthrough
69 case TRASH_ITEM_TYPE: // fallthrough
70 default:
71 break;
72 }
73 }
74 else {
75 // Incoherent multi selection
76 selectionType = -1;
77 break;
78 }
79 }
133 };
80 134
81 switch (selectionType) {
82 case CATALOGUE_ITEM_TYPE:
83 emit this->catalogueSelected(catalogues);
84 break;
85 case DATABASE_ITEM_TYPE:
86 emit this->databaseSelected(databases);
87 break;
88 case ALL_EVENT_ITEM_TYPE:
89 emit this->allEventsSelected();
90 break;
91 case TRASH_ITEM_TYPE:
92 emit this->trashSelected();
93 break;
94 default:
95 emit this->selectionCleared();
96 break;
97 }
135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
136 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
137 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
138 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
139 if (selectedIndexes.contains(index)) {
140 emitSelection();
98 141 }
99 142
143 auto item = impl->m_TreeModel->item(index);
144 impl->setHasChanges(true, index, ui->treeView);
145 });
100 146
101 };
102
103 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
104 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
105 connect(ui->treeWidget, &QTreeWidget::itemChanged,
106 [emitSelection, this](auto item, auto column) {
107 auto selectedItems = ui->treeWidget->selectedItems();
108 qDebug() << "ITEM CHANGED" << column;
109 if (selectedItems.contains(item) && column == 0) {
110 emitSelection();
111 }
112 });
113
114 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
115 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
147 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
148 connect(ui->treeView, &QTreeView::customContextMenuRequested, this,
116 149 &CatalogueSideBarWidget::onContextMenuRequested);
117 150 }
118 151
@@ -121,24 +154,54 CatalogueSideBarWidget::~CatalogueSideBarWidget()
121 154 delete ui;
122 155 }
123 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
124 164 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
125 165 bool hasChanges)
126 166 {
127 if (auto catalogueItem = impl->getCatalogueItem(catalogue, ui->treeWidget)) {
128 catalogueItem->setHasChanges(hasChanges);
129 catalogueItem->refresh();
167 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
168 auto index = impl->m_TreeModel->indexOf(catalogueItem);
169 impl->setHasChanges(hasChanges, index, ui->treeView);
170 // catalogueItem->refresh();
130 171 }
131 172 }
132 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
133 192 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
134 193 {
135 194 QMenu menu{this};
136 195
137 auto currentItem = ui->treeWidget->currentItem();
196 auto currentIndex = ui->treeView->currentIndex();
197 auto currentItem = impl->m_TreeModel->item(currentIndex);
198 if (!currentItem) {
199 return;
200 }
201
138 202 switch (currentItem->type()) {
139 203 case CATALOGUE_ITEM_TYPE:
140 menu.addAction("Rename",
141 [this, currentItem]() { ui->treeWidget->editItem(currentItem); });
204 menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); });
142 205 break;
143 206 case DATABASE_ITEM_TYPE:
144 207 break;
@@ -154,59 +217,56 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
154 217 }
155 218
156 219 if (!menu.isEmpty()) {
157 menu.exec(ui->treeWidget->mapToGlobal(pos));
220 menu.exec(ui->treeView->mapToGlobal(pos));
158 221 }
159 222 }
160 223
161 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
162 QTreeWidget *treeWidget)
224 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView)
163 225 {
164 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
165 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
166 treeWidget->addTopLevelItem(allEventsItem);
226 auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events",
227 ALL_EVENT_ITEM_TYPE};
228 auto allEventIndex = m_TreeModel->addTopLevelItem(allEventsItem);
229 treeView->setCurrentIndex(allEventIndex);
167 230
168 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
169 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
170 treeWidget->addTopLevelItem(trashItem);
231 auto trashItem
232 = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE};
233 m_TreeModel->addTopLevelItem(trashItem);
171 234
172 auto separator = new QFrame{treeWidget};
235 auto separator = new QFrame{treeView};
173 236 separator->setFrameShape(QFrame::HLine);
174 auto separatorItem = new QTreeWidgetItem{};
175 separatorItem->setFlags(Qt::NoItemFlags);
176 treeWidget->addTopLevelItem(separatorItem);
177 treeWidget->setItemWidget(separatorItem, 0, separator);
237 auto separatorItem
238 = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE};
239 separatorItem->setEnabled(false);
240 auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem);
241 treeView->setIndexWidget(separatorIndex, separator);
178 242
179 243 auto repositories = sqpApp->catalogueController().getRepositories();
180 244 for (auto dbname : repositories) {
181 auto db = addDatabaseItem(dbname, treeWidget);
182
245 auto dbIndex = addDatabaseItem(dbname);
183 246 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
184 247 for (auto catalogue : catalogues) {
185 addCatalogueItem(catalogue, db);
248 addCatalogueItem(catalogue, dbIndex);
186 249 }
187 250 }
188 251
189 treeWidget->expandAll();
252 treeView->expandAll();
190 253 }
191 254
192 QTreeWidgetItem *
193 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name,
194 QTreeWidget *treeWidget)
255 QModelIndex
256 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name)
195 257 {
196 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
197 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
198 treeWidget->addTopLevelItem(databaseItem);
258 auto databaseItem
259 = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE};
260 auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem);
199 261
200 return databaseItem;
262 return databaseIndex;
201 263 }
202 264
203 QTreeWidgetItem *
204 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
205 QTreeWidget *treeWidget)
265 CatalogueAbstractTreeItem *
266 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name)
206 267 {
207 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
208 auto item = treeWidget->topLevelItem(i);
209 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
268 for (auto item : m_TreeModel->topLevelItems()) {
269 if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) {
210 270 return item;
211 271 }
212 272 }
@@ -215,23 +275,21 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QSt
215 275 }
216 276
217 277 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
218 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem)
278 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
219 279 {
220 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
221 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
222 parentDatabaseItem->addChild(catalogueItem);
280 auto catalogueItem
281 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
282 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
223 283 }
224 284
225 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
226 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidget *treeWidget) const
285 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
286 const std::shared_ptr<DBCatalogue> &catalogue) const
227 287 {
228 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
229 auto item = treeWidget->topLevelItem(i);
288 for (auto item : m_TreeModel->topLevelItems()) {
230 289 if (item->type() == DATABASE_ITEM_TYPE) {
231 for (auto j = 0; j < item->childCount(); ++j) {
232 auto childItem = item->child(j);
290 for (auto childItem : item->children()) {
233 291 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
234 auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem);
292 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
235 293 if (catalogueItem->catalogue() == catalogue) {
236 294 return catalogueItem;
237 295 }
@@ -248,3 +306,32 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::
248 306
249 307 return nullptr;
250 308 }
309
310 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
311 const QModelIndex &index,
312 QTreeView *treeView)
313 {
314 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
315 if (value) {
316 if (!hasChanges(validationIndex, treeView)) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
318 treeView, [this, validationIndex,
319 treeView]() { setHasChanges(false, validationIndex, treeView); },
320 [this, validationIndex, treeView]() {
321 setHasChanges(false, validationIndex, treeView);
322 });
323 treeView->setIndexWidget(validationIndex, widget);
324 }
325 }
326 else {
327 // Note: the widget is destroyed
328 treeView->setIndexWidget(validationIndex, nullptr);
329 }
330 }
331
332 bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index,
333 QTreeView *treeView)
334 {
335 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
336 return treeView->indexWidget(validationIndex) != nullptr;
337 }
@@ -1,91 +1,95
1 #include "Catalogue/CatalogueTreeWidgetItem.h"
1 #include "Catalogue/CatalogueTreeItems/CatalogueTreeItem.h"
2 2 #include <Catalogue/CatalogueExplorerHelper.h>
3 3
4 4 #include <Catalogue/CatalogueController.h>
5 #include <Common/MimeTypesDef.h>
6 #include <QIcon>
7 #include <QMimeData>
5 8 #include <SqpApplication.h>
6 9
7 10 #include <memory>
8 11
9 12 #include <DBCatalogue.h>
10 13
11 /// Column in the tree widget where the apply and cancel buttons must appear
12 const auto APPLY_CANCEL_BUTTONS_COLUMN = 1;
13
14 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
14 struct CatalogueTreeItem::CatalogueTreeItemPrivate {
15 15
16 16 std::shared_ptr<DBCatalogue> m_Catalogue;
17 QIcon m_Icon;
17 18
18 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
19 CatalogueTreeItemPrivate(std::shared_ptr<DBCatalogue> catalogue, const QIcon &icon)
20 : m_Catalogue(catalogue), m_Icon(icon)
19 21 {
20 22 }
21 23 };
22 24
23 25
24 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
25 : QTreeWidgetItem(type),
26 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
26 CatalogueTreeItem::CatalogueTreeItem(std::shared_ptr<DBCatalogue> catalogue, const QIcon &icon,
27 int type)
28 : CatalogueAbstractTreeItem(type),
29 impl{spimpl::make_unique_impl<CatalogueTreeItemPrivate>(catalogue, icon)}
27 30 {
28 setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
29 31 }
30 32
31 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
33 QVariant CatalogueTreeItem::data(int column, int role) const
32 34 {
33 35 if (column == 0) {
34 36 switch (role) {
35 37 case Qt::EditRole: // fallthrough
36 38 case Qt::DisplayRole:
37 39 return impl->m_Catalogue->getName();
40 case Qt::DecorationRole:
41 return impl->m_Icon;
38 42 default:
39 43 break;
40 44 }
41 45 }
42 46
43 return QTreeWidgetItem::data(column, role);
47 return QVariant();
44 48 }
45 49
46 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
50 bool CatalogueTreeItem::setData(int column, int role, const QVariant &value)
47 51 {
52 bool result = false;
53
48 54 if (role == Qt::EditRole && column == 0) {
49 55 auto newName = value.toString();
50 56 if (newName != impl->m_Catalogue->getName()) {
51 setText(0, newName);
52 57 impl->m_Catalogue->setName(newName);
53 58 sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
54 setHasChanges(true);
59 result = true;
55 60 }
56 61 }
57 else {
58 QTreeWidgetItem::setData(column, role, value);
59 }
60 }
61 62
62 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
63 {
64 return impl->m_Catalogue;
63 return result;
65 64 }
66 65
67 void CatalogueTreeWidgetItem::setHasChanges(bool value)
66 Qt::ItemFlags CatalogueTreeItem::flags(int column) const
68 67 {
69 if (value) {
70 if (!hasChanges()) {
71 auto widget = CatalogueExplorerHelper::buildValidationWidget(
72 treeWidget(), [this]() { setHasChanges(false); },
73 [this]() { setHasChanges(false); });
74 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, widget);
75 }
68 if (column == 0) {
69 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable
70 | Qt::ItemIsDropEnabled;
76 71 }
77 72 else {
78 // Note: the widget is destroyed
79 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
73 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
80 74 }
81 75 }
82 76
83 bool CatalogueTreeWidgetItem::hasChanges()
77 bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action)
84 78 {
85 return treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) != nullptr;
79 return data->hasFormat(MIME_TYPE_EVENT_LIST);
86 80 }
87 81
88 void CatalogueTreeWidgetItem::refresh()
82 bool CatalogueTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action)
89 83 {
90 emitDataChanged();
84 Q_ASSERT(canDropMimeData(data, action));
85
86 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
87 // impl->m_Catalogue->addEvents(events); TODO: move events in the new catalogue
88 // Warning: Check that the events aren't already in the catalogue
89 // Also check for the repository !!!
90 }
91
92 std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const
93 {
94 return impl->m_Catalogue;
91 95 }
@@ -10,7 +10,8 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>()}
@@ -20,10 +21,9 CreateEventDialog::CreateEventDialog(QWidget *parent)
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
@@ -64,9 +64,6 public:
64 64 m_VariableControllerThread.setObjectName("VariableControllerThread");
65 65 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
66 66 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
67 m_CatalogueController->moveToThread(&m_CatalogueControllerThread);
68 m_CatalogueControllerThread.setObjectName("CatalogueControllerThread");
69
70 67
71 68 // Additionnal init
72 69 m_VariableController->setTimeController(m_TimeController.get());
@@ -85,9 +82,6 public:
85 82
86 83 m_VisualizationControllerThread.quit();
87 84 m_VisualizationControllerThread.wait();
88
89 m_CatalogueControllerThread.quit();
90 m_CatalogueControllerThread.wait();
91 85 }
92 86
93 87 std::unique_ptr<DataSourceController> m_DataSourceController;
@@ -101,7 +95,6 public:
101 95 QThread m_NetworkControllerThread;
102 96 QThread m_VariableControllerThread;
103 97 QThread m_VisualizationControllerThread;
104 QThread m_CatalogueControllerThread;
105 98
106 99 std::unique_ptr<DragDropGuiController> m_DragDropGuiController;
107 100 std::unique_ptr<ActionsGuiController> m_ActionsGuiController;
@@ -136,16 +129,11 SqpApplication::SqpApplication(int &argc, char **argv)
136 129 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
137 130 impl->m_VisualizationController.get(), &VisualizationController::finalize);
138 131
139 connect(&impl->m_CatalogueControllerThread, &QThread::started,
140 impl->m_CatalogueController.get(), &CatalogueController::initialize);
141 connect(&impl->m_CatalogueControllerThread, &QThread::finished,
142 impl->m_CatalogueController.get(), &CatalogueController::finalize);
143
144 132 impl->m_DataSourceControllerThread.start();
145 133 impl->m_NetworkControllerThread.start();
146 134 impl->m_VariableControllerThread.start();
147 135 impl->m_VisualizationControllerThread.start();
148 impl->m_CatalogueControllerThread.start();
136 impl->m_CatalogueController->initialize();
149 137 }
150 138
151 139 SqpApplication::~SqpApplication()
@@ -30,6 +30,9
30 30 <layout class="QHBoxLayout" name="horizontalLayout">
31 31 <item>
32 32 <widget class="QToolButton" name="btnAdd">
33 <property name="enabled">
34 <bool>false</bool>
35 </property>
33 36 <property name="text">
34 37 <string>+</string>
35 38 </property>
@@ -82,6 +85,9
82 85 </item>
83 86 <item>
84 87 <widget class="QToolButton" name="btnChart">
88 <property name="enabled">
89 <bool>false</bool>
90 </property>
85 91 <property name="text">
86 92 <string>G</string>
87 93 </property>
@@ -30,6 +30,9
30 30 <layout class="QHBoxLayout" name="horizontalLayout">
31 31 <item>
32 32 <widget class="QToolButton" name="btnAdd">
33 <property name="enabled">
34 <bool>false</bool>
35 </property>
33 36 <property name="text">
34 37 <string>+</string>
35 38 </property>
@@ -44,6 +47,9
44 47 </item>
45 48 <item>
46 49 <widget class="QToolButton" name="btnRemove">
50 <property name="enabled">
51 <bool>false</bool>
52 </property>
47 53 <property name="text">
48 54 <string> - </string>
49 55 </property>
@@ -72,18 +78,22
72 78 </layout>
73 79 </item>
74 80 <item>
75 <widget class="QTreeWidget" name="treeWidget">
81 <widget class="QTreeView" name="treeView">
82 <property name="acceptDrops">
83 <bool>true</bool>
84 </property>
85 <property name="dragDropMode">
86 <enum>QAbstractItemView::DragDrop</enum>
87 </property>
76 88 <property name="selectionMode">
77 89 <enum>QAbstractItemView::ExtendedSelection</enum>
78 90 </property>
79 91 <attribute name="headerVisible">
80 92 <bool>false</bool>
81 93 </attribute>
82 <column>
83 <property name="text">
84 <string notr="true">1</string>
85 </property>
86 </column>
94 <attribute name="headerStretchLastSection">
95 <bool>false</bool>
96 </attribute>
87 97 </widget>
88 98 </item>
89 99 </layout>
@@ -37,6 +37,7 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
37 37 auto actionLabel = QObject::tr(
38 38 itemType == DataSourceItemType::PRODUCT ? "Load %1 product" : "Load %1 component");
39 39 addLoadAction(actionLabel.arg(item.name()));
40 item.setData(DataSourceItem::ID_DATA_KEY, item.data(AMDA_XML_ID_KEY));
40 41 }
41 42
42 43 auto count = item.childCount();
@@ -28,6 +28,7 std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
28 28
29 29 // Adds plugin name to product metadata
30 30 result->setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME);
31 result->setData(DataSourceItem::ID_DATA_KEY, data.value(DataSourceItem::NAME_DATA_KEY));
31 32
32 33 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
33 34
1 NO CONTENT: file was removed
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