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