1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "core/components_v2/inspector/checkboxGroup_composed_element.h"
17
18 #include "base/log/dump_log.h"
19 #include "core/components/common/layout/constants.h"
20 #include "core/components_v2/inspector/utils.h"
21
22 namespace OHOS::Ace::V2 {
23 namespace {
24
25 const std::unordered_map<std::string,
26 std::function<std::string(const CheckboxGroupComposedElement&)>> CREATE_JSON_MAP {
__anonc053e4100202(const CheckboxGroupComposedElement& inspector) 27 { "group", [](const CheckboxGroupComposedElement& inspector) { return inspector.GetGroupName(); } },
__anonc053e4100302(const CheckboxGroupComposedElement& inspector) 28 { "selectAll", [](const CheckboxGroupComposedElement& inspector) { return inspector.GetSelectAll(); } },
__anonc053e4100402(const CheckboxGroupComposedElement& inspector) 29 { "selectedColor", [](const CheckboxGroupComposedElement& inspector) { return inspector.GetSelectedColor(); } }
30 };
31
32 } // namespace
33
Dump()34 void CheckboxGroupComposedElement::Dump()
35 {
36 InspectorComposedElement::Dump();
37 DumpLog::GetInstance().AddDesc(std::string("group: ").append(GetGroupName()));
38 DumpLog::GetInstance().AddDesc(std::string("selectAll: ").append(GetSelectAll()));
39 DumpLog::GetInstance().AddDesc(std::string("selectedColor: ").append(GetSelectedColor()));
40 }
41
ToJsonObject() const42 std::unique_ptr<JsonValue> CheckboxGroupComposedElement::ToJsonObject() const
43 {
44 auto resultJson = InspectorComposedElement::ToJsonObject();
45 for (const auto& value : CREATE_JSON_MAP) {
46 resultJson->Put(value.first.c_str(), value.second(*this).c_str());
47 }
48 return resultJson;
49 }
50
GetGroupName() const51 std::string CheckboxGroupComposedElement::GetGroupName() const
52 {
53 auto renderCheckbox = GetRenderCheckbox();
54 if (renderCheckbox) {
55 return renderCheckbox->GetGroupName().c_str();
56 }
57 return "";
58 }
59
GetSelectAll() const60 std::string CheckboxGroupComposedElement::GetSelectAll() const
61 {
62 auto renderCheckbox = GetRenderCheckbox();
63 auto selectAll = renderCheckbox ? renderCheckbox->GetCheckBoxValue() : false;
64 return ConvertBoolToString(selectAll);
65 }
66
GetSelectedColor() const67 std::string CheckboxGroupComposedElement::GetSelectedColor() const
68 {
69 auto renderCheckbox = GetRenderCheckbox();
70 if (renderCheckbox) {
71 return renderCheckbox->GetActiveColor().ColorToString();
72 }
73 return "";
74 }
75
GetRenderCheckbox() const76 RefPtr<RenderCheckbox> CheckboxGroupComposedElement::GetRenderCheckbox() const
77 {
78 auto node = GetInspectorNode(CheckableElement::TypeId());
79 if (node) {
80 return AceType::DynamicCast<RenderCheckbox>(node);
81 }
82 return nullptr;
83 }
84
85 } // namespace OHOS::Ace::V2