12#include <QStyleOption>
17#include <qwt_plot_curve.h>
18#include <qwt_plot_renderer.h>
19#include <qwt_plot_grid.h>
20#include <qwt_scale_draw.h>
21#include <qwt_text_label.h>
22#include <qwt_plot_canvas.h>
29 : QQuickPaintedItem { parent }
30 , Color_ { 0xFF, 0x4B, 0x10 }
53 for (
const auto& set : Multipoints_)
57 {
"color", QVariant::fromValue (set.Color_) },
58 {
"points", QVariant::fromValue (set.Points_) }
71 struct UnsupportedType
80 Multipoints_.clear ();
84 for (
const auto& set :
variant.toList ())
86 const auto& map = set.toMap ();
91 throw UnsupportedType {
"`color` expected to be a QString",
colorVar };
102 return var.toPointF ();
104 throw UnsupportedType {
"point element expected to be a QPointF",
var };
112 throw UnsupportedType {
"`brush` expected to be a QString",
brushVar };
119 catch (
const UnsupportedType&
ty)
122 <<
"invalid multipoints map: "
124 <<
" but got instead"
174 return YGridEnabled_;
184 return YMinorGridEnabled_;
215 return LeftAxisEnabled_;
225 return BottomAxisEnabled_;
235 return LeftAxisTitle_;
245 return BottomAxisTitle_;
265 return BackgroundColor_;
285 return GridLinesColor_;
309 Plot_ = std::make_shared<QwtPlot> ();
310 Plot_->setFrameShape (QFrame::NoFrame);
311 Plot_->setFrameShadow (QFrame::Plain);
312 Plot_->setLineWidth (0);
313 Plot_->setMidLineWidth (0);
316 canvas->setBorderRadius (0);
320 plot.enableAxis (QwtPlot::yLeft, LeftAxisEnabled_);
321 plot.enableAxis (QwtPlot::xBottom, BottomAxisEnabled_);
322 plot.setAxisTitle (QwtPlot::yLeft, LeftAxisTitle_);
323 plot.setAxisTitle (QwtPlot::xBottom, BottomAxisTitle_);
330 if (!
color.isValid ())
342 if (!PlotTitle_.isEmpty ())
345 if (MinYValue_ < MaxYValue_)
347 plot.setAxisAutoScale (QwtPlot::yLeft,
false);
348 plot.setAxisScale (QwtPlot::yLeft, MinYValue_, MaxYValue_);
350 plot.setAutoFillBackground (
false);
351 plot.setCanvasBackground (Qt::transparent);
356 grid->enableYMin (YMinorGridEnabled_);
357 grid->enableX (
false);
358 grid->setMajorPen (
QPen (GridLinesColor_, 1, Qt::SolidLine));
359 grid->setMinorPen (
QPen (GridLinesColor_, 1, Qt::DashLine));
363 auto items = Multipoints_;
364 if (
items.isEmpty ())
365 items.push_back ({ Color_, {}, Points_ });
367 if (MinXValue_ < MaxXValue_)
368 plot.setAxisScale (QwtPlot::xBottom, MinXValue_, MaxXValue_);
369 else if (
const auto ptsCount =
items.first ().Points_.size ())
372 std::vector<std::unique_ptr<QwtPlotCurve>>
curves;
380 if (
item.BrushColor_)
389 curve->setRenderHint (QwtPlotItem::RenderAntialiased);
392 curve->setSamples (
item.Points_.toVector ());
409 template<
typename T,
typename Notifier>
423 if (LeftAxisEnabled_)
424 result +=
plot.axisScaleDraw (QwtPlot::yLeft)->extent (
plot.axisFont (QwtPlot::yLeft));
431 if (BottomAxisEnabled_)
432 result +=
plot.axisScaleDraw (QwtPlot::xBottom)->extent (
plot.axisFont (QwtPlot::xBottom));
433 if (!PlotTitle_.isEmpty ())
434 result +=
plot.titleLabel ()->sizeHint ().height ();
void bottomAxisEnabledChanged()
void SetLeftAxisTitle(const QString &)
bool GetYGridEnabled() const
QColor GetBackground() const
double GetMaxYValue() const
void leftAxisTitleChanged()
void SetPlotTitle(const QString &)
void SetBottomAxisEnabled(bool)
void SetMinYValue(double)
double GetMinYValue() const
bool GetLeftAxisEnabled() const
void SetMaxXValue(double)
void SetMinXValue(double)
bool GetYMinorGridEnabled() const
QString GetLeftAxisTitle() const
QList< QPointF > GetPoints() const
void SetMaxYValue(double)
void SetTextColor(const QColor &)
QString GetBottomAxisTitle() const
QString GetPlotTitle() const
void leftAxisEnabledChanged()
void SetBackground(const QColor &)
double GetMinXValue() const
void SetMultipoints(const QVariant &)
void SetPoints(const QList< QPointF > &)
PlotItem(QQuickItem *=nullptr)
bool GetBottomAxisEnabled() const
QColor GetGridLinesColor() const
void SetLeftAxisEnabled(bool)
void SetBottomAxisTitle(const QString &)
QColor GetTextColor() const
void paint(QPainter *) override
void gridLinesColorChanged()
void SetGridLinesColor(const QColor &)
void SetYMinorGridEnabled(bool)
QVariant GetMultipoints() const
void SetColor(const QColor &)
double GetMaxXValue() const
void bottomAxisTitleChanged()
void SetYGridEnabled(bool)
Container< T > Filter(const Container< T > &c, F f)
auto Map(Container &&c, F &&f) noexcept(noexcept(std::is_nothrow_invocable_v< F, decltype(*c.begin())>))
Q_DECLARE_METATYPE(QVariantList *)