##// END OF EJS Templates
simple text item for barvalue
sauimone -
r811:04debc5ee52b
parent child
Show More
@@ -156,9 +156,6 QVector<QRectF> BarChartItem::calculateLayout()
156 156 BarValue* value = m_floatingValues.at(itemIndex);
157 157
158 158 QBarSet* barSet = m_series->barsetAt(set);
159 value->resize(100, 50); // TODO: proper layout for this.
160 value->setPos(xPos, yPos-barHeight / 2);
161 value->setPen(barSet->floatingValuePen());
162 159
163 160 if (!qFuzzyIsNull(m_series->valueAt(set,category))) {
164 161 value->setText(QString::number(m_series->valueAt(set, category)));
@@ -166,6 +163,9 QVector<QRectF> BarChartItem::calculateLayout()
166 163 value->setText(QString(""));
167 164 }
168 165
166 value->setPos(xPos, yPos-barHeight / 2);
167 value->setPen(barSet->floatingValuePen());
168
169 169 itemIndex++;
170 170 xPos += barWidth;
171 171 }
@@ -224,7 +224,6 void BarChartItem::handleLayoutChanged()
224 224 update();
225 225 }
226 226
227
228 227 void BarChartItem::showToolTip(QPoint pos, QString tip)
229 228 {
230 229 // TODO: cool tooltip instead of default
@@ -25,7 +25,6
25 25 #include "qbarseries.h"
26 26 #include <QPen>
27 27 #include <QBrush>
28 #include <QGraphicsItem>
29 28
30 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 30
@@ -21,71 +21,66
21 21 #include "barvalue_p.h"
22 22 #include <QPainter>
23 23 #include <QPen>
24 #include <QGraphicsSimpleTextItem>
24 25
25 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 27
27 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent)
28 : QGraphicsObject(parent),
28 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) : QGraphicsObject(parent),
29 29 m_barSet(set),
30 m_xPos(0),
31 m_yPos(0),
32 m_width(0),
33 m_height(0)
30 m_textItem(new QGraphicsSimpleTextItem(this))
34 31 {
35 32 setVisible(false);
36 33 }
37 34
38 35 void BarValue::setText(QString str)
39 36 {
40 m_valueString = str;
37 m_textItem->setText(str);
41 38 }
42 39
43 40 QString BarValue::text() const
44 41 {
45 return m_valueString;
42 return m_textItem->text();
46 43 }
47 44
48 45 void BarValue::setPen(const QPen &pen)
49 46 {
50 m_pen = pen;
47 m_textItem->setPen(pen);
51 48 }
52 49
53 50 QPen BarValue::pen() const
54 51 {
55 return m_pen;
52 return m_textItem->pen();
56 53 }
57 54
58 void BarValue::resize(qreal w, qreal h)
55 void BarValue::setFont(const QFont &font)
59 56 {
60 m_width = w;
61 m_height = h;
57 m_textItem->setFont(font);
58 }
59
60 QFont BarValue::font() const
61 {
62 return m_textItem->font();
62 63 }
63 64
64 65 void BarValue::setPos(qreal x, qreal y)
65 66 {
66 m_xPos = x;
67 m_yPos = y;
67 m_textItem->setPos(x,y);
68 68 }
69 69
70 70 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
71 71 {
72 72 Q_UNUSED(option)
73 73 Q_UNUSED(widget)
74
75 if (isVisible()) {
76 painter->setPen(m_pen);
77 painter->drawText(boundingRect(), m_valueString);
78 }
79 74 }
80 75
81 76 QRectF BarValue::boundingRect() const
82 77 {
83 QRectF r(m_xPos, m_yPos, m_width, m_height);
84 return r;
78 return m_textItem->boundingRect();
85 79 }
86 80
87 81 void BarValue::toggleVisible()
88 82 {
83 qDebug() << "toggle visible";
89 84 setVisible(!isVisible());
90 85 }
91 86
@@ -24,6 +24,7
24 24 #include "qchartglobal.h"
25 25 #include <QGraphicsObject>
26 26 #include <QPen>
27 class QGraphicsSimpleTextItem;
27 28
28 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 30
@@ -43,7 +44,9 public:
43 44 void setPen(const QPen &pen);
44 45 QPen pen() const;
45 46
46 void resize(qreal w, qreal h);
47 void setFont(const QFont &font);
48 QFont font() const;
49
47 50 void setPos(qreal x, qreal y);
48 51
49 52 // From QGraphicsItem
@@ -56,13 +59,7 public Q_SLOTS:
56 59 private:
57 60
58 61 QBarSet &m_barSet;
59 QPen m_pen;
60 QString m_valueString;
61
62 qreal m_xPos;
63 qreal m_yPos;
64 qreal m_width;
65 qreal m_height;
62 QGraphicsSimpleTextItem *m_textItem;
66 63 };
67 64
68 65 QTCOMMERCIALCHART_END_NAMESPACE
@@ -74,9 +74,6 QVector<QRectF> PercentBarChartItem::calculateLayout()
74 74 BarValue* value = m_floatingValues.at(itemIndex);
75 75
76 76 QBarSet* barSet = m_series->barsetAt(set);
77 value->resize(100, 50); // TODO: proper layout for this.
78 value->setPos(xPos, yPos-barHeight / 2);
79 value->setPen(barSet->floatingValuePen());
80 77
81 78 if (!qFuzzyIsNull(m_series->valueAt(set,category))) {
82 79 int p = m_series->percentageAt(set,category) * 100;
@@ -88,6 +85,9 QVector<QRectF> PercentBarChartItem::calculateLayout()
88 85 value->setText(QString(""));
89 86 }
90 87
88 value->setPos(xPos, yPos-barHeight / 2);
89 value->setPen(barSet->floatingValuePen());
90
91 91 itemIndex++;
92 92 yPos -= barHeight;
93 93 }
@@ -80,9 +80,6 QVector<QRectF> StackedBarChartItem::calculateLayout()
80 80 BarValue* value = m_floatingValues.at(itemIndex);
81 81
82 82 QBarSet* barSet = m_series->barsetAt(set);
83 value->resize(100, 50); // TODO: proper layout for this.
84 value->setPos(xPos, yPos-barHeight / 2);
85 value->setPen(barSet->floatingValuePen());
86 83
87 84 if (!qFuzzyIsNull(m_series->valueAt(set, category))) {
88 85 value->setText(QString::number(m_series->valueAt(set,category)));
@@ -90,6 +87,9 QVector<QRectF> StackedBarChartItem::calculateLayout()
90 87 value->setText(QString(""));
91 88 }
92 89
90 value->setPos(xPos, yPos-barHeight / 2);
91 value->setPen(barSet->floatingValuePen());
92
93 93 itemIndex++;
94 94 yPos -= barHeight;
95 95 }
General Comments 0
You need to be logged in to leave comments. Login now