##// 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 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 Bar::Bar(QGraphicsItem *parent)
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 void Bar::resize( qreal w, qreal h )
19 void Bar::resize( qreal w, qreal h )
13 {
20 {
14 // qDebug() << "bar::resize" << w << h;
21 // qDebug() << "bar::resize" << w << h;
@@ -16,6 +23,11 void Bar::resize( qreal w, qreal h )
16 mHeight = h;
23 mHeight = h;
17 }
24 }
18
25
26 void Bar::setColor( QColor col )
27 {
28 mColor = col;
29 }
30
19 void Bar::setPos(qreal x, qreal y)
31 void Bar::setPos(qreal x, qreal y)
20 {
32 {
21 // qDebug() << "Bar::setpos" << x << y;
33 // qDebug() << "Bar::setpos" << x << y;
@@ -38,8 +50,10 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg
38 if (0 == mHeight) {
50 if (0 == mHeight) {
39 return;
51 return;
40 }
52 }
41
53 // TODO: accept brush instead of color
42 painter->setBrush(mBrush);
54 painter->setBrush(mBrush);
55 // QBrush brush(mColor);
56 // painter->setBrush(brush);
43
57
44 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
58 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
45 int x0 = mXpos;
59 int x0 = mXpos;
@@ -57,21 +71,6 QRectF Bar::boundingRect() const
57 return r;
71 return r;
58 }
72 }
59
73
60 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
74 //#include "moc_bar_p.cpp"
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"
76
75
77 QTCOMMERCIALCHART_END_NAMESPACE
76 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,43 +1,35
1 #ifndef BAR_H
1 #ifndef BAR_H
2 #define BAR_H
2 #define BAR_H
3
3
4 //#include "chartitem_p.h"
4 #include "chartitem_p.h"
5 #include "qchartglobal.h"
5 #include "qchartglobal.h"
6 #include <QGraphicsObject>
6 #include <QGraphicsItem>
7 #include <QPen>
7 #include <QPen>
8 #include <QBrush>
8 #include <QBrush>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 // Single bar item of chart
12 // Single bar item of chart
13 class Bar : public QGraphicsObject
13 class Bar : public ChartItem
14 {
14 {
15 Q_OBJECT
16
17 public:
15 public:
18 Bar(QGraphicsItem *parent=0);
16 Bar(QGraphicsItem *parent=0);
19
17
20 public:
18 public: // from ChartItem
19 void setSize(const QSizeF &size);
21
20
22 // Layout Stuff
21 // Layout Stuff
23 void resize(qreal w, qreal h); // Size of bar.
22 void resize(qreal w, qreal h); // Size of bar.
24 void setPos(qreal x, qreal y);
23 void setPos(qreal x, qreal y);
25 void setPen(QPen pen);
24 void setPen(QPen pen);
26 void setBrush(QBrush brush);
25 void setBrush(QBrush brush);
26 void setColor( QColor col); // deprecated
27
27
28 public:
28 public:
29
30 // From QGraphicsItem
29 // From QGraphicsItem
30
31 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
31 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
32 QRectF boundingRect() const;
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 private:
34 private:
43
35
@@ -45,6 +37,7 private:
45 qreal mWidth;
37 qreal mWidth;
46 qreal mXpos;
38 qreal mXpos;
47 qreal mYpos;
39 qreal mYpos;
40 QColor mColor;
48
41
49 QBrush mBrush;
42 QBrush mBrush;
50 QPen mPen;
43 QPen mPen;
@@ -63,7 +63,7 void BarPresenterBase::dataChanged()
63 for (int c=0; c<mModel.countCategories(); c++) {
63 for (int c=0; c<mModel.countCategories(); c++) {
64 Bar *bar = new Bar(this);
64 Bar *bar = new Bar(this);
65 childItems().append(bar);
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