@@ -20,13 +20,11 int BarChartSeries::min() | |||
|
20 | 20 | |
|
21 | 21 | // TODO: make min and max members and update them when data changes. |
|
22 | 22 | // This is slower since they are checked every time, even if data is same since previous call. |
|
23 | QModelIndex modelIndex = mModel->index(0,0); | |
|
24 | int min = mModel->data(modelIndex).toInt(); | |
|
23 | int min = INT_MAX; | |
|
25 | 24 | |
|
26 | 25 | for (int i=0; i <mModel->rowCount(); i++) { |
|
27 | 26 | for(int j=0; j<mModel->columnCount(); j++) { |
|
28 |
|
|
|
29 | int temp = mModel->data(modelIndex).toInt(); | |
|
27 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
|
30 | 28 | if (temp < min) { |
|
31 | 29 | min = temp; |
|
32 | 30 | } |
@@ -42,13 +40,11 int BarChartSeries::max() | |||
|
42 | 40 | |
|
43 | 41 | // TODO: make min and max members and update them when data changes. |
|
44 | 42 | // This is slower since they are checked every time, even if data is same since previous call. |
|
45 | QModelIndex modelIndex = mModel->index(0,0); | |
|
46 | int max = mModel->data(modelIndex).toInt(); | |
|
43 | int max = INT_MIN; | |
|
47 | 44 | |
|
48 | 45 | for (int i=0; i <mModel->rowCount(); i++) { |
|
49 | 46 | for(int j=0; j<mModel->columnCount(); j++) { |
|
50 |
|
|
|
51 | int temp = mModel->data(modelIndex).toInt(); | |
|
47 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
|
52 | 48 | if (temp > max) { |
|
53 | 49 | max = temp; |
|
54 | 50 | } |
@@ -63,7 +59,7 int BarChartSeries::countSeries() | |||
|
63 | 59 | return mModel->rowCount(); |
|
64 | 60 | } |
|
65 | 61 | |
|
66 |
int BarChartSeries::count |
|
|
62 | int BarChartSeries::countColumns() | |
|
67 | 63 | { |
|
68 | 64 | return mModel->columnCount(); |
|
69 | 65 | } |
@@ -73,19 +69,11 int BarChartSeries::countTotalItems() | |||
|
73 | 69 | return mModel->rowCount() * mModel->columnCount(); |
|
74 | 70 | } |
|
75 | 71 | |
|
76 |
int BarChartSeries::valueAt(int |
|
|
72 | int BarChartSeries::valueAt(int row, int column) | |
|
77 | 73 | { |
|
78 | QModelIndex index = mModel->index(series,item); | |
|
79 | return mModel->data(index).toInt(); | |
|
74 | return mModel->data(mModel->index(row,column)).toInt(); | |
|
80 | 75 | } |
|
81 | 76 | |
|
82 | /* | |
|
83 | void BarChartSeries::chartSizeChanged(QRectF rect) | |
|
84 | { | |
|
85 | qDebug() << "barchart size changed:" << rect; | |
|
86 | // mBarGroup->resize(rect.toRect().width(), rect.toRect().height()); | |
|
87 | } | |
|
88 | */ | |
|
89 | 77 | #include "moc_barchartseries.cpp" |
|
90 | 78 | |
|
91 | 79 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -2,7 +2,7 | |||
|
2 | 2 | #define BARCHARTSERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <QList> |
|
5 | #include <QRectF> | |
|
5 | //#include <QRectF> | |
|
6 | 6 | #include <QAbstractItemModel> |
|
7 | 7 | #include "qchartseries.h" |
|
8 | 8 | #include "qchartglobal.h" |
@@ -29,9 +29,9 public: | |||
|
29 | 29 | int min(); |
|
30 | 30 | int max(); |
|
31 | 31 | int countSeries(); |
|
32 |
int count |
|
|
32 | int countColumns(); // Count items in one series. | |
|
33 | 33 | int countTotalItems(); |
|
34 |
int valueAt(int |
|
|
34 | int valueAt(int row, int column); | |
|
35 | 35 | |
|
36 | 36 | public Q_SLOTS: |
|
37 | 37 |
@@ -4,12 +4,6 | |||
|
4 | 4 | |
|
5 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 6 | |
|
7 | // TODO: singleton? | |
|
8 | //BarGroup* BarGroup::mBarGroupInstance = NULL; | |
|
9 | ||
|
10 | //BarGroup::BarGroup(QGraphicsItem *parent) : | |
|
11 | // QGraphicsItem(parent) | |
|
12 | // ,mSeries(series) | |
|
13 | 7 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : |
|
14 | 8 | ChartItem(parent) |
|
15 | 9 | ,mSeries(series) |
@@ -107,7 +101,7 void BarGroup::layoutChanged() | |||
|
107 | 101 | } |
|
108 | 102 | |
|
109 | 103 | // TODO: better way to auto-layout |
|
110 |
int count = mSeries.count |
|
|
104 | int count = mSeries.countColumns(); | |
|
111 | 105 | int posStep = (mWidth / (count+1)); |
|
112 | 106 | int startPos = (mWidth / (count+1)) - mSeries.countSeries() * mBarDefaultWidth /2; |
|
113 | 107 | qDebug() << "startpos" << startPos; |
@@ -115,7 +109,7 void BarGroup::layoutChanged() | |||
|
115 | 109 | // Scaling. |
|
116 | 110 | int itemIndex(0); |
|
117 | 111 | for (int series = 0; series < mSeries.countSeries(); series++) { |
|
118 |
for (int item=0; item < mSeries.count |
|
|
112 | for (int item=0; item < mSeries.countColumns(); item++) { | |
|
119 | 113 | qDebug() << itemIndex; |
|
120 | 114 | int barHeight = mSeries.valueAt(series, item) * mHeight / mMax; |
|
121 | 115 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
@@ -1,5 +1,5 | |||
|
1 |
#ifndef QBAR |
|
|
2 |
#define QBAR |
|
|
1 | #ifndef QBARGROUP_H | |
|
2 | #define QBARGROUP_H | |
|
3 | 3 | |
|
4 | 4 | #include "chartitem_p.h" |
|
5 | 5 | #include "bar.h" |
@@ -7,25 +7,8 | |||
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | // TODO: Better name for this? The function of this class is to know where each bar in series is laid out. | |
|
11 | //class BarGroup : public QGraphicsItemGroup | |
|
12 | ||
|
13 | 10 | class BarGroup : public ChartItem |
|
14 | 11 | { |
|
15 | /* // TODO: implement as singleton? | |
|
16 | private: | |
|
17 | static BarGroup* mBarGroupInstance; | |
|
18 | ||
|
19 | public: | |
|
20 | static BarGroup* instance() | |
|
21 | { | |
|
22 | if (mBarGroupInstance == NULL) { | |
|
23 | mBarGroupInstance = new BarGroup(); | |
|
24 | } | |
|
25 | return mBarGroupInstance; | |
|
26 | } | |
|
27 | private: | |
|
28 | */ | |
|
29 | 12 | public: |
|
30 | 13 | explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0); |
|
31 | 14 | |
@@ -68,4 +51,4 private: | |||
|
68 | 51 | |
|
69 | 52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | 53 | |
|
71 |
#endif // QBAR |
|
|
54 | #endif // QBARGROUP_H |
@@ -15,6 +15,7 public: | |||
|
15 | 15 | SeriesTypeLine = 0, |
|
16 | 16 | // SeriesTypeArea, |
|
17 | 17 | SeriesTypeBar, |
|
18 | SeriesTypeStackedBar, | |
|
18 | 19 | SeriesTypePie, |
|
19 | 20 | SeriesTypeScatter |
|
20 | 21 | // SeriesTypeSpline |
@@ -26,7 +26,9 SOURCES += \ | |||
|
26 | 26 | pieslice.cpp \ |
|
27 | 27 | qchartview.cpp \ |
|
28 | 28 | qchartseries.cpp \ |
|
29 | qchartaxis.cpp | |
|
29 | qchartaxis.cpp \ | |
|
30 | barchart/stackedbarchartseries.cpp \ | |
|
31 | barchart/stackedbargroup.cpp | |
|
30 | 32 | |
|
31 | 33 | PRIVATE_HEADERS += \ |
|
32 | 34 | xylinechart/xylinechartitem_p.h \ |
@@ -49,7 +51,9 PUBLIC_HEADERS += \ | |||
|
49 | 51 | qchartview.h \ |
|
50 | 52 | qchartaxis.h |
|
51 | 53 | |
|
52 | HEADERS += $$PUBLIC_HEADERS | |
|
54 | HEADERS += $$PUBLIC_HEADERS \ | |
|
55 | barchart/stackedbarchartseries.h \ | |
|
56 | barchart/stackedbargroup.h | |
|
53 | 57 | HEADERS += $$PRIVATE_HEADERS |
|
54 | 58 | |
|
55 | 59 | INCLUDEPATH += xylinechart \ |
General Comments 0
You need to be logged in to leave comments.
Login now