umya_spreadsheet/structs/
icon_set.rs1use std::io::Cursor;
2
3use quick_xml::{
4 Reader,
5 Writer,
6 events::{
7 BytesStart,
8 Event,
9 },
10};
11
12use super::{
13 Color,
14 ConditionalFormatValueObject,
15};
16use crate::{
17 reader::driver::xml_read_loop,
18 writer::driver::{
19 write_end_tag,
20 write_start_tag,
21 },
22};
23
24#[derive(Clone, Default, Debug)]
25pub struct IconSet {
26 cfvo_collection: Vec<ConditionalFormatValueObject>,
27 color_collection: Vec<Color>,
28}
29
30impl IconSet {
31 #[inline]
32 #[must_use]
33 pub fn cfvo_collection(&self) -> &[ConditionalFormatValueObject] {
34 &self.cfvo_collection
35 }
36
37 #[inline]
38 #[must_use]
39 #[deprecated(since = "3.0.0", note = "Use cfvo_collection()")]
40 pub fn get_cfvo_collection(&self) -> &[ConditionalFormatValueObject] {
41 self.cfvo_collection()
42 }
43
44 #[inline]
45 pub fn set_cfvo_collection(
46 &mut self,
47 value: impl Into<Vec<ConditionalFormatValueObject>>,
48 ) -> &mut Self {
49 self.cfvo_collection = value.into();
50 self
51 }
52
53 #[inline]
54 pub fn add_cfvo_collection(&mut self, value: ConditionalFormatValueObject) -> &mut Self {
55 self.cfvo_collection.push(value);
56 self
57 }
58
59 #[inline]
60 #[must_use]
61 pub fn color_collection(&self) -> &[Color] {
62 &self.color_collection
63 }
64
65 #[inline]
66 #[must_use]
67 #[deprecated(since = "3.0.0", note = "Use color_collection()")]
68 pub fn get_color_collection(&self) -> &[Color] {
69 self.color_collection()
70 }
71
72 #[inline]
73 pub fn set_color_collection(&mut self, value: impl Into<Vec<Color>>) -> &mut Self {
74 self.color_collection = value.into();
75 self
76 }
77
78 #[inline]
79 pub fn add_color_collection(&mut self, value: Color) -> &mut Self {
80 self.color_collection.push(value);
81 self
82 }
83
84 pub(crate) fn set_attributes<R: std::io::BufRead>(
85 &mut self,
86 reader: &mut Reader<R>,
87 _e: &BytesStart,
88 ) {
89 xml_read_loop!(
90 reader,
91 Event::Empty(ref e) => {
92 match e.name().into_inner() {
93 b"cfvo" => {
94 let mut obj = ConditionalFormatValueObject::default();
95 obj.set_attributes(reader, e, true);
96 self.cfvo_collection.push(obj);
97 }
98 b"color" => {
99 let mut obj = Color::default();
100 obj.set_attributes(reader, e, true);
101 self.color_collection.push(obj);
102 }
103 _ => (),
104 }
105 },
106 Event::End(ref e) => {
107 if e.name().into_inner() == b"iconSet" {
108 return
109 }
110 },
111 Event::Eof => return
112 );
113 }
114
115 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
116 write_start_tag(writer, "dataBar", vec![], false);
118
119 for v in &self.cfvo_collection {
121 v.write_to(writer);
122 }
123
124 for v in &self.color_collection {
126 v.write_to_color(writer);
127 }
128
129 write_end_tag(writer, "dataBar");
130 }
131}