From 8eda47151036b0834091eb83f350c749cdf008ea 2012-02-21 15:48:58 From: sauimone Date: 2012-02-21 15:48:58 Subject: [PATCH] toggling of floating values. still bit buggy --- diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index b6d59f8..4eba484 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -69,7 +69,7 @@ void BarPresenterBase::dataChanged() Bar *bar = new Bar(this); childItems().append(bar); mBars.append(bar); - connect(bar,SIGNAL(clicked()),set,SLOT(barClicked())); + connect(bar,SIGNAL(clicked()),set,SLOT(toggleFloatingValuesVisible())); } } @@ -93,17 +93,30 @@ void BarPresenterBase::dataChanged() // Create floating values 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 01c9ace..ecbe5fa 100644 --- a/src/barchart/barpresenterbase.h +++ b/src/barchart/barpresenterbase.h @@ -41,6 +41,9 @@ 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 7faaefd..cfa2063 100644 --- a/src/barchart/barvalue.cpp +++ b/src/barchart/barvalue.cpp @@ -4,8 +4,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -BarValue::BarValue(QGraphicsItem *parent) +BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) : QGraphicsItem(parent) + ,mBarSet(set) { // setVisible(false); } @@ -42,6 +43,11 @@ void BarValue::setPos(qreal x, qreal y) mYpos = y; } +bool BarValue::belongsToSet(QBarSet *set) +{ + return (&mBarSet == set); +} + void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->setPen(mPen); diff --git a/src/barchart/barvalue_p.h b/src/barchart/barvalue_p.h index 60f442c..eaba88b 100644 --- a/src/barchart/barvalue_p.h +++ b/src/barchart/barvalue_p.h @@ -7,14 +7,15 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE +class QBarSet; // Visual class for floating bar values // TODO: fonts, colors etc. // By default these are not visible. -class BarValue : public QGraphicsItem +class BarValue : public QGraphicsItem // TODO: public QGraphicsObject for signals? { public: - BarValue(QGraphicsItem *parent = 0); + BarValue(QBarSet &set, QGraphicsItem *parent = 0); void setValueString(QString str); QString valueString(); @@ -25,12 +26,15 @@ public: void resize(qreal w, qreal h); void setPos(qreal x, qreal y); + bool belongsToSet(QBarSet *set); + // From QGraphicsItem void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; private: + QBarSet& mBarSet; QPen mPen; QString mValueString; diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index bde3c8e..fc0107a 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -5,6 +5,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QBarSet::QBarSet() { + mFloatingValuesVisible = false; } void QBarSet::setName(QString name) @@ -57,6 +58,11 @@ const QBrush& QBarSet::brush() const return mBrush; } +bool QBarSet::isFloatingValuesVisible() +{ + return mFloatingValuesVisible; +} + void QBarSet::barClicked() { qDebug() << "QBarset::barClicked"; @@ -65,6 +71,18 @@ void QBarSet::barClicked() 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 9202c8b..9a7e82a 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -27,8 +27,11 @@ public: void setBrush(const QBrush& brush); const QBrush& brush() const; + bool isFloatingValuesVisible(); + Q_SIGNALS: void clicked(); + void setFloatingValuesVisible(QBarSet* set); /* void hoverEnter(); void hoverLeave(); @@ -36,6 +39,7 @@ Q_SIGNALS: public Q_SLOTS: void barClicked(); + void toggleFloatingValuesVisible(); private: @@ -44,6 +48,7 @@ private: QPen mPen; QBrush mBrush; + bool mFloatingValuesVisible; }; QTCOMMERCIALCHART_END_NAMESPACE