utils.cpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5  */
6 
7 #include "utils.h"
8 #include <QDebug>
9 
11  bool remove_older)
12 {
14 
15  auto moveDataImpl = [&](auto& source_series, auto& destination_series) {
16  for (auto& it : source_series)
17  {
18  const std::string& ID = it.first;
19  auto& source_plot = it.second;
20  const std::string& plot_name = source_plot.plotName();
21 
22  auto dest_plot_it = destination_series.find(ID);
23  if (dest_plot_it == destination_series.end())
24  {
25  ret.added_curves.push_back(ID);
26 
27  PlotGroup::Ptr group;
28  if (source_plot.group())
29  {
30  destination.getOrCreateGroup(source_plot.group()->name());
31  }
32  dest_plot_it = destination_series
33  .emplace(std::piecewise_construct, std::forward_as_tuple(ID),
34  std::forward_as_tuple(plot_name, group))
35  .first;
36  ret.curves_updated = true;
37  }
38 
39  auto& destination_plot = dest_plot_it->second;
40  PlotGroup::Ptr destination_group = destination_plot.group();
41 
42  // copy plot attributes
43  for (const auto& [name, attr] : source_plot.attributes())
44  {
45  if (destination_plot.attribute(name) != attr)
46  {
47  destination_plot.setAttribute(name, attr);
48  ret.curves_updated = true;
49  }
50  }
51  // Copy the group name and attributes
52  if (source_plot.group())
53  {
54  if (!destination_group ||
55  destination_group->name() != source_plot.group()->name())
56  {
57  destination_group = destination.getOrCreateGroup(source_plot.group()->name());
58  destination_plot.changeGroup(destination_group);
59  }
60 
61  for (const auto& [name, attr] : source_plot.group()->attributes())
62  {
63  if (destination_group->attribute(name) != attr)
64  {
65  destination_group->setAttribute(name, attr);
66  ret.curves_updated = true;
67  }
68  }
69  }
70 
71  if (remove_older)
72  {
73  destination_plot.clear();
74  }
75 
76  if (source_plot.size() > 0)
77  {
78  ret.data_pushed = true;
79  }
80 
81  if constexpr (std::is_same_v<PlotData, decltype(source_plot)> ||
82  std::is_same_v<StringSeries, decltype(source_plot)> ||
83  std::is_same_v<PlotDataAny, decltype(source_plot)>)
84  {
85  double max_range_x = source_plot.maximumRangeX();
86  destination_plot.setMaximumRangeX(max_range_x);
87  }
88 
89  if (destination_plot.size() == 0)
90  {
91  std::swap(destination_plot, source_plot);
92  }
93  else
94  {
95  for (size_t i = 0; i < source_plot.size(); i++)
96  {
97  destination_plot.pushBack(source_plot.at(i));
98  }
99  source_plot.clear();
100  }
101  }
102  };
103 
104  //--------------------------------------------
105  moveDataImpl(source.numeric, destination.numeric);
106  moveDataImpl(source.strings, destination.strings);
107  moveDataImpl(source.scatter_xy, destination.scatter_xy);
108  moveDataImpl(source.user_defined, destination.user_defined);
109 
110  return ret;
111 }
MoveDataRet
Definition: utils.h:44
detail::first
auto first(const T &value, const Tail &...) -> const T &
Definition: compile.h:60
PJ::TimeseriesBase
Definition: timeseries.h:16
PJ::PlotDataMapRef::getOrCreateGroup
PlotGroup::Ptr getOrCreateGroup(const std::string &name)
Definition: plotdata.cpp:93
PJ::PlotDataMapRef::numeric
TimeseriesMap numeric
Numerical timeseries.
Definition: plotdata.h:39
PJ::PlotGroup::Ptr
std::shared_ptr< PlotGroup > Ptr
Definition: plotdatabase.h:83
utils.h
PJ::PlotDataMapRef::scatter_xy
ScatterXYMap scatter_xy
Definition: plotdata.h:36
std::swap
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.hpp:21884
source
const char * source
Definition: lz4.h:767
PJ::PlotDataMapRef
Definition: plotdata.h:34
PJ::PlotDataMapRef::user_defined
AnySeriesMap user_defined
Definition: plotdata.h:43
MoveData
MoveDataRet MoveData(PlotDataMapRef &source, PlotDataMapRef &destination, bool remove_older)
Definition: utils.cpp:10
PJ::PlotDataMapRef::strings
StringSeriesMap strings
Series of strings.
Definition: plotdata.h:46
mqtt_test.ret
ret
Definition: mqtt_test.py:30
PJ::StringSeries
Definition: stringseries.h:17


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:48