Auto status change to "Under Review"
@@ -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 | } |
@@ -1,65 +1,66 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SciQLop Software |
|
2 | -- This file is a part of the SciQLop Software | |
3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef SCIQLOP_MAINWINDOW_H |
|
22 | #ifndef SCIQLOP_MAINWINDOW_H | |
23 | #define SCIQLOP_MAINWINDOW_H |
|
23 | #define SCIQLOP_MAINWINDOW_H | |
24 |
|
24 | |||
25 | #include <QListWidgetItem> |
|
25 | #include <QListWidgetItem> | |
26 | #include <QLoggingCategory> |
|
26 | #include <QLoggingCategory> | |
27 | #include <QMainWindow> |
|
27 | #include <QMainWindow> | |
28 | #include <QProgressBar> |
|
28 | #include <QProgressBar> | |
29 | #include <QProgressDialog> |
|
29 | #include <QProgressDialog> | |
30 | #include <QThread> |
|
30 | #include <QThread> | |
31 | #include <QVBoxLayout> |
|
31 | #include <QVBoxLayout> | |
32 | #include <QWidget> |
|
32 | #include <QWidget> | |
33 |
|
33 | |||
34 | #include <Common/spimpl.h> |
|
34 | #include <Common/spimpl.h> | |
35 |
|
35 | |||
36 | #include <memory> |
|
36 | #include <memory> | |
37 |
|
37 | |||
38 | Q_DECLARE_LOGGING_CATEGORY(LOG_MainWindow) |
|
38 | Q_DECLARE_LOGGING_CATEGORY(LOG_MainWindow) | |
39 |
|
39 | |||
40 | namespace Ui { |
|
40 | namespace Ui { | |
41 | class MainWindow; |
|
41 | class MainWindow; | |
42 | } // namespace Ui |
|
42 | } // namespace Ui | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | class MainWindow : public QMainWindow { |
|
45 | class MainWindow : public QMainWindow { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 |
|
47 | |||
48 | public: |
|
48 | public: | |
49 | explicit MainWindow(QWidget *parent = 0); |
|
49 | explicit MainWindow(QWidget *parent = 0); | |
50 | virtual ~MainWindow(); |
|
50 | virtual ~MainWindow(); | |
51 | public slots: |
|
51 | 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; | |
58 | // QWidget *m_progressWidget; |
|
59 | // QWidget *m_progressWidget; | |
59 | // QVBoxLayout *m_progressLayout; |
|
60 | // QVBoxLayout *m_progressLayout; | |
60 | // QList<QLopService*> m_qlopServices; |
|
61 | // QList<QLopService*> m_qlopServices; | |
61 | class MainWindowPrivate; |
|
62 | class MainWindowPrivate; | |
62 | spimpl::unique_impl_ptr<MainWindowPrivate> impl; |
|
63 | spimpl::unique_impl_ptr<MainWindowPrivate> impl; | |
63 | }; |
|
64 | }; | |
64 |
|
65 | |||
65 | #endif // SCIQLOP_MAINWINDOW_H |
|
66 | #endif // SCIQLOP_MAINWINDOW_H |
@@ -1,89 +1,91 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "MainWindow.h" |
|
22 | #include "MainWindow.h" | |
23 | #include <QProcessEnvironment> |
|
23 | #include <QProcessEnvironment> | |
24 | #include <QThread> |
|
24 | #include <QThread> | |
25 | #include <SqpApplication.h> |
|
25 | #include <SqpApplication.h> | |
26 | #include <qglobal.h> |
|
26 | #include <qglobal.h> | |
27 |
|
27 | |||
28 | #include <Plugin/PluginManager.h> |
|
28 | #include <Plugin/PluginManager.h> | |
29 | #include <QDir> |
|
29 | #include <QDir> | |
30 | #include <QtPlugin> |
|
30 | #include <QtPlugin> | |
31 |
|
31 | |||
32 | #include <QLoggingCategory> |
|
32 | #include <QLoggingCategory> | |
33 |
|
33 | |||
34 | Q_LOGGING_CATEGORY(LOG_Main, "Main") |
|
34 | Q_LOGGING_CATEGORY(LOG_Main, "Main") | |
35 |
|
35 | |||
36 | namespace { |
|
36 | namespace { | |
37 |
|
37 | |||
38 | const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); |
|
38 | const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | } // namespace |
|
41 | } // namespace | |
42 |
|
42 | |||
43 | int main(int argc, char *argv[]) |
|
43 | int main(int argc, char *argv[]) | |
44 | { |
|
44 | { | |
45 | #ifdef QT_STATICPLUGIN |
|
45 | #ifdef QT_STATICPLUGIN | |
46 | Q_IMPORT_PLUGIN(MockPlugin) |
|
46 | Q_IMPORT_PLUGIN(MockPlugin) | |
47 | Q_IMPORT_PLUGIN(AmdaPlugin) |
|
47 | Q_IMPORT_PLUGIN(AmdaPlugin) | |
48 | Q_INIT_RESOURCE(amdaresources); |
|
48 | Q_INIT_RESOURCE(amdaresources); | |
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 | |||
59 | // Loads plugins |
|
61 | // Loads plugins | |
60 | auto pluginDir = QDir{a.applicationDirPath()}; |
|
62 | auto pluginDir = QDir{a.applicationDirPath()}; | |
61 | auto pluginLookupPath = { |
|
63 | auto pluginLookupPath = { | |
62 | a.applicationDirPath(), |
|
64 | a.applicationDirPath(), | |
63 | a.applicationDirPath() + "/" + PLUGIN_DIRECTORY_NAME, |
|
65 | a.applicationDirPath() + "/" + PLUGIN_DIRECTORY_NAME, | |
64 | a.applicationDirPath() + "/../lib64/SciQlop", |
|
66 | a.applicationDirPath() + "/../lib64/SciQlop", | |
65 | a.applicationDirPath() + "/../lib64/sciqlop", |
|
67 | a.applicationDirPath() + "/../lib64/sciqlop", | |
66 | a.applicationDirPath() + "/../lib/SciQlop", |
|
68 | a.applicationDirPath() + "/../lib/SciQlop", | |
67 | a.applicationDirPath() + "/../lib/sciqlop", |
|
69 | a.applicationDirPath() + "/../lib/sciqlop", | |
68 | a.applicationDirPath() + "/../plugins", |
|
70 | a.applicationDirPath() + "/../plugins", | |
69 | }; |
|
71 | }; | |
70 |
|
72 | |||
71 | #if _WIN32 || _WIN64 |
|
73 | #if _WIN32 || _WIN64 | |
72 | pluginDir.mkdir(PLUGIN_DIRECTORY_NAME); |
|
74 | pluginDir.mkdir(PLUGIN_DIRECTORY_NAME); | |
73 | pluginDir.cd(PLUGIN_DIRECTORY_NAME); |
|
75 | pluginDir.cd(PLUGIN_DIRECTORY_NAME); | |
74 | #endif |
|
76 | #endif | |
75 |
|
77 | |||
76 | PluginManager pluginManager{}; |
|
78 | PluginManager pluginManager{}; | |
77 |
|
79 | |||
78 | for (auto &&path : pluginLookupPath) { |
|
80 | for (auto &&path : pluginLookupPath) { | |
79 | QDir directory{path}; |
|
81 | QDir directory{path}; | |
80 | if (directory.exists()) { |
|
82 | if (directory.exists()) { | |
81 | qCDebug(LOG_Main()) |
|
83 | qCDebug(LOG_Main()) | |
82 | << QObject::tr("Plugin directory: %1").arg(directory.absolutePath()); |
|
84 | << QObject::tr("Plugin directory: %1").arg(directory.absolutePath()); | |
83 | pluginManager.loadPlugins(directory); |
|
85 | pluginManager.loadPlugins(directory); | |
84 | } |
|
86 | } | |
85 | } |
|
87 | } | |
86 | pluginManager.loadStaticPlugins(); |
|
88 | pluginManager.loadStaticPlugins(); | |
87 |
|
89 | |||
88 | return a.exec(); |
|
90 | return a.exec(); | |
89 | } |
|
91 | } |
@@ -1,366 +1,405 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SciQLop Software |
|
2 | -- This file is a part of the SciQLop Software | |
3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
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> | |
28 | #include <Settings/SqpSettingsDialog.h> |
|
29 | #include <Settings/SqpSettingsDialog.h> | |
29 | #include <Settings/SqpSettingsGeneralWidget.h> |
|
30 | #include <Settings/SqpSettingsGeneralWidget.h> | |
30 | #include <SidePane/SqpSidePane.h> |
|
31 | #include <SidePane/SqpSidePane.h> | |
31 | #include <SqpApplication.h> |
|
32 | #include <SqpApplication.h> | |
32 | #include <Time/TimeController.h> |
|
33 | #include <Time/TimeController.h> | |
33 | #include <TimeWidget/TimeWidget.h> |
|
34 | #include <TimeWidget/TimeWidget.h> | |
34 | #include <Variable/Variable.h> |
|
35 | #include <Variable/Variable.h> | |
35 | #include <Variable/VariableController.h> |
|
36 | #include <Variable/VariableController.h> | |
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> | |
45 |
|
48 | |||
46 | #include "iostream" |
|
49 | #include "iostream" | |
47 |
|
50 | |||
48 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") |
|
51 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") | |
49 |
|
52 | |||
50 | namespace { |
|
53 | namespace { | |
51 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; |
|
54 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; | |
52 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; |
|
55 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; | |
53 | const auto VIEWPLITTERINDEX = 2; |
|
56 | const auto VIEWPLITTERINDEX = 2; | |
54 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; |
|
57 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; | |
55 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; |
|
58 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; | |
56 | } |
|
59 | } | |
57 |
|
60 | |||
58 | class MainWindow::MainWindowPrivate { |
|
61 | class MainWindow::MainWindowPrivate { | |
59 | public: |
|
62 | public: | |
60 | explicit MainWindowPrivate(MainWindow *mainWindow) |
|
63 | explicit MainWindowPrivate(MainWindow *mainWindow) | |
61 | : m_LastOpenLeftInspectorSize{}, |
|
64 | : m_LastOpenLeftInspectorSize{}, | |
62 | m_LastOpenRightInspectorSize{}, |
|
65 | m_LastOpenRightInspectorSize{}, | |
63 | m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}}, |
|
66 | m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}}, | |
64 | m_SettingsDialog{new SqpSettingsDialog{mainWindow}}, |
|
67 | m_SettingsDialog{new SqpSettingsDialog{mainWindow}}, | |
65 | m_CatalogExplorer{new CatalogueExplorer{mainWindow}} |
|
68 | m_CatalogExplorer{new CatalogueExplorer{mainWindow}} | |
66 | { |
|
69 | { | |
67 | } |
|
70 | } | |
68 |
|
71 | |||
69 | QSize m_LastOpenLeftInspectorSize; |
|
72 | QSize m_LastOpenLeftInspectorSize; | |
70 | QSize m_LastOpenRightInspectorSize; |
|
73 | QSize m_LastOpenRightInspectorSize; | |
71 | /// General settings widget. MainWindow has the ownership |
|
74 | /// General settings widget. MainWindow has the ownership | |
72 | SqpSettingsGeneralWidget *m_GeneralSettingsWidget; |
|
75 | SqpSettingsGeneralWidget *m_GeneralSettingsWidget; | |
73 | /// Settings dialog. MainWindow has the ownership |
|
76 | /// Settings dialog. MainWindow has the ownership | |
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) | |
80 | : QMainWindow{parent}, |
|
85 | : QMainWindow{parent}, | |
81 | m_Ui{new Ui::MainWindow}, |
|
86 | m_Ui{new Ui::MainWindow}, | |
82 | impl{spimpl::make_unique_impl<MainWindowPrivate>(this)} |
|
87 | impl{spimpl::make_unique_impl<MainWindowPrivate>(this)} | |
83 | { |
|
88 | { | |
84 | m_Ui->setupUi(this); |
|
89 | m_Ui->setupUi(this); | |
85 |
|
90 | |||
86 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
91 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); | |
87 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
92 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); | |
88 |
|
93 | |||
89 | impl->m_CatalogExplorer->setVisualizationWidget(m_Ui->view); |
|
94 | impl->m_CatalogExplorer->setVisualizationWidget(m_Ui->view); | |
90 |
|
95 | |||
91 |
|
96 | |||
92 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); |
|
97 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); | |
93 | auto openLeftInspectorAction = new QAction{QIcon{ |
|
98 | auto openLeftInspectorAction = new QAction{QIcon{ | |
94 | ":/icones/previous.png", |
|
99 | ":/icones/previous.png", | |
95 | }, |
|
100 | }, | |
96 | tr("Show/hide the left inspector"), this}; |
|
101 | tr("Show/hide the left inspector"), this}; | |
97 |
|
102 | |||
98 |
|
103 | |||
99 | auto spacerLeftTop = new QWidget{}; |
|
104 | auto spacerLeftTop = new QWidget{}; | |
100 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
105 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
101 |
|
106 | |||
102 | auto spacerLeftBottom = new QWidget{}; |
|
107 | auto spacerLeftBottom = new QWidget{}; | |
103 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
108 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
104 |
|
109 | |||
105 | leftSidePane->addWidget(spacerLeftTop); |
|
110 | leftSidePane->addWidget(spacerLeftTop); | |
106 | leftSidePane->addAction(openLeftInspectorAction); |
|
111 | leftSidePane->addAction(openLeftInspectorAction); | |
107 | leftSidePane->addWidget(spacerLeftBottom); |
|
112 | leftSidePane->addWidget(spacerLeftBottom); | |
108 |
|
113 | |||
109 |
|
114 | |||
110 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); |
|
115 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); | |
111 | auto openRightInspectorAction = new QAction{QIcon{ |
|
116 | auto openRightInspectorAction = new QAction{QIcon{ | |
112 | ":/icones/next.png", |
|
117 | ":/icones/next.png", | |
113 | }, |
|
118 | }, | |
114 | tr("Show/hide the right inspector"), this}; |
|
119 | tr("Show/hide the right inspector"), this}; | |
115 |
|
120 | |||
116 | auto spacerRightTop = new QWidget{}; |
|
121 | auto spacerRightTop = new QWidget{}; | |
117 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
122 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
118 |
|
123 | |||
119 | auto spacerRightBottom = new QWidget{}; |
|
124 | auto spacerRightBottom = new QWidget{}; | |
120 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
125 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
121 |
|
126 | |||
122 | rightSidePane->addWidget(spacerRightTop); |
|
127 | rightSidePane->addWidget(spacerRightTop); | |
123 | rightSidePane->addAction(openRightInspectorAction); |
|
128 | rightSidePane->addAction(openRightInspectorAction); | |
124 | rightSidePane->addWidget(spacerRightBottom); |
|
129 | rightSidePane->addWidget(spacerRightBottom); | |
125 |
|
130 | |||
126 | openLeftInspectorAction->setCheckable(true); |
|
131 | openLeftInspectorAction->setCheckable(true); | |
127 | openRightInspectorAction->setCheckable(true); |
|
132 | openRightInspectorAction->setCheckable(true); | |
128 |
|
133 | |||
129 | auto openInspector = [this](bool checked, bool right, auto action) { |
|
134 | auto openInspector = [this](bool checked, bool right, auto action) { | |
130 |
|
135 | |||
131 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); |
|
136 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); | |
132 |
|
137 | |||
133 | auto &lastInspectorSize |
|
138 | auto &lastInspectorSize | |
134 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; |
|
139 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; | |
135 |
|
140 | |||
136 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() |
|
141 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() | |
137 | : m_Ui->leftMainInspectorWidget->size(); |
|
142 | : m_Ui->leftMainInspectorWidget->size(); | |
138 |
|
143 | |||
139 | // Update of the last opened geometry |
|
144 | // Update of the last opened geometry | |
140 | if (checked) { |
|
145 | if (checked) { | |
141 | lastInspectorSize = nextInspectorSize; |
|
146 | lastInspectorSize = nextInspectorSize; | |
142 | } |
|
147 | } | |
143 |
|
148 | |||
144 | auto startSize = lastInspectorSize; |
|
149 | auto startSize = lastInspectorSize; | |
145 | auto endSize = startSize; |
|
150 | auto endSize = startSize; | |
146 | endSize.setWidth(0); |
|
151 | endSize.setWidth(0); | |
147 |
|
152 | |||
148 | auto splitterInspectorIndex |
|
153 | auto splitterInspectorIndex | |
149 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; |
|
154 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; | |
150 |
|
155 | |||
151 | auto currentSizes = m_Ui->splitter->sizes(); |
|
156 | auto currentSizes = m_Ui->splitter->sizes(); | |
152 | if (checked) { |
|
157 | if (checked) { | |
153 | // adjust sizes individually here, e.g. |
|
158 | // adjust sizes individually here, e.g. | |
154 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); |
|
159 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); | |
155 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); |
|
160 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); | |
156 | m_Ui->splitter->setSizes(currentSizes); |
|
161 | m_Ui->splitter->setSizes(currentSizes); | |
157 | } |
|
162 | } | |
158 | else { |
|
163 | else { | |
159 | // adjust sizes individually here, e.g. |
|
164 | // adjust sizes individually here, e.g. | |
160 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); |
|
165 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); | |
161 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); |
|
166 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); | |
162 | m_Ui->splitter->setSizes(currentSizes); |
|
167 | m_Ui->splitter->setSizes(currentSizes); | |
163 | } |
|
168 | } | |
164 |
|
169 | |||
165 | }; |
|
170 | }; | |
166 |
|
171 | |||
167 |
|
172 | |||
168 | connect(openLeftInspectorAction, &QAction::triggered, |
|
173 | connect(openLeftInspectorAction, &QAction::triggered, | |
169 | [openInspector, openLeftInspectorAction](bool checked) { |
|
174 | [openInspector, openLeftInspectorAction](bool checked) { | |
170 | openInspector(checked, false, openLeftInspectorAction); |
|
175 | openInspector(checked, false, openLeftInspectorAction); | |
171 | }); |
|
176 | }); | |
172 | connect(openRightInspectorAction, &QAction::triggered, |
|
177 | connect(openRightInspectorAction, &QAction::triggered, | |
173 | [openInspector, openRightInspectorAction](bool checked) { |
|
178 | [openInspector, openRightInspectorAction](bool checked) { | |
174 | openInspector(checked, true, openRightInspectorAction); |
|
179 | openInspector(checked, true, openRightInspectorAction); | |
175 | }); |
|
180 | }); | |
176 |
|
181 | |||
177 | // //////////////// // |
|
182 | // //////////////// // | |
178 | // Menu and Toolbar // |
|
183 | // Menu and Toolbar // | |
179 | // //////////////// // |
|
184 | // //////////////// // | |
180 | this->menuBar()->addAction(tr("File")); |
|
185 | this->menuBar()->addAction(tr("File")); | |
181 | auto toolsMenu = this->menuBar()->addMenu(tr("Tools")); |
|
186 | auto toolsMenu = this->menuBar()->addMenu(tr("Tools")); | |
182 | toolsMenu->addAction(tr("Settings..."), [this]() { |
|
187 | toolsMenu->addAction(tr("Settings..."), [this]() { | |
183 | // Loads settings |
|
188 | // Loads settings | |
184 | impl->m_SettingsDialog->loadSettings(); |
|
189 | impl->m_SettingsDialog->loadSettings(); | |
185 |
|
190 | |||
186 | // Open settings dialog and save settings if the dialog is accepted |
|
191 | // Open settings dialog and save settings if the dialog is accepted | |
187 | if (impl->m_SettingsDialog->exec() == QDialog::Accepted) { |
|
192 | if (impl->m_SettingsDialog->exec() == QDialog::Accepted) { | |
188 | impl->m_SettingsDialog->saveSettings(); |
|
193 | impl->m_SettingsDialog->saveSettings(); | |
189 | } |
|
194 | } | |
190 |
|
195 | |||
191 | }); |
|
196 | }); | |
192 |
|
197 | |||
193 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); |
|
198 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); | |
194 |
|
199 | |||
195 | auto timeWidget = new TimeWidget{}; |
|
200 | auto timeWidget = new TimeWidget{}; | |
196 | mainToolBar->addWidget(timeWidget); |
|
201 | mainToolBar->addWidget(timeWidget); | |
197 |
|
202 | |||
198 | // Interaction modes |
|
203 | // Interaction modes | |
199 | auto actionPointerMode = new QAction{QIcon(":/icones/pointer.png"), "Move", this}; |
|
204 | auto actionPointerMode = new QAction{QIcon(":/icones/pointer.png"), "Move", this}; | |
200 | actionPointerMode->setCheckable(true); |
|
205 | actionPointerMode->setCheckable(true); | |
201 | actionPointerMode->setChecked(sqpApp->plotsInteractionMode() |
|
206 | actionPointerMode->setChecked(sqpApp->plotsInteractionMode() | |
202 | == SqpApplication::PlotsInteractionMode::None); |
|
207 | == SqpApplication::PlotsInteractionMode::None); | |
203 | connect(actionPointerMode, &QAction::triggered, |
|
208 | connect(actionPointerMode, &QAction::triggered, | |
204 | []() { sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::None); }); |
|
209 | []() { sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::None); }); | |
205 |
|
210 | |||
206 | auto actionZoomMode = new QAction{QIcon(":/icones/zoom.png"), "Zoom", this}; |
|
211 | auto actionZoomMode = new QAction{QIcon(":/icones/zoom.png"), "Zoom", this}; | |
207 | actionZoomMode->setCheckable(true); |
|
212 | actionZoomMode->setCheckable(true); | |
208 | actionZoomMode->setChecked(sqpApp->plotsInteractionMode() |
|
213 | actionZoomMode->setChecked(sqpApp->plotsInteractionMode() | |
209 | == SqpApplication::PlotsInteractionMode::ZoomBox); |
|
214 | == SqpApplication::PlotsInteractionMode::ZoomBox); | |
210 | connect(actionZoomMode, &QAction::triggered, []() { |
|
215 | connect(actionZoomMode, &QAction::triggered, []() { | |
211 | sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::ZoomBox); |
|
216 | sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::ZoomBox); | |
212 | }); |
|
217 | }); | |
213 |
|
218 | |||
214 | auto actionOrganisationMode = new QAction{QIcon(":/icones/drag.png"), "Organize", this}; |
|
219 | auto actionOrganisationMode = new QAction{QIcon(":/icones/drag.png"), "Organize", this}; | |
215 | actionOrganisationMode->setCheckable(true); |
|
220 | actionOrganisationMode->setCheckable(true); | |
216 | actionOrganisationMode->setChecked(sqpApp->plotsInteractionMode() |
|
221 | actionOrganisationMode->setChecked(sqpApp->plotsInteractionMode() | |
217 | == SqpApplication::PlotsInteractionMode::DragAndDrop); |
|
222 | == SqpApplication::PlotsInteractionMode::DragAndDrop); | |
218 | connect(actionOrganisationMode, &QAction::triggered, []() { |
|
223 | connect(actionOrganisationMode, &QAction::triggered, []() { | |
219 | sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::DragAndDrop); |
|
224 | sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::DragAndDrop); | |
220 | }); |
|
225 | }); | |
221 |
|
226 | |||
222 | auto actionZonesMode = new QAction{QIcon(":/icones/rectangle.png"), "Zones", this}; |
|
227 | auto actionZonesMode = new QAction{QIcon(":/icones/rectangle.png"), "Zones", this}; | |
223 | actionZonesMode->setCheckable(true); |
|
228 | actionZonesMode->setCheckable(true); | |
224 | actionZonesMode->setChecked(sqpApp->plotsInteractionMode() |
|
229 | actionZonesMode->setChecked(sqpApp->plotsInteractionMode() | |
225 | == SqpApplication::PlotsInteractionMode::SelectionZones); |
|
230 | == SqpApplication::PlotsInteractionMode::SelectionZones); | |
226 | connect(actionZonesMode, &QAction::triggered, []() { |
|
231 | connect(actionZonesMode, &QAction::triggered, []() { | |
227 | sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::SelectionZones); |
|
232 | sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::SelectionZones); | |
228 | }); |
|
233 | }); | |
229 |
|
234 | |||
230 | auto modeActionGroup = new QActionGroup{this}; |
|
235 | auto modeActionGroup = new QActionGroup{this}; | |
231 | modeActionGroup->addAction(actionZoomMode); |
|
236 | modeActionGroup->addAction(actionZoomMode); | |
232 | modeActionGroup->addAction(actionZonesMode); |
|
237 | modeActionGroup->addAction(actionZonesMode); | |
233 | modeActionGroup->addAction(actionOrganisationMode); |
|
238 | modeActionGroup->addAction(actionOrganisationMode); | |
234 | modeActionGroup->addAction(actionPointerMode); |
|
239 | modeActionGroup->addAction(actionPointerMode); | |
235 | modeActionGroup->setExclusive(true); |
|
240 | modeActionGroup->setExclusive(true); | |
236 |
|
241 | |||
237 | mainToolBar->addSeparator(); |
|
242 | mainToolBar->addSeparator(); | |
238 | mainToolBar->addAction(actionPointerMode); |
|
243 | mainToolBar->addAction(actionPointerMode); | |
239 | mainToolBar->addAction(actionZoomMode); |
|
244 | mainToolBar->addAction(actionZoomMode); | |
240 | mainToolBar->addAction(actionOrganisationMode); |
|
245 | mainToolBar->addAction(actionOrganisationMode); | |
241 | mainToolBar->addAction(actionZonesMode); |
|
246 | mainToolBar->addAction(actionZonesMode); | |
242 | mainToolBar->addSeparator(); |
|
247 | mainToolBar->addSeparator(); | |
243 |
|
248 | |||
244 | // Cursors |
|
249 | // Cursors | |
245 | auto btnCursor = new QToolButton{this}; |
|
250 | auto btnCursor = new QToolButton{this}; | |
246 | btnCursor->setIcon(QIcon(":/icones/cursor.png")); |
|
251 | btnCursor->setIcon(QIcon(":/icones/cursor.png")); | |
247 | btnCursor->setText("Cursor"); |
|
252 | btnCursor->setText("Cursor"); | |
248 | btnCursor->setToolTip("Cursor"); |
|
253 | btnCursor->setToolTip("Cursor"); | |
249 | btnCursor->setPopupMode(QToolButton::InstantPopup); |
|
254 | btnCursor->setPopupMode(QToolButton::InstantPopup); | |
250 | auto cursorMenu = new QMenu("CursorMenu", this); |
|
255 | auto cursorMenu = new QMenu("CursorMenu", this); | |
251 | btnCursor->setMenu(cursorMenu); |
|
256 | btnCursor->setMenu(cursorMenu); | |
252 |
|
257 | |||
253 | auto noCursorAction = cursorMenu->addAction("No Cursor"); |
|
258 | auto noCursorAction = cursorMenu->addAction("No Cursor"); | |
254 | noCursorAction->setCheckable(true); |
|
259 | noCursorAction->setCheckable(true); | |
255 | noCursorAction->setChecked(sqpApp->plotsCursorMode() |
|
260 | noCursorAction->setChecked(sqpApp->plotsCursorMode() | |
256 | == SqpApplication::PlotsCursorMode::NoCursor); |
|
261 | == SqpApplication::PlotsCursorMode::NoCursor); | |
257 | connect(noCursorAction, &QAction::triggered, |
|
262 | connect(noCursorAction, &QAction::triggered, | |
258 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::NoCursor); }); |
|
263 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::NoCursor); }); | |
259 |
|
264 | |||
260 | cursorMenu->addSeparator(); |
|
265 | cursorMenu->addSeparator(); | |
261 | auto verticalCursorAction = cursorMenu->addAction("Vertical Cursor"); |
|
266 | auto verticalCursorAction = cursorMenu->addAction("Vertical Cursor"); | |
262 | verticalCursorAction->setCheckable(true); |
|
267 | verticalCursorAction->setCheckable(true); | |
263 | verticalCursorAction->setChecked(sqpApp->plotsCursorMode() |
|
268 | verticalCursorAction->setChecked(sqpApp->plotsCursorMode() | |
264 | == SqpApplication::PlotsCursorMode::Vertical); |
|
269 | == SqpApplication::PlotsCursorMode::Vertical); | |
265 | connect(verticalCursorAction, &QAction::triggered, |
|
270 | connect(verticalCursorAction, &QAction::triggered, | |
266 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Vertical); }); |
|
271 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Vertical); }); | |
267 |
|
272 | |||
268 | auto temporalCursorAction = cursorMenu->addAction("Temporal Cursor"); |
|
273 | auto temporalCursorAction = cursorMenu->addAction("Temporal Cursor"); | |
269 | temporalCursorAction->setCheckable(true); |
|
274 | temporalCursorAction->setCheckable(true); | |
270 | temporalCursorAction->setChecked(sqpApp->plotsCursorMode() |
|
275 | temporalCursorAction->setChecked(sqpApp->plotsCursorMode() | |
271 | == SqpApplication::PlotsCursorMode::Temporal); |
|
276 | == SqpApplication::PlotsCursorMode::Temporal); | |
272 | connect(temporalCursorAction, &QAction::triggered, |
|
277 | connect(temporalCursorAction, &QAction::triggered, | |
273 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Temporal); }); |
|
278 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Temporal); }); | |
274 |
|
279 | |||
275 | auto horizontalCursorAction = cursorMenu->addAction("Horizontal Cursor"); |
|
280 | auto horizontalCursorAction = cursorMenu->addAction("Horizontal Cursor"); | |
276 | horizontalCursorAction->setCheckable(true); |
|
281 | horizontalCursorAction->setCheckable(true); | |
277 | horizontalCursorAction->setChecked(sqpApp->plotsCursorMode() |
|
282 | horizontalCursorAction->setChecked(sqpApp->plotsCursorMode() | |
278 | == SqpApplication::PlotsCursorMode::Horizontal); |
|
283 | == SqpApplication::PlotsCursorMode::Horizontal); | |
279 | connect(horizontalCursorAction, &QAction::triggered, |
|
284 | connect(horizontalCursorAction, &QAction::triggered, | |
280 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Horizontal); }); |
|
285 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Horizontal); }); | |
281 |
|
286 | |||
282 | auto crossCursorAction = cursorMenu->addAction("Cross Cursor"); |
|
287 | auto crossCursorAction = cursorMenu->addAction("Cross Cursor"); | |
283 | crossCursorAction->setCheckable(true); |
|
288 | crossCursorAction->setCheckable(true); | |
284 | crossCursorAction->setChecked(sqpApp->plotsCursorMode() |
|
289 | crossCursorAction->setChecked(sqpApp->plotsCursorMode() | |
285 | == SqpApplication::PlotsCursorMode::Cross); |
|
290 | == SqpApplication::PlotsCursorMode::Cross); | |
286 | connect(crossCursorAction, &QAction::triggered, |
|
291 | connect(crossCursorAction, &QAction::triggered, | |
287 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Cross); }); |
|
292 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Cross); }); | |
288 |
|
293 | |||
289 | mainToolBar->addWidget(btnCursor); |
|
294 | mainToolBar->addWidget(btnCursor); | |
290 |
|
295 | |||
291 | auto cursorModeActionGroup = new QActionGroup{this}; |
|
296 | auto cursorModeActionGroup = new QActionGroup{this}; | |
292 | cursorModeActionGroup->setExclusive(true); |
|
297 | cursorModeActionGroup->setExclusive(true); | |
293 | cursorModeActionGroup->addAction(noCursorAction); |
|
298 | cursorModeActionGroup->addAction(noCursorAction); | |
294 | cursorModeActionGroup->addAction(verticalCursorAction); |
|
299 | cursorModeActionGroup->addAction(verticalCursorAction); | |
295 | cursorModeActionGroup->addAction(temporalCursorAction); |
|
300 | cursorModeActionGroup->addAction(temporalCursorAction); | |
296 | cursorModeActionGroup->addAction(horizontalCursorAction); |
|
301 | cursorModeActionGroup->addAction(horizontalCursorAction); | |
297 | cursorModeActionGroup->addAction(crossCursorAction); |
|
302 | cursorModeActionGroup->addAction(crossCursorAction); | |
298 |
|
303 | |||
299 | // Catalog |
|
304 | // Catalog | |
300 | mainToolBar->addSeparator(); |
|
305 | mainToolBar->addSeparator(); | |
301 | mainToolBar->addAction(QIcon(":/icones/catalogue.png"), "Catalogues", |
|
306 | mainToolBar->addAction(QIcon(":/icones/catalogue.png"), "Catalogues", | |
302 | [this]() { impl->m_CatalogExplorer->show(); }); |
|
307 | [this]() { impl->m_CatalogExplorer->show(); }); | |
303 |
|
308 | |||
304 | // //////// // |
|
309 | // //////// // | |
305 | // Settings // |
|
310 | // Settings // | |
306 | // //////// // |
|
311 | // //////// // | |
307 |
|
312 | |||
308 | // Registers "general settings" widget to the settings dialog |
|
313 | // Registers "general settings" widget to the settings dialog | |
309 | impl->m_SettingsDialog->registerWidget(QStringLiteral("General"), |
|
314 | impl->m_SettingsDialog->registerWidget(QStringLiteral("General"), | |
310 | impl->m_GeneralSettingsWidget); |
|
315 | impl->m_GeneralSettingsWidget); | |
311 |
|
316 | |||
312 | // /////////// // |
|
317 | // /////////// // | |
313 | // Connections // |
|
318 | // Connections // | |
314 | // /////////// // |
|
319 | // /////////// // | |
315 |
|
320 | |||
316 | // Controllers / controllers connections |
|
321 | // Controllers / controllers connections | |
317 | connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpRange)), &sqpApp->variableController(), |
|
322 | connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpRange)), &sqpApp->variableController(), | |
318 | SLOT(onDateTimeOnSelection(SqpRange))); |
|
323 | SLOT(onDateTimeOnSelection(SqpRange))); | |
319 |
|
324 | |||
320 | // Widgets / controllers connections |
|
325 | // Widgets / controllers connections | |
321 |
|
326 | |||
322 | // DataSource |
|
327 | // DataSource | |
323 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), |
|
328 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), | |
324 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); |
|
329 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); | |
325 |
|
330 | |||
326 | // Time |
|
331 | // Time | |
327 | connect(timeWidget, SIGNAL(timeUpdated(SqpRange)), &sqpApp->timeController(), |
|
332 | connect(timeWidget, SIGNAL(timeUpdated(SqpRange)), &sqpApp->timeController(), | |
328 | SLOT(onTimeToUpdate(SqpRange))); |
|
333 | SLOT(onTimeToUpdate(SqpRange))); | |
329 |
|
334 | |||
330 | // Visualization |
|
335 | // Visualization | |
331 | connect(&sqpApp->visualizationController(), |
|
336 | connect(&sqpApp->visualizationController(), | |
332 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view, |
|
337 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view, | |
333 | SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>))); |
|
338 | SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>))); | |
334 |
|
339 | |||
335 | connect(&sqpApp->visualizationController(), |
|
340 | connect(&sqpApp->visualizationController(), | |
336 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), m_Ui->view, |
|
341 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), m_Ui->view, | |
337 | SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpRange &))); |
|
342 | SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpRange &))); | |
338 |
|
343 | |||
339 | // Widgets / widgets connections |
|
344 | // Widgets / widgets connections | |
340 |
|
345 | |||
341 | // For the following connections, we use DirectConnection to allow each widget that can |
|
346 | // For the following connections, we use DirectConnection to allow each widget that can | |
342 | // potentially attach a menu to the variable's menu to do so before this menu is displayed. |
|
347 | // potentially attach a menu to the variable's menu to do so before this menu is displayed. | |
343 | // The order of connections is also important, since it determines the order in which each |
|
348 | // The order of connections is also important, since it determines the order in which each | |
344 | // widget will attach its menu |
|
349 | // widget will attach its menu | |
345 | connect( |
|
350 | connect( | |
346 | m_Ui->variableInspectorWidget, |
|
351 | m_Ui->variableInspectorWidget, | |
347 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), |
|
352 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | |
348 | m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), |
|
353 | m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | |
349 | Qt::DirectConnection); |
|
354 | Qt::DirectConnection); | |
350 | } |
|
355 | } | |
351 |
|
356 | |||
352 | MainWindow::~MainWindow() |
|
357 | MainWindow::~MainWindow() | |
353 | { |
|
358 | { | |
354 | } |
|
359 | } | |
355 |
|
360 | |||
356 | void MainWindow::changeEvent(QEvent *e) |
|
361 | void MainWindow::changeEvent(QEvent *e) | |
357 | { |
|
362 | { | |
358 | QMainWindow::changeEvent(e); |
|
363 | QMainWindow::changeEvent(e); | |
359 | switch (e->type()) { |
|
364 | switch (e->type()) { | |
360 | case QEvent::LanguageChange: |
|
365 | case QEvent::LanguageChange: | |
361 | m_Ui->retranslateUi(this); |
|
366 | m_Ui->retranslateUi(this); | |
362 | break; |
|
367 | break; | |
363 | default: |
|
368 | default: | |
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 | } |
@@ -1,75 +1,83 | |||||
1 | #ifndef SCIQLOP_CATALOGUECONTROLLER_H |
|
1 | #ifndef SCIQLOP_CATALOGUECONTROLLER_H | |
2 | #define SCIQLOP_CATALOGUECONTROLLER_H |
|
2 | #define SCIQLOP_CATALOGUECONTROLLER_H | |
3 |
|
3 | |||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/SqpRange.h> |
|
6 | #include <Data/SqpRange.h> | |
7 |
|
7 | |||
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
9 | #include <QObject> |
|
9 | #include <QObject> | |
10 | #include <QUuid> |
|
10 | #include <QUuid> | |
11 |
|
11 | |||
12 | #include <Common/spimpl.h> |
|
12 | #include <Common/spimpl.h> | |
13 |
|
13 | |||
14 | #include <memory> |
|
14 | #include <memory> | |
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 | |||
21 | class DataSourceItem; |
|
22 | class DataSourceItem; | |
22 | class Variable; |
|
23 | class Variable; | |
23 |
|
24 | |||
24 | /** |
|
25 | /** | |
25 | * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI |
|
26 | * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI | |
26 | * library. |
|
27 | * library. | |
27 | */ |
|
28 | */ | |
28 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { |
|
29 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { | |
29 | Q_OBJECT |
|
30 | Q_OBJECT | |
30 | public: |
|
31 | public: | |
31 | explicit CatalogueController(QObject *parent = 0); |
|
32 | explicit CatalogueController(QObject *parent = 0); | |
32 | virtual ~CatalogueController(); |
|
33 | virtual ~CatalogueController(); | |
33 |
|
34 | |||
34 | // DB |
|
35 | // DB | |
35 | QStringList getRepositories() const; |
|
36 | QStringList getRepositories() const; | |
36 | void addDB(const QString &dbPath); |
|
37 | void addDB(const QString &dbPath); | |
37 | void saveDB(const QString &destinationPath, const QString &repository); |
|
38 | void saveDB(const QString &destinationPath, const QString &repository); | |
38 |
|
39 | |||
39 | // Event |
|
40 | // Event | |
40 | /// retrieveEvents with empty repository retrieve them from the default repository |
|
41 | /// retrieveEvents with empty repository retrieve them from the default repository | |
41 | std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const; |
|
42 | std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const; | |
42 | std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const; |
|
43 | std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const; | |
43 | std::list<std::shared_ptr<DBEvent> > |
|
44 | std::list<std::shared_ptr<DBEvent> > | |
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( |
|
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); | |
54 | /// retrieveEvents with empty repository retrieve them from the default repository |
|
58 | /// retrieveEvents with empty repository retrieve them from the default repository | |
55 | std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository |
|
59 | std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository | |
56 | = QString()) const; |
|
60 | = QString()) const; | |
57 | void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue); |
|
61 | void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |
58 | void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue); |
|
62 | void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |
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 | }; | |
74 |
|
82 | |||
75 | #endif // SCIQLOP_CATALOGUECONTROLLER_H |
|
83 | #endif // SCIQLOP_CATALOGUECONTROLLER_H |
@@ -1,154 +1,156 | |||||
1 | #ifndef SCIQLOP_DATASOURCEITEM_H |
|
1 | #ifndef SCIQLOP_DATASOURCEITEM_H | |
2 | #define SCIQLOP_DATASOURCEITEM_H |
|
2 | #define SCIQLOP_DATASOURCEITEM_H | |
3 |
|
3 | |||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <Common/spimpl.h> |
|
6 | #include <Common/spimpl.h> | |
7 |
|
7 | |||
8 | #include <QVariant> |
|
8 | #include <QVariant> | |
9 | #include <QVector> |
|
9 | #include <QVector> | |
10 |
|
10 | |||
11 | class DataSourceItemAction; |
|
11 | class DataSourceItemAction; | |
12 |
|
12 | |||
13 | /** |
|
13 | /** | |
14 | * Possible types of an item |
|
14 | * Possible types of an item | |
15 | */ |
|
15 | */ | |
16 | enum class DataSourceItemType { NODE, PRODUCT, COMPONENT }; |
|
16 | enum class DataSourceItemType { NODE, PRODUCT, COMPONENT }; | |
17 |
|
17 | |||
18 | /** |
|
18 | /** | |
19 | * @brief The DataSourceItem class aims to represent a structure element of a data source. |
|
19 | * @brief The DataSourceItem class aims to represent a structure element of a data source. | |
20 | * A data source has a tree structure that is made up of a main DataSourceItem object (root) |
|
20 | * A data source has a tree structure that is made up of a main DataSourceItem object (root) | |
21 | * containing other DataSourceItem objects (children). |
|
21 | * containing other DataSourceItem objects (children). | |
22 | * For each DataSourceItem can be associated a set of data representing it. |
|
22 | * For each DataSourceItem can be associated a set of data representing it. | |
23 | */ |
|
23 | */ | |
24 | class SCIQLOP_CORE_EXPORT DataSourceItem { |
|
24 | class SCIQLOP_CORE_EXPORT DataSourceItem { | |
25 | public: |
|
25 | public: | |
26 | /// Key associated with the name of the item |
|
26 | /// Key associated with the name of the item | |
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 = {}); | |
33 |
|
35 | |||
34 | std::unique_ptr<DataSourceItem> clone() const; |
|
36 | std::unique_ptr<DataSourceItem> clone() const; | |
35 |
|
37 | |||
36 | /// @return the actions of the item as a vector |
|
38 | /// @return the actions of the item as a vector | |
37 | QVector<DataSourceItemAction *> actions() const noexcept; |
|
39 | QVector<DataSourceItemAction *> actions() const noexcept; | |
38 |
|
40 | |||
39 | /** |
|
41 | /** | |
40 | * Adds an action to the item. The item takes ownership of the action, and the action is |
|
42 | * Adds an action to the item. The item takes ownership of the action, and the action is | |
41 | * automatically associated to the item |
|
43 | * automatically associated to the item | |
42 | * @param action the action to add |
|
44 | * @param action the action to add | |
43 | */ |
|
45 | */ | |
44 | void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept; |
|
46 | void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept; | |
45 |
|
47 | |||
46 | /** |
|
48 | /** | |
47 | * Adds a child to the item. The item takes ownership of the child. |
|
49 | * Adds a child to the item. The item takes ownership of the child. | |
48 | * @param child the child to add |
|
50 | * @param child the child to add | |
49 | */ |
|
51 | */ | |
50 | void appendChild(std::unique_ptr<DataSourceItem> child) noexcept; |
|
52 | void appendChild(std::unique_ptr<DataSourceItem> child) noexcept; | |
51 |
|
53 | |||
52 | /** |
|
54 | /** | |
53 | * Returns the item's child associated to an index |
|
55 | * Returns the item's child associated to an index | |
54 | * @param childIndex the index to search |
|
56 | * @param childIndex the index to search | |
55 | * @return a pointer to the child if index is valid, nullptr otherwise |
|
57 | * @return a pointer to the child if index is valid, nullptr otherwise | |
56 | */ |
|
58 | */ | |
57 | DataSourceItem *child(int childIndex) const noexcept; |
|
59 | DataSourceItem *child(int childIndex) const noexcept; | |
58 |
|
60 | |||
59 | int childCount() const noexcept; |
|
61 | int childCount() const noexcept; | |
60 |
|
62 | |||
61 | /** |
|
63 | /** | |
62 | * Get the data associated to a key |
|
64 | * Get the data associated to a key | |
63 | * @param key the key to search |
|
65 | * @param key the key to search | |
64 | * @return the data found if key is valid, default QVariant otherwise |
|
66 | * @return the data found if key is valid, default QVariant otherwise | |
65 | */ |
|
67 | */ | |
66 | QVariant data(const QString &key) const noexcept; |
|
68 | QVariant data(const QString &key) const noexcept; | |
67 |
|
69 | |||
68 | /// Gets all data |
|
70 | /// Gets all data | |
69 | QVariantHash data() const noexcept; |
|
71 | QVariantHash data() const noexcept; | |
70 |
|
72 | |||
71 | /** |
|
73 | /** | |
72 | * Merge in the item the source item passed as parameter. |
|
74 | * Merge in the item the source item passed as parameter. | |
73 | * |
|
75 | * | |
74 | * The merge is done by adding as child of the item the complete tree represented by the source |
|
76 | * The merge is done by adding as child of the item the complete tree represented by the source | |
75 | * item. If a part of the tree already exists in the item (based on the name of the nodes), it |
|
77 | * item. If a part of the tree already exists in the item (based on the name of the nodes), it | |
76 | * is merged by completing the existing tree by items "leaves" (products, components or nodes |
|
78 | * is merged by completing the existing tree by items "leaves" (products, components or nodes | |
77 | * with no child). |
|
79 | * with no child). | |
78 | * |
|
80 | * | |
79 | * For example, with item representing the tree: |
|
81 | * For example, with item representing the tree: | |
80 | * R (root node) |
|
82 | * R (root node) | |
81 | * - N1 (node) |
|
83 | * - N1 (node) | |
82 | * -- N11 (node) |
|
84 | * -- N11 (node) | |
83 | * --- P1 (product) |
|
85 | * --- P1 (product) | |
84 | * --- P2 (product) |
|
86 | * --- P2 (product) | |
85 | * - N2 (node) |
|
87 | * - N2 (node) | |
86 | * |
|
88 | * | |
87 | * and the source item representing the tree: |
|
89 | * and the source item representing the tree: | |
88 | * N1 (root node) |
|
90 | * N1 (root node) | |
89 | * - N11 (node) |
|
91 | * - N11 (node) | |
90 | * -- P3 (product) |
|
92 | * -- P3 (product) | |
91 | * - N12 (node) |
|
93 | * - N12 (node) | |
92 | * |
|
94 | * | |
93 | * The leaves of the source item to merge into the item are N1/N11/P3 and N1/N12 => we therefore |
|
95 | * The leaves of the source item to merge into the item are N1/N11/P3 and N1/N12 => we therefore | |
94 | * have the following merge result: |
|
96 | * have the following merge result: | |
95 | * R |
|
97 | * R | |
96 | * - N1 |
|
98 | * - N1 | |
97 | * -- N11 |
|
99 | * -- N11 | |
98 | * --- P1 |
|
100 | * --- P1 | |
99 | * --- P2 |
|
101 | * --- P2 | |
100 | * --- P3 (added leaf) |
|
102 | * --- P3 (added leaf) | |
101 | * -- N12 (added leaf) |
|
103 | * -- N12 (added leaf) | |
102 | * |
|
104 | * | |
103 | * @param item the source item |
|
105 | * @param item the source item | |
104 | * @remarks No control is performed on products or components that are merged into the same tree |
|
106 | * @remarks No control is performed on products or components that are merged into the same tree | |
105 | * part (two products or components may have the same name) |
|
107 | * part (two products or components may have the same name) | |
106 | * @remarks the merge is made by copy (source item is not changed and still exists after the |
|
108 | * @remarks the merge is made by copy (source item is not changed and still exists after the | |
107 | * operation) |
|
109 | * operation) | |
108 | */ |
|
110 | */ | |
109 | void merge(const DataSourceItem &item); |
|
111 | void merge(const DataSourceItem &item); | |
110 |
|
112 | |||
111 | bool isRoot() const noexcept; |
|
113 | bool isRoot() const noexcept; | |
112 |
|
114 | |||
113 | QString name() const noexcept; |
|
115 | QString name() const noexcept; | |
114 |
|
116 | |||
115 | /** |
|
117 | /** | |
116 | * Get the item's parent |
|
118 | * Get the item's parent | |
117 | * @return a pointer to the parent if it exists, nullptr if the item is a root |
|
119 | * @return a pointer to the parent if it exists, nullptr if the item is a root | |
118 | */ |
|
120 | */ | |
119 | DataSourceItem *parentItem() const noexcept; |
|
121 | DataSourceItem *parentItem() const noexcept; | |
120 |
|
122 | |||
121 | /** |
|
123 | /** | |
122 | * Gets the item's root |
|
124 | * Gets the item's root | |
123 | * @return the top parent, the item itself if it's the root item |
|
125 | * @return the top parent, the item itself if it's the root item | |
124 | */ |
|
126 | */ | |
125 | const DataSourceItem &rootItem() const noexcept; |
|
127 | const DataSourceItem &rootItem() const noexcept; | |
126 |
|
128 | |||
127 | /** |
|
129 | /** | |
128 | * Sets or appends a value to a key |
|
130 | * Sets or appends a value to a key | |
129 | * @param key the key |
|
131 | * @param key the key | |
130 | * @param value the value |
|
132 | * @param value the value | |
131 | * @param append if true, the value is added to the values already existing for the key, |
|
133 | * @param append if true, the value is added to the values already existing for the key, | |
132 | * otherwise it replaces the existing values |
|
134 | * otherwise it replaces the existing values | |
133 | */ |
|
135 | */ | |
134 | void setData(const QString &key, const QVariant &value, bool append = false) noexcept; |
|
136 | void setData(const QString &key, const QVariant &value, bool append = false) noexcept; | |
135 |
|
137 | |||
136 | DataSourceItemType type() const noexcept; |
|
138 | DataSourceItemType type() const noexcept; | |
137 |
|
139 | |||
138 | /** |
|
140 | /** | |
139 | * @brief Searches the first child matching the specified data. |
|
141 | * @brief Searches the first child matching the specified data. | |
140 | * @param data The data to search. |
|
142 | * @param data The data to search. | |
141 | * @param recursive So the search recursively. |
|
143 | * @param recursive So the search recursively. | |
142 | * @return the item matching the data or nullptr if it was not found. |
|
144 | * @return the item matching the data or nullptr if it was not found. | |
143 | */ |
|
145 | */ | |
144 | DataSourceItem *findItem(const QVariantHash &data, bool recursive); |
|
146 | DataSourceItem *findItem(const QVariantHash &data, bool recursive); | |
145 |
|
147 | |||
146 | bool operator==(const DataSourceItem &other); |
|
148 | bool operator==(const DataSourceItem &other); | |
147 | bool operator!=(const DataSourceItem &other); |
|
149 | bool operator!=(const DataSourceItem &other); | |
148 |
|
150 | |||
149 | private: |
|
151 | private: | |
150 | class DataSourceItemPrivate; |
|
152 | class DataSourceItemPrivate; | |
151 | spimpl::unique_impl_ptr<DataSourceItemPrivate> impl; |
|
153 | spimpl::unique_impl_ptr<DataSourceItemPrivate> impl; | |
152 | }; |
|
154 | }; | |
153 |
|
155 | |||
154 | #endif // SCIQLOP_DATASOURCEITEMMODEL_H |
|
156 | #endif // SCIQLOP_DATASOURCEITEMMODEL_H |
@@ -1,296 +1,420 | |||||
1 | #include <Catalogue/CatalogueController.h> |
|
1 | #include <Catalogue/CatalogueController.h> | |
2 |
|
2 | |||
3 | #include <Variable/Variable.h> |
|
3 | #include <Variable/Variable.h> | |
4 |
|
4 | |||
5 | #include <CatalogueDao.h> |
|
5 | #include <CatalogueDao.h> | |
6 |
|
6 | |||
7 | #include <ComparaisonPredicate.h> |
|
7 | #include <ComparaisonPredicate.h> | |
8 | #include <CompoundPredicate.h> |
|
8 | #include <CompoundPredicate.h> | |
9 | #include <DBCatalogue.h> |
|
9 | #include <DBCatalogue.h> | |
10 | #include <DBEvent.h> |
|
10 | #include <DBEvent.h> | |
11 | #include <DBEventProduct.h> |
|
11 | #include <DBEventProduct.h> | |
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 | |||
18 | #include <QDir> |
|
19 | #include <QDir> | |
19 | #include <QStandardPaths> |
|
20 | #include <QStandardPaths> | |
20 |
|
21 | |||
21 | Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") |
|
22 | 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 { | |
30 |
|
31 | |||
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) | |
46 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} |
|
54 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} | |
47 | { |
|
55 | { | |
48 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") |
|
56 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") | |
49 | << QThread::currentThread(); |
|
57 | << QThread::currentThread(); | |
50 | } |
|
58 | } | |
51 |
|
59 | |||
52 | CatalogueController::~CatalogueController() |
|
60 | 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 | |
60 | { |
|
67 | { | |
61 | return impl->m_RepositoryList; |
|
68 | return impl->m_RepositoryList; | |
62 | } |
|
69 | } | |
63 |
|
70 | |||
64 | void CatalogueController::addDB(const QString &dbPath) |
|
71 | void CatalogueController::addDB(const QString &dbPath) | |
65 | { |
|
72 | { | |
66 | QDir dbDir(dbPath); |
|
73 | QDir dbDir(dbPath); | |
67 | if (dbDir.exists()) { |
|
74 | if (dbDir.exists()) { | |
68 | auto dirName = dbDir.dirName(); |
|
75 | auto dirName = dbDir.dirName(); | |
69 |
|
76 | |||
70 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) |
|
77 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) | |
71 | != impl->m_RepositoryList.cend()) { |
|
78 | != impl->m_RepositoryList.cend()) { | |
72 | qCCritical(LOG_CatalogueController()) |
|
79 | qCCritical(LOG_CatalogueController()) | |
73 | << tr("Impossible to addDB that is already loaded"); |
|
80 | << tr("Impossible to addDB that is already loaded"); | |
74 | } |
|
81 | } | |
75 |
|
82 | |||
76 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { |
|
83 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { | |
77 | qCCritical(LOG_CatalogueController()) |
|
84 | qCCritical(LOG_CatalogueController()) | |
78 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); |
|
85 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); | |
79 | } |
|
86 | } | |
80 | else { |
|
87 | else { | |
81 | impl->m_RepositoryList << dirName; |
|
88 | impl->m_RepositoryList << dirName; | |
82 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); |
|
89 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); | |
83 | } |
|
90 | } | |
84 | } |
|
91 | } | |
85 | else { |
|
92 | else { | |
86 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") |
|
93 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") | |
87 | << dbPath; |
|
94 | << dbPath; | |
88 | } |
|
95 | } | |
89 | } |
|
96 | } | |
90 |
|
97 | |||
91 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) |
|
98 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) | |
92 | { |
|
99 | { | |
93 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { |
|
100 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { | |
94 | qCCritical(LOG_CatalogueController()) |
|
101 | qCCritical(LOG_CatalogueController()) | |
95 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); |
|
102 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); | |
96 | } |
|
103 | } | |
97 | } |
|
104 | } | |
98 |
|
105 | |||
99 | std::list<std::shared_ptr<DBEvent> > |
|
106 | std::list<std::shared_ptr<DBEvent> > | |
100 | CatalogueController::retrieveEvents(const QString &repository) const |
|
107 | CatalogueController::retrieveEvents(const QString &repository) const | |
101 | { |
|
108 | { | |
102 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; |
|
109 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |
103 |
|
110 | |||
104 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
111 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
105 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); |
|
112 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); | |
106 | for (auto event : events) { |
|
113 | for (auto event : events) { | |
107 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
114 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
108 | } |
|
115 | } | |
109 | return eventsShared; |
|
116 | return eventsShared; | |
110 | } |
|
117 | } | |
111 |
|
118 | |||
112 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const |
|
119 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const | |
113 | { |
|
120 | { | |
114 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
121 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
115 | for (auto repository : impl->m_RepositoryList) { |
|
122 | for (auto repository : impl->m_RepositoryList) { | |
116 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); |
|
123 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); | |
117 | } |
|
124 | } | |
118 |
|
125 | |||
119 | return eventsShared; |
|
126 | return eventsShared; | |
120 | } |
|
127 | } | |
121 |
|
128 | |||
122 | std::list<std::shared_ptr<DBEvent> > |
|
129 | std::list<std::shared_ptr<DBEvent> > | |
123 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const |
|
130 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const | |
124 | { |
|
131 | { | |
125 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
132 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
126 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); |
|
133 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); | |
127 | for (auto event : events) { |
|
134 | for (auto event : events) { | |
128 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
135 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
129 | } |
|
136 | } | |
130 | return eventsShared; |
|
137 | return eventsShared; | |
131 | } |
|
138 | } | |
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->to |
|
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 | |
143 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
158 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
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> > | |
168 | CatalogueController::retrieveCatalogues(const QString &repository) const |
|
231 | CatalogueController::retrieveCatalogues(const QString &repository) const | |
169 | { |
|
232 | { | |
170 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; |
|
233 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |
171 |
|
234 | |||
172 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
235 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; | |
173 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); |
|
236 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); | |
174 | for (auto catalogue : catalogues) { |
|
237 | for (auto catalogue : catalogues) { | |
175 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); |
|
238 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); | |
176 | } |
|
239 | } | |
177 | return cataloguesShared; |
|
240 | return cataloguesShared; | |
178 | } |
|
241 | } | |
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->to |
|
245 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
183 |
|
246 | |||
184 | impl->m_CatalogueDao.updateCatalogue(*catalogue); |
|
247 | impl->m_CatalogueDao.updateCatalogue(*catalogue); | |
185 | } |
|
248 | } | |
186 |
|
249 | |||
187 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
250 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
188 | { |
|
251 | { | |
189 | // Remove it from both repository and repository_work |
|
252 | // Remove it from both repository and repository_work | |
190 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
253 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
191 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
254 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
192 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); |
|
255 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); | |
193 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
256 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
194 | } |
|
257 | } | |
195 |
|
258 | |||
196 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
259 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
197 | { |
|
260 | { | |
198 |
impl-> |
|
261 | impl->saveCatalogue(catalogue, true); | |
199 | impl->toSyncRepository(catalogue->getRepository()), true); |
|
|||
200 | } |
|
262 | } | |
201 |
|
263 | |||
202 | void CatalogueController::saveAll() |
|
264 | void CatalogueController::saveAll() | |
203 | { |
|
265 | { | |
204 | for (auto repository : impl->m_RepositoryList) { |
|
266 | for (auto repository : impl->m_RepositoryList) { | |
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 |
|
|
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 |
|
|
276 | impl->saveCatalogue(catalogue, false); | |
|
277 | } | |||
215 |
|
|
278 | } | |
|
279 | ||||
|
280 | impl->savAllDB(); | |||
|
281 | impl->m_EventKeysWithChanges.clear(); | |||
216 | } |
|
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 | } | |||
|
323 | } | |||
|
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); | |
227 |
|
337 | |||
228 | QDir defaultRepositoryLocationDir; |
|
338 | QDir defaultRepositoryLocationDir; | |
229 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { |
|
339 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { | |
230 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); |
|
340 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); | |
231 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); |
|
341 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); | |
232 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") |
|
342 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") | |
233 | << defaultRepository; |
|
343 | << defaultRepository; | |
234 | this->addDB(defaultRepository); |
|
344 | this->addDB(defaultRepository); | |
235 | } |
|
345 | } | |
236 | else { |
|
346 | else { | |
237 | qCWarning(LOG_CatalogueController()) |
|
347 | qCWarning(LOG_CatalogueController()) | |
238 | << tr("Cannot load the persistent default repository from ") |
|
348 | << tr("Cannot load the persistent default repository from ") | |
239 | << defaultRepositoryLocation; |
|
349 | << defaultRepositoryLocation; | |
240 | } |
|
350 | } | |
241 |
|
351 | |||
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 | |||
279 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) |
|
376 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) | |
280 | { |
|
377 | { | |
281 | auto syncRepository = toSyncRepository(repository); |
|
378 | auto syncRepository = toSyncRepository(repository); | |
282 |
|
379 | |||
283 |
return QString("%1 |
|
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) | |
287 | { |
|
384 | { | |
288 | auto syncRepository = repository; |
|
385 | auto syncRepository = repository; | |
289 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { |
|
386 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { | |
290 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); |
|
387 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); | |
291 | } |
|
388 | } | |
292 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { |
|
389 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { | |
293 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); |
|
390 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); | |
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 | } |
@@ -1,186 +1,187 | |||||
1 | #include <DataSource/DataSourceItem.h> |
|
1 | #include <DataSource/DataSourceItem.h> | |
2 | #include <DataSource/DataSourceItemAction.h> |
|
2 | #include <DataSource/DataSourceItemAction.h> | |
3 | #include <DataSource/DataSourceItemMergeHelper.h> |
|
3 | #include <DataSource/DataSourceItemMergeHelper.h> | |
4 |
|
4 | |||
5 | #include <QVector> |
|
5 | #include <QVector> | |
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) | |
12 | : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{} |
|
13 | : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{} | |
13 | { |
|
14 | { | |
14 | } |
|
15 | } | |
15 |
|
16 | |||
16 | DataSourceItem *m_Parent; |
|
17 | DataSourceItem *m_Parent; | |
17 | std::vector<std::unique_ptr<DataSourceItem> > m_Children; |
|
18 | std::vector<std::unique_ptr<DataSourceItem> > m_Children; | |
18 | DataSourceItemType m_Type; |
|
19 | DataSourceItemType m_Type; | |
19 | QVariantHash m_Data; |
|
20 | QVariantHash m_Data; | |
20 | std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions; |
|
21 | std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions; | |
21 | }; |
|
22 | }; | |
22 |
|
23 | |||
23 | DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name) |
|
24 | DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name) | |
24 | : DataSourceItem{type, QVariantHash{{NAME_DATA_KEY, name}}} |
|
25 | : DataSourceItem{type, QVariantHash{{NAME_DATA_KEY, name}}} | |
25 | { |
|
26 | { | |
26 | } |
|
27 | } | |
27 |
|
28 | |||
28 | DataSourceItem::DataSourceItem(DataSourceItemType type, QVariantHash data) |
|
29 | DataSourceItem::DataSourceItem(DataSourceItemType type, QVariantHash data) | |
29 | : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))} |
|
30 | : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))} | |
30 | { |
|
31 | { | |
31 | } |
|
32 | } | |
32 |
|
33 | |||
33 | std::unique_ptr<DataSourceItem> DataSourceItem::clone() const |
|
34 | std::unique_ptr<DataSourceItem> DataSourceItem::clone() const | |
34 | { |
|
35 | { | |
35 | auto result = std::make_unique<DataSourceItem>(impl->m_Type, impl->m_Data); |
|
36 | auto result = std::make_unique<DataSourceItem>(impl->m_Type, impl->m_Data); | |
36 |
|
37 | |||
37 | // Clones children |
|
38 | // Clones children | |
38 | for (const auto &child : impl->m_Children) { |
|
39 | for (const auto &child : impl->m_Children) { | |
39 | result->appendChild(std::move(child->clone())); |
|
40 | result->appendChild(std::move(child->clone())); | |
40 | } |
|
41 | } | |
41 |
|
42 | |||
42 | // Clones actions |
|
43 | // Clones actions | |
43 | for (const auto &action : impl->m_Actions) { |
|
44 | for (const auto &action : impl->m_Actions) { | |
44 | result->addAction(std::move(action->clone())); |
|
45 | result->addAction(std::move(action->clone())); | |
45 | } |
|
46 | } | |
46 |
|
47 | |||
47 | return result; |
|
48 | return result; | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 | QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept |
|
51 | QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept | |
51 | { |
|
52 | { | |
52 | auto result = QVector<DataSourceItemAction *>{}; |
|
53 | auto result = QVector<DataSourceItemAction *>{}; | |
53 |
|
54 | |||
54 | std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions), |
|
55 | std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions), | |
55 | std::back_inserter(result), [](const auto &action) { return action.get(); }); |
|
56 | std::back_inserter(result), [](const auto &action) { return action.get(); }); | |
56 |
|
57 | |||
57 | return result; |
|
58 | return result; | |
58 | } |
|
59 | } | |
59 |
|
60 | |||
60 | void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept |
|
61 | void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept | |
61 | { |
|
62 | { | |
62 | action->setDataSourceItem(this); |
|
63 | action->setDataSourceItem(this); | |
63 | impl->m_Actions.push_back(std::move(action)); |
|
64 | impl->m_Actions.push_back(std::move(action)); | |
64 | } |
|
65 | } | |
65 |
|
66 | |||
66 | void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept |
|
67 | void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept | |
67 | { |
|
68 | { | |
68 | child->impl->m_Parent = this; |
|
69 | child->impl->m_Parent = this; | |
69 | impl->m_Children.push_back(std::move(child)); |
|
70 | impl->m_Children.push_back(std::move(child)); | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | DataSourceItem *DataSourceItem::child(int childIndex) const noexcept |
|
73 | DataSourceItem *DataSourceItem::child(int childIndex) const noexcept | |
73 | { |
|
74 | { | |
74 | if (childIndex < 0 || childIndex >= childCount()) { |
|
75 | if (childIndex < 0 || childIndex >= childCount()) { | |
75 | return nullptr; |
|
76 | return nullptr; | |
76 | } |
|
77 | } | |
77 | else { |
|
78 | else { | |
78 | return impl->m_Children.at(childIndex).get(); |
|
79 | return impl->m_Children.at(childIndex).get(); | |
79 | } |
|
80 | } | |
80 | } |
|
81 | } | |
81 |
|
82 | |||
82 | int DataSourceItem::childCount() const noexcept |
|
83 | int DataSourceItem::childCount() const noexcept | |
83 | { |
|
84 | { | |
84 | return impl->m_Children.size(); |
|
85 | return impl->m_Children.size(); | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | QVariant DataSourceItem::data(const QString &key) const noexcept |
|
88 | QVariant DataSourceItem::data(const QString &key) const noexcept | |
88 | { |
|
89 | { | |
89 | return impl->m_Data.value(key); |
|
90 | return impl->m_Data.value(key); | |
90 | } |
|
91 | } | |
91 |
|
92 | |||
92 | QVariantHash DataSourceItem::data() const noexcept |
|
93 | QVariantHash DataSourceItem::data() const noexcept | |
93 | { |
|
94 | { | |
94 | return impl->m_Data; |
|
95 | return impl->m_Data; | |
95 | } |
|
96 | } | |
96 |
|
97 | |||
97 | void DataSourceItem::merge(const DataSourceItem &item) |
|
98 | void DataSourceItem::merge(const DataSourceItem &item) | |
98 | { |
|
99 | { | |
99 | DataSourceItemMergeHelper::merge(item, *this); |
|
100 | DataSourceItemMergeHelper::merge(item, *this); | |
100 | } |
|
101 | } | |
101 |
|
102 | |||
102 | bool DataSourceItem::isRoot() const noexcept |
|
103 | bool DataSourceItem::isRoot() const noexcept | |
103 | { |
|
104 | { | |
104 | return impl->m_Parent == nullptr; |
|
105 | return impl->m_Parent == nullptr; | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | QString DataSourceItem::name() const noexcept |
|
108 | QString DataSourceItem::name() const noexcept | |
108 | { |
|
109 | { | |
109 | return data(NAME_DATA_KEY).toString(); |
|
110 | return data(NAME_DATA_KEY).toString(); | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 | DataSourceItem *DataSourceItem::parentItem() const noexcept |
|
113 | DataSourceItem *DataSourceItem::parentItem() const noexcept | |
113 | { |
|
114 | { | |
114 | return impl->m_Parent; |
|
115 | return impl->m_Parent; | |
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | const DataSourceItem &DataSourceItem::rootItem() const noexcept |
|
118 | const DataSourceItem &DataSourceItem::rootItem() const noexcept | |
118 | { |
|
119 | { | |
119 | return isRoot() ? *this : parentItem()->rootItem(); |
|
120 | return isRoot() ? *this : parentItem()->rootItem(); | |
120 | } |
|
121 | } | |
121 |
|
122 | |||
122 | void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept |
|
123 | void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept | |
123 | { |
|
124 | { | |
124 | auto it = impl->m_Data.constFind(key); |
|
125 | auto it = impl->m_Data.constFind(key); | |
125 | if (append && it != impl->m_Data.constEnd()) { |
|
126 | if (append && it != impl->m_Data.constEnd()) { | |
126 | // Case of an existing value to which we want to add to the new value |
|
127 | // Case of an existing value to which we want to add to the new value | |
127 | if (it->canConvert<QVariantList>()) { |
|
128 | if (it->canConvert<QVariantList>()) { | |
128 | auto variantList = it->value<QVariantList>(); |
|
129 | auto variantList = it->value<QVariantList>(); | |
129 | variantList.append(value); |
|
130 | variantList.append(value); | |
130 |
|
131 | |||
131 | impl->m_Data.insert(key, variantList); |
|
132 | impl->m_Data.insert(key, variantList); | |
132 | } |
|
133 | } | |
133 | else { |
|
134 | else { | |
134 | impl->m_Data.insert(key, QVariantList{*it, value}); |
|
135 | impl->m_Data.insert(key, QVariantList{*it, value}); | |
135 | } |
|
136 | } | |
136 | } |
|
137 | } | |
137 | else { |
|
138 | else { | |
138 | // Other cases : |
|
139 | // Other cases : | |
139 | // - new value in map OR |
|
140 | // - new value in map OR | |
140 | // - replacement of an existing value (not appending) |
|
141 | // - replacement of an existing value (not appending) | |
141 | impl->m_Data.insert(key, value); |
|
142 | impl->m_Data.insert(key, value); | |
142 | } |
|
143 | } | |
143 | } |
|
144 | } | |
144 |
|
145 | |||
145 | DataSourceItemType DataSourceItem::type() const noexcept |
|
146 | DataSourceItemType DataSourceItem::type() const noexcept | |
146 | { |
|
147 | { | |
147 | return impl->m_Type; |
|
148 | return impl->m_Type; | |
148 | } |
|
149 | } | |
149 |
|
150 | |||
150 | DataSourceItem *DataSourceItem::findItem(const QVariantHash &data, bool recursive) |
|
151 | DataSourceItem *DataSourceItem::findItem(const QVariantHash &data, bool recursive) | |
151 | { |
|
152 | { | |
152 | for (const auto &child : impl->m_Children) { |
|
153 | for (const auto &child : impl->m_Children) { | |
153 | if (child->impl->m_Data == data) { |
|
154 | if (child->impl->m_Data == data) { | |
154 | return child.get(); |
|
155 | return child.get(); | |
155 | } |
|
156 | } | |
156 |
|
157 | |||
157 | if (recursive) { |
|
158 | if (recursive) { | |
158 | if (auto foundItem = child->findItem(data, true)) { |
|
159 | if (auto foundItem = child->findItem(data, true)) { | |
159 | return foundItem; |
|
160 | return foundItem; | |
160 | } |
|
161 | } | |
161 | } |
|
162 | } | |
162 | } |
|
163 | } | |
163 |
|
164 | |||
164 | return nullptr; |
|
165 | return nullptr; | |
165 | } |
|
166 | } | |
166 |
|
167 | |||
167 | bool DataSourceItem::operator==(const DataSourceItem &other) |
|
168 | bool DataSourceItem::operator==(const DataSourceItem &other) | |
168 | { |
|
169 | { | |
169 | // Compares items' attributes |
|
170 | // Compares items' attributes | |
170 | if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) { |
|
171 | if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) { | |
171 | // Compares contents of items' children |
|
172 | // Compares contents of items' children | |
172 | return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children), |
|
173 | return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children), | |
173 | std::cbegin(other.impl->m_Children), std::cend(other.impl->m_Children), |
|
174 | std::cbegin(other.impl->m_Children), std::cend(other.impl->m_Children), | |
174 | [](const auto &itemChild, const auto &otherChild) { |
|
175 | [](const auto &itemChild, const auto &otherChild) { | |
175 | return *itemChild == *otherChild; |
|
176 | return *itemChild == *otherChild; | |
176 | }); |
|
177 | }); | |
177 | } |
|
178 | } | |
178 | else { |
|
179 | else { | |
179 | return false; |
|
180 | return false; | |
180 | } |
|
181 | } | |
181 | } |
|
182 | } | |
182 |
|
183 | |||
183 | bool DataSourceItem::operator!=(const DataSourceItem &other) |
|
184 | bool DataSourceItem::operator!=(const DataSourceItem &other) | |
184 | { |
|
185 | { | |
185 | return !(*this == other); |
|
186 | return !(*this == other); | |
186 | } |
|
187 | } |
@@ -1,17 +1,19 | |||||
1 | #ifndef SCIQLOP_CATALOGUEACTIONMANAGER_H |
|
1 | #ifndef SCIQLOP_CATALOGUEACTIONMANAGER_H | |
2 | #define SCIQLOP_CATALOGUEACTIONMANAGER_H |
|
2 | #define SCIQLOP_CATALOGUEACTIONMANAGER_H | |
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 | |||
12 | private: |
|
14 | private: | |
13 | class CatalogueActionManagerPrivate; |
|
15 | class CatalogueActionManagerPrivate; | |
14 | spimpl::unique_impl_ptr<CatalogueActionManagerPrivate> impl; |
|
16 | spimpl::unique_impl_ptr<CatalogueActionManagerPrivate> impl; | |
15 | }; |
|
17 | }; | |
16 |
|
18 | |||
17 | #endif // SCIQLOP_CATALOGUEACTIONMANAGER_H |
|
19 | #endif // SCIQLOP_CATALOGUEACTIONMANAGER_H |
@@ -1,68 +1,68 | |||||
1 | #ifndef SCIQLOP_CATALOGUEEVENTSMODEL_H |
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSMODEL_H | |
2 | #define SCIQLOP_CATALOGUEEVENTSMODEL_H |
|
2 | #define SCIQLOP_CATALOGUEEVENTSMODEL_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <unordered_set> |
|
7 | #include <unordered_set> | |
8 |
|
8 | |||
9 | class DBEvent; |
|
9 | class DBEvent; | |
10 | class DBEventProduct; |
|
10 | class DBEventProduct; | |
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsModel) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsModel) | |
13 |
|
13 | |||
14 | class CatalogueEventsModel : public QAbstractItemModel { |
|
14 | class CatalogueEventsModel : public QAbstractItemModel { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 |
|
16 | |||
17 | signals: |
|
17 | signals: | |
18 | void modelSorted(); |
|
18 | void modelSorted(); | |
19 |
|
19 | |||
20 | public: |
|
20 | public: | |
21 | CatalogueEventsModel(QObject *parent = nullptr); |
|
21 | CatalogueEventsModel(QObject *parent = nullptr); | |
22 |
|
22 | |||
23 | enum class Column { Name, TStart, TEnd, Tags, Product, Validation, NbColumn }; |
|
23 | enum class Column { Name, TStart, TEnd, Tags, Product, Validation, NbColumn }; | |
24 |
|
24 | |||
25 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events); |
|
25 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events); | |
26 | void addEvent(const std::shared_ptr<DBEvent> &event); |
|
26 | void addEvent(const std::shared_ptr<DBEvent> &event); | |
27 | void removeEvent(const std::shared_ptr<DBEvent> &event); |
|
27 | void removeEvent(const std::shared_ptr<DBEvent> &event); | |
28 | QVector<std::shared_ptr<DBEvent> > events() const; |
|
28 | QVector<std::shared_ptr<DBEvent> > events() const; | |
29 |
|
29 | |||
30 | enum class ItemType { Root, Event, EventProduct }; |
|
30 | enum class ItemType { Root, Event, EventProduct }; | |
31 | ItemType itemTypeOf(const QModelIndex &index) const; |
|
31 | ItemType itemTypeOf(const QModelIndex &index) const; | |
32 | std::shared_ptr<DBEvent> getEvent(const QModelIndex &index) const; |
|
32 | std::shared_ptr<DBEvent> getEvent(const QModelIndex &index) const; | |
33 | std::shared_ptr<DBEvent> getParentEvent(const QModelIndex &index) const; |
|
33 | std::shared_ptr<DBEvent> getParentEvent(const QModelIndex &index) const; | |
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; | |
41 |
|
41 | |||
42 | /// Marks a change flag on the specified event to allow sorting on the validation column |
|
42 | /// Marks a change flag on the specified event to allow sorting on the validation column | |
43 | void setEventHasChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); |
|
43 | void setEventHasChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); | |
44 |
|
44 | |||
45 | /// Returns true if the specified event has unsaved changes |
|
45 | /// Returns true if the specified event has unsaved changes | |
46 | bool eventsHasChanges(const std::shared_ptr<DBEvent> &event) const; |
|
46 | bool eventsHasChanges(const std::shared_ptr<DBEvent> &event) const; | |
47 |
|
47 | |||
48 | // Model |
|
48 | // Model | |
49 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; |
|
49 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; | |
50 | QModelIndex parent(const QModelIndex &index) const; |
|
50 | QModelIndex parent(const QModelIndex &index) const; | |
51 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
|
51 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | |
52 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
|
52 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; | |
53 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
|
53 | Qt::ItemFlags flags(const QModelIndex &index) const override; | |
54 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
54 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | |
55 | QVariant headerData(int section, Qt::Orientation orientation, |
|
55 | QVariant headerData(int section, Qt::Orientation orientation, | |
56 | int role = Qt::DisplayRole) const override; |
|
56 | int role = Qt::DisplayRole) const override; | |
57 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; |
|
57 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; | |
58 |
|
58 | |||
59 | Qt::DropActions supportedDragActions() const override; |
|
59 | Qt::DropActions supportedDragActions() const override; | |
60 | QStringList mimeTypes() const override; |
|
60 | QStringList mimeTypes() const override; | |
61 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
|
61 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | class CatalogueEventsModelPrivate; |
|
64 | class CatalogueEventsModelPrivate; | |
65 | spimpl::unique_impl_ptr<CatalogueEventsModelPrivate> impl; |
|
65 | spimpl::unique_impl_ptr<CatalogueEventsModelPrivate> impl; | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | #endif // SCIQLOP_CATALOGUEEVENTSMODEL_H |
|
68 | #endif // SCIQLOP_CATALOGUEEVENTSMODEL_H |
@@ -1,48 +1,58 | |||||
1 | #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H |
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H | |
2 | #define SCIQLOP_CATALOGUEEVENTSWIDGET_H |
|
2 | #define SCIQLOP_CATALOGUEEVENTSWIDGET_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QLoggingCategory> |
|
5 | #include <QLoggingCategory> | |
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | class DBCatalogue; |
|
8 | class DBCatalogue; | |
9 | class DBEvent; |
|
9 | class DBEvent; | |
10 | class DBEventProduct; |
|
10 | class DBEventProduct; | |
11 | class VisualizationWidget; |
|
11 | class VisualizationWidget; | |
12 |
|
12 | |||
13 | namespace Ui { |
|
13 | namespace Ui { | |
14 | class CatalogueEventsWidget; |
|
14 | class CatalogueEventsWidget; | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget) |
|
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget) | |
18 |
|
18 | |||
19 | class CatalogueEventsWidget : public QWidget { |
|
19 | class CatalogueEventsWidget : public QWidget { | |
20 | Q_OBJECT |
|
20 | Q_OBJECT | |
21 |
|
21 | |||
22 | signals: |
|
22 | signals: | |
23 | void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event); |
|
23 | void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event); | |
24 | void eventProductsSelected( |
|
24 | void eventProductsSelected( | |
25 | const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > |
|
25 | const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > | |
26 | &eventproducts); |
|
26 | &eventproducts); | |
27 | void selectionCleared(); |
|
27 | void selectionCleared(); | |
28 |
|
28 | |||
29 | public: |
|
29 | public: | |
30 | explicit CatalogueEventsWidget(QWidget *parent = 0); |
|
30 | explicit CatalogueEventsWidget(QWidget *parent = 0); | |
31 | virtual ~CatalogueEventsWidget(); |
|
31 | virtual ~CatalogueEventsWidget(); | |
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 |
@@ -1,29 +1,35 | |||||
1 | #ifndef SCIQLOP_CATALOGUEEXPLORER_H |
|
1 | #ifndef SCIQLOP_CATALOGUEEXPLORER_H | |
2 | #define SCIQLOP_CATALOGUEEXPLORER_H |
|
2 | #define SCIQLOP_CATALOGUEEXPLORER_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QDialog> |
|
5 | #include <QDialog> | |
6 |
|
6 | |||
7 | namespace Ui { |
|
7 | 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 { | |
14 | Q_OBJECT |
|
17 | Q_OBJECT | |
15 |
|
18 | |||
16 | public: |
|
19 | public: | |
17 | explicit CatalogueExplorer(QWidget *parent = 0); |
|
20 | explicit CatalogueExplorer(QWidget *parent = 0); | |
18 | virtual ~CatalogueExplorer(); |
|
21 | virtual ~CatalogueExplorer(); | |
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 | |||
25 | class CatalogueExplorerPrivate; |
|
31 | class CatalogueExplorerPrivate; | |
26 | spimpl::unique_impl_ptr<CatalogueExplorerPrivate> impl; |
|
32 | spimpl::unique_impl_ptr<CatalogueExplorerPrivate> impl; | |
27 | }; |
|
33 | }; | |
28 |
|
34 | |||
29 | #endif // SCIQLOP_CATALOGUEEXPLORER_H |
|
35 | #endif // SCIQLOP_CATALOGUEEXPLORER_H |
@@ -1,43 +1,46 | |||||
1 | #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H |
|
1 | #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H | |
2 | #define SCIQLOP_CATALOGUESIDEBARWIDGET_H |
|
2 | #define SCIQLOP_CATALOGUESIDEBARWIDGET_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QLoggingCategory> |
|
5 | #include <QLoggingCategory> | |
6 | #include <QTreeWidgetItem> |
|
6 | #include <QTreeWidgetItem> | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 |
|
8 | |||
9 | class DBCatalogue; |
|
9 | class DBCatalogue; | |
10 |
|
10 | |||
11 | namespace Ui { |
|
11 | namespace Ui { | |
12 | class CatalogueSideBarWidget; |
|
12 | class CatalogueSideBarWidget; | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget) |
|
15 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget) | |
16 |
|
16 | |||
17 | class CatalogueSideBarWidget : public QWidget { |
|
17 | class CatalogueSideBarWidget : public QWidget { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 |
|
19 | |||
20 | signals: |
|
20 | signals: | |
21 | void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); |
|
21 | void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); | |
22 | void databaseSelected(const QStringList &databases); |
|
22 | void databaseSelected(const QStringList &databases); | |
23 | void allEventsSelected(); |
|
23 | void allEventsSelected(); | |
24 | void trashSelected(); |
|
24 | void trashSelected(); | |
25 | void selectionCleared(); |
|
25 | void selectionCleared(); | |
26 |
|
26 | |||
27 | public: |
|
27 | 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 | |||
36 | class CatalogueSideBarWidgetPrivate; |
|
39 | class CatalogueSideBarWidgetPrivate; | |
37 | spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl; |
|
40 | spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl; | |
38 |
|
41 | |||
39 | private slots: |
|
42 | private slots: | |
40 | void onContextMenuRequested(const QPoint &pos); |
|
43 | void onContextMenuRequested(const QPoint &pos); | |
41 | }; |
|
44 | }; | |
42 |
|
45 | |||
43 | #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H |
|
46 | #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H |
@@ -1,35 +1,36 | |||||
1 | #ifndef SCIQLOP_CREATEEVENTDIALOG_H |
|
1 | #ifndef SCIQLOP_CREATEEVENTDIALOG_H | |
2 | #define SCIQLOP_CREATEEVENTDIALOG_H |
|
2 | #define SCIQLOP_CREATEEVENTDIALOG_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QDialog> |
|
5 | #include <QDialog> | |
6 | #include <memory> |
|
6 | #include <memory> | |
7 |
|
7 | |||
8 | namespace Ui { |
|
8 | namespace Ui { | |
9 | class CreateEventDialog; |
|
9 | class CreateEventDialog; | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | class DBCatalogue; |
|
12 | class DBCatalogue; | |
13 |
|
13 | |||
14 | class CreateEventDialog : public QDialog { |
|
14 | 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(); | |
22 |
|
23 | |||
23 | QString eventName() const; |
|
24 | QString eventName() const; | |
24 |
|
25 | |||
25 | std::shared_ptr<DBCatalogue> selectedCatalogue() const; |
|
26 | std::shared_ptr<DBCatalogue> selectedCatalogue() const; | |
26 | QString catalogueName() const; |
|
27 | QString catalogueName() const; | |
27 |
|
28 | |||
28 | private: |
|
29 | private: | |
29 | Ui::CreateEventDialog *ui; |
|
30 | Ui::CreateEventDialog *ui; | |
30 |
|
31 | |||
31 | class CreateEventDialogPrivate; |
|
32 | class CreateEventDialogPrivate; | |
32 | spimpl::unique_impl_ptr<CreateEventDialogPrivate> impl; |
|
33 | spimpl::unique_impl_ptr<CreateEventDialogPrivate> impl; | |
33 | }; |
|
34 | }; | |
34 |
|
35 | |||
35 | #endif // SCIQLOP_CREATEEVENTDIALOG_H |
|
36 | #endif // SCIQLOP_CREATEEVENTDIALOG_H |
@@ -1,143 +1,147 | |||||
1 | qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) |
|
1 | qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) | |
2 | catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) |
|
2 | catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) | |
3 |
|
3 | |||
4 | gui_moc_headers = [ |
|
4 | gui_moc_headers = [ | |
5 | 'include/DataSource/DataSourceWidget.h', |
|
5 | 'include/DataSource/DataSourceWidget.h', | |
6 | 'include/Settings/SqpSettingsDialog.h', |
|
6 | 'include/Settings/SqpSettingsDialog.h', | |
7 | 'include/Settings/SqpSettingsGeneralWidget.h', |
|
7 | 'include/Settings/SqpSettingsGeneralWidget.h', | |
8 | 'include/SidePane/SqpSidePane.h', |
|
8 | 'include/SidePane/SqpSidePane.h', | |
9 | 'include/SqpApplication.h', |
|
9 | 'include/SqpApplication.h', | |
10 | 'include/DragAndDrop/DragDropScroller.h', |
|
10 | 'include/DragAndDrop/DragDropScroller.h', | |
11 | 'include/DragAndDrop/DragDropTabSwitcher.h', |
|
11 | 'include/DragAndDrop/DragDropTabSwitcher.h', | |
12 | 'include/TimeWidget/TimeWidget.h', |
|
12 | 'include/TimeWidget/TimeWidget.h', | |
13 | 'include/Variable/VariableInspectorWidget.h', |
|
13 | 'include/Variable/VariableInspectorWidget.h', | |
14 | 'include/Variable/RenameVariableDialog.h', |
|
14 | 'include/Variable/RenameVariableDialog.h', | |
15 | 'include/Visualization/qcustomplot.h', |
|
15 | 'include/Visualization/qcustomplot.h', | |
16 | 'include/Visualization/VisualizationGraphWidget.h', |
|
16 | 'include/Visualization/VisualizationGraphWidget.h', | |
17 | 'include/Visualization/VisualizationTabWidget.h', |
|
17 | 'include/Visualization/VisualizationTabWidget.h', | |
18 | 'include/Visualization/VisualizationWidget.h', |
|
18 | 'include/Visualization/VisualizationWidget.h', | |
19 | 'include/Visualization/VisualizationZoneWidget.h', |
|
19 | 'include/Visualization/VisualizationZoneWidget.h', | |
20 | 'include/Visualization/VisualizationDragDropContainer.h', |
|
20 | 'include/Visualization/VisualizationDragDropContainer.h', | |
21 | 'include/Visualization/VisualizationDragWidget.h', |
|
21 | 'include/Visualization/VisualizationDragWidget.h', | |
22 | 'include/Visualization/ColorScaleEditor.h', |
|
22 | 'include/Visualization/ColorScaleEditor.h', | |
23 | 'include/Actions/SelectionZoneAction.h', |
|
23 | 'include/Actions/SelectionZoneAction.h', | |
24 | 'include/Visualization/VisualizationMultiZoneSelectionDialog.h', |
|
24 | 'include/Visualization/VisualizationMultiZoneSelectionDialog.h', | |
25 | 'include/Catalogue/CatalogueExplorer.h', |
|
25 | 'include/Catalogue/CatalogueExplorer.h', | |
26 | 'include/Catalogue/CatalogueEventsWidget.h', |
|
26 | 'include/Catalogue/CatalogueEventsWidget.h', | |
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 = [ | |
34 | 'ui/DataSource/DataSourceWidget.ui', |
|
35 | 'ui/DataSource/DataSourceWidget.ui', | |
35 | 'ui/Settings/SqpSettingsDialog.ui', |
|
36 | 'ui/Settings/SqpSettingsDialog.ui', | |
36 | 'ui/Settings/SqpSettingsGeneralWidget.ui', |
|
37 | 'ui/Settings/SqpSettingsGeneralWidget.ui', | |
37 | 'ui/SidePane/SqpSidePane.ui', |
|
38 | 'ui/SidePane/SqpSidePane.ui', | |
38 | 'ui/TimeWidget/TimeWidget.ui', |
|
39 | 'ui/TimeWidget/TimeWidget.ui', | |
39 | 'ui/Variable/VariableInspectorWidget.ui', |
|
40 | 'ui/Variable/VariableInspectorWidget.ui', | |
40 | 'ui/Variable/RenameVariableDialog.ui', |
|
41 | 'ui/Variable/RenameVariableDialog.ui', | |
41 | 'ui/Variable/VariableMenuHeaderWidget.ui', |
|
42 | 'ui/Variable/VariableMenuHeaderWidget.ui', | |
42 | 'ui/Visualization/VisualizationGraphWidget.ui', |
|
43 | 'ui/Visualization/VisualizationGraphWidget.ui', | |
43 | 'ui/Visualization/VisualizationTabWidget.ui', |
|
44 | 'ui/Visualization/VisualizationTabWidget.ui', | |
44 | 'ui/Visualization/VisualizationWidget.ui', |
|
45 | 'ui/Visualization/VisualizationWidget.ui', | |
45 | 'ui/Visualization/VisualizationZoneWidget.ui', |
|
46 | 'ui/Visualization/VisualizationZoneWidget.ui', | |
46 | 'ui/Visualization/ColorScaleEditor.ui', |
|
47 | 'ui/Visualization/ColorScaleEditor.ui', | |
47 | 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui', |
|
48 | 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui', | |
48 | 'ui/Catalogue/CatalogueExplorer.ui', |
|
49 | 'ui/Catalogue/CatalogueExplorer.ui', | |
49 | 'ui/Catalogue/CatalogueEventsWidget.ui', |
|
50 | 'ui/Catalogue/CatalogueEventsWidget.ui', | |
50 | 'ui/Catalogue/CatalogueSideBarWidget.ui', |
|
51 | 'ui/Catalogue/CatalogueSideBarWidget.ui', | |
51 | 'ui/Catalogue/CatalogueInspectorWidget.ui', |
|
52 | 'ui/Catalogue/CatalogueInspectorWidget.ui', | |
52 | 'ui/Catalogue/CreateEventDialog.ui' |
|
53 | 'ui/Catalogue/CreateEventDialog.ui' | |
53 | ] |
|
54 | ] | |
54 |
|
55 | |||
55 | gui_qresources = ['resources/sqpguiresources.qrc'] |
|
56 | gui_qresources = ['resources/sqpguiresources.qrc'] | |
56 |
|
57 | |||
57 | rcc_gen = generator(rcc, |
|
58 | rcc_gen = generator(rcc, | |
58 | output : 'qrc_@BASENAME@.cpp', |
|
59 | output : 'qrc_@BASENAME@.cpp', | |
59 | arguments : [ |
|
60 | arguments : [ | |
60 | '--output', |
|
61 | '--output', | |
61 | '@OUTPUT@', |
|
62 | '@OUTPUT@', | |
62 | '@INPUT@', |
|
63 | '@INPUT@', | |
63 | '@EXTRA_ARGS@']) |
|
64 | '@EXTRA_ARGS@']) | |
64 |
|
65 | |||
65 | rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources']) |
|
66 | rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources']) | |
66 |
|
67 | |||
67 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, |
|
68 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, | |
68 | ui_files : gui_ui_files) |
|
69 | ui_files : gui_ui_files) | |
69 |
|
70 | |||
70 | gui_sources = [ |
|
71 | gui_sources = [ | |
71 | 'src/SqpApplication.cpp', |
|
72 | 'src/SqpApplication.cpp', | |
72 | 'src/DragAndDrop/DragDropGuiController.cpp', |
|
73 | 'src/DragAndDrop/DragDropGuiController.cpp', | |
73 | 'src/DragAndDrop/DragDropScroller.cpp', |
|
74 | 'src/DragAndDrop/DragDropScroller.cpp', | |
74 | 'src/DragAndDrop/DragDropTabSwitcher.cpp', |
|
75 | 'src/DragAndDrop/DragDropTabSwitcher.cpp', | |
75 | 'src/Common/ColorUtils.cpp', |
|
76 | 'src/Common/ColorUtils.cpp', | |
76 | 'src/Common/VisualizationDef.cpp', |
|
77 | 'src/Common/VisualizationDef.cpp', | |
77 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', |
|
78 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', | |
78 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', |
|
79 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', | |
79 | 'src/DataSource/DataSourceWidget.cpp', |
|
80 | 'src/DataSource/DataSourceWidget.cpp', | |
80 | 'src/DataSource/DataSourceTreeWidget.cpp', |
|
81 | 'src/DataSource/DataSourceTreeWidget.cpp', | |
81 | 'src/Settings/SqpSettingsDialog.cpp', |
|
82 | 'src/Settings/SqpSettingsDialog.cpp', | |
82 | 'src/Settings/SqpSettingsGeneralWidget.cpp', |
|
83 | 'src/Settings/SqpSettingsGeneralWidget.cpp', | |
83 | 'src/SidePane/SqpSidePane.cpp', |
|
84 | 'src/SidePane/SqpSidePane.cpp', | |
84 | 'src/TimeWidget/TimeWidget.cpp', |
|
85 | 'src/TimeWidget/TimeWidget.cpp', | |
85 | 'src/Variable/VariableInspectorWidget.cpp', |
|
86 | 'src/Variable/VariableInspectorWidget.cpp', | |
86 | 'src/Variable/VariableInspectorTableView.cpp', |
|
87 | 'src/Variable/VariableInspectorTableView.cpp', | |
87 | 'src/Variable/VariableMenuHeaderWidget.cpp', |
|
88 | 'src/Variable/VariableMenuHeaderWidget.cpp', | |
88 | 'src/Variable/RenameVariableDialog.cpp', |
|
89 | 'src/Variable/RenameVariableDialog.cpp', | |
89 | 'src/Visualization/VisualizationGraphHelper.cpp', |
|
90 | 'src/Visualization/VisualizationGraphHelper.cpp', | |
90 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', |
|
91 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', | |
91 | 'src/Visualization/VisualizationGraphWidget.cpp', |
|
92 | 'src/Visualization/VisualizationGraphWidget.cpp', | |
92 | 'src/Visualization/VisualizationTabWidget.cpp', |
|
93 | 'src/Visualization/VisualizationTabWidget.cpp', | |
93 | 'src/Visualization/VisualizationWidget.cpp', |
|
94 | 'src/Visualization/VisualizationWidget.cpp', | |
94 | 'src/Visualization/VisualizationZoneWidget.cpp', |
|
95 | 'src/Visualization/VisualizationZoneWidget.cpp', | |
95 | 'src/Visualization/qcustomplot.cpp', |
|
96 | 'src/Visualization/qcustomplot.cpp', | |
96 | 'src/Visualization/QCustomPlotSynchronizer.cpp', |
|
97 | 'src/Visualization/QCustomPlotSynchronizer.cpp', | |
97 | 'src/Visualization/operations/FindVariableOperation.cpp', |
|
98 | 'src/Visualization/operations/FindVariableOperation.cpp', | |
98 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', |
|
99 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', | |
99 | 'src/Visualization/operations/MenuBuilder.cpp', |
|
100 | 'src/Visualization/operations/MenuBuilder.cpp', | |
100 | 'src/Visualization/operations/RemoveVariableOperation.cpp', |
|
101 | 'src/Visualization/operations/RemoveVariableOperation.cpp', | |
101 | 'src/Visualization/operations/RescaleAxeOperation.cpp', |
|
102 | 'src/Visualization/operations/RescaleAxeOperation.cpp', | |
102 | 'src/Visualization/VisualizationDragDropContainer.cpp', |
|
103 | 'src/Visualization/VisualizationDragDropContainer.cpp', | |
103 | 'src/Visualization/VisualizationDragWidget.cpp', |
|
104 | 'src/Visualization/VisualizationDragWidget.cpp', | |
104 | 'src/Visualization/AxisRenderingUtils.cpp', |
|
105 | 'src/Visualization/AxisRenderingUtils.cpp', | |
105 | 'src/Visualization/PlottablesRenderingUtils.cpp', |
|
106 | 'src/Visualization/PlottablesRenderingUtils.cpp', | |
106 | 'src/Visualization/MacScrollBarStyle.cpp', |
|
107 | 'src/Visualization/MacScrollBarStyle.cpp', | |
107 | 'src/Visualization/VisualizationCursorItem.cpp', |
|
108 | 'src/Visualization/VisualizationCursorItem.cpp', | |
108 | 'src/Visualization/ColorScaleEditor.cpp', |
|
109 | 'src/Visualization/ColorScaleEditor.cpp', | |
109 | 'src/Visualization/SqpColorScale.cpp', |
|
110 | 'src/Visualization/SqpColorScale.cpp', | |
110 | 'src/Visualization/QCPColorMapIterator.cpp', |
|
111 | 'src/Visualization/QCPColorMapIterator.cpp', | |
111 | 'src/Visualization/VisualizationSelectionZoneItem.cpp', |
|
112 | 'src/Visualization/VisualizationSelectionZoneItem.cpp', | |
112 | 'src/Visualization/VisualizationSelectionZoneManager.cpp', |
|
113 | 'src/Visualization/VisualizationSelectionZoneManager.cpp', | |
113 | 'src/Actions/SelectionZoneAction.cpp', |
|
114 | 'src/Actions/SelectionZoneAction.cpp', | |
114 | 'src/Actions/ActionsGuiController.cpp', |
|
115 | 'src/Actions/ActionsGuiController.cpp', | |
115 | 'src/Visualization/VisualizationActionManager.cpp', |
|
116 | 'src/Visualization/VisualizationActionManager.cpp', | |
116 | 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp', |
|
117 | 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp', | |
117 | 'src/Catalogue/CatalogueExplorer.cpp', |
|
118 | 'src/Catalogue/CatalogueExplorer.cpp', | |
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/CatalogueTree |
|
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']) | |
129 |
|
133 | |||
130 | sciqlop_gui_lib = library('sciqlopgui', |
|
134 | sciqlop_gui_lib = library('sciqlopgui', | |
131 | gui_sources, |
|
135 | gui_sources, | |
132 | gui_moc_files, |
|
136 | gui_moc_files, | |
133 | rcc_files, |
|
137 | rcc_files, | |
134 | include_directories : [gui_inc], |
|
138 | include_directories : [gui_inc], | |
135 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], |
|
139 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], | |
136 | install : true |
|
140 | install : true | |
137 | ) |
|
141 | ) | |
138 |
|
142 | |||
139 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, |
|
143 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, | |
140 | include_directories : gui_inc, |
|
144 | include_directories : gui_inc, | |
141 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) |
|
145 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) | |
142 |
|
146 | |||
143 |
|
147 |
@@ -1,107 +1,136 | |||||
1 | #include "Catalogue/CatalogueActionManager.h" |
|
1 | #include "Catalogue/CatalogueActionManager.h" | |
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> | |
15 |
|
20 | |||
16 | #include <QBoxLayout> |
|
21 | #include <QBoxLayout> | |
17 | #include <QComboBox> |
|
22 | #include <QComboBox> | |
18 | #include <QDialog> |
|
23 | #include <QDialog> | |
19 | #include <QDialogButtonBox> |
|
24 | #include <QDialogButtonBox> | |
20 | #include <QLineEdit> |
|
25 | #include <QLineEdit> | |
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) | |
27 | { |
|
40 | { | |
28 | auto event = std::make_shared<DBEvent>(); |
|
41 | auto event = std::make_shared<DBEvent>(); | |
29 | event->setName(eventName); |
|
42 | event->setName(eventName); | |
30 |
|
43 | |||
31 | std::list<DBEventProduct> productList; |
|
44 | std::list<DBEventProduct> productList; | |
32 | for (auto zone : zones) { |
|
45 | for (auto zone : zones) { | |
33 | auto graph = zone->parentGraphWidget(); |
|
46 | auto graph = zone->parentGraphWidget(); | |
34 | for (auto var : graph->variables()) { |
|
47 | for (auto var : graph->variables()) { | |
35 | auto eventProduct = std::make_shared<DBEventProduct>(); |
|
48 | auto eventProduct = std::make_shared<DBEventProduct>(); | |
36 | eventProduct->setEvent(*event); |
|
49 | eventProduct->setEvent(*event); | |
37 |
|
50 | |||
38 | auto zoneRange = zone->range(); |
|
51 | auto zoneRange = zone->range(); | |
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( |
|
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 | } | |
46 | } |
|
60 | } | |
47 |
|
61 | |||
48 | event->setEventProducts(productList); |
|
62 | event->setEventProducts(productList); | |
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 | |||
64 | void CatalogueActionManager::installSelectionZoneActions() |
|
88 | void CatalogueActionManager::installSelectionZoneActions() | |
65 | { |
|
89 | { | |
66 | auto &actionController = sqpApp->actionsGuiController(); |
|
90 | auto &actionController = sqpApp->actionsGuiController(); | |
67 |
|
91 | |||
68 | auto createEventEnableFuntion = [](auto zones) { |
|
92 | auto createEventEnableFuntion = [](auto zones) { | |
69 | QSet<VisualizationGraphWidget *> usedGraphs; |
|
93 | QSet<VisualizationGraphWidget *> usedGraphs; | |
70 | for (auto zone : zones) { |
|
94 | for (auto zone : zones) { | |
71 | auto graph = zone->parentGraphWidget(); |
|
95 | auto graph = zone->parentGraphWidget(); | |
72 | if (!usedGraphs.contains(graph)) { |
|
96 | if (!usedGraphs.contains(graph)) { | |
73 | usedGraphs.insert(graph); |
|
97 | usedGraphs.insert(graph); | |
74 | } |
|
98 | } | |
75 | else { |
|
99 | else { | |
76 | return false; |
|
100 | return false; | |
77 | } |
|
101 | } | |
78 | } |
|
102 | } | |
79 |
|
103 | |||
80 | return true; |
|
104 | return true; | |
81 | }; |
|
105 | }; | |
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); | |
89 | } |
|
114 | } | |
90 | }); |
|
115 | }); | |
91 | createEventAction->setEnableFunction(createEventEnableFuntion); |
|
116 | createEventAction->setEnableFunction(createEventEnableFuntion); | |
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); | |
104 | } |
|
133 | } | |
105 | }); |
|
134 | }); | |
106 | createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion); |
|
135 | createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion); | |
107 | } |
|
136 | } |
@@ -1,442 +1,461 | |||||
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> | |
6 | #include <DBEventProduct.h> |
|
7 | #include <DBEventProduct.h> | |
7 | #include <DBTag.h> |
|
8 | #include <DBTag.h> | |
8 | #include <Data/SqpRange.h> |
|
9 | #include <Data/SqpRange.h> | |
9 | #include <SqpApplication.h> |
|
10 | #include <SqpApplication.h> | |
10 | #include <Time/TimeController.h> |
|
11 | #include <Time/TimeController.h> | |
11 |
|
12 | |||
12 | #include <list> |
|
13 | #include <list> | |
13 | #include <unordered_map> |
|
14 | #include <unordered_map> | |
14 |
|
15 | |||
15 | #include <QHash> |
|
16 | #include <QHash> | |
16 | #include <QMimeData> |
|
17 | #include <QMimeData> | |
17 |
|
18 | |||
18 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsModel, "CatalogueEventsModel") |
|
19 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsModel, "CatalogueEventsModel") | |
19 |
|
20 | |||
20 | const auto EVENT_ITEM_TYPE = 1; |
|
21 | const auto EVENT_ITEM_TYPE = 1; | |
21 | const auto EVENT_PRODUCT_ITEM_TYPE = 2; |
|
22 | const auto EVENT_PRODUCT_ITEM_TYPE = 2; | |
22 |
|
23 | |||
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 | { | |
30 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), |
|
30 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), | |
31 | tr("Tags"), tr("Product"), tr("")}; |
|
31 | tr("Tags"), tr("Product"), tr("")}; | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
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); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const |
|
44 | QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const | |
45 | { |
|
45 | { | |
46 | switch (static_cast<Column>(col)) { |
|
46 | switch (static_cast<Column>(col)) { | |
47 | case CatalogueEventsModel::Column::Name: |
|
47 | case CatalogueEventsModel::Column::Name: | |
48 | return event->getName(); |
|
48 | return event->getName(); | |
49 | case CatalogueEventsModel::Column::TStart: |
|
49 | case CatalogueEventsModel::Column::TStart: | |
50 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTStart()) |
|
50 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTStart()) | |
51 | : QVariant{}; |
|
51 | : QVariant{}; | |
52 | case CatalogueEventsModel::Column::TEnd: |
|
52 | case CatalogueEventsModel::Column::TEnd: | |
53 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTEnd()) |
|
53 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTEnd()) | |
54 | : QVariant{}; |
|
54 | : QVariant{}; | |
55 | case CatalogueEventsModel::Column::Product: |
|
55 | case CatalogueEventsModel::Column::Product: | |
56 | return QString::number(nbEventProducts(event)) + " product(s)"; |
|
56 | return QString::number(nbEventProducts(event)) + " product(s)"; | |
57 | case CatalogueEventsModel::Column::Tags: { |
|
57 | case CatalogueEventsModel::Column::Tags: { | |
58 | QString tagList; |
|
58 | QString tagList; | |
59 | auto tags = event->getTags(); |
|
59 | auto tags = event->getTags(); | |
60 | for (auto tag : tags) { |
|
60 | for (auto tag : tags) { | |
61 | tagList += tag.getName(); |
|
61 | tagList += tag.getName(); | |
62 | tagList += ' '; |
|
62 | tagList += ' '; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | return tagList; |
|
65 | return tagList; | |
66 | } |
|
66 | } | |
67 | case CatalogueEventsModel::Column::Validation: |
|
67 | case CatalogueEventsModel::Column::Validation: | |
68 | return QVariant(); |
|
68 | return QVariant(); | |
69 | default: |
|
69 | default: | |
70 | break; |
|
70 | break; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | Q_ASSERT(false); |
|
73 | Q_ASSERT(false); | |
74 | return QStringLiteral("Unknown Data"); |
|
74 | return QStringLiteral("Unknown Data"); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void parseEventProduct(const std::shared_ptr<DBEvent> &event) |
|
77 | void parseEventProduct(const std::shared_ptr<DBEvent> &event) | |
78 | { |
|
78 | { | |
79 | for (auto product : event->getEventProducts()) { |
|
79 | for (auto product : event->getEventProducts()) { | |
80 | m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product)); |
|
80 | m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product)); | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | int nbEventProducts(const std::shared_ptr<DBEvent> &event) const |
|
84 | int nbEventProducts(const std::shared_ptr<DBEvent> &event) const | |
85 | { |
|
85 | { | |
86 | auto eventProductsIt = m_EventProducts.find(event.get()); |
|
86 | auto eventProductsIt = m_EventProducts.find(event.get()); | |
87 | if (eventProductsIt != m_EventProducts.cend()) { |
|
87 | if (eventProductsIt != m_EventProducts.cend()) { | |
88 | return m_EventProducts.at(event.get()).count(); |
|
88 | return m_EventProducts.at(event.get()).count(); | |
89 | } |
|
89 | } | |
90 | else { |
|
90 | else { | |
91 | return 0; |
|
91 | return 0; | |
92 | } |
|
92 | } | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const |
|
95 | QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const | |
96 | { |
|
96 | { | |
97 | switch (static_cast<Column>(col)) { |
|
97 | switch (static_cast<Column>(col)) { | |
98 | case CatalogueEventsModel::Column::Name: |
|
98 | case CatalogueEventsModel::Column::Name: | |
99 | return eventProduct->getProductId(); |
|
99 | return eventProduct->getProductId(); | |
100 | case CatalogueEventsModel::Column::TStart: |
|
100 | case CatalogueEventsModel::Column::TStart: | |
101 | return DateUtils::dateTime(eventProduct->getTStart()); |
|
101 | return DateUtils::dateTime(eventProduct->getTStart()); | |
102 | case CatalogueEventsModel::Column::TEnd: |
|
102 | case CatalogueEventsModel::Column::TEnd: | |
103 | return DateUtils::dateTime(eventProduct->getTEnd()); |
|
103 | return DateUtils::dateTime(eventProduct->getTEnd()); | |
104 | case CatalogueEventsModel::Column::Product: |
|
104 | case CatalogueEventsModel::Column::Product: | |
105 | return eventProduct->getProductId(); |
|
105 | return eventProduct->getProductId(); | |
106 | case CatalogueEventsModel::Column::Tags: |
|
106 | case CatalogueEventsModel::Column::Tags: | |
107 | return QString(); |
|
107 | return QString(); | |
108 | case CatalogueEventsModel::Column::Validation: |
|
108 | case CatalogueEventsModel::Column::Validation: | |
109 | return QVariant(); |
|
109 | return QVariant(); | |
110 | default: |
|
110 | default: | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
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) | |
120 | : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()} |
|
128 | : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueEventsModelPrivate>()} | |
121 | { |
|
129 | { | |
122 | } |
|
130 | } | |
123 |
|
131 | |||
124 | void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events) |
|
132 | void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events) | |
125 | { |
|
133 | { | |
126 | beginResetModel(); |
|
134 | beginResetModel(); | |
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 | } | |
134 |
|
141 | |||
135 | endResetModel(); |
|
142 | endResetModel(); | |
136 | } |
|
143 | } | |
137 |
|
144 | |||
138 | std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const |
|
145 | std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(const QModelIndex &index) const | |
139 | { |
|
146 | { | |
140 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) { |
|
147 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::Event) { | |
141 | return impl->m_Events.value(index.row()); |
|
148 | return impl->m_Events.value(index.row()); | |
142 | } |
|
149 | } | |
143 | else { |
|
150 | else { | |
144 | return nullptr; |
|
151 | return nullptr; | |
145 | } |
|
152 | } | |
146 | } |
|
153 | } | |
147 |
|
154 | |||
148 | std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const |
|
155 | std::shared_ptr<DBEvent> CatalogueEventsModel::getParentEvent(const QModelIndex &index) const | |
149 | { |
|
156 | { | |
150 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { |
|
157 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { | |
151 | return getEvent(index.parent()); |
|
158 | return getEvent(index.parent()); | |
152 | } |
|
159 | } | |
153 | else { |
|
160 | else { | |
154 | return nullptr; |
|
161 | return nullptr; | |
155 | } |
|
162 | } | |
156 | } |
|
163 | } | |
157 |
|
164 | |||
158 | std::shared_ptr<DBEventProduct> |
|
165 | std::shared_ptr<DBEventProduct> | |
159 | CatalogueEventsModel::getEventProduct(const QModelIndex &index) const |
|
166 | CatalogueEventsModel::getEventProduct(const QModelIndex &index) const | |
160 | { |
|
167 | { | |
161 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { |
|
168 | if (itemTypeOf(index) == CatalogueEventsModel::ItemType::EventProduct) { | |
162 | auto event = static_cast<DBEvent *>(index.internalPointer()); |
|
169 | auto event = static_cast<DBEvent *>(index.internalPointer()); | |
163 | return impl->m_EventProducts.at(event).value(index.row()); |
|
170 | return impl->m_EventProducts.at(event).value(index.row()); | |
164 | } |
|
171 | } | |
165 | else { |
|
172 | else { | |
166 | return nullptr; |
|
173 | return nullptr; | |
167 | } |
|
174 | } | |
168 | } |
|
175 | } | |
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() |
|
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) | |
179 | { |
|
190 | { | |
180 | auto index = impl->m_Events.indexOf(event); |
|
191 | auto index = impl->m_Events.indexOf(event); | |
181 | if (index >= 0) { |
|
192 | if (index >= 0) { | |
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 | } | |
189 |
|
199 | |||
190 | QVector<std::shared_ptr<DBEvent> > CatalogueEventsModel::events() const |
|
200 | QVector<std::shared_ptr<DBEvent> > CatalogueEventsModel::events() const | |
191 | { |
|
201 | { | |
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."; | |
210 | } |
|
243 | } | |
211 | } |
|
244 | } | |
212 |
|
245 | |||
213 | QModelIndex CatalogueEventsModel::indexOf(const std::shared_ptr<DBEvent> &event) const |
|
246 | QModelIndex CatalogueEventsModel::indexOf(const std::shared_ptr<DBEvent> &event) const | |
214 | { |
|
247 | { | |
215 | auto row = impl->m_Events.indexOf(event); |
|
248 | auto row = impl->m_Events.indexOf(event); | |
216 | if (row >= 0) { |
|
249 | if (row >= 0) { | |
217 | return index(row, 0); |
|
250 | return index(row, 0); | |
218 | } |
|
251 | } | |
219 |
|
252 | |||
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)) { | |
242 | return QModelIndex(); |
|
259 | return QModelIndex(); | |
243 | } |
|
260 | } | |
244 |
|
261 | |||
245 | switch (itemTypeOf(parent)) { |
|
262 | switch (itemTypeOf(parent)) { | |
246 | case CatalogueEventsModel::ItemType::Root: |
|
263 | case CatalogueEventsModel::ItemType::Root: | |
247 | return createIndex(row, column); |
|
264 | return createIndex(row, column); | |
248 | case CatalogueEventsModel::ItemType::Event: { |
|
265 | case CatalogueEventsModel::ItemType::Event: { | |
249 | auto event = getEvent(parent); |
|
266 | auto event = getEvent(parent); | |
250 | return createIndex(row, column, event.get()); |
|
267 | return createIndex(row, column, event.get()); | |
251 | } |
|
268 | } | |
252 | case CatalogueEventsModel::ItemType::EventProduct: |
|
269 | case CatalogueEventsModel::ItemType::EventProduct: | |
253 | break; |
|
270 | break; | |
254 | default: |
|
271 | default: | |
255 | break; |
|
272 | break; | |
256 | } |
|
273 | } | |
257 |
|
274 | |||
258 | return QModelIndex(); |
|
275 | return QModelIndex(); | |
259 | } |
|
276 | } | |
260 |
|
277 | |||
261 | QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const |
|
278 | QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const | |
262 | { |
|
279 | { | |
263 | switch (itemTypeOf(index)) { |
|
280 | switch (itemTypeOf(index)) { | |
264 | case CatalogueEventsModel::ItemType::EventProduct: { |
|
281 | case CatalogueEventsModel::ItemType::EventProduct: { | |
265 | auto parentEvent = static_cast<DBEvent *>(index.internalPointer()); |
|
282 | auto parentEvent = static_cast<DBEvent *>(index.internalPointer()); | |
266 | auto it |
|
283 | auto it | |
267 | = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(), |
|
284 | = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(), | |
268 | [parentEvent](auto event) { return event.get() == parentEvent; }); |
|
285 | [parentEvent](auto event) { return event.get() == parentEvent; }); | |
269 |
|
286 | |||
270 | if (it != impl->m_Events.cend()) { |
|
287 | if (it != impl->m_Events.cend()) { | |
271 | return createIndex(it - impl->m_Events.cbegin(), 0); |
|
288 | return createIndex(it - impl->m_Events.cbegin(), 0); | |
272 | } |
|
289 | } | |
273 | else { |
|
290 | else { | |
274 | return QModelIndex(); |
|
291 | return QModelIndex(); | |
275 | } |
|
292 | } | |
276 | } |
|
293 | } | |
277 | case CatalogueEventsModel::ItemType::Root: |
|
294 | case CatalogueEventsModel::ItemType::Root: | |
278 | break; |
|
295 | break; | |
279 | case CatalogueEventsModel::ItemType::Event: |
|
296 | case CatalogueEventsModel::ItemType::Event: | |
280 | break; |
|
297 | break; | |
281 | default: |
|
298 | default: | |
282 | break; |
|
299 | break; | |
283 | } |
|
300 | } | |
284 |
|
301 | |||
285 | return QModelIndex(); |
|
302 | return QModelIndex(); | |
286 | } |
|
303 | } | |
287 |
|
304 | |||
288 | int CatalogueEventsModel::rowCount(const QModelIndex &parent) const |
|
305 | int CatalogueEventsModel::rowCount(const QModelIndex &parent) const | |
289 | { |
|
306 | { | |
290 | if (parent.column() > 0) { |
|
307 | if (parent.column() > 0) { | |
291 | return 0; |
|
308 | return 0; | |
292 | } |
|
309 | } | |
293 |
|
310 | |||
294 | switch (itemTypeOf(parent)) { |
|
311 | switch (itemTypeOf(parent)) { | |
295 | case CatalogueEventsModel::ItemType::Root: |
|
312 | case CatalogueEventsModel::ItemType::Root: | |
296 | return impl->m_Events.count(); |
|
313 | return impl->m_Events.count(); | |
297 | case CatalogueEventsModel::ItemType::Event: { |
|
314 | case CatalogueEventsModel::ItemType::Event: { | |
298 | auto event = getEvent(parent); |
|
315 | auto event = getEvent(parent); | |
299 | return impl->m_EventProducts[event.get()].count(); |
|
316 | return impl->m_EventProducts[event.get()].count(); | |
300 | } |
|
317 | } | |
301 | case CatalogueEventsModel::ItemType::EventProduct: |
|
318 | case CatalogueEventsModel::ItemType::EventProduct: | |
302 | break; |
|
319 | break; | |
303 | default: |
|
320 | default: | |
304 | break; |
|
321 | break; | |
305 | } |
|
322 | } | |
306 |
|
323 | |||
307 | return 0; |
|
324 | return 0; | |
308 | } |
|
325 | } | |
309 |
|
326 | |||
310 | int CatalogueEventsModel::columnCount(const QModelIndex &parent) const |
|
327 | int CatalogueEventsModel::columnCount(const QModelIndex &parent) const | |
311 | { |
|
328 | { | |
312 | return static_cast<int>(CatalogueEventsModel::Column::NbColumn); |
|
329 | return static_cast<int>(CatalogueEventsModel::Column::NbColumn); | |
313 | } |
|
330 | } | |
314 |
|
331 | |||
315 | Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const |
|
332 | Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const | |
316 | { |
|
333 | { | |
317 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; |
|
334 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; | |
318 | } |
|
335 | } | |
319 |
|
336 | |||
320 | QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const |
|
337 | QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const | |
321 | { |
|
338 | { | |
322 | if (index.isValid()) { |
|
339 | if (index.isValid()) { | |
323 |
|
340 | |||
324 | auto type = itemTypeOf(index); |
|
341 | auto type = itemTypeOf(index); | |
325 | if (type == CatalogueEventsModel::ItemType::Event) { |
|
342 | if (type == CatalogueEventsModel::ItemType::Event) { | |
326 | auto event = getEvent(index); |
|
343 | auto event = getEvent(index); | |
327 | switch (role) { |
|
344 | switch (role) { | |
328 | case Qt::DisplayRole: |
|
345 | case Qt::DisplayRole: | |
329 | return impl->eventData(index.column(), event); |
|
346 | return impl->eventData(index.column(), event); | |
330 | break; |
|
347 | break; | |
331 | } |
|
348 | } | |
332 | } |
|
349 | } | |
333 | else if (type == CatalogueEventsModel::ItemType::EventProduct) { |
|
350 | else if (type == CatalogueEventsModel::ItemType::EventProduct) { | |
334 | auto product = getEventProduct(index); |
|
351 | auto product = getEventProduct(index); | |
335 | switch (role) { |
|
352 | switch (role) { | |
336 | case Qt::DisplayRole: |
|
353 | case Qt::DisplayRole: | |
337 | return impl->eventProductData(index.column(), product); |
|
354 | return impl->eventProductData(index.column(), product); | |
338 | break; |
|
355 | break; | |
339 | } |
|
356 | } | |
340 | } |
|
357 | } | |
341 | } |
|
358 | } | |
342 |
|
359 | |||
343 | return QVariant{}; |
|
360 | return QVariant{}; | |
344 | } |
|
361 | } | |
345 |
|
362 | |||
346 | QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
363 | QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const | |
347 | { |
|
364 | { | |
348 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
|
365 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | |
349 | return impl->columnNames().value(section); |
|
366 | return impl->columnNames().value(section); | |
350 | } |
|
367 | } | |
351 |
|
368 | |||
352 | return QVariant(); |
|
369 | return QVariant(); | |
353 | } |
|
370 | } | |
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); | |
360 | auto data2 = impl->sortData(column, e2); |
|
378 | auto data2 = impl->sortData(column, e2); | |
361 |
|
379 | |||
362 | auto result = data1.toString() < data2.toString(); |
|
380 | auto result = data1.toString() < data2.toString(); | |
363 |
|
381 | |||
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 |
|
391 | return Qt::CopyAction; | |
374 | } |
|
392 | } | |
375 |
|
393 | |||
376 | QStringList CatalogueEventsModel::mimeTypes() const |
|
394 | QStringList CatalogueEventsModel::mimeTypes() const | |
377 | { |
|
395 | { | |
378 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; |
|
396 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; | |
379 | } |
|
397 | } | |
380 |
|
398 | |||
381 | QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const |
|
399 | QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const | |
382 | { |
|
400 | { | |
383 | auto mimeData = new QMimeData; |
|
401 | auto mimeData = new QMimeData; | |
384 |
|
402 | |||
385 | bool isFirst = true; |
|
403 | bool isFirst = true; | |
386 |
|
404 | |||
387 | QVector<std::shared_ptr<DBEvent> > eventList; |
|
405 | QVector<std::shared_ptr<DBEvent> > eventList; | |
388 | QVector<std::shared_ptr<DBEventProduct> > eventProductList; |
|
406 | QVector<std::shared_ptr<DBEventProduct> > eventProductList; | |
389 |
|
407 | |||
390 | SqpRange firstTimeRange; |
|
408 | SqpRange firstTimeRange; | |
391 | for (const auto &index : indexes) { |
|
409 | for (const auto &index : indexes) { | |
392 | if (index.column() == 0) { // only the first column |
|
410 | if (index.column() == 0) { // only the first column | |
393 |
|
411 | |||
394 | auto type = itemTypeOf(index); |
|
412 | auto type = itemTypeOf(index); | |
395 | if (type == ItemType::Event) { |
|
413 | if (type == ItemType::Event) { | |
396 | auto event = getEvent(index); |
|
414 | auto event = getEvent(index); | |
397 | eventList << event; |
|
415 | eventList << event; | |
398 |
|
416 | |||
399 | if (isFirst) { |
|
417 | if (isFirst) { | |
400 | isFirst = false; |
|
418 | isFirst = false; | |
401 | firstTimeRange.m_TStart = event->getTStart(); |
|
419 | firstTimeRange.m_TStart = event->getTStart(); | |
402 | firstTimeRange.m_TEnd = event->getTEnd(); |
|
420 | firstTimeRange.m_TEnd = event->getTEnd(); | |
403 | } |
|
421 | } | |
404 | } |
|
422 | } | |
405 | else if (type == ItemType::EventProduct) { |
|
423 | else if (type == ItemType::EventProduct) { | |
406 | auto product = getEventProduct(index); |
|
424 | auto product = getEventProduct(index); | |
407 | eventProductList << product; |
|
425 | eventProductList << product; | |
408 |
|
426 | |||
409 | if (isFirst) { |
|
427 | if (isFirst) { | |
410 | isFirst = false; |
|
428 | isFirst = false; | |
411 | firstTimeRange.m_TStart = product->getTStart(); |
|
429 | firstTimeRange.m_TStart = product->getTStart(); | |
412 | firstTimeRange.m_TEnd = product->getTEnd(); |
|
430 | firstTimeRange.m_TEnd = product->getTEnd(); | |
413 | } |
|
431 | } | |
414 | } |
|
432 | } | |
415 | } |
|
433 | } | |
416 | } |
|
434 | } | |
417 |
|
435 | |||
418 | auto eventsEncodedData |
|
436 | if (!eventList.isEmpty() && eventProductList.isEmpty()) { | |
419 |
= |
|
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 | |
424 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); |
|
443 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); | |
425 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); |
|
444 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); | |
426 | } |
|
445 | } | |
427 |
|
446 | |||
428 | return mimeData; |
|
447 | return mimeData; | |
429 | } |
|
448 | } | |
430 |
|
449 | |||
431 | CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const |
|
450 | CatalogueEventsModel::ItemType CatalogueEventsModel::itemTypeOf(const QModelIndex &index) const | |
432 | { |
|
451 | { | |
433 | if (!index.isValid()) { |
|
452 | if (!index.isValid()) { | |
434 | return ItemType::Root; |
|
453 | return ItemType::Root; | |
435 | } |
|
454 | } | |
436 | else if (index.internalPointer() == nullptr) { |
|
455 | else if (index.internalPointer() == nullptr) { | |
437 | return ItemType::Event; |
|
456 | return ItemType::Event; | |
438 | } |
|
457 | } | |
439 | else { |
|
458 | else { | |
440 | return ItemType::EventProduct; |
|
459 | return ItemType::EventProduct; | |
441 | } |
|
460 | } | |
442 | } |
|
461 | } |
@@ -1,360 +1,460 | |||||
1 | #include "Catalogue/CatalogueEventsWidget.h" |
|
1 | #include "Catalogue/CatalogueEventsWidget.h" | |
2 | #include "ui_CatalogueEventsWidget.h" |
|
2 | #include "ui_CatalogueEventsWidget.h" | |
3 |
|
3 | |||
4 | #include <Catalogue/CatalogueController.h> |
|
4 | #include <Catalogue/CatalogueController.h> | |
5 | #include <Catalogue/CatalogueEventsModel.h> |
|
5 | #include <Catalogue/CatalogueEventsModel.h> | |
6 | #include <Catalogue/CatalogueExplorerHelper.h> |
|
6 | #include <Catalogue/CatalogueExplorerHelper.h> | |
7 | #include <CatalogueDao.h> |
|
7 | #include <CatalogueDao.h> | |
8 | #include <DBCatalogue.h> |
|
8 | #include <DBCatalogue.h> | |
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 | #include <Visualization/VisualizationTabWidget.h> |
|
10 | #include <Visualization/VisualizationTabWidget.h> | |
11 | #include <Visualization/VisualizationWidget.h> |
|
11 | #include <Visualization/VisualizationWidget.h> | |
12 | #include <Visualization/VisualizationZoneWidget.h> |
|
12 | #include <Visualization/VisualizationZoneWidget.h> | |
13 |
|
13 | |||
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 | |||
20 | /// Fixed size of the validation column |
|
21 | /// Fixed size of the validation column | |
21 | const auto VALIDATION_COLUMN_SIZE = 35; |
|
22 | const auto VALIDATION_COLUMN_SIZE = 35; | |
22 |
|
23 | |||
23 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { |
|
24 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |
24 |
|
25 | |||
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, |
|
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) | |
39 | { |
|
48 | { | |
40 | treeView->setSortingEnabled(false); |
|
49 | treeView->setSortingEnabled(false); | |
41 | m_Model->addEvent(event); |
|
50 | m_Model->addEvent(event); | |
42 | treeView->setSortingEnabled(true); |
|
51 | treeView->setSortingEnabled(true); | |
43 | } |
|
52 | } | |
44 |
|
53 | |||
45 | void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) |
|
54 | void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) | |
46 | { |
|
55 | { | |
47 | treeView->setSortingEnabled(false); |
|
56 | treeView->setSortingEnabled(false); | |
48 | m_Model->removeEvent(event); |
|
57 | m_Model->removeEvent(event); | |
49 | treeView->setSortingEnabled(true); |
|
58 | treeView->setSortingEnabled(true); | |
50 | } |
|
59 | } | |
51 |
|
60 | |||
52 | QStringList getAvailableVisualizationZoneList() const |
|
61 | QStringList getAvailableVisualizationZoneList() const | |
53 | { |
|
62 | { | |
54 | if (m_VisualizationWidget) { |
|
63 | if (m_VisualizationWidget) { | |
55 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
64 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
56 | return tab->availableZoneWidgets(); |
|
65 | return tab->availableZoneWidgets(); | |
57 | } |
|
66 | } | |
58 | } |
|
67 | } | |
59 |
|
68 | |||
60 | return QStringList{}; |
|
69 | return QStringList{}; | |
61 | } |
|
70 | } | |
62 |
|
71 | |||
63 | QStringList selectZone(QWidget *parent, const QStringList &selectedZones, |
|
72 | QStringList selectZone(QWidget *parent, const QStringList &selectedZones, | |
64 | bool allowMultiSelection, const QPoint &location) |
|
73 | bool allowMultiSelection, const QPoint &location) | |
65 | { |
|
74 | { | |
66 | auto availableZones = getAvailableVisualizationZoneList(); |
|
75 | auto availableZones = getAvailableVisualizationZoneList(); | |
67 | if (availableZones.isEmpty()) { |
|
76 | if (availableZones.isEmpty()) { | |
68 | return QStringList{}; |
|
77 | return QStringList{}; | |
69 | } |
|
78 | } | |
70 |
|
79 | |||
71 | QDialog d(parent, Qt::Tool); |
|
80 | QDialog d(parent, Qt::Tool); | |
72 | d.setWindowTitle("Choose a zone"); |
|
81 | d.setWindowTitle("Choose a zone"); | |
73 | auto layout = new QVBoxLayout{&d}; |
|
82 | auto layout = new QVBoxLayout{&d}; | |
74 | layout->setContentsMargins(0, 0, 0, 0); |
|
83 | layout->setContentsMargins(0, 0, 0, 0); | |
75 | auto listWidget = new QListWidget{&d}; |
|
84 | auto listWidget = new QListWidget{&d}; | |
76 | layout->addWidget(listWidget); |
|
85 | layout->addWidget(listWidget); | |
77 |
|
86 | |||
78 | QSet<QListWidgetItem *> checkedItems; |
|
87 | QSet<QListWidgetItem *> checkedItems; | |
79 | for (auto zone : availableZones) { |
|
88 | for (auto zone : availableZones) { | |
80 | auto item = new QListWidgetItem{zone}; |
|
89 | auto item = new QListWidgetItem{zone}; | |
81 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); |
|
90 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); | |
82 | if (selectedZones.contains(zone)) { |
|
91 | if (selectedZones.contains(zone)) { | |
83 | item->setCheckState(Qt::Checked); |
|
92 | item->setCheckState(Qt::Checked); | |
84 | checkedItems << item; |
|
93 | checkedItems << item; | |
85 | } |
|
94 | } | |
86 | else { |
|
95 | else { | |
87 | item->setCheckState(Qt::Unchecked); |
|
96 | item->setCheckState(Qt::Unchecked); | |
88 | } |
|
97 | } | |
89 |
|
98 | |||
90 | listWidget->addItem(item); |
|
99 | listWidget->addItem(item); | |
91 | } |
|
100 | } | |
92 |
|
101 | |||
93 | auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d}; |
|
102 | auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d}; | |
94 | layout->addWidget(buttonBox); |
|
103 | layout->addWidget(buttonBox); | |
95 |
|
104 | |||
96 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept); |
|
105 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept); | |
97 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject); |
|
106 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject); | |
98 |
|
107 | |||
99 | QObject::connect(listWidget, &QListWidget::itemChanged, |
|
108 | QObject::connect(listWidget, &QListWidget::itemChanged, | |
100 | [&checkedItems, allowMultiSelection, listWidget](auto item) { |
|
109 | [&checkedItems, allowMultiSelection, listWidget](auto item) { | |
101 | if (item->checkState() == Qt::Checked) { |
|
110 | if (item->checkState() == Qt::Checked) { | |
102 | if (!allowMultiSelection) { |
|
111 | if (!allowMultiSelection) { | |
103 | for (auto checkedItem : checkedItems) { |
|
112 | for (auto checkedItem : checkedItems) { | |
104 | listWidget->blockSignals(true); |
|
113 | listWidget->blockSignals(true); | |
105 | checkedItem->setCheckState(Qt::Unchecked); |
|
114 | checkedItem->setCheckState(Qt::Unchecked); | |
106 | listWidget->blockSignals(false); |
|
115 | listWidget->blockSignals(false); | |
107 | } |
|
116 | } | |
108 |
|
117 | |||
109 | checkedItems.clear(); |
|
118 | checkedItems.clear(); | |
110 | } |
|
119 | } | |
111 | checkedItems << item; |
|
120 | checkedItems << item; | |
112 | } |
|
121 | } | |
113 | else { |
|
122 | else { | |
114 | checkedItems.remove(item); |
|
123 | checkedItems.remove(item); | |
115 | } |
|
124 | } | |
116 | }); |
|
125 | }); | |
117 |
|
126 | |||
118 | QStringList result; |
|
127 | QStringList result; | |
119 |
|
128 | |||
120 | d.setMinimumWidth(120); |
|
129 | d.setMinimumWidth(120); | |
121 | d.resize(d.minimumSizeHint()); |
|
130 | d.resize(d.minimumSizeHint()); | |
122 | d.move(location); |
|
131 | d.move(location); | |
123 | if (d.exec() == QDialog::Accepted) { |
|
132 | if (d.exec() == QDialog::Accepted) { | |
124 | for (auto item : checkedItems) { |
|
133 | for (auto item : checkedItems) { | |
125 | result += item->text(); |
|
134 | result += item->text(); | |
126 | } |
|
135 | } | |
127 | } |
|
136 | } | |
128 | else { |
|
137 | else { | |
129 | result = selectedZones; |
|
138 | result = selectedZones; | |
130 | } |
|
139 | } | |
131 |
|
140 | |||
132 | return result; |
|
141 | return result; | |
133 | } |
|
142 | } | |
134 |
|
143 | |||
135 | void updateForTimeMode(QTreeView *treeView) |
|
144 | void updateForTimeMode(QTreeView *treeView) | |
136 | { |
|
145 | { | |
137 | auto selectedRows = treeView->selectionModel()->selectedRows(); |
|
146 | auto selectedRows = treeView->selectionModel()->selectedRows(); | |
138 |
|
147 | |||
139 | if (selectedRows.count() == 1) { |
|
148 | if (selectedRows.count() == 1) { | |
140 | auto event = m_Model->getEvent(selectedRows.first()); |
|
149 | auto event = m_Model->getEvent(selectedRows.first()); | |
141 | if (event) { |
|
150 | if (event) { | |
142 | if (m_VisualizationWidget) { |
|
151 | if (m_VisualizationWidget) { | |
143 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
152 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
144 |
|
153 | |||
145 | for (auto zoneName : m_ZonesForTimeMode) { |
|
154 | for (auto zoneName : m_ZonesForTimeMode) { | |
146 | if (auto zone = tab->getZoneWithName(zoneName)) { |
|
155 | if (auto zone = tab->getZoneWithName(zoneName)) { | |
147 | SqpRange eventRange; |
|
156 | SqpRange eventRange; | |
148 | eventRange.m_TStart = event->getTStart(); |
|
157 | eventRange.m_TStart = event->getTStart(); | |
149 | eventRange.m_TEnd = event->getTEnd(); |
|
158 | eventRange.m_TEnd = event->getTEnd(); | |
150 | zone->setZoneRange(eventRange); |
|
159 | zone->setZoneRange(eventRange); | |
151 | } |
|
160 | } | |
152 | } |
|
161 | } | |
153 | } |
|
162 | } | |
154 | else { |
|
163 | else { | |
155 | qCWarning(LOG_CatalogueEventsWidget()) |
|
164 | qCWarning(LOG_CatalogueEventsWidget()) | |
156 | << "updateTimeZone: no tab found in the visualization"; |
|
165 | << "updateTimeZone: no tab found in the visualization"; | |
157 | } |
|
166 | } | |
158 | } |
|
167 | } | |
159 | else { |
|
168 | else { | |
160 | qCWarning(LOG_CatalogueEventsWidget()) |
|
169 | qCWarning(LOG_CatalogueEventsWidget()) | |
161 | << "updateTimeZone: visualization widget not found"; |
|
170 | << "updateTimeZone: visualization widget not found"; | |
162 | } |
|
171 | } | |
163 | } |
|
172 | } | |
164 | } |
|
173 | } | |
165 | else { |
|
174 | else { | |
166 | qCWarning(LOG_CatalogueEventsWidget()) |
|
175 | qCWarning(LOG_CatalogueEventsWidget()) | |
167 | << "updateTimeZone: not compatible with multiple events selected"; |
|
176 | << "updateTimeZone: not compatible with multiple events selected"; | |
168 | } |
|
177 | } | |
169 | } |
|
178 | } | |
170 |
|
179 | |||
171 | void updateForGraphMode(QTreeView *treeView) |
|
180 | void updateForGraphMode(QTreeView *treeView) | |
172 | { |
|
181 | { | |
173 | auto selectedRows = treeView->selectionModel()->selectedRows(); |
|
182 | auto selectedRows = treeView->selectionModel()->selectedRows(); | |
174 |
|
183 | |||
175 | if (selectedRows.count() == 1) { |
|
184 | if (selectedRows.count() == 1) { | |
176 | auto event = m_Model->getEvent(selectedRows.first()); |
|
185 | auto event = m_Model->getEvent(selectedRows.first()); | |
177 | if (m_VisualizationWidget) { |
|
186 | if (m_VisualizationWidget) { | |
178 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
187 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
179 | if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { |
|
188 | if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { | |
180 | // TODO |
|
189 | // TODO | |
181 | } |
|
190 | } | |
182 | } |
|
191 | } | |
183 | else { |
|
192 | else { | |
184 | qCWarning(LOG_CatalogueEventsWidget()) |
|
193 | qCWarning(LOG_CatalogueEventsWidget()) | |
185 | << "updateGraphMode: no tab found in the visualization"; |
|
194 | << "updateGraphMode: no tab found in the visualization"; | |
186 | } |
|
195 | } | |
187 | } |
|
196 | } | |
188 | else { |
|
197 | else { | |
189 | qCWarning(LOG_CatalogueEventsWidget()) |
|
198 | qCWarning(LOG_CatalogueEventsWidget()) | |
190 | << "updateGraphMode: visualization widget not found"; |
|
199 | << "updateGraphMode: visualization widget not found"; | |
191 | } |
|
200 | } | |
192 | } |
|
201 | } | |
193 | else { |
|
202 | else { | |
194 | qCWarning(LOG_CatalogueEventsWidget()) |
|
203 | qCWarning(LOG_CatalogueEventsWidget()) | |
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) | |
201 | : QWidget(parent), |
|
226 | : QWidget(parent), | |
202 | ui(new Ui::CatalogueEventsWidget), |
|
227 | ui(new Ui::CatalogueEventsWidget), | |
203 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} |
|
228 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} | |
204 | { |
|
229 | { | |
205 | ui->setupUi(this); |
|
230 | ui->setupUi(this); | |
206 |
|
231 | |||
207 | impl->m_Model = new CatalogueEventsModel{this}; |
|
232 | impl->m_Model = new CatalogueEventsModel{this}; | |
208 | ui->treeView->setModel(impl->m_Model); |
|
233 | ui->treeView->setModel(impl->m_Model); | |
209 |
|
234 | |||
210 | ui->treeView->setSortingEnabled(true); |
|
235 | ui->treeView->setSortingEnabled(true); | |
211 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); |
|
236 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); | |
212 | ui->treeView->setDragEnabled(true); |
|
237 | ui->treeView->setDragEnabled(true); | |
213 |
|
238 | |||
214 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { |
|
239 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { | |
215 | if (checked) { |
|
240 | if (checked) { | |
216 | ui->btnChart->setChecked(false); |
|
241 | ui->btnChart->setChecked(false); | |
217 | impl->m_ZonesForTimeMode |
|
242 | impl->m_ZonesForTimeMode | |
218 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, |
|
243 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, | |
219 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); |
|
244 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); | |
220 |
|
245 | |||
221 | impl->updateForTimeMode(ui->treeView); |
|
246 | impl->updateForTimeMode(ui->treeView); | |
222 | } |
|
247 | } | |
223 | }); |
|
248 | }); | |
224 |
|
249 | |||
225 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { |
|
250 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { | |
226 | if (checked) { |
|
251 | if (checked) { | |
227 | ui->btnTime->setChecked(false); |
|
252 | ui->btnTime->setChecked(false); | |
228 | impl->m_ZoneForGraphMode |
|
253 | impl->m_ZoneForGraphMode | |
229 | = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, |
|
254 | = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, | |
230 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) |
|
255 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) | |
231 | .value(0); |
|
256 | .value(0); | |
232 |
|
257 | |||
233 | impl->updateForGraphMode(ui->treeView); |
|
258 | impl->updateForGraphMode(ui->treeView); | |
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); | |
|
277 | impl->removeEvent(event, ui->treeView); | |||
255 | } |
|
278 | } | |
256 | else if (events.isEmpty() && !eventProducts.isEmpty()) { |
|
|||
257 | emit this->eventProductsSelected(eventProducts); |
|
|||
258 | } |
|
279 | } | |
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, |
|
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); | |
270 | ui->btnTime->setEnabled(isNotMultiSelection); |
|
291 | ui->btnTime->setEnabled(isNotMultiSelection); | |
271 |
|
292 | |||
272 | if (isNotMultiSelection && ui->btnTime->isChecked()) { |
|
293 | if (isNotMultiSelection && ui->btnTime->isChecked()) { | |
273 | impl->updateForTimeMode(ui->treeView); |
|
294 | impl->updateForTimeMode(ui->treeView); | |
274 | } |
|
295 | } | |
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:: |
|
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); | |
288 |
|
316 | |||
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, |
|
320 | setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event)); | |
293 | } |
|
321 | } | |
294 | }); |
|
322 | }); | |
|
323 | ||||
|
324 | populateWithAllEvents(); | |||
295 | } |
|
325 | } | |
296 |
|
326 | |||
297 | CatalogueEventsWidget::~CatalogueEventsWidget() |
|
327 | CatalogueEventsWidget::~CatalogueEventsWidget() | |
298 | { |
|
328 | { | |
299 | delete ui; |
|
329 | delete ui; | |
300 | } |
|
330 | } | |
301 |
|
331 | |||
302 | void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization) |
|
332 | void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization) | |
303 | { |
|
333 | { | |
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); | |
310 |
|
345 | |||
311 | auto eventIndex = impl->m_Model->indexOf(event); |
|
346 | auto eventIndex = impl->m_Model->indexOf(event); | |
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 | |||
|
350 | if (validationIndex.isValid()) { | |||
315 | if (hasChanges) { |
|
351 | if (hasChanges) { | |
316 | if (ui->treeView->indexWidget(validationIndex) == nullptr) { |
|
352 | if (ui->treeView->indexWidget(validationIndex) == nullptr) { | |
317 | auto widget = CatalogueExplorerHelper::buildValidationWidget( |
|
353 | auto widget = CatalogueExplorerHelper::buildValidationWidget( | |
318 | ui->treeView, [this, event]() { setEventChanges(event, false); }, |
|
354 | ui->treeView, | |
319 |
[this, event]() { |
|
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 | }); | |||
320 | ui->treeView->setIndexWidget(validationIndex, widget); |
|
365 | ui->treeView->setIndexWidget(validationIndex, widget); | |
321 | } |
|
366 | } | |
322 | } |
|
367 | } | |
323 | else { |
|
368 | else { | |
324 | // Note: the widget is destroyed |
|
369 | // Note: the widget is destroyed | |
325 | ui->treeView->setIndexWidget(validationIndex, nullptr); |
|
370 | ui->treeView->setIndexWidget(validationIndex, nullptr); | |
326 | } |
|
371 | } | |
|
372 | } | |||
|
373 | else { | |||
|
374 | qCWarning(LOG_CatalogueEventsWidget()) | |||
|
375 | << "setEventChanges: the event is not displayed in the model."; | |||
|
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 | |||
337 | for (auto catalogue : catalogues) { |
|
402 | for (auto catalogue : catalogues) { | |
338 | auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue); |
|
403 | auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue); | |
339 | for (auto event : catalogueEvents) { |
|
404 | for (auto event : catalogueEvents) { | |
340 | if (!eventIds.contains(event->getUniqId())) { |
|
405 | if (!eventIds.contains(event->getUniqId())) { | |
341 | events << event; |
|
406 | events << event; | |
342 | eventIds.insert(event->getUniqId()); |
|
407 | eventIds.insert(event->getUniqId()); | |
343 | } |
|
408 | } | |
344 | } |
|
409 | } | |
345 | } |
|
410 | } | |
346 |
|
411 | |||
347 |
impl->setEvents(events, |
|
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; | |
355 | for (auto event : allEvents) { |
|
422 | for (auto event : allEvents) { | |
356 | events << event; |
|
423 | events << event; | |
357 | } |
|
424 | } | |
358 |
|
425 | |||
359 |
impl->setEvents(events, |
|
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 | } |
@@ -1,95 +1,126 | |||||
1 | #include "Catalogue/CatalogueExplorer.h" |
|
1 | #include "Catalogue/CatalogueExplorer.h" | |
2 | #include "ui_CatalogueExplorer.h" |
|
2 | #include "ui_CatalogueExplorer.h" | |
3 |
|
3 | |||
4 | #include <Catalogue/CatalogueActionManager.h> |
|
4 | #include <Catalogue/CatalogueActionManager.h> | |
5 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <Catalogue/CatalogueController.h> | |
6 | #include <SqpApplication.h> |
|
6 | #include <SqpApplication.h> | |
7 | #include <Visualization/VisualizationWidget.h> |
|
7 | #include <Visualization/VisualizationWidget.h> | |
8 |
|
8 | |||
9 | #include <DBCatalogue.h> |
|
9 | #include <DBCatalogue.h> | |
10 | #include <DBEvent.h> |
|
10 | #include <DBEvent.h> | |
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 | |||
23 | impl->m_ActionManager.installSelectionZoneActions(); |
|
28 | impl->m_ActionManager.installSelectionZoneActions(); | |
24 |
|
29 | |||
25 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { |
|
30 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { | |
26 | if (catalogues.count() == 1) { |
|
31 | if (catalogues.count() == 1) { | |
27 | ui->inspector->setCatalogue(catalogues.first()); |
|
32 | ui->inspector->setCatalogue(catalogues.first()); | |
28 | } |
|
33 | } | |
29 | else { |
|
34 | else { | |
30 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
35 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
31 | } |
|
36 | } | |
32 |
|
37 | |||
33 | ui->events->populateWithCatalogues(catalogues); |
|
38 | ui->events->populateWithCatalogues(catalogues); | |
34 | }); |
|
39 | }); | |
35 |
|
40 | |||
36 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) { |
|
41 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) { | |
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 |
|
|
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::select |
|
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) { | |
53 | ui->inspector->setEvent(events.first()); |
|
71 | ui->inspector->setEvent(events.first()); | |
54 | } |
|
72 | } | |
55 | else { |
|
73 | else { | |
56 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
74 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
57 | } |
|
75 | } | |
58 | }); |
|
76 | }); | |
59 |
|
77 | |||
60 | connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) { |
|
78 | connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) { | |
61 | if (eventProducts.count() == 1) { |
|
79 | if (eventProducts.count() == 1) { | |
62 | ui->inspector->setEventProduct(eventProducts.first().first, |
|
80 | ui->inspector->setEventProduct(eventProducts.first().first, | |
63 | eventProducts.first().second); |
|
81 | eventProducts.first().second); | |
64 | } |
|
82 | } | |
65 | else { |
|
83 | else { | |
66 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); |
|
84 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
67 | } |
|
85 | } | |
68 | }); |
|
86 | }); | |
69 |
|
87 | |||
70 | connect(ui->events, &CatalogueEventsWidget::selectionCleared, |
|
88 | connect(ui->events, &CatalogueEventsWidget::selectionCleared, | |
71 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); |
|
89 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); | |
72 |
|
90 | |||
73 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) { |
|
91 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) { | |
74 | sqpApp->catalogueController().updateCatalogue(catalogue); |
|
92 | sqpApp->catalogueController().updateCatalogue(catalogue); | |
75 | ui->catalogues->setCatalogueChanges(catalogue, true); |
|
93 | ui->catalogues->setCatalogueChanges(catalogue, true); | |
76 | }); |
|
94 | }); | |
77 |
|
95 | |||
78 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) { |
|
96 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) { | |
79 | sqpApp->catalogueController().updateEvent(event); |
|
97 | sqpApp->catalogueController().updateEvent(event); | |
80 | ui->events->setEventChanges(event, true); |
|
98 | ui->events->setEventChanges(event, true); | |
81 | }); |
|
99 | }); | |
82 |
|
100 | |||
83 | connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, |
|
101 | connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, | |
84 |
[this](auto event, auto eventProduct) { |
|
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() | |
88 | { |
|
109 | { | |
89 | delete ui; |
|
110 | delete ui; | |
90 | } |
|
111 | } | |
91 |
|
112 | |||
92 | void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization) |
|
113 | void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization) | |
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 | } |
@@ -1,181 +1,211 | |||||
1 | #include "Catalogue/CatalogueInspectorWidget.h" |
|
1 | #include "Catalogue/CatalogueInspectorWidget.h" | |
2 | #include "ui_CatalogueInspectorWidget.h" |
|
2 | #include "ui_CatalogueInspectorWidget.h" | |
3 |
|
3 | |||
4 | #include <Common/DateUtils.h> |
|
4 | #include <Common/DateUtils.h> | |
5 | #include <DBCatalogue.h> |
|
5 | #include <DBCatalogue.h> | |
6 | #include <DBEvent.h> |
|
6 | #include <DBEvent.h> | |
7 | #include <DBEventProduct.h> |
|
7 | #include <DBEventProduct.h> | |
8 | #include <DBTag.h> |
|
8 | #include <DBTag.h> | |
9 |
|
9 | |||
10 | struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate { |
|
10 | struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate { | |
11 | std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr; |
|
11 | std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr; | |
12 | std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr; |
|
12 | std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr; | |
13 | std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr; |
|
13 | std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr; | |
14 |
|
14 | |||
15 | void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector, |
|
15 | void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector, | |
16 | Ui::CatalogueInspectorWidget *ui); |
|
16 | Ui::CatalogueInspectorWidget *ui); | |
17 | void connectEventUpdateSignals(CatalogueInspectorWidget *inspector, |
|
17 | void connectEventUpdateSignals(CatalogueInspectorWidget *inspector, | |
18 | Ui::CatalogueInspectorWidget *ui); |
|
18 | Ui::CatalogueInspectorWidget *ui); | |
19 | }; |
|
19 | }; | |
20 |
|
20 | |||
21 | CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent) |
|
21 | CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent) | |
22 | : QWidget(parent), |
|
22 | : QWidget(parent), | |
23 | ui(new Ui::CatalogueInspectorWidget), |
|
23 | ui(new Ui::CatalogueInspectorWidget), | |
24 | impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()} |
|
24 | impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()} | |
25 | { |
|
25 | { | |
26 | ui->setupUi(this); |
|
26 | ui->setupUi(this); | |
27 | showPage(Page::Empty); |
|
27 | showPage(Page::Empty); | |
28 |
|
28 | |||
29 | impl->connectCatalogueUpdateSignals(this, ui); |
|
29 | impl->connectCatalogueUpdateSignals(this, ui); | |
30 | impl->connectEventUpdateSignals(this, ui); |
|
30 | impl->connectEventUpdateSignals(this, ui); | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | CatalogueInspectorWidget::~CatalogueInspectorWidget() |
|
33 | CatalogueInspectorWidget::~CatalogueInspectorWidget() | |
34 | { |
|
34 | { | |
35 | delete ui; |
|
35 | delete ui; | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals( |
|
38 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals( | |
39 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) |
|
39 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) | |
40 | { |
|
40 | { | |
41 | connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
41 | connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
42 | if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) { |
|
42 | if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) { | |
43 | m_DisplayedCatalogue->setName(ui->leCatalogueName->text()); |
|
43 | m_DisplayedCatalogue->setName(ui->leCatalogueName->text()); | |
44 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); |
|
44 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); | |
45 | } |
|
45 | } | |
46 | }); |
|
46 | }); | |
47 |
|
47 | |||
48 | connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
48 | connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
49 | if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) { |
|
49 | if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) { | |
50 | m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text()); |
|
50 | m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text()); | |
51 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); |
|
51 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); | |
52 | } |
|
52 | } | |
53 | }); |
|
53 | }); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals( |
|
56 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals( | |
57 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) |
|
57 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) | |
58 | { |
|
58 | { | |
59 | connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
59 | connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
60 | if (ui->leEventName->text() != m_DisplayedEvent->getName()) { |
|
60 | if (ui->leEventName->text() != m_DisplayedEvent->getName()) { | |
61 | m_DisplayedEvent->setName(ui->leEventName->text()); |
|
61 | m_DisplayedEvent->setName(ui->leEventName->text()); | |
62 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
62 | emit inspector->eventUpdated(m_DisplayedEvent); | |
63 | } |
|
63 | } | |
64 | }); |
|
64 | }); | |
65 |
|
65 | |||
66 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
66 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
67 | auto tags = ui->leEventTags->text().split(QRegExp("\\s+")); |
|
67 | auto tags = ui->leEventTags->text().split(QRegExp("\\s+")); | |
68 | std::list<QString> tagNames; |
|
68 | std::list<QString> tagNames; | |
69 | for (auto tag : tags) { |
|
69 | for (auto tag : tags) { | |
70 | tagNames.push_back(tag); |
|
70 | tagNames.push_back(tag); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | if (m_DisplayedEvent->getTagsNames() != tagNames) { |
|
73 | if (m_DisplayedEvent->getTagsNames() != tagNames) { | |
74 | m_DisplayedEvent->setTagsNames(tagNames); |
|
74 | m_DisplayedEvent->setTagsNames(tagNames); | |
75 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
75 | emit inspector->eventUpdated(m_DisplayedEvent); | |
76 | } |
|
76 | } | |
77 | }); |
|
77 | }); | |
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 | |||
86 | connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
96 | connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { | |
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 | |||
94 | connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
113 | connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { | |
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 | } | |
102 |
|
130 | |||
103 | void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page) |
|
131 | void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page) | |
104 | { |
|
132 | { | |
105 | ui->stackedWidget->setCurrentIndex(static_cast<int>(page)); |
|
133 | ui->stackedWidget->setCurrentIndex(static_cast<int>(page)); | |
106 | } |
|
134 | } | |
107 |
|
135 | |||
108 | CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const |
|
136 | CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const | |
109 | { |
|
137 | { | |
110 | return static_cast<Page>(ui->stackedWidget->currentIndex()); |
|
138 | return static_cast<Page>(ui->stackedWidget->currentIndex()); | |
111 | } |
|
139 | } | |
112 |
|
140 | |||
113 | void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) |
|
141 | void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) | |
114 | { |
|
142 | { | |
115 | impl->m_DisplayedEvent = event; |
|
143 | impl->m_DisplayedEvent = event; | |
116 |
|
144 | |||
117 | blockSignals(true); |
|
145 | blockSignals(true); | |
118 |
|
146 | |||
119 | showPage(Page::EventProperties); |
|
147 | showPage(Page::EventProperties); | |
120 | ui->leEventName->setEnabled(true); |
|
148 | ui->leEventName->setEnabled(true); | |
121 | ui->leEventName->setText(event->getName()); |
|
149 | ui->leEventName->setText(event->getName()); | |
122 | ui->leEventProduct->setEnabled(false); |
|
150 | ui->leEventProduct->setEnabled(false); | |
123 | ui->leEventProduct->setText( |
|
151 | ui->leEventProduct->setText( | |
124 | QString::number(event->getEventProducts().size()).append(" product(s)")); |
|
152 | QString::number(event->getEventProducts().size()).append(" product(s)")); | |
125 |
|
153 | |||
126 | QString tagList; |
|
154 | QString tagList; | |
127 | auto tags = event->getTagsNames(); |
|
155 | auto tags = event->getTagsNames(); | |
128 | for (auto tag : tags) { |
|
156 | for (auto tag : tags) { | |
129 | tagList += tag; |
|
157 | tagList += tag; | |
130 | tagList += ' '; |
|
158 | tagList += ' '; | |
131 | } |
|
159 | } | |
132 |
|
160 | |||
133 | ui->leEventTags->setEnabled(true); |
|
161 | ui->leEventTags->setEnabled(true); | |
134 | ui->leEventTags->setText(tagList); |
|
162 | ui->leEventTags->setText(tagList); | |
135 |
|
163 | |||
136 | ui->dateTimeEventTStart->setEnabled(false); |
|
164 | ui->dateTimeEventTStart->setEnabled(false); | |
137 | ui->dateTimeEventTEnd->setEnabled(false); |
|
165 | ui->dateTimeEventTEnd->setEnabled(false); | |
138 |
|
166 | |||
139 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); |
|
167 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); | |
140 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); |
|
168 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); | |
141 |
|
169 | |||
142 | blockSignals(false); |
|
170 | blockSignals(false); | |
143 | } |
|
171 | } | |
144 |
|
172 | |||
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); | |
151 |
|
181 | |||
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( |
|
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); | |
159 | ui->leEventTags->clear(); |
|
189 | ui->leEventTags->clear(); | |
160 |
|
190 | |||
161 | ui->dateTimeEventTStart->setEnabled(true); |
|
191 | ui->dateTimeEventTStart->setEnabled(true); | |
162 | ui->dateTimeEventTEnd->setEnabled(true); |
|
192 | ui->dateTimeEventTEnd->setEnabled(true); | |
163 |
|
193 | |||
164 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart())); |
|
194 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart())); | |
165 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd())); |
|
195 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd())); | |
166 |
|
196 | |||
167 | blockSignals(false); |
|
197 | blockSignals(false); | |
168 | } |
|
198 | } | |
169 |
|
199 | |||
170 | void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue) |
|
200 | void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue) | |
171 | { |
|
201 | { | |
172 | impl->m_DisplayedCatalogue = catalogue; |
|
202 | impl->m_DisplayedCatalogue = catalogue; | |
173 |
|
203 | |||
174 | blockSignals(true); |
|
204 | blockSignals(true); | |
175 |
|
205 | |||
176 | showPage(Page::CatalogueProperties); |
|
206 | showPage(Page::CatalogueProperties); | |
177 | ui->leCatalogueName->setText(catalogue->getName()); |
|
207 | ui->leCatalogueName->setText(catalogue->getName()); | |
178 | ui->leCatalogueAuthor->setText(catalogue->getAuthor()); |
|
208 | ui->leCatalogueAuthor->setText(catalogue->getAuthor()); | |
179 |
|
209 | |||
180 | blockSignals(false); |
|
210 | blockSignals(false); | |
181 | } |
|
211 | } |
@@ -1,250 +1,337 | |||||
1 | #include "Catalogue/CatalogueSideBarWidget.h" |
|
1 | #include "Catalogue/CatalogueSideBarWidget.h" | |
2 | #include "ui_CatalogueSideBarWidget.h" |
|
2 | #include "ui_CatalogueSideBarWidget.h" | |
3 | #include <SqpApplication.h> |
|
3 | #include <SqpApplication.h> | |
4 |
|
4 | |||
5 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <Catalogue/CatalogueController.h> | |
6 |
#include <Catalogue/Catalogue |
|
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> | |
10 |
|
13 | |||
11 | #include <QMenu> |
|
14 | #include <QMenu> | |
12 |
|
15 | |||
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 = |
|
19 | constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1; | |
17 |
constexpr auto TRASH_ITEM_TYPE = |
|
20 | constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2; | |
18 |
constexpr auto CATALOGUE_ITEM_TYPE = |
|
21 | constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3; | |
19 |
constexpr auto DATABASE_ITEM_TYPE = |
|
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 |
|
|
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 | } | |||
|
77 | ||||
|
78 | return catalogues; | |||
|
79 | } | |||
|
80 | ||||
|
81 | QStringList selectedRepositories(QTreeView *treeView) const | |||
|
82 | { | |||
|
83 | QStringList repositories; | |||
|
84 | auto selectedItems = treeView->selectionModel()->selectedRows(); | |||
|
85 | for (auto itemIndex : selectedItems) { | |||
|
86 | auto item = m_TreeModel->item(itemIndex); | |||
|
87 | if (item && item->type() == DATABASE_ITEM_TYPE) { | |||
|
88 | repositories.append(item->text()); | |||
|
89 | } | |||
|
90 | } | |||
29 |
|
91 | |||
30 | CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, |
|
92 | return repositories; | |
31 | QTreeWidget *treeWidget) const; |
|
93 | } | |
32 | }; |
|
94 | }; | |
33 |
|
95 | |||
34 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) |
|
96 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) | |
35 | : QWidget(parent), |
|
97 | : QWidget(parent), | |
36 | ui(new Ui::CatalogueSideBarWidget), |
|
98 | ui(new Ui::CatalogueSideBarWidget), | |
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); |
|
|||
45 | ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch); |
|
|||
46 |
|
105 | |||
47 | auto emitSelection = [this]() { |
|
106 | impl->configureTreeWidget(ui->treeView); | |
48 |
|
107 | |||
49 | auto selectedItems = ui->treeWidget->selectedItems(); |
|
108 | ui->treeView->header()->setStretchLastSection(false); | |
50 | if (selectedItems.isEmpty()) { |
|
109 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
51 | emit this->selectionCleared(); |
|
110 | ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); | |
52 | } |
|
|||
53 | else { |
|
|||
54 | QVector<std::shared_ptr<DBCatalogue> > catalogues; |
|
|||
55 | QStringList databases; |
|
|||
56 | int selectionType = selectedItems.first()->type(); |
|
|||
57 |
|
111 | |||
58 | for (auto item : ui->treeWidget->selectedItems()) { |
|
112 | auto emitSelection = [this]() { | |
59 | if (item->type() == selectionType) { |
|
113 | ||
60 | switch (selectionType) { |
|
114 | auto selectionType = impl->selectionType(ui->treeView); | |
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 |
|
115 | |||
81 |
|
|
116 | switch (selectionType) { | |
82 |
|
|
117 | case CATALOGUE_ITEM_TYPE: | |
83 |
|
|
118 | emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView)); | |
84 |
|
|
119 | break; | |
85 |
|
|
120 | case DATABASE_ITEM_TYPE: | |
86 |
|
|
121 | emit this->databaseSelected(impl->selectedRepositories(ui->treeView)); | |
87 |
|
|
122 | break; | |
88 |
|
|
123 | case ALL_EVENT_ITEM_TYPE: | |
89 |
|
|
124 | emit this->allEventsSelected(); | |
90 |
|
|
125 | break; | |
91 |
|
|
126 | case TRASH_ITEM_TYPE: | |
92 |
|
|
127 | emit this->trashSelected(); | |
93 |
|
|
128 | break; | |
94 |
|
|
129 | default: | |
95 |
|
|
130 | emit this->selectionCleared(); | |
96 |
|
|
131 | break; | |
97 |
|
|
132 | } | |
98 | } |
|
|||
99 |
|
||||
100 |
|
||||
101 | }; |
|
133 | }; | |
102 |
|
134 | |||
103 |
connect(ui->tree |
|
135 | connect(ui->treeView, &QTreeView::clicked, emitSelection); | |
104 |
connect(ui->tree |
|
136 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection); | |
105 | connect(ui->treeWidget, &QTreeWidget::itemChanged, |
|
137 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) { | |
106 | [emitSelection, this](auto item, auto column) { |
|
138 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); | |
107 | auto selectedItems = ui->treeWidget->selectedItems(); |
|
139 | if (selectedIndexes.contains(index)) { | |
108 | qDebug() << "ITEM CHANGED" << column; |
|
|||
109 | if (selectedItems.contains(item) && column == 0) { |
|
|||
110 |
|
|
140 | emitSelection(); | |
111 |
|
|
141 | } | |
|
142 | ||||
|
143 | auto item = impl->m_TreeModel->item(index); | |||
|
144 | impl->setHasChanges(true, index, ui->treeView); | |||
112 |
|
|
145 | }); | |
113 |
|
146 | |||
114 |
ui->tree |
|
147 | ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); | |
115 |
connect(ui->tree |
|
148 | connect(ui->treeView, &QTreeView::customContextMenuRequested, this, | |
116 | &CatalogueSideBarWidget::onContextMenuRequested); |
|
149 | &CatalogueSideBarWidget::onContextMenuRequested); | |
117 | } |
|
150 | } | |
118 |
|
151 | |||
119 | CatalogueSideBarWidget::~CatalogueSideBarWidget() |
|
152 | CatalogueSideBarWidget::~CatalogueSideBarWidget() | |
120 | { |
|
153 | { | |
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 |
|
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 currentI |
|
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; | |
145 | case ALL_EVENT_ITEM_TYPE: |
|
208 | case ALL_EVENT_ITEM_TYPE: | |
146 | break; |
|
209 | break; | |
147 | case TRASH_ITEM_TYPE: |
|
210 | case TRASH_ITEM_TYPE: | |
148 | menu.addAction("Empty Trash", []() { |
|
211 | menu.addAction("Empty Trash", []() { | |
149 | // TODO |
|
212 | // TODO | |
150 | }); |
|
213 | }); | |
151 | break; |
|
214 | break; | |
152 | default: |
|
215 | default: | |
153 | break; |
|
216 | break; | |
154 | } |
|
217 | } | |
155 |
|
218 | |||
156 | if (!menu.isEmpty()) { |
|
219 | if (!menu.isEmpty()) { | |
157 |
menu.exec(ui->tree |
|
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 |
|
|
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 |
|
|
233 | m_TreeModel->addTopLevelItem(trashItem); | |
171 |
|
234 | |||
172 |
auto separator = new QFrame{tree |
|
235 | auto separator = new QFrame{treeView}; | |
173 | separator->setFrameShape(QFrame::HLine); |
|
236 | separator->setFrameShape(QFrame::HLine); | |
174 |
auto separatorItem |
|
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 |
|
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 |
tree |
|
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 |
|
|
260 | auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem); | |
199 |
|
261 | |||
200 |
return databaseI |
|
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 |
|
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 | } | |
213 |
|
273 | |||
214 | return nullptr; |
|
274 | return nullptr; | |
215 | } |
|
275 | } | |
216 |
|
276 | |||
217 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( |
|
277 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( | |
218 |
const std::shared_ptr<DBCatalogue> &catalogue, |
|
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 |
|
|
282 | m_TreeModel->addChildItem(catalogueItem, databaseIndex); | |
223 | } |
|
283 | } | |
224 |
|
284 | |||
225 |
CatalogueTree |
|
285 | CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( | |
226 |
const std::shared_ptr<DBCatalogue> &catalogue |
|
286 | const std::shared_ptr<DBCatalogue> &catalogue) const | |
227 | { |
|
287 | { | |
228 |
for (auto 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 |
|
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<CatalogueTree |
|
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 | } | |
238 | } |
|
296 | } | |
239 | else { |
|
297 | else { | |
240 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree " |
|
298 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree " | |
241 | "structure. A database item should " |
|
299 | "structure. A database item should " | |
242 | "only contain catalogues."; |
|
300 | "only contain catalogues."; | |
243 | Q_ASSERT(false); |
|
301 | Q_ASSERT(false); | |
244 | } |
|
302 | } | |
245 | } |
|
303 | } | |
246 | } |
|
304 | } | |
247 | } |
|
305 | } | |
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/CatalogueTree |
|
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 |
CatalogueTree |
|
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 |
CatalogueTree |
|
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 CatalogueTree |
|
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 |
|
|
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 |
|
|
59 | result = true; | |
55 | } |
|
|||
56 | } |
|
|||
57 | else { |
|
|||
58 | QTreeWidgetItem::setData(column, role, value); |
|
|||
59 | } |
|
60 | } | |
60 | } |
|
61 | } | |
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 ( |
|
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 | } |
@@ -1,59 +1,59 | |||||
1 | #include "Catalogue/CreateEventDialog.h" |
|
1 | #include "Catalogue/CreateEventDialog.h" | |
2 | #include "ui_CreateEventDialog.h" |
|
2 | #include "ui_CreateEventDialog.h" | |
3 |
|
3 | |||
4 | #include <Catalogue/CatalogueController.h> |
|
4 | #include <Catalogue/CatalogueController.h> | |
5 | #include <SqpApplication.h> |
|
5 | #include <SqpApplication.h> | |
6 |
|
6 | |||
7 | #include <DBCatalogue.h> |
|
7 | #include <DBCatalogue.h> | |
8 |
|
8 | |||
9 | struct CreateEventDialog::CreateEventDialogPrivate { |
|
9 | 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>()} | |
17 | { |
|
18 | { | |
18 | ui->setupUi(this); |
|
19 | ui->setupUi(this); | |
19 |
|
20 | |||
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 : |
|
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 | |||
30 | CreateEventDialog::~CreateEventDialog() |
|
30 | CreateEventDialog::~CreateEventDialog() | |
31 | { |
|
31 | { | |
32 | delete ui; |
|
32 | delete ui; | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | void CreateEventDialog::hideCatalogueChoice() |
|
35 | void CreateEventDialog::hideCatalogueChoice() | |
36 | { |
|
36 | { | |
37 | ui->cbCatalogue->hide(); |
|
37 | ui->cbCatalogue->hide(); | |
38 | ui->lblCatalogue->hide(); |
|
38 | ui->lblCatalogue->hide(); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QString CreateEventDialog::eventName() const |
|
41 | QString CreateEventDialog::eventName() const | |
42 | { |
|
42 | { | |
43 | return ui->leEvent->text(); |
|
43 | return ui->leEvent->text(); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | std::shared_ptr<DBCatalogue> CreateEventDialog::selectedCatalogue() const |
|
46 | std::shared_ptr<DBCatalogue> CreateEventDialog::selectedCatalogue() const | |
47 | { |
|
47 | { | |
48 | auto catalogue = impl->m_DisplayedCatalogues.value(ui->cbCatalogue->currentIndex()); |
|
48 | auto catalogue = impl->m_DisplayedCatalogues.value(ui->cbCatalogue->currentIndex()); | |
49 | if (!catalogue || catalogue->getName() != catalogueName()) { |
|
49 | if (!catalogue || catalogue->getName() != catalogueName()) { | |
50 | return nullptr; |
|
50 | return nullptr; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | return catalogue; |
|
53 | return catalogue; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | QString CreateEventDialog::catalogueName() const |
|
56 | QString CreateEventDialog::catalogueName() const | |
57 | { |
|
57 | { | |
58 | return ui->cbCatalogue->currentText(); |
|
58 | return ui->cbCatalogue->currentText(); | |
59 | } |
|
59 | } |
@@ -1,217 +1,205 | |||||
1 | #include "SqpApplication.h" |
|
1 | #include "SqpApplication.h" | |
2 |
|
2 | |||
3 | #include <Actions/ActionsGuiController.h> |
|
3 | #include <Actions/ActionsGuiController.h> | |
4 | #include <Catalogue/CatalogueController.h> |
|
4 | #include <Catalogue/CatalogueController.h> | |
5 | #include <Data/IDataProvider.h> |
|
5 | #include <Data/IDataProvider.h> | |
6 | #include <DataSource/DataSourceController.h> |
|
6 | #include <DataSource/DataSourceController.h> | |
7 | #include <DragAndDrop/DragDropGuiController.h> |
|
7 | #include <DragAndDrop/DragDropGuiController.h> | |
8 | #include <Network/NetworkController.h> |
|
8 | #include <Network/NetworkController.h> | |
9 | #include <QThread> |
|
9 | #include <QThread> | |
10 | #include <Time/TimeController.h> |
|
10 | #include <Time/TimeController.h> | |
11 | #include <Variable/Variable.h> |
|
11 | #include <Variable/Variable.h> | |
12 | #include <Variable/VariableController.h> |
|
12 | #include <Variable/VariableController.h> | |
13 | #include <Variable/VariableModel.h> |
|
13 | #include <Variable/VariableModel.h> | |
14 | #include <Visualization/VisualizationController.h> |
|
14 | #include <Visualization/VisualizationController.h> | |
15 |
|
15 | |||
16 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
16 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") | |
17 |
|
17 | |||
18 | class SqpApplication::SqpApplicationPrivate { |
|
18 | class SqpApplication::SqpApplicationPrivate { | |
19 | public: |
|
19 | public: | |
20 | SqpApplicationPrivate() |
|
20 | SqpApplicationPrivate() | |
21 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
21 | : m_DataSourceController{std::make_unique<DataSourceController>()}, | |
22 | m_VariableController{std::make_unique<VariableController>()}, |
|
22 | m_VariableController{std::make_unique<VariableController>()}, | |
23 | m_TimeController{std::make_unique<TimeController>()}, |
|
23 | m_TimeController{std::make_unique<TimeController>()}, | |
24 | m_NetworkController{std::make_unique<NetworkController>()}, |
|
24 | m_NetworkController{std::make_unique<NetworkController>()}, | |
25 | m_VisualizationController{std::make_unique<VisualizationController>()}, |
|
25 | m_VisualizationController{std::make_unique<VisualizationController>()}, | |
26 | m_DragDropGuiController{std::make_unique<DragDropGuiController>()}, |
|
26 | m_DragDropGuiController{std::make_unique<DragDropGuiController>()}, | |
27 | m_CatalogueController{std::make_unique<CatalogueController>()}, |
|
27 | m_CatalogueController{std::make_unique<CatalogueController>()}, | |
28 | m_ActionsGuiController{std::make_unique<ActionsGuiController>()}, |
|
28 | m_ActionsGuiController{std::make_unique<ActionsGuiController>()}, | |
29 | m_PlotInterractionMode(SqpApplication::PlotsInteractionMode::None), |
|
29 | m_PlotInterractionMode(SqpApplication::PlotsInteractionMode::None), | |
30 | m_PlotCursorMode(SqpApplication::PlotsCursorMode::NoCursor) |
|
30 | m_PlotCursorMode(SqpApplication::PlotsCursorMode::NoCursor) | |
31 | { |
|
31 | { | |
32 | // /////////////////////////////// // |
|
32 | // /////////////////////////////// // | |
33 | // Connections between controllers // |
|
33 | // Connections between controllers // | |
34 | // /////////////////////////////// // |
|
34 | // /////////////////////////////// // | |
35 |
|
35 | |||
36 | // VariableController <-> DataSourceController |
|
36 | // VariableController <-> DataSourceController | |
37 | connect(m_DataSourceController.get(), |
|
37 | connect(m_DataSourceController.get(), | |
38 | SIGNAL(variableCreationRequested(const QString &, const QVariantHash &, |
|
38 | SIGNAL(variableCreationRequested(const QString &, const QVariantHash &, | |
39 | std::shared_ptr<IDataProvider>)), |
|
39 | std::shared_ptr<IDataProvider>)), | |
40 | m_VariableController.get(), |
|
40 | m_VariableController.get(), | |
41 | SLOT(createVariable(const QString &, const QVariantHash &, |
|
41 | SLOT(createVariable(const QString &, const QVariantHash &, | |
42 | std::shared_ptr<IDataProvider>))); |
|
42 | std::shared_ptr<IDataProvider>))); | |
43 |
|
43 | |||
44 | connect(m_VariableController->variableModel(), &VariableModel::requestVariable, |
|
44 | connect(m_VariableController->variableModel(), &VariableModel::requestVariable, | |
45 | m_DataSourceController.get(), &DataSourceController::requestVariable); |
|
45 | m_DataSourceController.get(), &DataSourceController::requestVariable); | |
46 |
|
46 | |||
47 | // VariableController <-> VisualizationController |
|
47 | // VariableController <-> VisualizationController | |
48 | connect(m_VariableController.get(), |
|
48 | connect(m_VariableController.get(), | |
49 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), |
|
49 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), | |
50 | m_VisualizationController.get(), |
|
50 | m_VisualizationController.get(), | |
51 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
51 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); | |
52 |
|
52 | |||
53 | connect(m_VariableController.get(), |
|
53 | connect(m_VariableController.get(), | |
54 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), |
|
54 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), | |
55 | m_VisualizationController.get(), |
|
55 | m_VisualizationController.get(), | |
56 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &))); |
|
56 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &))); | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
59 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); | |
60 | m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); |
|
60 | m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); | |
61 | m_NetworkController->moveToThread(&m_NetworkControllerThread); |
|
61 | m_NetworkController->moveToThread(&m_NetworkControllerThread); | |
62 | m_NetworkControllerThread.setObjectName("NetworkControllerThread"); |
|
62 | m_NetworkControllerThread.setObjectName("NetworkControllerThread"); | |
63 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
63 | m_VariableController->moveToThread(&m_VariableControllerThread); | |
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()); | |
73 | } |
|
70 | } | |
74 |
|
71 | |||
75 | virtual ~SqpApplicationPrivate() |
|
72 | virtual ~SqpApplicationPrivate() | |
76 | { |
|
73 | { | |
77 | m_DataSourceControllerThread.quit(); |
|
74 | m_DataSourceControllerThread.quit(); | |
78 | m_DataSourceControllerThread.wait(); |
|
75 | m_DataSourceControllerThread.wait(); | |
79 |
|
76 | |||
80 | m_NetworkControllerThread.quit(); |
|
77 | m_NetworkControllerThread.quit(); | |
81 | m_NetworkControllerThread.wait(); |
|
78 | m_NetworkControllerThread.wait(); | |
82 |
|
79 | |||
83 | m_VariableControllerThread.quit(); |
|
80 | m_VariableControllerThread.quit(); | |
84 | m_VariableControllerThread.wait(); |
|
81 | m_VariableControllerThread.wait(); | |
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; | |
94 | std::unique_ptr<VariableController> m_VariableController; |
|
88 | std::unique_ptr<VariableController> m_VariableController; | |
95 | std::unique_ptr<TimeController> m_TimeController; |
|
89 | std::unique_ptr<TimeController> m_TimeController; | |
96 | std::unique_ptr<NetworkController> m_NetworkController; |
|
90 | std::unique_ptr<NetworkController> m_NetworkController; | |
97 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
91 | std::unique_ptr<VisualizationController> m_VisualizationController; | |
98 | std::unique_ptr<CatalogueController> m_CatalogueController; |
|
92 | std::unique_ptr<CatalogueController> m_CatalogueController; | |
99 |
|
93 | |||
100 | QThread m_DataSourceControllerThread; |
|
94 | QThread m_DataSourceControllerThread; | |
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; | |
108 |
|
101 | |||
109 | SqpApplication::PlotsInteractionMode m_PlotInterractionMode; |
|
102 | SqpApplication::PlotsInteractionMode m_PlotInterractionMode; | |
110 | SqpApplication::PlotsCursorMode m_PlotCursorMode; |
|
103 | SqpApplication::PlotsCursorMode m_PlotCursorMode; | |
111 | }; |
|
104 | }; | |
112 |
|
105 | |||
113 |
|
106 | |||
114 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
107 | SqpApplication::SqpApplication(int &argc, char **argv) | |
115 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
108 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} | |
116 | { |
|
109 | { | |
117 | qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread(); |
|
110 | qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread(); | |
118 |
|
111 | |||
119 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
112 | connect(&impl->m_DataSourceControllerThread, &QThread::started, | |
120 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
113 | impl->m_DataSourceController.get(), &DataSourceController::initialize); | |
121 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
114 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, | |
122 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
115 | impl->m_DataSourceController.get(), &DataSourceController::finalize); | |
123 |
|
116 | |||
124 | connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(), |
|
117 | connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(), | |
125 | &NetworkController::initialize); |
|
118 | &NetworkController::initialize); | |
126 | connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(), |
|
119 | connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(), | |
127 | &NetworkController::finalize); |
|
120 | &NetworkController::finalize); | |
128 |
|
121 | |||
129 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
122 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), | |
130 | &VariableController::initialize); |
|
123 | &VariableController::initialize); | |
131 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
124 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), | |
132 | &VariableController::finalize); |
|
125 | &VariableController::finalize); | |
133 |
|
126 | |||
134 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
127 | connect(&impl->m_VisualizationControllerThread, &QThread::started, | |
135 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
128 | impl->m_VisualizationController.get(), &VisualizationController::initialize); | |
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_CatalogueController |
|
136 | impl->m_CatalogueController->initialize(); | |
149 | } |
|
137 | } | |
150 |
|
138 | |||
151 | SqpApplication::~SqpApplication() |
|
139 | SqpApplication::~SqpApplication() | |
152 | { |
|
140 | { | |
153 | } |
|
141 | } | |
154 |
|
142 | |||
155 | void SqpApplication::initialize() |
|
143 | void SqpApplication::initialize() | |
156 | { |
|
144 | { | |
157 | } |
|
145 | } | |
158 |
|
146 | |||
159 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
147 | DataSourceController &SqpApplication::dataSourceController() noexcept | |
160 | { |
|
148 | { | |
161 | return *impl->m_DataSourceController; |
|
149 | return *impl->m_DataSourceController; | |
162 | } |
|
150 | } | |
163 |
|
151 | |||
164 | NetworkController &SqpApplication::networkController() noexcept |
|
152 | NetworkController &SqpApplication::networkController() noexcept | |
165 | { |
|
153 | { | |
166 | return *impl->m_NetworkController; |
|
154 | return *impl->m_NetworkController; | |
167 | } |
|
155 | } | |
168 |
|
156 | |||
169 | TimeController &SqpApplication::timeController() noexcept |
|
157 | TimeController &SqpApplication::timeController() noexcept | |
170 | { |
|
158 | { | |
171 | return *impl->m_TimeController; |
|
159 | return *impl->m_TimeController; | |
172 | } |
|
160 | } | |
173 |
|
161 | |||
174 | VariableController &SqpApplication::variableController() noexcept |
|
162 | VariableController &SqpApplication::variableController() noexcept | |
175 | { |
|
163 | { | |
176 | return *impl->m_VariableController; |
|
164 | return *impl->m_VariableController; | |
177 | } |
|
165 | } | |
178 |
|
166 | |||
179 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
167 | VisualizationController &SqpApplication::visualizationController() noexcept | |
180 | { |
|
168 | { | |
181 | return *impl->m_VisualizationController; |
|
169 | return *impl->m_VisualizationController; | |
182 | } |
|
170 | } | |
183 |
|
171 | |||
184 | CatalogueController &SqpApplication::catalogueController() noexcept |
|
172 | CatalogueController &SqpApplication::catalogueController() noexcept | |
185 | { |
|
173 | { | |
186 | return *impl->m_CatalogueController; |
|
174 | return *impl->m_CatalogueController; | |
187 | } |
|
175 | } | |
188 |
|
176 | |||
189 | DragDropGuiController &SqpApplication::dragDropGuiController() noexcept |
|
177 | DragDropGuiController &SqpApplication::dragDropGuiController() noexcept | |
190 | { |
|
178 | { | |
191 | return *impl->m_DragDropGuiController; |
|
179 | return *impl->m_DragDropGuiController; | |
192 | } |
|
180 | } | |
193 |
|
181 | |||
194 | ActionsGuiController &SqpApplication::actionsGuiController() noexcept |
|
182 | ActionsGuiController &SqpApplication::actionsGuiController() noexcept | |
195 | { |
|
183 | { | |
196 | return *impl->m_ActionsGuiController; |
|
184 | return *impl->m_ActionsGuiController; | |
197 | } |
|
185 | } | |
198 |
|
186 | |||
199 | SqpApplication::PlotsInteractionMode SqpApplication::plotsInteractionMode() const |
|
187 | SqpApplication::PlotsInteractionMode SqpApplication::plotsInteractionMode() const | |
200 | { |
|
188 | { | |
201 | return impl->m_PlotInterractionMode; |
|
189 | return impl->m_PlotInterractionMode; | |
202 | } |
|
190 | } | |
203 |
|
191 | |||
204 | void SqpApplication::setPlotsInteractionMode(SqpApplication::PlotsInteractionMode mode) |
|
192 | void SqpApplication::setPlotsInteractionMode(SqpApplication::PlotsInteractionMode mode) | |
205 | { |
|
193 | { | |
206 | impl->m_PlotInterractionMode = mode; |
|
194 | impl->m_PlotInterractionMode = mode; | |
207 | } |
|
195 | } | |
208 |
|
196 | |||
209 | SqpApplication::PlotsCursorMode SqpApplication::plotsCursorMode() const |
|
197 | SqpApplication::PlotsCursorMode SqpApplication::plotsCursorMode() const | |
210 | { |
|
198 | { | |
211 | return impl->m_PlotCursorMode; |
|
199 | return impl->m_PlotCursorMode; | |
212 | } |
|
200 | } | |
213 |
|
201 | |||
214 | void SqpApplication::setPlotsCursorMode(SqpApplication::PlotsCursorMode mode) |
|
202 | void SqpApplication::setPlotsCursorMode(SqpApplication::PlotsCursorMode mode) | |
215 | { |
|
203 | { | |
216 | impl->m_PlotCursorMode = mode; |
|
204 | impl->m_PlotCursorMode = mode; | |
217 | } |
|
205 | } |
@@ -1,142 +1,148 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>CatalogueEventsWidget</class> |
|
3 | <class>CatalogueEventsWidget</class> | |
4 | <widget class="QWidget" name="CatalogueEventsWidget"> |
|
4 | <widget class="QWidget" name="CatalogueEventsWidget"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>566</width> |
|
9 | <width>566</width> | |
10 | <height>258</height> |
|
10 | <height>258</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="windowTitle"> |
|
13 | <property name="windowTitle"> | |
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
16 | <layout class="QVBoxLayout" name="verticalLayout"> | |
17 | <property name="leftMargin"> |
|
17 | <property name="leftMargin"> | |
18 | <number>0</number> |
|
18 | <number>0</number> | |
19 | </property> |
|
19 | </property> | |
20 | <property name="topMargin"> |
|
20 | <property name="topMargin"> | |
21 | <number>0</number> |
|
21 | <number>0</number> | |
22 | </property> |
|
22 | </property> | |
23 | <property name="rightMargin"> |
|
23 | <property name="rightMargin"> | |
24 | <number>0</number> |
|
24 | <number>0</number> | |
25 | </property> |
|
25 | </property> | |
26 | <property name="bottomMargin"> |
|
26 | <property name="bottomMargin"> | |
27 | <number>0</number> |
|
27 | <number>0</number> | |
28 | </property> |
|
28 | </property> | |
29 | <item> |
|
29 | <item> | |
30 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
30 | <layout class="QHBoxLayout" name="horizontalLayout"> | |
31 | <item> |
|
31 | <item> | |
32 | <widget class="QToolButton" name="btnAdd"> |
|
32 | <widget class="QToolButton" name="btnAdd"> | |
|
33 | <property name="enabled"> | |||
|
34 | <bool>false</bool> | |||
|
35 | </property> | |||
33 | <property name="text"> |
|
36 | <property name="text"> | |
34 | <string>+</string> |
|
37 | <string>+</string> | |
35 | </property> |
|
38 | </property> | |
36 | <property name="icon"> |
|
39 | <property name="icon"> | |
37 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
40 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
38 | <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset> |
|
41 | <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset> | |
39 | </property> |
|
42 | </property> | |
40 | <property name="autoRaise"> |
|
43 | <property name="autoRaise"> | |
41 | <bool>true</bool> |
|
44 | <bool>true</bool> | |
42 | </property> |
|
45 | </property> | |
43 | </widget> |
|
46 | </widget> | |
44 | </item> |
|
47 | </item> | |
45 | <item> |
|
48 | <item> | |
46 | <widget class="QToolButton" name="btnRemove"> |
|
49 | <widget class="QToolButton" name="btnRemove"> | |
47 | <property name="text"> |
|
50 | <property name="text"> | |
48 | <string> - </string> |
|
51 | <string> - </string> | |
49 | </property> |
|
52 | </property> | |
50 | <property name="icon"> |
|
53 | <property name="icon"> | |
51 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
54 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
52 | <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset> |
|
55 | <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset> | |
53 | </property> |
|
56 | </property> | |
54 | <property name="autoRaise"> |
|
57 | <property name="autoRaise"> | |
55 | <bool>true</bool> |
|
58 | <bool>true</bool> | |
56 | </property> |
|
59 | </property> | |
57 | </widget> |
|
60 | </widget> | |
58 | </item> |
|
61 | </item> | |
59 | <item> |
|
62 | <item> | |
60 | <widget class="Line" name="line"> |
|
63 | <widget class="Line" name="line"> | |
61 | <property name="orientation"> |
|
64 | <property name="orientation"> | |
62 | <enum>Qt::Vertical</enum> |
|
65 | <enum>Qt::Vertical</enum> | |
63 | </property> |
|
66 | </property> | |
64 | </widget> |
|
67 | </widget> | |
65 | </item> |
|
68 | </item> | |
66 | <item> |
|
69 | <item> | |
67 | <widget class="QToolButton" name="btnTime"> |
|
70 | <widget class="QToolButton" name="btnTime"> | |
68 | <property name="text"> |
|
71 | <property name="text"> | |
69 | <string>T</string> |
|
72 | <string>T</string> | |
70 | </property> |
|
73 | </property> | |
71 | <property name="icon"> |
|
74 | <property name="icon"> | |
72 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
75 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
73 | <normaloff>:/icones/time.png</normaloff>:/icones/time.png</iconset> |
|
76 | <normaloff>:/icones/time.png</normaloff>:/icones/time.png</iconset> | |
74 | </property> |
|
77 | </property> | |
75 | <property name="checkable"> |
|
78 | <property name="checkable"> | |
76 | <bool>true</bool> |
|
79 | <bool>true</bool> | |
77 | </property> |
|
80 | </property> | |
78 | <property name="autoRaise"> |
|
81 | <property name="autoRaise"> | |
79 | <bool>true</bool> |
|
82 | <bool>true</bool> | |
80 | </property> |
|
83 | </property> | |
81 | </widget> |
|
84 | </widget> | |
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> | |
88 | <property name="icon"> |
|
94 | <property name="icon"> | |
89 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
95 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
90 | <normaloff>:/icones/chart.png</normaloff>:/icones/chart.png</iconset> |
|
96 | <normaloff>:/icones/chart.png</normaloff>:/icones/chart.png</iconset> | |
91 | </property> |
|
97 | </property> | |
92 | <property name="checkable"> |
|
98 | <property name="checkable"> | |
93 | <bool>true</bool> |
|
99 | <bool>true</bool> | |
94 | </property> |
|
100 | </property> | |
95 | <property name="autoRaise"> |
|
101 | <property name="autoRaise"> | |
96 | <bool>true</bool> |
|
102 | <bool>true</bool> | |
97 | </property> |
|
103 | </property> | |
98 | </widget> |
|
104 | </widget> | |
99 | </item> |
|
105 | </item> | |
100 | <item> |
|
106 | <item> | |
101 | <widget class="Line" name="line_2"> |
|
107 | <widget class="Line" name="line_2"> | |
102 | <property name="orientation"> |
|
108 | <property name="orientation"> | |
103 | <enum>Qt::Vertical</enum> |
|
109 | <enum>Qt::Vertical</enum> | |
104 | </property> |
|
110 | </property> | |
105 | </widget> |
|
111 | </widget> | |
106 | </item> |
|
112 | </item> | |
107 | <item> |
|
113 | <item> | |
108 | <widget class="QLineEdit" name="lineEdit"> |
|
114 | <widget class="QLineEdit" name="lineEdit"> | |
109 | <property name="enabled"> |
|
115 | <property name="enabled"> | |
110 | <bool>false</bool> |
|
116 | <bool>false</bool> | |
111 | </property> |
|
117 | </property> | |
112 | </widget> |
|
118 | </widget> | |
113 | </item> |
|
119 | </item> | |
114 | </layout> |
|
120 | </layout> | |
115 | </item> |
|
121 | </item> | |
116 | <item> |
|
122 | <item> | |
117 | <widget class="QTreeView" name="treeView"> |
|
123 | <widget class="QTreeView" name="treeView"> | |
118 | <property name="dragEnabled"> |
|
124 | <property name="dragEnabled"> | |
119 | <bool>true</bool> |
|
125 | <bool>true</bool> | |
120 | </property> |
|
126 | </property> | |
121 | <property name="dragDropMode"> |
|
127 | <property name="dragDropMode"> | |
122 | <enum>QAbstractItemView::DragDrop</enum> |
|
128 | <enum>QAbstractItemView::DragDrop</enum> | |
123 | </property> |
|
129 | </property> | |
124 | <property name="selectionMode"> |
|
130 | <property name="selectionMode"> | |
125 | <enum>QAbstractItemView::ExtendedSelection</enum> |
|
131 | <enum>QAbstractItemView::ExtendedSelection</enum> | |
126 | </property> |
|
132 | </property> | |
127 | <property name="selectionBehavior"> |
|
133 | <property name="selectionBehavior"> | |
128 | <enum>QAbstractItemView::SelectRows</enum> |
|
134 | <enum>QAbstractItemView::SelectRows</enum> | |
129 | </property> |
|
135 | </property> | |
130 | <attribute name="headerStretchLastSection"> |
|
136 | <attribute name="headerStretchLastSection"> | |
131 | <bool>false</bool> |
|
137 | <bool>false</bool> | |
132 | </attribute> |
|
138 | </attribute> | |
133 | </widget> |
|
139 | </widget> | |
134 | </item> |
|
140 | </item> | |
135 | </layout> |
|
141 | </layout> | |
136 | </widget> |
|
142 | </widget> | |
137 | <resources> |
|
143 | <resources> | |
138 | <include location="../../resources/sqpguiresources.qrc"/> |
|
144 | <include location="../../resources/sqpguiresources.qrc"/> | |
139 | <include location="../../resources/sqpguiresources.qrc"/> |
|
145 | <include location="../../resources/sqpguiresources.qrc"/> | |
140 | </resources> |
|
146 | </resources> | |
141 | <connections/> |
|
147 | <connections/> | |
142 | </ui> |
|
148 | </ui> |
@@ -1,96 +1,106 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>CatalogueSideBarWidget</class> |
|
3 | <class>CatalogueSideBarWidget</class> | |
4 | <widget class="QWidget" name="CatalogueSideBarWidget"> |
|
4 | <widget class="QWidget" name="CatalogueSideBarWidget"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>330</width> |
|
9 | <width>330</width> | |
10 | <height>523</height> |
|
10 | <height>523</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="windowTitle"> |
|
13 | <property name="windowTitle"> | |
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
16 | <layout class="QVBoxLayout" name="verticalLayout"> | |
17 | <property name="leftMargin"> |
|
17 | <property name="leftMargin"> | |
18 | <number>0</number> |
|
18 | <number>0</number> | |
19 | </property> |
|
19 | </property> | |
20 | <property name="topMargin"> |
|
20 | <property name="topMargin"> | |
21 | <number>0</number> |
|
21 | <number>0</number> | |
22 | </property> |
|
22 | </property> | |
23 | <property name="rightMargin"> |
|
23 | <property name="rightMargin"> | |
24 | <number>0</number> |
|
24 | <number>0</number> | |
25 | </property> |
|
25 | </property> | |
26 | <property name="bottomMargin"> |
|
26 | <property name="bottomMargin"> | |
27 | <number>0</number> |
|
27 | <number>0</number> | |
28 | </property> |
|
28 | </property> | |
29 | <item> |
|
29 | <item> | |
30 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
30 | <layout class="QHBoxLayout" name="horizontalLayout"> | |
31 | <item> |
|
31 | <item> | |
32 | <widget class="QToolButton" name="btnAdd"> |
|
32 | <widget class="QToolButton" name="btnAdd"> | |
|
33 | <property name="enabled"> | |||
|
34 | <bool>false</bool> | |||
|
35 | </property> | |||
33 | <property name="text"> |
|
36 | <property name="text"> | |
34 | <string>+</string> |
|
37 | <string>+</string> | |
35 | </property> |
|
38 | </property> | |
36 | <property name="icon"> |
|
39 | <property name="icon"> | |
37 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
40 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
38 | <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset> |
|
41 | <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset> | |
39 | </property> |
|
42 | </property> | |
40 | <property name="autoRaise"> |
|
43 | <property name="autoRaise"> | |
41 | <bool>true</bool> |
|
44 | <bool>true</bool> | |
42 | </property> |
|
45 | </property> | |
43 | </widget> |
|
46 | </widget> | |
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> | |
50 | <property name="icon"> |
|
56 | <property name="icon"> | |
51 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
57 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
52 | <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset> |
|
58 | <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset> | |
53 | </property> |
|
59 | </property> | |
54 | <property name="autoRaise"> |
|
60 | <property name="autoRaise"> | |
55 | <bool>true</bool> |
|
61 | <bool>true</bool> | |
56 | </property> |
|
62 | </property> | |
57 | </widget> |
|
63 | </widget> | |
58 | </item> |
|
64 | </item> | |
59 | <item> |
|
65 | <item> | |
60 | <spacer name="horizontalSpacer"> |
|
66 | <spacer name="horizontalSpacer"> | |
61 | <property name="orientation"> |
|
67 | <property name="orientation"> | |
62 | <enum>Qt::Horizontal</enum> |
|
68 | <enum>Qt::Horizontal</enum> | |
63 | </property> |
|
69 | </property> | |
64 | <property name="sizeHint" stdset="0"> |
|
70 | <property name="sizeHint" stdset="0"> | |
65 | <size> |
|
71 | <size> | |
66 | <width>40</width> |
|
72 | <width>40</width> | |
67 | <height>20</height> |
|
73 | <height>20</height> | |
68 | </size> |
|
74 | </size> | |
69 | </property> |
|
75 | </property> | |
70 | </spacer> |
|
76 | </spacer> | |
71 | </item> |
|
77 | </item> | |
72 | </layout> |
|
78 | </layout> | |
73 | </item> |
|
79 | </item> | |
74 | <item> |
|
80 | <item> | |
75 |
<widget class="QTree |
|
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> | |
90 | </widget> |
|
100 | </widget> | |
91 | <resources> |
|
101 | <resources> | |
92 | <include location="../../resources/sqpguiresources.qrc"/> |
|
102 | <include location="../../resources/sqpguiresources.qrc"/> | |
93 | <include location="../../resources/sqpguiresources.qrc"/> |
|
103 | <include location="../../resources/sqpguiresources.qrc"/> | |
94 | </resources> |
|
104 | </resources> | |
95 | <connections/> |
|
105 | <connections/> | |
96 | </ui> |
|
106 | </ui> |
@@ -1,78 +1,79 | |||||
1 | #include "AmdaPlugin.h" |
|
1 | #include "AmdaPlugin.h" | |
2 | #include "AmdaDefs.h" |
|
2 | #include "AmdaDefs.h" | |
3 | #include "AmdaParser.h" |
|
3 | #include "AmdaParser.h" | |
4 | #include "AmdaProvider.h" |
|
4 | #include "AmdaProvider.h" | |
5 | #include "AmdaServer.h" |
|
5 | #include "AmdaServer.h" | |
6 |
|
6 | |||
7 | #include <DataSource/DataSourceController.h> |
|
7 | #include <DataSource/DataSourceController.h> | |
8 | #include <DataSource/DataSourceItem.h> |
|
8 | #include <DataSource/DataSourceItem.h> | |
9 | #include <DataSource/DataSourceItemAction.h> |
|
9 | #include <DataSource/DataSourceItemAction.h> | |
10 |
|
10 | |||
11 | #include <SqpApplication.h> |
|
11 | #include <SqpApplication.h> | |
12 |
|
12 | |||
13 | Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin") |
|
13 | Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin") | |
14 |
|
14 | |||
15 | namespace { |
|
15 | namespace { | |
16 |
|
16 | |||
17 | /// Path of the file used to generate the data source item for AMDA |
|
17 | /// Path of the file used to generate the data source item for AMDA | |
18 | const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSampleV3.json"); |
|
18 | const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSampleV3.json"); | |
19 |
|
19 | |||
20 | void associateActions(DataSourceItem &item, const QUuid &dataSourceUid) |
|
20 | void associateActions(DataSourceItem &item, const QUuid &dataSourceUid) | |
21 | { |
|
21 | { | |
22 | auto addLoadAction = [&item, dataSourceUid](const QString &label) { |
|
22 | auto addLoadAction = [&item, dataSourceUid](const QString &label) { | |
23 | item.addAction( |
|
23 | item.addAction( | |
24 | std::make_unique<DataSourceItemAction>(label, [dataSourceUid](DataSourceItem &item) { |
|
24 | std::make_unique<DataSourceItemAction>(label, [dataSourceUid](DataSourceItem &item) { | |
25 | if (auto app = sqpApp) { |
|
25 | if (auto app = sqpApp) { | |
26 | app->dataSourceController().loadProductItem(dataSourceUid, item); |
|
26 | app->dataSourceController().loadProductItem(dataSourceUid, item); | |
27 | } |
|
27 | } | |
28 | })); |
|
28 | })); | |
29 | }; |
|
29 | }; | |
30 |
|
30 | |||
31 | const auto itemType = item.type(); |
|
31 | const auto itemType = item.type(); | |
32 | if (itemType == DataSourceItemType::PRODUCT || itemType == DataSourceItemType::COMPONENT) { |
|
32 | if (itemType == DataSourceItemType::PRODUCT || itemType == DataSourceItemType::COMPONENT) { | |
33 | // Adds plugin name to item metadata |
|
33 | // Adds plugin name to item metadata | |
34 | item.setData(DataSourceItem::PLUGIN_DATA_KEY, AmdaServer::instance().name()); |
|
34 | item.setData(DataSourceItem::PLUGIN_DATA_KEY, AmdaServer::instance().name()); | |
35 |
|
35 | |||
36 | // Adds load action |
|
36 | // Adds load action | |
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(); | |
43 | for (auto i = 0; i < count; ++i) { |
|
44 | for (auto i = 0; i < count; ++i) { | |
44 | if (auto child = item.child(i)) { |
|
45 | if (auto child = item.child(i)) { | |
45 | associateActions(*child, dataSourceUid); |
|
46 | associateActions(*child, dataSourceUid); | |
46 | } |
|
47 | } | |
47 | } |
|
48 | } | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 | } // namespace |
|
51 | } // namespace | |
51 |
|
52 | |||
52 | void AmdaPlugin::initialize() |
|
53 | void AmdaPlugin::initialize() | |
53 | { |
|
54 | { | |
54 | if (auto app = sqpApp) { |
|
55 | if (auto app = sqpApp) { | |
55 | auto dataSourceName = AmdaServer::instance().name(); |
|
56 | auto dataSourceName = AmdaServer::instance().name(); | |
56 |
|
57 | |||
57 | // Registers to the data source controller |
|
58 | // Registers to the data source controller | |
58 | auto &dataSourceController = app->dataSourceController(); |
|
59 | auto &dataSourceController = app->dataSourceController(); | |
59 | auto dataSourceUid = dataSourceController.registerDataSource(dataSourceName); |
|
60 | auto dataSourceUid = dataSourceController.registerDataSource(dataSourceName); | |
60 |
|
61 | |||
61 | // Sets data source tree |
|
62 | // Sets data source tree | |
62 | if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { |
|
63 | if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { | |
63 | dataSourceItem->setData(DataSourceItem::NAME_DATA_KEY, dataSourceName); |
|
64 | dataSourceItem->setData(DataSourceItem::NAME_DATA_KEY, dataSourceName); | |
64 |
|
65 | |||
65 | associateActions(*dataSourceItem, dataSourceUid); |
|
66 | associateActions(*dataSourceItem, dataSourceUid); | |
66 | dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); |
|
67 | dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); | |
67 | } |
|
68 | } | |
68 | else { |
|
69 | else { | |
69 | qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA"); |
|
70 | qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA"); | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | // Sets data provider |
|
73 | // Sets data provider | |
73 | dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>()); |
|
74 | dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>()); | |
74 | } |
|
75 | } | |
75 | else { |
|
76 | else { | |
76 | qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application"); |
|
77 | qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application"); | |
77 | } |
|
78 | } | |
78 | } |
|
79 | } |
@@ -1,118 +1,119 | |||||
1 | #include "MockPlugin.h" |
|
1 | #include "MockPlugin.h" | |
2 | #include "CosinusProvider.h" |
|
2 | #include "CosinusProvider.h" | |
3 | #include "MockDefs.h" |
|
3 | #include "MockDefs.h" | |
4 |
|
4 | |||
5 | #include <DataSource/DataSourceController.h> |
|
5 | #include <DataSource/DataSourceController.h> | |
6 | #include <DataSource/DataSourceItem.h> |
|
6 | #include <DataSource/DataSourceItem.h> | |
7 | #include <DataSource/DataSourceItemAction.h> |
|
7 | #include <DataSource/DataSourceItemAction.h> | |
8 |
|
8 | |||
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 |
|
10 | |||
11 | Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin") |
|
11 | Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin") | |
12 |
|
12 | |||
13 | namespace { |
|
13 | namespace { | |
14 |
|
14 | |||
15 | /// Name of the data source |
|
15 | /// Name of the data source | |
16 | const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); |
|
16 | const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); | |
17 |
|
17 | |||
18 | /// Creates the data provider relative to the plugin |
|
18 | /// Creates the data provider relative to the plugin | |
19 | std::unique_ptr<IDataProvider> createDataProvider() noexcept |
|
19 | std::unique_ptr<IDataProvider> createDataProvider() noexcept | |
20 | { |
|
20 | { | |
21 | return std::make_unique<CosinusProvider>(); |
|
21 | return std::make_unique<CosinusProvider>(); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data, |
|
24 | std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data, | |
25 | const QUuid &dataSourceUid) |
|
25 | const QUuid &dataSourceUid) | |
26 | { |
|
26 | { | |
27 | auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data); |
|
27 | auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, 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 | |||
34 | // Add action to load product from DataSourceController |
|
35 | // Add action to load product from DataSourceController | |
35 | result->addAction(std::make_unique<DataSourceItemAction>( |
|
36 | result->addAction(std::make_unique<DataSourceItemAction>( | |
36 | QObject::tr("Load %1 product").arg(productName), |
|
37 | QObject::tr("Load %1 product").arg(productName), | |
37 | [productName, dataSourceUid](DataSourceItem &item) { |
|
38 | [productName, dataSourceUid](DataSourceItem &item) { | |
38 | if (auto app = sqpApp) { |
|
39 | if (auto app = sqpApp) { | |
39 | app->dataSourceController().loadProductItem(dataSourceUid, item); |
|
40 | app->dataSourceController().loadProductItem(dataSourceUid, item); | |
40 | } |
|
41 | } | |
41 | })); |
|
42 | })); | |
42 |
|
43 | |||
43 | return result; |
|
44 | return result; | |
44 | } |
|
45 | } | |
45 |
|
46 | |||
46 | /// Creates the data source item relative to the plugin |
|
47 | /// Creates the data source item relative to the plugin | |
47 | std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept |
|
48 | std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept | |
48 | { |
|
49 | { | |
49 | // Magnetic field products |
|
50 | // Magnetic field products | |
50 | auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, |
|
51 | auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, | |
51 | QStringLiteral("_Magnetic field")); |
|
52 | QStringLiteral("_Magnetic field")); | |
52 | magneticFieldFolder->appendChild( |
|
53 | magneticFieldFolder->appendChild( | |
53 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 10 Hz")}, |
|
54 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 10 Hz")}, | |
54 | {COSINUS_TYPE_KEY, "scalar"}, |
|
55 | {COSINUS_TYPE_KEY, "scalar"}, | |
55 | {COSINUS_FREQUENCY_KEY, 10.}}, |
|
56 | {COSINUS_FREQUENCY_KEY, 10.}}, | |
56 | dataSourceUid)); |
|
57 | dataSourceUid)); | |
57 | magneticFieldFolder->appendChild( |
|
58 | magneticFieldFolder->appendChild( | |
58 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 60 Hz")}, |
|
59 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 60 Hz")}, | |
59 | {COSINUS_TYPE_KEY, "scalar"}, |
|
60 | {COSINUS_TYPE_KEY, "scalar"}, | |
60 | {COSINUS_FREQUENCY_KEY, 60.}}, |
|
61 | {COSINUS_FREQUENCY_KEY, 60.}}, | |
61 | dataSourceUid)); |
|
62 | dataSourceUid)); | |
62 | magneticFieldFolder->appendChild( |
|
63 | magneticFieldFolder->appendChild( | |
63 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 100 Hz")}, |
|
64 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 100 Hz")}, | |
64 | {COSINUS_TYPE_KEY, "scalar"}, |
|
65 | {COSINUS_TYPE_KEY, "scalar"}, | |
65 | {COSINUS_FREQUENCY_KEY, 100.}}, |
|
66 | {COSINUS_FREQUENCY_KEY, 100.}}, | |
66 | dataSourceUid)); |
|
67 | dataSourceUid)); | |
67 | magneticFieldFolder->appendChild( |
|
68 | magneticFieldFolder->appendChild( | |
68 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 10 Hz")}, |
|
69 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 10 Hz")}, | |
69 | {COSINUS_TYPE_KEY, "vector"}, |
|
70 | {COSINUS_TYPE_KEY, "vector"}, | |
70 | {COSINUS_FREQUENCY_KEY, 10.}}, |
|
71 | {COSINUS_FREQUENCY_KEY, 10.}}, | |
71 | dataSourceUid)); |
|
72 | dataSourceUid)); | |
72 | magneticFieldFolder->appendChild( |
|
73 | magneticFieldFolder->appendChild( | |
73 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 60 Hz")}, |
|
74 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 60 Hz")}, | |
74 | {COSINUS_TYPE_KEY, "vector"}, |
|
75 | {COSINUS_TYPE_KEY, "vector"}, | |
75 | {COSINUS_FREQUENCY_KEY, 60.}}, |
|
76 | {COSINUS_FREQUENCY_KEY, 60.}}, | |
76 | dataSourceUid)); |
|
77 | dataSourceUid)); | |
77 | magneticFieldFolder->appendChild( |
|
78 | magneticFieldFolder->appendChild( | |
78 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 100 Hz")}, |
|
79 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 100 Hz")}, | |
79 | {COSINUS_TYPE_KEY, "vector"}, |
|
80 | {COSINUS_TYPE_KEY, "vector"}, | |
80 | {COSINUS_FREQUENCY_KEY, 100.}}, |
|
81 | {COSINUS_FREQUENCY_KEY, 100.}}, | |
81 | dataSourceUid)); |
|
82 | dataSourceUid)); | |
82 | magneticFieldFolder->appendChild( |
|
83 | magneticFieldFolder->appendChild( | |
83 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Spectrogram 1 Hz")}, |
|
84 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Spectrogram 1 Hz")}, | |
84 | {COSINUS_TYPE_KEY, "spectrogram"}, |
|
85 | {COSINUS_TYPE_KEY, "spectrogram"}, | |
85 | {COSINUS_FREQUENCY_KEY, 1.}}, |
|
86 | {COSINUS_FREQUENCY_KEY, 1.}}, | |
86 | dataSourceUid)); |
|
87 | dataSourceUid)); | |
87 |
|
88 | |||
88 | // Electric field products |
|
89 | // Electric field products | |
89 | auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, |
|
90 | auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, | |
90 | QStringLiteral("_Electric field")); |
|
91 | QStringLiteral("_Electric field")); | |
91 |
|
92 | |||
92 | // Root |
|
93 | // Root | |
93 | auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME); |
|
94 | auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME); | |
94 | root->appendChild(std::move(magneticFieldFolder)); |
|
95 | root->appendChild(std::move(magneticFieldFolder)); | |
95 | root->appendChild(std::move(electricFieldFolder)); |
|
96 | root->appendChild(std::move(electricFieldFolder)); | |
96 |
|
97 | |||
97 | return root; |
|
98 | return root; | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | } // namespace |
|
101 | } // namespace | |
101 |
|
102 | |||
102 | void MockPlugin::initialize() |
|
103 | void MockPlugin::initialize() | |
103 | { |
|
104 | { | |
104 | if (auto app = sqpApp) { |
|
105 | if (auto app = sqpApp) { | |
105 | // Registers to the data source controller |
|
106 | // Registers to the data source controller | |
106 | auto &dataSourceController = app->dataSourceController(); |
|
107 | auto &dataSourceController = app->dataSourceController(); | |
107 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); |
|
108 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); | |
108 |
|
109 | |||
109 | // Sets data source tree |
|
110 | // Sets data source tree | |
110 | dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid)); |
|
111 | dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid)); | |
111 |
|
112 | |||
112 | // Sets data provider |
|
113 | // Sets data provider | |
113 | dataSourceController.setDataProvider(dataSourceUid, createDataProvider()); |
|
114 | dataSourceController.setDataProvider(dataSourceUid, createDataProvider()); | |
114 | } |
|
115 | } | |
115 | else { |
|
116 | else { | |
116 | qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); |
|
117 | qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); | |
117 | } |
|
118 | } | |
118 | } |
|
119 | } |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now