1 /*
2  * Copyright (c) 2021-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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_MULTITEXT_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_MULTITEXT_COMPONENT_H
18 
19 #include "core/components/picker/picker_base_component.h"
20 
21 namespace OHOS::Ace {
22 
23 class PickerMultiTextComponent : public PickerBaseComponent {
24     DECLARE_ACE_TYPE(PickerMultiTextComponent, PickerBaseComponent);
25 
26 public:
27     PickerMultiTextComponent() = default;
28     ~PickerMultiTextComponent() override = default;
29 
GetSelected()30     const std::vector<uint32_t>& GetSelected() const
31     {
32         return selectedIndexes_;
33     }
SetSelected(const std::vector<uint32_t> & value)34     void SetSelected(const std::vector<uint32_t>& value)
35     {
36         if (IsEqualSelected(value)) {
37             return;
38         }
39         selectedIndexes_ = value;
40         HandleSelectedChange();
41     }
42 
GetRange()43     const std::vector<std::vector<std::string>>& GetRange() const
44     {
45         return range_;
46     }
SetRange(const std::vector<std::vector<std::string>> & value)47     void SetRange(const std::vector<std::vector<std::string>>& value)
48     {
49         if (IsEqualRange(value)) {
50             return;
51         }
52         range_ = value;
53         HandleRangeChange();
54     }
55 
GetColumnCount()56     uint32_t GetColumnCount() const override
57     {
58         return columnCount_;
59     }
SetColumnCount(uint32_t value)60     void SetColumnCount(uint32_t value)
61     {
62         if (hasCreateColumn_) {
63             return;
64         }
65         columnCount_ = value;
66     }
67 
68     void OnTitleBuilding() override;
69 
70     void OnColumnsBuilding() override;
71 
72     std::string GetSelectedObject(bool isColumnChange,
73         const std::string& changeColumnTag, int32_t status = -1) const override;
74 
75     void OnSelectedSaving() override;
76 
77     void OnDataLinking(const std::string& tag, bool isAdd, uint32_t index,
78         std::vector<std::string>& resultTags) override;
79 
80     void OnColumnsCreating() override;
81 
82 private:
83     void HandleRangeChange();
84 
85     void HandleSelectedChange();
86 
87     bool IsEqualSelected(const std::vector<uint32_t>& value) const;
88 
89     bool IsEqualRange(const std::vector<std::vector<std::string>>& value) const;
90 
91     bool IsEqualStrings(const std::vector<std::string>& first, const std::vector<std::string>& second) const;
92 
93     std::vector<uint32_t> selectedIndexes_;
94     std::vector<std::string> selectedValues_;
95     std::vector<std::vector<std::string>> range_;
96 
97     uint32_t columnCount_ = 0;
98     bool hasCreateColumn_ = false;
99 };
100 
101 } // namespace OHOS::Ace
102 
103 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_MULTITEXT_COMPONENT_H
104