| 1 | /**************************************************************************** | 
|---|---|
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 or (at your option) any later version | 
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by | 
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 | 
| 22 | ** included in the packaging of this file. Please review the following | 
| 23 | ** information to ensure the GNU General Public License requirements will | 
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 25 | ** | 
| 26 | ** $QT_END_LICENSE$ | 
| 27 | ** | 
| 28 | ****************************************************************************/ | 
| 29 | |
| 30 | |
| 31 | #ifndef CHARTS_H | 
| 32 | #define CHARTS_H | 
| 33 | #include "model.h" | 
| 34 | #include <QtCore/QList> | 
| 35 | #include <QtCore/QString> | 
| 36 | #include <QtCore/QSharedPointer> | 
| 37 | #include <QtCharts/QChartGlobal> | 
| 38 | |
| 39 | QT_CHARTS_BEGIN_NAMESPACE | 
| 40 | class QChart; | 
| 41 | QT_CHARTS_END_NAMESPACE | 
| 42 | |
| 43 | QT_CHARTS_USE_NAMESPACE | 
| 44 | |
| 45 | class Chart | 
| 46 | { | 
| 47 | public: | 
| 48 | virtual ~Chart() {}; | 
| 49 | virtual QChart *createChart(const DataTable &table) = 0; | 
| 50 | virtual QString name() = 0; | 
| 51 | virtual QString category() = 0; | 
| 52 | virtual QString subCategory() = 0; | 
| 53 | |
| 54 | }; | 
| 55 | |
| 56 | namespace Charts | 
| 57 | { | 
| 58 | |
| 59 | typedef QList<Chart *> ChartList; | 
| 60 | |
| 61 | inline ChartList &chartList() | 
| 62 | { | 
| 63 | static ChartList list; | 
| 64 | return list; | 
| 65 | } | 
| 66 | |
| 67 | inline bool findChart(Chart *chart) | 
| 68 | { | 
| 69 | ChartList &list = chartList(); | 
| 70 | if (list.contains(t: chart)) | 
| 71 | return true; | 
| 72 | |
| 73 | foreach (Chart *item, list) { | 
| 74 | if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) | 
| 75 | return true; | 
| 76 | } | 
| 77 | return false; | 
| 78 | } | 
| 79 | |
| 80 | inline void addChart(Chart *chart) | 
| 81 | { | 
| 82 | ChartList &list = chartList(); | 
| 83 | if (!findChart(chart)) | 
| 84 | list.append(t: chart); | 
| 85 | } | 
| 86 | } | 
| 87 | |
| 88 | template <class T> | 
| 89 | class ChartWrapper | 
| 90 | { | 
| 91 | public: | 
| 92 | QSharedPointer<T> chart; | 
| 93 | ChartWrapper() : chart(new T) { Charts::addChart(chart: chart.data()); } | 
| 94 | }; | 
| 95 | |
| 96 | #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; | 
| 97 | #define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName; | 
| 98 | |
| 99 | #endif | 
| 100 | 
