35 #include <QStyleOption>
38 #include <qwt_plot_curve.h>
39 #include <qwt_plot_renderer.h>
40 #include <qwt_plot_grid.h>
41 #include <qwt_scale_draw.h>
42 #include <qwt_text_label.h>
51 #if QT_VERSION < 0x050000
52 PlotItem::PlotItem (QDeclarativeItem *
parent)
53 : QDeclarativeItem { parent }
56 : QQuickPaintedItem { parent }
58 , Color_ {
"#FF4B10" }
60 #if QT_VERSION < 0x050000
61 setFlag (QGraphicsItem::ItemHasNoContents,
false);
63 setFlag (ItemHasContents,
true);
86 result << Util::MakeMap<QString, QVariant> ({
87 {
"color", QVariant::fromValue (set.Color_) },
88 {
"points", QVariant::fromValue (set.Points_) }
97 for (
const auto& set : variant.toList ())
99 const auto& map = set.toMap ();
101 const auto& colorVar = map [
"color"];
102 const auto& pointsVar = map [
"points"];
104 if (!colorVar.canConvert<QString> () ||
107 qWarning () << Q_FUNC_INFO
110 qWarning () << Q_FUNC_INFO
111 <<
"ignoring this point";
116 map [
"color"].toString (),
294 #if QT_VERSION < 0x050000
295 void PlotItem::paint (QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget*)
297 const auto& rect = option->rect;
301 const auto& rect = contentsBoundingRect ().toRect ();
306 Plot_ = std::make_shared<QwtPlot> ();
307 Plot_->setFrameShape (QFrame::NoFrame);
308 Plot_->setFrameShadow (QFrame::Plain);
309 Plot_->setLineWidth (0);
310 Plot_->setMidLineWidth (0);
319 if (plot.size () != rect.size ())
320 plot.resize (rect.size ());
322 auto setPaletteColor = [&plot] (
const QColor&
color, QPalette::ColorRole role)
324 if (!color.isValid ())
327 auto pal = plot.palette ();
328 pal.setColor (role, { color });
329 plot.setPalette (pal);
333 setPaletteColor (
TextColor_, QPalette::WindowText);
341 plot.setAxisAutoScale (QwtPlot::yLeft,
false);
344 plot.setAutoFillBackground (
false);
345 plot.setCanvasBackground (Qt::transparent);
349 auto grid =
new QwtPlotGrid;
351 grid->enableX (
false);
352 #if QWT_VERSION >= 0x060100
359 grid->attach (&plot);
363 if (items.isEmpty ())
368 else if (
const auto ptsCount = items.first ().Points_.size ())
369 plot.setAxisScale (QwtPlot::xBottom, 0, ptsCount - 1);
371 std::vector<std::unique_ptr<QwtPlotCurve>> curves;
372 for (
const auto& item : items)
374 curves.emplace_back (
new QwtPlotCurve);
375 const auto curve = curves.back ().get ();
377 curve->setPen (QPen (item.Color_));
378 auto transpColor = item.Color_;
379 transpColor.setAlphaF (
Alpha_);
380 curve->setBrush (transpColor);
382 curve->setRenderHint (QwtPlotItem::RenderAntialiased);
383 curve->attach (&plot);
385 curve->setSamples (item.Points_.toVector ());
390 QwtPlotRenderer {}.render (&plot, painter, rect);
392 const auto xExtent = CalcXExtent (plot);
393 const auto yExtent = CalcYExtent (plot);
403 void PlotItem::SetNewValue (T val, T& ourVal,
const std::function<
void ()>& notifier)
413 int PlotItem::CalcXExtent (QwtPlot& plot)
const
417 result += plot.axisScaleDraw (QwtPlot::yLeft)->
418 extent (plot.axisFont (QwtPlot::yLeft));
422 int PlotItem::CalcYExtent (QwtPlot& plot)
const
426 result += plot.axisScaleDraw (QwtPlot::xBottom)->
427 extent (plot.axisFont (QwtPlot::xBottom));
429 result += plot.titleLabel ()->sizeHint ().height ();
void SetMinXValue(double)
QList< QPointF > GetPoints() const
void leftAxisTitleChanged()
QColor GetTextColor() const
double GetMinXValue() const
double GetMaxXValue() const
QString GetBottomAxisTitle() const
void gridLinesColorChanged()
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
bool GetLeftAxisEnabled() const
QList< PointsSet > Multipoints_
void SetGridLinesColor(const QColor &)
void leftAxisEnabledChanged()
void SetBottomAxisTitle(const QString &)
void SetLeftAxisTitle(const QString &)
void bottomAxisEnabledChanged()
void SetPoints(const QList< QPointF > &)
void SetYMinorGridEnabled(bool)
QString GetPlotTitle() const
QString GetLeftAxisTitle() const
void SetMultipoints(const QVariant &)
void SetMaxYValue(double)
bool GetBottomAxisEnabled() const
void SetMaxXValue(double)
bool GetYMinorGridEnabled() const
std::shared_ptr< QwtPlot > Plot_
double GetMaxYValue() const
void SetLeftAxisEnabled(bool)
double GetMinYValue() const
QVariant GetMultipoints() const
void SetYGridEnabled(bool)
void SetColor(const QColor &)
void SetBackground(const QColor &)
bool GetYGridEnabled() const
Q_DECLARE_METATYPE(LeechCraft::ANFieldData)
void SetPlotTitle(const QString &)
QColor GetGridLinesColor() const
void SetMinYValue(double)
QColor GetBackground() const
PlotItem(QDeclarativeItem *=0)
void bottomAxisTitleChanged()
void SetBottomAxisEnabled(bool)
void SetTextColor(const QColor &)