LeechCraft  0.6.70-9312-g4cc613a2df
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #if QT_VERSION < 0x050000
37 #include <QDeclarativeItem>
38 #else
39 #include <QQuickPaintedItem>
40 #endif
41 #include "qmlconfig.h"
42 
43 class QwtPlot;
44 
45 namespace LeechCraft
46 {
47 namespace Util
48 {
49  class UTIL_QML_API PlotItem : public QQuickPaintedItem
50  {
51  Q_OBJECT
52 
53  Q_PROPERTY (QList<QPointF> points READ GetPoints WRITE SetPoints NOTIFY pointsChanged)
54 
55  Q_PROPERTY (QVariant multipoints READ GetMultipoints WRITE SetMultipoints NOTIFY multipointsChanged)
56 
57  Q_PROPERTY (double minXValue READ GetMinXValue WRITE SetMinXValue NOTIFY minXValueChanged)
58  Q_PROPERTY (double maxXValue READ GetMaxXValue WRITE SetMaxXValue NOTIFY maxXValueChanged)
59  Q_PROPERTY (double minYValue READ GetMinYValue WRITE SetMinYValue NOTIFY minYValueChanged)
60  Q_PROPERTY (double maxYValue READ GetMaxYValue WRITE SetMaxYValue NOTIFY maxYValueChanged)
61 
62  Q_PROPERTY (bool yGridEnabled READ GetYGridEnabled WRITE SetYGridEnabled NOTIFY yGridChanged)
63  Q_PROPERTY (bool yMinorGridEnabled READ GetYMinorGridEnabled WRITE SetYMinorGridEnabled NOTIFY yMinorGridChanged)
64 
65  Q_PROPERTY (double alpha READ GetAlpha WRITE SetAlpha NOTIFY alphaChanged)
66  Q_PROPERTY (QColor color READ GetColor WRITE SetColor NOTIFY colorChanged)
67  Q_PROPERTY (bool leftAxisEnabled READ GetLeftAxisEnabled WRITE SetLeftAxisEnabled NOTIFY leftAxisEnabledChanged)
68  Q_PROPERTY (bool bottomAxisEnabled READ GetBottomAxisEnabled WRITE SetBottomAxisEnabled NOTIFY bottomAxisEnabledChanged)
69  Q_PROPERTY (QString leftAxisTitle READ GetLeftAxisTitle WRITE SetLeftAxisTitle NOTIFY leftAxisTitleChanged)
70  Q_PROPERTY (QString bottomAxisTitle READ GetBottomAxisTitle WRITE SetBottomAxisTitle NOTIFY bottomAxisTitleChanged)
71 
72  Q_PROPERTY (QString plotTitle READ GetPlotTitle WRITE SetPlotTitle NOTIFY plotTitleChanged)
73 
74  Q_PROPERTY (QColor background READ GetBackground WRITE SetBackground NOTIFY backgroundChanged)
75  Q_PROPERTY (QColor textColor READ GetTextColor WRITE SetTextColor NOTIFY textColorChanged)
76  Q_PROPERTY (QColor gridLinesColor READ GetGridLinesColor WRITE SetGridLinesColor NOTIFY gridLinesColorChanged)
77 
78  Q_PROPERTY (int xExtent READ GetXExtent NOTIFY extentsChanged)
79  Q_PROPERTY (int yExtent READ GetYExtent NOTIFY extentsChanged)
80 
81  QList<QPointF> Points_;
82 
83  struct PointsSet
84  {
85  QColor Color_;
86  boost::optional<QColor> BrushColor_;
88  };
90 
91  double MinXValue_ = -1;
92  double MaxXValue_ = -1;
93  double MinYValue_ = -1;
94  double MaxYValue_ = -1;
95 
96  bool YGridEnabled_ = false;
97  bool YMinorGridEnabled_ = false;
98 
99  double Alpha_ = 0.3;
100 
101  QColor Color_;
102 
103  bool LeftAxisEnabled_ = false;
104  bool BottomAxisEnabled_ = false;
105 
106  QString LeftAxisTitle_;
108 
109  QString PlotTitle_;
110 
112  QColor TextColor_;
114 
115  int XExtent_ = 0;
116  int YExtent_ = 0;
117 
118  std::shared_ptr<QwtPlot> Plot_;
119  public:
120 #if QT_VERSION < 0x050000
121  PlotItem (QDeclarativeItem* = 0);
122 #else
123  PlotItem (QQuickItem* = 0);
124 #endif
125 
126  QList<QPointF> GetPoints () const;
127  void SetPoints (const QList<QPointF>&);
128 
129  QVariant GetMultipoints () const;
130  void SetMultipoints (const QVariant&);
131 
132  double GetMinXValue () const;
133  void SetMinXValue (double);
134  double GetMaxXValue () const;
135  void SetMaxXValue (double);
136  double GetMinYValue () const;
137  void SetMinYValue (double);
138  double GetMaxYValue () const;
139  void SetMaxYValue (double);
140 
141  bool GetYGridEnabled () const;
142  void SetYGridEnabled (bool);
143  bool GetYMinorGridEnabled () const;
144  void SetYMinorGridEnabled (bool);
145 
146  double GetAlpha () const;
147  void SetAlpha (double);
148 
149  QColor GetColor () const;
150  void SetColor (const QColor&);
151 
152  bool GetLeftAxisEnabled () const;
153  void SetLeftAxisEnabled (bool);
154  bool GetBottomAxisEnabled () const;
155  void SetBottomAxisEnabled (bool);
156 
157  QString GetLeftAxisTitle () const;
158  void SetLeftAxisTitle (const QString&);
159  QString GetBottomAxisTitle () const;
160  void SetBottomAxisTitle (const QString&);
161 
162  QString GetPlotTitle () const;
163  void SetPlotTitle (const QString&);
164 
165  QColor GetBackground () const;
166  void SetBackground (const QColor&);
167  QColor GetTextColor () const;
168  void SetTextColor (const QColor&);
169  QColor GetGridLinesColor () const;
170  void SetGridLinesColor (const QColor&);
171 
172  int GetXExtent () const;
173  int GetYExtent () const;
174 
175 #if QT_VERSION < 0x050000
176  void paint (QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
177 #else
178  void paint (QPainter*) override;
179 #endif
180  private:
181  template<typename T>
182  void SetNewValue (T val, T& ourVal, const std::function<void ()>& notifier);
183 
184  int CalcXExtent (QwtPlot&) const;
185  int CalcYExtent (QwtPlot&) const;
186  signals:
187  void pointsChanged ();
188  void multipointsChanged ();
189 
190  void minXValueChanged ();
191  void maxXValueChanged ();
192  void minYValueChanged ();
193  void maxYValueChanged ();
194 
195  void yGridChanged ();
196  void yMinorGridChanged ();
197 
198  void alphaChanged ();
199 
200  void colorChanged ();
201 
202  void leftAxisEnabledChanged ();
203  void bottomAxisEnabledChanged ();
204 
205  void leftAxisTitleChanged ();
206  void bottomAxisTitleChanged ();
207 
208  void plotTitleChanged ();
209 
210  void backgroundChanged ();
211  void textColorChanged ();
212  void gridLinesColorChanged ();
213 
214  void extentsChanged ();
215  };
216 }
217 }
QList< PointsSet > Multipoints_
Definition: plotitem.h:89
std::shared_ptr< QwtPlot > Plot_
Definition: plotitem.h:118
boost::optional< QColor > BrushColor_
Definition: plotitem.h:86
#define UTIL_QML_API
Definition: qmlconfig.h:37