1 | /* |
2 | * This file is part of KQuickCharts |
3 | * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl> |
4 | * |
5 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #ifndef CHARTAXISSOURCE_H |
9 | #define CHARTAXISSOURCE_H |
10 | |
11 | #include "ChartDataSource.h" |
12 | |
13 | class XYChart; |
14 | |
15 | /** |
16 | * A data source that provides values from a chart's axis as data. |
17 | */ |
18 | class QUICKCHARTS_EXPORT ChartAxisSource : public ChartDataSource |
19 | { |
20 | Q_OBJECT |
21 | QML_ELEMENT |
22 | |
23 | public: |
24 | enum class Axis { XAxis, YAxis }; |
25 | Q_ENUM(Axis) |
26 | |
27 | /** |
28 | * Constructor |
29 | * |
30 | * @param parent TODO |
31 | */ |
32 | ChartAxisSource(QObject *parent = nullptr); |
33 | |
34 | Q_PROPERTY(XYChart *chart READ chart WRITE setChart NOTIFY chartChanged) |
35 | XYChart *chart() const; |
36 | Q_SLOT void setChart(XYChart *newChart); |
37 | Q_SIGNAL void chartChanged(); |
38 | |
39 | Q_PROPERTY(ChartAxisSource::Axis axis READ axis WRITE setAxis NOTIFY axisChanged) |
40 | ChartAxisSource::Axis axis() const; |
41 | Q_SLOT void setAxis(ChartAxisSource::Axis newAxis); |
42 | Q_SIGNAL void axisChanged(); |
43 | |
44 | Q_PROPERTY(int itemCount READ itemCount WRITE setItemCount NOTIFY itemCountChanged) |
45 | virtual int itemCount() const override; |
46 | Q_SLOT void setItemCount(int newItemCount); |
47 | Q_SIGNAL void itemCountChanged(); |
48 | |
49 | virtual QVariant item(int index) const override; |
50 | QVariant minimum() const override; |
51 | QVariant maximum() const override; |
52 | |
53 | private: |
54 | XYChart *m_chart = nullptr; |
55 | Axis m_axis = Axis::XAxis; |
56 | int m_itemCount = 2; |
57 | }; |
58 | |
59 | #endif // CHARTAXISSOURCE_H |
60 | |