LeechCraft  0.6.70-13729-g7046a9d2a7
Modular cross-platform feature rich live environment.
plotitem.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #include <memory>
33 #include <functional>
34 #include <boost/optional.hpp>
35 #include <QtGlobal>
36 #include <QQuickPaintedItem>
37 #include "qmlconfig.h"
38 
39 class QwtPlot;
40 
41 namespace LC
42 {
43 namespace Util
44 {
45  class UTIL_QML_API PlotItem : public QQuickPaintedItem
46  {
47  Q_OBJECT
48 
49  Q_PROPERTY (QList<QPointF> points READ GetPoints WRITE SetPoints NOTIFY pointsChanged)
50 
51  Q_PROPERTY (QVariant multipoints READ GetMultipoints WRITE SetMultipoints NOTIFY multipointsChanged)
52 
53  Q_PROPERTY (double minXValue READ GetMinXValue WRITE SetMinXValue NOTIFY minXValueChanged)
54  Q_PROPERTY (double maxXValue READ GetMaxXValue WRITE SetMaxXValue NOTIFY maxXValueChanged)
55  Q_PROPERTY (double minYValue READ GetMinYValue WRITE SetMinYValue NOTIFY minYValueChanged)
56  Q_PROPERTY (double maxYValue READ GetMaxYValue WRITE SetMaxYValue NOTIFY maxYValueChanged)
57 
58  Q_PROPERTY (bool yGridEnabled READ GetYGridEnabled WRITE SetYGridEnabled NOTIFY yGridChanged)
59  Q_PROPERTY (bool yMinorGridEnabled READ GetYMinorGridEnabled WRITE SetYMinorGridEnabled NOTIFY yMinorGridChanged)
60 
61  Q_PROPERTY (double alpha READ GetAlpha WRITE SetAlpha NOTIFY alphaChanged)
62  Q_PROPERTY (QColor color READ GetColor WRITE SetColor NOTIFY colorChanged)
63  Q_PROPERTY (bool leftAxisEnabled READ GetLeftAxisEnabled WRITE SetLeftAxisEnabled NOTIFY leftAxisEnabledChanged)
64  Q_PROPERTY (bool bottomAxisEnabled READ GetBottomAxisEnabled WRITE SetBottomAxisEnabled NOTIFY bottomAxisEnabledChanged)
65  Q_PROPERTY (QString leftAxisTitle READ GetLeftAxisTitle WRITE SetLeftAxisTitle NOTIFY leftAxisTitleChanged)
66  Q_PROPERTY (QString bottomAxisTitle READ GetBottomAxisTitle WRITE SetBottomAxisTitle NOTIFY bottomAxisTitleChanged)
67 
68  Q_PROPERTY (QString plotTitle READ GetPlotTitle WRITE SetPlotTitle NOTIFY plotTitleChanged)
69 
70  Q_PROPERTY (QColor background READ GetBackground WRITE SetBackground NOTIFY backgroundChanged)
71  Q_PROPERTY (QColor textColor READ GetTextColor WRITE SetTextColor NOTIFY textColorChanged)
72  Q_PROPERTY (QColor gridLinesColor READ GetGridLinesColor WRITE SetGridLinesColor NOTIFY gridLinesColorChanged)
73 
74  Q_PROPERTY (int xExtent READ GetXExtent NOTIFY extentsChanged)
75  Q_PROPERTY (int yExtent READ GetYExtent NOTIFY extentsChanged)
76 
77  QList<QPointF> Points_;
78 
79  struct PointsSet
80  {
81  QColor Color_;
82  boost::optional<QColor> BrushColor_;
83  QList<QPointF> Points_;
84  };
85  QList<PointsSet> Multipoints_;
86 
87  double MinXValue_ = -1;
88  double MaxXValue_ = -1;
89  double MinYValue_ = -1;
90  double MaxYValue_ = -1;
91 
92  bool YGridEnabled_ = false;
93  bool YMinorGridEnabled_ = false;
94 
95  double Alpha_ = 0.3;
96 
97  QColor Color_;
98 
99  bool LeftAxisEnabled_ = false;
100  bool BottomAxisEnabled_ = false;
101 
102  QString LeftAxisTitle_;
103  QString BottomAxisTitle_;
104 
105  QString PlotTitle_;
106 
107  QColor BackgroundColor_;
108  QColor TextColor_;
109  QColor GridLinesColor_;
110 
111  int XExtent_ = 0;
112  int YExtent_ = 0;
113 
114  std::shared_ptr<QwtPlot> Plot_;
115  public:
116  PlotItem (QQuickItem* = 0);
117 
118  QList<QPointF> GetPoints () const;
119  void SetPoints (const QList<QPointF>&);
120 
121  QVariant GetMultipoints () const;
122  void SetMultipoints (const QVariant&);
123 
124  double GetMinXValue () const;
125  void SetMinXValue (double);
126  double GetMaxXValue () const;
127  void SetMaxXValue (double);
128  double GetMinYValue () const;
129  void SetMinYValue (double);
130  double GetMaxYValue () const;
131  void SetMaxYValue (double);
132 
133  bool GetYGridEnabled () const;
134  void SetYGridEnabled (bool);
135  bool GetYMinorGridEnabled () const;
136  void SetYMinorGridEnabled (bool);
137 
138  double GetAlpha () const;
139  void SetAlpha (double);
140 
141  QColor GetColor () const;
142  void SetColor (const QColor&);
143 
144  bool GetLeftAxisEnabled () const;
145  void SetLeftAxisEnabled (bool);
146  bool GetBottomAxisEnabled () const;
147  void SetBottomAxisEnabled (bool);
148 
149  QString GetLeftAxisTitle () const;
150  void SetLeftAxisTitle (const QString&);
151  QString GetBottomAxisTitle () const;
152  void SetBottomAxisTitle (const QString&);
153 
154  QString GetPlotTitle () const;
155  void SetPlotTitle (const QString&);
156 
157  QColor GetBackground () const;
158  void SetBackground (const QColor&);
159  QColor GetTextColor () const;
160  void SetTextColor (const QColor&);
161  QColor GetGridLinesColor () const;
162  void SetGridLinesColor (const QColor&);
163 
164  int GetXExtent () const;
165  int GetYExtent () const;
166 
167  void paint (QPainter*) override;
168  private:
169  template<typename T>
170  void SetNewValue (T val, T& ourVal, const std::function<void ()>& notifier);
171 
172  int CalcXExtent (QwtPlot&) const;
173  int CalcYExtent (QwtPlot&) const;
174  signals:
175  void pointsChanged ();
176  void multipointsChanged ();
177 
178  void minXValueChanged ();
179  void maxXValueChanged ();
180  void minYValueChanged ();
181  void maxYValueChanged ();
182 
183  void yGridChanged ();
184  void yMinorGridChanged ();
185 
186  void alphaChanged ();
187 
188  void colorChanged ();
189 
190  void leftAxisEnabledChanged ();
191  void bottomAxisEnabledChanged ();
192 
193  void leftAxisTitleChanged ();
194  void bottomAxisTitleChanged ();
195 
196  void plotTitleChanged ();
197 
198  void backgroundChanged ();
199  void textColorChanged ();
200  void gridLinesColorChanged ();
201 
202  void extentsChanged ();
203  };
204 }
205 }
#define UTIL_QML_API
Definition: qmlconfig.h:37
Definition: constants.h:35