From 5f68000bea7aa1fb5eef385fba51cfda709ad3ce 2012-02-23 11:58:25 From: sauimone Date: 2012-02-23 11:58:25 Subject: [PATCH] moved tooltip to presenter --- diff --git a/src/barchart/barpresenter.cpp b/src/barchart/barpresenter.cpp index bf6eaeb..9e06f12 100644 --- a/src/barchart/barpresenter.cpp +++ b/src/barchart/barpresenter.cpp @@ -7,8 +7,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -BarPresenter::BarPresenter(BarChartModel& model, QGraphicsItem *parent) : - BarPresenterBase(model,parent) +BarPresenter::BarPresenter(QBarChartSeries *series, QGraphicsItem *parent) : + BarPresenterBase(series, parent) { mBarDefaultWidth = 15; } @@ -17,7 +17,7 @@ void BarPresenter::layoutChanged() { // Scale bars to new layout // Layout for bars: - if (mModel.countSets() <= 0) { + if (mSeries->countSets() <= 0) { qDebug() << "No sets in model!"; return; } @@ -29,12 +29,12 @@ void BarPresenter::layoutChanged() // TODO: better way to auto-layout? // Use reals for accurancy (we might get some compiler warnings... :) - int categoryCount = mModel.countCategories(); - int setCount = mModel.countSets(); + int categoryCount = mSeries->countCategories(); + int setCount = mSeries->countSets(); qreal tW = mWidth; qreal tH = mHeight; - qreal tM = mModel.max(); + qreal tM = mSeries->max(); qreal scale = (tH/tM); qreal tC = categoryCount+1; qreal xStepPerSet = (tW/tC); @@ -47,13 +47,13 @@ void BarPresenter::layoutChanged() qreal xPos = xStepPerSet * category + ((tW + mBarDefaultWidth*setCount)/(categoryCount*2)); qreal yPos = mHeight; for (int set = 0; set < setCount; set++) { - qreal barHeight = mModel.valueAt(set, category) * scale; + qreal barHeight = mSeries->valueAt(set,category) * scale; Bar* bar = mBars.at(itemIndex); // TODO: width settable per bar? bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mModel.setAt(set)->brush()); - bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight); + bar->setBrush(mSeries->setAt(set)->brush()); + bar->setPos(xPos, yPos-barHeight); itemIndex++; xPos += mBarDefaultWidth; } @@ -67,11 +67,11 @@ void BarPresenter::layoutChanged() // Position floating values itemIndex = 0; - for (int category=0; category < mModel.countCategories(); category++) { + for (int category=0; category < mSeries->countCategories(); category++) { qreal xPos = xStepPerSet * category + ((tW + mBarDefaultWidth*setCount)/(categoryCount*2)); qreal yPos = mHeight; - for (int set=0; set < mModel.countSets(); set++) { - qreal barHeight = mModel.valueAt(set,category) * scale; + for (int set=0; set < mSeries->countSets(); set++) { + qreal barHeight = mSeries->valueAt(set,category) * scale; BarValue* value = mFloatingValues.at(itemIndex); // TODO: remove hard coding, apply layout @@ -79,8 +79,8 @@ void BarPresenter::layoutChanged() value->setPos(xPos, yPos-barHeight/2); value->setPen(QPen(QColor(255,255,255,255))); - if (mModel.valueAt(set,category) != 0) { - value->setValueString(QString::number(mModel.valueAt(set,category))); + if (mSeries->valueAt(set,category) != 0) { + value->setValueString(QString::number(mSeries->valueAt(set,category))); } else { value->setValueString(QString("")); } @@ -92,4 +92,6 @@ void BarPresenter::layoutChanged() mLayoutDirty = true; } +#include "moc_barpresenter.cpp" + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/barpresenter.h b/src/barchart/barpresenter.h index 197c0ab..623ea6b 100644 --- a/src/barchart/barpresenter.h +++ b/src/barchart/barpresenter.h @@ -1,17 +1,20 @@ #ifndef BARPRESENTER_H #define BARPRESENTER_H +#include "qchartglobal.h" #include "barpresenterbase.h" -#include "qbarchartseries.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE +class QBarChartSeries; + // Presenter for parallel bars. Grouping of bars is done on category basis. class BarPresenter : public BarPresenterBase { + Q_OBJECT public: - explicit BarPresenter(BarChartModel& model, QGraphicsItem *parent = 0); + explicit BarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0); private: diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index 34bc5f5..207d9c0 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -4,24 +4,33 @@ #include "barlabel_p.h" #include "separator_p.h" #include "qbarset.h" +#include "qbarchartseries.h" #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE -BarPresenterBase::BarPresenterBase(BarChartModel& model, QGraphicsItem *parent) +BarPresenterBase::BarPresenterBase(QBarChartSeries *series, QGraphicsItem *parent) : ChartItem(parent) ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready ,mLayoutSet(false) ,mLayoutDirty(true) - ,mSeparatorsVisible(false) - ,mModel(model) + ,mSeries(series) { + connect(series,SIGNAL(floatingValuesEnabled(bool)),this,SLOT(enableFloatingValues(bool))); + connect(series,SIGNAL(toolTipEnabled(bool)),this,SLOT(enableToolTip(bool))); + connect(series,SIGNAL(separatorsEnabled(bool)),this,SLOT(enableSeparators(bool))); + connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); dataChanged(); } -void BarPresenterBase::setSeparatorsVisible(bool visible) +BarPresenterBase::~BarPresenterBase() { - mSeparatorsVisible = visible; + disconnect(this,SLOT(enableFloatingValues(bool))); + disconnect(this,SLOT(enableToolTip(bool))); + disconnect(this,SLOT(enableSeparators(bool))); + disconnect(this,SLOT(showToolTip(QPoint,QString))); + delete mSeries; } void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -63,9 +72,9 @@ void BarPresenterBase::dataChanged() mFloatingValues.clear(); // Create new graphic items for bars - for (int c=0; ccountCategories(); c++) { + for (int s=0; scountSets(); s++) { + QBarSet *set = mSeries->setAt(s); Bar *bar = new Bar(this); childItems().append(bar); mBars.append(bar); @@ -77,16 +86,16 @@ void BarPresenterBase::dataChanged() } // Create labels - int count = mModel.countCategories(); + int count = mSeries->countCategories(); for (int i=0; iset(mModel.label(i)); + label->set(mSeries->label(i)); childItems().append(label); mLabels.append(label); } // Create separators - count = mModel.countCategories() - 1; // There is one less separator than columns + count = mSeries->countCategories() - 1; // There is one less separator than columns for (int i=0; isetColor(QColor(255,0,0,255)); // TODO: color for separations from theme @@ -95,9 +104,9 @@ void BarPresenterBase::dataChanged() } // Create floating values - for (int category=0; categorycountCategories(); category++) { + for (int s=0; scountSets(); s++) { + QBarSet *set = mSeries->setAt(s); BarValue *value = new BarValue(*set, this); childItems().append(value); mFloatingValues.append(value); @@ -134,15 +143,27 @@ void BarPresenterBase::handleGeometryChanged(const QRectF& rect) setPos(rect.topLeft()); } +void BarPresenterBase::enableFloatingValues(bool enabled) +{ + mFloatingValuesEnabled = enabled; +} + +void BarPresenterBase::enableToolTip(bool enabled) +{ + mToolTipEnabled = enabled; +} -void BarPresenterBase::barHoverEntered(QGraphicsSceneHoverEvent *event) +void BarPresenterBase::enableSeparators(bool enabled) { - //TODO: show tooltip (name of series, where bar belongs...) + mSeparatorsEnabled = enabled; } -void BarPresenterBase::barHoverLeaved(QGraphicsSceneHoverEvent *event) +void BarPresenterBase::showToolTip(QPoint pos, QString tip) { - //TODO: hide tooltip (name of series, where bar belongs...) + if (mToolTipEnabled) { + // TODO: cool tooltip instead of default + QToolTip::showText(pos,tip); + } } #include "moc_barpresenterbase.cpp" diff --git a/src/barchart/barpresenterbase.h b/src/barchart/barpresenterbase.h index 11fe9f0..7787409 100644 --- a/src/barchart/barpresenterbase.h +++ b/src/barchart/barpresenterbase.h @@ -2,7 +2,7 @@ #define BARPRESENTERBASE_H #include "chartitem_p.h" -#include "barchartmodel_p.h" +#include "qbarchartseries.h" #include #include #include @@ -20,11 +20,10 @@ class BarPresenterBase : public QObject, public ChartItem { Q_OBJECT public: - BarPresenterBase(BarChartModel& model, QGraphicsItem *parent = 0); - void setSeparatorsVisible(bool visible = true); + BarPresenterBase(QBarChartSeries *series, QGraphicsItem *parent = 0); + ~BarPresenterBase(); public: - // From QGraphicsItem void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; @@ -41,8 +40,11 @@ protected slots: void handleDomainChanged(const Domain& domain); void handleGeometryChanged(const QRectF& size); - void barHoverEntered(QGraphicsSceneHoverEvent *event); // Internal. - void barHoverLeaved(QGraphicsSceneHoverEvent *event); + // Internal slots + void enableFloatingValues(bool enabled=true); // enables floating values on top of bars + void enableToolTip(bool enabled=true); // enables tooltips + void enableSeparators(bool enabled=true); // enables separators between categories + void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) protected: @@ -54,14 +56,19 @@ protected: bool mLayoutSet; // True, if component has been laid out. bool mLayoutDirty; - bool mSeparatorsVisible; - BarChartModel& mModel; + bool mFloatingValuesEnabled; + bool mToolTipEnabled; + bool mSeparatorsEnabled; + + // Owned + QBarChartSeries* mSeries; // Not owned. QList mBars; QList mLabels; QList mSeparators; QList mFloatingValues; + }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/percentbarpresenter.cpp b/src/barchart/percentbarpresenter.cpp index 4aae2c4..f620f80 100644 --- a/src/barchart/percentbarpresenter.cpp +++ b/src/barchart/percentbarpresenter.cpp @@ -9,8 +9,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -PercentBarPresenter::PercentBarPresenter(BarChartModel& model, QGraphicsItem *parent) : - BarPresenterBase(model, parent) +PercentBarPresenter::PercentBarPresenter(QBarChartSeries *series, QGraphicsItem *parent) : + BarPresenterBase(series, parent) { } @@ -18,7 +18,7 @@ void PercentBarPresenter::layoutChanged() { // Scale bars to new layout // Layout for bars: - if (mModel.countSets() <= 0) { + if (mSeries->countSets() <= 0) { qDebug() << "No sets in model!"; // Nothing to do. return; @@ -31,7 +31,7 @@ void PercentBarPresenter::layoutChanged() // TODO: better way to auto-layout // Use reals for accurancy (we might get some compiler warnings... :) - int count = mModel.countCategories(); + int count = mSeries->countCategories(); int itemIndex(0); int labelIndex(0); qreal tW = mWidth; @@ -40,17 +40,17 @@ void PercentBarPresenter::layoutChanged() qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); qreal h = mHeight; - for (int category = 0; category < mModel.countCategories(); category++) { - qreal colSum = mModel.categorySum(category); + for (int category = 0; category < mSeries->countCategories(); category++) { + qreal colSum = mSeries->categorySum(category); qreal scale = (h / colSum); qreal yPos = h; - for (int set=0; set < mModel.countSets(); set++) { - qreal barHeight = mModel.valueAt(set, category) * scale; + for (int set=0; set < mSeries->countSets(); set++) { + qreal barHeight = mSeries->valueAt(set, category) * scale; Bar* bar = mBars.at(itemIndex); // TODO: width settable per bar? bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mModel.setAt(set)->brush()); + bar->setBrush(mSeries->setAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; yPos -= barHeight; @@ -65,7 +65,7 @@ void PercentBarPresenter::layoutChanged() // Position separators xPos = xStep + xStep/2; - for (int s=0; s < mModel.countCategories() - 1; s++) { + for (int s=0; s < mSeries->countCategories() - 1; s++) { Separator* sep = mSeparators.at(s); sep->setPos(xPos,0); sep->setSize(QSizeF(1,mHeight)); @@ -75,12 +75,12 @@ void PercentBarPresenter::layoutChanged() // Position floating values itemIndex = 0; xPos = ((tW/tC) - mBarDefaultWidth / 2); - for (int category=0; category < mModel.countCategories(); category++) { + for (int category=0; category < mSeries->countCategories(); category++) { qreal yPos = h; - qreal colSum = mModel.categorySum(category); + qreal colSum = mSeries->categorySum(category); qreal scale = (h / colSum); - for (int set=0; set < mModel.countSets(); set++) { - qreal barHeight = mModel.valueAt(set,category) * scale; + for (int set=0; set < mSeries->countSets(); set++) { + qreal barHeight = mSeries->valueAt(set,category) * scale; BarValue* value = mFloatingValues.at(itemIndex); // TODO: remove hard coding, apply layout @@ -88,8 +88,8 @@ void PercentBarPresenter::layoutChanged() value->setPos(xPos, yPos-barHeight/2); value->setPen(QPen(QColor(255,255,255,255))); - if (mModel.valueAt(set,category) != 0) { - int p = mModel.percentageAt(set,category) * 100; + if (mSeries->valueAt(set,category) != 0) { + int p = mSeries->percentageAt(set,category) * 100; QString vString(QString::number(p)); vString.truncate(3); vString.append("%"); @@ -107,4 +107,6 @@ void PercentBarPresenter::layoutChanged() mLayoutDirty = true; } +#include "moc_percentbarpresenter.cpp" + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/percentbarpresenter.h b/src/barchart/percentbarpresenter.h index fa35af6..fa16399 100644 --- a/src/barchart/percentbarpresenter.h +++ b/src/barchart/percentbarpresenter.h @@ -11,8 +11,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class PercentBarPresenter : public BarPresenterBase { + Q_OBJECT public: - PercentBarPresenter(BarChartModel& model, QGraphicsItem *parent = 0); + PercentBarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0); private: diff --git a/src/barchart/qbarchartseries.cpp b/src/barchart/qbarchartseries.cpp index 0dab9b6..4a0e31a 100644 --- a/src/barchart/qbarchartseries.cpp +++ b/src/barchart/qbarchartseries.cpp @@ -15,15 +15,18 @@ QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent) void QBarChartSeries::addBarSet(QBarSet *set) { -// connect(this,SIGNAL(floatingValuesEnabled(bool)),set,SLOT(enableFloatingValues(bool))); -// connect(this,SIGNAL(hoverNamesEnabled(bool)),set,SLOT(enableHoverNames(bool))); + connect(this,SIGNAL(floatingValuesEnabled(bool)),set,SLOT(enableFloatingValues(bool))); + connect(this,SIGNAL(separatorsEnabled(bool)),set,SLOT(enableSeparators(bool))); + connect(this,SIGNAL(toolTipEnabled(bool)),set,SLOT(enableToolTip(bool))); + connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); mModel->addBarSet(set); } void QBarChartSeries::removeBarSet(QBarSet *set) { -// disconnect(set,SLOT(enableFloatingValues(bool))); -// disconnect(set,SLOT(enableHoverNames(bool))); + disconnect(set,SLOT(enableFloatingValues(bool))); + disconnect(set,SLOT(enableSeparators(bool))); + disconnect(set,SLOT(enableToolTip(bool))); mModel->removeBarSet(set); } @@ -37,19 +40,34 @@ QBarSet* QBarChartSeries::nextSet(bool getFirst) return mModel->nextSet(getFirst); } +QBarSet* QBarChartSeries::setAt(int index) +{ + return mModel->setAt(index); +} + QList QBarChartSeries::legend() { return mModel->legend(); } +QString QBarChartSeries::label(int category) +{ + return mModel->label(category); +} + void QBarChartSeries::enableFloatingValues(bool enabled) { emit floatingValuesEnabled(enabled); } -void QBarChartSeries::enableHoverNames(bool enabled) +void QBarChartSeries::enableToolTip(bool enabled) { - emit hoverNamesEnabled(enabled); + emit toolTipEnabled(enabled); +} + +void QBarChartSeries::enableSeparators(bool enabled) +{ + emit separatorsEnabled(enabled); } int QBarChartSeries::countCategories() @@ -72,6 +90,16 @@ qreal QBarChartSeries::valueAt(int set, int category) return mModel->valueAt(set,category); } +qreal QBarChartSeries::percentageAt(int set, int category) +{ + return mModel->percentageAt(set,category); +} + +qreal QBarChartSeries::categorySum(int category) +{ + return mModel->categorySum(category); +} + qreal QBarChartSeries::maxCategorySum() { return mModel->maxCategorySum(); diff --git a/src/barchart/qbarchartseries.h b/src/barchart/qbarchartseries.h index b93240e..bfe345a 100644 --- a/src/barchart/qbarchartseries.h +++ b/src/barchart/qbarchartseries.h @@ -22,19 +22,27 @@ public: void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set int countSets(); QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true + QBarSet *setAt(int index); - QList legend(); // Returns legend of series (ie. names of all sets in series) + QList legend(); // Returns legend of series (ie. names of all sets in series) + QString label(int category); +public Q_SLOTS: // Disabled by default. Call these to change behavior. - void enableFloatingValues(bool enabled=true); - void enableHoverNames(bool enabled=true); + void enableFloatingValues(bool enabled=true); // enables floating values on top of bars + void enableToolTip(bool enabled=true); // enables tooltips + void enableSeparators(bool enabled=true); // enables separators between categories +public: // TODO: Functions below this are not part of api and will be moved // to private implementation, when we start using it (not part of api) int countCategories(); qreal min(); qreal max(); qreal valueAt(int set, int category); + qreal percentageAt(int set, int category); + + qreal categorySum(int category); qreal maxCategorySum(); BarChartModel& model(); @@ -42,12 +50,11 @@ public: signals: void changed(int index); - // TODO: these to private implementation. + // TODO: internal signals, these to private implementation. void floatingValuesEnabled(bool enabled); - void hoverNamesEnabled(bool enabled); - - -//public Q_SLOTS: + void toolTipEnabled(bool enabled); + void separatorsEnabled(bool enabled); + void showToolTip(QPoint pos, QString tip); protected: BarChartModel* mModel; diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index 10fa65d..7fe2ef2 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -7,7 +7,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QBarSet::QBarSet(QString name, QObject *parent) : QObject(parent) ,mName(name) - ,mHoverNamesEnabled(true) // TODO: these 2 as false by default, when implementation is ready + ,mToolTipEnabled(true) // TODO: these 2 as false by default, when implementation is ready ,mFloatingValuesEnabled(true) { } @@ -64,19 +64,25 @@ const QBrush& QBarSet::brush() const void QBarSet::enableFloatingValues(bool enabled) { - qDebug() << "QBarSet::enableFloatingValues" << enabled; + qDebug() << "QBarSet::enableFloatingValues"; mFloatingValuesEnabled = enabled; } void QBarSet::enableToolTip(bool enabled) { - qDebug() << "QBarSet::enableHoverNames" << enabled; - mHoverNamesEnabled = enabled; + qDebug() << "QBarSet::enableToolTip"; + mToolTipEnabled = enabled; +} + +void QBarSet::enableSeparators(bool enabled) +{ + qDebug() << "QBarSet::enableSeparators"; + mSeparatorsEnabled = enabled; } void QBarSet::barClicked() { - qDebug() << "QBarset::barClicked" << this; +// qDebug() << "QBarset::barClicked" << this; // Some bar of this set has been clicked // TODO: What happens then? emit clicked(); // Notify that set has been clicked @@ -84,19 +90,21 @@ void QBarSet::barClicked() void QBarSet::barHoverEntered(QPoint pos) { - qDebug() << "QBarset::barHoverEntered" << this << pos; - if (mHoverNamesEnabled) { - QToolTip::showText(pos, mName); -// emit hoverEnter(); + if (mToolTipEnabled) { + emit showToolTip(pos, mName); } + // Emit signal to user of charts + emit hoverEnter(pos); } void QBarSet::barHoverLeaved() { - qDebug() << "QBarset::barHoverLeaved" << this; - if (mHoverNamesEnabled) { -// emit hoverLeave(); - } +// qDebug() << "QBarset::barHoverLeaved" << this; +// if (mToolTipEnabled) { + // TODO: do what? +// } + // Emit signal to user of charts + emit hoverLeave(); } #include "moc_qbarset.cpp" diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 50da311..964144e 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -29,14 +29,15 @@ public: Q_SIGNALS: void clicked(); // Clicked and hover signals exposed to user - void hoverEnter(); + void hoverEnter(QPoint pos); void hoverLeave(); - void toggleFloatingValues(); // Private signal, TODO: move to private impl + void toggleFloatingValues(); // Private signal, TODO: move to private impl + void showToolTip(QPoint pos, QString tip); // Private signal, TODO: move to private impl public Q_SLOTS: - // TODO: should these be in series instead? void enableFloatingValues(bool enabled); // enables floating values on top of bars void enableToolTip(bool enabled); // enables tooltips + void enableSeparators(bool enabled); // enables separators between categories // TODO: these slots belong to private implementation. // These are for single bars to notify set about internal events @@ -53,7 +54,8 @@ private: // TODO: to pimpl bool mFloatingValuesEnabled; - bool mHoverNamesEnabled; + bool mToolTipEnabled; + bool mSeparatorsEnabled; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/stackedbarpresenter.cpp b/src/barchart/stackedbarpresenter.cpp index 8816756..644548c 100644 --- a/src/barchart/stackedbarpresenter.cpp +++ b/src/barchart/stackedbarpresenter.cpp @@ -8,8 +8,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -StackedBarPresenter::StackedBarPresenter(BarChartModel& model, QGraphicsItem *parent) : - BarPresenterBase(model,parent) +StackedBarPresenter::StackedBarPresenter(QBarChartSeries *series, QGraphicsItem *parent) : + BarPresenterBase(series,parent) { } @@ -17,13 +17,13 @@ void StackedBarPresenter::layoutChanged() { // Scale bars to new layout // Layout for bars: - if (mModel.countSets() <= 0) { + if (mSeries->countSets() <= 0) { qDebug() << "No sets in model!"; // Nothing to do. return; } - if (mModel.countCategories() == 0) { + if (mSeries->countCategories() == 0) { qDebug() << "No categories in model!"; // Nothing to do return; @@ -37,25 +37,25 @@ void StackedBarPresenter::layoutChanged() // TODO: better way to auto-layout // Use reals for accurancy (we might get some compiler warnings... :) // TODO: use temp variable for category count... - qreal maxSum = mModel.maxCategorySum(); + qreal maxSum = mSeries->maxCategorySum(); qreal h = mHeight; qreal scale = (h / maxSum); int itemIndex(0); int labelIndex(0); qreal tW = mWidth; - qreal tC = mModel.countCategories() + 1; + qreal tC = mSeries->countCategories() + 1; qreal xStep = (tW/tC); qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); - for (int category = 0; category < mModel.countCategories(); category++) { + for (int category = 0; category < mSeries->countCategories(); category++) { qreal yPos = h; - for (int set=0; set < mModel.countSets(); set++) { - qreal barHeight = mModel.valueAt(set, category) * scale; + for (int set=0; set < mSeries->countSets(); set++) { + qreal barHeight = mSeries->valueAt(set, category) * scale; Bar* bar = mBars.at(itemIndex); bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mModel.setAt(set)->brush()); + bar->setBrush(mSeries->setAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; yPos -= barHeight; @@ -70,7 +70,7 @@ void StackedBarPresenter::layoutChanged() // Position separators xPos = xStep + xStep/2; - for (int s=0; s < mModel.countCategories() - 1; s++) { + for (int s=0; s < mSeries->countCategories() - 1; s++) { Separator* sep = mSeparators.at(s); sep->setPos(xPos,0); sep->setSize(QSizeF(1,mHeight)); @@ -80,10 +80,10 @@ void StackedBarPresenter::layoutChanged() // Position floating values itemIndex = 0; xPos = ((tW/tC) - mBarDefaultWidth / 2); - for (int category=0; category < mModel.countCategories(); category++) { + for (int category=0; category < mSeries->countCategories(); category++) { qreal yPos = h; - for (int set=0; set < mModel.countSets(); set++) { - qreal barHeight = mModel.valueAt(set,category) * scale; + for (int set=0; set < mSeries->countSets(); set++) { + qreal barHeight = mSeries->valueAt(set,category) * scale; BarValue* value = mFloatingValues.at(itemIndex); // TODO: remove hard coding, apply layout @@ -91,8 +91,8 @@ void StackedBarPresenter::layoutChanged() value->setPos(xPos, yPos-barHeight/2); value->setPen(QPen(QColor(255,255,255,255))); - if (mModel.valueAt(set,category) != 0) { - value->setValueString(QString::number(mModel.valueAt(set,category))); + if (mSeries->valueAt(set,category) != 0) { + value->setValueString(QString::number(mSeries->valueAt(set,category))); } else { value->setValueString(QString("")); } @@ -106,4 +106,6 @@ void StackedBarPresenter::layoutChanged() mLayoutDirty = true; } +#include "moc_stackedbarpresenter.cpp" + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/stackedbarpresenter.h b/src/barchart/stackedbarpresenter.h index 1db1be0..a3afa29 100644 --- a/src/barchart/stackedbarpresenter.h +++ b/src/barchart/stackedbarpresenter.h @@ -9,8 +9,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class StackedBarPresenter : public BarPresenterBase { + Q_OBJECT public: - StackedBarPresenter(BarChartModel& model, QGraphicsItem *parent = 0); + StackedBarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0); private: // From BarPresenterBase diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index e767dc6..06ea2a1 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -115,7 +115,7 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) case QChartSeries::SeriesTypeBar: { QBarChartSeries* barSeries = static_cast(series); - BarPresenter* item = new BarPresenter(barSeries->model(),m_chart); + BarPresenter* item = new BarPresenter(barSeries,m_chart); m_chartTheme->decorate(item,barSeries,m_chartItems.count()); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); @@ -127,7 +127,7 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) case QChartSeries::SeriesTypeStackedBar: { QStackedBarChartSeries* stackedBarSeries = static_cast(series); - StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries->model(),m_chart); + StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); @@ -138,7 +138,7 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) case QChartSeries::SeriesTypePercentBar: { QPercentBarChartSeries* percentBarSeries = static_cast(series); - PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries->model(),m_chart); + PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));