From 8e580b305fe62ee0d6ec5e4c2fb447250f366691 2012-02-10 12:29:55 From: sauimone Date: 2012-02-10 12:29:55 Subject: [PATCH] integrating bar charts to test app.. crashes for now --- diff --git a/src/barchart/barchartmodel.cpp b/src/barchart/barchartmodel.cpp index 62453fc..506dd99 100644 --- a/src/barchart/barchartmodel.cpp +++ b/src/barchart/barchartmodel.cpp @@ -30,6 +30,7 @@ int BarChartModel::addData(QList data) void BarChartModel::removeData(int id) { + qDebug() << "BarChartModel::removeData"; foreach(DataContainer* c, mDataModel) { if (c->mId == id) { mDataModel.removeOne(c); @@ -40,11 +41,13 @@ void BarChartModel::removeData(int id) int BarChartModel::countRows() { + qDebug() << "BarChartModel::countRows"; return mDataModel.count(); } int BarChartModel::countColumns() { + qDebug() << "BarChartModel::countColumns"; int count(0); for (int i=0; i 0); // TODO: make min and max members and update them when data changes. // This is slower since they are checked every time, even if data is same since previous call. @@ -85,6 +90,7 @@ int BarChartModel::min() int BarChartModel::max() { + qDebug() << "BarChartModel::max"; Q_ASSERT(mDataModel.count() > 0); // TODO: make min and max members and update them when data changes. @@ -106,6 +112,7 @@ int BarChartModel::max() qreal BarChartModel::valueAt(int series, int item) { + qDebug() << "BarChartModel::valueAt" << series << item; if ((series < 0) || (series >= mDataModel.count())) { // No series, no value. return 0; @@ -114,11 +121,13 @@ qreal BarChartModel::valueAt(int series, int item) return 0; } + qDebug() << "ValueAt" << series << item << "=" << mDataModel.at(series)->valueAt(item); return mDataModel.at(series)->valueAt(item); } qreal BarChartModel::columnSum(int column) { + qDebug() << "BarChartModel::columnSum"; int sum(0); int count = mDataModel.count(); // Count rows @@ -132,6 +141,7 @@ qreal BarChartModel::columnSum(int column) qreal BarChartModel::maxColumnSum() { + qDebug() << "BarChartModel::maxColumnSum"; int max = INT_MIN; int count = countColumns(); diff --git a/src/barchart/barchartseriesbase.cpp b/src/barchart/barchartseriesbase.cpp index f944cb7..61c246f 100644 --- a/src/barchart/barchartseriesbase.cpp +++ b/src/barchart/barchartseriesbase.cpp @@ -39,6 +39,7 @@ int BarChartSeriesBase::countColumns() qreal BarChartSeriesBase::valueAt(int series, int item) { + qDebug() << "BarChartSeriesBase::valueAt" << series << item; return mModel.valueAt(series,item); } diff --git a/src/barchart/bargroupbase.cpp b/src/barchart/bargroupbase.cpp index 390864b..ab2ace3 100644 --- a/src/barchart/bargroupbase.cpp +++ b/src/barchart/bargroupbase.cpp @@ -42,12 +42,13 @@ QRectF BarGroupBase::boundingRect() const { return QRectF(0,0,mWidth,mHeight); } - +/* void BarGroupBase::themeChanged(ChartTheme *theme) { - mTheme = theme; + qDebug() << "BarGroupBase::themeChanged" +// mTheme = theme; } - +*/ void BarGroupBase::setBarWidth( int w ) { mBarDefaultWidth = w; @@ -55,6 +56,7 @@ void BarGroupBase::setBarWidth( int w ) int BarGroupBase::addColor( QColor color ) { + qDebug() << "BarGroupBase::addColor"; int colorIndex = mColors.count(); mColors.append(color); return colorIndex; @@ -62,6 +64,7 @@ int BarGroupBase::addColor( QColor color ) void BarGroupBase::resetColors() { + qDebug() << "BarGroupBase::resetColors"; mColors.clear(); } @@ -105,7 +108,7 @@ void BarGroupBase::dataChanged() void BarGroupBase::handleModelChanged(int index) { - qDebug() << "BarGroupBase::handleModelChanged PUUH" << index; + qDebug() << "BarGroupBase::handleModelChanged" << index; dataChanged(); } @@ -117,6 +120,7 @@ void BarGroupBase::handleDomainChanged(const Domain& domain) void BarGroupBase::handleGeometryChanged(const QRectF& rect) { + qDebug() << "BarGroupBase::handleGeometryChanged"; mWidth = rect.width(); mHeight = rect.height(); layoutChanged(); diff --git a/src/barchart/bargroupbase.h b/src/barchart/bargroupbase.h index bb73044..aa508f5 100644 --- a/src/barchart/bargroupbase.h +++ b/src/barchart/bargroupbase.h @@ -28,7 +28,7 @@ public: // From ChartItem QRectF boundingRect() const; // From ChartThemeObserver - void themeChanged(ChartTheme *theme); +// void themeChanged(ChartTheme *theme); // TODO: these may change with layout awarness. void setBarWidth( int w ); diff --git a/src/barchart/stackedbargroup.cpp b/src/barchart/stackedbargroup.cpp index 299e3af..7c9137f 100644 --- a/src/barchart/stackedbargroup.cpp +++ b/src/barchart/stackedbargroup.cpp @@ -13,7 +13,7 @@ StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p void StackedBarGroup::layoutChanged() { - + qDebug() << "StackedBarGroup::layoutChanged"; // Scale bars to new layout // Layout for bars: if (mModel.countRows() <= 0) { diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 758055b..a7bd49e 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -128,6 +128,9 @@ void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int coun void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) { + for (int i=0; i< m_seriesColor.count(); i++) { + item->addColor(m_seriesColor.at(i)); + } item->addColor(QColor(255,0,0,128)); item->addColor(QColor(255,255,0,128)); item->addColor(QColor(0,255,0,128)); @@ -137,7 +140,9 @@ void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) { - // Add some fugly colors for 5 fist series... + for (int i=0; i< m_seriesColor.count(); i++) { + item->addColor(m_seriesColor.at(i)); + } item->addColor(QColor(255,0,0,128)); item->addColor(QColor(255,255,0,128)); item->addColor(QColor(0,255,0,128)); @@ -147,7 +152,9 @@ void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,i void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) { -// Add some fugly colors for 5 fist series... + for (int i=0; i< m_seriesColor.count(); i++) { + item->addColor(m_seriesColor.at(i)); + } item->addColor(QColor(255,0,0,128)); item->addColor(QColor(255,255,0,128)); item->addColor(QColor(0,255,0,128)); diff --git a/src/qchartseries.h b/src/qchartseries.h index 01d9367..dcf1a15 100644 --- a/src/qchartseries.h +++ b/src/qchartseries.h @@ -39,6 +39,9 @@ public: // Prototype for data model. TODO: remove the other setData methods and use something like this for now? virtual bool setData(QAbstractItemModel* /*model*/) { return false; } + // Methods for building a table for bar chart. Call repeatedly to add more than one series + virtual int addData(QList data) {return -1;} + virtual void removeData(int id) {} }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index 5bafadf..437843b 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -4,6 +4,7 @@ #include "qpieseries.h" #include #include +#include #include #include #include @@ -236,31 +237,28 @@ void MainWidget::addSeries(QString series, QString data) if (series == "Bar") { // This is the another way of creating series. Should we create test cases for both ways, if we support them? qDebug() << "Bar chart series"; - newSeries = new BarChartSeries(this); + StackedBarChartSeries* series0 = new StackedBarChartSeries(this); // Create some test data to chart - QStandardItemModel dataModel(2,10,this); - QModelIndex index; - index = dataModel.index(0,0); - // Series 1, items 6 to 9 missing. - dataModel.setData(dataModel.index(0,0),1); - dataModel.setData(dataModel.index(0,1),12); - dataModel.setData(dataModel.index(0,2),5); - dataModel.setData(dataModel.index(0,3),8); - dataModel.setData(dataModel.index(0,4),17); - dataModel.setData(dataModel.index(0,5),9); - - // Series 2, some other items missing - dataModel.setData(dataModel.index(1,0),5); - dataModel.setData(dataModel.index(1,3),4); - dataModel.setData(dataModel.index(1,5),7); - dataModel.setData(dataModel.index(1,6),8); - dataModel.setData(dataModel.index(1,8),9); - dataModel.setData(dataModel.index(1,9),9); - - newSeries->setData(&dataModel); - - m_chartWidget->addSeries(newSeries); + QList data0; + data0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10; + QList data1; + data1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0; + QList data2; + data2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1; + QList data3; + data3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5; + QList data4; + data4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10; + + series0->addData(data0); + series0->addData(data1); + series0->addData(data2); + series0->addData(data3); + series0->addData(data4); + + m_chartWidget->addSeries(series0); + newSeries = series0; } setCurrentSeries(newSeries);