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