diff --git a/src/barchart/barchartitem.cpp b/src/barchart/barchartitem.cpp index b242ff6..8acf6b3 100644 --- a/src/barchart/barchartitem.cpp +++ b/src/barchart/barchartitem.cpp @@ -156,9 +156,6 @@ QVector BarChartItem::calculateLayout() BarValue* value = m_floatingValues.at(itemIndex); QBarSet* barSet = m_series->barsetAt(set); - value->resize(100, 50); // TODO: proper layout for this. - value->setPos(xPos, yPos-barHeight / 2); - value->setPen(barSet->floatingValuePen()); if (!qFuzzyIsNull(m_series->valueAt(set,category))) { value->setText(QString::number(m_series->valueAt(set, category))); @@ -166,6 +163,9 @@ QVector BarChartItem::calculateLayout() value->setText(QString("")); } + value->setPos(xPos, yPos-barHeight / 2); + value->setPen(barSet->floatingValuePen()); + itemIndex++; xPos += barWidth; } @@ -224,7 +224,6 @@ void BarChartItem::handleLayoutChanged() update(); } - void BarChartItem::showToolTip(QPoint pos, QString tip) { // TODO: cool tooltip instead of default diff --git a/src/barchart/barchartitem_p.h b/src/barchart/barchartitem_p.h index 81ee3d8..d042ed8 100644 --- a/src/barchart/barchartitem_p.h +++ b/src/barchart/barchartitem_p.h @@ -25,7 +25,6 @@ #include "qbarseries.h" #include #include -#include QTCOMMERCIALCHART_BEGIN_NAMESPACE diff --git a/src/barchart/barvalue.cpp b/src/barchart/barvalue.cpp index 000ca0e..91c3660 100644 --- a/src/barchart/barvalue.cpp +++ b/src/barchart/barvalue.cpp @@ -21,71 +21,66 @@ #include "barvalue_p.h" #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE -BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) - : QGraphicsObject(parent), +BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) : QGraphicsObject(parent), m_barSet(set), - m_xPos(0), - m_yPos(0), - m_width(0), - m_height(0) + m_textItem(new QGraphicsSimpleTextItem(this)) { setVisible(false); } void BarValue::setText(QString str) { - m_valueString = str; + m_textItem->setText(str); } QString BarValue::text() const { - return m_valueString; + return m_textItem->text(); } void BarValue::setPen(const QPen &pen) { - m_pen = pen; + m_textItem->setPen(pen); } QPen BarValue::pen() const { - return m_pen; + return m_textItem->pen(); } -void BarValue::resize(qreal w, qreal h) +void BarValue::setFont(const QFont &font) { - m_width = w; - m_height = h; + m_textItem->setFont(font); +} + +QFont BarValue::font() const +{ + return m_textItem->font(); } void BarValue::setPos(qreal x, qreal y) { - m_xPos = x; - m_yPos = y; + m_textItem->setPos(x,y); } void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) Q_UNUSED(widget) - - if (isVisible()) { - painter->setPen(m_pen); - painter->drawText(boundingRect(), m_valueString); - } } QRectF BarValue::boundingRect() const { - QRectF r(m_xPos, m_yPos, m_width, m_height); - return r; + return m_textItem->boundingRect(); } void BarValue::toggleVisible() { + qDebug() << "toggle visible"; setVisible(!isVisible()); } diff --git a/src/barchart/barvalue_p.h b/src/barchart/barvalue_p.h index 232c1e5..b67c9fd 100644 --- a/src/barchart/barvalue_p.h +++ b/src/barchart/barvalue_p.h @@ -24,6 +24,7 @@ #include "qchartglobal.h" #include #include +class QGraphicsSimpleTextItem; QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -43,7 +44,9 @@ public: void setPen(const QPen &pen); QPen pen() const; - void resize(qreal w, qreal h); + void setFont(const QFont &font); + QFont font() const; + void setPos(qreal x, qreal y); // From QGraphicsItem @@ -56,13 +59,7 @@ public Q_SLOTS: private: QBarSet &m_barSet; - QPen m_pen; - QString m_valueString; - - qreal m_xPos; - qreal m_yPos; - qreal m_width; - qreal m_height; + QGraphicsSimpleTextItem *m_textItem; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/percentbarchartitem.cpp b/src/barchart/percentbarchartitem.cpp index b95b1e1..141a813 100644 --- a/src/barchart/percentbarchartitem.cpp +++ b/src/barchart/percentbarchartitem.cpp @@ -74,9 +74,6 @@ QVector PercentBarChartItem::calculateLayout() BarValue* value = m_floatingValues.at(itemIndex); QBarSet* barSet = m_series->barsetAt(set); - value->resize(100, 50); // TODO: proper layout for this. - value->setPos(xPos, yPos-barHeight / 2); - value->setPen(barSet->floatingValuePen()); if (!qFuzzyIsNull(m_series->valueAt(set,category))) { int p = m_series->percentageAt(set,category) * 100; @@ -88,6 +85,9 @@ QVector PercentBarChartItem::calculateLayout() value->setText(QString("")); } + value->setPos(xPos, yPos-barHeight / 2); + value->setPen(barSet->floatingValuePen()); + itemIndex++; yPos -= barHeight; } diff --git a/src/barchart/stackedbarchartitem.cpp b/src/barchart/stackedbarchartitem.cpp index e5373f7..4c92ca1 100644 --- a/src/barchart/stackedbarchartitem.cpp +++ b/src/barchart/stackedbarchartitem.cpp @@ -80,9 +80,6 @@ QVector StackedBarChartItem::calculateLayout() BarValue* value = m_floatingValues.at(itemIndex); QBarSet* barSet = m_series->barsetAt(set); - value->resize(100, 50); // TODO: proper layout for this. - value->setPos(xPos, yPos-barHeight / 2); - value->setPen(barSet->floatingValuePen()); if (!qFuzzyIsNull(m_series->valueAt(set, category))) { value->setText(QString::number(m_series->valueAt(set,category))); @@ -90,6 +87,9 @@ QVector StackedBarChartItem::calculateLayout() value->setText(QString("")); } + value->setPos(xPos, yPos-barHeight / 2); + value->setPen(barSet->floatingValuePen()); + itemIndex++; yPos -= barHeight; }