@@ -0,0 +1,44 | |||||
|
1 | #include "qchartglobal.h" | |||
|
2 | #include "qlegend.h" | |||
|
3 | #include "qseries.h" | |||
|
4 | ||||
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
6 | QLegend::QLegend(QGraphicsItem *parent) | |||
|
7 | : QGraphicsObject(parent) | |||
|
8 | ,mBoundingRect(0,0,0,0) | |||
|
9 | { | |||
|
10 | } | |||
|
11 | ||||
|
12 | ||||
|
13 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
|
14 | { | |||
|
15 | // TODO: | |||
|
16 | qDebug() << "QLegend::paint"; | |||
|
17 | foreach(QSeries* s, mSeriesList) { | |||
|
18 | for (int i=0; i<s->legendEntries().count(); i++) { | |||
|
19 | // Paint it... | |||
|
20 | //qDebug() << s->legendEntries().at(i).mName; | |||
|
21 | } | |||
|
22 | } | |||
|
23 | } | |||
|
24 | ||||
|
25 | QRectF QLegend::boundingRect() const | |||
|
26 | { | |||
|
27 | return mBoundingRect; | |||
|
28 | } | |||
|
29 | ||||
|
30 | void QLegend::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
31 | { | |||
|
32 | // TODO: append entries | |||
|
33 | mSeriesList.append(series); | |||
|
34 | } | |||
|
35 | ||||
|
36 | void QLegend::handleSeriesRemoved(QSeries* series) | |||
|
37 | { | |||
|
38 | // TODO: remove entries | |||
|
39 | mSeriesList.removeOne(series); | |||
|
40 | } | |||
|
41 | ||||
|
42 | ||||
|
43 | #include "moc_qlegend.cpp" | |||
|
44 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,36 | |||||
|
1 | #ifndef QLEGEND_H | |||
|
2 | #define QLEGEND_H | |||
|
3 | ||||
|
4 | #include "qchartglobal.h" | |||
|
5 | #include "qseries.h" | |||
|
6 | #include <QGraphicsObject> | |||
|
7 | ||||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | ||||
|
10 | class Domain; | |||
|
11 | ||||
|
12 | class QLegend : public QGraphicsObject | |||
|
13 | { | |||
|
14 | Q_OBJECT | |||
|
15 | public: | |||
|
16 | ||||
|
17 | explicit QLegend(QGraphicsItem *parent = 0); | |||
|
18 | ||||
|
19 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |||
|
20 | QRectF boundingRect() const; | |||
|
21 | ||||
|
22 | signals: | |||
|
23 | ||||
|
24 | public slots: | |||
|
25 | void handleSeriesAdded(QSeries* series,Domain* domain); | |||
|
26 | void handleSeriesRemoved(QSeries* series); | |||
|
27 | ||||
|
28 | private: | |||
|
29 | ||||
|
30 | QRectF mBoundingRect; | |||
|
31 | QList<QSeries*> mSeriesList; | |||
|
32 | }; | |||
|
33 | ||||
|
34 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
35 | ||||
|
36 | #endif // QLEGEND_H |
@@ -1,172 +1,172 | |||||
1 | #include <limits.h> |
|
1 | #include <limits.h> | |
2 | #include <QVector> |
|
2 | #include <QVector> | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 | #include "qbarset.h" |
|
5 | #include "qbarset.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | BarChartModel::BarChartModel(QStringList categories, QObject *parent) : |
|
9 | BarChartModel::BarChartModel(QStringList categories, QObject *parent) : | |
10 | QObject(parent) |
|
10 | QObject(parent) | |
11 | ,mCategory(categories) |
|
11 | ,mCategory(categories) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | QStringList BarChartModel::category() |
|
15 | QStringList BarChartModel::category() | |
16 | { |
|
16 | { | |
17 | return mCategory; |
|
17 | return mCategory; | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | void BarChartModel::addBarSet(QBarSet *set) |
|
20 | void BarChartModel::addBarSet(QBarSet *set) | |
21 | { |
|
21 | { | |
22 | mDataModel.append(set); |
|
22 | mDataModel.append(set); | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | void BarChartModel::removeBarSet(QBarSet *set) |
|
25 | void BarChartModel::removeBarSet(QBarSet *set) | |
26 | { |
|
26 | { | |
27 | if (mDataModel.contains(set)) { |
|
27 | if (mDataModel.contains(set)) { | |
28 | mDataModel.removeOne(set); |
|
28 | mDataModel.removeOne(set); | |
29 | } |
|
29 | } | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | QBarSet* BarChartModel::setAt(int index) |
|
32 | QBarSet* BarChartModel::setAt(int index) | |
33 | { |
|
33 | { | |
34 | return mDataModel.at(index); |
|
34 | return mDataModel.at(index); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | QList<QBarSet*> BarChartModel::barSets() |
|
37 | QList<QBarSet*> BarChartModel::barSets() | |
38 | { |
|
38 | { | |
39 | return mDataModel; |
|
39 | return mDataModel; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QList<QSeries::Legend> BarChartModel::legend() |
|
42 | QList<QSeries::LegendEntry> BarChartModel::legendEntries() | |
43 | { |
|
43 | { | |
44 | QList<QSeries::Legend> legend; |
|
44 | QList<QSeries::LegendEntry> legend; | |
45 |
|
45 | |||
46 | for (int i=0; i<mDataModel.count(); i++) { |
|
46 | for (int i=0; i<mDataModel.count(); i++) { | |
47 | QSeries::Legend l; |
|
47 | QSeries::LegendEntry l; | |
48 | l.mName = mDataModel.at(i)->name(); |
|
48 | l.mName = mDataModel.at(i)->name(); | |
49 | l.mPen = mDataModel.at(i)->pen(); |
|
49 | l.mPen = mDataModel.at(i)->pen(); | |
50 | legend.append(l); |
|
50 | legend.append(l); | |
51 | } |
|
51 | } | |
52 | return legend; |
|
52 | return legend; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | int BarChartModel::barsetCount() |
|
55 | int BarChartModel::barsetCount() | |
56 | { |
|
56 | { | |
57 | return mDataModel.count(); |
|
57 | return mDataModel.count(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | int BarChartModel::categoryCount() |
|
60 | int BarChartModel::categoryCount() | |
61 | { |
|
61 | { | |
62 | return mCategory.count(); |
|
62 | return mCategory.count(); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | qreal BarChartModel::min() |
|
65 | qreal BarChartModel::min() | |
66 | { |
|
66 | { | |
67 | Q_ASSERT(mDataModel.count() > 0); |
|
67 | Q_ASSERT(mDataModel.count() > 0); | |
68 | // TODO: make min and max members and update them when data changes. |
|
68 | // TODO: make min and max members and update them when data changes. | |
69 | // This is slower since they are checked every time, even if data is same since previous call. |
|
69 | // This is slower since they are checked every time, even if data is same since previous call. | |
70 | qreal min = INT_MAX; |
|
70 | qreal min = INT_MAX; | |
71 |
|
71 | |||
72 | for (int i=0; i <mDataModel.count(); i++) { |
|
72 | for (int i=0; i <mDataModel.count(); i++) { | |
73 | int itemCount = mDataModel.at(i)->count(); |
|
73 | int itemCount = mDataModel.at(i)->count(); | |
74 | for (int j=0; j<itemCount; j++) { |
|
74 | for (int j=0; j<itemCount; j++) { | |
75 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
75 | qreal temp = mDataModel.at(i)->valueAt(j); | |
76 | if (temp < min) { |
|
76 | if (temp < min) { | |
77 | min = temp; |
|
77 | min = temp; | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 | } |
|
80 | } | |
81 | return min; |
|
81 | return min; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | qreal BarChartModel::max() |
|
84 | qreal BarChartModel::max() | |
85 | { |
|
85 | { | |
86 | Q_ASSERT(mDataModel.count() > 0); |
|
86 | Q_ASSERT(mDataModel.count() > 0); | |
87 |
|
87 | |||
88 | // TODO: make min and max members and update them when data changes. |
|
88 | // TODO: make min and max members and update them when data changes. | |
89 | // This is slower since they are checked every time, even if data is same since previous call. |
|
89 | // This is slower since they are checked every time, even if data is same since previous call. | |
90 | qreal max = INT_MIN; |
|
90 | qreal max = INT_MIN; | |
91 |
|
91 | |||
92 | for (int i=0; i <mDataModel.count(); i++) { |
|
92 | for (int i=0; i <mDataModel.count(); i++) { | |
93 | int itemCount = mDataModel.at(i)->count(); |
|
93 | int itemCount = mDataModel.at(i)->count(); | |
94 | for (int j=0; j<itemCount; j++) { |
|
94 | for (int j=0; j<itemCount; j++) { | |
95 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
95 | qreal temp = mDataModel.at(i)->valueAt(j); | |
96 | if (temp > max) { |
|
96 | if (temp > max) { | |
97 | max = temp; |
|
97 | max = temp; | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | return max; |
|
102 | return max; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | qreal BarChartModel::valueAt(int set, int category) |
|
105 | qreal BarChartModel::valueAt(int set, int category) | |
106 | { |
|
106 | { | |
107 | if ((set < 0) || (set >= mDataModel.count())) { |
|
107 | if ((set < 0) || (set >= mDataModel.count())) { | |
108 | // No set, no value. |
|
108 | // No set, no value. | |
109 | return 0; |
|
109 | return 0; | |
110 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { |
|
110 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { | |
111 | // No category, no value. |
|
111 | // No category, no value. | |
112 | return 0; |
|
112 | return 0; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | return mDataModel.at(set)->valueAt(category); |
|
115 | return mDataModel.at(set)->valueAt(category); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | qreal BarChartModel::percentageAt(int set, int category) |
|
118 | qreal BarChartModel::percentageAt(int set, int category) | |
119 | { |
|
119 | { | |
120 | if ((set < 0) || (set >= mDataModel.count())) { |
|
120 | if ((set < 0) || (set >= mDataModel.count())) { | |
121 | // No set, no value. |
|
121 | // No set, no value. | |
122 | return 0; |
|
122 | return 0; | |
123 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { |
|
123 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { | |
124 | // No category, no value. |
|
124 | // No category, no value. | |
125 | return 0; |
|
125 | return 0; | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | qreal value = mDataModel.at(set)->valueAt(category); |
|
128 | qreal value = mDataModel.at(set)->valueAt(category); | |
129 | qreal total = categorySum(category); |
|
129 | qreal total = categorySum(category); | |
130 | if (0 == total) { |
|
130 | if (0 == total) { | |
131 | return 100.0; |
|
131 | return 100.0; | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | return value / total; |
|
134 | return value / total; | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 |
|
137 | |||
138 | qreal BarChartModel::categorySum(int category) |
|
138 | qreal BarChartModel::categorySum(int category) | |
139 | { |
|
139 | { | |
140 | qreal sum(0); |
|
140 | qreal sum(0); | |
141 | int count = mDataModel.count(); // Count sets |
|
141 | int count = mDataModel.count(); // Count sets | |
142 |
|
142 | |||
143 | for (int set = 0; set < count; set++) { |
|
143 | for (int set = 0; set < count; set++) { | |
144 | if (category < mDataModel.at(set)->count()) { |
|
144 | if (category < mDataModel.at(set)->count()) { | |
145 | sum += mDataModel.at(set)->valueAt(category); |
|
145 | sum += mDataModel.at(set)->valueAt(category); | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 | return sum; |
|
148 | return sum; | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | qreal BarChartModel::maxCategorySum() |
|
151 | qreal BarChartModel::maxCategorySum() | |
152 | { |
|
152 | { | |
153 | qreal max = INT_MIN; |
|
153 | qreal max = INT_MIN; | |
154 | int count = categoryCount(); |
|
154 | int count = categoryCount(); | |
155 |
|
155 | |||
156 | for (int col=0; col<count; col++) { |
|
156 | for (int col=0; col<count; col++) { | |
157 | qreal sum = categorySum(col); |
|
157 | qreal sum = categorySum(col); | |
158 | if (sum > max) { |
|
158 | if (sum > max) { | |
159 | max = sum; |
|
159 | max = sum; | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
162 | return max; |
|
162 | return max; | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | QString BarChartModel::categoryName(int category) |
|
165 | QString BarChartModel::categoryName(int category) | |
166 | { |
|
166 | { | |
167 | return mCategory.at(category); |
|
167 | return mCategory.at(category); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | #include "moc_barchartmodel_p.cpp" |
|
170 | #include "moc_barchartmodel_p.cpp" | |
171 |
|
171 | |||
172 | QTCOMMERCIALCHART_END_NAMESPACE |
|
172 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,59 | |||||
1 | #ifndef BARCHARTMODEL_H |
|
1 | #ifndef BARCHARTMODEL_H | |
2 | #define BARCHARTMODEL_H |
|
2 | #define BARCHARTMODEL_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QStringList> |
|
5 | #include <QStringList> | |
6 | #include "qchartglobal.h" |
|
6 | #include "qchartglobal.h" | |
7 | #include <qseries.h> |
|
7 | #include <qseries.h> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | // Model for bar chart. Internal class. |
|
11 | // Model for bar chart. Internal class. | |
12 | // TODO: Implement as QAbstractItemModel? |
|
12 | // TODO: Implement as QAbstractItemModel? | |
13 |
|
13 | |||
14 | class QBarSet; |
|
14 | class QBarSet; | |
15 |
|
15 | |||
16 | class BarChartModel : public QObject //, public QAbstractItemModel |
|
16 | class BarChartModel : public QObject //, public QAbstractItemModel | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | explicit BarChartModel(QStringList categories, QObject *parent = 0); |
|
20 | explicit BarChartModel(QStringList categories, QObject *parent = 0); | |
21 |
|
21 | |||
22 | QStringList category(); |
|
22 | QStringList category(); | |
23 | void addBarSet(QBarSet *set); |
|
23 | void addBarSet(QBarSet *set); | |
24 | void removeBarSet(QBarSet *set); |
|
24 | void removeBarSet(QBarSet *set); | |
25 | QBarSet *setAt(int index); |
|
25 | QBarSet *setAt(int index); | |
26 | QList<QBarSet*> barSets(); |
|
26 | QList<QBarSet*> barSets(); | |
27 |
|
27 | |||
28 | QList<QSeries::Legend> legend(); |
|
28 | QList<QSeries::LegendEntry> legendEntries(); | |
29 |
|
29 | |||
30 | int barsetCount(); // Number of sets in model |
|
30 | int barsetCount(); // Number of sets in model | |
31 | int categoryCount(); // Number of categories |
|
31 | int categoryCount(); // Number of categories | |
32 |
|
32 | |||
33 | qreal max(); // Maximum value of all sets |
|
33 | qreal max(); // Maximum value of all sets | |
34 | qreal min(); // Minimum value of all sets |
|
34 | qreal min(); // Minimum value of all sets | |
35 | qreal valueAt(int set, int category); |
|
35 | qreal valueAt(int set, int category); | |
36 | qreal percentageAt(int set, int category); |
|
36 | qreal percentageAt(int set, int category); | |
37 |
|
37 | |||
38 | qreal categorySum(int category); |
|
38 | qreal categorySum(int category); | |
39 | qreal maxCategorySum(); // returns maximum sum of sets in all categories. |
|
39 | qreal maxCategorySum(); // returns maximum sum of sets in all categories. | |
40 |
|
40 | |||
41 | QString categoryName(int category); |
|
41 | QString categoryName(int category); | |
42 |
|
42 | |||
43 | signals: |
|
43 | signals: | |
44 | void modelUpdated(); |
|
44 | void modelUpdated(); | |
45 |
|
45 | |||
46 | public slots: |
|
46 | public slots: | |
47 |
|
47 | |||
48 | private: |
|
48 | private: | |
49 |
|
49 | |||
50 | QList<QBarSet*> mDataModel; |
|
50 | QList<QBarSet*> mDataModel; | |
51 | QStringList mCategory; |
|
51 | QStringList mCategory; | |
52 |
|
52 | |||
53 | int mCurrentSet; |
|
53 | int mCurrentSet; | |
54 |
|
54 | |||
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |
58 |
|
58 | |||
59 | #endif // BARCHARTMODEL_H |
|
59 | #endif // BARCHARTMODEL_H |
@@ -1,227 +1,227 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "qbarseries.h" |
|
2 | #include "qbarseries.h" | |
3 | #include "qbarset.h" |
|
3 | #include "qbarset.h" | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | /*! |
|
8 | /*! | |
9 | \class QBarSeries |
|
9 | \class QBarSeries | |
10 | \brief part of QtCommercial chart API. |
|
10 | \brief part of QtCommercial chart API. | |
11 |
|
11 | |||
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
14 | by QStringList. |
|
14 | by QStringList. | |
15 |
|
15 | |||
16 | \mainclass |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \fn virtual QSeriesType QBarSeries::type() const |
|
22 | \fn virtual QSeriesType QBarSeries::type() const | |
23 | \brief Returns type of series. |
|
23 | \brief Returns type of series. | |
24 | \sa QSeries, QSeriesType |
|
24 | \sa QSeries, QSeriesType | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
29 | \brief \internal \a pos \a tip |
|
29 | \brief \internal \a pos \a tip | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
34 | QBarSeries is QObject which is a child of a \a parent. |
|
34 | QBarSeries is QObject which is a child of a \a parent. | |
35 | */ |
|
35 | */ | |
36 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) |
|
36 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) | |
37 | : QSeries(parent) |
|
37 | : QSeries(parent) | |
38 | ,mModel(new BarChartModel(categories, this)) |
|
38 | ,mModel(new BarChartModel(categories, this)) | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | Adds a set of bars to series. Takes ownership of \a set. |
|
43 | Adds a set of bars to series. Takes ownership of \a set. | |
44 | Connects the clicked(QString) and rightClicked(QString) signals |
|
44 | Connects the clicked(QString) and rightClicked(QString) signals | |
45 | of \a set to this series |
|
45 | of \a set to this series | |
46 | */ |
|
46 | */ | |
47 | void QBarSeries::addBarSet(QBarSet *set) |
|
47 | void QBarSeries::addBarSet(QBarSet *set) | |
48 | { |
|
48 | { | |
49 | mModel->addBarSet(set); |
|
49 | mModel->addBarSet(set); | |
50 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
50 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
51 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
51 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
55 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
56 | Disconnects the clicked(QString) and rightClicked(QString) signals |
|
56 | Disconnects the clicked(QString) and rightClicked(QString) signals | |
57 | of \a set from this series |
|
57 | of \a set from this series | |
58 | */ |
|
58 | */ | |
59 | void QBarSeries::removeBarSet(QBarSet *set) |
|
59 | void QBarSeries::removeBarSet(QBarSet *set) | |
60 | { |
|
60 | { | |
61 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
61 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
62 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
62 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
63 | mModel->removeBarSet(set); |
|
63 | mModel->removeBarSet(set); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Returns number of sets in series. |
|
67 | Returns number of sets in series. | |
68 | */ |
|
68 | */ | |
69 | int QBarSeries::barsetCount() |
|
69 | int QBarSeries::barsetCount() | |
70 | { |
|
70 | { | |
71 | return mModel->barsetCount(); |
|
71 | return mModel->barsetCount(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | Returns number of categories in series |
|
75 | Returns number of categories in series | |
76 | */ |
|
76 | */ | |
77 | int QBarSeries::categoryCount() |
|
77 | int QBarSeries::categoryCount() | |
78 | { |
|
78 | { | |
79 | return mModel->categoryCount(); |
|
79 | return mModel->categoryCount(); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | Returns a list of sets in series. Keeps ownership of sets. |
|
83 | Returns a list of sets in series. Keeps ownership of sets. | |
84 | */ |
|
84 | */ | |
85 | QList<QBarSet*> QBarSeries::barSets() |
|
85 | QList<QBarSet*> QBarSeries::barSets() | |
86 | { |
|
86 | { | |
87 | return mModel->barSets(); |
|
87 | return mModel->barSets(); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \internal \a index |
|
91 | \internal \a index | |
92 | */ |
|
92 | */ | |
93 | QBarSet* QBarSeries::barsetAt(int index) |
|
93 | QBarSet* QBarSeries::barsetAt(int index) | |
94 | { |
|
94 | { | |
95 | return mModel->setAt(index); |
|
95 | return mModel->setAt(index); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | Returns legend of series. |
|
99 | Returns legend of series. | |
100 | */ |
|
100 | */ | |
101 | QList<QSeries::Legend> QBarSeries::legend() |
|
101 | QList<QSeries::LegendEntry> QBarSeries::legendEntries() | |
102 | { |
|
102 | { | |
103 | return mModel->legend(); |
|
103 | return mModel->legendEntries(); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | /*! |
|
106 | /*! | |
107 | \internal \a category |
|
107 | \internal \a category | |
108 | */ |
|
108 | */ | |
109 | QString QBarSeries::categoryName(int category) |
|
109 | QString QBarSeries::categoryName(int category) | |
110 | { |
|
110 | { | |
111 | return mModel->categoryName(category); |
|
111 | return mModel->categoryName(category); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | Enables or disables tooltip depending on parameter \a enabled. |
|
115 | Enables or disables tooltip depending on parameter \a enabled. | |
116 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
116 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
117 | Calling without parameter \a enabled, enables the tooltip |
|
117 | Calling without parameter \a enabled, enables the tooltip | |
118 | */ |
|
118 | */ | |
119 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
119 | void QBarSeries::setToolTipEnabled(bool enabled) | |
120 | { |
|
120 | { | |
121 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
121 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
122 | if (enabled) { |
|
122 | if (enabled) { | |
123 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
123 | for (int i=0; i<mModel->barsetCount(); i++) { | |
124 | QBarSet *set = mModel->setAt(i); |
|
124 | QBarSet *set = mModel->setAt(i); | |
125 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
125 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
126 | } |
|
126 | } | |
127 | } else { |
|
127 | } else { | |
128 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
128 | for (int i=0; i<mModel->barsetCount(); i++) { | |
129 | QBarSet *set = mModel->setAt(i); |
|
129 | QBarSet *set = mModel->setAt(i); | |
130 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
130 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | Enables or disables separators depending on parameter \a enabled. |
|
136 | Enables or disables separators depending on parameter \a enabled. | |
137 | Separators are visual elements that are drawn between categories. |
|
137 | Separators are visual elements that are drawn between categories. | |
138 | Calling without parameter \a enabled, enables the separators |
|
138 | Calling without parameter \a enabled, enables the separators | |
139 | */ |
|
139 | */ | |
140 | void QBarSeries::setSeparatorsVisible(bool visible) |
|
140 | void QBarSeries::setSeparatorsVisible(bool visible) | |
141 | { |
|
141 | { | |
142 | mSeparatorsVisible = visible; |
|
142 | mSeparatorsVisible = visible; | |
143 | emit enableSeparators(visible); |
|
143 | emit enableSeparators(visible); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \internal \a category |
|
148 | \internal \a category | |
149 | */ |
|
149 | */ | |
150 | void QBarSeries::barsetClicked(QString category) |
|
150 | void QBarSeries::barsetClicked(QString category) | |
151 | { |
|
151 | { | |
152 | emit clicked(qobject_cast<QBarSet*>(sender()), category); |
|
152 | emit clicked(qobject_cast<QBarSet*>(sender()), category); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \internal \a category |
|
156 | \internal \a category | |
157 | */ |
|
157 | */ | |
158 | void QBarSeries::barsetRightClicked(QString category) |
|
158 | void QBarSeries::barsetRightClicked(QString category) | |
159 | { |
|
159 | { | |
160 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); |
|
160 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | \internal |
|
165 | \internal | |
166 | */ |
|
166 | */ | |
167 | qreal QBarSeries::min() |
|
167 | qreal QBarSeries::min() | |
168 | { |
|
168 | { | |
169 | return mModel->min(); |
|
169 | return mModel->min(); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \internal |
|
173 | \internal | |
174 | */ |
|
174 | */ | |
175 | qreal QBarSeries::max() |
|
175 | qreal QBarSeries::max() | |
176 | { |
|
176 | { | |
177 | return mModel->max(); |
|
177 | return mModel->max(); | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | \internal \a set \a category |
|
181 | \internal \a set \a category | |
182 | */ |
|
182 | */ | |
183 | qreal QBarSeries::valueAt(int set, int category) |
|
183 | qreal QBarSeries::valueAt(int set, int category) | |
184 | { |
|
184 | { | |
185 | return mModel->valueAt(set,category); |
|
185 | return mModel->valueAt(set,category); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \internal \a set \a category |
|
189 | \internal \a set \a category | |
190 | */ |
|
190 | */ | |
191 | qreal QBarSeries::percentageAt(int set, int category) |
|
191 | qreal QBarSeries::percentageAt(int set, int category) | |
192 | { |
|
192 | { | |
193 | return mModel->percentageAt(set,category); |
|
193 | return mModel->percentageAt(set,category); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | /*! |
|
196 | /*! | |
197 | \internal \a category |
|
197 | \internal \a category | |
198 | */ |
|
198 | */ | |
199 | qreal QBarSeries::categorySum(int category) |
|
199 | qreal QBarSeries::categorySum(int category) | |
200 | { |
|
200 | { | |
201 | return mModel->categorySum(category); |
|
201 | return mModel->categorySum(category); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | \internal |
|
205 | \internal | |
206 | */ |
|
206 | */ | |
207 | qreal QBarSeries::maxCategorySum() |
|
207 | qreal QBarSeries::maxCategorySum() | |
208 | { |
|
208 | { | |
209 | return mModel->maxCategorySum(); |
|
209 | return mModel->maxCategorySum(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | \internal |
|
213 | \internal | |
214 | */ |
|
214 | */ | |
215 | BarChartModel& QBarSeries::model() |
|
215 | BarChartModel& QBarSeries::model() | |
216 | { |
|
216 | { | |
217 | return *mModel; |
|
217 | return *mModel; | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | bool QBarSeries::separatorsVisible() |
|
220 | bool QBarSeries::separatorsVisible() | |
221 | { |
|
221 | { | |
222 | return mSeparatorsVisible; |
|
222 | return mSeparatorsVisible; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | #include "moc_qbarseries.cpp" |
|
225 | #include "moc_qbarseries.cpp" | |
226 |
|
226 | |||
227 | QTCOMMERCIALCHART_END_NAMESPACE |
|
227 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,72 | |||||
1 | #ifndef BARSERIES_H |
|
1 | #ifndef BARSERIES_H | |
2 | #define BARSERIES_H |
|
2 | #define BARSERIES_H | |
3 |
|
3 | |||
4 | #include "qseries.h" |
|
4 | #include "qseries.h" | |
5 | #include <QStringList> |
|
5 | #include <QStringList> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class QBarSet; |
|
9 | class QBarSet; | |
10 | class BarChartModel; |
|
10 | class BarChartModel; | |
11 | class BarCategory; |
|
11 | class BarCategory; | |
12 |
|
12 | |||
13 | // Container for series |
|
13 | // Container for series | |
14 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
14 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | QBarSeries(QStringList categories, QObject* parent=0); |
|
18 | QBarSeries(QStringList categories, QObject* parent=0); | |
19 |
|
19 | |||
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
21 |
|
21 | |||
22 | void addBarSet(QBarSet *set); // Takes ownership of set |
|
22 | void addBarSet(QBarSet *set); // Takes ownership of set | |
23 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
23 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
24 | int barsetCount(); |
|
24 | int barsetCount(); | |
25 | int categoryCount(); |
|
25 | int categoryCount(); | |
26 | QList<QBarSet*> barSets(); |
|
26 | QList<QBarSet*> barSets(); | |
27 | QList<QSeries::Legend> legend(); |
|
27 | QList<QSeries::LegendEntry> legendEntries(); | |
28 |
|
28 | |||
29 | public: |
|
29 | public: | |
30 | // TODO: Functions below this are not part of api and will be moved |
|
30 | // TODO: Functions below this are not part of api and will be moved | |
31 | // to private implementation, when we start using it |
|
31 | // to private implementation, when we start using it | |
32 | // TODO: TO PIMPL ---> |
|
32 | // TODO: TO PIMPL ---> | |
33 | QBarSet* barsetAt(int index); |
|
33 | QBarSet* barsetAt(int index); | |
34 | QString categoryName(int category); |
|
34 | QString categoryName(int category); | |
35 | qreal min(); |
|
35 | qreal min(); | |
36 | qreal max(); |
|
36 | qreal max(); | |
37 | qreal valueAt(int set, int category); |
|
37 | qreal valueAt(int set, int category); | |
38 | qreal percentageAt(int set, int category); |
|
38 | qreal percentageAt(int set, int category); | |
39 | qreal categorySum(int category); |
|
39 | qreal categorySum(int category); | |
40 | qreal maxCategorySum(); |
|
40 | qreal maxCategorySum(); | |
41 | BarChartModel& model(); |
|
41 | BarChartModel& model(); | |
42 | bool separatorsVisible(); |
|
42 | bool separatorsVisible(); | |
43 | // <--- TO PIMPL |
|
43 | // <--- TO PIMPL | |
44 |
|
44 | |||
45 | signals: |
|
45 | signals: | |
46 | //void changed(int index); |
|
46 | //void changed(int index); | |
47 | void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals |
|
47 | void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals | |
48 | void rightClicked(QBarSet* barset, QString category); |
|
48 | void rightClicked(QBarSet* barset, QString category); | |
49 |
|
49 | |||
50 | // TODO: internal signals, these to private implementation. |
|
50 | // TODO: internal signals, these to private implementation. | |
51 | // TODO: TO PIMPL ---> |
|
51 | // TODO: TO PIMPL ---> | |
52 | void enableSeparators(bool enable); |
|
52 | void enableSeparators(bool enable); | |
53 | void showToolTip(QPoint pos, QString tip); |
|
53 | void showToolTip(QPoint pos, QString tip); | |
54 | // <--- TO PIMPL |
|
54 | // <--- TO PIMPL | |
55 |
|
55 | |||
56 | public Q_SLOTS: |
|
56 | public Q_SLOTS: | |
57 | void setToolTipEnabled(bool enabled=true); // enables tooltips |
|
57 | void setToolTipEnabled(bool enabled=true); // enables tooltips | |
58 | void setSeparatorsVisible(bool visible=true); // enables separators between categories |
|
58 | void setSeparatorsVisible(bool visible=true); // enables separators between categories | |
59 |
|
59 | |||
60 | // TODO: TO PIMPL ---> |
|
60 | // TODO: TO PIMPL ---> | |
61 | void barsetClicked(QString category); |
|
61 | void barsetClicked(QString category); | |
62 | void barsetRightClicked(QString category); |
|
62 | void barsetRightClicked(QString category); | |
63 | // <--- TO PIMPL |
|
63 | // <--- TO PIMPL | |
64 |
|
64 | |||
65 | protected: |
|
65 | protected: | |
66 | BarChartModel* mModel; |
|
66 | BarChartModel* mModel; | |
67 | bool mSeparatorsVisible; |
|
67 | bool mSeparatorsVisible; | |
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
71 | |||
72 | #endif // BARSERIES_H |
|
72 | #endif // BARSERIES_H |
@@ -1,306 +1,321 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
|
3 | #include "qlegend.h" | |||
3 | #include "chartpresenter_p.h" |
|
4 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
5 | #include "chartdataset_p.h" | |
5 | #include <QGraphicsScene> |
|
6 | #include <QGraphicsScene> | |
6 | #include <QGraphicsSceneResizeEvent> |
|
7 | #include <QGraphicsSceneResizeEvent> | |
7 | #include <QDebug> |
|
8 | #include <QDebug> | |
8 |
|
9 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
11 | |||
11 | /*! |
|
12 | /*! | |
12 | \enum QChart::ChartTheme |
|
13 | \enum QChart::ChartTheme | |
13 |
|
14 | |||
14 | This enum describes the theme used by the chart. |
|
15 | This enum describes the theme used by the chart. | |
15 |
|
16 | |||
16 | \value ChartThemeDefault |
|
17 | \value ChartThemeDefault | |
17 | \value ChartThemeVanilla |
|
18 | \value ChartThemeVanilla | |
18 | \value ChartThemeIcy |
|
19 | \value ChartThemeIcy | |
19 | \value ChartThemeGrayscale |
|
20 | \value ChartThemeGrayscale | |
20 | \value ChartThemeScientific |
|
21 | \value ChartThemeScientific | |
21 | */ |
|
22 | */ | |
22 |
|
23 | |||
23 | /*! |
|
24 | /*! | |
24 | \enum QChart::AnimationOption |
|
25 | \enum QChart::AnimationOption | |
25 |
|
26 | |||
26 | For enabling/disabling animations. Defaults to NoAnimation. |
|
27 | For enabling/disabling animations. Defaults to NoAnimation. | |
27 |
|
28 | |||
28 | \value NoAnimation |
|
29 | \value NoAnimation | |
29 | \value GridAxisAnimations |
|
30 | \value GridAxisAnimations | |
30 | \value SeriesAnimations |
|
31 | \value SeriesAnimations | |
31 | \value AllAnimations |
|
32 | \value AllAnimations | |
32 | */ |
|
33 | */ | |
33 |
|
34 | |||
34 | /*! |
|
35 | /*! | |
35 | \class QChart |
|
36 | \class QChart | |
36 | \brief QtCommercial chart API. |
|
37 | \brief QtCommercial chart API. | |
37 |
|
38 | |||
38 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
39 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
39 | representation of different types of QChartSeries and other chart related objects like |
|
40 | representation of different types of QChartSeries and other chart related objects like | |
40 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
41 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
41 | convenience class QChartView instead of QChart. |
|
42 | convenience class QChartView instead of QChart. | |
42 | \sa QChartView |
|
43 | \sa QChartView | |
43 | */ |
|
44 | */ | |
44 |
|
45 | |||
45 | /*! |
|
46 | /*! | |
46 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
47 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
47 | */ |
|
48 | */ | |
48 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
49 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
49 | m_backgroundItem(0), |
|
50 | m_backgroundItem(0), | |
50 | m_titleItem(0), |
|
51 | m_titleItem(0), | |
51 | m_dataset(new ChartDataSet(this)), |
|
52 | m_dataset(new ChartDataSet(this)), | |
52 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
53 | m_presenter(new ChartPresenter(this,m_dataset)), | |
|
54 | m_legend(new QLegend(this)) // TODO: is this the parent we want the legend to have? | |||
53 | { |
|
55 | { | |
|
56 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |||
|
57 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |||
54 | } |
|
58 | } | |
55 |
|
59 | |||
56 | /*! |
|
60 | /*! | |
57 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
61 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
58 | */ |
|
62 | */ | |
59 | QChart::~QChart() |
|
63 | QChart::~QChart() | |
60 | { |
|
64 | { | |
|
65 | disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |||
|
66 | disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |||
61 | } |
|
67 | } | |
62 |
|
68 | |||
63 | /*! |
|
69 | /*! | |
64 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
70 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
65 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
71 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
66 | the y axis). |
|
72 | the y axis). | |
67 | */ |
|
73 | */ | |
68 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
74 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
69 | { |
|
75 | { | |
70 | m_dataset->addSeries(series, axisY); |
|
76 | m_dataset->addSeries(series, axisY); | |
71 | } |
|
77 | } | |
72 |
|
78 | |||
73 | /*! |
|
79 | /*! | |
74 | Removes the \a series specified in a perameter from the QChartView. |
|
80 | Removes the \a series specified in a perameter from the QChartView. | |
75 | It releses its ownership of the specified QChartSeries object. |
|
81 | It releses its ownership of the specified QChartSeries object. | |
76 | It does not delete the pointed QChartSeries data object |
|
82 | It does not delete the pointed QChartSeries data object | |
77 | \sa addSeries(), removeAllSeries() |
|
83 | \sa addSeries(), removeAllSeries() | |
78 | */ |
|
84 | */ | |
79 | void QChart::removeSeries(QSeries* series) |
|
85 | void QChart::removeSeries(QSeries* series) | |
80 | { |
|
86 | { | |
81 | m_dataset->removeSeries(series); |
|
87 | m_dataset->removeSeries(series); | |
82 | } |
|
88 | } | |
83 |
|
89 | |||
84 | /*! |
|
90 | /*! | |
85 | Removes all the QChartSeries that have been added to the QChartView |
|
91 | Removes all the QChartSeries that have been added to the QChartView | |
86 | It also deletes the pointed QChartSeries data objects |
|
92 | It also deletes the pointed QChartSeries data objects | |
87 | \sa addSeries(), removeSeries() |
|
93 | \sa addSeries(), removeSeries() | |
88 | */ |
|
94 | */ | |
89 | void QChart::removeAllSeries() |
|
95 | void QChart::removeAllSeries() | |
90 | { |
|
96 | { | |
91 | m_dataset->removeAllSeries(); |
|
97 | m_dataset->removeAllSeries(); | |
92 | } |
|
98 | } | |
93 |
|
99 | |||
94 | /*! |
|
100 | /*! | |
95 | Sets the \a brush that is used for painting the background of the chart area. |
|
101 | Sets the \a brush that is used for painting the background of the chart area. | |
96 | */ |
|
102 | */ | |
97 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
103 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
98 | { |
|
104 | { | |
99 | createChartBackgroundItem(); |
|
105 | createChartBackgroundItem(); | |
100 | m_backgroundItem->setBrush(brush); |
|
106 | m_backgroundItem->setBrush(brush); | |
101 | m_backgroundItem->update(); |
|
107 | m_backgroundItem->update(); | |
102 | } |
|
108 | } | |
103 |
|
109 | |||
104 | /*! |
|
110 | /*! | |
105 | Sets the \a pen that is used for painting the background of the chart area. |
|
111 | Sets the \a pen that is used for painting the background of the chart area. | |
106 | */ |
|
112 | */ | |
107 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
113 | void QChart::setChartBackgroundPen(const QPen& pen) | |
108 | { |
|
114 | { | |
109 | createChartBackgroundItem(); |
|
115 | createChartBackgroundItem(); | |
110 | m_backgroundItem->setPen(pen); |
|
116 | m_backgroundItem->setPen(pen); | |
111 | m_backgroundItem->update(); |
|
117 | m_backgroundItem->update(); | |
112 | } |
|
118 | } | |
113 |
|
119 | |||
114 | /*! |
|
120 | /*! | |
115 | Sets the chart \a title. The description text that is drawn above the chart. |
|
121 | Sets the chart \a title. The description text that is drawn above the chart. | |
116 | */ |
|
122 | */ | |
117 | void QChart::setChartTitle(const QString& title) |
|
123 | void QChart::setChartTitle(const QString& title) | |
118 | { |
|
124 | { | |
119 | createChartTitleItem(); |
|
125 | createChartTitleItem(); | |
120 | m_titleItem->setText(title); |
|
126 | m_titleItem->setText(title); | |
121 | } |
|
127 | } | |
122 |
|
128 | |||
123 | /*! |
|
129 | /*! | |
124 | Returns the chart title. The description text that is drawn above the chart. |
|
130 | Returns the chart title. The description text that is drawn above the chart. | |
125 | */ |
|
131 | */ | |
126 | QString QChart::chartTitle() const |
|
132 | QString QChart::chartTitle() const | |
127 | { |
|
133 | { | |
128 | if(m_titleItem) |
|
134 | if(m_titleItem) | |
129 | return m_titleItem->text(); |
|
135 | return m_titleItem->text(); | |
130 | else |
|
136 | else | |
131 | return QString(); |
|
137 | return QString(); | |
132 | } |
|
138 | } | |
133 |
|
139 | |||
134 | /*! |
|
140 | /*! | |
135 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
141 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
136 | */ |
|
142 | */ | |
137 | void QChart::setChartTitleFont(const QFont& font) |
|
143 | void QChart::setChartTitleFont(const QFont& font) | |
138 | { |
|
144 | { | |
139 | createChartTitleItem(); |
|
145 | createChartTitleItem(); | |
140 | m_titleItem->setFont(font); |
|
146 | m_titleItem->setFont(font); | |
141 | } |
|
147 | } | |
142 |
|
148 | |||
143 | /*! |
|
149 | /*! | |
144 | Sets the \a brush used for rendering the title text. |
|
150 | Sets the \a brush used for rendering the title text. | |
145 | */ |
|
151 | */ | |
146 | void QChart::setChartTitleBrush(const QBrush &brush) |
|
152 | void QChart::setChartTitleBrush(const QBrush &brush) | |
147 | { |
|
153 | { | |
148 | createChartTitleItem(); |
|
154 | createChartTitleItem(); | |
149 | m_titleItem->setBrush(brush); |
|
155 | m_titleItem->setBrush(brush); | |
150 | } |
|
156 | } | |
151 |
|
157 | |||
152 | /*! |
|
158 | /*! | |
153 | Returns the brush used for rendering the title text. |
|
159 | Returns the brush used for rendering the title text. | |
154 | */ |
|
160 | */ | |
155 | QBrush QChart::chartTitleBrush() |
|
161 | QBrush QChart::chartTitleBrush() | |
156 | { |
|
162 | { | |
157 | createChartTitleItem(); |
|
163 | createChartTitleItem(); | |
158 | return m_titleItem->brush(); |
|
164 | return m_titleItem->brush(); | |
159 | } |
|
165 | } | |
160 |
|
166 | |||
161 | void QChart::createChartBackgroundItem() |
|
167 | void QChart::createChartBackgroundItem() | |
162 | { |
|
168 | { | |
163 | if(!m_backgroundItem) { |
|
169 | if(!m_backgroundItem) { | |
164 | m_backgroundItem = new QGraphicsRectItem(this); |
|
170 | m_backgroundItem = new QGraphicsRectItem(this); | |
165 | m_backgroundItem->setPen(Qt::NoPen); |
|
171 | m_backgroundItem->setPen(Qt::NoPen); | |
166 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
172 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
167 | } |
|
173 | } | |
168 | } |
|
174 | } | |
169 |
|
175 | |||
170 | void QChart::createChartTitleItem() |
|
176 | void QChart::createChartTitleItem() | |
171 | { |
|
177 | { | |
172 | if(!m_titleItem) { |
|
178 | if(!m_titleItem) { | |
173 | m_titleItem = new QGraphicsSimpleTextItem(this); |
|
179 | m_titleItem = new QGraphicsSimpleTextItem(this); | |
174 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
180 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
175 | } |
|
181 | } | |
176 | } |
|
182 | } | |
177 |
|
183 | |||
178 | /*! |
|
184 | /*! | |
179 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
185 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
180 | \sa setMargin() |
|
186 | \sa setMargin() | |
181 | */ |
|
187 | */ | |
182 | int QChart::margin() const |
|
188 | int QChart::margin() const | |
183 | { |
|
189 | { | |
184 | return m_presenter->margin(); |
|
190 | return m_presenter->margin(); | |
185 | } |
|
191 | } | |
186 |
|
192 | |||
187 | /*! |
|
193 | /*! | |
188 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
194 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
189 | \sa margin() |
|
195 | \sa margin() | |
190 | */ |
|
196 | */ | |
191 | void QChart::setMargin(int margin) |
|
197 | void QChart::setMargin(int margin) | |
192 | { |
|
198 | { | |
193 | m_presenter->setMargin(margin); |
|
199 | m_presenter->setMargin(margin); | |
194 | } |
|
200 | } | |
195 |
|
201 | |||
196 | /*! |
|
202 | /*! | |
197 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
203 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
198 | \sa ChartTheme, chartTheme() |
|
204 | \sa ChartTheme, chartTheme() | |
199 | */ |
|
205 | */ | |
200 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
206 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
201 | { |
|
207 | { | |
202 | m_presenter->setChartTheme(theme); |
|
208 | m_presenter->setChartTheme(theme); | |
203 | } |
|
209 | } | |
204 |
|
210 | |||
205 | /*! |
|
211 | /*! | |
206 | Returns the theme enum used by the chart. |
|
212 | Returns the theme enum used by the chart. | |
207 | \sa ChartTheme, setChartTheme() |
|
213 | \sa ChartTheme, setChartTheme() | |
208 | */ |
|
214 | */ | |
209 | QChart::ChartTheme QChart::chartTheme() const |
|
215 | QChart::ChartTheme QChart::chartTheme() const | |
210 | { |
|
216 | { | |
211 | return m_presenter->chartTheme(); |
|
217 | return m_presenter->chartTheme(); | |
212 | } |
|
218 | } | |
213 |
|
219 | |||
214 | /*! |
|
220 | /*! | |
215 | Zooms in the view by a factor of 2 |
|
221 | Zooms in the view by a factor of 2 | |
216 | */ |
|
222 | */ | |
217 | void QChart::zoomIn() |
|
223 | void QChart::zoomIn() | |
218 | { |
|
224 | { | |
219 | m_presenter->zoomIn(); |
|
225 | m_presenter->zoomIn(); | |
220 | } |
|
226 | } | |
221 |
|
227 | |||
222 | /*! |
|
228 | /*! | |
223 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
229 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
224 | */ |
|
230 | */ | |
225 | void QChart::zoomIn(const QRectF& rect) |
|
231 | void QChart::zoomIn(const QRectF& rect) | |
226 | { |
|
232 | { | |
227 |
|
233 | |||
228 | if(!rect.isValid()) return; |
|
234 | if(!rect.isValid()) return; | |
229 | m_presenter->zoomIn(rect); |
|
235 | m_presenter->zoomIn(rect); | |
230 | } |
|
236 | } | |
231 |
|
237 | |||
232 | /*! |
|
238 | /*! | |
233 | Restores the view zoom level to the previous one. |
|
239 | Restores the view zoom level to the previous one. | |
234 | */ |
|
240 | */ | |
235 | void QChart::zoomOut() |
|
241 | void QChart::zoomOut() | |
236 | { |
|
242 | { | |
237 | m_presenter->zoomOut(); |
|
243 | m_presenter->zoomOut(); | |
238 | } |
|
244 | } | |
239 |
|
245 | |||
240 | /*! |
|
246 | /*! | |
241 | Resets to the default view. |
|
247 | Resets to the default view. | |
242 | */ |
|
248 | */ | |
243 | void QChart::zoomReset() |
|
249 | void QChart::zoomReset() | |
244 | { |
|
250 | { | |
245 | m_presenter->zoomReset(); |
|
251 | m_presenter->zoomReset(); | |
246 | } |
|
252 | } | |
247 |
|
253 | |||
248 | /*! |
|
254 | /*! | |
249 | Returns the pointer to the x axis object of the chart |
|
255 | Returns the pointer to the x axis object of the chart | |
250 | */ |
|
256 | */ | |
251 | QChartAxis* QChart::axisX() const |
|
257 | QChartAxis* QChart::axisX() const | |
252 | { |
|
258 | { | |
253 | return m_dataset->axisX(); |
|
259 | return m_dataset->axisX(); | |
254 | } |
|
260 | } | |
255 |
|
261 | |||
256 | /*! |
|
262 | /*! | |
257 | Returns the pointer to the y axis object of the chart |
|
263 | Returns the pointer to the y axis object of the chart | |
258 | */ |
|
264 | */ | |
259 | QChartAxis* QChart::axisY() const |
|
265 | QChartAxis* QChart::axisY() const | |
260 | { |
|
266 | { | |
261 | return m_dataset->axisY(); |
|
267 | return m_dataset->axisY(); | |
262 | } |
|
268 | } | |
263 |
|
269 | |||
264 | /*! |
|
270 | /*! | |
|
271 | Returns the legend object of the chart | |||
|
272 | */ | |||
|
273 | QLegend* QChart::legend() const | |||
|
274 | { | |||
|
275 | return m_legend; | |||
|
276 | } | |||
|
277 | ||||
|
278 | ||||
|
279 | /*! | |||
265 | Resizes and updates the chart area using the \a event data |
|
280 | Resizes and updates the chart area using the \a event data | |
266 | */ |
|
281 | */ | |
267 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
282 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
268 | { |
|
283 | { | |
269 |
|
284 | |||
270 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
285 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
271 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
286 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
272 |
|
287 | |||
273 | // recalculate title position |
|
288 | // recalculate title position | |
274 | if (m_titleItem) { |
|
289 | if (m_titleItem) { | |
275 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
290 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
276 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
291 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
277 | } |
|
292 | } | |
278 |
|
293 | |||
279 | //recalculate background gradient |
|
294 | //recalculate background gradient | |
280 | if (m_backgroundItem) { |
|
295 | if (m_backgroundItem) { | |
281 | m_backgroundItem->setRect(rect); |
|
296 | m_backgroundItem->setRect(rect); | |
282 | } |
|
297 | } | |
283 |
|
298 | |||
284 | QGraphicsWidget::resizeEvent(event); |
|
299 | QGraphicsWidget::resizeEvent(event); | |
285 | update(); |
|
300 | update(); | |
286 | } |
|
301 | } | |
287 |
|
302 | |||
288 | /*! |
|
303 | /*! | |
289 | Sets animation \a options for the chart |
|
304 | Sets animation \a options for the chart | |
290 | */ |
|
305 | */ | |
291 | void QChart::setAnimationOptions(AnimationOptions options) |
|
306 | void QChart::setAnimationOptions(AnimationOptions options) | |
292 | { |
|
307 | { | |
293 | m_presenter->setAnimationOptions(options); |
|
308 | m_presenter->setAnimationOptions(options); | |
294 | } |
|
309 | } | |
295 |
|
310 | |||
296 | /*! |
|
311 | /*! | |
297 | Returns animation options for the chart |
|
312 | Returns animation options for the chart | |
298 | */ |
|
313 | */ | |
299 | QChart::AnimationOptions QChart::animationOptions() const |
|
314 | QChart::AnimationOptions QChart::animationOptions() const | |
300 | { |
|
315 | { | |
301 | return m_presenter->animationOptions(); |
|
316 | return m_presenter->animationOptions(); | |
302 | } |
|
317 | } | |
303 |
|
318 | |||
304 | #include "moc_qchart.cpp" |
|
319 | #include "moc_qchart.cpp" | |
305 |
|
320 | |||
306 | QTCOMMERCIALCHART_END_NAMESPACE |
|
321 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,98 +1,102 | |||||
1 | #ifndef QCHART_H |
|
1 | #ifndef QCHART_H | |
2 | #define QCHART_H |
|
2 | #define QCHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qseries.h> |
|
5 | #include <qseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QSeries; |
|
15 | class QSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarPresenter; |
|
17 | class BarPresenter; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
|
23 | class QLegend; | |||
23 |
|
24 | |||
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
25 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
25 | { |
|
26 | { | |
26 | Q_OBJECT |
|
27 | Q_OBJECT | |
27 | public: |
|
28 | public: | |
28 | enum ChartTheme { |
|
29 | enum ChartTheme { | |
29 | ChartThemeDefault, |
|
30 | ChartThemeDefault, | |
30 | ChartThemeVanilla, |
|
31 | ChartThemeVanilla, | |
31 | ChartThemeIcy, |
|
32 | ChartThemeIcy, | |
32 | ChartThemeGrayscale, |
|
33 | ChartThemeGrayscale, | |
33 | ChartThemeScientific |
|
34 | ChartThemeScientific | |
34 | //ChartThemeUnnamed1 |
|
35 | //ChartThemeUnnamed1 | |
35 | /*! The default theme follows the GUI style of the Operating System */ |
|
36 | /*! The default theme follows the GUI style of the Operating System */ | |
36 | }; |
|
37 | }; | |
37 |
|
38 | |||
38 | enum AnimationOption { |
|
39 | enum AnimationOption { | |
39 | NoAnimation = 0x0, |
|
40 | NoAnimation = 0x0, | |
40 | GridAxisAnimations = 0x1, |
|
41 | GridAxisAnimations = 0x1, | |
41 | SeriesAnimations =0x2, |
|
42 | SeriesAnimations =0x2, | |
42 | AllAnimations = 0x3 |
|
43 | AllAnimations = 0x3 | |
43 | }; |
|
44 | }; | |
44 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
45 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
45 |
|
46 | |||
46 | public: |
|
47 | public: | |
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
48 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
48 | ~QChart(); |
|
49 | ~QChart(); | |
49 |
|
50 | |||
50 | void addSeries(QSeries* series, QChartAxis* axisY = 0); |
|
51 | void addSeries(QSeries* series, QChartAxis* axisY = 0); | |
51 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
52 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
52 | void removeAllSeries(); // deletes series and axis |
|
53 | void removeAllSeries(); // deletes series and axis | |
53 |
|
54 | |||
54 | void setMargin(int margin); |
|
55 | void setMargin(int margin); | |
55 | int margin() const; |
|
56 | int margin() const; | |
56 | void setChartTheme(QChart::ChartTheme theme); |
|
57 | void setChartTheme(QChart::ChartTheme theme); | |
57 | QChart::ChartTheme chartTheme() const; |
|
58 | QChart::ChartTheme chartTheme() const; | |
58 |
|
59 | |||
59 | void setChartTitle(const QString& title); |
|
60 | void setChartTitle(const QString& title); | |
60 | QString chartTitle() const; |
|
61 | QString chartTitle() const; | |
61 | void setChartTitleFont(const QFont& font); |
|
62 | void setChartTitleFont(const QFont& font); | |
62 | void setChartTitleBrush(const QBrush &brush); |
|
63 | void setChartTitleBrush(const QBrush &brush); | |
63 | QBrush chartTitleBrush(); |
|
64 | QBrush chartTitleBrush(); | |
64 | void setChartBackgroundBrush(const QBrush& brush); |
|
65 | void setChartBackgroundBrush(const QBrush& brush); | |
65 | void setChartBackgroundPen(const QPen& pen); |
|
66 | void setChartBackgroundPen(const QPen& pen); | |
66 |
|
67 | |||
67 | void setAnimationOptions(AnimationOptions options); |
|
68 | void setAnimationOptions(AnimationOptions options); | |
68 | AnimationOptions animationOptions() const; |
|
69 | AnimationOptions animationOptions() const; | |
69 |
|
70 | |||
70 | void zoomIn(); |
|
71 | void zoomIn(); | |
71 | void zoomIn(const QRectF& rect); |
|
72 | void zoomIn(const QRectF& rect); | |
72 | void zoomOut(); |
|
73 | void zoomOut(); | |
73 | void zoomReset(); |
|
74 | void zoomReset(); | |
74 |
|
75 | |||
75 | QChartAxis* axisX() const; |
|
76 | QChartAxis* axisX() const; | |
76 | QChartAxis* axisY() const; |
|
77 | QChartAxis* axisY() const; | |
77 |
|
78 | |||
|
79 | QLegend* legend() const; | |||
|
80 | ||||
78 | protected: |
|
81 | protected: | |
79 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
82 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
80 |
|
83 | |||
81 | private: |
|
84 | private: | |
82 | inline void createChartBackgroundItem(); |
|
85 | inline void createChartBackgroundItem(); | |
83 | inline void createChartTitleItem(); |
|
86 | inline void createChartTitleItem(); | |
84 |
|
87 | |||
85 | private: |
|
88 | private: | |
86 | Q_DISABLE_COPY(QChart) |
|
89 | Q_DISABLE_COPY(QChart) | |
87 | QGraphicsRectItem* m_backgroundItem; |
|
90 | QGraphicsRectItem* m_backgroundItem; | |
88 | QGraphicsSimpleTextItem* m_titleItem; |
|
91 | QGraphicsSimpleTextItem* m_titleItem; | |
89 | QRectF m_rect; |
|
92 | QRectF m_rect; | |
90 | ChartDataSet *m_dataset; |
|
93 | ChartDataSet *m_dataset; | |
91 | ChartPresenter *m_presenter; |
|
94 | ChartPresenter *m_presenter; | |
|
95 | QLegend* m_legend; | |||
92 | }; |
|
96 | }; | |
93 |
|
97 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
98 | QTCOMMERCIALCHART_END_NAMESPACE | |
95 |
|
99 | |||
96 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
100 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
97 |
|
101 | |||
98 | #endif |
|
102 | #endif |
@@ -1,55 +1,54 | |||||
1 | #ifndef QSERIES_H |
|
1 | #ifndef QSERIES_H | |
2 | #define QSERIES_H |
|
2 | #define QSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QAbstractItemModel> |
|
6 | #include <QAbstractItemModel> | |
7 | #include <QPen> |
|
7 | #include <QPen> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QSeries : public QObject |
|
11 | class QTCOMMERCIALCHART_EXPORT QSeries : public QObject | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | enum QSeriesType { |
|
15 | enum QSeriesType { | |
16 | SeriesTypeLine, |
|
16 | SeriesTypeLine, | |
17 | SeriesTypeArea, |
|
17 | SeriesTypeArea, | |
18 | SeriesTypeBar, |
|
18 | SeriesTypeBar, | |
19 | SeriesTypeStackedBar, |
|
19 | SeriesTypeStackedBar, | |
20 | SeriesTypePercentBar, |
|
20 | SeriesTypePercentBar, | |
21 | SeriesTypePie, |
|
21 | SeriesTypePie, | |
22 | SeriesTypeScatter, |
|
22 | SeriesTypeScatter, | |
23 | SeriesTypeSpline |
|
23 | SeriesTypeSpline | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 | // Helper class to contain legend and color for it |
|
26 | // Helper class to contain legend and color for it | |
27 | // TODO: This as private class? Or should we expose this to user of API |
|
27 | // TODO: This as private class? Or should we expose this to user of API | |
28 | class Legend { |
|
28 | class LegendEntry { | |
29 | public: |
|
29 | public: | |
30 | QString mName; |
|
30 | QString mName; | |
31 | QPen mPen; |
|
31 | QPen mPen; | |
32 | }; |
|
32 | }; | |
33 |
|
33 | |||
34 | protected: |
|
34 | protected: | |
35 | QSeries(QObject *parent = 0) : QObject(parent) {} |
|
35 | QSeries(QObject *parent = 0) : QObject(parent) {} | |
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | virtual ~QSeries() {} |
|
38 | virtual ~QSeries() {} | |
39 | virtual QSeriesType type() const = 0; |
|
39 | virtual QSeriesType type() const = 0; | |
40 | // TODO |
|
40 | // TODO | |
41 | virtual bool setModel(QAbstractItemModel* /*model*/) { return false; } |
|
41 | virtual bool setModel(QAbstractItemModel* /*model*/) { return false; } | |
42 |
|
42 | |||
43 | // TODO: should this be internal? |
|
43 | virtual QList<QSeries::LegendEntry> legendEntries() { QList<QSeries::LegendEntry> l; return l; } | |
44 | virtual QList<QSeries::Legend> legend() { QList<QSeries::Legend> l; return l; } |
|
|||
45 |
|
44 | |||
46 | void setTitle(QString title) { m_title = title; } |
|
45 | void setTitle(QString title) { m_title = title; } | |
47 | QString title() { return m_title; } |
|
46 | QString title() { return m_title; } | |
48 |
|
47 | |||
49 | private: |
|
48 | private: | |
50 | QString m_title; |
|
49 | QString m_title; | |
51 | }; |
|
50 | }; | |
52 |
|
51 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE | |
54 |
|
53 | |||
55 | #endif |
|
54 | #endif |
@@ -1,93 +1,95 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | CONFIG += debug_and_release |
|
7 | CONFIG += debug_and_release | |
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
9 | SOURCES += \ |
|
9 | SOURCES += \ | |
10 | chartdataset.cpp \ |
|
10 | chartdataset.cpp \ | |
11 | chartpresenter.cpp \ |
|
11 | chartpresenter.cpp \ | |
12 | charttheme.cpp \ |
|
12 | charttheme.cpp \ | |
13 | domain.cpp \ |
|
13 | domain.cpp \ | |
14 | qchart.cpp \ |
|
14 | qchart.cpp \ | |
15 | qchartview.cpp \ |
|
15 | qchartview.cpp \ | |
16 | qseries.cpp |
|
16 | qseries.cpp \ | |
|
17 | qlegend.cpp | |||
17 | PRIVATE_HEADERS += \ |
|
18 | PRIVATE_HEADERS += \ | |
18 | chartdataset_p.h \ |
|
19 | chartdataset_p.h \ | |
19 | chartitem_p.h \ |
|
20 | chartitem_p.h \ | |
20 | chartpresenter_p.h \ |
|
21 | chartpresenter_p.h \ | |
21 | charttheme_p.h \ |
|
22 | charttheme_p.h \ | |
22 | domain_p.h |
|
23 | domain_p.h | |
23 | PUBLIC_HEADERS += \ |
|
24 | PUBLIC_HEADERS += \ | |
24 | qchart.h \ |
|
25 | qchart.h \ | |
25 | qchartglobal.h \ |
|
26 | qchartglobal.h \ | |
26 | qseries.h \ |
|
27 | qseries.h \ | |
27 | qchartview.h |
|
28 | qchartview.h \ | |
28 |
|
29 | qlegend.h | ||
|
30 | ||||
29 | include(axis/axis.pri) |
|
31 | include(axis/axis.pri) | |
30 | include(xychart/xychart.pri) |
|
32 | include(xychart/xychart.pri) | |
31 | include(linechart/linechart.pri) |
|
33 | include(linechart/linechart.pri) | |
32 | include(areachart/areachart.pri) |
|
34 | include(areachart/areachart.pri) | |
33 | include(barchart/barchart.pri) |
|
35 | include(barchart/barchart.pri) | |
34 | include(piechart/piechart.pri) |
|
36 | include(piechart/piechart.pri) | |
35 | include(scatterseries/scatter.pri) |
|
37 | include(scatterseries/scatter.pri) | |
36 | include(splinechart/splinechart.pri) |
|
38 | include(splinechart/splinechart.pri) | |
37 |
|
39 | |||
38 | THEMES += themes/chartthemedefault_p.h \ |
|
40 | THEMES += themes/chartthemedefault_p.h \ | |
39 | themes/chartthemeicy_p.h \ |
|
41 | themes/chartthemeicy_p.h \ | |
40 | themes/chartthemegrayscale_p.h \ |
|
42 | themes/chartthemegrayscale_p.h \ | |
41 | themes/chartthemescientific_p.h \ |
|
43 | themes/chartthemescientific_p.h \ | |
42 | themes/chartthemevanilla_p.h |
|
44 | themes/chartthemevanilla_p.h | |
43 | HEADERS += $$PUBLIC_HEADERS |
|
45 | HEADERS += $$PUBLIC_HEADERS | |
44 | HEADERS += $$PRIVATE_HEADERS |
|
46 | HEADERS += $$PRIVATE_HEADERS | |
45 | HEADERS += $$THEMES |
|
47 | HEADERS += $$THEMES | |
46 | INCLUDEPATH += linechart \ |
|
48 | INCLUDEPATH += linechart \ | |
47 | barchart \ |
|
49 | barchart \ | |
48 | themes \ |
|
50 | themes \ | |
49 | . |
|
51 | . | |
50 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
52 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
51 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
53 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
52 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
54 | UI_DIR = $$CHART_BUILD_DIR/lib | |
53 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
55 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
54 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
56 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
55 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
57 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
56 | public_headers.files = $$PUBLIC_HEADERS |
|
58 | public_headers.files = $$PUBLIC_HEADERS | |
57 | target.path = $$[QT_INSTALL_LIBS] |
|
59 | target.path = $$[QT_INSTALL_LIBS] | |
58 | INSTALLS += target \ |
|
60 | INSTALLS += target \ | |
59 | public_headers |
|
61 | public_headers | |
60 | install_build_public_headers.name = bild_public_headers |
|
62 | install_build_public_headers.name = bild_public_headers | |
61 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
63 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
62 | install_build_public_headers.input = PUBLIC_HEADERS |
|
64 | install_build_public_headers.input = PUBLIC_HEADERS | |
63 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
65 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
64 | ${QMAKE_FILE_NAME} \ |
|
66 | ${QMAKE_FILE_NAME} \ | |
65 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
67 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
66 | install_build_public_headers.CONFIG += target_predeps \ |
|
68 | install_build_public_headers.CONFIG += target_predeps \ | |
67 | no_link |
|
69 | no_link | |
68 | install_build_private_headers.name = bild_private_headers |
|
70 | install_build_private_headers.name = bild_private_headers | |
69 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
71 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
70 | install_build_private_headers.input = PRIVATE_HEADERS |
|
72 | install_build_private_headers.input = PRIVATE_HEADERS | |
71 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
73 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
72 | ${QMAKE_FILE_NAME} \ |
|
74 | ${QMAKE_FILE_NAME} \ | |
73 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
75 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
74 | install_build_private_headers.CONFIG += target_predeps \ |
|
76 | install_build_private_headers.CONFIG += target_predeps \ | |
75 | no_link |
|
77 | no_link | |
76 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
78 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
77 | install_build_private_headers |
|
79 | install_build_private_headers | |
78 | chartversion.target = qchartversion_p.h |
|
80 | chartversion.target = qchartversion_p.h | |
79 | chartversion.commands = @echo \ |
|
81 | chartversion.commands = @echo \ | |
80 | "build_time" \ |
|
82 | "build_time" \ | |
81 | > \ |
|
83 | > \ | |
82 | $$chartversion.target; |
|
84 | $$chartversion.target; | |
83 | chartversion.depends = $$HEADERS \ |
|
85 | chartversion.depends = $$HEADERS \ | |
84 | $$SOURCES |
|
86 | $$SOURCES | |
85 | PRE_TARGETDEPS += qchartversion_p.h |
|
87 | PRE_TARGETDEPS += qchartversion_p.h | |
86 | QMAKE_CLEAN += qchartversion_p.h |
|
88 | QMAKE_CLEAN += qchartversion_p.h | |
87 | QMAKE_EXTRA_TARGETS += chartversion |
|
89 | QMAKE_EXTRA_TARGETS += chartversion | |
88 | unix:QMAKE_DISTCLEAN += -r \ |
|
90 | unix:QMAKE_DISTCLEAN += -r \ | |
89 | $$CHART_BUILD_HEADER_DIR \ |
|
91 | $$CHART_BUILD_HEADER_DIR \ | |
90 | $$CHART_BUILD_LIB_DIR |
|
92 | $$CHART_BUILD_LIB_DIR | |
91 | win32:QMAKE_DISTCLEAN += /Q \ |
|
93 | win32:QMAKE_DISTCLEAN += /Q \ | |
92 | $$CHART_BUILD_HEADER_DIR \ |
|
94 | $$CHART_BUILD_HEADER_DIR \ | |
93 | $$CHART_BUILD_LIB_DIR |
|
95 | $$CHART_BUILD_LIB_DIR |
General Comments 0
You need to be logged in to leave comments.
Login now