@@ -75,6 +75,10 public slots: | |||||
75 | void initialize(); |
|
75 | void initialize(); | |
76 | void finalize(); |
|
76 | void finalize(); | |
77 |
|
77 | |||
|
78 | /// Request the creation of a variable from the ID_DATA_KEY of a product | |||
|
79 | void requestVariable(const QString &datasourceIdKey); | |||
|
80 | ||||
|
81 | /// Request the creation of a variable from metadata of a product | |||
78 | void requestVariable(const QVariantHash &productData); |
|
82 | void requestVariable(const QVariantHash &productData); | |
79 |
|
83 | |||
80 | signals: |
|
84 | signals: |
@@ -145,6 +145,14 public: | |||||
145 | */ |
|
145 | */ | |
146 | DataSourceItem *findItem(const QVariantHash &data, bool recursive); |
|
146 | DataSourceItem *findItem(const QVariantHash &data, bool recursive); | |
147 |
|
147 | |||
|
148 | /** | |||
|
149 | * @brief Searches the first child matching the specified \p ID_DATA_KEY in its metadata. | |||
|
150 | * @param id The id to search. | |||
|
151 | * @param recursive So the search recursively. | |||
|
152 | * @return the item matching the data or nullptr if it was not found. | |||
|
153 | */ | |||
|
154 | DataSourceItem *findItem(const QString &datasourceIdKey, bool recursive); | |||
|
155 | ||||
148 | bool operator==(const DataSourceItem &other); |
|
156 | bool operator==(const DataSourceItem &other); | |
149 | bool operator!=(const DataSourceItem &other); |
|
157 | bool operator!=(const DataSourceItem &other); | |
150 |
|
158 |
@@ -37,6 +37,20 public: | |||||
37 |
|
37 | |||
38 | return sourceItem; |
|
38 | return sourceItem; | |
39 | } |
|
39 | } | |
|
40 | ||||
|
41 | // Search for the first datasource item matching the specified ID_DATA_KEY | |||
|
42 | DataSourceItem *findDataSourceItem(const QString &datasourceIdKey) | |||
|
43 | { | |||
|
44 | DataSourceItem *sourceItem = nullptr; | |||
|
45 | for (const auto &item : m_DataSourceItems) { | |||
|
46 | sourceItem = item.second->findItem(datasourceIdKey, true); | |||
|
47 | if (sourceItem) { | |||
|
48 | break; | |||
|
49 | } | |||
|
50 | } | |||
|
51 | ||||
|
52 | return sourceItem; | |||
|
53 | } | |||
40 | }; |
|
54 | }; | |
41 |
|
55 | |||
42 | DataSourceController::DataSourceController(QObject *parent) |
|
56 | DataSourceController::DataSourceController(QObject *parent) | |
@@ -149,6 +163,20 void DataSourceController::finalize() | |||||
149 | impl->m_WorkingMutex.unlock(); |
|
163 | impl->m_WorkingMutex.unlock(); | |
150 | } |
|
164 | } | |
151 |
|
165 | |||
|
166 | void DataSourceController::requestVariable(const QString &datasourceIdKey) | |||
|
167 | { | |||
|
168 | auto sourceItem = impl->findDataSourceItem(datasourceIdKey); | |||
|
169 | ||||
|
170 | if (sourceItem) { | |||
|
171 | auto sourceName = sourceItem->rootItem().name(); | |||
|
172 | auto sourceId = impl->m_DataSources.key(sourceName); | |||
|
173 | loadProductItem(sourceId, *sourceItem); | |||
|
174 | } | |||
|
175 | else { | |||
|
176 | qCWarning(LOG_DataSourceController()) << tr("requestVariable, product data not found"); | |||
|
177 | } | |||
|
178 | } | |||
|
179 | ||||
152 | void DataSourceController::requestVariable(const QVariantHash &productData) |
|
180 | void DataSourceController::requestVariable(const QVariantHash &productData) | |
153 | { |
|
181 | { | |
154 | auto sourceItem = impl->findDataSourceItem(productData); |
|
182 | auto sourceItem = impl->findDataSourceItem(productData); |
@@ -165,6 +165,24 DataSourceItem *DataSourceItem::findItem(const QVariantHash &data, bool recursiv | |||||
165 | return nullptr; |
|
165 | return nullptr; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
|
168 | DataSourceItem *DataSourceItem::findItem(const QString &datasourceIdKey, bool recursive) | |||
|
169 | { | |||
|
170 | for (const auto &child : impl->m_Children) { | |||
|
171 | auto childId = child->impl->m_Data.value(ID_DATA_KEY); | |||
|
172 | if (childId == datasourceIdKey) { | |||
|
173 | return child.get(); | |||
|
174 | } | |||
|
175 | ||||
|
176 | if (recursive) { | |||
|
177 | if (auto foundItem = child->findItem(datasourceIdKey, true)) { | |||
|
178 | return foundItem; | |||
|
179 | } | |||
|
180 | } | |||
|
181 | } | |||
|
182 | ||||
|
183 | return nullptr; | |||
|
184 | } | |||
|
185 | ||||
168 | bool DataSourceItem::operator==(const DataSourceItem &other) |
|
186 | bool DataSourceItem::operator==(const DataSourceItem &other) | |
169 | { |
|
187 | { | |
170 | // Compares items' attributes |
|
188 | // Compares items' attributes |
General Comments 0
You need to be logged in to leave comments.
Login now