##// END OF EJS Templates
making bar as qobject causes crash for some reason. rewinding back a bit...
sauimone -
r247:8f79fcf18e90
parent child
Show More
@@ -5,10 +5,17
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 7 Bar::Bar(QGraphicsItem *parent)
8 : QGraphicsObject(parent)
8 : ChartItem(parent)
9 9 {
10 10 }
11 11
12 void Bar::setSize(const QSizeF& size)
13 {
14 mWidth = size.width();
15 mHeight = size.height();
16 }
17
18
12 19 void Bar::resize( qreal w, qreal h )
13 20 {
14 21 // qDebug() << "bar::resize" << w << h;
@@ -16,6 +23,11 void Bar::resize( qreal w, qreal h )
16 23 mHeight = h;
17 24 }
18 25
26 void Bar::setColor( QColor col )
27 {
28 mColor = col;
29 }
30
19 31 void Bar::setPos(qreal x, qreal y)
20 32 {
21 33 // qDebug() << "Bar::setpos" << x << y;
@@ -38,8 +50,10 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg
38 50 if (0 == mHeight) {
39 51 return;
40 52 }
41
53 // TODO: accept brush instead of color
42 54 painter->setBrush(mBrush);
55 // QBrush brush(mColor);
56 // painter->setBrush(brush);
43 57
44 58 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
45 59 int x0 = mXpos;
@@ -57,21 +71,6 QRectF Bar::boundingRect() const
57 71 return r;
58 72 }
59 73
60 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
61 {
62 emit hoverEnter();
63 }
64
65 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
66 {
67 emit hoverLeave();
68 }
69
70 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
71 {
72 emit clicked();
73 }
74
75 #include "moc_bar_p.cpp"
74 //#include "moc_bar_p.cpp"
76 75
77 76 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,43 +1,35
1 1 #ifndef BAR_H
2 2 #define BAR_H
3 3
4 //#include "chartitem_p.h"
4 #include "chartitem_p.h"
5 5 #include "qchartglobal.h"
6 #include <QGraphicsObject>
6 #include <QGraphicsItem>
7 7 #include <QPen>
8 8 #include <QBrush>
9 9
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11
12 12 // Single bar item of chart
13 class Bar : public QGraphicsObject
13 class Bar : public ChartItem
14 14 {
15 Q_OBJECT
16
17 15 public:
18 16 Bar(QGraphicsItem *parent=0);
19 17
20 public:
18 public: // from ChartItem
19 void setSize(const QSizeF &size);
21 20
22 21 // Layout Stuff
23 22 void resize(qreal w, qreal h); // Size of bar.
24 23 void setPos(qreal x, qreal y);
25 24 void setPen(QPen pen);
26 25 void setBrush(QBrush brush);
26 void setColor( QColor col); // deprecated
27 27
28 28 public:
29
30 29 // From QGraphicsItem
30
31 31 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
32 32 QRectF boundingRect() const;
33 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
34 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
35 void mousePressEvent(QGraphicsSceneMouseEvent *event);
36
37 Q_SIGNALS:
38 void clicked();
39 void hoverEnter();
40 void hoverLeave();
41 33
42 34 private:
43 35
@@ -45,6 +37,7 private:
45 37 qreal mWidth;
46 38 qreal mXpos;
47 39 qreal mYpos;
40 QColor mColor;
48 41
49 42 QBrush mBrush;
50 43 QPen mPen;
@@ -63,7 +63,7 void BarPresenterBase::dataChanged()
63 63 for (int c=0; c<mModel.countCategories(); c++) {
64 64 Bar *bar = new Bar(this);
65 65 childItems().append(bar);
66 connect(bar,SIGNAL(clicked()),set,SLOT(barClicked()));
66 //connect(bar,SIGNAL(clicked()),set,SLOT(barClicked()));
67 67 }
68 68 }
69 69
General Comments 0
You need to be logged in to leave comments. Login now