@@ -1,114 +1,115 | |||||
1 | #include "barpresenterbase.h" |
|
1 | #include "barpresenterbase.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include "separator_p.h" |
|
4 | #include "separator_p.h" | |
|
5 | #include "qbarset.h" | |||
5 | #include <QDebug> |
|
6 | #include <QDebug> | |
6 |
|
7 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
9 | |||
9 | BarPresenterBase::BarPresenterBase(BarChartModel& model, QGraphicsItem *parent) |
|
10 | BarPresenterBase::BarPresenterBase(BarChartModel& model, QGraphicsItem *parent) | |
10 | : ChartItem(parent) |
|
11 | : ChartItem(parent) | |
11 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
12 | ,mLayoutSet(false) |
|
13 | ,mLayoutSet(false) | |
13 | ,mLayoutDirty(true) |
|
14 | ,mLayoutDirty(true) | |
14 | ,mSeparatorsVisible(true) |
|
15 | ,mSeparatorsVisible(true) | |
15 | ,mModel(model) |
|
16 | ,mModel(model) | |
16 | { |
|
17 | { | |
17 | dataChanged(); |
|
18 | dataChanged(); | |
18 | } |
|
19 | } | |
19 |
|
20 | |||
20 | void BarPresenterBase::setSeparatorsVisible(bool visible) |
|
21 | void BarPresenterBase::setSeparatorsVisible(bool visible) | |
21 | { |
|
22 | { | |
22 | mSeparatorsVisible = visible; |
|
23 | mSeparatorsVisible = visible; | |
23 | } |
|
24 | } | |
24 |
|
25 | |||
25 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
26 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
26 | { |
|
27 | { | |
27 | // qDebug() << "BarGroupBase::paint" << childItems().count(); |
|
28 | // qDebug() << "BarGroupBase::paint" << childItems().count(); | |
28 | if (!mLayoutSet) { |
|
29 | if (!mLayoutSet) { | |
29 | qDebug() << "BarGroupBase::paint called without layout set. Aborting."; |
|
30 | qDebug() << "BarGroupBase::paint called without layout set. Aborting."; | |
30 | return; |
|
31 | return; | |
31 | } |
|
32 | } | |
32 | // if (mLayoutDirty) { |
|
33 | // if (mLayoutDirty) { | |
33 | // Layout or data has changed. Need to redraw. |
|
34 | // Layout or data has changed. Need to redraw. | |
34 | foreach(QGraphicsItem* i, childItems()) { |
|
35 | foreach(QGraphicsItem* i, childItems()) { | |
35 | i->paint(painter,option,widget); |
|
36 | i->paint(painter,option,widget); | |
36 | } |
|
37 | } | |
37 | // } |
|
38 | // } | |
38 | } |
|
39 | } | |
39 |
|
40 | |||
40 | QRectF BarPresenterBase::boundingRect() const |
|
41 | QRectF BarPresenterBase::boundingRect() const | |
41 | { |
|
42 | { | |
42 | return QRectF(0,0,mWidth,mHeight); |
|
43 | return QRectF(0,0,mWidth,mHeight); | |
43 | } |
|
44 | } | |
44 |
|
45 | |||
45 | void BarPresenterBase::setBarWidth( int w ) |
|
46 | void BarPresenterBase::setBarWidth( int w ) | |
46 | { |
|
47 | { | |
47 | mBarDefaultWidth = w; |
|
48 | mBarDefaultWidth = w; | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 | void BarPresenterBase::dataChanged() |
|
51 | void BarPresenterBase::dataChanged() | |
51 | { |
|
52 | { | |
52 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
53 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
53 |
|
54 | |||
54 | // Delete old bars |
|
55 | // Delete old bars | |
55 | foreach (QGraphicsItem* item, childItems()) { |
|
56 | foreach (QGraphicsItem* item, childItems()) { | |
56 | delete item; |
|
57 | delete item; | |
57 | } |
|
58 | } | |
58 |
|
59 | |||
59 | // Create new graphic items for bars |
|
60 | // Create new graphic items for bars | |
60 | for (int s=0; s<mModel.countSets(); s++) { |
|
61 | for (int s=0; s<mModel.countSets(); s++) { | |
61 | QBarSet *set = mModel.nextSet(0==s); |
|
62 | QBarSet *set = mModel.nextSet(0==s); | |
62 | for (int c=0; c<mModel.countCategories(); c++) { |
|
63 | for (int c=0; c<mModel.countCategories(); c++) { | |
63 | Bar *bar = new Bar(this); |
|
64 | Bar *bar = new Bar(this); | |
64 | childItems().append(bar); |
|
65 | childItems().append(bar); | |
65 | connect(bar,SIGNAL(clicked()),set,SLOT(barClicked())); |
|
66 | connect(bar,SIGNAL(clicked()),set,SLOT(barClicked())); | |
66 | } |
|
67 | } | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | int count = mModel.countCategories(); |
|
70 | int count = mModel.countCategories(); | |
70 | for (int i=0; i<count; i++) { |
|
71 | for (int i=0; i<count; i++) { | |
71 | BarLabel* label = new BarLabel(this); |
|
72 | BarLabel* label = new BarLabel(this); | |
72 | label->set(mModel.label(i)); |
|
73 | label->set(mModel.label(i)); | |
73 | childItems().append(label); |
|
74 | childItems().append(label); | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | count = mModel.countCategories() - 1; // There is one less separator than columns |
|
77 | count = mModel.countCategories() - 1; // There is one less separator than columns | |
77 | for (int i=0; i<count; i++) { |
|
78 | for (int i=0; i<count; i++) { | |
78 | Separator* sep = new Separator(this); |
|
79 | Separator* sep = new Separator(this); | |
79 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme |
|
80 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme | |
80 | childItems().append(sep); |
|
81 | childItems().append(sep); | |
81 | } |
|
82 | } | |
82 |
|
83 | |||
83 | // TODO: if (autolayout) { layoutChanged() } or something |
|
84 | // TODO: if (autolayout) { layoutChanged() } or something | |
84 | mLayoutDirty = true; |
|
85 | mLayoutDirty = true; | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | //handlers |
|
88 | //handlers | |
88 |
|
89 | |||
89 | void BarPresenterBase::handleModelChanged(int index) |
|
90 | void BarPresenterBase::handleModelChanged(int index) | |
90 | { |
|
91 | { | |
91 | // qDebug() << "BarGroupBase::handleModelChanged" << index; |
|
92 | // qDebug() << "BarGroupBase::handleModelChanged" << index; | |
92 | dataChanged(); |
|
93 | dataChanged(); | |
93 | } |
|
94 | } | |
94 |
|
95 | |||
95 | void BarPresenterBase::handleDomainChanged(const Domain& domain) |
|
96 | void BarPresenterBase::handleDomainChanged(const Domain& domain) | |
96 | { |
|
97 | { | |
97 | // qDebug() << "BarGroupBase::handleDomainChanged"; |
|
98 | // qDebug() << "BarGroupBase::handleDomainChanged"; | |
98 | // TODO: Figure out the use case for this. |
|
99 | // TODO: Figure out the use case for this. | |
99 | // Affects the size of visible item, so layout is changed. |
|
100 | // Affects the size of visible item, so layout is changed. | |
100 | // layoutChanged(); |
|
101 | // layoutChanged(); | |
101 | } |
|
102 | } | |
102 |
|
103 | |||
103 | void BarPresenterBase::handleGeometryChanged(const QRectF& rect) |
|
104 | void BarPresenterBase::handleGeometryChanged(const QRectF& rect) | |
104 | { |
|
105 | { | |
105 | mWidth = rect.width(); |
|
106 | mWidth = rect.width(); | |
106 | mHeight = rect.height(); |
|
107 | mHeight = rect.height(); | |
107 | layoutChanged(); |
|
108 | layoutChanged(); | |
108 | mLayoutSet = true; |
|
109 | mLayoutSet = true; | |
109 | setPos(rect.topLeft()); |
|
110 | setPos(rect.topLeft()); | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 | #include "moc_barpresenterbase.cpp" |
|
113 | #include "moc_barpresenterbase.cpp" | |
113 |
|
114 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
115 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,50 | |||||
1 | #ifndef QBARSET_H |
|
1 | #ifndef QBARSET_H | |
2 | #define QBARSET_H |
|
2 | #define QBARSET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
6 | #include <QBrush> |
|
6 | #include <QBrush> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QTCOMMERCIALCHART_EXPORT QBarSet : 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 | |||
16 | void setName(QString name); |
|
16 | void setName(QString name); | |
17 | QString name(); |
|
17 | QString name(); | |
18 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
18 | QBarSet& operator << (const qreal &value); // appends new value to set | |
19 |
|
19 | |||
20 | int count(); // count of values in set |
|
20 | int count(); // count of values in set | |
21 | qreal valueAt(int index); // for modifying individual values |
|
21 | qreal valueAt(int index); // for modifying individual values | |
22 | void setValue(int index, qreal value); // |
|
22 | void setValue(int index, qreal value); // | |
23 |
|
23 | |||
24 | void setPen(const QPen& pen); |
|
24 | void setPen(const QPen& pen); | |
25 | const QPen& pen() const; |
|
25 | const QPen& pen() const; | |
26 |
|
26 | |||
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(); |
|
30 | // void clicked(); | |
31 | /* |
|
31 | /* | |
32 | void hoverEnter(); |
|
32 | void hoverEnter(); | |
33 | void hoverLeave(); |
|
33 | void hoverLeave(); | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | public Q_SLOTS: |
|
36 | public Q_SLOTS: | |
37 | void barClicked(); |
|
37 | void barClicked(); | |
38 |
|
38 | |||
39 | private: |
|
39 | private: | |
40 |
|
40 | |||
41 | QString mName; |
|
41 | QString mName; | |
42 | QList<qreal> mValues; |
|
42 | QList<qreal> mValues; | |
43 | QPen mPen; |
|
43 | QPen mPen; | |
44 | QBrush mBrush; |
|
44 | QBrush mBrush; | |
45 |
|
45 | |||
46 | }; |
|
46 | }; | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
49 | |||
50 | #endif // QBARSET_H |
|
50 | #endif // QBARSET_H |
General Comments 0
You need to be logged in to leave comments.
Login now