diff --git a/src/barchart/stackedbargroup.cpp b/src/barchart/stackedbargroup.cpp index 3acd52b..2f9daa5 100644 --- a/src/barchart/stackedbargroup.cpp +++ b/src/barchart/stackedbargroup.cpp @@ -2,6 +2,7 @@ #include "bar_p.h" #include "barlabel_p.h" #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -12,14 +13,18 @@ StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p ,mLayoutDirty(true) ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready ,mTheme(0) + ,mSeparatorsVisible(true) { dataChanged(); } +void StackedBarGroup::setSeparatorsVisible(bool visible) +{ + mSeparatorsVisible = visible; +} void StackedBarGroup::setSize(const QSizeF& size) { -// qDebug() << "StackedBarGroup::setSize"; mWidth = size.width(); mHeight = size.height(); layoutChanged(); @@ -65,8 +70,17 @@ void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *o foreach(QGraphicsItem* i, childItems()) { i->paint(painter,option,widget); } - mLayoutDirty = false; - //TODO: draw labels. + if (mSeparatorsVisible) { + //TODO: own class for separators (graphicsitem), because they may have style etc later. + // this is just to see that the positions are calculated correctly. + QPen pen(QColor(0,0,255,255)); + painter->setPen(pen); + for (int i=0; idrawLine(xp,0,xp,mHeight); + } + } +// mLayoutDirty = false; } } @@ -79,7 +93,7 @@ QRectF StackedBarGroup::boundingRect() const void StackedBarGroup::dataChanged() { - qDebug() << "QBarChart::dataChanged mSeries"; + qDebug() << "QBarChart::dataChanged"; // Find out maximum and minimum of all series mMax = mSeries.max(); @@ -107,6 +121,8 @@ void StackedBarGroup::dataChanged() childItems().append(label); } + mSeparatorPositions.clear(); + // TODO: if (autolayout) { layoutChanged() } or something mLayoutDirty = true; } @@ -120,16 +136,21 @@ void StackedBarGroup::layoutChanged() return; } + if (mSeries.countColumns() == 0) { + // Nothing to do + return; + } + // TODO: better way to auto-layout // Use reals for accurancy (we might get some compiler warnings... :) + // TODO: use temp variable for column count... qreal maxSum = mSeries.maxColumnSum(); qreal h = mHeight; qreal scale = (h / maxSum); - int count = mSeries.countColumns(); int itemIndex(0); qreal tW = mWidth; - qreal tC = count+1; + qreal tC = mSeries.countColumns() + 1; qreal xStep = (tW/tC); qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); int labelIndex = mSeries.countColumns() * mSeries.countRows(); @@ -157,6 +178,14 @@ void StackedBarGroup::layoutChanged() xPos += xStep; } + // Position separators + mSeparatorPositions.clear(); + xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. + for (int s=0; s < mSeries.countColumns() - 1; s++) { + mSeparatorPositions.append(xPos); + xPos += xStep; + } + mLayoutDirty = true; } diff --git a/src/barchart/stackedbargroup.h b/src/barchart/stackedbargroup.h index 82aff55..b3c860f 100644 --- a/src/barchart/stackedbargroup.h +++ b/src/barchart/stackedbargroup.h @@ -16,6 +16,9 @@ class StackedBarGroup : public ChartItem, public ChartThemeObserver public: StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); + // Bar chart spesific + void setSeparatorsVisible(bool visible = true); + public: // From ChartItem void setSize(const QSizeF &size); void setPlotDomain(const PlotDomain& data); @@ -56,7 +59,8 @@ private: QList mColors; // List of colors for series for now ChartTheme* mTheme; -// QList mLabels; + bool mSeparatorsVisible; + QList mSeparatorPositions; }; diff --git a/src/qchart.cpp b/src/qchart.cpp index c8d792e..4c64ce5 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -99,6 +99,7 @@ void QChart::addSeries(QChartSeries* series) domain.m_minY = qMin(domain.m_minY,y); domain.m_maxX = qMax(domain.m_maxX,x); domain.m_maxY = qMax(domain.m_maxY,y); + m_axisXItem->setVisible(false); break; } case QChartSeries::SeriesTypeStackedBar: { @@ -123,6 +124,7 @@ void QChart::addSeries(QChartSeries* series) domain.m_minY = qMin(domain.m_minY,y); domain.m_maxX = qMax(domain.m_maxX,x); domain.m_maxY = qMax(domain.m_maxY,y); + m_axisXItem->setVisible(false); break; } case QChartSeries::SeriesTypePercentBar: { @@ -146,6 +148,7 @@ void QChart::addSeries(QChartSeries* series) domain.m_minY = 0; domain.m_maxX = qMax(domain.m_maxX,x); domain.m_maxY = 100; + m_axisXItem->setVisible(false); break; } case QChartSeries::SeriesTypeScatter: {