| 57 | }; |
| 58 | |
| 59 | static ApplyResult applyAndDiff( |
| 60 | QWidget* root, PJ::DialogHandle& handle, nlohmann::json& prev_data, bool enable_diff, int& diff_apply_count) { |
| 61 | std::string raw = handle.widget_data(); |
| 62 | nlohmann::json new_data = nlohmann::json::parse(raw, nullptr, false); |
| 63 | if (new_data.is_discarded()) { |
| 64 | return {}; |
| 65 | } |
| 66 | |
| 67 | PJ::WidgetDataView full_view(raw); |
| 68 | ApplyResult result; |
| 69 | result.wants_accept = full_view.requestAccept(); |
| 70 | result.sub_dialog_ui = full_view.subDialogUi(); |
| 71 | |
| 72 | // Strip commands before diffing (they're one-shot) |
| 73 | new_data.erase("__request_accept"); |
| 74 | new_data.erase("__request_sub_dialog"); |
| 75 | |
| 76 | if (enable_diff) { |
| 77 | nlohmann::json diff = computeDiff(prev_data, new_data); |
| 78 | if (!diff.empty()) { |
| 79 | PJ::WidgetDataView view(diff.dump()); |
| 80 | applyWidgetData(root, view); |
| 81 | ++diff_apply_count; |
| 82 | } |
| 83 | } else { |
| 84 | applyWidgetData(root, full_view); |
| 85 | } |
| 86 | prev_data = std::move(new_data); |
| 87 | return result; |
| 88 | } |
| 89 | |
| 90 | // --------------------------------------------------------------------------- |
| 91 | // show_dialog |
no test coverage detected