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