* @brief Add group */
| 1676 | * @brief Add group |
| 1677 | */ |
| 1678 | API::CommandResponse API::Handlers::ProjectHandler::groupAdd(const QString& id, |
| 1679 | const QJsonObject& params) |
| 1680 | { |
| 1681 | if (!params.contains(QStringLiteral("title"))) { |
| 1682 | return CommandResponse::makeError( |
| 1683 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: title")); |
| 1684 | } |
| 1685 | |
| 1686 | if (!params.contains(QStringLiteral("widgetType"))) { |
| 1687 | return CommandResponse::makeError( |
| 1688 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: widgetType")); |
| 1689 | } |
| 1690 | |
| 1691 | const QString title = params.value(QStringLiteral("title")).toString(); |
| 1692 | if (title.isEmpty()) { |
| 1693 | return CommandResponse::makeError( |
| 1694 | id, ErrorCode::InvalidParam, QStringLiteral("title cannot be empty")); |
| 1695 | } |
| 1696 | |
| 1697 | const int widget_type = params.value(QStringLiteral("widgetType")).toInt(); |
| 1698 | if (widget_type < 0 || widget_type > static_cast<int>(SerialStudio::Painter)) { |
| 1699 | return CommandResponse::makeError( |
| 1700 | id, |
| 1701 | ErrorCode::InvalidParam, |
| 1702 | QStringLiteral("Invalid widgetType: must be 0..%1 " |
| 1703 | "(see GroupWidget enum: 0=DataGrid, 1=Accelerometer, " |
| 1704 | "2=Gyroscope, 3=GPS, 4=MultiPlot, 5=NoGroupWidget, " |
| 1705 | "6=Plot3D, 7=ImageView, 8=Painter)") |
| 1706 | .arg(static_cast<int>(SerialStudio::Painter))); |
| 1707 | } |
| 1708 | |
| 1709 | const auto widget = static_cast<SerialStudio::GroupWidget>(widget_type); |
| 1710 | DataModel::ProjectModel::instance().addGroup(title, widget); |
| 1711 | |
| 1712 | QJsonObject result; |
| 1713 | result[QStringLiteral("title")] = title; |
| 1714 | result[QStringLiteral("widgetType")] = widget_type; |
| 1715 | return CommandResponse::makeSuccess(id, result); |
| 1716 | } |
| 1717 | |
| 1718 | /** |
| 1719 | * @brief Delete a group by id |