From 1db754feb986eb8a1c71a449a54c69e4bd73b701 2012-03-09 10:31:24 From: Tero Ahola Date: 2012-03-09 10:31:24 Subject: [PATCH] Fixed initial bounding rect issue with bar series --- diff --git a/demos/chartthemes/main.cpp b/demos/chartthemes/main.cpp index 5b605eb..6894c48 100644 --- a/demos/chartthemes/main.cpp +++ b/demos/chartthemes/main.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -38,7 +40,7 @@ public: // generate random data int listCount = 3; int valueMax = 100; - int valueCount = 50; + int valueCount = 21; for (int i(0); i < listCount; i++) { DataList dataList; for (int j(0); j < valueCount; j++) { @@ -85,6 +87,20 @@ public: chart->setChartTitle("bar chart"); chart->setRenderHint(QPainter::Antialiasing); baseLayout->addWidget(chart, 1, 1); + { + QStringList categories; + // TODO: categories + for (int i(0); i < valueCount; i++) + categories << QString::number(i); + QBarSeries* series = new QBarSeries(categories, chart); + for (int i(0); i < m_dataTable.count(); i++) { + QBarSet *set = new QBarSet("Set" + QString::number(i)); + foreach (Data data, m_dataTable[i]) + *set << data.first.y(); + series->addBarSet(set); + } + chart->addSeries(series); + } m_charts << chart; // line chart diff --git a/src/barchart/bar.cpp b/src/barchart/bar.cpp index ebc873e..34fff83 100644 --- a/src/barchart/bar.cpp +++ b/src/barchart/bar.cpp @@ -6,8 +6,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Bar::Bar(QString category, QGraphicsItem *parent) - : QGraphicsObject(parent) - ,mCategory(category) + : QGraphicsObject(parent), + mCategory(category), + mXpos(0), + mYpos(0), + mWidth(0), + mHeight(0) { setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); setAcceptHoverEvents(true); diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index 225c5d2..86e0edc 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -12,11 +12,13 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) - : ChartItem(parent) - ,mLayoutSet(false) - ,mSeries(series) - ,mChart(parent) +BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) : + ChartItem(parent), + mLayoutSet(false), + mSeries(series), + mChart(parent), + mWidth(0), + mHeight(0) { connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); connect(series,SIGNAL(enableSeparators(bool)),this,SLOT(enableSeparators(bool))); @@ -44,7 +46,7 @@ void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem * QRectF BarPresenterBase::boundingRect() const { - return QRectF(0,0,mWidth,mHeight); + return QRectF(0, 0, mWidth, mHeight); } void BarPresenterBase::dataChanged() diff --git a/src/barchart/barvalue.cpp b/src/barchart/barvalue.cpp index dbe83fc..9cebf3e 100644 --- a/src/barchart/barvalue.cpp +++ b/src/barchart/barvalue.cpp @@ -5,8 +5,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) - : QGraphicsObject(parent) - ,mBarSet(set) + : QGraphicsObject(parent), + mBarSet(set), + mXpos(0), + mYpos(0), + mWidth(0), + mHeight(0) { setVisible(false); }