Auto status change to "Under Review"
@@ -1,154 +1,156 | |||
|
1 | 1 | #ifndef SCIQLOP_DATASOURCEITEM_H |
|
2 | 2 | #define SCIQLOP_DATASOURCEITEM_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Common/spimpl.h> |
|
7 | 7 | |
|
8 | 8 | #include <QVariant> |
|
9 | 9 | #include <QVector> |
|
10 | 10 | |
|
11 | 11 | class DataSourceItemAction; |
|
12 | 12 | |
|
13 | 13 | /** |
|
14 | 14 | * Possible types of an item |
|
15 | 15 | */ |
|
16 | 16 | enum class DataSourceItemType { NODE, PRODUCT, COMPONENT }; |
|
17 | 17 | |
|
18 | 18 | /** |
|
19 | 19 | * @brief The DataSourceItem class aims to represent a structure element of a data source. |
|
20 | 20 | * A data source has a tree structure that is made up of a main DataSourceItem object (root) |
|
21 | 21 | * containing other DataSourceItem objects (children). |
|
22 | 22 | * For each DataSourceItem can be associated a set of data representing it. |
|
23 | 23 | */ |
|
24 | 24 | class SCIQLOP_CORE_EXPORT DataSourceItem { |
|
25 | 25 | public: |
|
26 | 26 | /// Key associated with the name of the item |
|
27 | 27 | static const QString NAME_DATA_KEY; |
|
28 | 28 | /// Key associated with the plugin of the item |
|
29 | 29 | static const QString PLUGIN_DATA_KEY; |
|
30 | /// Key associated with a unique id of the plugin | |
|
31 | static const QString ID_DATA_KEY; | |
|
30 | 32 | |
|
31 | 33 | explicit DataSourceItem(DataSourceItemType type, const QString &name); |
|
32 | 34 | explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {}); |
|
33 | 35 | |
|
34 | 36 | std::unique_ptr<DataSourceItem> clone() const; |
|
35 | 37 | |
|
36 | 38 | /// @return the actions of the item as a vector |
|
37 | 39 | QVector<DataSourceItemAction *> actions() const noexcept; |
|
38 | 40 | |
|
39 | 41 | /** |
|
40 | 42 | * Adds an action to the item. The item takes ownership of the action, and the action is |
|
41 | 43 | * automatically associated to the item |
|
42 | 44 | * @param action the action to add |
|
43 | 45 | */ |
|
44 | 46 | void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept; |
|
45 | 47 | |
|
46 | 48 | /** |
|
47 | 49 | * Adds a child to the item. The item takes ownership of the child. |
|
48 | 50 | * @param child the child to add |
|
49 | 51 | */ |
|
50 | 52 | void appendChild(std::unique_ptr<DataSourceItem> child) noexcept; |
|
51 | 53 | |
|
52 | 54 | /** |
|
53 | 55 | * Returns the item's child associated to an index |
|
54 | 56 | * @param childIndex the index to search |
|
55 | 57 | * @return a pointer to the child if index is valid, nullptr otherwise |
|
56 | 58 | */ |
|
57 | 59 | DataSourceItem *child(int childIndex) const noexcept; |
|
58 | 60 | |
|
59 | 61 | int childCount() const noexcept; |
|
60 | 62 | |
|
61 | 63 | /** |
|
62 | 64 | * Get the data associated to a key |
|
63 | 65 | * @param key the key to search |
|
64 | 66 | * @return the data found if key is valid, default QVariant otherwise |
|
65 | 67 | */ |
|
66 | 68 | QVariant data(const QString &key) const noexcept; |
|
67 | 69 | |
|
68 | 70 | /// Gets all data |
|
69 | 71 | QVariantHash data() const noexcept; |
|
70 | 72 | |
|
71 | 73 | /** |
|
72 | 74 | * Merge in the item the source item passed as parameter. |
|
73 | 75 | * |
|
74 | 76 | * The merge is done by adding as child of the item the complete tree represented by the source |
|
75 | 77 | * item. If a part of the tree already exists in the item (based on the name of the nodes), it |
|
76 | 78 | * is merged by completing the existing tree by items "leaves" (products, components or nodes |
|
77 | 79 | * with no child). |
|
78 | 80 | * |
|
79 | 81 | * For example, with item representing the tree: |
|
80 | 82 | * R (root node) |
|
81 | 83 | * - N1 (node) |
|
82 | 84 | * -- N11 (node) |
|
83 | 85 | * --- P1 (product) |
|
84 | 86 | * --- P2 (product) |
|
85 | 87 | * - N2 (node) |
|
86 | 88 | * |
|
87 | 89 | * and the source item representing the tree: |
|
88 | 90 | * N1 (root node) |
|
89 | 91 | * - N11 (node) |
|
90 | 92 | * -- P3 (product) |
|
91 | 93 | * - N12 (node) |
|
92 | 94 | * |
|
93 | 95 | * The leaves of the source item to merge into the item are N1/N11/P3 and N1/N12 => we therefore |
|
94 | 96 | * have the following merge result: |
|
95 | 97 | * R |
|
96 | 98 | * - N1 |
|
97 | 99 | * -- N11 |
|
98 | 100 | * --- P1 |
|
99 | 101 | * --- P2 |
|
100 | 102 | * --- P3 (added leaf) |
|
101 | 103 | * -- N12 (added leaf) |
|
102 | 104 | * |
|
103 | 105 | * @param item the source item |
|
104 | 106 | * @remarks No control is performed on products or components that are merged into the same tree |
|
105 | 107 | * part (two products or components may have the same name) |
|
106 | 108 | * @remarks the merge is made by copy (source item is not changed and still exists after the |
|
107 | 109 | * operation) |
|
108 | 110 | */ |
|
109 | 111 | void merge(const DataSourceItem &item); |
|
110 | 112 | |
|
111 | 113 | bool isRoot() const noexcept; |
|
112 | 114 | |
|
113 | 115 | QString name() const noexcept; |
|
114 | 116 | |
|
115 | 117 | /** |
|
116 | 118 | * Get the item's parent |
|
117 | 119 | * @return a pointer to the parent if it exists, nullptr if the item is a root |
|
118 | 120 | */ |
|
119 | 121 | DataSourceItem *parentItem() const noexcept; |
|
120 | 122 | |
|
121 | 123 | /** |
|
122 | 124 | * Gets the item's root |
|
123 | 125 | * @return the top parent, the item itself if it's the root item |
|
124 | 126 | */ |
|
125 | 127 | const DataSourceItem &rootItem() const noexcept; |
|
126 | 128 | |
|
127 | 129 | /** |
|
128 | 130 | * Sets or appends a value to a key |
|
129 | 131 | * @param key the key |
|
130 | 132 | * @param value the value |
|
131 | 133 | * @param append if true, the value is added to the values already existing for the key, |
|
132 | 134 | * otherwise it replaces the existing values |
|
133 | 135 | */ |
|
134 | 136 | void setData(const QString &key, const QVariant &value, bool append = false) noexcept; |
|
135 | 137 | |
|
136 | 138 | DataSourceItemType type() const noexcept; |
|
137 | 139 | |
|
138 | 140 | /** |
|
139 | 141 | * @brief Searches the first child matching the specified data. |
|
140 | 142 | * @param data The data to search. |
|
141 | 143 | * @param recursive So the search recursively. |
|
142 | 144 | * @return the item matching the data or nullptr if it was not found. |
|
143 | 145 | */ |
|
144 | 146 | DataSourceItem *findItem(const QVariantHash &data, bool recursive); |
|
145 | 147 | |
|
146 | 148 | bool operator==(const DataSourceItem &other); |
|
147 | 149 | bool operator!=(const DataSourceItem &other); |
|
148 | 150 | |
|
149 | 151 | private: |
|
150 | 152 | class DataSourceItemPrivate; |
|
151 | 153 | spimpl::unique_impl_ptr<DataSourceItemPrivate> impl; |
|
152 | 154 | }; |
|
153 | 155 | |
|
154 | 156 | #endif // SCIQLOP_DATASOURCEITEMMODEL_H |
@@ -1,186 +1,187 | |||
|
1 | 1 | #include <DataSource/DataSourceItem.h> |
|
2 | 2 | #include <DataSource/DataSourceItemAction.h> |
|
3 | 3 | #include <DataSource/DataSourceItemMergeHelper.h> |
|
4 | 4 | |
|
5 | 5 | #include <QVector> |
|
6 | 6 | |
|
7 | 7 | const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name"); |
|
8 | 8 | const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin"); |
|
9 | const QString DataSourceItem::ID_DATA_KEY = QStringLiteral("uuid"); | |
|
9 | 10 | |
|
10 | 11 | struct DataSourceItem::DataSourceItemPrivate { |
|
11 | 12 | explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data) |
|
12 | 13 | : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{} |
|
13 | 14 | { |
|
14 | 15 | } |
|
15 | 16 | |
|
16 | 17 | DataSourceItem *m_Parent; |
|
17 | 18 | std::vector<std::unique_ptr<DataSourceItem> > m_Children; |
|
18 | 19 | DataSourceItemType m_Type; |
|
19 | 20 | QVariantHash m_Data; |
|
20 | 21 | std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions; |
|
21 | 22 | }; |
|
22 | 23 | |
|
23 | 24 | DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name) |
|
24 | 25 | : DataSourceItem{type, QVariantHash{{NAME_DATA_KEY, name}}} |
|
25 | 26 | { |
|
26 | 27 | } |
|
27 | 28 | |
|
28 | 29 | DataSourceItem::DataSourceItem(DataSourceItemType type, QVariantHash data) |
|
29 | 30 | : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))} |
|
30 | 31 | { |
|
31 | 32 | } |
|
32 | 33 | |
|
33 | 34 | std::unique_ptr<DataSourceItem> DataSourceItem::clone() const |
|
34 | 35 | { |
|
35 | 36 | auto result = std::make_unique<DataSourceItem>(impl->m_Type, impl->m_Data); |
|
36 | 37 | |
|
37 | 38 | // Clones children |
|
38 | 39 | for (const auto &child : impl->m_Children) { |
|
39 | 40 | result->appendChild(std::move(child->clone())); |
|
40 | 41 | } |
|
41 | 42 | |
|
42 | 43 | // Clones actions |
|
43 | 44 | for (const auto &action : impl->m_Actions) { |
|
44 | 45 | result->addAction(std::move(action->clone())); |
|
45 | 46 | } |
|
46 | 47 | |
|
47 | 48 | return result; |
|
48 | 49 | } |
|
49 | 50 | |
|
50 | 51 | QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept |
|
51 | 52 | { |
|
52 | 53 | auto result = QVector<DataSourceItemAction *>{}; |
|
53 | 54 | |
|
54 | 55 | std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions), |
|
55 | 56 | std::back_inserter(result), [](const auto &action) { return action.get(); }); |
|
56 | 57 | |
|
57 | 58 | return result; |
|
58 | 59 | } |
|
59 | 60 | |
|
60 | 61 | void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept |
|
61 | 62 | { |
|
62 | 63 | action->setDataSourceItem(this); |
|
63 | 64 | impl->m_Actions.push_back(std::move(action)); |
|
64 | 65 | } |
|
65 | 66 | |
|
66 | 67 | void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept |
|
67 | 68 | { |
|
68 | 69 | child->impl->m_Parent = this; |
|
69 | 70 | impl->m_Children.push_back(std::move(child)); |
|
70 | 71 | } |
|
71 | 72 | |
|
72 | 73 | DataSourceItem *DataSourceItem::child(int childIndex) const noexcept |
|
73 | 74 | { |
|
74 | 75 | if (childIndex < 0 || childIndex >= childCount()) { |
|
75 | 76 | return nullptr; |
|
76 | 77 | } |
|
77 | 78 | else { |
|
78 | 79 | return impl->m_Children.at(childIndex).get(); |
|
79 | 80 | } |
|
80 | 81 | } |
|
81 | 82 | |
|
82 | 83 | int DataSourceItem::childCount() const noexcept |
|
83 | 84 | { |
|
84 | 85 | return impl->m_Children.size(); |
|
85 | 86 | } |
|
86 | 87 | |
|
87 | 88 | QVariant DataSourceItem::data(const QString &key) const noexcept |
|
88 | 89 | { |
|
89 | 90 | return impl->m_Data.value(key); |
|
90 | 91 | } |
|
91 | 92 | |
|
92 | 93 | QVariantHash DataSourceItem::data() const noexcept |
|
93 | 94 | { |
|
94 | 95 | return impl->m_Data; |
|
95 | 96 | } |
|
96 | 97 | |
|
97 | 98 | void DataSourceItem::merge(const DataSourceItem &item) |
|
98 | 99 | { |
|
99 | 100 | DataSourceItemMergeHelper::merge(item, *this); |
|
100 | 101 | } |
|
101 | 102 | |
|
102 | 103 | bool DataSourceItem::isRoot() const noexcept |
|
103 | 104 | { |
|
104 | 105 | return impl->m_Parent == nullptr; |
|
105 | 106 | } |
|
106 | 107 | |
|
107 | 108 | QString DataSourceItem::name() const noexcept |
|
108 | 109 | { |
|
109 | 110 | return data(NAME_DATA_KEY).toString(); |
|
110 | 111 | } |
|
111 | 112 | |
|
112 | 113 | DataSourceItem *DataSourceItem::parentItem() const noexcept |
|
113 | 114 | { |
|
114 | 115 | return impl->m_Parent; |
|
115 | 116 | } |
|
116 | 117 | |
|
117 | 118 | const DataSourceItem &DataSourceItem::rootItem() const noexcept |
|
118 | 119 | { |
|
119 | 120 | return isRoot() ? *this : parentItem()->rootItem(); |
|
120 | 121 | } |
|
121 | 122 | |
|
122 | 123 | void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept |
|
123 | 124 | { |
|
124 | 125 | auto it = impl->m_Data.constFind(key); |
|
125 | 126 | if (append && it != impl->m_Data.constEnd()) { |
|
126 | 127 | // Case of an existing value to which we want to add to the new value |
|
127 | 128 | if (it->canConvert<QVariantList>()) { |
|
128 | 129 | auto variantList = it->value<QVariantList>(); |
|
129 | 130 | variantList.append(value); |
|
130 | 131 | |
|
131 | 132 | impl->m_Data.insert(key, variantList); |
|
132 | 133 | } |
|
133 | 134 | else { |
|
134 | 135 | impl->m_Data.insert(key, QVariantList{*it, value}); |
|
135 | 136 | } |
|
136 | 137 | } |
|
137 | 138 | else { |
|
138 | 139 | // Other cases : |
|
139 | 140 | // - new value in map OR |
|
140 | 141 | // - replacement of an existing value (not appending) |
|
141 | 142 | impl->m_Data.insert(key, value); |
|
142 | 143 | } |
|
143 | 144 | } |
|
144 | 145 | |
|
145 | 146 | DataSourceItemType DataSourceItem::type() const noexcept |
|
146 | 147 | { |
|
147 | 148 | return impl->m_Type; |
|
148 | 149 | } |
|
149 | 150 | |
|
150 | 151 | DataSourceItem *DataSourceItem::findItem(const QVariantHash &data, bool recursive) |
|
151 | 152 | { |
|
152 | 153 | for (const auto &child : impl->m_Children) { |
|
153 | 154 | if (child->impl->m_Data == data) { |
|
154 | 155 | return child.get(); |
|
155 | 156 | } |
|
156 | 157 | |
|
157 | 158 | if (recursive) { |
|
158 | 159 | if (auto foundItem = child->findItem(data, true)) { |
|
159 | 160 | return foundItem; |
|
160 | 161 | } |
|
161 | 162 | } |
|
162 | 163 | } |
|
163 | 164 | |
|
164 | 165 | return nullptr; |
|
165 | 166 | } |
|
166 | 167 | |
|
167 | 168 | bool DataSourceItem::operator==(const DataSourceItem &other) |
|
168 | 169 | { |
|
169 | 170 | // Compares items' attributes |
|
170 | 171 | if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) { |
|
171 | 172 | // Compares contents of items' children |
|
172 | 173 | return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children), |
|
173 | 174 | std::cbegin(other.impl->m_Children), std::cend(other.impl->m_Children), |
|
174 | 175 | [](const auto &itemChild, const auto &otherChild) { |
|
175 | 176 | return *itemChild == *otherChild; |
|
176 | 177 | }); |
|
177 | 178 | } |
|
178 | 179 | else { |
|
179 | 180 | return false; |
|
180 | 181 | } |
|
181 | 182 | } |
|
182 | 183 | |
|
183 | 184 | bool DataSourceItem::operator!=(const DataSourceItem &other) |
|
184 | 185 | { |
|
185 | 186 | return !(*this == other); |
|
186 | 187 | } |
@@ -1,133 +1,135 | |||
|
1 | 1 | #include "Catalogue/CatalogueActionManager.h" |
|
2 | 2 | |
|
3 | 3 | #include <Actions/ActionsGuiController.h> |
|
4 | 4 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <DataSource/DataSourceItem.h> | |
|
5 | 6 | #include <SqpApplication.h> |
|
6 | 7 | #include <Variable/Variable.h> |
|
7 | 8 | #include <Visualization/VisualizationGraphWidget.h> |
|
8 | 9 | #include <Visualization/VisualizationSelectionZoneItem.h> |
|
9 | 10 | |
|
10 | 11 | #include <Catalogue/CatalogueEventsWidget.h> |
|
11 | 12 | #include <Catalogue/CatalogueExplorer.h> |
|
12 | 13 | #include <Catalogue/CatalogueSideBarWidget.h> |
|
13 | 14 | #include <Catalogue/CreateEventDialog.h> |
|
14 | 15 | |
|
15 | 16 | #include <DBCatalogue.h> |
|
16 | 17 | #include <DBEvent.h> |
|
17 | 18 | #include <DBEventProduct.h> |
|
18 | 19 | |
|
19 | 20 | #include <QBoxLayout> |
|
20 | 21 | #include <QComboBox> |
|
21 | 22 | #include <QDialog> |
|
22 | 23 | #include <QDialogButtonBox> |
|
23 | 24 | #include <QLineEdit> |
|
24 | 25 | #include <memory> |
|
25 | 26 | |
|
26 | 27 | struct CatalogueActionManager::CatalogueActionManagerPrivate { |
|
27 | 28 | |
|
28 | 29 | CatalogueExplorer *m_CatalogueExplorer = nullptr; |
|
29 | 30 | |
|
30 | 31 | CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer) |
|
31 | 32 | : m_CatalogueExplorer(catalogueExplorer) |
|
32 | 33 | { |
|
33 | 34 | } |
|
34 | 35 | |
|
35 | 36 | void createEventFromZones(const QString &eventName, |
|
36 | 37 | const QVector<VisualizationSelectionZoneItem *> &zones, |
|
37 | 38 | const std::shared_ptr<DBCatalogue> &catalogue = nullptr) |
|
38 | 39 | { |
|
39 | 40 | auto event = std::make_shared<DBEvent>(); |
|
40 | 41 | event->setName(eventName); |
|
41 | 42 | |
|
42 | 43 | std::list<DBEventProduct> productList; |
|
43 | 44 | for (auto zone : zones) { |
|
44 | 45 | auto graph = zone->parentGraphWidget(); |
|
45 | 46 | for (auto var : graph->variables()) { |
|
46 | 47 | auto eventProduct = std::make_shared<DBEventProduct>(); |
|
47 | 48 | eventProduct->setEvent(*event); |
|
48 | 49 | |
|
49 | 50 | auto zoneRange = zone->range(); |
|
50 | 51 | eventProduct->setTStart(zoneRange.m_TStart); |
|
51 | 52 | eventProduct->setTEnd(zoneRange.m_TEnd); |
|
52 | 53 | |
|
53 |
eventProduct->setProductId( |
|
|
54 | eventProduct->setProductId( | |
|
55 | var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString()); | |
|
54 | 56 | |
|
55 | 57 | productList.push_back(*eventProduct); |
|
56 | 58 | } |
|
57 | 59 | } |
|
58 | 60 | |
|
59 | 61 | event->setEventProducts(productList); |
|
60 | 62 | |
|
61 | 63 | sqpApp->catalogueController().addEvent(event); |
|
62 | 64 | |
|
63 | 65 | |
|
64 | 66 | if (catalogue) { |
|
65 | 67 | // TODO |
|
66 | 68 | // catalogue->addEvent(event); |
|
67 | 69 | m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true); |
|
68 | 70 | if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) { |
|
69 | 71 | m_CatalogueExplorer->eventsWidget().addEvent(event); |
|
70 | 72 | m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); |
|
71 | 73 | } |
|
72 | 74 | } |
|
73 | 75 | else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) { |
|
74 | 76 | m_CatalogueExplorer->eventsWidget().addEvent(event); |
|
75 | 77 | m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); |
|
76 | 78 | } |
|
77 | 79 | } |
|
78 | 80 | }; |
|
79 | 81 | |
|
80 | 82 | CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer) |
|
81 | 83 | : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)} |
|
82 | 84 | { |
|
83 | 85 | } |
|
84 | 86 | |
|
85 | 87 | void CatalogueActionManager::installSelectionZoneActions() |
|
86 | 88 | { |
|
87 | 89 | auto &actionController = sqpApp->actionsGuiController(); |
|
88 | 90 | |
|
89 | 91 | auto createEventEnableFuntion = [](auto zones) { |
|
90 | 92 | QSet<VisualizationGraphWidget *> usedGraphs; |
|
91 | 93 | for (auto zone : zones) { |
|
92 | 94 | auto graph = zone->parentGraphWidget(); |
|
93 | 95 | if (!usedGraphs.contains(graph)) { |
|
94 | 96 | usedGraphs.insert(graph); |
|
95 | 97 | } |
|
96 | 98 | else { |
|
97 | 99 | return false; |
|
98 | 100 | } |
|
99 | 101 | } |
|
100 | 102 | |
|
101 | 103 | return true; |
|
102 | 104 | }; |
|
103 | 105 | |
|
104 | 106 | auto createEventAction = actionController.addSectionZoneAction( |
|
105 | 107 | {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) { |
|
106 | 108 | CreateEventDialog dialog( |
|
107 | 109 | impl->m_CatalogueExplorer->sideBarWidget().getCatalogues("Default")); |
|
108 | 110 | dialog.hideCatalogueChoice(); |
|
109 | 111 | if (dialog.exec() == QDialog::Accepted) { |
|
110 | 112 | impl->createEventFromZones(dialog.eventName(), zones); |
|
111 | 113 | } |
|
112 | 114 | }); |
|
113 | 115 | createEventAction->setEnableFunction(createEventEnableFuntion); |
|
114 | 116 | |
|
115 | 117 | auto createEventInCatalogueAction = actionController.addSectionZoneAction( |
|
116 | 118 | {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) { |
|
117 | 119 | CreateEventDialog dialog( |
|
118 | 120 | impl->m_CatalogueExplorer->sideBarWidget().getCatalogues("Default")); |
|
119 | 121 | if (dialog.exec() == QDialog::Accepted) { |
|
120 | 122 | auto selectedCatalogue = dialog.selectedCatalogue(); |
|
121 | 123 | if (!selectedCatalogue) { |
|
122 | 124 | selectedCatalogue = std::make_shared<DBCatalogue>(); |
|
123 | 125 | selectedCatalogue->setName(dialog.catalogueName()); |
|
124 | 126 | // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO |
|
125 | 127 | impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue, |
|
126 | 128 | "Default"); |
|
127 | 129 | } |
|
128 | 130 | |
|
129 | 131 | impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue); |
|
130 | 132 | } |
|
131 | 133 | }); |
|
132 | 134 | createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion); |
|
133 | 135 | } |
@@ -1,78 +1,79 | |||
|
1 | 1 | #include "AmdaPlugin.h" |
|
2 | 2 | #include "AmdaDefs.h" |
|
3 | 3 | #include "AmdaParser.h" |
|
4 | 4 | #include "AmdaProvider.h" |
|
5 | 5 | #include "AmdaServer.h" |
|
6 | 6 | |
|
7 | 7 | #include <DataSource/DataSourceController.h> |
|
8 | 8 | #include <DataSource/DataSourceItem.h> |
|
9 | 9 | #include <DataSource/DataSourceItemAction.h> |
|
10 | 10 | |
|
11 | 11 | #include <SqpApplication.h> |
|
12 | 12 | |
|
13 | 13 | Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin") |
|
14 | 14 | |
|
15 | 15 | namespace { |
|
16 | 16 | |
|
17 | 17 | /// Path of the file used to generate the data source item for AMDA |
|
18 | 18 | const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSampleV3.json"); |
|
19 | 19 | |
|
20 | 20 | void associateActions(DataSourceItem &item, const QUuid &dataSourceUid) |
|
21 | 21 | { |
|
22 | 22 | auto addLoadAction = [&item, dataSourceUid](const QString &label) { |
|
23 | 23 | item.addAction( |
|
24 | 24 | std::make_unique<DataSourceItemAction>(label, [dataSourceUid](DataSourceItem &item) { |
|
25 | 25 | if (auto app = sqpApp) { |
|
26 | 26 | app->dataSourceController().loadProductItem(dataSourceUid, item); |
|
27 | 27 | } |
|
28 | 28 | })); |
|
29 | 29 | }; |
|
30 | 30 | |
|
31 | 31 | const auto itemType = item.type(); |
|
32 | 32 | if (itemType == DataSourceItemType::PRODUCT || itemType == DataSourceItemType::COMPONENT) { |
|
33 | 33 | // Adds plugin name to item metadata |
|
34 | 34 | item.setData(DataSourceItem::PLUGIN_DATA_KEY, AmdaServer::instance().name()); |
|
35 | 35 | |
|
36 | 36 | // Adds load action |
|
37 | 37 | auto actionLabel = QObject::tr( |
|
38 | 38 | itemType == DataSourceItemType::PRODUCT ? "Load %1 product" : "Load %1 component"); |
|
39 | 39 | addLoadAction(actionLabel.arg(item.name())); |
|
40 | item.setData(DataSourceItem::ID_DATA_KEY, item.data(AMDA_XML_ID_KEY)); | |
|
40 | 41 | } |
|
41 | 42 | |
|
42 | 43 | auto count = item.childCount(); |
|
43 | 44 | for (auto i = 0; i < count; ++i) { |
|
44 | 45 | if (auto child = item.child(i)) { |
|
45 | 46 | associateActions(*child, dataSourceUid); |
|
46 | 47 | } |
|
47 | 48 | } |
|
48 | 49 | } |
|
49 | 50 | |
|
50 | 51 | } // namespace |
|
51 | 52 | |
|
52 | 53 | void AmdaPlugin::initialize() |
|
53 | 54 | { |
|
54 | 55 | if (auto app = sqpApp) { |
|
55 | 56 | auto dataSourceName = AmdaServer::instance().name(); |
|
56 | 57 | |
|
57 | 58 | // Registers to the data source controller |
|
58 | 59 | auto &dataSourceController = app->dataSourceController(); |
|
59 | 60 | auto dataSourceUid = dataSourceController.registerDataSource(dataSourceName); |
|
60 | 61 | |
|
61 | 62 | // Sets data source tree |
|
62 | 63 | if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { |
|
63 | 64 | dataSourceItem->setData(DataSourceItem::NAME_DATA_KEY, dataSourceName); |
|
64 | 65 | |
|
65 | 66 | associateActions(*dataSourceItem, dataSourceUid); |
|
66 | 67 | dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); |
|
67 | 68 | } |
|
68 | 69 | else { |
|
69 | 70 | qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA"); |
|
70 | 71 | } |
|
71 | 72 | |
|
72 | 73 | // Sets data provider |
|
73 | 74 | dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>()); |
|
74 | 75 | } |
|
75 | 76 | else { |
|
76 | 77 | qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application"); |
|
77 | 78 | } |
|
78 | 79 | } |
@@ -1,118 +1,119 | |||
|
1 | 1 | #include "MockPlugin.h" |
|
2 | 2 | #include "CosinusProvider.h" |
|
3 | 3 | #include "MockDefs.h" |
|
4 | 4 | |
|
5 | 5 | #include <DataSource/DataSourceController.h> |
|
6 | 6 | #include <DataSource/DataSourceItem.h> |
|
7 | 7 | #include <DataSource/DataSourceItemAction.h> |
|
8 | 8 | |
|
9 | 9 | #include <SqpApplication.h> |
|
10 | 10 | |
|
11 | 11 | Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin") |
|
12 | 12 | |
|
13 | 13 | namespace { |
|
14 | 14 | |
|
15 | 15 | /// Name of the data source |
|
16 | 16 | const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); |
|
17 | 17 | |
|
18 | 18 | /// Creates the data provider relative to the plugin |
|
19 | 19 | std::unique_ptr<IDataProvider> createDataProvider() noexcept |
|
20 | 20 | { |
|
21 | 21 | return std::make_unique<CosinusProvider>(); |
|
22 | 22 | } |
|
23 | 23 | |
|
24 | 24 | std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data, |
|
25 | 25 | const QUuid &dataSourceUid) |
|
26 | 26 | { |
|
27 | 27 | auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data); |
|
28 | 28 | |
|
29 | 29 | // Adds plugin name to product metadata |
|
30 | 30 | result->setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME); |
|
31 | result->setData(DataSourceItem::ID_DATA_KEY, data.value(DataSourceItem::NAME_DATA_KEY)); | |
|
31 | 32 | |
|
32 | 33 | auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString(); |
|
33 | 34 | |
|
34 | 35 | // Add action to load product from DataSourceController |
|
35 | 36 | result->addAction(std::make_unique<DataSourceItemAction>( |
|
36 | 37 | QObject::tr("Load %1 product").arg(productName), |
|
37 | 38 | [productName, dataSourceUid](DataSourceItem &item) { |
|
38 | 39 | if (auto app = sqpApp) { |
|
39 | 40 | app->dataSourceController().loadProductItem(dataSourceUid, item); |
|
40 | 41 | } |
|
41 | 42 | })); |
|
42 | 43 | |
|
43 | 44 | return result; |
|
44 | 45 | } |
|
45 | 46 | |
|
46 | 47 | /// Creates the data source item relative to the plugin |
|
47 | 48 | std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept |
|
48 | 49 | { |
|
49 | 50 | // Magnetic field products |
|
50 | 51 | auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, |
|
51 | 52 | QStringLiteral("_Magnetic field")); |
|
52 | 53 | magneticFieldFolder->appendChild( |
|
53 | 54 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 10 Hz")}, |
|
54 | 55 | {COSINUS_TYPE_KEY, "scalar"}, |
|
55 | 56 | {COSINUS_FREQUENCY_KEY, 10.}}, |
|
56 | 57 | dataSourceUid)); |
|
57 | 58 | magneticFieldFolder->appendChild( |
|
58 | 59 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 60 Hz")}, |
|
59 | 60 | {COSINUS_TYPE_KEY, "scalar"}, |
|
60 | 61 | {COSINUS_FREQUENCY_KEY, 60.}}, |
|
61 | 62 | dataSourceUid)); |
|
62 | 63 | magneticFieldFolder->appendChild( |
|
63 | 64 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 100 Hz")}, |
|
64 | 65 | {COSINUS_TYPE_KEY, "scalar"}, |
|
65 | 66 | {COSINUS_FREQUENCY_KEY, 100.}}, |
|
66 | 67 | dataSourceUid)); |
|
67 | 68 | magneticFieldFolder->appendChild( |
|
68 | 69 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 10 Hz")}, |
|
69 | 70 | {COSINUS_TYPE_KEY, "vector"}, |
|
70 | 71 | {COSINUS_FREQUENCY_KEY, 10.}}, |
|
71 | 72 | dataSourceUid)); |
|
72 | 73 | magneticFieldFolder->appendChild( |
|
73 | 74 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 60 Hz")}, |
|
74 | 75 | {COSINUS_TYPE_KEY, "vector"}, |
|
75 | 76 | {COSINUS_FREQUENCY_KEY, 60.}}, |
|
76 | 77 | dataSourceUid)); |
|
77 | 78 | magneticFieldFolder->appendChild( |
|
78 | 79 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 100 Hz")}, |
|
79 | 80 | {COSINUS_TYPE_KEY, "vector"}, |
|
80 | 81 | {COSINUS_FREQUENCY_KEY, 100.}}, |
|
81 | 82 | dataSourceUid)); |
|
82 | 83 | magneticFieldFolder->appendChild( |
|
83 | 84 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Spectrogram 1 Hz")}, |
|
84 | 85 | {COSINUS_TYPE_KEY, "spectrogram"}, |
|
85 | 86 | {COSINUS_FREQUENCY_KEY, 1.}}, |
|
86 | 87 | dataSourceUid)); |
|
87 | 88 | |
|
88 | 89 | // Electric field products |
|
89 | 90 | auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, |
|
90 | 91 | QStringLiteral("_Electric field")); |
|
91 | 92 | |
|
92 | 93 | // Root |
|
93 | 94 | auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME); |
|
94 | 95 | root->appendChild(std::move(magneticFieldFolder)); |
|
95 | 96 | root->appendChild(std::move(electricFieldFolder)); |
|
96 | 97 | |
|
97 | 98 | return root; |
|
98 | 99 | } |
|
99 | 100 | |
|
100 | 101 | } // namespace |
|
101 | 102 | |
|
102 | 103 | void MockPlugin::initialize() |
|
103 | 104 | { |
|
104 | 105 | if (auto app = sqpApp) { |
|
105 | 106 | // Registers to the data source controller |
|
106 | 107 | auto &dataSourceController = app->dataSourceController(); |
|
107 | 108 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); |
|
108 | 109 | |
|
109 | 110 | // Sets data source tree |
|
110 | 111 | dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid)); |
|
111 | 112 | |
|
112 | 113 | // Sets data provider |
|
113 | 114 | dataSourceController.setDataProvider(dataSourceUid, createDataProvider()); |
|
114 | 115 | } |
|
115 | 116 | else { |
|
116 | 117 | qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); |
|
117 | 118 | } |
|
118 | 119 | } |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now