MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / buildDatasetObject

Function buildDatasetObject

app/src/API/Handlers/ProjectHandler.cpp:138–220  ·  view source on GitHub ↗

* @brief Builds the canonical dataset response object used by list / get* / snapshot. */

Source from the content-addressed store, hash-verified

136 * @brief Builds the canonical dataset response object used by list / get* / snapshot.
137 */
138static QJsonObject buildDatasetObject(const DataModel::Dataset& dataset,
139 const DataModel::Group& group)
140{
141 QJsonObject dataset_obj = DataModel::serialize(dataset);
142
143 dataset_obj[QStringLiteral("groupId")] = group.groupId;
144 dataset_obj[QStringLiteral("groupTitle")] = group.title;
145 dataset_obj[Keys::SourceId] = dataset.sourceId;
146 dataset_obj[Keys::UniqueId] = dataset.uniqueId;
147
148 QStringList enabled;
149 if (dataset.plt)
150 enabled.append(QStringLiteral("plot"));
151
152 if (dataset.fft)
153 enabled.append(QStringLiteral("FFT"));
154
155 if (dataset.led)
156 enabled.append(QStringLiteral("LED"));
157
158 if (dataset.log)
159 enabled.append(QStringLiteral("log"));
160
161 if (dataset.waterfall)
162 enabled.append(QStringLiteral("waterfall"));
163
164 if (!dataset.alarmBands.empty())
165 enabled.append(QStringLiteral("alarm"));
166
167 if (!dataset.widget.isEmpty())
168 enabled.append(dataset.widget);
169
170 dataset_obj[QStringLiteral("enabledFeatures")] =
171 enabled.isEmpty() ? QStringLiteral("plain numeric") : enabled.join(QStringLiteral(", "));
172
173 const int optionsBits = datasetOptionsBitflag(dataset);
174 dataset_obj[QStringLiteral("enabledOptions")] = optionsBits;
175
176 QJsonArray optionSlugs;
177 for (const auto& slug : API::EnumLabels::datasetOptionsBitsToSlugs(optionsBits))
178 optionSlugs.append(slug);
179
180 dataset_obj[QStringLiteral("enabledOptionsSlugs")] = optionSlugs;
181
182 QJsonArray ds_widget_types;
183 appendDatasetWidgetTypes(dataset, ds_widget_types);
184 dataset_obj[QStringLiteral("enabledWidgetTypes")] = ds_widget_types;
185
186 QJsonArray ds_widget_type_slugs;
187 for (const auto w : SerialStudio::getDashboardWidgets(dataset)) {
188 const auto slug = API::EnumLabels::dashboardWidgetSlug(static_cast<int>(w));
189 if (!ds_widget_type_slugs.contains(slug))
190 ds_widget_type_slugs.append(slug);
191 }
192 dataset_obj[QStringLiteral("enabledWidgetTypesSlugs")] = ds_widget_type_slugs;
193
194 dataset_obj[QStringLiteral("hasTransform")] = !dataset.transformCode.isEmpty();
195 dataset_obj[QStringLiteral("isVirtual")] = dataset.virtual_;

Callers 5

datasetsListMethod · 0.85
datasetGetByUniqueIdMethod · 0.85
datasetGetByTitleMethod · 0.85
datasetGetByPathMethod · 0.85
buildSnapshotGroupsFunction · 0.85

Calls 8

serializeFunction · 0.85
datasetOptionsBitflagFunction · 0.85
appendDatasetWidgetTypesFunction · 0.85
emptyMethod · 0.80
isEmptyMethod · 0.80
appendMethod · 0.45
containsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected