* @brief List all groups with basic info */
| 3210 | * @brief List all groups with basic info |
| 3211 | */ |
| 3212 | API::CommandResponse API::Handlers::ProjectHandler::groupsList(const QString& id, |
| 3213 | const QJsonObject& params) |
| 3214 | { |
| 3215 | Q_UNUSED(params) |
| 3216 | |
| 3217 | const auto& groups = DataModel::ProjectModel::instance().groups(); |
| 3218 | |
| 3219 | QJsonArray groups_array; |
| 3220 | for (const auto& group : groups) { |
| 3221 | QJsonObject obj = DataModel::serialize(group); |
| 3222 | |
| 3223 | obj[QStringLiteral("datasetCount")] = static_cast<int>(group.datasets.size()); |
| 3224 | |
| 3225 | QJsonArray ds_summary; |
| 3226 | for (const auto& ds : group.datasets) { |
| 3227 | QJsonObject d; |
| 3228 | d[Keys::DatasetId] = ds.datasetId; |
| 3229 | d[Keys::UniqueId] = ds.uniqueId; |
| 3230 | d[QStringLiteral("index")] = ds.index; |
| 3231 | d[QStringLiteral("title")] = ds.title; |
| 3232 | if (!ds.units.isEmpty()) |
| 3233 | d[QStringLiteral("units")] = ds.units; |
| 3234 | |
| 3235 | d[QStringLiteral("enabledOptions")] = datasetOptionsBitflag(ds); |
| 3236 | |
| 3237 | QJsonArray ds_compat; |
| 3238 | appendDatasetWidgetTypes(ds, ds_compat); |
| 3239 | d[QStringLiteral("enabledWidgetTypes")] = ds_compat; |
| 3240 | |
| 3241 | ds_summary.append(d); |
| 3242 | } |
| 3243 | obj[QStringLiteral("datasetSummary")] = ds_summary; |
| 3244 | |
| 3245 | QJsonArray compat; |
| 3246 | const auto group_w = static_cast<int>(SerialStudio::getDashboardWidget(group)); |
| 3247 | if (group_w != SerialStudio::DashboardNoWidget) |
| 3248 | compat.append(group_w); |
| 3249 | |
| 3250 | for (const auto& ds : group.datasets) |
| 3251 | appendDatasetWidgetTypes(ds, compat); |
| 3252 | |
| 3253 | obj[QStringLiteral("compatibleWidgetTypes")] = compat; |
| 3254 | |
| 3255 | QJsonArray compatSlugs; |
| 3256 | for (const auto& v : compat) { |
| 3257 | const auto slug = API::EnumLabels::dashboardWidgetSlug(v.toInt()); |
| 3258 | if (!compatSlugs.contains(slug)) |
| 3259 | compatSlugs.append(slug); |
| 3260 | } |
| 3261 | obj[QStringLiteral("compatibleWidgetTypeSlugs")] = compatSlugs; |
| 3262 | |
| 3263 | groups_array.append(obj); |
| 3264 | } |
| 3265 | |
| 3266 | QString summary; |
| 3267 | if (groups.empty()) { |
| 3268 | summary = QStringLiteral("No groups configured."); |
| 3269 | } else { |
nothing calls this directly
no test coverage detected