@@ -1,24 +1,27 | |||||
1 |
#ifndef SCIQLOP_CATALOGUEEVENTS |
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSMODEL_H | |
2 |
#define SCIQLOP_CATALOGUEEVENTS |
|
2 | #define SCIQLOP_CATALOGUEEVENTSMODEL_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 |
#include <QAbstract |
|
5 | #include <QAbstractItemModel> | |
6 |
|
6 | |||
7 | class DBEvent; |
|
7 | class DBEvent; | |
8 |
|
8 | |||
9 |
class CatalogueEvents |
|
9 | class CatalogueEventsModel : public QAbstractItemModel { | |
10 | public: |
|
10 | public: | |
11 |
CatalogueEvents |
|
11 | CatalogueEventsModel(QObject *parent = nullptr); | |
12 |
|
12 | |||
13 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events); |
|
13 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events); | |
14 | std::shared_ptr<DBEvent> getEvent(int row) const; |
|
14 | std::shared_ptr<DBEvent> getEvent(int row) const; | |
15 |
|
15 | |||
|
16 | ||||
16 | void addEvent(const std::shared_ptr<DBEvent> &event); |
|
17 | void addEvent(const std::shared_ptr<DBEvent> &event); | |
17 | void removeEvent(const std::shared_ptr<DBEvent> &event); |
|
18 | void removeEvent(const std::shared_ptr<DBEvent> &event); | |
18 |
|
19 | |||
19 | void refreshEvent(const std::shared_ptr<DBEvent> &event); |
|
20 | void refreshEvent(const std::shared_ptr<DBEvent> &event); | |
20 |
|
21 | |||
21 | // Model |
|
22 | // Model | |
|
23 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; | |||
|
24 | QModelIndex parent(const QModelIndex &index) const; | |||
22 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
|
25 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | |
23 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
|
26 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; | |
24 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
|
27 | Qt::ItemFlags flags(const QModelIndex &index) const override; | |
@@ -31,10 +34,9 public: | |||||
31 | QStringList mimeTypes() const override; |
|
34 | QStringList mimeTypes() const override; | |
32 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
|
35 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | |
33 |
|
36 | |||
34 |
|
||||
35 | private: |
|
37 | private: | |
36 | class CatalogueEventsTableModelPrivate; |
|
38 | class CatalogueEventsTableModelPrivate; | |
37 | spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl; |
|
39 | spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl; | |
38 | }; |
|
40 | }; | |
39 |
|
41 | |||
40 |
#endif // SCIQLOP_CATALOGUEEVENTS |
|
42 | #endif // SCIQLOP_CATALOGUEEVENTSMODEL_H |
@@ -108,7 +108,7 gui_sources = [ | |||||
108 | 'src/Catalogue/CatalogueSideBarWidget.cpp', |
|
108 | 'src/Catalogue/CatalogueSideBarWidget.cpp', | |
109 | 'src/Catalogue/CatalogueInspectorWidget.cpp', |
|
109 | 'src/Catalogue/CatalogueInspectorWidget.cpp', | |
110 | 'src/Catalogue/CatalogueTreeWidgetItem.cpp', |
|
110 | 'src/Catalogue/CatalogueTreeWidgetItem.cpp', | |
111 |
'src/Catalogue/CatalogueEvents |
|
111 | 'src/Catalogue/CatalogueEventsModel.cpp' | |
112 | ] |
|
112 | ] | |
113 |
|
113 | |||
114 | gui_inc = include_directories(['include']) |
|
114 | gui_inc = include_directories(['include']) |
@@ -1,18 +1,28 | |||||
1 |
#include "Catalogue/CatalogueEvents |
|
1 | #include "Catalogue/CatalogueEventsModel.h" | |
2 |
|
2 | |||
3 | #include <Common/DateUtils.h> |
|
3 | #include <Common/DateUtils.h> | |
4 | #include <Common/MimeTypesDef.h> |
|
4 | #include <Common/MimeTypesDef.h> | |
5 | #include <DBEvent.h> |
|
5 | #include <DBEvent.h> | |
|
6 | #include <DBEventProduct.h> | |||
6 | #include <DBTag.h> |
|
7 | #include <DBTag.h> | |
7 | #include <Data/SqpRange.h> |
|
8 | #include <Data/SqpRange.h> | |
8 | #include <QMimeData> |
|
|||
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 | #include <Time/TimeController.h> |
|
10 | #include <Time/TimeController.h> | |
11 |
|
11 | |||
12 | struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate { |
|
12 | #include <list> | |
|
13 | #include <unordered_map> | |||
|
14 | ||||
|
15 | #include <QHash> | |||
|
16 | #include <QMimeData> | |||
|
17 | ||||
|
18 | const auto EVENT_ITEM_TYPE = 1; | |||
|
19 | const auto EVENT_PRODUCT_ITEM_TYPE = 2; | |||
|
20 | ||||
|
21 | struct CatalogueEventsModel::CatalogueEventsTableModelPrivate { | |||
13 | QVector<std::shared_ptr<DBEvent> > m_Events; |
|
22 | QVector<std::shared_ptr<DBEvent> > m_Events; | |
|
23 | std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts; | |||
14 |
|
24 | |||
15 |
enum class Column { |
|
25 | enum class Column { Name, TStart, TEnd, Tags, Product, NbColumn }; | |
16 | QStringList columnNames() |
|
26 | QStringList columnNames() | |
17 | { |
|
27 | { | |
18 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")}; |
|
28 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")}; | |
@@ -21,14 +31,21 struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate { | |||||
21 | QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const |
|
31 | QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const | |
22 | { |
|
32 | { | |
23 | switch (static_cast<Column>(col)) { |
|
33 | switch (static_cast<Column>(col)) { | |
24 |
case Column:: |
|
34 | case Column::Name: | |
25 | return event->getName(); |
|
35 | return event->getName(); | |
26 | case Column::TStart: |
|
36 | case Column::TStart: | |
27 |
return |
|
37 | return "Oo"; // DateUtils::dateTime(event->getTStart()); | |
28 | case Column::TEnd: |
|
38 | case Column::TEnd: | |
29 |
return |
|
39 | return "oO"; // DateUtils::dateTime(event->getTEnd()); | |
30 | case Column::Product: |
|
40 | case Column::Product: { | |
31 | return event->getProduct(); |
|
41 | auto eventProductsIt = m_EventProducts.find(event.get()); | |
|
42 | if (eventProductsIt != m_EventProducts.cend()) { | |||
|
43 | return QString::number(m_EventProducts.at(event.get()).count()) + " product(s)"; | |||
|
44 | } | |||
|
45 | else { | |||
|
46 | return "0 product"; | |||
|
47 | } | |||
|
48 | } | |||
32 | case Column::Tags: { |
|
49 | case Column::Tags: { | |
33 | QString tagList; |
|
50 | QString tagList; | |
34 | auto tags = event->getTags(); |
|
51 | auto tags = event->getTags(); | |
@@ -46,44 +63,101 struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate { | |||||
46 | Q_ASSERT(false); |
|
63 | Q_ASSERT(false); | |
47 | return QStringLiteral("Unknown Data"); |
|
64 | return QStringLiteral("Unknown Data"); | |
48 | } |
|
65 | } | |
|
66 | ||||
|
67 | void parseEventProduct(const std::shared_ptr<DBEvent> &event) | |||
|
68 | { | |||
|
69 | for (auto product : event->getEventProducts()) { | |||
|
70 | m_EventProducts[event.get()].append(std::make_shared<DBEventProduct>(product)); | |||
|
71 | } | |||
|
72 | } | |||
|
73 | ||||
|
74 | QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const | |||
|
75 | { | |||
|
76 | switch (static_cast<Column>(col)) { | |||
|
77 | case Column::Name: | |||
|
78 | return eventProduct->getProductId(); | |||
|
79 | case Column::TStart: | |||
|
80 | return DateUtils::dateTime(eventProduct->getTStart()); | |||
|
81 | case Column::TEnd: | |||
|
82 | return DateUtils::dateTime(eventProduct->getTEnd()); | |||
|
83 | case Column::Product: | |||
|
84 | return eventProduct->getProductId(); | |||
|
85 | case Column::Tags: { | |||
|
86 | return QString(); | |||
|
87 | } | |||
|
88 | default: | |||
|
89 | break; | |||
|
90 | } | |||
|
91 | ||||
|
92 | Q_ASSERT(false); | |||
|
93 | return QStringLiteral("Unknown Data"); | |||
|
94 | } | |||
|
95 | ||||
|
96 | enum class ItemType { Root, Event, EventProduct }; | |||
|
97 | ItemType indexItemType(const QModelIndex &index) const | |||
|
98 | { | |||
|
99 | ||||
|
100 | if (!index.isValid()) { | |||
|
101 | return ItemType::Root; | |||
|
102 | } | |||
|
103 | else if (index.internalPointer() == nullptr) { | |||
|
104 | return ItemType::Event; | |||
|
105 | } | |||
|
106 | else { | |||
|
107 | return ItemType::EventProduct; | |||
|
108 | } | |||
|
109 | } | |||
|
110 | ||||
|
111 | std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) | |||
|
112 | { | |||
|
113 | auto event = static_cast<DBEvent *>(index.internalPointer()); | |||
|
114 | return m_EventProducts.at(event).value(index.row()); | |||
|
115 | } | |||
49 | }; |
|
116 | }; | |
50 |
|
117 | |||
51 |
CatalogueEvents |
|
118 | CatalogueEventsModel::CatalogueEventsModel(QObject *parent) | |
52 |
: QAbstract |
|
119 | : QAbstractItemModel(parent), | |
53 | impl{spimpl::make_unique_impl<CatalogueEventsTableModelPrivate>()} |
|
120 | impl{spimpl::make_unique_impl<CatalogueEventsTableModelPrivate>()} | |
54 | { |
|
121 | { | |
55 | } |
|
122 | } | |
56 |
|
123 | |||
57 |
void CatalogueEvents |
|
124 | void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events) | |
58 | { |
|
125 | { | |
59 | beginResetModel(); |
|
126 | beginResetModel(); | |
|
127 | ||||
60 | impl->m_Events = events; |
|
128 | impl->m_Events = events; | |
|
129 | for (auto event : events) { | |||
|
130 | impl->parseEventProduct(event); | |||
|
131 | } | |||
|
132 | ||||
61 | endResetModel(); |
|
133 | endResetModel(); | |
62 | } |
|
134 | } | |
63 |
|
135 | |||
64 |
std::shared_ptr<DBEvent> CatalogueEvents |
|
136 | std::shared_ptr<DBEvent> CatalogueEventsModel::getEvent(int row) const | |
65 | { |
|
137 | { | |
66 | return impl->m_Events.value(row); |
|
138 | return impl->m_Events.value(row); | |
67 | } |
|
139 | } | |
68 |
|
140 | |||
69 |
void CatalogueEvents |
|
141 | void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event) | |
70 | { |
|
142 | { | |
71 | beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1); |
|
143 | beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1); | |
72 | impl->m_Events.append(event); |
|
144 | impl->m_Events.append(event); | |
|
145 | impl->parseEventProduct(event); | |||
73 | endInsertRows(); |
|
146 | endInsertRows(); | |
74 | } |
|
147 | } | |
75 |
|
148 | |||
76 |
void CatalogueEvents |
|
149 | void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event) | |
77 | { |
|
150 | { | |
78 | auto index = impl->m_Events.indexOf(event); |
|
151 | auto index = impl->m_Events.indexOf(event); | |
79 | if (index >= 0) { |
|
152 | if (index >= 0) { | |
80 | beginRemoveRows(QModelIndex(), index, index); |
|
153 | beginRemoveRows(QModelIndex(), index, index); | |
81 | impl->m_Events.removeAt(index); |
|
154 | impl->m_Events.removeAt(index); | |
|
155 | impl->m_EventProducts.erase(event.get()); | |||
82 | endRemoveRows(); |
|
156 | endRemoveRows(); | |
83 | } |
|
157 | } | |
84 | } |
|
158 | } | |
85 |
|
159 | |||
86 |
void CatalogueEvents |
|
160 | void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event) | |
87 | { |
|
161 | { | |
88 | auto eventIndex = impl->m_Events.indexOf(event); |
|
162 | auto eventIndex = impl->m_Events.indexOf(event); | |
89 | if (eventIndex >= 0) { |
|
163 | if (eventIndex >= 0) { | |
@@ -91,39 +165,114 void CatalogueEventsTableModel::refreshEvent(const std::shared_ptr<DBEvent> &eve | |||||
91 | } |
|
165 | } | |
92 | } |
|
166 | } | |
93 |
|
167 | |||
94 |
int |
|
168 | QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const | |
95 | { |
|
169 | { | |
96 | int r = impl->m_Events.count(); |
|
170 | if (!hasIndex(row, column, parent)) { | |
97 | return r; |
|
171 | return QModelIndex(); | |
|
172 | } | |||
|
173 | ||||
|
174 | switch (impl->indexItemType(parent)) { | |||
|
175 | case CatalogueEventsTableModelPrivate::ItemType::Root: | |||
|
176 | return createIndex(row, column); | |||
|
177 | case CatalogueEventsTableModelPrivate::ItemType::Event: { | |||
|
178 | auto event = getEvent(parent.row()); | |||
|
179 | return createIndex(row, column, event.get()); | |||
|
180 | } | |||
|
181 | case CatalogueEventsTableModelPrivate::ItemType::EventProduct: | |||
|
182 | break; | |||
|
183 | default: | |||
|
184 | break; | |||
|
185 | } | |||
|
186 | ||||
|
187 | return QModelIndex(); | |||
98 | } |
|
188 | } | |
99 |
|
189 | |||
100 |
|
|
190 | QModelIndex CatalogueEventsModel::parent(const QModelIndex &index) const | |
|
191 | { | |||
|
192 | switch (impl->indexItemType(index)) { | |||
|
193 | case CatalogueEventsTableModelPrivate::ItemType::EventProduct: { | |||
|
194 | auto parentEvent = static_cast<DBEvent *>(index.internalPointer()); | |||
|
195 | auto it | |||
|
196 | = std::find_if(impl->m_Events.cbegin(), impl->m_Events.cend(), | |||
|
197 | [parentEvent](auto event) { return event.get() == parentEvent; }); | |||
|
198 | ||||
|
199 | if (it != impl->m_Events.cend()) { | |||
|
200 | return createIndex(it - impl->m_Events.cbegin(), 0); | |||
|
201 | } | |||
|
202 | else { | |||
|
203 | return QModelIndex(); | |||
|
204 | } | |||
|
205 | } | |||
|
206 | case CatalogueEventsTableModelPrivate::ItemType::Root: | |||
|
207 | break; | |||
|
208 | case CatalogueEventsTableModelPrivate::ItemType::Event: | |||
|
209 | break; | |||
|
210 | default: | |||
|
211 | break; | |||
|
212 | } | |||
|
213 | ||||
|
214 | return QModelIndex(); | |||
|
215 | } | |||
|
216 | ||||
|
217 | int CatalogueEventsModel::rowCount(const QModelIndex &parent) const | |||
|
218 | { | |||
|
219 | if (parent.column() > 0) { | |||
|
220 | return 0; | |||
|
221 | } | |||
|
222 | ||||
|
223 | switch (impl->indexItemType(parent)) { | |||
|
224 | case CatalogueEventsTableModelPrivate::ItemType::Root: | |||
|
225 | return impl->m_Events.count(); | |||
|
226 | case CatalogueEventsTableModelPrivate::ItemType::Event: { | |||
|
227 | auto event = getEvent(parent.row()); | |||
|
228 | return impl->m_EventProducts[event.get()].count(); | |||
|
229 | } | |||
|
230 | case CatalogueEventsTableModelPrivate::ItemType::EventProduct: | |||
|
231 | break; | |||
|
232 | default: | |||
|
233 | break; | |||
|
234 | } | |||
|
235 | ||||
|
236 | return 0; | |||
|
237 | } | |||
|
238 | ||||
|
239 | int CatalogueEventsModel::columnCount(const QModelIndex &parent) const | |||
101 | { |
|
240 | { | |
102 | return static_cast<int>(CatalogueEventsTableModelPrivate::Column::NbColumn); |
|
241 | return static_cast<int>(CatalogueEventsTableModelPrivate::Column::NbColumn); | |
103 | } |
|
242 | } | |
104 |
|
243 | |||
105 |
Qt::ItemFlags CatalogueEvents |
|
244 | Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const | |
106 | { |
|
245 | { | |
107 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; |
|
246 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; | |
108 | } |
|
247 | } | |
109 |
|
248 | |||
110 |
QVariant CatalogueEvents |
|
249 | QVariant CatalogueEventsModel::data(const QModelIndex &index, int role) const | |
111 | { |
|
250 | { | |
112 | if (index.isValid()) { |
|
251 | if (index.isValid()) { | |
113 | auto event = getEvent(index.row()); |
|
|||
114 |
|
252 | |||
115 | switch (role) { |
|
253 | auto type = impl->indexItemType(index); | |
116 | case Qt::DisplayRole: |
|
254 | if (type == CatalogueEventsTableModelPrivate::ItemType::Event) { | |
117 | return impl->eventData(index.column(), event); |
|
255 | auto event = getEvent(index.row()); | |
118 | break; |
|
256 | switch (role) { | |
|
257 | case Qt::DisplayRole: | |||
|
258 | return impl->eventData(index.column(), event); | |||
|
259 | break; | |||
|
260 | } | |||
|
261 | } | |||
|
262 | else if (type == CatalogueEventsTableModelPrivate::ItemType::EventProduct) { | |||
|
263 | auto product = impl->getEventProduct(index); | |||
|
264 | switch (role) { | |||
|
265 | case Qt::DisplayRole: | |||
|
266 | return impl->eventProductData(index.column(), product); | |||
|
267 | break; | |||
|
268 | } | |||
119 | } |
|
269 | } | |
120 | } |
|
270 | } | |
121 |
|
271 | |||
122 | return QVariant{}; |
|
272 | return QVariant{}; | |
123 | } |
|
273 | } | |
124 |
|
274 | |||
125 |
QVariant CatalogueEvents |
|
275 | QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const | |
126 | int role) const |
|
|||
127 | { |
|
276 | { | |
128 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
|
277 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | |
129 | return impl->columnNames().value(section); |
|
278 | return impl->columnNames().value(section); | |
@@ -132,7 +281,7 QVariant CatalogueEventsTableModel::headerData(int section, Qt::Orientation orie | |||||
132 | return QVariant(); |
|
281 | return QVariant(); | |
133 | } |
|
282 | } | |
134 |
|
283 | |||
135 |
void CatalogueEvents |
|
284 | void CatalogueEventsModel::sort(int column, Qt::SortOrder order) | |
136 | { |
|
285 | { | |
137 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), |
|
286 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), | |
138 | [this, column, order](auto e1, auto e2) { |
|
287 | [this, column, order](auto e1, auto e2) { | |
@@ -147,17 +296,17 void CatalogueEventsTableModel::sort(int column, Qt::SortOrder order) | |||||
147 | emit dataChanged(QModelIndex(), QModelIndex()); |
|
296 | emit dataChanged(QModelIndex(), QModelIndex()); | |
148 | } |
|
297 | } | |
149 |
|
298 | |||
150 |
Qt::DropActions CatalogueEvents |
|
299 | Qt::DropActions CatalogueEventsModel::supportedDragActions() const | |
151 | { |
|
300 | { | |
152 | return Qt::CopyAction | Qt::MoveAction; |
|
301 | return Qt::CopyAction | Qt::MoveAction; | |
153 | } |
|
302 | } | |
154 |
|
303 | |||
155 |
QStringList CatalogueEvents |
|
304 | QStringList CatalogueEventsModel::mimeTypes() const | |
156 | { |
|
305 | { | |
157 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; |
|
306 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; | |
158 | } |
|
307 | } | |
159 |
|
308 | |||
160 |
QMimeData *CatalogueEvents |
|
309 | QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const | |
161 | { |
|
310 | { | |
162 | auto mimeData = new QMimeData; |
|
311 | auto mimeData = new QMimeData; | |
163 |
|
312 | |||
@@ -169,8 +318,8 QMimeData *CatalogueEventsTableModel::mimeData(const QModelIndexList &indexes) c | |||||
169 | auto event = getEvent(index.row()); |
|
318 | auto event = getEvent(index.row()); | |
170 | if (eventList.isEmpty()) { |
|
319 | if (eventList.isEmpty()) { | |
171 | // Gets the range of the first variable |
|
320 | // Gets the range of the first variable | |
172 | firstTimeRange.m_TStart = event->getTStart(); |
|
321 | // firstTimeRange.m_TStart = event->getTStart(); | |
173 | firstTimeRange.m_TEnd = event->getTEnd(); |
|
322 | // firstTimeRange.m_TEnd = event->getTEnd(); | |
174 | } |
|
323 | } | |
175 |
|
324 | |||
176 | eventList << event; |
|
325 | eventList << event; |
@@ -2,7 +2,7 | |||||
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/CatalogueEvents |
|
5 | #include <Catalogue/CatalogueEventsModel.h> | |
6 | #include <CatalogueDao.h> |
|
6 | #include <CatalogueDao.h> | |
7 | #include <DBCatalogue.h> |
|
7 | #include <DBCatalogue.h> | |
8 | #include <SqpApplication.h> |
|
8 | #include <SqpApplication.h> | |
@@ -21,31 +21,31 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); | |||||
21 |
|
21 | |||
22 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { |
|
22 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |
23 |
|
23 | |||
24 |
CatalogueEvents |
|
24 | CatalogueEventsModel *m_Model = nullptr; | |
25 | QStringList m_ZonesForTimeMode; |
|
25 | QStringList m_ZonesForTimeMode; | |
26 | QString m_ZoneForGraphMode; |
|
26 | QString m_ZoneForGraphMode; | |
27 |
|
27 | |||
28 | VisualizationWidget *m_VisualizationWidget = nullptr; |
|
28 | VisualizationWidget *m_VisualizationWidget = nullptr; | |
29 |
|
29 | |||
30 |
void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QT |
|
30 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView) | |
31 | { |
|
31 | { | |
32 |
t |
|
32 | treeView->setSortingEnabled(false); | |
33 | m_Model->setEvents(events); |
|
33 | m_Model->setEvents(events); | |
34 |
t |
|
34 | treeView->setSortingEnabled(true); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 |
void addEvent(const std::shared_ptr<DBEvent> &event, QT |
|
37 | void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) | |
38 | { |
|
38 | { | |
39 |
t |
|
39 | treeView->setSortingEnabled(false); | |
40 | m_Model->addEvent(event); |
|
40 | m_Model->addEvent(event); | |
41 |
t |
|
41 | treeView->setSortingEnabled(true); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 |
void removeEvent(const std::shared_ptr<DBEvent> &event, QT |
|
44 | void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) | |
45 | { |
|
45 | { | |
46 |
t |
|
46 | treeView->setSortingEnabled(false); | |
47 | m_Model->removeEvent(event); |
|
47 | m_Model->removeEvent(event); | |
48 |
t |
|
48 | treeView->setSortingEnabled(true); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | QStringList getAvailableVisualizationZoneList() const |
|
51 | QStringList getAvailableVisualizationZoneList() const | |
@@ -131,9 +131,9 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |||||
131 | return result; |
|
131 | return result; | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 |
void updateForTimeMode(QT |
|
134 | void updateForTimeMode(QTreeView *treeView) | |
135 | { |
|
135 | { | |
136 |
auto selectedRows = t |
|
136 | auto selectedRows = treeView->selectionModel()->selectedRows(); | |
137 |
|
137 | |||
138 | if (selectedRows.count() == 1) { |
|
138 | if (selectedRows.count() == 1) { | |
139 | auto event = m_Model->getEvent(selectedRows.first().row()); |
|
139 | auto event = m_Model->getEvent(selectedRows.first().row()); | |
@@ -143,8 +143,8 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |||||
143 | for (auto zoneName : m_ZonesForTimeMode) { |
|
143 | for (auto zoneName : m_ZonesForTimeMode) { | |
144 | if (auto zone = tab->getZoneWithName(zoneName)) { |
|
144 | if (auto zone = tab->getZoneWithName(zoneName)) { | |
145 | SqpRange eventRange; |
|
145 | SqpRange eventRange; | |
146 | eventRange.m_TStart = event->getTStart(); |
|
146 | // eventRange.m_TStart = event->getTStart(); | |
147 | eventRange.m_TEnd = event->getTEnd(); |
|
147 | // eventRange.m_TEnd = event->getTEnd(); | |
148 | zone->setZoneRange(eventRange); |
|
148 | zone->setZoneRange(eventRange); | |
149 | } |
|
149 | } | |
150 | } |
|
150 | } | |
@@ -165,9 +165,9 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |||||
165 | } |
|
165 | } | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 |
void updateForGraphMode(QT |
|
168 | void updateForGraphMode(QTreeView *treeView) | |
169 | { |
|
169 | { | |
170 |
auto selectedRows = t |
|
170 | auto selectedRows = treeView->selectionModel()->selectedRows(); | |
171 |
|
171 | |||
172 | if (selectedRows.count() == 1) { |
|
172 | if (selectedRows.count() == 1) { | |
173 | auto event = m_Model->getEvent(selectedRows.first().row()); |
|
173 | auto event = m_Model->getEvent(selectedRows.first().row()); | |
@@ -201,12 +201,12 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||||
201 | { |
|
201 | { | |
202 | ui->setupUi(this); |
|
202 | ui->setupUi(this); | |
203 |
|
203 | |||
204 |
impl->m_Model = new CatalogueEvents |
|
204 | impl->m_Model = new CatalogueEventsModel{this}; | |
205 |
ui->t |
|
205 | ui->treeView->setModel(impl->m_Model); | |
206 |
|
206 | |||
207 |
ui->t |
|
207 | ui->treeView->setSortingEnabled(true); | |
208 |
ui->t |
|
208 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); | |
209 |
ui->t |
|
209 | ui->treeView->setDragEnabled(true); | |
210 |
|
210 | |||
211 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { |
|
211 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { | |
212 | if (checked) { |
|
212 | if (checked) { | |
@@ -215,7 +215,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||||
215 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, |
|
215 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, | |
216 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); |
|
216 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); | |
217 |
|
217 | |||
218 |
impl->updateForTimeMode(ui->t |
|
218 | impl->updateForTimeMode(ui->treeView); | |
219 | } |
|
219 | } | |
220 | }); |
|
220 | }); | |
221 |
|
221 | |||
@@ -227,38 +227,38 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||||
227 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) |
|
227 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) | |
228 | .value(0); |
|
228 | .value(0); | |
229 |
|
229 | |||
230 |
impl->updateForGraphMode(ui->t |
|
230 | impl->updateForGraphMode(ui->treeView); | |
231 | } |
|
231 | } | |
232 | }); |
|
232 | }); | |
233 |
|
233 | |||
234 | auto emitSelection = [this]() { |
|
234 | auto emitSelection = [this]() { | |
235 | QVector<std::shared_ptr<DBEvent> > events; |
|
235 | QVector<std::shared_ptr<DBEvent> > events; | |
236 |
for (auto rowIndex : ui->t |
|
236 | for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) { | |
237 | events << impl->m_Model->getEvent(rowIndex.row()); |
|
237 | events << impl->m_Model->getEvent(rowIndex.row()); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | emit this->eventsSelected(events); |
|
240 | emit this->eventsSelected(events); | |
241 | }; |
|
241 | }; | |
242 |
|
242 | |||
243 |
connect(ui->t |
|
243 | connect(ui->treeView, &QTreeView::clicked, emitSelection); | |
244 |
connect(ui->t |
|
244 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); | |
245 |
|
245 | |||
246 |
connect(ui->t |
|
246 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { | |
247 |
auto isNotMultiSelection = ui->t |
|
247 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; | |
248 | ui->btnChart->setEnabled(isNotMultiSelection); |
|
248 | ui->btnChart->setEnabled(isNotMultiSelection); | |
249 | ui->btnTime->setEnabled(isNotMultiSelection); |
|
249 | ui->btnTime->setEnabled(isNotMultiSelection); | |
250 |
|
250 | |||
251 | if (isNotMultiSelection && ui->btnTime->isChecked()) { |
|
251 | if (isNotMultiSelection && ui->btnTime->isChecked()) { | |
252 |
impl->updateForTimeMode(ui->t |
|
252 | impl->updateForTimeMode(ui->treeView); | |
253 | } |
|
253 | } | |
254 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { |
|
254 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { | |
255 |
impl->updateForGraphMode(ui->t |
|
255 | impl->updateForGraphMode(ui->treeView); | |
256 | } |
|
256 | } | |
257 | }); |
|
257 | }); | |
258 |
|
258 | |||
259 |
ui->t |
|
259 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
260 |
ui->t |
|
260 | ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); | |
261 |
ui->t |
|
261 | ui->treeView->header()->setSortIndicatorShown(true); | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | CatalogueEventsWidget::~CatalogueEventsWidget() |
|
264 | CatalogueEventsWidget::~CatalogueEventsWidget() | |
@@ -292,5 +292,5 void CatalogueEventsWidget::populateWithCatalogues( | |||||
292 | } |
|
292 | } | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 |
impl->setEvents(events, ui->t |
|
295 | impl->setEvents(events, ui->treeView); | |
296 | } |
|
296 | } |
@@ -62,17 +62,17 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpda | |||||
62 | }); |
|
62 | }); | |
63 |
|
63 | |||
64 | connect(ui->leEventMission, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
64 | connect(ui->leEventMission, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
65 | if (ui->leEventMission->text() != m_DisplayedEvent->getMission()) { |
|
65 | // if (ui->leEventMission->text() != m_DisplayedEvent->getMission()) { | |
66 | m_DisplayedEvent->setMission(ui->leEventMission->text()); |
|
66 | // m_DisplayedEvent->setMission(ui->leEventMission->text()); | |
67 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
67 | // emit inspector->eventUpdated(m_DisplayedEvent); | |
68 | } |
|
68 | // } | |
69 | }); |
|
69 | }); | |
70 |
|
70 | |||
71 | connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
71 | connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
72 | if (ui->leEventProduct->text() != m_DisplayedEvent->getProduct()) { |
|
72 | // if (ui->leEventProduct->text() != m_DisplayedEvent->getProduct()) { | |
73 | m_DisplayedEvent->setProduct(ui->leEventProduct->text()); |
|
73 | // m_DisplayedEvent->setProduct(ui->leEventProduct->text()); | |
74 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
74 | // emit inspector->eventUpdated(m_DisplayedEvent); | |
75 | } |
|
75 | // } | |
76 | }); |
|
76 | }); | |
77 |
|
77 | |||
78 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
78 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
@@ -80,19 +80,19 void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpda | |||||
80 | }); |
|
80 | }); | |
81 |
|
81 | |||
82 | connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
82 | connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { | |
83 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); |
|
83 | // auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); | |
84 | if (time != m_DisplayedEvent->getTStart()) { |
|
84 | // if (time != m_DisplayedEvent->getTStart()) { | |
85 | m_DisplayedEvent->setTStart(time); |
|
85 | // m_DisplayedEvent->setTStart(time); | |
86 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
86 | // emit inspector->eventUpdated(m_DisplayedEvent); | |
87 | } |
|
87 | // } | |
88 | }); |
|
88 | }); | |
89 |
|
89 | |||
90 | connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
90 | connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { | |
91 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); |
|
91 | // auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); | |
92 | if (time != m_DisplayedEvent->getTEnd()) { |
|
92 | // if (time != m_DisplayedEvent->getTEnd()) { | |
93 | m_DisplayedEvent->setTEnd(time); |
|
93 | // m_DisplayedEvent->setTEnd(time); | |
94 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
94 | // emit inspector->eventUpdated(m_DisplayedEvent); | |
95 | } |
|
95 | // } | |
96 | }); |
|
96 | }); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
@@ -114,8 +114,8 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) | |||||
114 |
|
114 | |||
115 | showPage(Page::EventProperties); |
|
115 | showPage(Page::EventProperties); | |
116 | ui->leEventName->setText(event->getName()); |
|
116 | ui->leEventName->setText(event->getName()); | |
117 | ui->leEventMission->setText(event->getMission()); |
|
117 | // ui->leEventMission->setText(event->getMission()); | |
118 | ui->leEventProduct->setText(event->getProduct()); |
|
118 | // ui->leEventProduct->setText(event->getProduct()); | |
119 |
|
119 | |||
120 | QString tagList; |
|
120 | QString tagList; | |
121 | auto tags = event->getTags(); |
|
121 | auto tags = event->getTags(); | |
@@ -126,8 +126,8 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) | |||||
126 |
|
126 | |||
127 | ui->leEventTags->setText(tagList); |
|
127 | ui->leEventTags->setText(tagList); | |
128 |
|
128 | |||
129 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); |
|
129 | // ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); | |
130 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); |
|
130 | // ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); | |
131 |
|
131 | |||
132 | blockSignals(false); |
|
132 | blockSignals(false); | |
133 | } |
|
133 | } |
@@ -114,7 +114,7 | |||||
114 | </layout> |
|
114 | </layout> | |
115 | </item> |
|
115 | </item> | |
116 | <item> |
|
116 | <item> | |
117 |
<widget class="QT |
|
117 | <widget class="QTreeView" name="treeView"> | |
118 | <property name="dragEnabled"> |
|
118 | <property name="dragEnabled"> | |
119 | <bool>true</bool> |
|
119 | <bool>true</bool> | |
120 | </property> |
|
120 | </property> | |
@@ -124,22 +124,7 | |||||
124 | <property name="selectionBehavior"> |
|
124 | <property name="selectionBehavior"> | |
125 | <enum>QAbstractItemView::SelectRows</enum> |
|
125 | <enum>QAbstractItemView::SelectRows</enum> | |
126 | </property> |
|
126 | </property> | |
127 |
<attribute name="h |
|
127 | <attribute name="headerStretchLastSection"> | |
128 | <bool>true</bool> |
|
|||
129 | </attribute> |
|
|||
130 | <attribute name="horizontalHeaderHighlightSections"> |
|
|||
131 | <bool>false</bool> |
|
|||
132 | </attribute> |
|
|||
133 | <attribute name="horizontalHeaderShowSortIndicator" stdset="0"> |
|
|||
134 | <bool>true</bool> |
|
|||
135 | </attribute> |
|
|||
136 | <attribute name="verticalHeaderVisible"> |
|
|||
137 | <bool>false</bool> |
|
|||
138 | </attribute> |
|
|||
139 | <attribute name="verticalHeaderDefaultSectionSize"> |
|
|||
140 | <number>25</number> |
|
|||
141 | </attribute> |
|
|||
142 | <attribute name="verticalHeaderHighlightSections"> |
|
|||
143 | <bool>false</bool> |
|
128 | <bool>false</bool> | |
144 | </attribute> |
|
129 | </attribute> | |
145 | </widget> |
|
130 | </widget> |
General Comments 0
You need to be logged in to leave comments.
Login now