7 #ifndef PJ_PLOTDATA_BASE_H 8 #define PJ_PLOTDATA_BASE_H 16 #include <type_traits> 20 #include <unordered_map> 22 #include <string_view> 57 using Attributes = std::unordered_map<PlotAttribute, QVariant>;
65 return value.type() == QVariant::Color;
67 return value.type() == QVariant::Bool;
69 return value.type() == QVariant::String;
82 using Ptr = std::shared_ptr<PlotGroup>;
88 const std::string&
name()
const 105 _attributes[id] = value;
110 auto it = _attributes.find(
id);
111 return (it == _attributes.end()) ? QVariant() : it->second;
120 template <
typename TypeX,
typename Value>
137 MAX_CAPACITY = 1024 * 1024,
138 ASYNC_BUFFER_CAPACITY = 1024
141 typedef typename std::deque<Point>::iterator
Iterator;
146 : _name(name), _range_x_dirty(true), _range_y_dirty(true), _group(group)
184 return _points.size();
192 const Point&
at(
size_t index)
const 194 return _points[index];
197 Point&
at(
size_t index)
199 return _points[index];
215 _range_x_dirty =
true;
216 _range_y_dirty =
true;
231 _attributes[id] = value;
234 throw std::runtime_error(
"PlotDataBase::setAttribute : wrong type");
240 auto it = _attributes.find(
id);
241 return (it == _attributes.end()) ? QVariant() : it->second;
246 return _points.front();
251 return _points.back();
256 return _points.begin();
261 return _points.end();
266 return _points.begin();
271 return _points.end();
277 if constexpr (std::is_arithmetic_v<TypeX>)
285 _range_x.min = front().x;
286 _range_x.max = _range_x.min;
287 for (
const auto& p : _points)
289 _range_x.min = std::min(_range_x.min, p.x);
290 _range_x.max = std::max(_range_x.max, p.x);
292 _range_x_dirty =
false;
302 if constexpr (std::is_arithmetic_v<Value>)
310 _range_y.min = front().y;
311 _range_y.max = _range_y.min;
312 for (
const auto& p : _points)
314 _range_y.min = std::min(_range_y.min, p.y);
315 _range_y.max = std::max(_range_y.max, p.y);
317 _range_y_dirty =
false;
332 if constexpr (std::is_arithmetic_v<TypeX>)
340 if constexpr (std::is_arithmetic_v<Value>)
349 _points.emplace_back(p);
352 virtual void insert(Iterator it, Point&& p)
354 if constexpr (std::is_arithmetic_v<TypeX>)
362 if constexpr (std::is_arithmetic_v<Value>)
371 _points.insert(it, p);
376 const auto& p = _points.front();
378 if constexpr (std::is_arithmetic_v<TypeX>)
380 if (!_range_x_dirty && (p.x == _range_x.max || p.x == _range_x.min))
382 _range_x_dirty =
true;
386 if constexpr (std::is_arithmetic_v<Value>)
388 if (!_range_y_dirty && (p.y == _range_y.max || p.y == _range_y.min))
390 _range_y_dirty =
true;
405 mutable std::shared_ptr<PlotGroup>
_group;
410 if constexpr (std::is_arithmetic_v<TypeX>)
414 _range_x_dirty =
false;
420 if (p.x > _range_x.
max)
424 else if (p.x < _range_x.
min)
430 _range_x_dirty =
true;
439 if constexpr (std::is_arithmetic_v<Value>)
443 if (p.y > _range_y.
max)
447 else if (p.y < _range_y.
min)
453 _range_y_dirty =
true;
std::shared_ptr< PlotGroup > Ptr
PlotData may or may not have a group. Think of PlotGroup as a way to say that certain set of series a...
std::shared_ptr< PlotGroup > _group
virtual void insert(Iterator it, Point &&p)
ConstIterator end() const
bool CheckType(PlotAttribute attr, const QVariant &value)
virtual bool isTimeseries() const
virtual RangeOpt rangeY() const
PlotGroup(const std::string &name)
virtual void pushUpdateRangeX(const Point &p)
virtual void pushUpdateRangeY(const Point &p)
std::deque< Point >::iterator Iterator
std::deque< Point >::const_iterator ConstIterator
std::optional< Range > RangeOpt
virtual size_t size() const
const Point & operator[](size_t index) const
const Point & front() const
Point(TypeX _x, Value _y)
QVariant attribute(PlotAttribute id) const
const Attributes & attributes() const
virtual RangeOpt rangeX() const
Point & operator[](size_t index)
std::deque< Point > _points
const T & move(const T &v)
QVariant attribute(const PlotAttribute &id) const
const PlotGroup::Ptr & group() const
const Point & at(size_t index) const
const Attributes & attributes() const
void setAttribute(PlotAttribute id, const QVariant &value)
virtual void pushBack(Point &&p)
const std::string & name() const
const std::string & plotName() const
const Point & back() const
void clonePoints(const PlotDataBase &other)
Attributes & attributes()
void setAttribute(const PlotAttribute &id, const QVariant &value)
virtual void pushBack(const Point &p)
std::unordered_map< PlotAttribute, QVariant > Attributes
PlotDataBase(const std::string &name, PlotGroup::Ptr group)
ConstIterator begin() const
Attributes & attributes()
void changeGroup(PlotGroup::Ptr group)