6 #include <QElapsedTimer>
35 bool newly_added =
false;
38 if (dst_data_it == src_data.
numeric.end())
44 PlotData& dst_data = dst_data_it->second;
45 std::vector<PlotData*> dst_vector = { &dst_data };
48 setData(&src_data, {}, dst_vector);
60 std::rethrow_exception(std::current_exception());
74 if (data_it ==
plotData()->numeric.end())
87 throw std::runtime_error(
"Invalid channel name");
89 const PlotData* chan_data = &(it->second);
96 dst_data->setMaximumRangeX(main_data_source->
maximumRangeX());
98 double last_updated_stamp = std::numeric_limits<double>::lowest();
99 if (dst_data->size() != 0)
101 last_updated_stamp = dst_data->back().x;
104 std::vector<PlotData::Point> points;
105 for (
size_t i = 0; i < main_data_source->
size(); ++i)
107 if (main_data_source->
at(i).x > last_updated_stamp)
114 dst_data->pushBack(point);
134 if (xml_text.isEmpty())
140 QString parseErrorMsg;
142 if (!doc.setContent(xml_text, &parseErrorMsg, &parseErrorLine))
144 QMessageBox::critical(
nullptr,
"Error",
145 QString(
"Failed to parse snippets (xml), error %1 at line %2")
147 .
arg(parseErrorLine));
152 QDomElement snippets_element = doc.documentElement();
161 for (
auto elem = snippets_element.firstChildElement(
"snippet"); !elem.isNull();
162 elem = elem.nextSiblingElement(
"snipp"
166 snippets.insert({ snippet.
alias_name, snippet });
173 auto snippets_root = doc.createElement(
"snippets");
175 for (
const auto& it : snippets)
177 const auto& snippet = it.second;
179 snippets_root.appendChild(element);
181 return snippets_root;
187 snippet.
linked_source = element.firstChildElement(
"linked_source").text().trimmed();
188 snippet.
alias_name = element.attribute(
"name");
189 snippet.
global_vars = element.firstChildElement(
"global").text().trimmed();
190 snippet.
function = element.firstChildElement(
"function").text().trimmed();
192 auto additional_el = element.firstChildElement(
"additional_sources");
193 if (!additional_el.isNull())
196 auto tag_name = QString(
"v%1").arg(
count);
197 auto source_el = additional_el.firstChildElement(tag_name);
198 while (!source_el.isNull())
201 tag_name = QString(
"v%1").arg(++
count);
202 source_el = additional_el.firstChildElement(tag_name);
210 auto element = doc.createElement(
"snippet");
212 element.setAttribute(
"name", snippet.
alias_name);
214 auto global_el = doc.createElement(
"global");
215 global_el.appendChild(doc.createTextNode(snippet.
global_vars));
216 element.appendChild(global_el);
218 auto equation_el = doc.createElement(
"function");
219 equation_el.appendChild(doc.createTextNode(snippet.
function));
220 element.appendChild(equation_el);
222 auto linked_el = doc.createElement(
"linked_source");
223 linked_el.appendChild(doc.createTextNode(snippet.
linked_source));
224 element.appendChild(linked_el);
228 auto sources_el = doc.createElement(
"additional_sources");
233 auto tag_name = QString(
"v%1").arg(
count++);
234 auto source_el = doc.createElement(tag_name);
235 source_el.appendChild(doc.createTextNode(curve_name));
236 sources_el.appendChild(source_el);
239 element.appendChild(sources_el);