diff --git a/src/barchart/barchartitem.cpp b/src/barchart/barchartitem.cpp index 072d227..3e41933 100644 --- a/src/barchart/barchartitem.cpp +++ b/src/barchart/barchartitem.cpp @@ -88,103 +88,8 @@ void BarChartItem::dataChanged() } } } -/* -void BarChartItem::layoutChanged() -{ - qDebug() << "Deprecated BarChartItem::layoutChanged called. aborting"; - return; - // Scale bars to new layout - // Layout for bars: - if (mSeries->barsetCount() <= 0) { - qDebug() << "No sets in model!"; - return; - } - - if (childItems().count() == 0) { - qDebug() << "WARNING: BarChartitem::layoutChanged called before graphics items are created!"; - return; - } - - - // Use temporary qreals for accurancy (we might get some compiler warnings... :) - qreal categoryCount = mSeries->categoryCount(); - qreal setCount = mSeries->barsetCount(); - qreal max = mSeries->max(); - - // Domain: - if (mDomainMaxY > max) { - max = mDomainMaxY; - } - - qreal width = geometry().width(); - qreal height = geometry().height(); - qreal scale = (height/max); - qreal categoryWidth = width/categoryCount; - qreal barWidth = categoryWidth / (setCount+1); - - BarLayout layout; - - int itemIndex(0); - for (int category=0; category < categoryCount; category++) { - qreal xPos = categoryWidth * category + barWidth/2; - qreal yPos = height; - for (int set = 0; set < setCount; set++) { - qreal barHeight = mSeries->valueAt(set,category) * scale; - Bar* bar = mBars.at(itemIndex); - - QRectF rect(xPos,yPos-barHeight,mBarWidth,barHeight); - layout.insert(bar,rect); - // TODO: width settable per bar? - bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); - bar->setPen(mSeries->barsetAt(set)->pen()); - bar->setBrush(mSeries->barsetAt(set)->brush()); - -// bar->resize(mBarWidth, barHeight); -// layout.insert(bar,QSizeF(mBarWidth,barHeight)); - bar->setPen(mSeries->barsetAt(set)->pen()); - bar->setBrush(mSeries->barsetAt(set)->brush()); -// bar->setPos(xPos, yPos-barHeight); - itemIndex++; - xPos += barWidth; - } - } - - // Position floating values - itemIndex = 0; - for (int category=0; category < mSeries->categoryCount(); category++) { - qreal xPos = categoryWidth * category + categoryWidth/2 + barWidth; - qreal yPos = height; - for (int set=0; set < mSeries->barsetCount(); set++) { - qreal barHeight = mSeries->valueAt(set,category) * scale; - BarValue* value = mFloatingValues.at(itemIndex); - - QBarSet* barSet = mSeries->barsetAt(set); - value->resize(100,50); // TODO: proper layout for this. - value->setPos(xPos, yPos-barHeight/2); - value->setPen(barSet->floatingValuePen()); - - if (mSeries->valueAt(set,category) != 0) { - value->setValueString(QString::number(mSeries->valueAt(set,category))); - } else { - value->setValueString(QString("")); - } - - itemIndex++; - xPos += barWidth; - } - } -// update(); -} -*/ QVector BarChartItem::calculateLayout() { -// layoutChanged(); -/* - BarLayout layout; - foreach(Bar* bar, mBars) { - layout.insert(bar,bar->boundingRect()); - } -*/ QVector layout; // Use temporary qreals for accurancy (we might get some compiler warnings... :) @@ -214,14 +119,9 @@ QVector BarChartItem::calculateLayout() Bar* bar = mBars.at(itemIndex); QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); - //layout.insert(bar,rect); layout.append(rect); - // TODO: width settable per bar? -// bar->resize(mBarWidth, barHeight); -// layout.insert(bar,QSizeF(mBarWidth,barHeight)); bar->setPen(mSeries->barsetAt(set)->pen()); bar->setBrush(mSeries->barsetAt(set)->brush()); -// bar->setPos(xPos, yPos-barHeight); itemIndex++; xPos += barWidth; } @@ -268,8 +168,6 @@ void BarChartItem::setLayout(const QVector &layout) mLayout = layout; for (int i=0; isetSize(layout.at(i).size()); - //mBars.at(i)->setPos(layout.at(i).topLeft()); mBars.at(i)->setRect(layout.at(i)); } diff --git a/src/barchart/barchartitem_p.h b/src/barchart/barchartitem_p.h index 2455c3f..7f78f24 100644 --- a/src/barchart/barchartitem_p.h +++ b/src/barchart/barchartitem_p.h @@ -34,10 +34,9 @@ public: // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes private slots: - //virtual void layoutChanged(); // layout has changed -> need to recalculate bar sizes public: - QVector calculateLayout(); + virtual QVector calculateLayout(); void applyLayout(const QVector &layout); void setLayout(const QVector &layout); void updateLayout(const QVector &layout); diff --git a/src/barchart/percentbarchartitem.cpp b/src/barchart/percentbarchartitem.cpp index 17347d5..e426299 100644 --- a/src/barchart/percentbarchartitem.cpp +++ b/src/barchart/percentbarchartitem.cpp @@ -11,20 +11,9 @@ PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter* pre { } -void PercentBarChartItem::layoutChanged() +QVector PercentBarChartItem::calculateLayout() { - // Scale bars to new layout - // Layout for bars: - if (mSeries->barsetCount() <= 0) { - qDebug() << "No sets in model!"; - // Nothing to do. - return; - } - - if (childItems().count() == 0) { - qDebug() << "WARNING: PercentBarChartItem::layoutChanged called before graphics items are created!"; - return; - } + QVector layout; // Use temporary qreals for accurancy (we might get some compiler warnings... :) qreal width = geometry().width(); @@ -43,13 +32,10 @@ void PercentBarChartItem::layoutChanged() for (int set=0; set < mSeries->barsetCount(); set++) { qreal barHeight = mSeries->valueAt(set, category) * scale; Bar* bar = mBars.at(itemIndex); - - // TODO: width settable per bar? - bar->setPen(mSeries->barsetAt(set)->pen()); - bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); bar->setBrush(mSeries->barsetAt(set)->brush()); - + QRectF rect(xPos, yPos-barHeight,barWidth, barHeight); + layout.append(rect); itemIndex++; yPos -= barHeight; } @@ -87,6 +73,7 @@ void PercentBarChartItem::layoutChanged() } xPos += xStep; } + return layout; } #include "moc_percentbarchartitem_p.cpp" diff --git a/src/barchart/percentbarchartitem_p.h b/src/barchart/percentbarchartitem_p.h index a6eb3ae..b8ef3c1 100644 --- a/src/barchart/percentbarchartitem_p.h +++ b/src/barchart/percentbarchartitem_p.h @@ -15,8 +15,7 @@ public: PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter); private: - - void layoutChanged(); // layout has changed -> need to recalculate bar sizes + virtual QVector calculateLayout(); private: diff --git a/src/barchart/stackedbarchartitem.cpp b/src/barchart/stackedbarchartitem.cpp index 06866bf..b4d2ede 100644 --- a/src/barchart/stackedbarchartitem.cpp +++ b/src/barchart/stackedbarchartitem.cpp @@ -16,27 +16,9 @@ StackedBarChartItem::~StackedBarChartItem() } -void StackedBarChartItem::layoutChanged() +QVector StackedBarChartItem::calculateLayout() { - // Scale bars to new layout - // Layout for bars: - if (mSeries->barsetCount() <= 0) { - qDebug() << "No sets in model!"; - // Nothing to do. - return; - } - - if (mSeries->categoryCount() == 0) { - qDebug() << "No categories in model!"; - // Nothing to do - return; - } - - if (childItems().count() == 0) { - qDebug() << "WARNING: StackedBarChartItem::layoutChanged called before graphics items are created!"; - return; - } - + QVector layout; // Use temporary qreals for accurancy (we might get some compiler warnings... :) qreal maxSum = mSeries->maxCategorySum(); @@ -53,7 +35,6 @@ void StackedBarChartItem::layoutChanged() qreal xStep = width/categotyCount; qreal xPos = xStep/2 - barWidth/2; - int itemIndex(0); for (int category = 0; category < categotyCount; category++) { qreal yPos = height; @@ -62,7 +43,8 @@ void StackedBarChartItem::layoutChanged() Bar* bar = mBars.at(itemIndex); bar->setPen(mSeries->barsetAt(set)->pen()); bar->setBrush(mSeries->barsetAt(set)->brush()); - bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); + QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); + layout.append(rect); itemIndex++; yPos -= barHeight; } @@ -94,6 +76,7 @@ void StackedBarChartItem::layoutChanged() } xPos += xStep; } + return layout; } #include "moc_stackedbarchartitem_p.cpp" diff --git a/src/barchart/stackedbarchartitem_p.h b/src/barchart/stackedbarchartitem_p.h index 6e02d56..c714d06 100644 --- a/src/barchart/stackedbarchartitem_p.h +++ b/src/barchart/stackedbarchartitem_p.h @@ -16,7 +16,7 @@ public: private: // From BarChartItem - void layoutChanged(); // layout has changed -> need to recalculate bar sizes + virtual QVector calculateLayout(); private: