##// END OF EJS Templates
signals and slots for bars and sets
sauimone -
r239:b700ad3a5165
parent child
Show More
@@ -5,17 +5,10
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 Bar::Bar(QGraphicsItem *parent)
7 Bar::Bar(QGraphicsItem *parent)
8 : ChartItem(parent)
8 : QGraphicsObject(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
19 void Bar::resize( qreal w, qreal h )
12 void Bar::resize( qreal w, qreal h )
20 {
13 {
21 // qDebug() << "bar::resize" << w << h;
14 // qDebug() << "bar::resize" << w << h;
@@ -23,11 +16,6 void Bar::resize( qreal w, qreal h )
23 mHeight = h;
16 mHeight = h;
24 }
17 }
25
18
26 void Bar::setColor( QColor col )
27 {
28 mColor = col;
29 }
30
31 void Bar::setPos(qreal x, qreal y)
19 void Bar::setPos(qreal x, qreal y)
32 {
20 {
33 // qDebug() << "Bar::setpos" << x << y;
21 // qDebug() << "Bar::setpos" << x << y;
@@ -50,10 +38,8 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg
50 if (0 == mHeight) {
38 if (0 == mHeight) {
51 return;
39 return;
52 }
40 }
53 // TODO: accept brush instead of color
41
54 painter->setBrush(mBrush);
42 painter->setBrush(mBrush);
55 // QBrush brush(mColor);
56 // painter->setBrush(brush);
57
43
58 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
44 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
59 int x0 = mXpos;
45 int x0 = mXpos;
@@ -71,4 +57,21 QRectF Bar::boundingRect() const
71 return r;
57 return r;
72 }
58 }
73
59
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"
76
74 QTCOMMERCIALCHART_END_NAMESPACE
77 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,35 +1,43
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 <QGraphicsItem>
6 #include <QGraphicsObject>
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 ChartItem
13 class Bar : public QGraphicsObject
14 {
14 {
15 Q_OBJECT
16
15 public:
17 public:
16 Bar(QGraphicsItem *parent=0);
18 Bar(QGraphicsItem *parent=0);
17
19
18 public: // from ChartItem
20 public:
19 void setSize(const QSizeF &size);
20
21
21 // Layout Stuff
22 // Layout Stuff
22 void resize(qreal w, qreal h); // Size of bar.
23 void resize(qreal w, qreal h); // Size of bar.
23 void setPos(qreal x, qreal y);
24 void setPos(qreal x, qreal y);
24 void setPen(QPen pen);
25 void setPen(QPen pen);
25 void setBrush(QBrush brush);
26 void setBrush(QBrush brush);
26 void setColor( QColor col); // deprecated
27
27
28 public:
28 public:
29 // From QGraphicsItem
30
29
30 // From QGraphicsItem
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();
33
41
34 private:
42 private:
35
43
@@ -37,7 +45,6 private:
37 qreal mWidth;
45 qreal mWidth;
38 qreal mXpos;
46 qreal mXpos;
39 qreal mYpos;
47 qreal mYpos;
40 QColor mColor;
41
48
42 QBrush mBrush;
49 QBrush mBrush;
43 QPen mPen;
50 QPen mPen;
@@ -57,10 +57,13 void BarPresenterBase::dataChanged()
57 }
57 }
58
58
59 // Create new graphic items for bars
59 // Create new graphic items for bars
60 int totalItems = mModel.countTotalItems();
60 for (int s=0; s<mModel.countSets(); s++) {
61 for (int i=0; i<totalItems; i++) {
61 QBarSet *set = mModel.nextSet(0==s);
62 for (int c=0; c<mModel.countCategories(); c++) {
62 Bar *bar = new Bar(this);
63 Bar *bar = new Bar(this);
63 childItems().append(bar);
64 childItems().append(bar);
65 connect(bar,SIGNAL(clicked()),set,SLOT(barClicked()));
66 }
64 }
67 }
65
68
66 int count = mModel.countCategories();
69 int count = mModel.countCategories();
@@ -1,4 +1,5
1 #include "qbarset.h"
1 #include "qbarset.h"
2 #include <QDebug>
2
3
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
5
@@ -56,8 +57,13 const QBrush& QBarSet::brush() const
56 return mBrush;
57 return mBrush;
57 }
58 }
58
59
60 void QBarSet::barClicked()
61 {
62 // Some bar of this set has been clicked
63 // TODO: What happens then?
64 qDebug() << "bar Clicked";
65 }
59
66
60
67
61 //TODO?:
68 #include "moc_qbarset.cpp"
62 //#include "moc_qbarset.cpp"
63 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
@@ -7,9 +7,9
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QTCOMMERCIALCHART_EXPORT QBarSet // TODO? : public QObject
10 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
11 {
11 {
12 //Q_OBJECT;
12 Q_OBJECT;
13 public:
13 public:
14 QBarSet();
14 QBarSet();
15
15
@@ -27,12 +27,22 public:
27 void setBrush(const QBrush& brush);
27 void setBrush(const QBrush& brush);
28 const QBrush& brush() const;
28 const QBrush& brush() const;
29
29
30 // void clicked();
31 /*
32 void hoverEnter();
33 void hoverLeave();
34 */
35
36 public Q_SLOTS:
37 void barClicked();
38
30 private:
39 private:
31
40
32 QString mName;
41 QString mName;
33 QList<qreal> mValues;
42 QList<qreal> mValues;
34 QPen mPen;
43 QPen mPen;
35 QBrush mBrush;
44 QBrush mBrush;
45
36 };
46 };
37
47
38 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now