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