From 108ca5a00d742b35a288bd49ac741582849dc8a6 2012-02-22 10:54:39 From: sauimone Date: 2012-02-22 10:54:39 Subject: [PATCH] floating values working now. bounding rect bug fixed --- diff --git a/example/stackedbarchart/main.cpp b/example/stackedbarchart/main.cpp index c593b92..cf6294c 100644 --- a/example/stackedbarchart/main.cpp +++ b/example/stackedbarchart/main.cpp @@ -26,15 +26,15 @@ int main(int argc, char *argv[]) // Create some test data to chart *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; - *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; - *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; - *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; +// *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; +// *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; +// *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; series0->addBarSet(set0); - series0->addBarSet(set1); - series0->addBarSet(set2); - series0->addBarSet(set3); +// series0->addBarSet(set1); +// series0->addBarSet(set2); +// series0->addBarSet(set3); series0->addBarSet(set4); ChartWidget* chartWidget = new ChartWidget(&window); diff --git a/src/barchart/bar.cpp b/src/barchart/bar.cpp index 615314b..941c5be 100644 --- a/src/barchart/bar.cpp +++ b/src/barchart/bar.cpp @@ -63,7 +63,7 @@ void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg QRectF Bar::boundingRect() const { - QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); + QRectF r(mXpos, mYpos, mWidth, mHeight); return r; } diff --git a/src/barchart/barchartmodel.cpp b/src/barchart/barchartmodel.cpp index 55826af..463dc47 100644 --- a/src/barchart/barchartmodel.cpp +++ b/src/barchart/barchartmodel.cpp @@ -51,10 +51,9 @@ QBarSet* BarChartModel::nextSet(bool getFirst) return set; } - -QBarSet& BarChartModel::setAt(int index) +QBarSet* BarChartModel::setAt(int index) { - return *mDataModel.at(index); + return mDataModel.at(index); } int BarChartModel::countSets() diff --git a/src/barchart/barchartmodel_p.h b/src/barchart/barchartmodel_p.h index 26f3009..40b821d 100644 --- a/src/barchart/barchartmodel_p.h +++ b/src/barchart/barchartmodel_p.h @@ -23,8 +23,7 @@ public: void addBarSet(QBarSet *set); void removeBarSet(QBarSet *set); QBarSet* nextSet(bool getFirst); - - QBarSet& setAt(int index); // Internal + QBarSet *setAt(int index); int countSets(); // Number of sets in model int countCategories(); // Number of categories diff --git a/src/barchart/barlabel.cpp b/src/barchart/barlabel.cpp index 3437334..6f8c635 100644 --- a/src/barchart/barlabel.cpp +++ b/src/barchart/barlabel.cpp @@ -29,7 +29,7 @@ void BarLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QRectF BarLabel::boundingRect() const { - QRectF r(mXpos, mYpos, mXpos + mSize.width(), mYpos + mSize.height()); + QRectF r(mXpos, mYpos, mSize.width(), mSize.height()); return r; } diff --git a/src/barchart/barpresenter.cpp b/src/barchart/barpresenter.cpp index 3323d2a..592f997 100644 --- a/src/barchart/barpresenter.cpp +++ b/src/barchart/barpresenter.cpp @@ -52,7 +52,7 @@ void BarPresenter::layoutChanged() // TODO: width settable per bar? bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mModel.setAt(set).brush()); + bar->setBrush(mModel.setAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight); itemIndex++; xPos += mBarDefaultWidth; diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index 4eba484..75d5782 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -63,13 +63,13 @@ void BarPresenterBase::dataChanged() mFloatingValues.clear(); // Create new graphic items for bars - for (int s=0; sbelongsToSet(set)) { - mFloatingValues.at(i)->setVisible(set->isFloatingValuesVisible()); - } - } -} - //handlers void BarPresenterBase::handleModelChanged(int index) diff --git a/src/barchart/barpresenterbase.h b/src/barchart/barpresenterbase.h index ecbe5fa..01c9ace 100644 --- a/src/barchart/barpresenterbase.h +++ b/src/barchart/barpresenterbase.h @@ -41,9 +41,6 @@ public: virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes -public Q_SLOTS: - void setFloatingValues(QBarSet *set); - protected slots: void handleModelChanged(int index); void handleDomainChanged(const Domain& domain); diff --git a/src/barchart/barvalue.cpp b/src/barchart/barvalue.cpp index cfa2063..3673227 100644 --- a/src/barchart/barvalue.cpp +++ b/src/barchart/barvalue.cpp @@ -5,10 +5,10 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) - : QGraphicsItem(parent) + : QGraphicsObject(parent) ,mBarSet(set) { -// setVisible(false); + setVisible(false); } void BarValue::setValueString(QString str) @@ -56,9 +56,14 @@ void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QRectF BarValue::boundingRect() const { - QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); + QRectF r(mXpos, mYpos, mWidth, mHeight); return r; } +void BarValue::toggleVisible() +{ + setVisible(!isVisible()); +} +#include "moc_barvalue_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/barvalue_p.h b/src/barchart/barvalue_p.h index eaba88b..e705c14 100644 --- a/src/barchart/barvalue_p.h +++ b/src/barchart/barvalue_p.h @@ -2,7 +2,7 @@ #define BARVALUE_P_H #include "qchartglobal.h" -#include +#include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -12,8 +12,9 @@ class QBarSet; // Visual class for floating bar values // TODO: fonts, colors etc. // By default these are not visible. -class BarValue : public QGraphicsItem // TODO: public QGraphicsObject for signals? +class BarValue : public QGraphicsObject { + Q_OBJECT public: BarValue(QBarSet &set, QGraphicsItem *parent = 0); @@ -32,6 +33,9 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; +public Q_SLOTS: + void toggleVisible(); + private: QBarSet& mBarSet; diff --git a/src/barchart/percentbarpresenter.cpp b/src/barchart/percentbarpresenter.cpp index dd90d73..7169a17 100644 --- a/src/barchart/percentbarpresenter.cpp +++ b/src/barchart/percentbarpresenter.cpp @@ -50,7 +50,7 @@ void PercentBarPresenter::layoutChanged() // TODO: width settable per bar? bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mModel.setAt(set).brush()); + bar->setBrush(mModel.setAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; yPos -= barHeight; diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index fc0107a..1548c2d 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -65,24 +65,11 @@ bool QBarSet::isFloatingValuesVisible() void QBarSet::barClicked() { - qDebug() << "QBarset::barClicked"; + qDebug() << "QBarset::barClicked" << this; // Some bar of this set has been clicked // TODO: What happens then? emit clicked(); // Notify that set has been clicked } -void QBarSet::toggleFloatingValuesVisible() -{ - qDebug() << "QBarset::toggleFloatingValuesVisible"; - // TODO: toggle vs explicit set? - if (mFloatingValuesVisible) { - mFloatingValuesVisible=false; - } else { - mFloatingValuesVisible=true; - } - emit setFloatingValuesVisible(this); -} - - #include "moc_qbarset.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 9a7e82a..889881a 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -31,7 +31,6 @@ public: Q_SIGNALS: void clicked(); - void setFloatingValuesVisible(QBarSet* set); /* void hoverEnter(); void hoverLeave(); @@ -39,7 +38,6 @@ Q_SIGNALS: public Q_SLOTS: void barClicked(); - void toggleFloatingValuesVisible(); private: diff --git a/src/barchart/stackedbarpresenter.cpp b/src/barchart/stackedbarpresenter.cpp index 67c0c7b..e5dafa0 100644 --- a/src/barchart/stackedbarpresenter.cpp +++ b/src/barchart/stackedbarpresenter.cpp @@ -55,7 +55,7 @@ void StackedBarPresenter::layoutChanged() Bar* bar = mBars.at(itemIndex); bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mModel.setAt(set).brush()); + bar->setBrush(mModel.setAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; yPos -= barHeight;