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