@@ -1,40 +1,42 | |||
|
1 |
#ifndef SCIQLOP_CATALOGUEEVENTS |
|
|
2 |
#define SCIQLOP_CATALOGUEEVENTS |
|
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSMODEL_H | |
|
2 | #define SCIQLOP_CATALOGUEEVENTSMODEL_H | |
|
3 | 3 | |
|
4 | 4 | #include <Common/spimpl.h> |
|
5 |
#include <QAbstract |
|
|
5 | #include <QAbstractItemModel> | |
|
6 | 6 | |
|
7 | 7 | class DBEvent; |
|
8 | 8 | |
|
9 |
class CatalogueEvents |
|
|
9 | class CatalogueEventsModel : public QAbstractItemModel { | |
|
10 | 10 | public: |
|
11 |
CatalogueEvents |
|
|
11 | CatalogueEventsModel(QObject *parent = nullptr); | |
|
12 | 12 | |
|
13 | 13 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events); |
|
14 | 14 | std::shared_ptr<DBEvent> getEvent(int row) const; |
|
15 | 15 | |
|
16 | ||
|
16 | 17 | void addEvent(const std::shared_ptr<DBEvent> &event); |
|
17 | 18 | void removeEvent(const std::shared_ptr<DBEvent> &event); |
|
18 | 19 | |
|
19 | 20 | void refreshEvent(const std::shared_ptr<DBEvent> &event); |
|
20 | 21 | |
|
21 | 22 | // Model |
|
23 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; | |
|
24 | QModelIndex parent(const QModelIndex &index) const; | |
|
22 | 25 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
|
23 | 26 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
|
24 | 27 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
|
25 | 28 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
26 | 29 | QVariant headerData(int section, Qt::Orientation orientation, |
|
27 | 30 | int role = Qt::DisplayRole) const override; |
|
28 | 31 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; |
|
29 | 32 | |
|
30 | 33 | Qt::DropActions supportedDragActions() const override; |
|
31 | 34 | QStringList mimeTypes() const override; |
|
32 | 35 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
|
33 | 36 | |
|
34 | ||
|
35 | 37 | private: |
|
36 | 38 | class CatalogueEventsTableModelPrivate; |
|
37 | 39 | spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl; |
|
38 | 40 | }; |
|
39 | 41 | |
|
40 |
#endif // SCIQLOP_CATALOGUEEVENTS |
|
|
42 | #endif // SCIQLOP_CATALOGUEEVENTSMODEL_H |
@@ -1,127 +1,127 | |||
|
1 | 1 | |
|
2 | 2 | qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) |
|
3 | 3 | catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) |
|
4 | 4 | |
|
5 | 5 | gui_moc_headers = [ |
|
6 | 6 | 'include/DataSource/DataSourceWidget.h', |
|
7 | 7 | 'include/Settings/SqpSettingsDialog.h', |
|
8 | 8 | 'include/Settings/SqpSettingsGeneralWidget.h', |
|
9 | 9 | 'include/SidePane/SqpSidePane.h', |
|
10 | 10 | 'include/SqpApplication.h', |
|
11 | 11 | 'include/DragAndDrop/DragDropScroller.h', |
|
12 | 12 | 'include/DragAndDrop/DragDropTabSwitcher.h', |
|
13 | 13 | 'include/TimeWidget/TimeWidget.h', |
|
14 | 14 | 'include/Variable/VariableInspectorWidget.h', |
|
15 | 15 | 'include/Variable/RenameVariableDialog.h', |
|
16 | 16 | 'include/Visualization/qcustomplot.h', |
|
17 | 17 | 'include/Visualization/VisualizationGraphWidget.h', |
|
18 | 18 | 'include/Visualization/VisualizationTabWidget.h', |
|
19 | 19 | 'include/Visualization/VisualizationWidget.h', |
|
20 | 20 | 'include/Visualization/VisualizationZoneWidget.h', |
|
21 | 21 | 'include/Visualization/VisualizationDragDropContainer.h', |
|
22 | 22 | 'include/Visualization/VisualizationDragWidget.h', |
|
23 | 23 | 'include/Visualization/ColorScaleEditor.h', |
|
24 | 24 | 'include/Actions/SelectionZoneAction.h', |
|
25 | 25 | 'include/Visualization/VisualizationMultiZoneSelectionDialog.h', |
|
26 | 26 | 'include/Catalogue/CatalogueExplorer.h', |
|
27 | 27 | 'include/Catalogue/CatalogueEventsWidget.h', |
|
28 | 28 | 'include/Catalogue/CatalogueSideBarWidget.h', |
|
29 | 29 | 'include/Catalogue/CatalogueInspectorWidget.h' |
|
30 | 30 | ] |
|
31 | 31 | |
|
32 | 32 | gui_ui_files = [ |
|
33 | 33 | 'ui/DataSource/DataSourceWidget.ui', |
|
34 | 34 | 'ui/Settings/SqpSettingsDialog.ui', |
|
35 | 35 | 'ui/Settings/SqpSettingsGeneralWidget.ui', |
|
36 | 36 | 'ui/SidePane/SqpSidePane.ui', |
|
37 | 37 | 'ui/TimeWidget/TimeWidget.ui', |
|
38 | 38 | 'ui/Variable/VariableInspectorWidget.ui', |
|
39 | 39 | 'ui/Variable/RenameVariableDialog.ui', |
|
40 | 40 | 'ui/Variable/VariableMenuHeaderWidget.ui', |
|
41 | 41 | 'ui/Visualization/VisualizationGraphWidget.ui', |
|
42 | 42 | 'ui/Visualization/VisualizationTabWidget.ui', |
|
43 | 43 | 'ui/Visualization/VisualizationWidget.ui', |
|
44 | 44 | 'ui/Visualization/VisualizationZoneWidget.ui', |
|
45 | 45 | 'ui/Visualization/ColorScaleEditor.ui', |
|
46 | 46 | 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui', |
|
47 | 47 | 'ui/Catalogue/CatalogueExplorer.ui', |
|
48 | 48 | 'ui/Catalogue/CatalogueEventsWidget.ui', |
|
49 | 49 | 'ui/Catalogue/CatalogueSideBarWidget.ui', |
|
50 | 50 | 'ui/Catalogue/CatalogueInspectorWidget.ui' |
|
51 | 51 | ] |
|
52 | 52 | |
|
53 | 53 | gui_qresources = ['resources/sqpguiresources.qrc'] |
|
54 | 54 | |
|
55 | 55 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, |
|
56 | 56 | ui_files : gui_ui_files, |
|
57 | 57 | qresources : gui_qresources) |
|
58 | 58 | |
|
59 | 59 | gui_sources = [ |
|
60 | 60 | 'src/SqpApplication.cpp', |
|
61 | 61 | 'src/DragAndDrop/DragDropGuiController.cpp', |
|
62 | 62 | 'src/DragAndDrop/DragDropScroller.cpp', |
|
63 | 63 | 'src/DragAndDrop/DragDropTabSwitcher.cpp', |
|
64 | 64 | 'src/Common/ColorUtils.cpp', |
|
65 | 65 | 'src/Common/VisualizationDef.cpp', |
|
66 | 66 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', |
|
67 | 67 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', |
|
68 | 68 | 'src/DataSource/DataSourceWidget.cpp', |
|
69 | 69 | 'src/DataSource/DataSourceTreeWidget.cpp', |
|
70 | 70 | 'src/Settings/SqpSettingsDialog.cpp', |
|
71 | 71 | 'src/Settings/SqpSettingsGeneralWidget.cpp', |
|
72 | 72 | 'src/SidePane/SqpSidePane.cpp', |
|
73 | 73 | 'src/TimeWidget/TimeWidget.cpp', |
|
74 | 74 | 'src/Variable/VariableInspectorWidget.cpp', |
|
75 | 75 | 'src/Variable/VariableInspectorTableView.cpp', |
|
76 | 76 | 'src/Variable/VariableMenuHeaderWidget.cpp', |
|
77 | 77 | 'src/Variable/RenameVariableDialog.cpp', |
|
78 | 78 | 'src/Visualization/VisualizationGraphHelper.cpp', |
|
79 | 79 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', |
|
80 | 80 | 'src/Visualization/VisualizationGraphWidget.cpp', |
|
81 | 81 | 'src/Visualization/VisualizationTabWidget.cpp', |
|
82 | 82 | 'src/Visualization/VisualizationWidget.cpp', |
|
83 | 83 | 'src/Visualization/VisualizationZoneWidget.cpp', |
|
84 | 84 | 'src/Visualization/qcustomplot.cpp', |
|
85 | 85 | 'src/Visualization/QCustomPlotSynchronizer.cpp', |
|
86 | 86 | 'src/Visualization/operations/FindVariableOperation.cpp', |
|
87 | 87 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', |
|
88 | 88 | 'src/Visualization/operations/MenuBuilder.cpp', |
|
89 | 89 | 'src/Visualization/operations/RemoveVariableOperation.cpp', |
|
90 | 90 | 'src/Visualization/operations/RescaleAxeOperation.cpp', |
|
91 | 91 | 'src/Visualization/VisualizationDragDropContainer.cpp', |
|
92 | 92 | 'src/Visualization/VisualizationDragWidget.cpp', |
|
93 | 93 | 'src/Visualization/AxisRenderingUtils.cpp', |
|
94 | 94 | 'src/Visualization/PlottablesRenderingUtils.cpp', |
|
95 | 95 | 'src/Visualization/MacScrollBarStyle.cpp', |
|
96 | 96 | 'src/Visualization/VisualizationCursorItem.cpp', |
|
97 | 97 | 'src/Visualization/ColorScaleEditor.cpp', |
|
98 | 98 | 'src/Visualization/SqpColorScale.cpp', |
|
99 | 99 | 'src/Visualization/QCPColorMapIterator.cpp', |
|
100 | 100 | 'src/Visualization/VisualizationSelectionZoneItem.cpp', |
|
101 | 101 | 'src/Visualization/VisualizationSelectionZoneManager.cpp', |
|
102 | 102 | 'src/Actions/SelectionZoneAction.cpp', |
|
103 | 103 | 'src/Actions/ActionsGuiController.cpp', |
|
104 | 104 | 'src/Visualization/VisualizationActionManager.cpp', |
|
105 | 105 | 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp', |
|
106 | 106 | 'src/Catalogue/CatalogueExplorer.cpp', |
|
107 | 107 | 'src/Catalogue/CatalogueEventsWidget.cpp', |
|
108 | 108 | 'src/Catalogue/CatalogueSideBarWidget.cpp', |
|
109 | 109 | 'src/Catalogue/CatalogueInspectorWidget.cpp', |
|
110 | 110 | 'src/Catalogue/CatalogueTreeWidgetItem.cpp', |
|
111 |
'src/Catalogue/CatalogueEvents |
|
|
111 | 'src/Catalogue/CatalogueEventsModel.cpp' | |
|
112 | 112 | ] |
|
113 | 113 | |
|
114 | 114 | gui_inc = include_directories(['include']) |
|
115 | 115 | |
|
116 | 116 | sciqlop_gui_lib = library('sciqlopgui', |
|
117 | 117 | gui_sources, |
|
118 | 118 | gui_moc_files, |
|
119 | 119 | include_directories : [gui_inc], |
|
120 | 120 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], |
|
121 | 121 | install : true |
|
122 | 122 | ) |
|
123 | 123 | |
|
124 | 124 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, |
|
125 | 125 | include_directories : gui_inc, |
|
126 | 126 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) |
|
127 | 127 |
@@ -1,191 +1,340 | |||
|
1 |
#include "Catalogue/CatalogueEvents |
|
|
1 | #include "Catalogue/CatalogueEventsModel.h" | |
|
2 | 2 | |
|
3 | 3 | #include <Common/DateUtils.h> |
|
4 | 4 | #include <Common/MimeTypesDef.h> |
|
5 | 5 | #include <DBEvent.h> |
|
6 | #include <DBEventProduct.h> | |
|
6 | 7 | #include <DBTag.h> |
|
7 | 8 | #include <Data/SqpRange.h> |
|
8 | #include <QMimeData> | |
|
9 | 9 | #include <SqpApplication.h> |
|
10 | 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 | 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 | 26 | QStringList columnNames() |
|
17 | 27 | { |
|
18 | 28 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")}; |
|
19 | 29 | } |
|
20 | 30 | |
|
21 | 31 | QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const |
|
22 | 32 | { |
|
23 | 33 | switch (static_cast<Column>(col)) { |
|
24 |
case Column:: |
|
|
34 | case Column::Name: | |
|
25 | 35 | return event->getName(); |
|
26 | 36 | case Column::TStart: |
|
27 |
return |
|
|
37 | return "Oo"; // DateUtils::dateTime(event->getTStart()); | |
|
28 | 38 | case Column::TEnd: |
|
29 |
return |
|
|
30 | case Column::Product: | |
|
31 | return event->getProduct(); | |
|
39 | return "oO"; // DateUtils::dateTime(event->getTEnd()); | |
|
40 | case Column::Product: { | |
|
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 | 49 | case Column::Tags: { |
|
33 | 50 | QString tagList; |
|
34 | 51 | auto tags = event->getTags(); |
|
35 | 52 | for (auto tag : tags) { |
|
36 | 53 | tagList += tag.getName(); |
|
37 | 54 | tagList += ' '; |
|
38 | 55 | } |
|
39 | 56 | |
|
40 | 57 | return tagList; |
|
41 | 58 | } |
|
42 | 59 | default: |
|
43 | 60 | break; |
|
44 | 61 | } |
|
45 | 62 | |
|
46 | 63 | Q_ASSERT(false); |
|
47 | 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 |
|
|
52 |
: QAbstract |
|
|
118 | CatalogueEventsModel::CatalogueEventsModel(QObject *parent) | |
|
119 | : QAbstractItemModel(parent), | |
|
53 | 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 | 126 | beginResetModel(); |
|
127 | ||
|
60 | 128 | impl->m_Events = events; |
|
129 | for (auto event : events) { | |
|
130 | impl->parseEventProduct(event); | |
|
131 | } | |
|
132 | ||
|
61 | 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 | 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 | 143 | beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1); |
|
72 | 144 | impl->m_Events.append(event); |
|
145 | impl->parseEventProduct(event); | |
|
73 | 146 | endInsertRows(); |
|
74 | 147 | } |
|
75 | 148 | |
|
76 |
void CatalogueEvents |
|
|
149 | void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event) | |
|
77 | 150 | { |
|
78 | 151 | auto index = impl->m_Events.indexOf(event); |
|
79 | 152 | if (index >= 0) { |
|
80 | 153 | beginRemoveRows(QModelIndex(), index, index); |
|
81 | 154 | impl->m_Events.removeAt(index); |
|
155 | impl->m_EventProducts.erase(event.get()); | |
|
82 | 156 | endRemoveRows(); |
|
83 | 157 | } |
|
84 | 158 | } |
|
85 | 159 | |
|
86 |
void CatalogueEvents |
|
|
160 | void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event) | |
|
87 | 161 | { |
|
88 | 162 | auto eventIndex = impl->m_Events.indexOf(event); |
|
89 | 163 | if (eventIndex >= 0) { |
|
90 | 164 | emit dataChanged(index(eventIndex, 0), index(eventIndex, columnCount())); |
|
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(); | |
|
97 | return r; | |
|
170 | if (!hasIndex(row, column, parent)) { | |
|
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 | 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 | 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 | 251 | if (index.isValid()) { |
|
113 | auto event = getEvent(index.row()); | |
|
114 | 252 | |
|
115 | switch (role) { | |
|
116 | case Qt::DisplayRole: | |
|
117 | return impl->eventData(index.column(), event); | |
|
118 | break; | |
|
253 | auto type = impl->indexItemType(index); | |
|
254 | if (type == CatalogueEventsTableModelPrivate::ItemType::Event) { | |
|
255 | auto event = getEvent(index.row()); | |
|
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 | 272 | return QVariant{}; |
|
123 | 273 | } |
|
124 | 274 | |
|
125 |
QVariant CatalogueEvents |
|
|
126 | int role) const | |
|
275 | QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientation, int role) const | |
|
127 | 276 | { |
|
128 | 277 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
|
129 | 278 | return impl->columnNames().value(section); |
|
130 | 279 | } |
|
131 | 280 | |
|
132 | 281 | return QVariant(); |
|
133 | 282 | } |
|
134 | 283 | |
|
135 |
void CatalogueEvents |
|
|
284 | void CatalogueEventsModel::sort(int column, Qt::SortOrder order) | |
|
136 | 285 | { |
|
137 | 286 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), |
|
138 | 287 | [this, column, order](auto e1, auto e2) { |
|
139 | 288 | auto data1 = impl->eventData(column, e1); |
|
140 | 289 | auto data2 = impl->eventData(column, e2); |
|
141 | 290 | |
|
142 | 291 | auto result = data1.toString() < data2.toString(); |
|
143 | 292 | |
|
144 | 293 | return order == Qt::AscendingOrder ? result : !result; |
|
145 | 294 | }); |
|
146 | 295 | |
|
147 | 296 | emit dataChanged(QModelIndex(), QModelIndex()); |
|
148 | 297 | } |
|
149 | 298 | |
|
150 |
Qt::DropActions CatalogueEvents |
|
|
299 | Qt::DropActions CatalogueEventsModel::supportedDragActions() const | |
|
151 | 300 | { |
|
152 | 301 | return Qt::CopyAction | Qt::MoveAction; |
|
153 | 302 | } |
|
154 | 303 | |
|
155 |
QStringList CatalogueEvents |
|
|
304 | QStringList CatalogueEventsModel::mimeTypes() const | |
|
156 | 305 | { |
|
157 | 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 | 311 | auto mimeData = new QMimeData; |
|
163 | 312 | |
|
164 | 313 | QVector<std::shared_ptr<DBEvent> > eventList; |
|
165 | 314 | |
|
166 | 315 | SqpRange firstTimeRange; |
|
167 | 316 | for (const auto &index : indexes) { |
|
168 | 317 | if (index.column() == 0) { // only the first column |
|
169 | 318 | auto event = getEvent(index.row()); |
|
170 | 319 | if (eventList.isEmpty()) { |
|
171 | 320 | // Gets the range of the first variable |
|
172 | firstTimeRange.m_TStart = event->getTStart(); | |
|
173 | firstTimeRange.m_TEnd = event->getTEnd(); | |
|
321 | // firstTimeRange.m_TStart = event->getTStart(); | |
|
322 | // firstTimeRange.m_TEnd = event->getTEnd(); | |
|
174 | 323 | } |
|
175 | 324 | |
|
176 | 325 | eventList << event; |
|
177 | 326 | } |
|
178 | 327 | } |
|
179 | 328 | |
|
180 | 329 | auto eventsEncodedData |
|
181 | 330 | = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO |
|
182 | 331 | mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData); |
|
183 | 332 | |
|
184 | 333 | if (eventList.count() == 1) { |
|
185 | 334 | // No time range MIME data if multiple events are dragged |
|
186 | 335 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); |
|
187 | 336 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); |
|
188 | 337 | } |
|
189 | 338 | |
|
190 | 339 | return mimeData; |
|
191 | 340 | } |
@@ -1,296 +1,296 | |||
|
1 | 1 | #include "Catalogue/CatalogueEventsWidget.h" |
|
2 | 2 | #include "ui_CatalogueEventsWidget.h" |
|
3 | 3 | |
|
4 | 4 | #include <Catalogue/CatalogueController.h> |
|
5 |
#include <Catalogue/CatalogueEvents |
|
|
5 | #include <Catalogue/CatalogueEventsModel.h> | |
|
6 | 6 | #include <CatalogueDao.h> |
|
7 | 7 | #include <DBCatalogue.h> |
|
8 | 8 | #include <SqpApplication.h> |
|
9 | 9 | #include <Visualization/VisualizationTabWidget.h> |
|
10 | 10 | #include <Visualization/VisualizationWidget.h> |
|
11 | 11 | #include <Visualization/VisualizationZoneWidget.h> |
|
12 | 12 | |
|
13 | 13 | #include <QDialog> |
|
14 | 14 | #include <QDialogButtonBox> |
|
15 | 15 | #include <QListWidget> |
|
16 | 16 | |
|
17 | 17 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") |
|
18 | 18 | |
|
19 | 19 | /// Format of the dates appearing in the label of a cursor |
|
20 | 20 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); |
|
21 | 21 | |
|
22 | 22 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { |
|
23 | 23 | |
|
24 |
CatalogueEvents |
|
|
24 | CatalogueEventsModel *m_Model = nullptr; | |
|
25 | 25 | QStringList m_ZonesForTimeMode; |
|
26 | 26 | QString m_ZoneForGraphMode; |
|
27 | 27 | |
|
28 | 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 | 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 | 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 | 47 | m_Model->removeEvent(event); |
|
48 |
t |
|
|
48 | treeView->setSortingEnabled(true); | |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | QStringList getAvailableVisualizationZoneList() const |
|
52 | 52 | { |
|
53 | 53 | if (m_VisualizationWidget) { |
|
54 | 54 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
55 | 55 | return tab->availableZoneWidgets(); |
|
56 | 56 | } |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | return QStringList{}; |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | QStringList selectZone(QWidget *parent, const QStringList &selectedZones, |
|
63 | 63 | bool allowMultiSelection, const QPoint &location) |
|
64 | 64 | { |
|
65 | 65 | auto availableZones = getAvailableVisualizationZoneList(); |
|
66 | 66 | if (availableZones.isEmpty()) { |
|
67 | 67 | return QStringList{}; |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | QDialog d(parent, Qt::Tool); |
|
71 | 71 | d.setWindowTitle("Choose a zone"); |
|
72 | 72 | auto layout = new QVBoxLayout{&d}; |
|
73 | 73 | layout->setContentsMargins(0, 0, 0, 0); |
|
74 | 74 | auto listWidget = new QListWidget{&d}; |
|
75 | 75 | layout->addWidget(listWidget); |
|
76 | 76 | |
|
77 | 77 | QSet<QListWidgetItem *> checkedItems; |
|
78 | 78 | for (auto zone : availableZones) { |
|
79 | 79 | auto item = new QListWidgetItem{zone}; |
|
80 | 80 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); |
|
81 | 81 | if (selectedZones.contains(zone)) { |
|
82 | 82 | item->setCheckState(Qt::Checked); |
|
83 | 83 | checkedItems << item; |
|
84 | 84 | } |
|
85 | 85 | else { |
|
86 | 86 | item->setCheckState(Qt::Unchecked); |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | listWidget->addItem(item); |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d}; |
|
93 | 93 | layout->addWidget(buttonBox); |
|
94 | 94 | |
|
95 | 95 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept); |
|
96 | 96 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject); |
|
97 | 97 | |
|
98 | 98 | QObject::connect(listWidget, &QListWidget::itemChanged, |
|
99 | 99 | [&checkedItems, allowMultiSelection, listWidget](auto item) { |
|
100 | 100 | if (item->checkState() == Qt::Checked) { |
|
101 | 101 | if (!allowMultiSelection) { |
|
102 | 102 | for (auto checkedItem : checkedItems) { |
|
103 | 103 | listWidget->blockSignals(true); |
|
104 | 104 | checkedItem->setCheckState(Qt::Unchecked); |
|
105 | 105 | listWidget->blockSignals(false); |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | checkedItems.clear(); |
|
109 | 109 | } |
|
110 | 110 | checkedItems << item; |
|
111 | 111 | } |
|
112 | 112 | else { |
|
113 | 113 | checkedItems.remove(item); |
|
114 | 114 | } |
|
115 | 115 | }); |
|
116 | 116 | |
|
117 | 117 | QStringList result; |
|
118 | 118 | |
|
119 | 119 | d.setMinimumWidth(120); |
|
120 | 120 | d.resize(d.minimumSizeHint()); |
|
121 | 121 | d.move(location); |
|
122 | 122 | if (d.exec() == QDialog::Accepted) { |
|
123 | 123 | for (auto item : checkedItems) { |
|
124 | 124 | result += item->text(); |
|
125 | 125 | } |
|
126 | 126 | } |
|
127 | 127 | else { |
|
128 | 128 | result = selectedZones; |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 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 | 138 | if (selectedRows.count() == 1) { |
|
139 | 139 | auto event = m_Model->getEvent(selectedRows.first().row()); |
|
140 | 140 | if (m_VisualizationWidget) { |
|
141 | 141 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
142 | 142 | |
|
143 | 143 | for (auto zoneName : m_ZonesForTimeMode) { |
|
144 | 144 | if (auto zone = tab->getZoneWithName(zoneName)) { |
|
145 | 145 | SqpRange eventRange; |
|
146 | eventRange.m_TStart = event->getTStart(); | |
|
147 | eventRange.m_TEnd = event->getTEnd(); | |
|
146 | // eventRange.m_TStart = event->getTStart(); | |
|
147 | // eventRange.m_TEnd = event->getTEnd(); | |
|
148 | 148 | zone->setZoneRange(eventRange); |
|
149 | 149 | } |
|
150 | 150 | } |
|
151 | 151 | } |
|
152 | 152 | else { |
|
153 | 153 | qCWarning(LOG_CatalogueEventsWidget()) |
|
154 | 154 | << "updateTimeZone: no tab found in the visualization"; |
|
155 | 155 | } |
|
156 | 156 | } |
|
157 | 157 | else { |
|
158 | 158 | qCWarning(LOG_CatalogueEventsWidget()) |
|
159 | 159 | << "updateTimeZone: visualization widget not found"; |
|
160 | 160 | } |
|
161 | 161 | } |
|
162 | 162 | else { |
|
163 | 163 | qCWarning(LOG_CatalogueEventsWidget()) |
|
164 | 164 | << "updateTimeZone: not compatible with multiple events selected"; |
|
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 | 172 | if (selectedRows.count() == 1) { |
|
173 | 173 | auto event = m_Model->getEvent(selectedRows.first().row()); |
|
174 | 174 | if (m_VisualizationWidget) { |
|
175 | 175 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
176 | 176 | if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { |
|
177 | 177 | // TODO |
|
178 | 178 | } |
|
179 | 179 | } |
|
180 | 180 | else { |
|
181 | 181 | qCWarning(LOG_CatalogueEventsWidget()) |
|
182 | 182 | << "updateGraphMode: no tab found in the visualization"; |
|
183 | 183 | } |
|
184 | 184 | } |
|
185 | 185 | else { |
|
186 | 186 | qCWarning(LOG_CatalogueEventsWidget()) |
|
187 | 187 | << "updateGraphMode: visualization widget not found"; |
|
188 | 188 | } |
|
189 | 189 | } |
|
190 | 190 | else { |
|
191 | 191 | qCWarning(LOG_CatalogueEventsWidget()) |
|
192 | 192 | << "updateGraphMode: not compatible with multiple events selected"; |
|
193 | 193 | } |
|
194 | 194 | } |
|
195 | 195 | }; |
|
196 | 196 | |
|
197 | 197 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) |
|
198 | 198 | : QWidget(parent), |
|
199 | 199 | ui(new Ui::CatalogueEventsWidget), |
|
200 | 200 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} |
|
201 | 201 | { |
|
202 | 202 | ui->setupUi(this); |
|
203 | 203 | |
|
204 |
impl->m_Model = new CatalogueEvents |
|
|
205 |
ui->t |
|
|
204 | impl->m_Model = new CatalogueEventsModel{this}; | |
|
205 | ui->treeView->setModel(impl->m_Model); | |
|
206 | 206 | |
|
207 |
ui->t |
|
|
208 |
ui->t |
|
|
209 |
ui->t |
|
|
207 | ui->treeView->setSortingEnabled(true); | |
|
208 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); | |
|
209 | ui->treeView->setDragEnabled(true); | |
|
210 | 210 | |
|
211 | 211 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { |
|
212 | 212 | if (checked) { |
|
213 | 213 | ui->btnChart->setChecked(false); |
|
214 | 214 | impl->m_ZonesForTimeMode |
|
215 | 215 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, |
|
216 | 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 | |
|
222 | 222 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { |
|
223 | 223 | if (checked) { |
|
224 | 224 | ui->btnTime->setChecked(false); |
|
225 | 225 | impl->m_ZoneForGraphMode |
|
226 | 226 | = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, |
|
227 | 227 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) |
|
228 | 228 | .value(0); |
|
229 | 229 | |
|
230 |
impl->updateForGraphMode(ui->t |
|
|
230 | impl->updateForGraphMode(ui->treeView); | |
|
231 | 231 | } |
|
232 | 232 | }); |
|
233 | 233 | |
|
234 | 234 | auto emitSelection = [this]() { |
|
235 | 235 | QVector<std::shared_ptr<DBEvent> > events; |
|
236 |
for (auto rowIndex : ui->t |
|
|
236 | for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) { | |
|
237 | 237 | events << impl->m_Model->getEvent(rowIndex.row()); |
|
238 | 238 | } |
|
239 | 239 | |
|
240 | 240 | emit this->eventsSelected(events); |
|
241 | 241 | }; |
|
242 | 242 | |
|
243 |
connect(ui->t |
|
|
244 |
connect(ui->t |
|
|
243 | connect(ui->treeView, &QTreeView::clicked, emitSelection); | |
|
244 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); | |
|
245 | 245 | |
|
246 |
connect(ui->t |
|
|
247 |
auto isNotMultiSelection = ui->t |
|
|
246 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { | |
|
247 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; | |
|
248 | 248 | ui->btnChart->setEnabled(isNotMultiSelection); |
|
249 | 249 | ui->btnTime->setEnabled(isNotMultiSelection); |
|
250 | 250 | |
|
251 | 251 | if (isNotMultiSelection && ui->btnTime->isChecked()) { |
|
252 |
impl->updateForTimeMode(ui->t |
|
|
252 | impl->updateForTimeMode(ui->treeView); | |
|
253 | 253 | } |
|
254 | 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 |
|
|
260 |
ui->t |
|
|
261 |
ui->t |
|
|
259 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
|
260 | ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); | |
|
261 | ui->treeView->header()->setSortIndicatorShown(true); | |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | CatalogueEventsWidget::~CatalogueEventsWidget() |
|
265 | 265 | { |
|
266 | 266 | delete ui; |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization) |
|
270 | 270 | { |
|
271 | 271 | impl->m_VisualizationWidget = visualization; |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges) |
|
275 | 275 | { |
|
276 | 276 | impl->m_Model->refreshEvent(event); |
|
277 | 277 | } |
|
278 | 278 | |
|
279 | 279 | void CatalogueEventsWidget::populateWithCatalogues( |
|
280 | 280 | const QVector<std::shared_ptr<DBCatalogue> > &catalogues) |
|
281 | 281 | { |
|
282 | 282 | QSet<QUuid> eventIds; |
|
283 | 283 | QVector<std::shared_ptr<DBEvent> > events; |
|
284 | 284 | |
|
285 | 285 | for (auto catalogue : catalogues) { |
|
286 | 286 | auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue); |
|
287 | 287 | for (auto event : catalogueEvents) { |
|
288 | 288 | if (!eventIds.contains(event->getUniqId())) { |
|
289 | 289 | events << event; |
|
290 | 290 | eventIds.insert(event->getUniqId()); |
|
291 | 291 | } |
|
292 | 292 | } |
|
293 | 293 | } |
|
294 | 294 | |
|
295 |
impl->setEvents(events, ui->t |
|
|
295 | impl->setEvents(events, ui->treeView); | |
|
296 | 296 | } |
@@ -1,146 +1,146 | |||
|
1 | 1 | #include "Catalogue/CatalogueInspectorWidget.h" |
|
2 | 2 | #include "ui_CatalogueInspectorWidget.h" |
|
3 | 3 | |
|
4 | 4 | #include <Common/DateUtils.h> |
|
5 | 5 | #include <DBCatalogue.h> |
|
6 | 6 | #include <DBEvent.h> |
|
7 | 7 | #include <DBTag.h> |
|
8 | 8 | |
|
9 | 9 | struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate { |
|
10 | 10 | std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr; |
|
11 | 11 | std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr; |
|
12 | 12 | |
|
13 | 13 | void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector, |
|
14 | 14 | Ui::CatalogueInspectorWidget *ui); |
|
15 | 15 | void connectEventUpdateSignals(CatalogueInspectorWidget *inspector, |
|
16 | 16 | Ui::CatalogueInspectorWidget *ui); |
|
17 | 17 | }; |
|
18 | 18 | |
|
19 | 19 | CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent) |
|
20 | 20 | : QWidget(parent), |
|
21 | 21 | ui(new Ui::CatalogueInspectorWidget), |
|
22 | 22 | impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()} |
|
23 | 23 | { |
|
24 | 24 | ui->setupUi(this); |
|
25 | 25 | showPage(Page::Empty); |
|
26 | 26 | |
|
27 | 27 | impl->connectCatalogueUpdateSignals(this, ui); |
|
28 | 28 | impl->connectEventUpdateSignals(this, ui); |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | CatalogueInspectorWidget::~CatalogueInspectorWidget() |
|
32 | 32 | { |
|
33 | 33 | delete ui; |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals( |
|
37 | 37 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) |
|
38 | 38 | { |
|
39 | 39 | connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
40 | 40 | if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) { |
|
41 | 41 | m_DisplayedCatalogue->setName(ui->leCatalogueName->text()); |
|
42 | 42 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); |
|
43 | 43 | } |
|
44 | 44 | }); |
|
45 | 45 | |
|
46 | 46 | connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
47 | 47 | if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) { |
|
48 | 48 | m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text()); |
|
49 | 49 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); |
|
50 | 50 | } |
|
51 | 51 | }); |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals( |
|
55 | 55 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) |
|
56 | 56 | { |
|
57 | 57 | connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
58 | 58 | if (ui->leEventName->text() != m_DisplayedEvent->getName()) { |
|
59 | 59 | m_DisplayedEvent->setName(ui->leEventName->text()); |
|
60 | 60 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
61 | 61 | } |
|
62 | 62 | }); |
|
63 | 63 | |
|
64 | 64 | connect(ui->leEventMission, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
65 | if (ui->leEventMission->text() != m_DisplayedEvent->getMission()) { | |
|
66 | m_DisplayedEvent->setMission(ui->leEventMission->text()); | |
|
67 | emit inspector->eventUpdated(m_DisplayedEvent); | |
|
68 | } | |
|
65 | // if (ui->leEventMission->text() != m_DisplayedEvent->getMission()) { | |
|
66 | // m_DisplayedEvent->setMission(ui->leEventMission->text()); | |
|
67 | // emit inspector->eventUpdated(m_DisplayedEvent); | |
|
68 | // } | |
|
69 | 69 | }); |
|
70 | 70 | |
|
71 | 71 | connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
72 | if (ui->leEventProduct->text() != m_DisplayedEvent->getProduct()) { | |
|
73 | m_DisplayedEvent->setProduct(ui->leEventProduct->text()); | |
|
74 | emit inspector->eventUpdated(m_DisplayedEvent); | |
|
75 | } | |
|
72 | // if (ui->leEventProduct->text() != m_DisplayedEvent->getProduct()) { | |
|
73 | // m_DisplayedEvent->setProduct(ui->leEventProduct->text()); | |
|
74 | // emit inspector->eventUpdated(m_DisplayedEvent); | |
|
75 | // } | |
|
76 | 76 | }); |
|
77 | 77 | |
|
78 | 78 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
79 | 79 | // TODO |
|
80 | 80 | }); |
|
81 | 81 | |
|
82 | 82 | connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
83 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); | |
|
84 | if (time != m_DisplayedEvent->getTStart()) { | |
|
85 | m_DisplayedEvent->setTStart(time); | |
|
86 | emit inspector->eventUpdated(m_DisplayedEvent); | |
|
87 | } | |
|
83 | // auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); | |
|
84 | // if (time != m_DisplayedEvent->getTStart()) { | |
|
85 | // m_DisplayedEvent->setTStart(time); | |
|
86 | // emit inspector->eventUpdated(m_DisplayedEvent); | |
|
87 | // } | |
|
88 | 88 | }); |
|
89 | 89 | |
|
90 | 90 | connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
91 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); | |
|
92 | if (time != m_DisplayedEvent->getTEnd()) { | |
|
93 | m_DisplayedEvent->setTEnd(time); | |
|
94 | emit inspector->eventUpdated(m_DisplayedEvent); | |
|
95 | } | |
|
91 | // auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); | |
|
92 | // if (time != m_DisplayedEvent->getTEnd()) { | |
|
93 | // m_DisplayedEvent->setTEnd(time); | |
|
94 | // emit inspector->eventUpdated(m_DisplayedEvent); | |
|
95 | // } | |
|
96 | 96 | }); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page) |
|
100 | 100 | { |
|
101 | 101 | ui->stackedWidget->setCurrentIndex(static_cast<int>(page)); |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const |
|
105 | 105 | { |
|
106 | 106 | return static_cast<Page>(ui->stackedWidget->currentIndex()); |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) |
|
110 | 110 | { |
|
111 | 111 | impl->m_DisplayedEvent = event; |
|
112 | 112 | |
|
113 | 113 | blockSignals(true); |
|
114 | 114 | |
|
115 | 115 | showPage(Page::EventProperties); |
|
116 | 116 | ui->leEventName->setText(event->getName()); |
|
117 | ui->leEventMission->setText(event->getMission()); | |
|
118 | ui->leEventProduct->setText(event->getProduct()); | |
|
117 | // ui->leEventMission->setText(event->getMission()); | |
|
118 | // ui->leEventProduct->setText(event->getProduct()); | |
|
119 | 119 | |
|
120 | 120 | QString tagList; |
|
121 | 121 | auto tags = event->getTags(); |
|
122 | 122 | for (auto tag : tags) { |
|
123 | 123 | tagList += tag.getName(); |
|
124 | 124 | tagList += ' '; |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | ui->leEventTags->setText(tagList); |
|
128 | 128 | |
|
129 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); | |
|
130 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); | |
|
129 | // ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); | |
|
130 | // ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); | |
|
131 | 131 | |
|
132 | 132 | blockSignals(false); |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue) |
|
136 | 136 | { |
|
137 | 137 | impl->m_DisplayedCatalogue = catalogue; |
|
138 | 138 | |
|
139 | 139 | blockSignals(true); |
|
140 | 140 | |
|
141 | 141 | showPage(Page::CatalogueProperties); |
|
142 | 142 | ui->leCatalogueName->setText(catalogue->getName()); |
|
143 | 143 | ui->leCatalogueAuthor->setText(catalogue->getAuthor()); |
|
144 | 144 | |
|
145 | 145 | blockSignals(false); |
|
146 | 146 | } |
@@ -1,154 +1,139 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>CatalogueEventsWidget</class> |
|
4 | 4 | <widget class="QWidget" name="CatalogueEventsWidget"> |
|
5 | 5 | <property name="geometry"> |
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 | 9 | <width>566</width> |
|
10 | 10 | <height>258</height> |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="windowTitle"> |
|
14 | 14 | <string>Form</string> |
|
15 | 15 | </property> |
|
16 | 16 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
17 | 17 | <property name="leftMargin"> |
|
18 | 18 | <number>0</number> |
|
19 | 19 | </property> |
|
20 | 20 | <property name="topMargin"> |
|
21 | 21 | <number>0</number> |
|
22 | 22 | </property> |
|
23 | 23 | <property name="rightMargin"> |
|
24 | 24 | <number>0</number> |
|
25 | 25 | </property> |
|
26 | 26 | <property name="bottomMargin"> |
|
27 | 27 | <number>0</number> |
|
28 | 28 | </property> |
|
29 | 29 | <item> |
|
30 | 30 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
31 | 31 | <item> |
|
32 | 32 | <widget class="QToolButton" name="btnAdd"> |
|
33 | 33 | <property name="text"> |
|
34 | 34 | <string>+</string> |
|
35 | 35 | </property> |
|
36 | 36 | <property name="icon"> |
|
37 | 37 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
38 | 38 | <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset> |
|
39 | 39 | </property> |
|
40 | 40 | <property name="autoRaise"> |
|
41 | 41 | <bool>true</bool> |
|
42 | 42 | </property> |
|
43 | 43 | </widget> |
|
44 | 44 | </item> |
|
45 | 45 | <item> |
|
46 | 46 | <widget class="QToolButton" name="btnRemove"> |
|
47 | 47 | <property name="text"> |
|
48 | 48 | <string> - </string> |
|
49 | 49 | </property> |
|
50 | 50 | <property name="icon"> |
|
51 | 51 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
52 | 52 | <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset> |
|
53 | 53 | </property> |
|
54 | 54 | <property name="autoRaise"> |
|
55 | 55 | <bool>true</bool> |
|
56 | 56 | </property> |
|
57 | 57 | </widget> |
|
58 | 58 | </item> |
|
59 | 59 | <item> |
|
60 | 60 | <widget class="Line" name="line"> |
|
61 | 61 | <property name="orientation"> |
|
62 | 62 | <enum>Qt::Vertical</enum> |
|
63 | 63 | </property> |
|
64 | 64 | </widget> |
|
65 | 65 | </item> |
|
66 | 66 | <item> |
|
67 | 67 | <widget class="QToolButton" name="btnTime"> |
|
68 | 68 | <property name="text"> |
|
69 | 69 | <string>T</string> |
|
70 | 70 | </property> |
|
71 | 71 | <property name="icon"> |
|
72 | 72 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
73 | 73 | <normaloff>:/icones/time.png</normaloff>:/icones/time.png</iconset> |
|
74 | 74 | </property> |
|
75 | 75 | <property name="checkable"> |
|
76 | 76 | <bool>true</bool> |
|
77 | 77 | </property> |
|
78 | 78 | <property name="autoRaise"> |
|
79 | 79 | <bool>true</bool> |
|
80 | 80 | </property> |
|
81 | 81 | </widget> |
|
82 | 82 | </item> |
|
83 | 83 | <item> |
|
84 | 84 | <widget class="QToolButton" name="btnChart"> |
|
85 | 85 | <property name="text"> |
|
86 | 86 | <string>G</string> |
|
87 | 87 | </property> |
|
88 | 88 | <property name="icon"> |
|
89 | 89 | <iconset resource="../../resources/sqpguiresources.qrc"> |
|
90 | 90 | <normaloff>:/icones/chart.png</normaloff>:/icones/chart.png</iconset> |
|
91 | 91 | </property> |
|
92 | 92 | <property name="checkable"> |
|
93 | 93 | <bool>true</bool> |
|
94 | 94 | </property> |
|
95 | 95 | <property name="autoRaise"> |
|
96 | 96 | <bool>true</bool> |
|
97 | 97 | </property> |
|
98 | 98 | </widget> |
|
99 | 99 | </item> |
|
100 | 100 | <item> |
|
101 | 101 | <widget class="Line" name="line_2"> |
|
102 | 102 | <property name="orientation"> |
|
103 | 103 | <enum>Qt::Vertical</enum> |
|
104 | 104 | </property> |
|
105 | 105 | </widget> |
|
106 | 106 | </item> |
|
107 | 107 | <item> |
|
108 | 108 | <widget class="QLineEdit" name="lineEdit"> |
|
109 | 109 | <property name="enabled"> |
|
110 | 110 | <bool>false</bool> |
|
111 | 111 | </property> |
|
112 | 112 | </widget> |
|
113 | 113 | </item> |
|
114 | 114 | </layout> |
|
115 | 115 | </item> |
|
116 | 116 | <item> |
|
117 |
<widget class="QT |
|
|
117 | <widget class="QTreeView" name="treeView"> | |
|
118 | 118 | <property name="dragEnabled"> |
|
119 | 119 | <bool>true</bool> |
|
120 | 120 | </property> |
|
121 | 121 | <property name="dragDropMode"> |
|
122 | 122 | <enum>QAbstractItemView::DragDrop</enum> |
|
123 | 123 | </property> |
|
124 | 124 | <property name="selectionBehavior"> |
|
125 | 125 | <enum>QAbstractItemView::SelectRows</enum> |
|
126 | 126 | </property> |
|
127 |
<attribute name="h |
|
|
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"> | |
|
127 | <attribute name="headerStretchLastSection"> | |
|
143 | 128 | <bool>false</bool> |
|
144 | 129 | </attribute> |
|
145 | 130 | </widget> |
|
146 | 131 | </item> |
|
147 | 132 | </layout> |
|
148 | 133 | </widget> |
|
149 | 134 | <resources> |
|
150 | 135 | <include location="../../resources/sqpguiresources.qrc"/> |
|
151 | 136 | <include location="../../resources/sqpguiresources.qrc"/> |
|
152 | 137 | </resources> |
|
153 | 138 | <connections/> |
|
154 | 139 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now