umya_spreadsheet/structs/
sequence_of_references.rs1use super::Range;
2use crate::traits::AdjustmentCoordinate;
3use thin_vec::ThinVec;
4
5#[derive(Default, Debug, Clone)]
6pub struct SequenceOfReferences {
7 range_collection: ThinVec<Range>,
8}
9
10impl SequenceOfReferences {
11 #[inline]
12 pub fn get_range_collection(&self) -> &[Range] {
13 &self.range_collection
14 }
15
16 #[inline]
17 pub fn get_range_collection_mut(&mut self) -> &mut ThinVec<Range> {
18 &mut self.range_collection
19 }
20
21 #[inline]
22 pub fn set_range_collection(&mut self, value: impl Into<ThinVec<Range>>) -> &mut Self {
23 self.range_collection = value.into();
24 self
25 }
26
27 #[inline]
28 pub fn add_range_collection(&mut self, value: Range) -> &mut Self {
29 self.range_collection.push(value);
30 self
31 }
32
33 #[inline]
34 pub fn remove_range_collection(&mut self) -> &mut Self {
35 self.range_collection.clear();
36 self
37 }
38
39 pub fn set_sqref<S: Into<String>>(&mut self, value: S) -> &mut Self {
40 value.into().split(' ').for_each(|range_value| {
41 let mut range = Range::default();
42 range.set_range(range_value);
43 self.range_collection.push(range);
44 });
45 self
46 }
47
48 #[inline]
49 pub fn get_sqref(&self) -> String {
50 self.range_collection
51 .iter()
52 .map(|range| range.get_range())
53 .collect::<Vec<String>>()
54 .join(" ")
55 }
56}
57impl AdjustmentCoordinate for SequenceOfReferences {
58 fn adjustment_insert_coordinate(
59 &mut self,
60 root_col_num: &u32,
61 offset_col_num: &u32,
62 root_row_num: &u32,
63 offset_row_num: &u32,
64 ) {
65 for range in &mut self.range_collection {
66 range.adjustment_insert_coordinate(
67 root_col_num,
68 offset_col_num,
69 root_row_num,
70 offset_row_num,
71 );
72 }
73 }
74
75 fn adjustment_remove_coordinate(
76 &mut self,
77 root_col_num: &u32,
78 offset_col_num: &u32,
79 root_row_num: &u32,
80 offset_row_num: &u32,
81 ) {
82 for range in &mut self.range_collection {
83 range.adjustment_remove_coordinate(
84 root_col_num,
85 offset_col_num,
86 root_row_num,
87 offset_row_num,
88 );
89 }
90 }
91
92 fn is_remove_coordinate(
93 &self,
94 root_col_num: &u32,
95 offset_col_num: &u32,
96 root_row_num: &u32,
97 offset_row_num: &u32,
98 ) -> bool {
99 for range in &self.range_collection {
100 if range.is_remove_coordinate(
101 root_col_num,
102 offset_col_num,
103 root_row_num,
104 offset_row_num,
105 ) {
106 return true;
107 }
108 }
109 false
110 }
111}