Skip to main content

umya_spreadsheet/structs/
sequence_of_references.rs

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