chart.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.5
4  Written in Qt
5 
6  chart.h - description
7  -------------------
8  copyright : (C) 2005-2019 by Dimitris B. Kalamaras
9  project site : https://socnetv.org
10 
11  ***************************************************************************/
12 
13 /*******************************************************************************
14 * This program is free software: you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation, either version 3 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
26 ********************************************************************************/
27 
28 #ifndef CHART_H
29 #define CHART_H
30 
31 #include <QObject>
32 #include <QtCharts/QChartGlobal>
33 #include <QtCharts/QChartView>
34 
35 QT_BEGIN_NAMESPACE
36 
37 QT_END_NAMESPACE
38 
39 
40 QT_CHARTS_BEGIN_NAMESPACE
41 class QSplineSeries;
42 class QChart;
43 class QAbstractAxis;
44 QT_CHARTS_END_NAMESPACE
45 
46 
47 
48 QT_CHARTS_USE_NAMESPACE
49 
50 class Chart : public QChartView
51 {
52  Q_OBJECT
53 public:
54  explicit Chart (QWidget *parent = Q_NULLPTR );
55  //explicit Chart ( QChart *ch = Q_NULLPTR, QWidget *parent = Q_NULLPTR );
56  ~Chart();
57 
58  void setTitle(const QString &title = QString::null, const QFont &font=QFont());
59  void addSeries(QAbstractSeries *series = Q_NULLPTR );
60  void appendToSeries (const QPointF &p);
61  void removeAllSeries();
62 
63  void createDefaultAxes();
64  QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical,
65  QAbstractSeries *series = Q_NULLPTR) const;
66  void removeAllAxes();
67 
68  void addAxis(QAbstractAxis *axis, Qt::Alignment alignment);
69 
70  void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = Q_NULLPTR);
71  void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = Q_NULLPTR);
72 
73  void setAxisXRange(const QVariant &min, const QVariant &max);
74  void setAxisXMin(const QVariant &min);
75  void setAxisYRange(const QVariant &min, const QVariant &max);
76  void setAxisYMin(const QVariant &min);
77 
78  void setAxesThemeDefault ();
79 
80  void setAxisXLabelsAngle (const int &angle);
81 
82  void setAxisXLabelFont(const QFont &font=QFont("Helvetica", 6 ));
83  void setAxisYLabelFont(const QFont &font=QFont("Helvetica", 6 ));
84 
85  void setAxisXLinePen(const QPen &pen = QPen(QColor("#d0d0d0"), 1,Qt::SolidLine) );
86  void setAxisYLinePen(const QPen &pen = QPen(QColor("#d0d0d0"), 1,Qt::SolidLine) );
87 
88  void setAxisXGridLinePen(const QPen &pen = QPen(QColor("#e0e0e0"), 1,Qt::DotLine) );
89  void setAxisYGridLinePen(const QPen &pen = QPen(QColor("#e0e0e0"), 1,Qt::DotLine) );
90 
91 
92  void setTheme(QChart::ChartTheme theme=QChart::ChartThemeQt);
93  void setThemeSmallWidget(const int minWidth, const int minHeight);
94 
95  void setChartBackgroundBrush(const QBrush & brush = QBrush(Qt::transparent));
96  void setChartBackgroundPen(const QBrush & brush = QBrush(Qt::transparent));
97  void setMargins(const QMargins &margins = QMargins());
98  void toggleLegend(const bool &toggle = false);
99 
100  void resetToTrivial();
101 
102  QPixmap getPixmap();
103 private:
104  QChart *m_chart;
105  QSplineSeries *m_series;
106 };
107 
108 #endif // CHART_H
void setChartBackgroundBrush(const QBrush &brush=QBrush(Qt::transparent))
Sets the background brush of the QChart If no brush defined, it uses a transparent brush...
Definition: chart.cpp:385
void setThemeSmallWidget(const int minWidth, const int minHeight)
Set the theme for when our chart widget is small.
Definition: chart.cpp:416
Definition: chart.h:50
void toggleLegend(const bool &toggle=false)
Toggle the legend of the QChart.
Definition: chart.cpp:370
void setAxisYGridLinePen(const QPen &pen=QPen(QColor("#e0e0e0"), 1, Qt::DotLine))
Set the grid line pen of the vertical axis.
Definition: chart.cpp:356
QSplineSeries * m_series
Definition: chart.h:105
void setAxisXMin(const QVariant &min)
Sets the minimum value shown on the horizontal axis.
Definition: chart.cpp:257
void createDefaultAxes()
Creates default axes. Must be called AFTER loading a series to the chart.
Definition: chart.cpp:143
QPixmap getPixmap()
Definition: chart.cpp:489
void setAxisY(QAbstractAxis *axis, QAbstractSeries *series=Q_NULLPTR)
Adds the axis axis to the chart and attaches it to the series series as a left-aligned horizontal axi...
Definition: chart.cpp:213
void setAxisX(QAbstractAxis *axis, QAbstractSeries *series=Q_NULLPTR)
Adds the axis axis to the chart and attaches it to the series series as a bottom-aligned horizontal a...
Definition: chart.cpp:198
void setAxisXRange(const QVariant &min, const QVariant &max)
Set the range of the (first) horizontal axis.
Definition: chart.cpp:246
~Chart()
Definition: chart.cpp:73
void setAxisXLabelFont(const QFont &font=QFont("Helvetica", 6))
Set the label font of the horizontal axis.
Definition: chart.cpp:298
void setAxisYMin(const QVariant &min)
Sets the minimum value shown on the vertical axis.
Definition: chart.cpp:281
void removeAllSeries()
Removes and deletes all series objects that have been added to the chart.
Definition: chart.cpp:123
void addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
Add Axis axis to the QChart. Does not delete previously attached axis.
Definition: chart.cpp:232
void removeAllAxes()
Removes all previously attached X,Y axes from the QChart.
Definition: chart.cpp:167
QList< QAbstractAxis * > axes(Qt::Orientations orientation=Qt::Horizontal|Qt::Vertical, QAbstractSeries *series=Q_NULLPTR) const
Definition: chart.cpp:150
void setTitle(const QString &title=QString::null, const QFont &font=QFont())
Set the title of the QChart.
Definition: chart.cpp:448
void setAxisXLabelsAngle(const int &angle)
Definition: chart.cpp:288
void setAxisXGridLinePen(const QPen &pen=QPen(QColor("#e0e0e0"), 1, Qt::DotLine))
Set the grid line pen of the horizontal axis.
Definition: chart.cpp:345
void setAxisYLabelFont(const QFont &font=QFont("Helvetica", 6))
Set the label font of the vertical axis.
Definition: chart.cpp:309
void setAxesThemeDefault()
Applies a simple theme to axes (default label fonts, line and grid line pen). WARNING: Axes must be a...
Definition: chart.cpp:459
void setChartBackgroundPen(const QBrush &brush=QBrush(Qt::transparent))
Sets the background pen of the QChart If no pen defined, it uses a transparent pen.
Definition: chart.cpp:396
void addSeries(QAbstractSeries *series=Q_NULLPTR)
Add QAbstractSeries series to chart If no series are passed, a new QSplineSeries is created with 1 po...
Definition: chart.cpp:87
Chart(QWidget *parent=Q_NULLPTR)
Definition: chart.cpp:52
void setTheme(QChart::ChartTheme theme=QChart::ChartThemeQt)
Set the theme of the QChart.
Definition: chart.cpp:406
void resetToTrivial()
Definition: chart.cpp:473
void setAxisYLinePen(const QPen &pen=QPen(QColor("#d0d0d0"), 1, Qt::SolidLine))
Set the line pen of the vertical axis.
Definition: chart.cpp:332
void setMargins(const QMargins &margins=QMargins())
Set the margins of the QChart.
Definition: chart.cpp:438
void appendToSeries(const QPointF &p)
Adds the data point p(qreal,qreal) to the series.
Definition: chart.cpp:113
void setAxisXLinePen(const QPen &pen=QPen(QColor("#d0d0d0"), 1, Qt::SolidLine))
Set the line pen of the horizontal axis.
Definition: chart.cpp:321
QChart * m_chart
Definition: chart.h:104
void setAxisYRange(const QVariant &min, const QVariant &max)
Set the range of the vertical axis.
Definition: chart.cpp:269