35 #include <QStyleOption>
38 #include <qwt_plot_curve.h>
39 #include <qwt_plot_renderer.h>
40 #include <qwt_plot_grid.h>
49 PlotItem::PlotItem (QDeclarativeItem *parent)
50 : QDeclarativeItem { parent }
51 , Color_ {
"#FF4B10" }
53 setFlag (QGraphicsItem::ItemHasNoContents,
false);
74 for (
const auto& set : Multipoints_)
75 result << Util::MakeMap<QString, QVariant> ({
76 {
"color", QVariant::fromValue (set.Color_) },
77 {
"points", QVariant::fromValue (set.Points_) }
84 Multipoints_.clear ();
86 for (
const auto& set : variant.toList ())
88 const auto& map = set.toMap ();
89 Multipoints_.append ({
90 map [
"color"].toString (),
119 return YGridEnabled_;
124 SetNewValue (val, YGridEnabled_, [
this] { emit
yGridChanged (); });
129 return YMinorGridEnabled_;
155 SetNewValue (color, Color_, [
this] { emit
colorChanged (); });
160 return LeftAxisEnabled_;
170 return BottomAxisEnabled_;
180 return LeftAxisTitle_;
190 return BottomAxisTitle_;
210 return BackgroundColor_;
228 void PlotItem::paint (QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget*)
231 plot.setFrameShape (QFrame::NoFrame);
232 plot.enableAxis (QwtPlot::yLeft, LeftAxisEnabled_);
233 plot.enableAxis (QwtPlot::xBottom, BottomAxisEnabled_);
234 plot.setAxisTitle (QwtPlot::yLeft, LeftAxisTitle_);
235 plot.setAxisTitle (QwtPlot::xBottom, BottomAxisTitle_);
236 plot.resize (option->rect.size ());
238 auto setPaletteColor = [&plot] (
const QColor& color, QPalette::ColorRole role) ->
void
240 if (!color.isValid ())
243 auto pal = plot.palette ();
244 pal.setColor (role, { color });
245 plot.setPalette (pal);
249 setPaletteColor (TextColor_, QPalette::WindowText);
250 setPaletteColor (TextColor_, QPalette::Text);
252 if (!PlotTitle_.isEmpty ())
253 plot.setTitle (QwtText { PlotTitle_ });
255 if (MinYValue_ < MaxYValue_)
257 plot.setAxisAutoScale (QwtPlot::yLeft,
false);
258 plot.setAxisScale (QwtPlot::yLeft, MinYValue_, MaxYValue_);
260 plot.setAutoFillBackground (
false);
261 plot.setCanvasBackground (Qt::transparent);
265 auto grid =
new QwtPlotGrid;
266 grid->enableYMin (YMinorGridEnabled_);
267 grid->enableX (
false);
268 #if QWT_VERSION >= 0x060100
269 grid->setMinorPen (QPen (Qt::gray, 1, Qt::DashLine));
271 grid->setMinPen (QPen (Qt::gray, 1, Qt::DashLine));
273 grid->attach (&plot);
276 auto items = Multipoints_;
277 if (items.isEmpty ())
278 items.push_back ({ Color_, Points_ });
280 const auto ptsCount = items.first ().Points_.size ();
282 plot.setAxisScale (QwtPlot::xBottom, 0, ptsCount - 1);
284 std::vector<std::unique_ptr<QwtPlotCurve>> curves;
285 for (
const auto& item : items)
287 auto curve =
new QwtPlotCurve;
289 curve->setPen (QPen (item.Color_));
290 auto transpColor = item.Color_;
291 transpColor.setAlphaF (Alpha_);
292 curve->setBrush (transpColor);
294 curve->setRenderHint (QwtPlotItem::RenderAntialiased);
295 curve->attach (&plot);
297 curve->setSamples (item.Points_.toVector ());
301 QwtPlotRenderer {}.render (&plot, painter, option->rect);
305 void PlotItem::SetNewValue (T val, T& ourVal,
const std::function<
void ()>& notifier)
QList< QPointF > GetPoints() const
void leftAxisTitleChanged()
QColor GetTextColor() const
QString GetBottomAxisTitle() const
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
bool GetLeftAxisEnabled() const
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
bool GetYMinorGridEnabled() const
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 &)
void SetMinYValue(double)
QColor GetBackground() const
void bottomAxisTitleChanged()
void SetBottomAxisEnabled(bool)
void SetTextColor(const QColor &)