LeechCraft  %{LEECHCRAFT_VERSION}
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 <functional>
33 #include <QDeclarativeItem>
34 #include "qmlconfig.h"
35 
36 namespace LeechCraft
37 {
38 namespace Util
39 {
40  class UTIL_QML_API PlotItem : public QDeclarativeItem
41  {
42  Q_OBJECT
43 
44  Q_PROPERTY (QList<QPointF> points READ GetPoints WRITE SetPoints NOTIFY pointsChanged)
45 
46  Q_PROPERTY (QVariant multipoints READ GetMultipoints WRITE SetMultipoints NOTIFY multipointsChanged)
47 
48  Q_PROPERTY (double minYValue READ GetMinYValue WRITE SetMinYValue NOTIFY minYValueChanged)
49  Q_PROPERTY (double maxYValue READ GetMaxYValue WRITE SetMaxYValue NOTIFY maxYValueChanged)
50 
51  Q_PROPERTY (bool yGridEnabled READ GetYGridEnabled WRITE SetYGridEnabled NOTIFY yGridChanged)
52  Q_PROPERTY (bool yMinorGridEnabled READ GetYMinorGridEnabled WRITE SetYMinorGridEnabled NOTIFY yMinorGridChanged)
53 
54  Q_PROPERTY (double alpha READ GetAlpha WRITE SetAlpha NOTIFY alphaChanged)
55  Q_PROPERTY (QColor color READ GetColor WRITE SetColor NOTIFY colorChanged)
56  Q_PROPERTY (bool leftAxisEnabled READ GetLeftAxisEnabled WRITE SetLeftAxisEnabled NOTIFY leftAxisEnabledChanged)
57  Q_PROPERTY (bool bottomAxisEnabled READ GetBottomAxisEnabled WRITE SetBottomAxisEnabled NOTIFY bottomAxisEnabledChanged)
58  Q_PROPERTY (QString leftAxisTitle READ GetLeftAxisTitle WRITE SetLeftAxisTitle NOTIFY leftAxisTitleChanged)
59  Q_PROPERTY (QString bottomAxisTitle READ GetBottomAxisTitle WRITE SetBottomAxisTitle NOTIFY bottomAxisTitleChanged)
60 
61  Q_PROPERTY (QString plotTitle READ GetPlotTitle WRITE SetPlotTitle NOTIFY plotTitleChanged)
62 
63  Q_PROPERTY (QColor background READ GetBackground WRITE SetBackground NOTIFY backgroundChanged)
64  Q_PROPERTY (QColor textColor READ GetTextColor WRITE SetTextColor NOTIFY textColorChanged)
65 
66  QList<QPointF> Points_;
67 
68  struct PointsSet
69  {
70  QColor Color_;
71  QList<QPointF> Points_;
72  };
73  QList<PointsSet> Multipoints_;
74 
75  double MinYValue_ = -1;
76  double MaxYValue_ = -1;
77 
78  bool YGridEnabled_ = false;
79  bool YMinorGridEnabled_ = false;
80 
81  double Alpha_ = 0.3;
82 
83  QColor Color_;
84 
85  bool LeftAxisEnabled_ = false;
86  bool BottomAxisEnabled_ = false;
87 
88  QString LeftAxisTitle_;
89  QString BottomAxisTitle_;
90 
91  QString PlotTitle_;
92 
93  QColor BackgroundColor_;
94  QColor TextColor_;
95  public:
96  PlotItem (QDeclarativeItem* = 0);
97 
98  QList<QPointF> GetPoints () const;
99  void SetPoints (const QList<QPointF>&);
100 
101  QVariant GetMultipoints () const;
102  void SetMultipoints (const QVariant&);
103 
104  double GetMinYValue () const;
105  void SetMinYValue (double);
106  double GetMaxYValue () const;
107  void SetMaxYValue (double);
108 
109  bool GetYGridEnabled () const;
110  void SetYGridEnabled (bool);
111  bool GetYMinorGridEnabled () const;
112  void SetYMinorGridEnabled (bool);
113 
114  double GetAlpha () const;
115  void SetAlpha (double);
116 
117  QColor GetColor () const;
118  void SetColor (const QColor&);
119 
120  bool GetLeftAxisEnabled () const;
121  void SetLeftAxisEnabled (bool);
122  bool GetBottomAxisEnabled () const;
123  void SetBottomAxisEnabled (bool);
124 
125  QString GetLeftAxisTitle () const;
126  void SetLeftAxisTitle (const QString&);
127  QString GetBottomAxisTitle () const;
128  void SetBottomAxisTitle (const QString&);
129 
130  QString GetPlotTitle () const;
131  void SetPlotTitle (const QString&);
132 
133  QColor GetBackground () const;
134  void SetBackground (const QColor&);
135  QColor GetTextColor () const;
136  void SetTextColor (const QColor&);
137 
138  void paint (QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
139  private:
140  template<typename T>
141  void SetNewValue (T val, T& ourVal, const std::function<void ()>& notifier);
142  signals:
143  void pointsChanged ();
144  void multipointsChanged ();
145 
146  void minYValueChanged ();
147  void maxYValueChanged ();
148 
149  void yGridChanged ();
150  void yMinorGridChanged ();
151 
152  void alphaChanged ();
153 
154  void colorChanged ();
155 
156  void leftAxisEnabledChanged ();
157  void bottomAxisEnabledChanged ();
158 
159  void leftAxisTitleChanged ();
160  void bottomAxisTitleChanged ();
161 
162  void plotTitleChanged ();
163 
164  void backgroundChanged ();
165  void textColorChanged ();
166  };
167 }
168 }
#define UTIL_QML_API
Definition: qmlconfig.h:37