| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
|
| 5 |
#ifndef CHARTS_H |
| 6 |
#define CHARTS_H |
| 7 |
#include "model.h" |
| 8 |
#include <QtCore/QList> |
| 9 |
#include <QtCore/QString> |
| 10 |
#include <QtCore/QSharedPointer> |
| 11 |
#include <QtCharts/QChartGlobal> |
| 12 |
|
| 13 |
QT_BEGIN_NAMESPACE |
| 14 |
class QChart; |
| 15 |
QT_END_NAMESPACE |
| 16 |
|
| 17 |
QT_USE_NAMESPACE |
| 18 |
|
| 19 |
class Chart |
| 20 |
{ |
| 21 |
public: |
| 22 |
virtual ~Chart() {}; |
| 23 |
virtual QChart *createChart(const DataTable &table) = 0; |
| 24 |
virtual QString name() = 0; |
| 25 |
virtual QString category() = 0; |
| 26 |
virtual QString subCategory() = 0; |
| 27 |
|
| 28 |
}; |
| 29 |
|
| 30 |
namespace Charts |
| 31 |
{ |
| 32 |
|
| 33 |
typedef QList<Chart *> ChartList; |
| 34 |
|
| 35 |
inline ChartList &chartList() |
| 36 |
{ |
| 37 |
static ChartList list; |
| 38 |
return list; |
| 39 |
} |
| 40 |
|
| 41 |
inline bool findChart(Chart *chart) |
| 42 |
{ |
| 43 |
const ChartList &list = chartList(); |
| 44 |
if (list.contains(chart)) |
| 45 |
return true; |
| 46 |
|
| 47 |
for (Chart *item : list) { |
| 48 |
if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) |
| 49 |
return true; |
| 50 |
} |
| 51 |
return false; |
| 52 |
} |
| 53 |
|
| 54 |
inline void addChart(Chart *chart) |
| 55 |
{ |
| 56 |
ChartList &list = chartList(); |
| 57 |
if (!findChart(chart)) |
| 58 |
list.append(chart); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
template <class T> |
| 63 |
class ChartWrapper |
| 64 |
{ |
| 65 |
public: |
| 66 |
QSharedPointer<T> chart; |
| 67 |
ChartWrapper() : chart(new T) { Charts::addChart(chart.data()); } |
| 68 |
}; |
| 69 |
|
| 70 |
#define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; |
| 71 |
#define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName; |
| 72 |
|
| 73 |
#endif |