##// 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 protected:
53 protected:
54 void changeEvent(QEvent *e);
54 void changeEvent(QEvent *e);
55 void closeEvent(QCloseEvent *event);
55
56
56 private:
57 private:
57 std::unique_ptr<Ui::MainWindow> m_Ui;
58 std::unique_ptr<Ui::MainWindow> m_Ui;
@@ -49,10 +49,12 int main(int argc, char *argv[])
49 #endif
49 #endif
50 Q_INIT_RESOURCE(sqpguiresources);
50 Q_INIT_RESOURCE(sqpguiresources);
51
51
52 SqpApplication a{argc, argv};
53 SqpApplication::setOrganizationName("LPP");
52 SqpApplication::setOrganizationName("LPP");
54 SqpApplication::setOrganizationDomain("lpp.fr");
53 SqpApplication::setOrganizationDomain("lpp.fr");
55 SqpApplication::setApplicationName("SciQLop");
54 SqpApplication::setApplicationName("SciQLop");
55
56 SqpApplication a{argc, argv};
57
56 MainWindow w;
58 MainWindow w;
57 w.show();
59 w.show();
58
60
@@ -22,6 +22,7
22 #include "MainWindow.h"
22 #include "MainWindow.h"
23 #include "ui_MainWindow.h"
23 #include "ui_MainWindow.h"
24
24
25 #include <Catalogue/CatalogueController.h>
25 #include <Catalogue/CatalogueExplorer.h>
26 #include <Catalogue/CatalogueExplorer.h>
26 #include <DataSource/DataSourceController.h>
27 #include <DataSource/DataSourceController.h>
27 #include <DataSource/DataSourceWidget.h>
28 #include <DataSource/DataSourceWidget.h>
@@ -36,9 +37,11
36 #include <Visualization/VisualizationController.h>
37 #include <Visualization/VisualizationController.h>
37
38
38 #include <QAction>
39 #include <QAction>
40 #include <QCloseEvent>
39 #include <QDate>
41 #include <QDate>
40 #include <QDir>
42 #include <QDir>
41 #include <QFileDialog>
43 #include <QFileDialog>
44 #include <QMessageBox>
42 #include <QToolBar>
45 #include <QToolBar>
43 #include <QToolButton>
46 #include <QToolButton>
44 #include <memory.h>
47 #include <memory.h>
@@ -74,6 +77,8 public:
74 SqpSettingsDialog *m_SettingsDialog;
77 SqpSettingsDialog *m_SettingsDialog;
75 /// Catalogue dialog. MainWindow has the ownership
78 /// Catalogue dialog. MainWindow has the ownership
76 CatalogueExplorer *m_CatalogExplorer;
79 CatalogueExplorer *m_CatalogExplorer;
80
81 bool checkDataToSave(QWidget *parentWidget);
77 };
82 };
78
83
79 MainWindow::MainWindow(QWidget *parent)
84 MainWindow::MainWindow(QWidget *parent)
@@ -364,3 +369,37 void MainWindow::changeEvent(QEvent *e)
364 break;
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 class DBCatalogue;
16 class DBCatalogue;
17 class DBEvent;
17 class DBEvent;
18 class DBEventProduct;
18
19
19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20
21
@@ -44,10 +45,13 public:
44 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
45 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
45 void addEvent(std::shared_ptr<DBEvent> event);
46 void addEvent(std::shared_ptr<DBEvent> event);
46 void updateEvent(std::shared_ptr<DBEvent> event);
47 void updateEvent(std::shared_ptr<DBEvent> event);
48 void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
47 void removeEvent(std::shared_ptr<DBEvent> event);
49 void removeEvent(std::shared_ptr<DBEvent> event);
48 // void trashEvent(std::shared_ptr<DBEvent> event);
50 // void trashEvent(std::shared_ptr<DBEvent> event);
49 // void restore(QUuid eventId);
51 // void restore(std::shared_ptr<DBEvent> event);
50 void saveEvent(std::shared_ptr<DBEvent> event);
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 // Catalogue
56 // Catalogue
53 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
57 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
@@ -59,15 +63,19 public:
59 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
60
64
61 void saveAll();
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 public slots:
74 public slots:
64 /// Manage init/end of the controller
75 /// Manage init/end of the controller
65 void initialize();
76 void initialize();
66 void finalize();
67
77
68 private:
78 private:
69 void waitForFinish();
70
71 class CatalogueControllerPrivate;
79 class CatalogueControllerPrivate;
72 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
80 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
73 };
81 };
@@ -27,6 +27,8 public:
27 static const QString NAME_DATA_KEY;
27 static const QString NAME_DATA_KEY;
28 /// Key associated with the plugin of the item
28 /// Key associated with the plugin of the item
29 static const QString PLUGIN_DATA_KEY;
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 explicit DataSourceItem(DataSourceItemType type, const QString &name);
33 explicit DataSourceItem(DataSourceItemType type, const QString &name);
32 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
34 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
@@ -12,6 +12,7
12 #include <DBTag.h>
12 #include <DBTag.h>
13 #include <IRequestPredicate.h>
13 #include <IRequestPredicate.h>
14
14
15 #include <QDataStream>
15 #include <QMutex>
16 #include <QMutex>
16 #include <QThread>
17 #include <QThread>
17
18
@@ -22,8 +23,8 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
22
23
23 namespace {
24 namespace {
24
25
25 static QString REPOSITORY_WORK_SUFFIX = QString{"work"};
26 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"trash"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
27 }
28 }
28
29
29 class CatalogueController::CatalogueControllerPrivate {
30 class CatalogueController::CatalogueControllerPrivate {
@@ -31,15 +32,22 class CatalogueController::CatalogueControllerPrivate {
31 public:
32 public:
32 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33
34
34 QMutex m_WorkingMutex;
35 CatalogueDao m_CatalogueDao;
35 CatalogueDao m_CatalogueDao;
36
36
37 QStringList m_RepositoryList;
37 QStringList m_RepositoryList;
38 CatalogueController *m_Q;
38 CatalogueController *m_Q;
39
39
40 QSet<QString> m_EventKeysWithChanges;
41
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
43
40 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
41 QString toWorkRepository(QString repository);
45 QString toWorkRepository(QString repository);
42 QString toSyncRepository(QString repository);
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 CatalogueController::CatalogueController(QObject *parent)
53 CatalogueController::CatalogueController(QObject *parent)
@@ -53,7 +61,6 CatalogueController::~CatalogueController()
53 {
61 {
54 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
62 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
55 << QThread::currentThread();
63 << QThread::currentThread();
56 this->waitForFinish();
57 }
64 }
58
65
59 QStringList CatalogueController::getRepositories() const
66 QStringList CatalogueController::getRepositories() const
@@ -132,11 +139,19 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> ca
132
139
133 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
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 impl->m_CatalogueDao.updateEvent(*event);
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 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
155 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
141 {
156 {
142 // Remove it from both repository and repository_work
157 // Remove it from both repository and repository_work
@@ -144,24 +159,72 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
144 impl->m_CatalogueDao.removeEvent(*event);
159 impl->m_CatalogueDao.removeEvent(*event);
145 event->setRepository(impl->toSyncRepository(event->getRepository()));
160 event->setRepository(impl->toSyncRepository(event->getRepository()));
146 impl->m_CatalogueDao.removeEvent(*event);
161 impl->m_CatalogueDao.removeEvent(*event);
162 impl->savAllDB();
147 }
163 }
148
164
149 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
165 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
150 {
166 {
151 event->setRepository(impl->toWorkRepository(event->getRepository()));
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 // Call update is necessary at the creation of add Event if it has some tags or some event
172 // Call update is necessary at the creation of add Event if it has some tags or some event
156 // products
173 // products
157 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
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 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
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 std::list<std::shared_ptr<DBCatalogue> >
230 std::list<std::shared_ptr<DBCatalogue> >
@@ -179,7 +242,7 CatalogueController::retrieveCatalogues(const QString &repository) const
179
242
180 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
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 impl->m_CatalogueDao.updateCatalogue(*catalogue);
247 impl->m_CatalogueDao.updateCatalogue(*catalogue);
185 }
248 }
@@ -195,8 +258,7 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue
195
258
196 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
259 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
197 {
260 {
198 impl->m_CatalogueDao.moveCatalogue(*catalogue,
261 impl->saveCatalogue(catalogue, true);
199 impl->toSyncRepository(catalogue->getRepository()), true);
200 }
262 }
201
263
202 void CatalogueController::saveAll()
264 void CatalogueController::saveAll()
@@ -205,22 +267,70 void CatalogueController::saveAll()
205 // Save Event
267 // Save Event
206 auto events = this->retrieveEvents(repository);
268 auto events = this->retrieveEvents(repository);
207 for (auto event : events) {
269 for (auto event : events) {
208 this->saveEvent(event);
270 impl->saveEvent(event, false);
209 }
271 }
210
272
211 // Save Catalogue
273 // Save Catalogue
212 auto catalogues = this->retrieveCatalogues(repository);
274 auto catalogues = this->retrieveCatalogues(repository);
213 for (auto catalogue : catalogues) {
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 void CatalogueController::initialize()
329 void CatalogueController::initialize()
220 {
330 {
221 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
331 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
222 << QThread::currentThread();
332 << QThread::currentThread();
223 impl->m_WorkingMutex.lock();
333
224 impl->m_CatalogueDao.initialize();
334 impl->m_CatalogueDao.initialize();
225 auto defaultRepositoryLocation
335 auto defaultRepositoryLocation
226 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
336 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
@@ -242,37 +352,24 void CatalogueController::initialize()
242 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
352 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
243 }
353 }
244
354
245 void CatalogueController::finalize()
355 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
246 {
356 const std::shared_ptr<DBEvent> &event) const
247 impl->m_WorkingMutex.unlock();
248 }
249
250 void CatalogueController::waitForFinish()
251 {
357 {
252 QMutexLocker locker{&impl->m_WorkingMutex};
358 return event->getUniqId().toString().append(event->getRepository());
253 }
359 }
254
360
255 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
361 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
256 const QString &dbTo)
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 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
365 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
366 auto events = m_CatalogueDao.getEvents(dbFrom);
260 for (auto catalogue : catalogues) {
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 for (auto event : events) {
371 for (auto event : events) {
267 eventsShared.push_back(std::make_shared<DBEvent>(event));
372 m_CatalogueDao.copyEvent(event, dbTo, true);
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);
276 }
373 }
277 }
374 }
278
375
@@ -280,7 +377,7 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QStrin
280 {
377 {
281 auto syncRepository = toSyncRepository(repository);
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 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
383 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
@@ -294,3 +391,30 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QStrin
294 }
391 }
295 return syncRepository;
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 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
7 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
8 const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin");
8 const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin");
9 const QString DataSourceItem::ID_DATA_KEY = QStringLiteral("uuid");
9
10
10 struct DataSourceItem::DataSourceItemPrivate {
11 struct DataSourceItem::DataSourceItemPrivate {
11 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
12 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
@@ -3,9 +3,11
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 class CatalogueExplorer;
7
6 class CatalogueActionManager {
8 class CatalogueActionManager {
7 public:
9 public:
8 CatalogueActionManager();
10 CatalogueActionManager(CatalogueExplorer *catalogueExplorer);
9
11
10 void installSelectionZoneActions();
12 void installSelectionZoneActions();
11
13
@@ -34,7 +34,7 public:
34 std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const;
34 std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const;
35
35
36 /// Refresh the data for the specified event
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 /// Returns a QModelIndex which represent the specified event
39 /// Returns a QModelIndex which represent the specified event
40 QModelIndex indexOf(const std::shared_ptr<DBEvent> &event) const;
40 QModelIndex indexOf(const std::shared_ptr<DBEvent> &event) const;
@@ -32,17 +32,27 public:
32
32
33 void setVisualizationWidget(VisualizationWidget *visualization);
33 void setVisualizationWidget(VisualizationWidget *visualization);
34
34
35 void addEvent(const std::shared_ptr<DBEvent> &event);
35 void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges);
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 public slots:
42 public slots:
38 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
43 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
39 void populateWithAllEvents();
44 void populateWithAllEvents();
45 void clear();
46 void refresh();
40
47
41 private:
48 private:
42 Ui::CatalogueEventsWidget *ui;
49 Ui::CatalogueEventsWidget *ui;
43
50
44 class CatalogueEventsWidgetPrivate;
51 class CatalogueEventsWidgetPrivate;
45 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
52 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
53
54 private slots:
55 void emitSelection();
46 };
56 };
47
57
48 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
58 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
@@ -8,6 +8,9 namespace Ui {
8 class CatalogueExplorer;
8 class CatalogueExplorer;
9 }
9 }
10
10
11 class CatalogueEventsWidget;
12 class CatalogueSideBarWidget;
13
11 class VisualizationWidget;
14 class VisualizationWidget;
12
15
13 class CatalogueExplorer : public QDialog {
16 class CatalogueExplorer : public QDialog {
@@ -19,6 +22,9 public:
19
22
20 void setVisualizationWidget(VisualizationWidget *visualization);
23 void setVisualizationWidget(VisualizationWidget *visualization);
21
24
25 CatalogueEventsWidget &eventsWidget() const;
26 CatalogueSideBarWidget &sideBarWidget() const;
27
22 private:
28 private:
23 Ui::CatalogueExplorer *ui;
29 Ui::CatalogueExplorer *ui;
24
30
@@ -28,8 +28,11 public:
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
29 virtual ~CatalogueSideBarWidget();
29 virtual ~CatalogueSideBarWidget();
30
30
31 void addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, const QString &repository);
31 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
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 private:
36 private:
34 Ui::CatalogueSideBarWidget *ui;
37 Ui::CatalogueSideBarWidget *ui;
35
38
@@ -15,7 +15,8 class CreateEventDialog : public QDialog {
15 Q_OBJECT
15 Q_OBJECT
16
16
17 public:
17 public:
18 explicit CreateEventDialog(QWidget *parent = 0);
18 explicit CreateEventDialog(const QVector<std::shared_ptr<DBCatalogue> > &catalogues,
19 QWidget *parent = 0);
19 virtual ~CreateEventDialog();
20 virtual ~CreateEventDialog();
20
21
21 void hideCatalogueChoice();
22 void hideCatalogueChoice();
@@ -27,7 +27,8 gui_moc_headers = [
27 'include/Catalogue/CatalogueSideBarWidget.h',
27 'include/Catalogue/CatalogueSideBarWidget.h',
28 'include/Catalogue/CatalogueInspectorWidget.h',
28 'include/Catalogue/CatalogueInspectorWidget.h',
29 'include/Catalogue/CatalogueEventsModel.h',
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 gui_ui_files = [
34 gui_ui_files = [
@@ -118,11 +119,14 gui_sources = [
118 'src/Catalogue/CatalogueEventsWidget.cpp',
119 'src/Catalogue/CatalogueEventsWidget.cpp',
119 'src/Catalogue/CatalogueSideBarWidget.cpp',
120 'src/Catalogue/CatalogueSideBarWidget.cpp',
120 'src/Catalogue/CatalogueInspectorWidget.cpp',
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 'src/Catalogue/CatalogueEventsModel.cpp',
125 'src/Catalogue/CatalogueEventsModel.cpp',
123 'src/Catalogue/CatalogueExplorerHelper.cpp',
126 'src/Catalogue/CatalogueExplorerHelper.cpp',
124 'src/Catalogue/CatalogueActionManager.cpp',
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 gui_inc = include_directories(['include'])
132 gui_inc = include_directories(['include'])
@@ -2,13 +2,18
2
2
3 #include <Actions/ActionsGuiController.h>
3 #include <Actions/ActionsGuiController.h>
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <DataSource/DataSourceItem.h>
5 #include <SqpApplication.h>
6 #include <SqpApplication.h>
6 #include <Variable/Variable.h>
7 #include <Variable/Variable.h>
7 #include <Visualization/VisualizationGraphWidget.h>
8 #include <Visualization/VisualizationGraphWidget.h>
8 #include <Visualization/VisualizationSelectionZoneItem.h>
9 #include <Visualization/VisualizationSelectionZoneItem.h>
9
10
11 #include <Catalogue/CatalogueEventsWidget.h>
12 #include <Catalogue/CatalogueExplorer.h>
13 #include <Catalogue/CatalogueSideBarWidget.h>
10 #include <Catalogue/CreateEventDialog.h>
14 #include <Catalogue/CreateEventDialog.h>
11
15
16 #include <CatalogueDao.h>
12 #include <DBCatalogue.h>
17 #include <DBCatalogue.h>
13 #include <DBEvent.h>
18 #include <DBEvent.h>
14 #include <DBEventProduct.h>
19 #include <DBEventProduct.h>
@@ -21,6 +26,14
21 #include <memory>
26 #include <memory>
22
27
23 struct CatalogueActionManager::CatalogueActionManagerPrivate {
28 struct CatalogueActionManager::CatalogueActionManagerPrivate {
29
30 CatalogueExplorer *m_CatalogueExplorer = nullptr;
31
32 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
33 : m_CatalogueExplorer(catalogueExplorer)
34 {
35 }
36
24 void createEventFromZones(const QString &eventName,
37 void createEventFromZones(const QString &eventName,
25 const QVector<VisualizationSelectionZoneItem *> &zones,
38 const QVector<VisualizationSelectionZoneItem *> &zones,
26 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
39 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
@@ -39,7 +52,8 struct CatalogueActionManager::CatalogueActionManagerPrivate {
39 eventProduct->setTStart(zoneRange.m_TStart);
52 eventProduct->setTStart(zoneRange.m_TStart);
40 eventProduct->setTEnd(zoneRange.m_TEnd);
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 productList.push_back(*eventProduct);
58 productList.push_back(*eventProduct);
45 }
59 }
@@ -49,15 +63,25 struct CatalogueActionManager::CatalogueActionManagerPrivate {
49
63
50 sqpApp->catalogueController().addEvent(event);
64 sqpApp->catalogueController().addEvent(event);
51
65
66
52 if (catalogue) {
67 if (catalogue) {
53 // TODO
68 // TODO
54 // catalogue->addEvent(event);
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()
83 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
60 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>()}
84 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
61 {
85 {
62 }
86 }
63
87
@@ -82,7 +106,8 void CatalogueActionManager::installSelectionZoneActions()
82
106
83 auto createEventAction = actionController.addSectionZoneAction(
107 auto createEventAction = actionController.addSectionZoneAction(
84 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
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 dialog.hideCatalogueChoice();
111 dialog.hideCatalogueChoice();
87 if (dialog.exec() == QDialog::Accepted) {
112 if (dialog.exec() == QDialog::Accepted) {
88 impl->createEventFromZones(dialog.eventName(), zones);
113 impl->createEventFromZones(dialog.eventName(), zones);
@@ -92,12 +117,16 void CatalogueActionManager::installSelectionZoneActions()
92
117
93 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
118 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
94 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
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 if (dialog.exec() == QDialog::Accepted) {
122 if (dialog.exec() == QDialog::Accepted) {
97 auto selectedCatalogue = dialog.selectedCatalogue();
123 auto selectedCatalogue = dialog.selectedCatalogue();
98 if (!selectedCatalogue) {
124 if (!selectedCatalogue) {
99 selectedCatalogue = std::make_shared<DBCatalogue>();
125 selectedCatalogue = std::make_shared<DBCatalogue>();
100 selectedCatalogue->setName(dialog.catalogueName());
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 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
132 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
@@ -1,5 +1,6
1 #include "Catalogue/CatalogueEventsModel.h"
1 #include "Catalogue/CatalogueEventsModel.h"
2
2
3 #include <Catalogue/CatalogueController.h>
3 #include <Common/DateUtils.h>
4 #include <Common/DateUtils.h>
4 #include <Common/MimeTypesDef.h>
5 #include <Common/MimeTypesDef.h>
5 #include <DBEvent.h>
6 #include <DBEvent.h>
@@ -23,7 +24,6 const auto EVENT_PRODUCT_ITEM_TYPE = 2;
23 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
24 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
24 QVector<std::shared_ptr<DBEvent> > m_Events;
25 QVector<std::shared_ptr<DBEvent> > m_Events;
25 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
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 QStringList columnNames()
28 QStringList columnNames()
29 {
29 {
@@ -34,8 +34,8 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
34 QVariant sortData(int col, const std::shared_ptr<DBEvent> &event) const
34 QVariant sortData(int col, const std::shared_ptr<DBEvent> &event) const
35 {
35 {
36 if (col == (int)CatalogueEventsModel::Column::Validation) {
36 if (col == (int)CatalogueEventsModel::Column::Validation) {
37 return m_EventsWithChanges.find(event) != m_EventsWithChanges.cend() ? true
37 auto hasChanges = sqpApp->catalogueController().eventHasChanges(event);
38 : QVariant();
38 return hasChanges ? true : QVariant();
39 }
39 }
40
40
41 return eventData(col, event);
41 return eventData(col, event);
@@ -114,6 +114,14 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
114 Q_ASSERT(false);
114 Q_ASSERT(false);
115 return QStringLiteral("Unknown Data");
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 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
127 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
@@ -127,7 +135,6 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &e
127
135
128 impl->m_Events = events;
136 impl->m_Events = events;
129 impl->m_EventProducts.clear();
137 impl->m_EventProducts.clear();
130 impl->m_EventsWithChanges.clear();
131 for (auto event : events) {
138 for (auto event : events) {
132 impl->parseEventProduct(event);
139 impl->parseEventProduct(event);
133 }
140 }
@@ -169,10 +176,14 CatalogueEventsModel::getEventProduct(const QModelIndex &index) const
169
176
170 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
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 impl->m_Events.append(event);
180 impl->m_Events.append(event);
174 impl->parseEventProduct(event);
181 impl->parseEventProduct(event);
175 endInsertRows();
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 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
189 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
@@ -182,7 +193,6 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
182 beginRemoveRows(QModelIndex(), index, index);
193 beginRemoveRows(QModelIndex(), index, index);
183 impl->m_Events.removeAt(index);
194 impl->m_Events.removeAt(index);
184 impl->m_EventProducts.erase(event.get());
195 impl->m_EventProducts.erase(event.get());
185 impl->m_EventsWithChanges.erase(event);
186 endRemoveRows();
196 endRemoveRows();
187 }
197 }
188 }
198 }
@@ -192,18 +202,41 QVector<std::shared_ptr<DBEvent> > CatalogueEventsModel::events() const
192 return impl->m_Events;
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 auto eventIndex = indexOf(event);
208 auto eventIndex = indexOf(event);
198 if (eventIndex.isValid()) {
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 // Refreshes the event line
234 // Refreshes the event line
201 auto colCount = columnCount();
235 auto colCount = columnCount();
202 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
236 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
203
237
204 // Also refreshes its children event products
238 // Also refreshes its children event products
205 auto childCount = rowCount(eventIndex);
239 impl->refreshChildrenOfIndex(this, eventIndex);
206 emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex));
207 }
240 }
208 else {
241 else {
209 qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found.";
242 qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found.";
@@ -220,22 +253,6 QModelIndex CatalogueEventsModel::indexOf(const std::shared_ptr<DBEvent> &event)
220 return QModelIndex();
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 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
256 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
240 {
257 {
241 if (!hasIndex(row, column, parent)) {
258 if (!hasIndex(row, column, parent)) {
@@ -354,6 +371,7 QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientati
354
371
355 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
372 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
356 {
373 {
374 beginResetModel();
357 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
375 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
358 [this, column, order](auto e1, auto e2) {
376 [this, column, order](auto e1, auto e2) {
359 auto data1 = impl->sortData(column, e1);
377 auto data1 = impl->sortData(column, e1);
@@ -364,13 +382,13 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
364 return order == Qt::AscendingOrder ? result : !result;
382 return order == Qt::AscendingOrder ? result : !result;
365 });
383 });
366
384
367 emit dataChanged(QModelIndex(), QModelIndex());
385 endResetModel();
368 emit modelSorted();
386 emit modelSorted();
369 }
387 }
370
388
371 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
389 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
372 {
390 {
373 return Qt::CopyAction | Qt::MoveAction;
391 return Qt::CopyAction;
374 }
392 }
375
393
376 QStringList CatalogueEventsModel::mimeTypes() const
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
436 if (!eventList.isEmpty() && eventProductList.isEmpty()) {
419 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
437 auto eventsEncodedData = sqpApp->catalogueController().mimeDataForEvents(eventList);
420 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
438 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
439 }
421
440
422 if (eventList.count() + eventProductList.count() == 1) {
441 if (eventList.count() + eventProductList.count() == 1) {
423 // No time range MIME data if multiple events are dragged
442 // No time range MIME data if multiple events are dragged
@@ -14,6 +14,7
14 #include <QDialog>
14 #include <QDialog>
15 #include <QDialogButtonBox>
15 #include <QDialogButtonBox>
16 #include <QListWidget>
16 #include <QListWidget>
17 #include <QMessageBox>
17
18
18 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19
20
@@ -25,14 +26,22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
25 CatalogueEventsModel *m_Model = nullptr;
26 CatalogueEventsModel *m_Model = nullptr;
26 QStringList m_ZonesForTimeMode;
27 QStringList m_ZonesForTimeMode;
27 QString m_ZoneForGraphMode;
28 QString m_ZoneForGraphMode;
29 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
28
30
29 VisualizationWidget *m_VisualizationWidget = nullptr;
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 m_Model->setEvents(events);
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 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
47 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
@@ -195,6 +204,22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
195 << "updateGraphMode: not compatible with multiple events selected";
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 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
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 QVector<std::shared_ptr<DBEvent> > events;
263 QVector<std::shared_ptr<DBEvent> > events;
239 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
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);
269 if (QMessageBox::warning(this, tr("Remove Event(s)"),
244 if (itemType == CatalogueEventsModel::ItemType::Event) {
270 tr("The selected event(s) will be completly removed "
245 events << impl->m_Model->getEvent(rowIndex);
271 "from the repository!\nAre you sure you want to continue?"),
246 }
272 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
247 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
273 == QMessageBox::Yes) {
248 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
249 impl->m_Model->getEventProduct(rowIndex));
250 }
251 }
252
274
253 if (!events.isEmpty() && eventProducts.isEmpty()) {
275 for (auto event : events) {
254 emit this->eventsSelected(events);
276 sqpApp->catalogueController().removeEvent(event);
255 }
277 impl->removeEvent(event, ui->treeView);
256 else if (events.isEmpty() && !eventProducts.isEmpty()) {
278 }
257 emit this->eventProductsSelected(eventProducts);
279 }
258 }
259 else {
260 emit this->selectionCleared();
261 }
280 }
262 };
281 });
263
282
264 connect(ui->treeView, &QTreeView::clicked, emitSelection);
283 connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection);
265 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, 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 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
288 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
268 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
289 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
269 ui->btnChart->setEnabled(isNotMultiSelection);
290 ui->btnChart->setEnabled(isNotMultiSelection);
@@ -275,13 +296,20 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
275 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
296 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
276 impl->updateForGraphMode(ui->treeView);
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 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
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 QHeaderView::Stretch);
308 QHeaderView::Stretch);
283 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
309 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
284 QHeaderView::Fixed);
310 QHeaderView::Fixed);
311 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
312 QHeaderView::Interactive);
285 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
313 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
286 VALIDATION_COLUMN_SIZE);
314 VALIDATION_COLUMN_SIZE);
287 ui->treeView->header()->setSortIndicatorShown(true);
315 ui->treeView->header()->setSortIndicatorShown(true);
@@ -289,9 +317,11 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
289 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
317 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
290 auto allEvents = impl->m_Model->events();
318 auto allEvents = impl->m_Model->events();
291 for (auto event : allEvents) {
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 CatalogueEventsWidget::~CatalogueEventsWidget()
327 CatalogueEventsWidget::~CatalogueEventsWidget()
@@ -304,6 +334,11 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualiz
304 impl->m_VisualizationWidget = visualization;
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 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
342 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
308 {
343 {
309 impl->m_Model->refreshEvent(event);
344 impl->m_Model->refreshEvent(event);
@@ -312,25 +347,55 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &even
312 auto validationIndex
347 auto validationIndex
313 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
348 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
314
349
315 if (hasChanges) {
350 if (validationIndex.isValid()) {
316 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
351 if (hasChanges) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
352 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
318 ui->treeView, [this, event]() { setEventChanges(event, false); },
353 auto widget = CatalogueExplorerHelper::buildValidationWidget(
319 [this, event]() { setEventChanges(event, false); });
354 ui->treeView,
320 ui->treeView->setIndexWidget(validationIndex, widget);
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 else {
373 else {
324 // Note: the widget is destroyed
374 qCWarning(LOG_CatalogueEventsWidget())
325 ui->treeView->setIndexWidget(validationIndex, nullptr);
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 void CatalogueEventsWidget::populateWithCatalogues(
394 void CatalogueEventsWidget::populateWithCatalogues(
332 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
395 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
333 {
396 {
397 impl->m_DisplayedCatalogues = catalogues;
398
334 QSet<QUuid> eventIds;
399 QSet<QUuid> eventIds;
335 QVector<std::shared_ptr<DBEvent> > events;
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 void CatalogueEventsWidget::populateWithAllEvents()
415 void CatalogueEventsWidget::populateWithAllEvents()
351 {
416 {
417 impl->m_DisplayedCatalogues.clear();
418
352 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
419 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
353
420
354 QVector<std::shared_ptr<DBEvent> > events;
421 QVector<std::shared_ptr<DBEvent> > events;
@@ -356,5 +423,38 void CatalogueEventsWidget::populateWithAllEvents()
356 events << event;
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 struct CatalogueExplorer::CatalogueExplorerPrivate {
12 struct CatalogueExplorer::CatalogueExplorerPrivate {
13 CatalogueActionManager m_ActionManager;
13 CatalogueActionManager m_ActionManager;
14
15 CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer)
16 : m_ActionManager(catalogueExplorer)
17 {
18 }
14 };
19 };
15
20
16 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
21 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
17 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
22 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
18 ui(new Ui::CatalogueExplorer),
23 ui(new Ui::CatalogueExplorer),
19 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()}
24 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>(this)}
20 {
25 {
21 ui->setupUi(this);
26 ui->setupUi(this);
22
27
@@ -37,16 +42,29 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
37 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
42 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
38 });
43 });
39
44
40 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
45 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, [this]() {
41 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
46 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
47 ui->events->clear();
48 });
42
49
43 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
50 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
44 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
51 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
45 ui->events->populateWithAllEvents();
52 ui->events->populateWithAllEvents();
46 });
53 });
47
54
48 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
55 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databaseList) {
49 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
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 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
69 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
52 if (events.count() == 1) {
70 if (events.count() == 1) {
@@ -81,7 +99,10 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
81 });
99 });
82
100
83 connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated,
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 CatalogueExplorer::~CatalogueExplorer()
108 CatalogueExplorer::~CatalogueExplorer()
@@ -93,3 +114,13 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualizatio
93 {
114 {
94 ui->events->setVisualizationWidget(visualization);
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 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
79 connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() {
80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
80 if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) {
81 auto oldProductId = m_DisplayedEventProduct->getProductId();
81 m_DisplayedEventProduct->setProductId(ui->leEventProduct->text());
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 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
97 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime());
88 if (time != m_DisplayedEventProduct->getTStart()) {
98 if (time != m_DisplayedEventProduct->getTStart()) {
89 m_DisplayedEventProduct->setTStart(time);
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 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
114 auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime());
96 if (time != m_DisplayedEventProduct->getTEnd()) {
115 if (time != m_DisplayedEventProduct->getTEnd()) {
97 m_DisplayedEventProduct->setTEnd(time);
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 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
173 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event,
146 const std::shared_ptr<DBEventProduct> &eventProduct)
174 const std::shared_ptr<DBEventProduct> &eventProduct)
147 {
175 {
176
177 impl->m_DisplayedEvent = event;
148 impl->m_DisplayedEventProduct = eventProduct;
178 impl->m_DisplayedEventProduct = eventProduct;
149
179
150 blockSignals(true);
180 blockSignals(true);
@@ -152,7 +182,7 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &e
152 showPage(Page::EventProperties);
182 showPage(Page::EventProperties);
153 ui->leEventName->setEnabled(false);
183 ui->leEventName->setEnabled(false);
154 ui->leEventName->setText(event->getName());
184 ui->leEventName->setText(event->getName());
155 ui->leEventProduct->setEnabled(true);
185 ui->leEventProduct->setEnabled(false);
156 ui->leEventProduct->setText(eventProduct->getProductId());
186 ui->leEventProduct->setText(eventProduct->getProductId());
157
187
158 ui->leEventTags->setEnabled(false);
188 ui->leEventTags->setEnabled(false);
@@ -3,7 +3,10
3 #include <SqpApplication.h>
3 #include <SqpApplication.h>
4
4
5 #include <Catalogue/CatalogueController.h>
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 #include <CatalogueDao.h>
10 #include <CatalogueDao.h>
8 #include <ComparaisonPredicate.h>
11 #include <ComparaisonPredicate.h>
9 #include <DBCatalogue.h>
12 #include <DBCatalogue.h>
@@ -13,22 +16,81
13 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
16 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
14
17
15
18
16 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
19 constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1;
17 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
20 constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2;
18 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
21 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
19 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
22 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
20
23
21
24
22 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
25 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
23
26
24 void configureTreeWidget(QTreeWidget *treeWidget);
27 CatalogueTreeModel *m_TreeModel = nullptr;
25 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
28
26 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
29 void configureTreeWidget(QTreeView *treeView);
30 QModelIndex addDatabaseItem(const QString &name);
31 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
27 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
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,
78 return catalogues;
31 QTreeWidget *treeWidget) const;
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 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
96 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
@@ -37,82 +99,53 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
37 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
99 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
38 {
100 {
39 ui->setupUi(this);
101 ui->setupUi(this);
40 impl->configureTreeWidget(ui->treeWidget);
41
102
42 ui->treeWidget->setColumnCount(2);
103 impl->m_TreeModel = new CatalogueTreeModel(this);
43 ui->treeWidget->header()->setStretchLastSection(false);
104 ui->treeView->setModel(impl->m_TreeModel);
44 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
105
45 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
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 auto emitSelection = [this]() {
112 auto emitSelection = [this]() {
48
113
49 auto selectedItems = ui->treeWidget->selectedItems();
114 auto selectionType = impl->selectionType(ui->treeView);
50 if (selectedItems.isEmpty()) {
115
51 emit this->selectionCleared();
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 {
133 };
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 }
80
134
81 switch (selectionType) {
135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
82 case CATALOGUE_ITEM_TYPE:
136 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
83 emit this->catalogueSelected(catalogues);
137 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
84 break;
138 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
85 case DATABASE_ITEM_TYPE:
139 if (selectedIndexes.contains(index)) {
86 emit this->databaseSelected(databases);
140 emitSelection();
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 }
98 }
141 }
99
142
143 auto item = impl->m_TreeModel->item(index);
144 impl->setHasChanges(true, index, ui->treeView);
145 });
100
146
101 };
147 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
102
148 connect(ui->treeView, &QTreeView::customContextMenuRequested, this,
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,
116 &CatalogueSideBarWidget::onContextMenuRequested);
149 &CatalogueSideBarWidget::onContextMenuRequested);
117 }
150 }
118
151
@@ -121,24 +154,54 CatalogueSideBarWidget::~CatalogueSideBarWidget()
121 delete ui;
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 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
164 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
125 bool hasChanges)
165 bool hasChanges)
126 {
166 {
127 if (auto catalogueItem = impl->getCatalogueItem(catalogue, ui->treeWidget)) {
167 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
128 catalogueItem->setHasChanges(hasChanges);
168 auto index = impl->m_TreeModel->indexOf(catalogueItem);
129 catalogueItem->refresh();
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 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
192 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
134 {
193 {
135 QMenu menu{this};
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 switch (currentItem->type()) {
202 switch (currentItem->type()) {
139 case CATALOGUE_ITEM_TYPE:
203 case CATALOGUE_ITEM_TYPE:
140 menu.addAction("Rename",
204 menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); });
141 [this, currentItem]() { ui->treeWidget->editItem(currentItem); });
142 break;
205 break;
143 case DATABASE_ITEM_TYPE:
206 case DATABASE_ITEM_TYPE:
144 break;
207 break;
@@ -154,59 +217,56 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
154 }
217 }
155
218
156 if (!menu.isEmpty()) {
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(
224 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView)
162 QTreeWidget *treeWidget)
163 {
225 {
164 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
226 auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events",
165 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
227 ALL_EVENT_ITEM_TYPE};
166 treeWidget->addTopLevelItem(allEventsItem);
228 auto allEventIndex = m_TreeModel->addTopLevelItem(allEventsItem);
229 treeView->setCurrentIndex(allEventIndex);
167
230
168 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
231 auto trashItem
169 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
232 = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE};
170 treeWidget->addTopLevelItem(trashItem);
233 m_TreeModel->addTopLevelItem(trashItem);
171
234
172 auto separator = new QFrame{treeWidget};
235 auto separator = new QFrame{treeView};
173 separator->setFrameShape(QFrame::HLine);
236 separator->setFrameShape(QFrame::HLine);
174 auto separatorItem = new QTreeWidgetItem{};
237 auto separatorItem
175 separatorItem->setFlags(Qt::NoItemFlags);
238 = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE};
176 treeWidget->addTopLevelItem(separatorItem);
239 separatorItem->setEnabled(false);
177 treeWidget->setItemWidget(separatorItem, 0, separator);
240 auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem);
241 treeView->setIndexWidget(separatorIndex, separator);
178
242
179 auto repositories = sqpApp->catalogueController().getRepositories();
243 auto repositories = sqpApp->catalogueController().getRepositories();
180 for (auto dbname : repositories) {
244 for (auto dbname : repositories) {
181 auto db = addDatabaseItem(dbname, treeWidget);
245 auto dbIndex = addDatabaseItem(dbname);
182
183 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
246 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
184 for (auto catalogue : catalogues) {
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 *
255 QModelIndex
193 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name,
256 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name)
194 QTreeWidget *treeWidget)
195 {
257 {
196 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
258 auto databaseItem
197 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
259 = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE};
198 treeWidget->addTopLevelItem(databaseItem);
260 auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem);
199
261
200 return databaseItem;
262 return databaseIndex;
201 }
263 }
202
264
203 QTreeWidgetItem *
265 CatalogueAbstractTreeItem *
204 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
266 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name)
205 QTreeWidget *treeWidget)
206 {
267 {
207 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
268 for (auto item : m_TreeModel->topLevelItems()) {
208 auto item = treeWidget->topLevelItem(i);
269 if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) {
209 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
210 return item;
270 return item;
211 }
271 }
212 }
272 }
@@ -215,23 +275,21 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QSt
215 }
275 }
216
276
217 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
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};
280 auto catalogueItem
221 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
281 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
222 parentDatabaseItem->addChild(catalogueItem);
282 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
223 }
283 }
224
284
225 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
285 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
226 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidget *treeWidget) const
286 const std::shared_ptr<DBCatalogue> &catalogue) const
227 {
287 {
228 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
288 for (auto item : m_TreeModel->topLevelItems()) {
229 auto item = treeWidget->topLevelItem(i);
230 if (item->type() == DATABASE_ITEM_TYPE) {
289 if (item->type() == DATABASE_ITEM_TYPE) {
231 for (auto j = 0; j < item->childCount(); ++j) {
290 for (auto childItem : item->children()) {
232 auto childItem = item->child(j);
233 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
291 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
234 auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem);
292 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
235 if (catalogueItem->catalogue() == catalogue) {
293 if (catalogueItem->catalogue() == catalogue) {
236 return catalogueItem;
294 return catalogueItem;
237 }
295 }
@@ -248,3 +306,32 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::
248
306
249 return nullptr;
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 #include <Catalogue/CatalogueExplorerHelper.h>
2 #include <Catalogue/CatalogueExplorerHelper.h>
3
3
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <Common/MimeTypesDef.h>
6 #include <QIcon>
7 #include <QMimeData>
5 #include <SqpApplication.h>
8 #include <SqpApplication.h>
6
9
7 #include <memory>
10 #include <memory>
8
11
9 #include <DBCatalogue.h>
12 #include <DBCatalogue.h>
10
13
11 /// Column in the tree widget where the apply and cancel buttons must appear
14 struct CatalogueTreeItem::CatalogueTreeItemPrivate {
12 const auto APPLY_CANCEL_BUTTONS_COLUMN = 1;
13
14 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
15
15
16 std::shared_ptr<DBCatalogue> m_Catalogue;
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)
26 CatalogueTreeItem::CatalogueTreeItem(std::shared_ptr<DBCatalogue> catalogue, const QIcon &icon,
25 : QTreeWidgetItem(type),
27 int type)
26 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
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 if (column == 0) {
35 if (column == 0) {
34 switch (role) {
36 switch (role) {
35 case Qt::EditRole: // fallthrough
37 case Qt::EditRole: // fallthrough
36 case Qt::DisplayRole:
38 case Qt::DisplayRole:
37 return impl->m_Catalogue->getName();
39 return impl->m_Catalogue->getName();
40 case Qt::DecorationRole:
41 return impl->m_Icon;
38 default:
42 default:
39 break;
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 if (role == Qt::EditRole && column == 0) {
54 if (role == Qt::EditRole && column == 0) {
49 auto newName = value.toString();
55 auto newName = value.toString();
50 if (newName != impl->m_Catalogue->getName()) {
56 if (newName != impl->m_Catalogue->getName()) {
51 setText(0, newName);
52 impl->m_Catalogue->setName(newName);
57 impl->m_Catalogue->setName(newName);
53 sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
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 return result;
63 {
64 return impl->m_Catalogue;
65 }
64 }
66
65
67 void CatalogueTreeWidgetItem::setHasChanges(bool value)
66 Qt::ItemFlags CatalogueTreeItem::flags(int column) const
68 {
67 {
69 if (value) {
68 if (column == 0) {
70 if (!hasChanges()) {
69 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable
71 auto widget = CatalogueExplorerHelper::buildValidationWidget(
70 | Qt::ItemIsDropEnabled;
72 treeWidget(), [this]() { setHasChanges(false); },
73 [this]() { setHasChanges(false); });
74 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, widget);
75 }
76 }
71 }
77 else {
72 else {
78 // Note: the widget is destroyed
73 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
79 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
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 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
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 : QDialog(parent),
15 : QDialog(parent),
15 ui(new Ui::CreateEventDialog),
16 ui(new Ui::CreateEventDialog),
16 impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()}
17 impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()}
@@ -20,10 +21,9 CreateEventDialog::CreateEventDialog(QWidget *parent)
20 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
21 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
21 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
22 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
22
23
23 auto catalogues = sqpApp->catalogueController().retrieveCatalogues();
24 impl->m_DisplayedCatalogues = catalogues;
24 for (auto cat : catalogues) {
25 for (auto cat : impl->m_DisplayedCatalogues) {
25 ui->cbCatalogue->addItem(cat->getName());
26 ui->cbCatalogue->addItem(cat->getName());
26 impl->m_DisplayedCatalogues << cat;
27 }
27 }
28 }
28 }
29
29
@@ -64,9 +64,6 public:
64 m_VariableControllerThread.setObjectName("VariableControllerThread");
64 m_VariableControllerThread.setObjectName("VariableControllerThread");
65 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
65 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
66 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
66 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
67 m_CatalogueController->moveToThread(&m_CatalogueControllerThread);
68 m_CatalogueControllerThread.setObjectName("CatalogueControllerThread");
69
70
67
71 // Additionnal init
68 // Additionnal init
72 m_VariableController->setTimeController(m_TimeController.get());
69 m_VariableController->setTimeController(m_TimeController.get());
@@ -85,9 +82,6 public:
85
82
86 m_VisualizationControllerThread.quit();
83 m_VisualizationControllerThread.quit();
87 m_VisualizationControllerThread.wait();
84 m_VisualizationControllerThread.wait();
88
89 m_CatalogueControllerThread.quit();
90 m_CatalogueControllerThread.wait();
91 }
85 }
92
86
93 std::unique_ptr<DataSourceController> m_DataSourceController;
87 std::unique_ptr<DataSourceController> m_DataSourceController;
@@ -101,7 +95,6 public:
101 QThread m_NetworkControllerThread;
95 QThread m_NetworkControllerThread;
102 QThread m_VariableControllerThread;
96 QThread m_VariableControllerThread;
103 QThread m_VisualizationControllerThread;
97 QThread m_VisualizationControllerThread;
104 QThread m_CatalogueControllerThread;
105
98
106 std::unique_ptr<DragDropGuiController> m_DragDropGuiController;
99 std::unique_ptr<DragDropGuiController> m_DragDropGuiController;
107 std::unique_ptr<ActionsGuiController> m_ActionsGuiController;
100 std::unique_ptr<ActionsGuiController> m_ActionsGuiController;
@@ -136,16 +129,11 SqpApplication::SqpApplication(int &argc, char **argv)
136 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
129 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
137 impl->m_VisualizationController.get(), &VisualizationController::finalize);
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 impl->m_DataSourceControllerThread.start();
132 impl->m_DataSourceControllerThread.start();
145 impl->m_NetworkControllerThread.start();
133 impl->m_NetworkControllerThread.start();
146 impl->m_VariableControllerThread.start();
134 impl->m_VariableControllerThread.start();
147 impl->m_VisualizationControllerThread.start();
135 impl->m_VisualizationControllerThread.start();
148 impl->m_CatalogueControllerThread.start();
136 impl->m_CatalogueController->initialize();
149 }
137 }
150
138
151 SqpApplication::~SqpApplication()
139 SqpApplication::~SqpApplication()
@@ -30,6 +30,9
30 <layout class="QHBoxLayout" name="horizontalLayout">
30 <layout class="QHBoxLayout" name="horizontalLayout">
31 <item>
31 <item>
32 <widget class="QToolButton" name="btnAdd">
32 <widget class="QToolButton" name="btnAdd">
33 <property name="enabled">
34 <bool>false</bool>
35 </property>
33 <property name="text">
36 <property name="text">
34 <string>+</string>
37 <string>+</string>
35 </property>
38 </property>
@@ -82,6 +85,9
82 </item>
85 </item>
83 <item>
86 <item>
84 <widget class="QToolButton" name="btnChart">
87 <widget class="QToolButton" name="btnChart">
88 <property name="enabled">
89 <bool>false</bool>
90 </property>
85 <property name="text">
91 <property name="text">
86 <string>G</string>
92 <string>G</string>
87 </property>
93 </property>
@@ -30,6 +30,9
30 <layout class="QHBoxLayout" name="horizontalLayout">
30 <layout class="QHBoxLayout" name="horizontalLayout">
31 <item>
31 <item>
32 <widget class="QToolButton" name="btnAdd">
32 <widget class="QToolButton" name="btnAdd">
33 <property name="enabled">
34 <bool>false</bool>
35 </property>
33 <property name="text">
36 <property name="text">
34 <string>+</string>
37 <string>+</string>
35 </property>
38 </property>
@@ -44,6 +47,9
44 </item>
47 </item>
45 <item>
48 <item>
46 <widget class="QToolButton" name="btnRemove">
49 <widget class="QToolButton" name="btnRemove">
50 <property name="enabled">
51 <bool>false</bool>
52 </property>
47 <property name="text">
53 <property name="text">
48 <string> - </string>
54 <string> - </string>
49 </property>
55 </property>
@@ -72,18 +78,22
72 </layout>
78 </layout>
73 </item>
79 </item>
74 <item>
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 <property name="selectionMode">
88 <property name="selectionMode">
77 <enum>QAbstractItemView::ExtendedSelection</enum>
89 <enum>QAbstractItemView::ExtendedSelection</enum>
78 </property>
90 </property>
79 <attribute name="headerVisible">
91 <attribute name="headerVisible">
80 <bool>false</bool>
92 <bool>false</bool>
81 </attribute>
93 </attribute>
82 <column>
94 <attribute name="headerStretchLastSection">
83 <property name="text">
95 <bool>false</bool>
84 <string notr="true">1</string>
96 </attribute>
85 </property>
86 </column>
87 </widget>
97 </widget>
88 </item>
98 </item>
89 </layout>
99 </layout>
@@ -37,6 +37,7 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
37 auto actionLabel = QObject::tr(
37 auto actionLabel = QObject::tr(
38 itemType == DataSourceItemType::PRODUCT ? "Load %1 product" : "Load %1 component");
38 itemType == DataSourceItemType::PRODUCT ? "Load %1 product" : "Load %1 component");
39 addLoadAction(actionLabel.arg(item.name()));
39 addLoadAction(actionLabel.arg(item.name()));
40 item.setData(DataSourceItem::ID_DATA_KEY, item.data(AMDA_XML_ID_KEY));
40 }
41 }
41
42
42 auto count = item.childCount();
43 auto count = item.childCount();
@@ -28,6 +28,7 std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
28
28
29 // Adds plugin name to product metadata
29 // Adds plugin name to product metadata
30 result->setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME);
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 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
33 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
33
34
1 NO CONTENT: file was removed
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