@@ -1,159 +1,169 | |||||
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 | void BarChartModel::insertBarSet(int i, QBarSet *set) | |||
|
33 | { | |||
|
34 | mDataModel.insert(i, set); | |||
|
35 | } | |||
|
36 | ||||
|
37 | void BarChartModel::insertCategory(int i, QString category) | |||
|
38 | { | |||
|
39 | mCategory.insert(i, category); | |||
|
40 | } | |||
|
41 | ||||
32 | QBarSet* BarChartModel::setAt(int index) |
|
42 | QBarSet* BarChartModel::setAt(int index) | |
33 | { |
|
43 | { | |
34 | return mDataModel.at(index); |
|
44 | return mDataModel.at(index); | |
35 | } |
|
45 | } | |
36 |
|
46 | |||
37 | QList<QBarSet*> BarChartModel::barSets() |
|
47 | QList<QBarSet*> BarChartModel::barSets() | |
38 | { |
|
48 | { | |
39 | return mDataModel; |
|
49 | return mDataModel; | |
40 | } |
|
50 | } | |
41 |
|
51 | |||
42 | int BarChartModel::barsetCount() |
|
52 | int BarChartModel::barsetCount() | |
43 | { |
|
53 | { | |
44 | return mDataModel.count(); |
|
54 | return mDataModel.count(); | |
45 | } |
|
55 | } | |
46 |
|
56 | |||
47 | int BarChartModel::categoryCount() |
|
57 | int BarChartModel::categoryCount() | |
48 | { |
|
58 | { | |
49 | return mCategory.count(); |
|
59 | return mCategory.count(); | |
50 | } |
|
60 | } | |
51 |
|
61 | |||
52 | qreal BarChartModel::min() |
|
62 | qreal BarChartModel::min() | |
53 | { |
|
63 | { | |
54 | Q_ASSERT(mDataModel.count() > 0); |
|
64 | Q_ASSERT(mDataModel.count() > 0); | |
55 | // TODO: make min and max members and update them when data changes. |
|
65 | // TODO: make min and max members and update them when data changes. | |
56 | // This is slower since they are checked every time, even if data is same since previous call. |
|
66 | // This is slower since they are checked every time, even if data is same since previous call. | |
57 | qreal min = INT_MAX; |
|
67 | qreal min = INT_MAX; | |
58 |
|
68 | |||
59 | for (int i=0; i <mDataModel.count(); i++) { |
|
69 | for (int i=0; i <mDataModel.count(); i++) { | |
60 | int itemCount = mDataModel.at(i)->count(); |
|
70 | int itemCount = mDataModel.at(i)->count(); | |
61 | for (int j=0; j<itemCount; j++) { |
|
71 | for (int j=0; j<itemCount; j++) { | |
62 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
72 | qreal temp = mDataModel.at(i)->valueAt(j); | |
63 | if (temp < min) { |
|
73 | if (temp < min) { | |
64 | min = temp; |
|
74 | min = temp; | |
65 | } |
|
75 | } | |
66 | } |
|
76 | } | |
67 | } |
|
77 | } | |
68 | return min; |
|
78 | return min; | |
69 | } |
|
79 | } | |
70 |
|
80 | |||
71 | qreal BarChartModel::max() |
|
81 | qreal BarChartModel::max() | |
72 | { |
|
82 | { | |
73 | Q_ASSERT(mDataModel.count() > 0); |
|
83 | Q_ASSERT(mDataModel.count() > 0); | |
74 |
|
84 | |||
75 | // TODO: make min and max members and update them when data changes. |
|
85 | // TODO: make min and max members and update them when data changes. | |
76 | // This is slower since they are checked every time, even if data is same since previous call. |
|
86 | // This is slower since they are checked every time, even if data is same since previous call. | |
77 | qreal max = INT_MIN; |
|
87 | qreal max = INT_MIN; | |
78 |
|
88 | |||
79 | for (int i=0; i <mDataModel.count(); i++) { |
|
89 | for (int i=0; i <mDataModel.count(); i++) { | |
80 | int itemCount = mDataModel.at(i)->count(); |
|
90 | int itemCount = mDataModel.at(i)->count(); | |
81 | for (int j=0; j<itemCount; j++) { |
|
91 | for (int j=0; j<itemCount; j++) { | |
82 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
92 | qreal temp = mDataModel.at(i)->valueAt(j); | |
83 | if (temp > max) { |
|
93 | if (temp > max) { | |
84 | max = temp; |
|
94 | max = temp; | |
85 | } |
|
95 | } | |
86 | } |
|
96 | } | |
87 | } |
|
97 | } | |
88 |
|
98 | |||
89 | return max; |
|
99 | return max; | |
90 | } |
|
100 | } | |
91 |
|
101 | |||
92 | qreal BarChartModel::valueAt(int set, int category) |
|
102 | qreal BarChartModel::valueAt(int set, int category) | |
93 | { |
|
103 | { | |
94 | if ((set < 0) || (set >= mDataModel.count())) { |
|
104 | if ((set < 0) || (set >= mDataModel.count())) { | |
95 | // No set, no value. |
|
105 | // No set, no value. | |
96 | return 0; |
|
106 | return 0; | |
97 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { |
|
107 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { | |
98 | // No category, no value. |
|
108 | // No category, no value. | |
99 | return 0; |
|
109 | return 0; | |
100 | } |
|
110 | } | |
101 |
|
111 | |||
102 | return mDataModel.at(set)->valueAt(category); |
|
112 | return mDataModel.at(set)->valueAt(category); | |
103 | } |
|
113 | } | |
104 |
|
114 | |||
105 | qreal BarChartModel::percentageAt(int set, int category) |
|
115 | qreal BarChartModel::percentageAt(int set, int category) | |
106 | { |
|
116 | { | |
107 | if ((set < 0) || (set >= mDataModel.count())) { |
|
117 | if ((set < 0) || (set >= mDataModel.count())) { | |
108 | // No set, no value. |
|
118 | // No set, no value. | |
109 | return 0; |
|
119 | return 0; | |
110 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { |
|
120 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { | |
111 | // No category, no value. |
|
121 | // No category, no value. | |
112 | return 0; |
|
122 | return 0; | |
113 | } |
|
123 | } | |
114 |
|
124 | |||
115 | qreal value = mDataModel.at(set)->valueAt(category); |
|
125 | qreal value = mDataModel.at(set)->valueAt(category); | |
116 | qreal total = categorySum(category); |
|
126 | qreal total = categorySum(category); | |
117 | if (0 == total) { |
|
127 | if (0 == total) { | |
118 | return 100.0; |
|
128 | return 100.0; | |
119 | } |
|
129 | } | |
120 |
|
130 | |||
121 | return value / total; |
|
131 | return value / total; | |
122 | } |
|
132 | } | |
123 |
|
133 | |||
124 |
|
134 | |||
125 | qreal BarChartModel::categorySum(int category) |
|
135 | qreal BarChartModel::categorySum(int category) | |
126 | { |
|
136 | { | |
127 | qreal sum(0); |
|
137 | qreal sum(0); | |
128 | int count = mDataModel.count(); // Count sets |
|
138 | int count = mDataModel.count(); // Count sets | |
129 |
|
139 | |||
130 | for (int set = 0; set < count; set++) { |
|
140 | for (int set = 0; set < count; set++) { | |
131 | if (category < mDataModel.at(set)->count()) { |
|
141 | if (category < mDataModel.at(set)->count()) { | |
132 | sum += mDataModel.at(set)->valueAt(category); |
|
142 | sum += mDataModel.at(set)->valueAt(category); | |
133 | } |
|
143 | } | |
134 | } |
|
144 | } | |
135 | return sum; |
|
145 | return sum; | |
136 | } |
|
146 | } | |
137 |
|
147 | |||
138 | qreal BarChartModel::maxCategorySum() |
|
148 | qreal BarChartModel::maxCategorySum() | |
139 | { |
|
149 | { | |
140 | qreal max = INT_MIN; |
|
150 | qreal max = INT_MIN; | |
141 | int count = categoryCount(); |
|
151 | int count = categoryCount(); | |
142 |
|
152 | |||
143 | for (int col=0; col<count; col++) { |
|
153 | for (int col=0; col<count; col++) { | |
144 | qreal sum = categorySum(col); |
|
154 | qreal sum = categorySum(col); | |
145 | if (sum > max) { |
|
155 | if (sum > max) { | |
146 | max = sum; |
|
156 | max = sum; | |
147 | } |
|
157 | } | |
148 | } |
|
158 | } | |
149 | return max; |
|
159 | return max; | |
150 | } |
|
160 | } | |
151 |
|
161 | |||
152 | QString BarChartModel::categoryName(int category) |
|
162 | QString BarChartModel::categoryName(int category) | |
153 | { |
|
163 | { | |
154 | return mCategory.at(category); |
|
164 | return mCategory.at(category); | |
155 | } |
|
165 | } | |
156 |
|
166 | |||
157 | #include "moc_barchartmodel_p.cpp" |
|
167 | #include "moc_barchartmodel_p.cpp" | |
158 |
|
168 | |||
159 | QTCOMMERCIALCHART_END_NAMESPACE |
|
169 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +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 | void insertBarSet(int i, QBarSet *set); | |||
|
26 | void insertCategory(int i, QString category); | |||
25 | QBarSet *setAt(int index); |
|
27 | QBarSet *setAt(int index); | |
26 | QList<QBarSet*> barSets(); |
|
28 | QList<QBarSet*> barSets(); | |
27 |
|
29 | |||
28 | int barsetCount(); // Number of sets in model |
|
30 | int barsetCount(); // Number of sets in model | |
29 | int categoryCount(); // Number of categories |
|
31 | int categoryCount(); // Number of categories | |
30 |
|
32 | |||
31 | qreal max(); // Maximum value of all sets |
|
33 | qreal max(); // Maximum value of all sets | |
32 | qreal min(); // Minimum value of all sets |
|
34 | qreal min(); // Minimum value of all sets | |
33 | qreal valueAt(int set, int category); |
|
35 | qreal valueAt(int set, int category); | |
34 | qreal percentageAt(int set, int category); |
|
36 | qreal percentageAt(int set, int category); | |
35 |
|
37 | |||
36 | qreal categorySum(int category); |
|
38 | qreal categorySum(int category); | |
37 | qreal maxCategorySum(); // returns maximum sum of sets in all categories. |
|
39 | qreal maxCategorySum(); // returns maximum sum of sets in all categories. | |
38 |
|
40 | |||
39 | QString categoryName(int category); |
|
41 | QString categoryName(int category); | |
40 |
|
42 | |||
41 | signals: |
|
43 | signals: | |
42 | void modelUpdated(); |
|
44 | void modelUpdated(); | |
43 |
|
45 | |||
44 | public slots: |
|
46 | public slots: | |
45 |
|
47 | |||
46 | private: |
|
48 | private: | |
47 |
|
49 | |||
48 | QList<QBarSet*> mDataModel; |
|
50 | QList<QBarSet*> mDataModel; | |
49 | QStringList mCategory; |
|
51 | QStringList mCategory; | |
50 |
|
52 | |||
51 | int mCurrentSet; |
|
53 | int mCurrentSet; | |
52 |
|
54 | |||
53 | }; |
|
55 | }; | |
54 |
|
56 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
58 | |||
57 | #endif // BARCHARTMODEL_H |
|
59 | #endif // BARCHARTMODEL_H |
@@ -1,88 +1,89 | |||||
1 | #include "barpresenter_p.h" |
|
1 | #include "barpresenter_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : |
|
9 | BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : | |
10 | BarPresenterBase(series, parent) |
|
10 | BarPresenterBase(series, parent) | |
11 | { |
|
11 | { | |
12 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); |
|
12 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); | |
|
13 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |||
13 | } |
|
14 | } | |
14 |
|
15 | |||
15 | void BarPresenter::layoutChanged() |
|
16 | void BarPresenter::layoutChanged() | |
16 | { |
|
17 | { | |
17 | // Scale bars to new layout |
|
18 | // Scale bars to new layout | |
18 | // Layout for bars: |
|
19 | // Layout for bars: | |
19 | if (mSeries->barsetCount() <= 0) { |
|
20 | if (mSeries->barsetCount() <= 0) { | |
20 | qDebug() << "No sets in model!"; |
|
21 | qDebug() << "No sets in model!"; | |
21 | return; |
|
22 | return; | |
22 | } |
|
23 | } | |
23 |
|
24 | |||
24 | if (childItems().count() == 0) { |
|
25 | if (childItems().count() == 0) { | |
25 | qDebug() << "WARNING: BarPresenter::layoutChanged called before graphics items are created!"; |
|
26 | qDebug() << "WARNING: BarPresenter::layoutChanged called before graphics items are created!"; | |
26 | return; |
|
27 | return; | |
27 | } |
|
28 | } | |
28 |
|
29 | |||
29 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
30 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
30 | int categoryCount = mSeries->categoryCount(); |
|
31 | int categoryCount = mSeries->categoryCount(); | |
31 | int setCount = mSeries->barsetCount(); |
|
32 | int setCount = mSeries->barsetCount(); | |
32 |
|
33 | |||
33 | qreal tW = mWidth; |
|
34 | qreal tW = mWidth; | |
34 | qreal tH = mHeight; |
|
35 | qreal tH = mHeight; | |
35 | qreal tM = mSeries->max(); |
|
36 | qreal tM = mSeries->max(); | |
36 | qreal scale = (tH/tM); |
|
37 | qreal scale = (tH/tM); | |
37 | qreal tC = categoryCount + 1; |
|
38 | qreal tC = categoryCount + 1; | |
38 | qreal categoryWidth = tW/tC; |
|
39 | qreal categoryWidth = tW/tC; | |
39 | mBarWidth = categoryWidth / (setCount+1); |
|
40 | mBarWidth = categoryWidth / (setCount+1); | |
40 |
|
41 | |||
41 | int itemIndex(0); |
|
42 | int itemIndex(0); | |
42 | for (int category=0; category < categoryCount; category++) { |
|
43 | for (int category=0; category < categoryCount; category++) { | |
43 | qreal xPos = categoryWidth * category + categoryWidth /2 + mBarWidth/2; |
|
44 | qreal xPos = categoryWidth * category + categoryWidth /2 + mBarWidth/2; | |
44 | qreal yPos = mHeight; |
|
45 | qreal yPos = mHeight; | |
45 | for (int set = 0; set < setCount; set++) { |
|
46 | for (int set = 0; set < setCount; set++) { | |
46 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
47 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
47 | Bar* bar = mBars.at(itemIndex); |
|
48 | Bar* bar = mBars.at(itemIndex); | |
48 |
|
49 | |||
49 | // TODO: width settable per bar? |
|
50 | // TODO: width settable per bar? | |
50 | bar->resize(mBarWidth, barHeight); |
|
51 | bar->resize(mBarWidth, barHeight); | |
51 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
52 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
52 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
53 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
53 | bar->setPos(xPos, yPos-barHeight); |
|
54 | bar->setPos(xPos, yPos-barHeight); | |
54 | itemIndex++; |
|
55 | itemIndex++; | |
55 | xPos += mBarWidth; |
|
56 | xPos += mBarWidth; | |
56 | } |
|
57 | } | |
57 | } |
|
58 | } | |
58 |
|
59 | |||
59 | // Position floating values |
|
60 | // Position floating values | |
60 | itemIndex = 0; |
|
61 | itemIndex = 0; | |
61 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
62 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
62 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth; |
|
63 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth; | |
63 | qreal yPos = mHeight; |
|
64 | qreal yPos = mHeight; | |
64 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
65 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
65 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
66 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
66 | BarValue* value = mFloatingValues.at(itemIndex); |
|
67 | BarValue* value = mFloatingValues.at(itemIndex); | |
67 |
|
68 | |||
68 | QBarSet* barSet = mSeries->barsetAt(set); |
|
69 | QBarSet* barSet = mSeries->barsetAt(set); | |
69 | value->resize(100,50); // TODO: proper layout for this. |
|
70 | value->resize(100,50); // TODO: proper layout for this. | |
70 | value->setPos(xPos, yPos-barHeight/2); |
|
71 | value->setPos(xPos, yPos-barHeight/2); | |
71 | value->setPen(barSet->floatingValuePen()); |
|
72 | value->setPen(barSet->floatingValuePen()); | |
72 |
|
73 | |||
73 | if (mSeries->valueAt(set,category) != 0) { |
|
74 | if (mSeries->valueAt(set,category) != 0) { | |
74 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
75 | value->setValueString(QString::number(mSeries->valueAt(set,category))); | |
75 | } else { |
|
76 | } else { | |
76 | value->setValueString(QString("")); |
|
77 | value->setValueString(QString("")); | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | itemIndex++; |
|
80 | itemIndex++; | |
80 | xPos += mBarWidth; |
|
81 | xPos += mBarWidth; | |
81 | } |
|
82 | } | |
82 | } |
|
83 | } | |
83 | update(); |
|
84 | update(); | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | #include "moc_barpresenter_p.cpp" |
|
87 | #include "moc_barpresenter_p.cpp" | |
87 |
|
88 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,331 +1,358 | |||||
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 | m_model = NULL; |
|
40 | m_model = NULL; | |
41 | m_mapCategories = -1; |
|
41 | m_mapCategories = -1; | |
42 | m_mapBarBottom = -1; |
|
42 | m_mapBarBottom = -1; | |
43 | m_mapBarTop = -1; |
|
43 | m_mapBarTop = -1; | |
44 | m_mapOrientation = Qt::Vertical; |
|
44 | m_mapOrientation = Qt::Vertical; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | Adds a set of bars to series. Takes ownership of \a set. |
|
48 | Adds a set of bars to series. Takes ownership of \a set. | |
49 | Connects the clicked(QString) and rightClicked(QString) signals |
|
49 | Connects the clicked(QString) and rightClicked(QString) signals | |
50 | of \a set to this series |
|
50 | of \a set to this series | |
51 | */ |
|
51 | */ | |
52 | void QBarSeries::addBarSet(QBarSet *set) |
|
52 | void QBarSeries::addBarSet(QBarSet *set) | |
53 | { |
|
53 | { | |
54 | mModel->addBarSet(set); |
|
54 | mModel->addBarSet(set); | |
55 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
55 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
56 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
56 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
57 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
57 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
61 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
62 | Disconnects the clicked(QString) and rightClicked(QString) signals |
|
62 | Disconnects the clicked(QString) and rightClicked(QString) signals | |
63 | of \a set from this series |
|
63 | of \a set from this series | |
64 | */ |
|
64 | */ | |
65 | void QBarSeries::removeBarSet(QBarSet *set) |
|
65 | void QBarSeries::removeBarSet(QBarSet *set) | |
66 | { |
|
66 | { | |
67 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
67 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
68 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
68 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
69 | mModel->removeBarSet(set); |
|
69 | mModel->removeBarSet(set); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
|
72 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |||
|
73 | { | |||
|
74 | mModel->insertBarSet(i, set); | |||
|
75 | // emit barsetChanged(); | |||
|
76 | } | |||
|
77 | ||||
|
78 | void QBarSeries::insertCategory(int i, QString category) | |||
|
79 | { | |||
|
80 | mModel->insertCategory(i, category); | |||
|
81 | } | |||
|
82 | ||||
72 | /*! |
|
83 | /*! | |
73 | Returns number of sets in series. |
|
84 | Returns number of sets in series. | |
74 | */ |
|
85 | */ | |
75 | int QBarSeries::barsetCount() |
|
86 | int QBarSeries::barsetCount() | |
76 | { |
|
87 | { | |
77 | // if(m_model) |
|
88 | // if(m_model) | |
78 | // return m_mapBarTop - m_mapBarBottom; |
|
89 | // return m_mapBarTop - m_mapBarBottom; | |
79 | // else |
|
90 | // else | |
80 |
|
|
91 | return mModel->barsetCount(); | |
81 | } |
|
92 | } | |
82 |
|
93 | |||
83 | /*! |
|
94 | /*! | |
84 | Returns number of categories in series |
|
95 | Returns number of categories in series | |
85 | */ |
|
96 | */ | |
86 | int QBarSeries::categoryCount() |
|
97 | int QBarSeries::categoryCount() | |
87 | { |
|
98 | { | |
88 | return mModel->categoryCount(); |
|
99 | return mModel->categoryCount(); | |
89 | } |
|
100 | } | |
90 |
|
101 | |||
91 | /*! |
|
102 | /*! | |
92 | Returns a list of sets in series. Keeps ownership of sets. |
|
103 | Returns a list of sets in series. Keeps ownership of sets. | |
93 | */ |
|
104 | */ | |
94 | QList<QBarSet*> QBarSeries::barSets() |
|
105 | QList<QBarSet*> QBarSeries::barSets() | |
95 | { |
|
106 | { | |
96 | return mModel->barSets(); |
|
107 | return mModel->barSets(); | |
97 | } |
|
108 | } | |
98 |
|
109 | |||
99 | /*! |
|
110 | /*! | |
100 | \internal \a index |
|
111 | \internal \a index | |
101 | */ |
|
112 | */ | |
102 | QBarSet* QBarSeries::barsetAt(int index) |
|
113 | QBarSet* QBarSeries::barsetAt(int index) | |
103 | { |
|
114 | { | |
104 | return mModel->setAt(index); |
|
115 | return mModel->setAt(index); | |
105 | } |
|
116 | } | |
106 |
|
117 | |||
107 | /*! |
|
118 | /*! | |
108 | \internal \a category |
|
119 | \internal \a category | |
109 | */ |
|
120 | */ | |
110 | QString QBarSeries::categoryName(int category) |
|
121 | QString QBarSeries::categoryName(int category) | |
111 | { |
|
122 | { | |
112 | return mModel->categoryName(category); |
|
123 | return mModel->categoryName(category); | |
113 | } |
|
124 | } | |
114 |
|
125 | |||
115 | /*! |
|
126 | /*! | |
116 | Enables or disables tooltip depending on parameter \a enabled. |
|
127 | Enables or disables tooltip depending on parameter \a enabled. | |
117 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
128 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
118 | Calling without parameter \a enabled, enables the tooltip |
|
129 | Calling without parameter \a enabled, enables the tooltip | |
119 | */ |
|
130 | */ | |
120 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
131 | void QBarSeries::setToolTipEnabled(bool enabled) | |
121 | { |
|
132 | { | |
122 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
133 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
123 | if (enabled) { |
|
134 | if (enabled) { | |
124 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
135 | for (int i=0; i<mModel->barsetCount(); i++) { | |
125 | QBarSet *set = mModel->setAt(i); |
|
136 | QBarSet *set = mModel->setAt(i); | |
126 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
137 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
127 | } |
|
138 | } | |
128 | } else { |
|
139 | } else { | |
129 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
140 | for (int i=0; i<mModel->barsetCount(); i++) { | |
130 | QBarSet *set = mModel->setAt(i); |
|
141 | QBarSet *set = mModel->setAt(i); | |
131 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
142 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
132 | } |
|
143 | } | |
133 | } |
|
144 | } | |
134 | } |
|
145 | } | |
135 |
|
146 | |||
136 |
|
147 | |||
137 | /*! |
|
148 | /*! | |
138 | \internal \a category |
|
149 | \internal \a category | |
139 | */ |
|
150 | */ | |
140 | void QBarSeries::barsetClicked(QString category) |
|
151 | void QBarSeries::barsetClicked(QString category) | |
141 | { |
|
152 | { | |
142 | emit clicked(qobject_cast<QBarSet*>(sender()), category); |
|
153 | emit clicked(qobject_cast<QBarSet*>(sender()), category); | |
143 | } |
|
154 | } | |
144 |
|
155 | |||
145 | /*! |
|
156 | /*! | |
146 | \internal \a category |
|
157 | \internal \a category | |
147 | */ |
|
158 | */ | |
148 | void QBarSeries::barsetRightClicked(QString category) |
|
159 | void QBarSeries::barsetRightClicked(QString category) | |
149 | { |
|
160 | { | |
150 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); |
|
161 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); | |
151 | } |
|
162 | } | |
152 |
|
163 | |||
153 |
|
164 | |||
154 | /*! |
|
165 | /*! | |
155 | \internal |
|
166 | \internal | |
156 | */ |
|
167 | */ | |
157 | qreal QBarSeries::min() |
|
168 | qreal QBarSeries::min() | |
158 | { |
|
169 | { | |
159 | return mModel->min(); |
|
170 | return mModel->min(); | |
160 | } |
|
171 | } | |
161 |
|
172 | |||
162 | /*! |
|
173 | /*! | |
163 | \internal |
|
174 | \internal | |
164 | */ |
|
175 | */ | |
165 | qreal QBarSeries::max() |
|
176 | qreal QBarSeries::max() | |
166 | { |
|
177 | { | |
167 | return mModel->max(); |
|
178 | return mModel->max(); | |
168 | } |
|
179 | } | |
169 |
|
180 | |||
170 | /*! |
|
181 | /*! | |
171 | \internal \a set \a category |
|
182 | \internal \a set \a category | |
172 | */ |
|
183 | */ | |
173 | qreal QBarSeries::valueAt(int set, int category) |
|
184 | qreal QBarSeries::valueAt(int set, int category) | |
174 | { |
|
185 | { | |
175 | return mModel->valueAt(set,category); |
|
186 | return mModel->valueAt(set,category); | |
176 | } |
|
187 | } | |
177 |
|
188 | |||
178 | /*! |
|
189 | /*! | |
179 | \internal \a set \a category |
|
190 | \internal \a set \a category | |
180 | */ |
|
191 | */ | |
181 | qreal QBarSeries::percentageAt(int set, int category) |
|
192 | qreal QBarSeries::percentageAt(int set, int category) | |
182 | { |
|
193 | { | |
183 | return mModel->percentageAt(set,category); |
|
194 | return mModel->percentageAt(set,category); | |
184 | } |
|
195 | } | |
185 |
|
196 | |||
186 | /*! |
|
197 | /*! | |
187 | \internal \a category |
|
198 | \internal \a category | |
188 | */ |
|
199 | */ | |
189 | qreal QBarSeries::categorySum(int category) |
|
200 | qreal QBarSeries::categorySum(int category) | |
190 | { |
|
201 | { | |
191 | return mModel->categorySum(category); |
|
202 | return mModel->categorySum(category); | |
192 | } |
|
203 | } | |
193 |
|
204 | |||
194 | /*! |
|
205 | /*! | |
195 | \internal |
|
206 | \internal | |
196 | */ |
|
207 | */ | |
197 | qreal QBarSeries::maxCategorySum() |
|
208 | qreal QBarSeries::maxCategorySum() | |
198 | { |
|
209 | { | |
199 | return mModel->maxCategorySum(); |
|
210 | return mModel->maxCategorySum(); | |
200 | } |
|
211 | } | |
201 |
|
212 | |||
202 | /*! |
|
213 | /*! | |
203 | \internal |
|
214 | \internal | |
204 | */ |
|
215 | */ | |
205 | BarChartModel& QBarSeries::model() |
|
216 | BarChartModel& QBarSeries::model() | |
206 | { |
|
217 | { | |
207 | return *mModel; |
|
218 | return *mModel; | |
208 | } |
|
219 | } | |
209 |
|
220 | |||
210 | bool QBarSeries::setModel(QAbstractItemModel* model) |
|
221 | bool QBarSeries::setModel(QAbstractItemModel* model) | |
211 | { |
|
222 | { | |
212 | // disconnect signals from old model |
|
223 | // disconnect signals from old model | |
213 | if(m_model) |
|
224 | if(m_model) | |
214 | { |
|
225 | { | |
215 | disconnect(m_model, 0, this, 0); |
|
226 | disconnect(m_model, 0, this, 0); | |
216 | m_mapCategories = -1; |
|
227 | m_mapCategories = -1; | |
217 | m_mapBarBottom = -1; |
|
228 | m_mapBarBottom = -1; | |
218 | m_mapBarTop = -1; |
|
229 | m_mapBarTop = -1; | |
219 | m_mapOrientation = Qt::Vertical; |
|
230 | m_mapOrientation = Qt::Vertical; | |
220 | } |
|
231 | } | |
221 |
|
232 | |||
222 | // set new model |
|
233 | // set new model | |
223 | if(model) |
|
234 | if(model) | |
224 | { |
|
235 | { | |
225 | m_model = model; |
|
236 | m_model = model; | |
226 | return true; |
|
237 | return true; | |
227 | } |
|
238 | } | |
228 | else |
|
239 | else | |
229 | { |
|
240 | { | |
230 | m_model = NULL; |
|
241 | m_model = NULL; | |
231 | return false; |
|
242 | return false; | |
232 | } |
|
243 | } | |
233 | } |
|
244 | } | |
234 |
|
245 | |||
235 | // TODO |
|
246 | // TODO | |
236 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
247 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
237 | { |
|
248 | { | |
238 | if (m_model == NULL) |
|
249 | if (m_model == NULL) | |
239 | return; |
|
250 | return; | |
240 | m_mapCategories = categories; |
|
251 | m_mapCategories = categories; | |
241 | m_mapBarBottom = bottomBoundry; |
|
252 | m_mapBarBottom = bottomBoundry; | |
242 | m_mapBarTop = topBoundry; |
|
253 | m_mapBarTop = topBoundry; | |
243 | m_mapOrientation = orientation; |
|
254 | m_mapOrientation = orientation; | |
244 |
|
255 | |||
245 | // connect the signals |
|
256 | // connect the signals | |
246 | if (m_mapOrientation == Qt::Vertical) |
|
257 | if (m_mapOrientation == Qt::Vertical) | |
247 | { |
|
258 | { | |
248 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
259 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
249 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
260 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
250 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
261 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
251 | } |
|
262 | } | |
252 | else |
|
263 | else | |
253 | { |
|
264 | { | |
254 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
265 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
255 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
266 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
256 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
267 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
257 | } |
|
268 | } | |
258 |
|
269 | |||
259 |
|
270 | |||
260 | // create the initial bars |
|
271 | // create the initial bars | |
261 | delete mModel; |
|
272 | delete mModel; | |
262 | if (m_mapOrientation == Qt::Vertical) |
|
273 | if (m_mapOrientation == Qt::Vertical) | |
263 | { |
|
274 | { | |
264 | QStringList categories; |
|
275 | QStringList categories; | |
265 | for (int k = 0; k < m_model->rowCount(); k++) |
|
276 | for (int k = 0; k < m_model->rowCount(); k++) | |
266 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
277 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
267 | mModel = new BarChartModel(categories, this); |
|
278 | mModel = new BarChartModel(categories, this); | |
268 |
|
279 | |||
269 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
280 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
270 | { |
|
281 | { | |
271 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
282 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
272 | for(int m = 0; m < m_model->rowCount(); m++) |
|
283 | for(int m = 0; m < m_model->rowCount(); m++) | |
273 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
284 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
274 | addBarSet(barSet); |
|
285 | addBarSet(barSet); | |
275 | } |
|
286 | } | |
276 | } |
|
287 | } | |
277 | else |
|
288 | else | |
278 | { |
|
289 | { | |
279 | QStringList categories; |
|
290 | QStringList categories; | |
280 | for (int k = 0; k < m_model->columnCount(); k++) |
|
291 | for (int k = 0; k < m_model->columnCount(); k++) | |
281 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
292 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
282 | mModel = new BarChartModel(categories, this); |
|
293 | mModel = new BarChartModel(categories, this); | |
283 |
|
294 | |||
284 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
295 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
285 | { |
|
296 | { | |
286 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
297 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
287 | for(int m = 0; m < m_model->columnCount(); m++) |
|
298 | for(int m = 0; m < m_model->columnCount(); m++) | |
288 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
299 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
289 | addBarSet(barSet); |
|
300 | addBarSet(barSet); | |
290 | } |
|
301 | } | |
291 | } |
|
302 | } | |
292 | } |
|
303 | } | |
293 |
|
304 | |||
294 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
305 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
295 | { |
|
306 | { | |
296 | Q_UNUSED(bottomRight) |
|
307 | Q_UNUSED(bottomRight) | |
297 |
|
308 | |||
298 | if (m_mapOrientation == Qt::Vertical) |
|
309 | if (m_mapOrientation == Qt::Vertical) | |
299 | { |
|
310 | { | |
300 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) |
|
311 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) | |
301 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
312 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
302 | // else if (topLeft.column() == m_mapCategories) |
|
313 | // else if (topLeft.column() == m_mapCategories) | |
303 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
314 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
304 | } |
|
315 | } | |
305 | else |
|
316 | else | |
306 | { |
|
317 | { | |
307 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) |
|
318 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) | |
308 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
319 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
309 | // else if (topLeft.row() == m_mapCategories) |
|
320 | // else if (topLeft.row() == m_mapCategories) | |
310 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
321 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
311 | } |
|
322 | } | |
312 | } |
|
323 | } | |
313 |
|
324 | |||
314 |
void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int |
|
325 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
315 | { |
|
326 | { | |
316 | // |
|
327 | if (m_mapOrientation == Qt::Vertical) | |
|
328 | { | |||
|
329 | insertCategory(start, QString("Row: %1").arg(start + 1)); | |||
|
330 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |||
|
331 | { | |||
|
332 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |||
|
333 | } | |||
|
334 | } | |||
|
335 | else | |||
|
336 | { | |||
|
337 | insertCategory(start, QString("Column: %1").arg(start + 1)); | |||
|
338 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |||
|
339 | { | |||
|
340 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |||
|
341 | } | |||
|
342 | } | |||
|
343 | emit restructuredBar(1); | |||
317 | } |
|
344 | } | |
318 |
|
345 | |||
319 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int /*start*/, int /*end*/) |
|
346 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int /*start*/, int /*end*/) | |
320 | { |
|
347 | { | |
321 | // |
|
348 | // | |
322 | } |
|
349 | } | |
323 |
|
350 | |||
324 | void QBarSeries::barsetChanged() |
|
351 | void QBarSeries::barsetChanged() | |
325 | { |
|
352 | { | |
326 | emit updatedBars(); |
|
353 | emit updatedBars(); | |
327 | } |
|
354 | } | |
328 |
|
355 | |||
329 | #include "moc_qbarseries.cpp" |
|
356 | #include "moc_qbarseries.cpp" | |
330 |
|
357 | |||
331 | QTCOMMERCIALCHART_END_NAMESPACE |
|
358 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,87 +1,90 | |||||
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 | void insertBarSet(int i, QBarSet *set); | |||
|
25 | void insertCategory(int i, QString category); | |||
24 | int barsetCount(); |
|
26 | int barsetCount(); | |
25 | int categoryCount(); |
|
27 | int categoryCount(); | |
26 | QList<QBarSet*> barSets(); |
|
28 | QList<QBarSet*> barSets(); | |
27 |
|
29 | |||
28 | bool setModel(QAbstractItemModel* model); |
|
30 | bool setModel(QAbstractItemModel* model); | |
29 | QAbstractItemModel* modelExt() {return m_model;} |
|
31 | QAbstractItemModel* modelExt() {return m_model;} | |
30 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
32 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
31 |
|
33 | |||
32 | public: |
|
34 | public: | |
33 | // TODO: Functions below this are not part of api and will be moved |
|
35 | // TODO: Functions below this are not part of api and will be moved | |
34 | // to private implementation, when we start using it |
|
36 | // to private implementation, when we start using it | |
35 | // TODO: TO PIMPL ---> |
|
37 | // TODO: TO PIMPL ---> | |
36 | QBarSet* barsetAt(int index); |
|
38 | QBarSet* barsetAt(int index); | |
37 | QString categoryName(int category); |
|
39 | QString categoryName(int category); | |
38 | qreal min(); |
|
40 | qreal min(); | |
39 | qreal max(); |
|
41 | qreal max(); | |
40 | qreal valueAt(int set, int category); |
|
42 | qreal valueAt(int set, int category); | |
41 | qreal percentageAt(int set, int category); |
|
43 | qreal percentageAt(int set, int category); | |
42 | qreal categorySum(int category); |
|
44 | qreal categorySum(int category); | |
43 | qreal maxCategorySum(); |
|
45 | qreal maxCategorySum(); | |
44 | BarChartModel& model(); |
|
46 | BarChartModel& model(); | |
45 | // <--- TO PIMPL |
|
47 | // <--- TO PIMPL | |
46 |
|
48 | |||
47 | signals: |
|
49 | signals: | |
48 | //void changed(int index); |
|
50 | //void changed(int index); | |
49 | void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals |
|
51 | void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals | |
50 | void rightClicked(QBarSet* barset, QString category); |
|
52 | void rightClicked(QBarSet* barset, QString category); | |
51 |
|
53 | |||
52 | // |
|
54 | // | |
53 | void updatedBars(); |
|
55 | void updatedBars(); | |
|
56 | void restructuredBar(int); | |||
54 |
|
57 | |||
55 | // TODO: internal signals, these to private implementation. |
|
58 | // TODO: internal signals, these to private implementation. | |
56 | // TODO: TO PIMPL ---> |
|
59 | // TODO: TO PIMPL ---> | |
57 | void showToolTip(QPoint pos, QString tip); |
|
60 | void showToolTip(QPoint pos, QString tip); | |
58 | // <--- TO PIMPL |
|
61 | // <--- TO PIMPL | |
59 |
|
62 | |||
60 | public Q_SLOTS: |
|
63 | public Q_SLOTS: | |
61 | void setToolTipEnabled(bool enabled=true); // enables tooltips |
|
64 | void setToolTipEnabled(bool enabled=true); // enables tooltips | |
62 |
|
65 | |||
63 | // TODO: TO PIMPL ---> |
|
66 | // TODO: TO PIMPL ---> | |
64 | void barsetClicked(QString category); |
|
67 | void barsetClicked(QString category); | |
65 | void barsetRightClicked(QString category); |
|
68 | void barsetRightClicked(QString category); | |
66 | // <--- TO PIMPL |
|
69 | // <--- TO PIMPL | |
67 |
|
70 | |||
68 | private Q_SLOTS: |
|
71 | private Q_SLOTS: | |
69 | // slots for updating bars when data in model changes |
|
72 | // slots for updating bars when data in model changes | |
70 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
73 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
71 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
74 | void modelDataAdded(QModelIndex parent, int start, int end); | |
72 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
75 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
73 | void barsetChanged(); |
|
76 | void barsetChanged(); | |
74 |
|
77 | |||
75 | protected: |
|
78 | protected: | |
76 | BarChartModel* mModel; |
|
79 | BarChartModel* mModel; | |
77 |
|
80 | |||
78 | // QAbstractItemModel* m_model; |
|
81 | // QAbstractItemModel* m_model; | |
79 | int m_mapCategories; |
|
82 | int m_mapCategories; | |
80 | int m_mapBarBottom; |
|
83 | int m_mapBarBottom; | |
81 | int m_mapBarTop; |
|
84 | int m_mapBarTop; | |
82 | Qt::Orientation m_mapOrientation; |
|
85 | Qt::Orientation m_mapOrientation; | |
83 | }; |
|
86 | }; | |
84 |
|
87 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE | |
86 |
|
89 | |||
87 | #endif // BARSERIES_H |
|
90 | #endif // BARSERIES_H |
@@ -1,195 +1,200 | |||||
1 | #include "qbarset.h" |
|
1 | #include "qbarset.h" | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 | #include <QToolTip> |
|
3 | #include <QToolTip> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | /*! |
|
7 | /*! | |
8 | \class QBarSet |
|
8 | \class QBarSet | |
9 | \brief part of QtCommercial chart API. |
|
9 | \brief part of QtCommercial chart API. | |
10 |
|
10 | |||
11 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
11 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
12 | First value of set is assumed to belong to first category, second to second category and so on. |
|
12 | First value of set is assumed to belong to first category, second to second category and so on. | |
13 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
13 | If set has fewer values than there are categories, then the missing values are assumed to be | |
14 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
14 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
15 |
|
15 | |||
16 | \mainclass |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \fn void QBarSet::clicked(QString category) |
|
22 | \fn void QBarSet::clicked(QString category) | |
23 | \brief signals that set has been clicked |
|
23 | \brief signals that set has been clicked | |
24 | Parameter \a category describes on which category was clicked |
|
24 | Parameter \a category describes on which category was clicked | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QBarSet::rightClicked(QString category) |
|
28 | \fn void QBarSet::rightClicked(QString category) | |
29 | \brief signals that set has been clicked with right mouse button |
|
29 | \brief signals that set has been clicked with right mouse button | |
30 | Parameter \a category describes on which category was clicked |
|
30 | Parameter \a category describes on which category was clicked | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
34 | \fn void QBarSet::hoverEnter(QPoint pos) | |
35 | \brief signals that mouse has entered over the set at position \a pos. |
|
35 | \brief signals that mouse has entered over the set at position \a pos. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \fn void QBarSet::hoverLeave() |
|
39 | \fn void QBarSet::hoverLeave() | |
40 | \brief signals that mouse has left from the set. |
|
40 | \brief signals that mouse has left from the set. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \fn void QBarSet::toggleFloatingValues() |
|
44 | \fn void QBarSet::toggleFloatingValues() | |
45 | \brief \internal |
|
45 | \brief \internal | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
49 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) | |
50 | \brief \internal \a pos \a tip |
|
50 | \brief \internal \a pos \a tip | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
55 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
56 | */ |
|
56 | */ | |
57 | QBarSet::QBarSet(QString name, QObject *parent) |
|
57 | QBarSet::QBarSet(QString name, QObject *parent) | |
58 | : QObject(parent) |
|
58 | : QObject(parent) | |
59 | ,mName(name) |
|
59 | ,mName(name) | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Sets new \a name for set. |
|
64 | Sets new \a name for set. | |
65 | */ |
|
65 | */ | |
66 | void QBarSet::setName(QString name) |
|
66 | void QBarSet::setName(QString name) | |
67 | { |
|
67 | { | |
68 | mName = name; |
|
68 | mName = name; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | Returns name of the set. |
|
72 | Returns name of the set. | |
73 | */ |
|
73 | */ | |
74 | QString QBarSet::name() |
|
74 | QString QBarSet::name() | |
75 | { |
|
75 | { | |
76 | return mName; |
|
76 | return mName; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | Appends new value \a value to the end of set. |
|
80 | Appends new value \a value to the end of set. | |
81 | */ |
|
81 | */ | |
82 | QBarSet& QBarSet::operator << (const qreal &value) |
|
82 | QBarSet& QBarSet::operator << (const qreal &value) | |
83 | { |
|
83 | { | |
84 | mValues.append(value); |
|
84 | mValues.append(value); | |
85 | emit structureChanged(); |
|
85 | emit structureChanged(); | |
86 | return *this; |
|
86 | return *this; | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
|
89 | void QBarSet::insertValue(int i, qreal value) | |||
|
90 | { | |||
|
91 | mValues.insert(i, value); | |||
|
92 | } | |||
|
93 | ||||
89 | /*! |
|
94 | /*! | |
90 | Returns count of values in set. |
|
95 | Returns count of values in set. | |
91 | */ |
|
96 | */ | |
92 | int QBarSet::count() |
|
97 | int QBarSet::count() | |
93 | { |
|
98 | { | |
94 | return mValues.count(); |
|
99 | return mValues.count(); | |
95 | } |
|
100 | } | |
96 |
|
101 | |||
97 | /*! |
|
102 | /*! | |
98 | Returns value of set indexed by \a index |
|
103 | Returns value of set indexed by \a index | |
99 | */ |
|
104 | */ | |
100 | qreal QBarSet::valueAt(int index) |
|
105 | qreal QBarSet::valueAt(int index) | |
101 | { |
|
106 | { | |
102 | return mValues.at(index); |
|
107 | return mValues.at(index); | |
103 | } |
|
108 | } | |
104 |
|
109 | |||
105 | /*! |
|
110 | /*! | |
106 | Sets a new value \a value to set, indexed by \a index |
|
111 | Sets a new value \a value to set, indexed by \a index | |
107 | */ |
|
112 | */ | |
108 | void QBarSet::setValue(int index, qreal value) |
|
113 | void QBarSet::setValue(int index, qreal value) | |
109 | { |
|
114 | { | |
110 | mValues.replace(index,value); |
|
115 | mValues.replace(index,value); | |
111 | emit valueChanged(); |
|
116 | emit valueChanged(); | |
112 | } |
|
117 | } | |
113 |
|
118 | |||
114 | /*! |
|
119 | /*! | |
115 | Returns total sum of all values in barset. |
|
120 | Returns total sum of all values in barset. | |
116 | */ |
|
121 | */ | |
117 | qreal QBarSet::total() |
|
122 | qreal QBarSet::total() | |
118 | { |
|
123 | { | |
119 | qreal total(0); |
|
124 | qreal total(0); | |
120 | for (int i=0; i<mValues.count(); i++) { |
|
125 | for (int i=0; i<mValues.count(); i++) { | |
121 | total += mValues.at(i); |
|
126 | total += mValues.at(i); | |
122 | } |
|
127 | } | |
123 | return total; |
|
128 | return total; | |
124 | } |
|
129 | } | |
125 |
|
130 | |||
126 | /*! |
|
131 | /*! | |
127 | Sets pen for set. Bars of this set are drawn using \a pen |
|
132 | Sets pen for set. Bars of this set are drawn using \a pen | |
128 | */ |
|
133 | */ | |
129 | void QBarSet::setPen(const QPen pen) |
|
134 | void QBarSet::setPen(const QPen pen) | |
130 | { |
|
135 | { | |
131 | mPen = pen; |
|
136 | mPen = pen; | |
132 | emit valueChanged(); |
|
137 | emit valueChanged(); | |
133 | } |
|
138 | } | |
134 |
|
139 | |||
135 | /*! |
|
140 | /*! | |
136 | Returns pen of the set. |
|
141 | Returns pen of the set. | |
137 | */ |
|
142 | */ | |
138 | QPen QBarSet::pen() const |
|
143 | QPen QBarSet::pen() const | |
139 | { |
|
144 | { | |
140 | return mPen; |
|
145 | return mPen; | |
141 | } |
|
146 | } | |
142 |
|
147 | |||
143 | /*! |
|
148 | /*! | |
144 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
149 | Sets brush for the set. Bars of this set are drawn using \a brush | |
145 | */ |
|
150 | */ | |
146 | void QBarSet::setBrush(const QBrush brush) |
|
151 | void QBarSet::setBrush(const QBrush brush) | |
147 | { |
|
152 | { | |
148 | mBrush = brush; |
|
153 | mBrush = brush; | |
149 | emit valueChanged(); |
|
154 | emit valueChanged(); | |
150 | } |
|
155 | } | |
151 |
|
156 | |||
152 | /*! |
|
157 | /*! | |
153 | Returns brush of the set. |
|
158 | Returns brush of the set. | |
154 | */ |
|
159 | */ | |
155 | QBrush QBarSet::brush() const |
|
160 | QBrush QBarSet::brush() const | |
156 | { |
|
161 | { | |
157 | return mBrush; |
|
162 | return mBrush; | |
158 | } |
|
163 | } | |
159 |
|
164 | |||
160 | /*! |
|
165 | /*! | |
161 | Sets the pen for floating values that are drawn on top of this set |
|
166 | Sets the pen for floating values that are drawn on top of this set | |
162 | */ |
|
167 | */ | |
163 | void QBarSet::setFloatingValuePen(const QPen pen) |
|
168 | void QBarSet::setFloatingValuePen(const QPen pen) | |
164 | { |
|
169 | { | |
165 | mFloatingValuePen = pen; |
|
170 | mFloatingValuePen = pen; | |
166 | } |
|
171 | } | |
167 |
|
172 | |||
168 | /*! |
|
173 | /*! | |
169 | Returns the pen for floating values that are drawn on top of this set |
|
174 | Returns the pen for floating values that are drawn on top of this set | |
170 | */ |
|
175 | */ | |
171 | QPen QBarSet::floatingValuePen() const |
|
176 | QPen QBarSet::floatingValuePen() const | |
172 | { |
|
177 | { | |
173 | return mFloatingValuePen; |
|
178 | return mFloatingValuePen; | |
174 | } |
|
179 | } | |
175 |
|
180 | |||
176 | /*! |
|
181 | /*! | |
177 | \internal \a pos |
|
182 | \internal \a pos | |
178 | */ |
|
183 | */ | |
179 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
184 | void QBarSet::barHoverEnterEvent(QPoint pos) | |
180 | { |
|
185 | { | |
181 | emit showToolTip(pos, mName); |
|
186 | emit showToolTip(pos, mName); | |
182 | emit hoverEnter(pos); |
|
187 | emit hoverEnter(pos); | |
183 | } |
|
188 | } | |
184 |
|
189 | |||
185 | /*! |
|
190 | /*! | |
186 | \internal |
|
191 | \internal | |
187 | */ |
|
192 | */ | |
188 | void QBarSet::barHoverLeaveEvent() |
|
193 | void QBarSet::barHoverLeaveEvent() | |
189 | { |
|
194 | { | |
190 | // Emit signal to user of charts |
|
195 | // Emit signal to user of charts | |
191 | emit hoverLeave(); |
|
196 | emit hoverLeave(); | |
192 | } |
|
197 | } | |
193 |
|
198 | |||
194 | #include "moc_qbarset.cpp" |
|
199 | #include "moc_qbarset.cpp" | |
195 | QTCOMMERCIALCHART_END_NAMESPACE |
|
200 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,73 | |||||
1 | #ifndef QBARSET_H |
|
1 | #ifndef QBARSET_H | |
2 | #define QBARSET_H |
|
2 | #define QBARSET_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
6 | #include <QBrush> |
|
6 | #include <QBrush> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
10 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | QBarSet(QString name, QObject *parent = 0); |
|
14 | QBarSet(QString name, QObject *parent = 0); | |
15 |
|
15 | |||
16 | void setName(QString name); |
|
16 | void setName(QString name); | |
17 | QString name(); |
|
17 | QString name(); | |
18 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
18 | QBarSet& operator << (const qreal &value); // appends new value to set | |
|
19 | void insertValue(int i, qreal value); | |||
19 |
|
20 | |||
20 | // TODO: remove indices eventually. Use as internal? |
|
21 | // TODO: remove indices eventually. Use as internal? | |
21 | int count(); // count of values in set |
|
22 | int count(); // count of values in set | |
22 | qreal valueAt(int index); // for modifying individual values |
|
23 | qreal valueAt(int index); // for modifying individual values | |
23 | void setValue(int index, qreal value); // setter for individual value |
|
24 | void setValue(int index, qreal value); // setter for individual value | |
24 | qreal total(); // total values in the set |
|
25 | qreal total(); // total values in the set | |
25 |
|
26 | |||
26 | // TODO: |
|
27 | // TODO: | |
27 | //qreal value(QString category); |
|
28 | //qreal value(QString category); | |
28 | //void setValue(QString category, qreal value); |
|
29 | //void setValue(QString category, qreal value); | |
29 |
|
30 | |||
30 | void setPen(const QPen pen); |
|
31 | void setPen(const QPen pen); | |
31 | QPen pen() const; |
|
32 | QPen pen() const; | |
32 |
|
33 | |||
33 | void setBrush(const QBrush brush); |
|
34 | void setBrush(const QBrush brush); | |
34 | QBrush brush() const; |
|
35 | QBrush brush() const; | |
35 |
|
36 | |||
36 | void setFloatingValuePen(const QPen pen); |
|
37 | void setFloatingValuePen(const QPen pen); | |
37 | QPen floatingValuePen() const; |
|
38 | QPen floatingValuePen() const; | |
38 |
|
39 | |||
39 | Q_SIGNALS: |
|
40 | Q_SIGNALS: | |
40 | void clicked(QString category); // Clicked and hover signals exposed to user |
|
41 | void clicked(QString category); // Clicked and hover signals exposed to user | |
41 | void rightClicked(QString category); |
|
42 | void rightClicked(QString category); | |
42 | void toggleFloatingValues(); |
|
43 | void toggleFloatingValues(); | |
43 |
|
44 | |||
44 | // TODO: Expose this to user or not? |
|
45 | // TODO: Expose this to user or not? | |
45 | // TODO: TO PIMPL ---> |
|
46 | // TODO: TO PIMPL ---> | |
46 | void structureChanged(); |
|
47 | void structureChanged(); | |
47 | void valueChanged(); |
|
48 | void valueChanged(); | |
48 | void hoverEnter(QPoint pos); |
|
49 | void hoverEnter(QPoint pos); | |
49 | void hoverLeave(); |
|
50 | void hoverLeave(); | |
50 | void showToolTip(QPoint pos, QString tip); // Private signal |
|
51 | void showToolTip(QPoint pos, QString tip); // Private signal | |
51 | // <--- TO PIMPL |
|
52 | // <--- TO PIMPL | |
52 |
|
53 | |||
53 | public Q_SLOTS: |
|
54 | public Q_SLOTS: | |
54 | // These are for internal communication |
|
55 | // These are for internal communication | |
55 | // TODO: TO PIMPL ---> |
|
56 | // TODO: TO PIMPL ---> | |
56 | void barHoverEnterEvent(QPoint pos); |
|
57 | void barHoverEnterEvent(QPoint pos); | |
57 | void barHoverLeaveEvent(); |
|
58 | void barHoverLeaveEvent(); | |
58 | // <--- TO PIMPL |
|
59 | // <--- TO PIMPL | |
59 |
|
60 | |||
60 | private: |
|
61 | private: | |
61 |
|
62 | |||
62 | QString mName; |
|
63 | QString mName; | |
63 | QList<qreal> mValues; // TODO: replace with map (category, value) |
|
64 | QList<qreal> mValues; // TODO: replace with map (category, value) | |
64 | QMap<QString,qreal> mMappedValues; |
|
65 | QMap<QString,qreal> mMappedValues; | |
65 | QPen mPen; |
|
66 | QPen mPen; | |
66 | QBrush mBrush; |
|
67 | QBrush mBrush; | |
67 | QPen mFloatingValuePen; |
|
68 | QPen mFloatingValuePen; | |
68 | }; |
|
69 | }; | |
69 |
|
70 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
72 | |||
72 | #endif // QBARSET_H |
|
73 | #endif // QBARSET_H |
General Comments 0
You need to be logged in to leave comments.
Login now