Mercurial > hg > svcore
comparison base/Selection.cpp @ 1429:48e9f538e6e9
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | cc27f35aa75c |
children | 796ae7eecced |
comparison
equal
deleted
inserted
replaced
1428:87ae75da6527 | 1429:48e9f538e6e9 |
---|---|
25 Selection::Selection(sv_frame_t startFrame, sv_frame_t endFrame) : | 25 Selection::Selection(sv_frame_t startFrame, sv_frame_t endFrame) : |
26 m_startFrame(startFrame), | 26 m_startFrame(startFrame), |
27 m_endFrame(endFrame) | 27 m_endFrame(endFrame) |
28 { | 28 { |
29 if (m_startFrame > m_endFrame) { | 29 if (m_startFrame > m_endFrame) { |
30 sv_frame_t tmp = m_endFrame; | 30 sv_frame_t tmp = m_endFrame; |
31 m_endFrame = m_startFrame; | 31 m_endFrame = m_startFrame; |
32 m_startFrame = tmp; | 32 m_startFrame = tmp; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 Selection::Selection(const Selection &s) : | 36 Selection::Selection(const Selection &s) : |
37 m_startFrame(s.m_startFrame), | 37 m_startFrame(s.m_startFrame), |
41 | 41 |
42 Selection & | 42 Selection & |
43 Selection::operator=(const Selection &s) | 43 Selection::operator=(const Selection &s) |
44 { | 44 { |
45 if (this != &s) { | 45 if (this != &s) { |
46 m_startFrame = s.m_startFrame; | 46 m_startFrame = s.m_startFrame; |
47 m_endFrame = s.m_endFrame; | 47 m_endFrame = s.m_endFrame; |
48 } | 48 } |
49 return *this; | 49 return *this; |
50 } | 50 } |
51 | 51 |
52 Selection::~Selection() | 52 Selection::~Selection() |
79 | 79 |
80 bool | 80 bool |
81 Selection::operator<(const Selection &s) const | 81 Selection::operator<(const Selection &s) const |
82 { | 82 { |
83 if (isEmpty()) { | 83 if (isEmpty()) { |
84 if (s.isEmpty()) return false; | 84 if (s.isEmpty()) return false; |
85 else return true; | 85 else return true; |
86 } else { | 86 } else { |
87 if (s.isEmpty()) return false; | 87 if (s.isEmpty()) return false; |
88 else return (m_startFrame < s.m_startFrame); | 88 else return (m_startFrame < s.m_startFrame); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 bool | 92 bool |
93 Selection::operator==(const Selection &s) const | 93 Selection::operator==(const Selection &s) const |
94 { | 94 { |
95 if (isEmpty()) return s.isEmpty(); | 95 if (isEmpty()) return s.isEmpty(); |
96 | 96 |
97 return (m_startFrame == s.m_startFrame && | 97 return (m_startFrame == s.m_startFrame && |
98 m_endFrame == s.m_endFrame); | 98 m_endFrame == s.m_endFrame); |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 MultiSelection::MultiSelection() | 102 MultiSelection::MultiSelection() |
103 { | 103 { |
132 // It's essential for the correct operation of | 132 // It's essential for the correct operation of |
133 // getContainingSelection that the selections do not overlap, so | 133 // getContainingSelection that the selections do not overlap, so |
134 // this is not just a frill. | 134 // this is not just a frill. |
135 | 135 |
136 for (SelectionList::iterator i = m_selections.begin(); | 136 for (SelectionList::iterator i = m_selections.begin(); |
137 i != m_selections.end(); ) { | 137 i != m_selections.end(); ) { |
138 | 138 |
139 SelectionList::iterator j = i; | 139 SelectionList::iterator j = i; |
140 if (++j == m_selections.end()) break; | 140 if (++j == m_selections.end()) break; |
141 | 141 |
142 if (i->getEndFrame() >= j->getStartFrame()) { | 142 if (i->getEndFrame() >= j->getStartFrame()) { |
143 Selection merged(i->getStartFrame(), | 143 Selection merged(i->getStartFrame(), |
144 std::max(i->getEndFrame(), j->getEndFrame())); | 144 std::max(i->getEndFrame(), j->getEndFrame())); |
145 m_selections.erase(i); | 145 m_selections.erase(i); |
146 m_selections.erase(j); | 146 m_selections.erase(j); |
147 m_selections.insert(merged); | 147 m_selections.insert(merged); |
148 i = m_selections.begin(); | 148 i = m_selections.begin(); |
149 } else { | 149 } else { |
150 ++i; | 150 ++i; |
151 } | 151 } |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 void | 155 void |
156 MultiSelection::removeSelection(const Selection &selection) | 156 MultiSelection::removeSelection(const Selection &selection) |
159 //where selection is not one of the original selection set but | 159 //where selection is not one of the original selection set but |
160 //simply overlaps one of them (cutting down the original selection | 160 //simply overlaps one of them (cutting down the original selection |
161 //appropriately) | 161 //appropriately) |
162 | 162 |
163 if (m_selections.find(selection) != m_selections.end()) { | 163 if (m_selections.find(selection) != m_selections.end()) { |
164 m_selections.erase(selection); | 164 m_selections.erase(selection); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 void | 168 void |
169 MultiSelection::clearSelections() | 169 MultiSelection::clearSelections() |
170 { | 170 { |
171 if (!m_selections.empty()) { | 171 if (!m_selections.empty()) { |
172 m_selections.clear(); | 172 m_selections.clear(); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 void | 176 void |
177 MultiSelection::getExtents(sv_frame_t &startFrame, sv_frame_t &endFrame) const | 177 MultiSelection::getExtents(sv_frame_t &startFrame, sv_frame_t &endFrame) const |
178 { | 178 { |
179 startFrame = 0; | 179 startFrame = 0; |
180 endFrame = 0; | 180 endFrame = 0; |
181 | 181 |
182 for (SelectionList::const_iterator i = m_selections.begin(); | 182 for (SelectionList::const_iterator i = m_selections.begin(); |
183 i != m_selections.end(); ++i) { | 183 i != m_selections.end(); ++i) { |
184 | 184 |
185 if (i == m_selections.begin() || i->getStartFrame() < startFrame) { | 185 if (i == m_selections.begin() || i->getStartFrame() < startFrame) { |
186 startFrame = i->getStartFrame(); | 186 startFrame = i->getStartFrame(); |
187 } | 187 } |
188 | 188 |
198 // This scales very badly with the number of selections, but it's | 198 // This scales very badly with the number of selections, but it's |
199 // more efficient for very small numbers of selections than a more | 199 // more efficient for very small numbers of selections than a more |
200 // scalable method, and I think that may be what we need | 200 // scalable method, and I think that may be what we need |
201 | 201 |
202 for (SelectionList::const_iterator i = m_selections.begin(); | 202 for (SelectionList::const_iterator i = m_selections.begin(); |
203 i != m_selections.end(); ++i) { | 203 i != m_selections.end(); ++i) { |
204 | 204 |
205 if (i->contains(frame)) return *i; | 205 if (i->contains(frame)) return *i; |
206 | 206 |
207 if (i->getStartFrame() > frame) { | 207 if (i->getStartFrame() > frame) { |
208 if (defaultToFollowing) return *i; | 208 if (defaultToFollowing) return *i; |
209 else return Selection(); | 209 else return Selection(); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 return Selection(); | 213 return Selection(); |
214 } | 214 } |
215 | 215 |
217 MultiSelection::toXml(QTextStream &stream, QString indent, | 217 MultiSelection::toXml(QTextStream &stream, QString indent, |
218 QString extraAttributes) const | 218 QString extraAttributes) const |
219 { | 219 { |
220 stream << indent << QString("<selections %1>\n").arg(extraAttributes); | 220 stream << indent << QString("<selections %1>\n").arg(extraAttributes); |
221 for (SelectionList::iterator i = m_selections.begin(); | 221 for (SelectionList::iterator i = m_selections.begin(); |
222 i != m_selections.end(); ++i) { | 222 i != m_selections.end(); ++i) { |
223 stream << indent | 223 stream << indent |
224 << QString(" <selection start=\"%1\" end=\"%2\"/>\n") | 224 << QString(" <selection start=\"%1\" end=\"%2\"/>\n") |
225 .arg(i->getStartFrame()).arg(i->getEndFrame()); | 225 .arg(i->getStartFrame()).arg(i->getEndFrame()); |
226 } | 226 } |
227 stream << indent << "</selections>\n"; | 227 stream << indent << "</selections>\n"; |
228 } | 228 } |
229 | 229 |