##// END OF EJS Templates
integrating bar charts to test app.. crashes for now
sauimone -
r164:8e580b305fe6
parent child
Show More
@@ -30,6 +30,7 int BarChartModel::addData(QList<qreal> data)
30
30
31 void BarChartModel::removeData(int id)
31 void BarChartModel::removeData(int id)
32 {
32 {
33 qDebug() << "BarChartModel::removeData";
33 foreach(DataContainer* c, mDataModel) {
34 foreach(DataContainer* c, mDataModel) {
34 if (c->mId == id) {
35 if (c->mId == id) {
35 mDataModel.removeOne(c);
36 mDataModel.removeOne(c);
@@ -40,11 +41,13 void BarChartModel::removeData(int id)
40
41
41 int BarChartModel::countRows()
42 int BarChartModel::countRows()
42 {
43 {
44 qDebug() << "BarChartModel::countRows";
43 return mDataModel.count();
45 return mDataModel.count();
44 }
46 }
45
47
46 int BarChartModel::countColumns()
48 int BarChartModel::countColumns()
47 {
49 {
50 qDebug() << "BarChartModel::countColumns";
48 int count(0);
51 int count(0);
49 for (int i=0; i<mDataModel.count(); i++){
52 for (int i=0; i<mDataModel.count(); i++){
50 // TODO: can we assume that all series have same number of values? If not. then which values are empty?
53 // TODO: can we assume that all series have same number of values? If not. then which values are empty?
@@ -58,6 +61,7 int BarChartModel::countColumns()
58
61
59 int BarChartModel::countTotalItems()
62 int BarChartModel::countTotalItems()
60 {
63 {
64 qDebug() << "BarChartModel::countTotalItems";
61 int total = mDataModel.count() * countColumns();
65 int total = mDataModel.count() * countColumns();
62 qDebug() << "BarChartModel::countTotalItems datamodel count" << mDataModel.count();
66 qDebug() << "BarChartModel::countTotalItems datamodel count" << mDataModel.count();
63 qDebug() << "BarChartModel::countTotalItems countColumns count" << countColumns();
67 qDebug() << "BarChartModel::countTotalItems countColumns count" << countColumns();
@@ -66,6 +70,7 int BarChartModel::countTotalItems()
66
70
67 int BarChartModel::min()
71 int BarChartModel::min()
68 {
72 {
73 qDebug() << "BarChartModel::min";
69 Q_ASSERT(mDataModel.count() > 0);
74 Q_ASSERT(mDataModel.count() > 0);
70 // TODO: make min and max members and update them when data changes.
75 // TODO: make min and max members and update them when data changes.
71 // This is slower since they are checked every time, even if data is same since previous call.
76 // This is slower since they are checked every time, even if data is same since previous call.
@@ -85,6 +90,7 int BarChartModel::min()
85
90
86 int BarChartModel::max()
91 int BarChartModel::max()
87 {
92 {
93 qDebug() << "BarChartModel::max";
88 Q_ASSERT(mDataModel.count() > 0);
94 Q_ASSERT(mDataModel.count() > 0);
89
95
90 // TODO: make min and max members and update them when data changes.
96 // TODO: make min and max members and update them when data changes.
@@ -106,6 +112,7 int BarChartModel::max()
106
112
107 qreal BarChartModel::valueAt(int series, int item)
113 qreal BarChartModel::valueAt(int series, int item)
108 {
114 {
115 qDebug() << "BarChartModel::valueAt" << series << item;
109 if ((series < 0) || (series >= mDataModel.count())) {
116 if ((series < 0) || (series >= mDataModel.count())) {
110 // No series, no value.
117 // No series, no value.
111 return 0;
118 return 0;
@@ -114,11 +121,13 qreal BarChartModel::valueAt(int series, int item)
114 return 0;
121 return 0;
115 }
122 }
116
123
124 qDebug() << "ValueAt" << series << item << "=" << mDataModel.at(series)->valueAt(item);
117 return mDataModel.at(series)->valueAt(item);
125 return mDataModel.at(series)->valueAt(item);
118 }
126 }
119
127
120 qreal BarChartModel::columnSum(int column)
128 qreal BarChartModel::columnSum(int column)
121 {
129 {
130 qDebug() << "BarChartModel::columnSum";
122 int sum(0);
131 int sum(0);
123 int count = mDataModel.count(); // Count rows
132 int count = mDataModel.count(); // Count rows
124
133
@@ -132,6 +141,7 qreal BarChartModel::columnSum(int column)
132
141
133 qreal BarChartModel::maxColumnSum()
142 qreal BarChartModel::maxColumnSum()
134 {
143 {
144 qDebug() << "BarChartModel::maxColumnSum";
135 int max = INT_MIN;
145 int max = INT_MIN;
136 int count = countColumns();
146 int count = countColumns();
137
147
@@ -39,6 +39,7 int BarChartSeriesBase::countColumns()
39
39
40 qreal BarChartSeriesBase::valueAt(int series, int item)
40 qreal BarChartSeriesBase::valueAt(int series, int item)
41 {
41 {
42 qDebug() << "BarChartSeriesBase::valueAt" << series << item;
42 return mModel.valueAt(series,item);
43 return mModel.valueAt(series,item);
43 }
44 }
44
45
@@ -42,12 +42,13 QRectF BarGroupBase::boundingRect() const
42 {
42 {
43 return QRectF(0,0,mWidth,mHeight);
43 return QRectF(0,0,mWidth,mHeight);
44 }
44 }
45
45 /*
46 void BarGroupBase::themeChanged(ChartTheme *theme)
46 void BarGroupBase::themeChanged(ChartTheme *theme)
47 {
47 {
48 mTheme = theme;
48 qDebug() << "BarGroupBase::themeChanged"
49 // mTheme = theme;
49 }
50 }
50
51 */
51 void BarGroupBase::setBarWidth( int w )
52 void BarGroupBase::setBarWidth( int w )
52 {
53 {
53 mBarDefaultWidth = w;
54 mBarDefaultWidth = w;
@@ -55,6 +56,7 void BarGroupBase::setBarWidth( int w )
55
56
56 int BarGroupBase::addColor( QColor color )
57 int BarGroupBase::addColor( QColor color )
57 {
58 {
59 qDebug() << "BarGroupBase::addColor";
58 int colorIndex = mColors.count();
60 int colorIndex = mColors.count();
59 mColors.append(color);
61 mColors.append(color);
60 return colorIndex;
62 return colorIndex;
@@ -62,6 +64,7 int BarGroupBase::addColor( QColor color )
62
64
63 void BarGroupBase::resetColors()
65 void BarGroupBase::resetColors()
64 {
66 {
67 qDebug() << "BarGroupBase::resetColors";
65 mColors.clear();
68 mColors.clear();
66 }
69 }
67
70
@@ -105,7 +108,7 void BarGroupBase::dataChanged()
105
108
106 void BarGroupBase::handleModelChanged(int index)
109 void BarGroupBase::handleModelChanged(int index)
107 {
110 {
108 qDebug() << "BarGroupBase::handleModelChanged PUUH" << index;
111 qDebug() << "BarGroupBase::handleModelChanged" << index;
109 dataChanged();
112 dataChanged();
110 }
113 }
111
114
@@ -117,6 +120,7 void BarGroupBase::handleDomainChanged(const Domain& domain)
117
120
118 void BarGroupBase::handleGeometryChanged(const QRectF& rect)
121 void BarGroupBase::handleGeometryChanged(const QRectF& rect)
119 {
122 {
123 qDebug() << "BarGroupBase::handleGeometryChanged";
120 mWidth = rect.width();
124 mWidth = rect.width();
121 mHeight = rect.height();
125 mHeight = rect.height();
122 layoutChanged();
126 layoutChanged();
@@ -28,7 +28,7 public: // From ChartItem
28 QRectF boundingRect() const;
28 QRectF boundingRect() const;
29
29
30 // From ChartThemeObserver
30 // From ChartThemeObserver
31 void themeChanged(ChartTheme *theme);
31 // void themeChanged(ChartTheme *theme);
32
32
33 // TODO: these may change with layout awarness.
33 // TODO: these may change with layout awarness.
34 void setBarWidth( int w );
34 void setBarWidth( int w );
@@ -13,7 +13,7 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p
13
13
14 void StackedBarGroup::layoutChanged()
14 void StackedBarGroup::layoutChanged()
15 {
15 {
16
16 qDebug() << "StackedBarGroup::layoutChanged";
17 // Scale bars to new layout
17 // Scale bars to new layout
18 // Layout for bars:
18 // Layout for bars:
19 if (mModel.countRows() <= 0) {
19 if (mModel.countRows() <= 0) {
@@ -128,6 +128,9 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int coun
128
128
129 void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count)
129 void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count)
130 {
130 {
131 for (int i=0; i< m_seriesColor.count(); i++) {
132 item->addColor(m_seriesColor.at(i));
133 }
131 item->addColor(QColor(255,0,0,128));
134 item->addColor(QColor(255,0,0,128));
132 item->addColor(QColor(255,255,0,128));
135 item->addColor(QColor(255,255,0,128));
133 item->addColor(QColor(0,255,0,128));
136 item->addColor(QColor(0,255,0,128));
@@ -137,7 +140,9 void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count)
137
140
138 void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count)
141 void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count)
139 {
142 {
140 // Add some fugly colors for 5 fist series...
143 for (int i=0; i< m_seriesColor.count(); i++) {
144 item->addColor(m_seriesColor.at(i));
145 }
141 item->addColor(QColor(255,0,0,128));
146 item->addColor(QColor(255,0,0,128));
142 item->addColor(QColor(255,255,0,128));
147 item->addColor(QColor(255,255,0,128));
143 item->addColor(QColor(0,255,0,128));
148 item->addColor(QColor(0,255,0,128));
@@ -147,7 +152,9 void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,i
147
152
148 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count)
153 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count)
149 {
154 {
150 // Add some fugly colors for 5 fist series...
155 for (int i=0; i< m_seriesColor.count(); i++) {
156 item->addColor(m_seriesColor.at(i));
157 }
151 item->addColor(QColor(255,0,0,128));
158 item->addColor(QColor(255,0,0,128));
152 item->addColor(QColor(255,255,0,128));
159 item->addColor(QColor(255,255,0,128));
153 item->addColor(QColor(0,255,0,128));
160 item->addColor(QColor(0,255,0,128));
@@ -39,6 +39,9 public:
39 // Prototype for data model. TODO: remove the other setData methods and use something like this for now?
39 // Prototype for data model. TODO: remove the other setData methods and use something like this for now?
40 virtual bool setData(QAbstractItemModel* /*model*/) { return false; }
40 virtual bool setData(QAbstractItemModel* /*model*/) { return false; }
41
41
42 // Methods for building a table for bar chart. Call repeatedly to add more than one series
43 virtual int addData(QList<qreal> data) {return -1;}
44 virtual void removeData(int id) {}
42 };
45 };
43
46
44 QTCOMMERCIALCHART_END_NAMESPACE
47 QTCOMMERCIALCHART_END_NAMESPACE
@@ -4,6 +4,7
4 #include "qpieseries.h"
4 #include "qpieseries.h"
5 #include <qlinechartseries.h>
5 #include <qlinechartseries.h>
6 #include <barchartseries.h>
6 #include <barchartseries.h>
7 #include <stackedbarchartseries.h>
7 #include <QPushButton>
8 #include <QPushButton>
8 #include <QComboBox>
9 #include <QComboBox>
9 #include <QSpinBox>
10 #include <QSpinBox>
@@ -236,31 +237,28 void MainWidget::addSeries(QString series, QString data)
236 if (series == "Bar") {
237 if (series == "Bar") {
237 // This is the another way of creating series. Should we create test cases for both ways, if we support them?
238 // This is the another way of creating series. Should we create test cases for both ways, if we support them?
238 qDebug() << "Bar chart series";
239 qDebug() << "Bar chart series";
239 newSeries = new BarChartSeries(this);
240 StackedBarChartSeries* series0 = new StackedBarChartSeries(this);
240
241
241 // Create some test data to chart
242 // Create some test data to chart
242 QStandardItemModel dataModel(2,10,this);
243 QList<qreal> data0;
243 QModelIndex index;
244 data0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10;
244 index = dataModel.index(0,0);
245 QList<qreal> data1;
245 // Series 1, items 6 to 9 missing.
246 data1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0;
246 dataModel.setData(dataModel.index(0,0),1);
247 QList<qreal> data2;
247 dataModel.setData(dataModel.index(0,1),12);
248 data2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1;
248 dataModel.setData(dataModel.index(0,2),5);
249 QList<qreal> data3;
249 dataModel.setData(dataModel.index(0,3),8);
250 data3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5;
250 dataModel.setData(dataModel.index(0,4),17);
251 QList<qreal> data4;
251 dataModel.setData(dataModel.index(0,5),9);
252 data4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10;
252
253
253 // Series 2, some other items missing
254 series0->addData(data0);
254 dataModel.setData(dataModel.index(1,0),5);
255 series0->addData(data1);
255 dataModel.setData(dataModel.index(1,3),4);
256 series0->addData(data2);
256 dataModel.setData(dataModel.index(1,5),7);
257 series0->addData(data3);
257 dataModel.setData(dataModel.index(1,6),8);
258 series0->addData(data4);
258 dataModel.setData(dataModel.index(1,8),9);
259
259 dataModel.setData(dataModel.index(1,9),9);
260 m_chartWidget->addSeries(series0);
260
261 newSeries = series0;
261 newSeries->setData(&dataModel);
262
263 m_chartWidget->addSeries(newSeries);
264 }
262 }
265
263
266 setCurrentSeries(newSeries);
264 setCurrentSeries(newSeries);
General Comments 0
You need to be logged in to leave comments. Login now