* @brief Patch any subset of output-widget fields by groupId + widgetId. */
| 5111 | * @brief Patch any subset of output-widget fields by groupId + widgetId. |
| 5112 | */ |
| 5113 | API::CommandResponse API::Handlers::ProjectHandler::outputWidgetUpdate(const QString& id, |
| 5114 | const QJsonObject& params) |
| 5115 | { |
| 5116 | if (!params.contains(QStringLiteral("groupId"))) |
| 5117 | return CommandResponse::makeError( |
| 5118 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: groupId")); |
| 5119 | |
| 5120 | if (!params.contains(QStringLiteral("widgetId"))) |
| 5121 | return CommandResponse::makeError( |
| 5122 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: widgetId")); |
| 5123 | |
| 5124 | const int groupId = params.value(QStringLiteral("groupId")).toInt(); |
| 5125 | const int widgetId = params.value(QStringLiteral("widgetId")).toInt(); |
| 5126 | auto& project = DataModel::ProjectModel::instance(); |
| 5127 | const auto& groups = project.groups(); |
| 5128 | if (groupId < 0 || static_cast<size_t>(groupId) >= groups.size()) |
| 5129 | return CommandResponse::makeError( |
| 5130 | id, ErrorCode::InvalidParam, QStringLiteral("Group id not found: %1").arg(groupId)); |
| 5131 | |
| 5132 | DataModel::Group g = groups[groupId]; |
| 5133 | if (widgetId < 0 || static_cast<size_t>(widgetId) >= g.outputWidgets.size()) |
| 5134 | return CommandResponse::makeError(id, |
| 5135 | ErrorCode::InvalidParam, |
| 5136 | QStringLiteral("Widget id not found: %1 in group %2") |
| 5137 | .arg(QString::number(widgetId), QString::number(groupId))); |
| 5138 | |
| 5139 | DataModel::OutputWidget& w = g.outputWidgets[widgetId]; |
| 5140 | bool rebuildTree = false; |
| 5141 | QSet<QString> consumed{QStringLiteral("groupId"), QStringLiteral("widgetId")}; |
| 5142 | const auto identityKeyCount = consumed.size(); |
| 5143 | |
| 5144 | const auto take = [&](const QString& key) -> bool { |
| 5145 | if (!params.contains(key)) |
| 5146 | return false; |
| 5147 | |
| 5148 | consumed.insert(key); |
| 5149 | return true; |
| 5150 | }; |
| 5151 | |
| 5152 | if (take(QStringLiteral("title"))) { |
| 5153 | w.title = params.value(QStringLiteral("title")).toString(); |
| 5154 | rebuildTree = true; |
| 5155 | } |
| 5156 | if (take(QStringLiteral("icon"))) { |
| 5157 | w.icon = params.value(QStringLiteral("icon")).toString(); |
| 5158 | rebuildTree = true; |
| 5159 | } |
| 5160 | if (take(QStringLiteral("transmitFunction"))) |
| 5161 | w.transmitFunction = params.value(QStringLiteral("transmitFunction")).toString(); |
| 5162 | |
| 5163 | if (take(Keys::SourceId)) |
| 5164 | w.sourceId = params.value(Keys::SourceId).toInt(); |
| 5165 | |
| 5166 | if (take(QStringLiteral("txEncoding"))) |
| 5167 | w.txEncoding = params.value(QStringLiteral("txEncoding")).toInt(); |
| 5168 | |
| 5169 | if (take(QStringLiteral("monoIcon"))) { |
| 5170 | w.monoIcon = params.value(QStringLiteral("monoIcon")).toBool(); |
nothing calls this directly
no test coverage detected