@@ -1,66 +1,66 | |||||
1 | #include "bar.h" |
|
1 | #include "bar_p.h" | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 | #include <QPainter> |
|
3 | #include <QPainter> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | Bar::Bar(QGraphicsItem *parent) |
|
7 | Bar::Bar(QGraphicsItem *parent) | |
8 | : ChartItem(parent) |
|
8 | : ChartItem(parent) | |
9 | { |
|
9 | { | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | void Bar::setSize(const QSizeF& size) |
|
12 | void Bar::setSize(const QSizeF& size) | |
13 | { |
|
13 | { | |
14 | mWidth = size.width(); |
|
14 | mWidth = size.width(); | |
15 | mHeight = size.height(); |
|
15 | mHeight = size.height(); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | void Bar::setPlotDomain(const PlotDomain& data) |
|
18 | void Bar::setPlotDomain(const PlotDomain& data) | |
19 | { |
|
19 | { | |
20 | mPlotDomain = data; |
|
20 | mPlotDomain = data; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | void Bar::resize( qreal w, qreal h ) |
|
23 | void Bar::resize( qreal w, qreal h ) | |
24 | { |
|
24 | { | |
25 | // qDebug() << "bar::resize" << w << h; |
|
25 | // qDebug() << "bar::resize" << w << h; | |
26 | mWidth = w; |
|
26 | mWidth = w; | |
27 | mHeight = h; |
|
27 | mHeight = h; | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | void Bar::setColor( QColor col ) |
|
30 | void Bar::setColor( QColor col ) | |
31 | { |
|
31 | { | |
32 | mColor = col; |
|
32 | mColor = col; | |
33 | } |
|
33 | } | |
34 | void Bar::setPos(qreal x, qreal y) |
|
34 | void Bar::setPos(qreal x, qreal y) | |
35 | { |
|
35 | { | |
36 | // qDebug() << "Bar::setpos" << x << y; |
|
36 | // qDebug() << "Bar::setpos" << x << y; | |
37 | mXpos = x; |
|
37 | mXpos = x; | |
38 | mYpos = y; |
|
38 | mYpos = y; | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
41 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
42 | { |
|
42 | { | |
43 | if (0 == mHeight) { |
|
43 | if (0 == mHeight) { | |
44 | return; |
|
44 | return; | |
45 | } |
|
45 | } | |
46 | // TODO: accept brush instead of color |
|
46 | // TODO: accept brush instead of color | |
47 | QBrush brush(mColor); |
|
47 | QBrush brush(mColor); | |
48 | painter->setBrush(brush); |
|
48 | painter->setBrush(brush); | |
49 |
|
49 | |||
50 | // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. |
|
50 | // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. | |
51 | int x0 = mXpos; |
|
51 | int x0 = mXpos; | |
52 | int x1 = (mXpos + mWidth); |
|
52 | int x1 = (mXpos + mWidth); | |
53 | int w = x1-x0; |
|
53 | int w = x1-x0; | |
54 | int y0 = mYpos; |
|
54 | int y0 = mYpos; | |
55 | int y1 = (mYpos + mHeight); |
|
55 | int y1 = (mYpos + mHeight); | |
56 | int h = y1-y0; |
|
56 | int h = y1-y0; | |
57 | painter->drawRect(x0, y0 ,w ,h); |
|
57 | painter->drawRect(x0, y0 ,w ,h); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QRectF Bar::boundingRect() const |
|
60 | QRectF Bar::boundingRect() const | |
61 | { |
|
61 | { | |
62 | QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); |
|
62 | QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); | |
63 | return r; |
|
63 | return r; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | QTCOMMERCIALCHART_END_NAMESPACE |
1 | NO CONTENT: file renamed from src/barchart/bar.h to src/barchart/bar_p.h |
|
NO CONTENT: file renamed from src/barchart/bar.h to src/barchart/bar_p.h |
@@ -1,157 +1,157 | |||||
1 | #include "bargroup.h" |
|
1 | #include "bargroup.h" | |
2 | #include "bar.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : |
|
8 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : | |
9 | ChartItem(parent) |
|
9 | ChartItem(parent) | |
10 | ,mSeries(series) |
|
10 | ,mSeries(series) | |
11 | ,mLayoutSet(false) |
|
11 | ,mLayoutSet(false) | |
12 | ,mLayoutDirty(true) |
|
12 | ,mLayoutDirty(true) | |
13 | ,mBarDefaultWidth(10) |
|
13 | ,mBarDefaultWidth(10) | |
14 | { |
|
14 | { | |
15 | dataChanged(); |
|
15 | dataChanged(); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | void BarGroup::setSize(const QSizeF& size) |
|
18 | void BarGroup::setSize(const QSizeF& size) | |
19 | { |
|
19 | { | |
20 | qDebug() << "BarGroup::setSize"; |
|
20 | qDebug() << "BarGroup::setSize"; | |
21 | mWidth = size.width(); |
|
21 | mWidth = size.width(); | |
22 | mHeight = size.height(); |
|
22 | mHeight = size.height(); | |
23 | layoutChanged(); |
|
23 | layoutChanged(); | |
24 | mLayoutSet = true; |
|
24 | mLayoutSet = true; | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | void BarGroup::setPlotDomain(const PlotDomain& data) |
|
27 | void BarGroup::setPlotDomain(const PlotDomain& data) | |
28 | { |
|
28 | { | |
29 | qDebug() << "BarGroup::setPlotDomain"; |
|
29 | qDebug() << "BarGroup::setPlotDomain"; | |
30 | // TODO: |
|
30 | // TODO: | |
31 | mPlotDomain = data; |
|
31 | mPlotDomain = data; | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void BarGroup::setBarWidth( int w ) |
|
34 | void BarGroup::setBarWidth( int w ) | |
35 | { |
|
35 | { | |
36 | mBarDefaultWidth = w; |
|
36 | mBarDefaultWidth = w; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | int BarGroup::addColor( QColor color ) |
|
39 | int BarGroup::addColor( QColor color ) | |
40 | { |
|
40 | { | |
41 | int colorIndex = mColors.count(); |
|
41 | int colorIndex = mColors.count(); | |
42 | mColors.append(color); |
|
42 | mColors.append(color); | |
43 | return colorIndex; |
|
43 | return colorIndex; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void BarGroup::resetColors() |
|
46 | void BarGroup::resetColors() | |
47 | { |
|
47 | { | |
48 | mColors.clear(); |
|
48 | mColors.clear(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
51 | void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
52 | { |
|
52 | { | |
53 | if (!mLayoutSet) { |
|
53 | if (!mLayoutSet) { | |
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
55 | return; |
|
55 | return; | |
56 | } |
|
56 | } | |
57 | if (mLayoutDirty) { |
|
57 | if (mLayoutDirty) { | |
58 | // Layout or data has changed. Need to redraw. |
|
58 | // Layout or data has changed. Need to redraw. | |
59 | foreach(QGraphicsItem* i, childItems()) { |
|
59 | foreach(QGraphicsItem* i, childItems()) { | |
60 | i->paint(painter,option,widget); |
|
60 | i->paint(painter,option,widget); | |
61 | mLayoutDirty = false; |
|
61 | mLayoutDirty = false; | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QRectF BarGroup::boundingRect() const |
|
66 | QRectF BarGroup::boundingRect() const | |
67 | { |
|
67 | { | |
68 | return QRectF(0,0,mWidth,mHeight); |
|
68 | return QRectF(0,0,mWidth,mHeight); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | void BarGroup::dataChanged() |
|
72 | void BarGroup::dataChanged() | |
73 | { |
|
73 | { | |
74 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
74 | qDebug() << "QBarChart::dataChanged mSeries"; | |
75 |
|
75 | |||
76 | // Find out maximum and minimum of all series |
|
76 | // Find out maximum and minimum of all series | |
77 | mMax = mSeries.max(); |
|
77 | mMax = mSeries.max(); | |
78 | mMin = mSeries.min(); |
|
78 | mMin = mSeries.min(); | |
79 |
|
79 | |||
80 | // Delete old bars |
|
80 | // Delete old bars | |
81 | // Is this correct way to delete childItems? |
|
81 | // Is this correct way to delete childItems? | |
82 | foreach (QGraphicsItem* item, childItems()) { |
|
82 | foreach (QGraphicsItem* item, childItems()) { | |
83 | delete item; |
|
83 | delete item; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | // Create new graphic items for bars |
|
86 | // Create new graphic items for bars | |
87 | int totalItems = mSeries.countTotalItems(); |
|
87 | int totalItems = mSeries.countTotalItems(); | |
88 | for (int i=0; i<totalItems; i++) { |
|
88 | for (int i=0; i<totalItems; i++) { | |
89 | Bar *bar = new Bar(this); |
|
89 | Bar *bar = new Bar(this); | |
90 | childItems().append(bar); |
|
90 | childItems().append(bar); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | // TODO: labels from series. This creates just some example labels |
|
93 | // TODO: labels from series. This creates just some example labels | |
94 | int count = mSeries.countColumns(); |
|
94 | int count = mSeries.countColumns(); | |
95 | for (int i=0; i<count; i++) { |
|
95 | for (int i=0; i<count; i++) { | |
96 | BarLabel* label = new BarLabel(this); |
|
96 | BarLabel* label = new BarLabel(this); | |
97 | QString text("Label " + QString::number(i)); |
|
97 | QString text("Label " + QString::number(i)); | |
98 | label->set(text); |
|
98 | label->set(text); | |
99 | childItems().append(label); |
|
99 | childItems().append(label); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | // TODO: if (autolayout) { layoutChanged() } or something |
|
102 | // TODO: if (autolayout) { layoutChanged() } or something | |
103 | mLayoutDirty = true; |
|
103 | mLayoutDirty = true; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void BarGroup::layoutChanged() |
|
106 | void BarGroup::layoutChanged() | |
107 | { |
|
107 | { | |
108 | // Scale bars to new layout |
|
108 | // Scale bars to new layout | |
109 | // Layout for bars: |
|
109 | // Layout for bars: | |
110 | if (mSeries.countRows() <= 0) { |
|
110 | if (mSeries.countRows() <= 0) { | |
111 | // Nothing to do. |
|
111 | // Nothing to do. | |
112 | return; |
|
112 | return; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | // TODO: better way to auto-layout? |
|
115 | // TODO: better way to auto-layout? | |
116 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
116 | // Use reals for accurancy (we might get some compiler warnings... :) | |
117 | int columnCount = mSeries.countColumns(); |
|
117 | int columnCount = mSeries.countColumns(); | |
118 | int rowCount = mSeries.countRows(); |
|
118 | int rowCount = mSeries.countRows(); | |
119 |
|
119 | |||
120 | qreal tW = mWidth; |
|
120 | qreal tW = mWidth; | |
121 | qreal tH = mHeight; |
|
121 | qreal tH = mHeight; | |
122 | qreal tM = mMax; |
|
122 | qreal tM = mMax; | |
123 | qreal scale = (tH/tM); |
|
123 | qreal scale = (tH/tM); | |
124 |
|
124 | |||
125 | qreal tC = columnCount+1; |
|
125 | qreal tC = columnCount+1; | |
126 | qreal xStepPerSeries = (tW/tC); |
|
126 | qreal xStepPerSeries = (tW/tC); | |
127 |
|
127 | |||
128 | // Scaling. |
|
128 | // Scaling. | |
129 | int itemIndex(0); |
|
129 | int itemIndex(0); | |
130 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
130 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); | |
131 |
|
131 | |||
132 | for (int column=0; column < columnCount; column++) { |
|
132 | for (int column=0; column < columnCount; column++) { | |
133 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); |
|
133 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); | |
134 | qreal yPos = mHeight; |
|
134 | qreal yPos = mHeight; | |
135 | for (int row = 0; row < rowCount; row++) { |
|
135 | for (int row = 0; row < rowCount; row++) { | |
136 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
136 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
137 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
137 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
138 |
|
138 | |||
139 | // TODO: width settable per bar? |
|
139 | // TODO: width settable per bar? | |
140 | bar->resize(mBarDefaultWidth, barHeight); |
|
140 | bar->resize(mBarDefaultWidth, barHeight); | |
141 | bar->setColor(mColors.at(row)); |
|
141 | bar->setColor(mColors.at(row)); | |
142 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); |
|
142 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
143 | itemIndex++; |
|
143 | itemIndex++; | |
144 | xPos += mBarDefaultWidth; |
|
144 | xPos += mBarDefaultWidth; | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | // TODO: Layout for labels, remove magic number |
|
147 | // TODO: Layout for labels, remove magic number | |
148 | xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); |
|
148 | xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); | |
149 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
149 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
150 | label->setPos(xPos, mHeight + 20); |
|
150 | label->setPos(xPos, mHeight + 20); | |
151 | labelIndex++; |
|
151 | labelIndex++; | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | mLayoutDirty = true; |
|
154 | mLayoutDirty = true; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | QTCOMMERCIALCHART_END_NAMESPACE |
|
157 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,57 | |||||
1 | #ifndef QBARGROUP_H |
|
1 | #ifndef QBARGROUP_H | |
2 | #define QBARGROUP_H |
|
2 | #define QBARGROUP_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include "bar.h" |
|
5 | #include "bar_p.h" | |
6 | #include "barchartseries.h" |
|
6 | #include "barchartseries.h" | |
7 | #include <QGraphicsItem> |
|
7 | #include <QGraphicsItem> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class BarGroup : public ChartItem |
|
11 | class BarGroup : public ChartItem | |
12 | { |
|
12 | { | |
13 | public: |
|
13 | public: | |
14 | explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0); |
|
14 | explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0); | |
15 |
|
15 | |||
16 | public: // from ChartItem |
|
16 | public: // from ChartItem | |
17 | void setSize(const QSizeF &size); |
|
17 | void setSize(const QSizeF &size); | |
18 | void setPlotDomain(const PlotDomain& data); |
|
18 | void setPlotDomain(const PlotDomain& data); | |
19 |
|
19 | |||
20 | // Layout "api" |
|
20 | // Layout "api" | |
21 | void setPos(qreal x, qreal y); |
|
21 | void setPos(qreal x, qreal y); | |
22 | void setBarWidth( int w ); // Default width for each bar |
|
22 | void setBarWidth( int w ); // Default width for each bar | |
23 |
|
23 | |||
24 | int addColor( QColor color ); |
|
24 | int addColor( QColor color ); | |
25 | void resetColors(); |
|
25 | void resetColors(); | |
26 |
|
26 | |||
27 | // From QGraphicsItem |
|
27 | // From QGraphicsItem | |
28 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
28 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
29 | QRectF boundingRect() const; |
|
29 | QRectF boundingRect() const; | |
30 |
|
30 | |||
31 | private: |
|
31 | private: | |
32 |
|
32 | |||
33 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
33 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
34 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
34 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
35 |
|
35 | |||
36 | private: |
|
36 | private: | |
37 |
|
37 | |||
38 | // Data |
|
38 | // Data | |
39 | BarChartSeries& mSeries; |
|
39 | BarChartSeries& mSeries; | |
40 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) |
|
40 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) | |
41 | int mMax; |
|
41 | int mMax; | |
42 |
|
42 | |||
43 | int mHeight; // Layout spesific |
|
43 | int mHeight; // Layout spesific | |
44 | int mWidth; |
|
44 | int mWidth; | |
45 | int mBarDefaultWidth; |
|
45 | int mBarDefaultWidth; | |
46 |
|
46 | |||
47 | bool mLayoutSet; // True, if component has been laid out. |
|
47 | bool mLayoutSet; // True, if component has been laid out. | |
48 | bool mLayoutDirty; |
|
48 | bool mLayoutDirty; | |
49 |
|
49 | |||
50 | QList<QColor> mColors; // List of colors for series for now |
|
50 | QList<QColor> mColors; // List of colors for series for now | |
51 |
|
51 | |||
52 | PlotDomain mPlotDomain; |
|
52 | PlotDomain mPlotDomain; | |
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
56 | |||
57 | #endif // QBARGROUP_H |
|
57 | #endif // QBARGROUP_H |
@@ -1,152 +1,152 | |||||
1 | #include "percentbargroup.h" |
|
1 | #include "percentbargroup.h" | |
2 | #include "bar.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : |
|
8 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : | |
9 | ChartItem(parent) |
|
9 | ChartItem(parent) | |
10 | ,mSeries(series) |
|
10 | ,mSeries(series) | |
11 | ,mLayoutSet(false) |
|
11 | ,mLayoutSet(false) | |
12 | ,mLayoutDirty(true) |
|
12 | ,mLayoutDirty(true) | |
13 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
13 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
14 | { |
|
14 | { | |
15 | dataChanged(); |
|
15 | dataChanged(); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | void PercentBarGroup::setSize(const QSizeF& size) |
|
19 | void PercentBarGroup::setSize(const QSizeF& size) | |
20 | { |
|
20 | { | |
21 | // qDebug() << "PercentBarGroup::setSize"; |
|
21 | // qDebug() << "PercentBarGroup::setSize"; | |
22 | mWidth = size.width(); |
|
22 | mWidth = size.width(); | |
23 | mHeight = size.height(); |
|
23 | mHeight = size.height(); | |
24 | layoutChanged(); |
|
24 | layoutChanged(); | |
25 | mLayoutSet = true; |
|
25 | mLayoutSet = true; | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void PercentBarGroup::setPlotDomain(const PlotDomain& data) |
|
28 | void PercentBarGroup::setPlotDomain(const PlotDomain& data) | |
29 | { |
|
29 | { | |
30 | qDebug() << "PercentBarGroup::setPlotDomain"; |
|
30 | qDebug() << "PercentBarGroup::setPlotDomain"; | |
31 | // TODO: |
|
31 | // TODO: | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void PercentBarGroup::setBarWidth( int w ) |
|
34 | void PercentBarGroup::setBarWidth( int w ) | |
35 | { |
|
35 | { | |
36 | mBarDefaultWidth = w; |
|
36 | mBarDefaultWidth = w; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | int PercentBarGroup::addColor( QColor color ) |
|
39 | int PercentBarGroup::addColor( QColor color ) | |
40 | { |
|
40 | { | |
41 | int colorIndex = mColors.count(); |
|
41 | int colorIndex = mColors.count(); | |
42 | mColors.append(color); |
|
42 | mColors.append(color); | |
43 | return colorIndex; |
|
43 | return colorIndex; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void PercentBarGroup::resetColors() |
|
46 | void PercentBarGroup::resetColors() | |
47 | { |
|
47 | { | |
48 | mColors.clear(); |
|
48 | mColors.clear(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
51 | void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
52 | { |
|
52 | { | |
53 | if (!mLayoutSet) { |
|
53 | if (!mLayoutSet) { | |
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
55 | return; |
|
55 | return; | |
56 | } |
|
56 | } | |
57 | if (mLayoutDirty) { |
|
57 | if (mLayoutDirty) { | |
58 | // Layout or data has changed. Need to redraw. |
|
58 | // Layout or data has changed. Need to redraw. | |
59 | foreach(QGraphicsItem* i, childItems()) { |
|
59 | foreach(QGraphicsItem* i, childItems()) { | |
60 | i->paint(painter,option,widget); |
|
60 | i->paint(painter,option,widget); | |
61 | } |
|
61 | } | |
62 | mLayoutDirty = false; |
|
62 | mLayoutDirty = false; | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QRectF PercentBarGroup::boundingRect() const |
|
66 | QRectF PercentBarGroup::boundingRect() const | |
67 | { |
|
67 | { | |
68 | return QRectF(0,0,mWidth,mHeight); |
|
68 | return QRectF(0,0,mWidth,mHeight); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | void PercentBarGroup::dataChanged() |
|
72 | void PercentBarGroup::dataChanged() | |
73 | { |
|
73 | { | |
74 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
74 | qDebug() << "QBarChart::dataChanged mSeries"; | |
75 |
|
75 | |||
76 | // Find out maximum and minimum of all series |
|
76 | // Find out maximum and minimum of all series | |
77 | mMax = mSeries.max(); |
|
77 | mMax = mSeries.max(); | |
78 | mMin = mSeries.min(); |
|
78 | mMin = mSeries.min(); | |
79 |
|
79 | |||
80 | // Delete old bars |
|
80 | // Delete old bars | |
81 | // Is this correct way to delete childItems? |
|
81 | // Is this correct way to delete childItems? | |
82 | foreach (QGraphicsItem* item, childItems()) { |
|
82 | foreach (QGraphicsItem* item, childItems()) { | |
83 | delete item; |
|
83 | delete item; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | // Create new graphic items for bars |
|
86 | // Create new graphic items for bars | |
87 | int totalItems = mSeries.countTotalItems(); |
|
87 | int totalItems = mSeries.countTotalItems(); | |
88 | for (int i=0; i<totalItems; i++) { |
|
88 | for (int i=0; i<totalItems; i++) { | |
89 | Bar *bar = new Bar(this); |
|
89 | Bar *bar = new Bar(this); | |
90 | childItems().append(bar); |
|
90 | childItems().append(bar); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | // TODO: labels from series. This creates just some example labels |
|
93 | // TODO: labels from series. This creates just some example labels | |
94 | int count = mSeries.countColumns(); |
|
94 | int count = mSeries.countColumns(); | |
95 | for (int i=0; i<count; i++) { |
|
95 | for (int i=0; i<count; i++) { | |
96 | BarLabel* label = new BarLabel(this); |
|
96 | BarLabel* label = new BarLabel(this); | |
97 | QString text("Label " + QString::number(i)); |
|
97 | QString text("Label " + QString::number(i)); | |
98 | label->set(text); |
|
98 | label->set(text); | |
99 | childItems().append(label); |
|
99 | childItems().append(label); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | // TODO: if (autolayout) { layoutChanged() } or something |
|
102 | // TODO: if (autolayout) { layoutChanged() } or something | |
103 | mLayoutDirty = true; |
|
103 | mLayoutDirty = true; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void PercentBarGroup::layoutChanged() |
|
106 | void PercentBarGroup::layoutChanged() | |
107 | { |
|
107 | { | |
108 | // Scale bars to new layout |
|
108 | // Scale bars to new layout | |
109 | // Layout for bars: |
|
109 | // Layout for bars: | |
110 | if (mSeries.countRows() <= 0) { |
|
110 | if (mSeries.countRows() <= 0) { | |
111 | // Nothing to do. |
|
111 | // Nothing to do. | |
112 | return; |
|
112 | return; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | // TODO: better way to auto-layout |
|
115 | // TODO: better way to auto-layout | |
116 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
116 | // Use reals for accurancy (we might get some compiler warnings... :) | |
117 | int count = mSeries.countColumns(); |
|
117 | int count = mSeries.countColumns(); | |
118 | int itemIndex(0); |
|
118 | int itemIndex(0); | |
119 | qreal tW = mWidth; |
|
119 | qreal tW = mWidth; | |
120 | qreal tC = count+1; |
|
120 | qreal tC = count+1; | |
121 | qreal xStep = (tW/tC); |
|
121 | qreal xStep = (tW/tC); | |
122 | // qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); |
|
122 | // qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); | |
123 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
123 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
124 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
124 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); | |
125 |
|
125 | |||
126 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
126 | for (int column = 0; column < mSeries.countColumns(); column++) { | |
127 | qreal colSum = mSeries.columnSum(column); |
|
127 | qreal colSum = mSeries.columnSum(column); | |
128 | qreal h = mHeight; |
|
128 | qreal h = mHeight; | |
129 | qreal scale = (h / colSum); |
|
129 | qreal scale = (h / colSum); | |
130 | qreal yPos = h; |
|
130 | qreal yPos = h; | |
131 | for (int row=0; row < mSeries.countRows(); row++) { |
|
131 | for (int row=0; row < mSeries.countRows(); row++) { | |
132 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
132 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
133 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
133 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
134 |
|
134 | |||
135 | // TODO: width settable per bar? |
|
135 | // TODO: width settable per bar? | |
136 | bar->resize(mBarDefaultWidth, barHeight); |
|
136 | bar->resize(mBarDefaultWidth, barHeight); | |
137 | bar->setColor(mColors.at(row)); |
|
137 | bar->setColor(mColors.at(row)); | |
138 | bar->setPos(xPos, yPos-barHeight); |
|
138 | bar->setPos(xPos, yPos-barHeight); | |
139 | itemIndex++; |
|
139 | itemIndex++; | |
140 | yPos -= barHeight; |
|
140 | yPos -= barHeight; | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | // TODO: Layout for labels, remove magic number |
|
143 | // TODO: Layout for labels, remove magic number | |
144 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
144 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
145 | label->setPos(xPos, mHeight + 20); |
|
145 | label->setPos(xPos, mHeight + 20); | |
146 | labelIndex++; |
|
146 | labelIndex++; | |
147 | xPos += xStep; |
|
147 | xPos += xStep; | |
148 | } |
|
148 | } | |
149 | mLayoutDirty = true; |
|
149 | mLayoutDirty = true; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | QTCOMMERCIALCHART_END_NAMESPACE |
|
152 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,57 | |||||
1 | #ifndef PERCENTBARGROUP_H |
|
1 | #ifndef PERCENTBARGROUP_H | |
2 | #define PERCENTBARGROUP_H |
|
2 | #define PERCENTBARGROUP_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include "bar.h" |
|
5 | #include "bar_p.h" | |
6 | #include "percentbarchartseries.h" |
|
6 | #include "percentbarchartseries.h" | |
7 | #include <QGraphicsItem> |
|
7 | #include <QGraphicsItem> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class PercentBarGroup : public ChartItem |
|
11 | class PercentBarGroup : public ChartItem | |
12 | { |
|
12 | { | |
13 | public: |
|
13 | public: | |
14 | PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0); |
|
14 | PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0); | |
15 |
|
15 | |||
16 | public: // From ChartItem |
|
16 | public: // From ChartItem | |
17 | void setSize(const QSizeF &size); |
|
17 | void setSize(const QSizeF &size); | |
18 | void setPlotDomain(const PlotDomain& data); |
|
18 | void setPlotDomain(const PlotDomain& data); | |
19 |
|
19 | |||
20 | public: |
|
20 | public: | |
21 | // Layout "api" |
|
21 | // Layout "api" | |
22 | void setPos(qreal x, qreal y); |
|
22 | void setPos(qreal x, qreal y); | |
23 | void setBarWidth( int w ); // Default width for each bar |
|
23 | void setBarWidth( int w ); // Default width for each bar | |
24 |
|
24 | |||
25 | int addColor( QColor color ); |
|
25 | int addColor( QColor color ); | |
26 | void resetColors(); |
|
26 | void resetColors(); | |
27 |
|
27 | |||
28 | // From QGraphicsItem |
|
28 | // From QGraphicsItem | |
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
30 | QRectF boundingRect() const; |
|
30 | QRectF boundingRect() const; | |
31 |
|
31 | |||
32 | private: |
|
32 | private: | |
33 |
|
33 | |||
34 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
34 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
35 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
35 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
36 |
|
36 | |||
37 | private: |
|
37 | private: | |
38 |
|
38 | |||
39 | // Data |
|
39 | // Data | |
40 | PercentBarChartSeries& mSeries; |
|
40 | PercentBarChartSeries& mSeries; | |
41 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) |
|
41 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) | |
42 | int mMax; |
|
42 | int mMax; | |
43 |
|
43 | |||
44 | int mHeight; // Layout spesific |
|
44 | int mHeight; // Layout spesific | |
45 | int mWidth; |
|
45 | int mWidth; | |
46 | int mBarDefaultWidth; |
|
46 | int mBarDefaultWidth; | |
47 |
|
47 | |||
48 | bool mLayoutSet; // True, if component has been laid out. |
|
48 | bool mLayoutSet; // True, if component has been laid out. | |
49 | bool mLayoutDirty; |
|
49 | bool mLayoutDirty; | |
50 |
|
50 | |||
51 | QList<QColor> mColors; // List of colors for series for now |
|
51 | QList<QColor> mColors; // List of colors for series for now | |
52 |
|
52 | |||
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
56 | |||
57 | #endif // PERCENTBARGROUP_H |
|
57 | #endif // PERCENTBARGROUP_H |
@@ -1,163 +1,163 | |||||
1 | #include "stackedbargroup.h" |
|
1 | #include "stackedbargroup.h" | |
2 | #include "bar.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : |
|
8 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : | |
9 | ChartItem(parent) |
|
9 | ChartItem(parent) | |
10 | ,mSeries(series) |
|
10 | ,mSeries(series) | |
11 | ,mLayoutSet(false) |
|
11 | ,mLayoutSet(false) | |
12 | ,mLayoutDirty(true) |
|
12 | ,mLayoutDirty(true) | |
13 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
13 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
14 | ,mTheme(0) |
|
14 | ,mTheme(0) | |
15 | { |
|
15 | { | |
16 | dataChanged(); |
|
16 | dataChanged(); | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | void StackedBarGroup::setSize(const QSizeF& size) |
|
20 | void StackedBarGroup::setSize(const QSizeF& size) | |
21 | { |
|
21 | { | |
22 | // qDebug() << "StackedBarGroup::setSize"; |
|
22 | // qDebug() << "StackedBarGroup::setSize"; | |
23 | mWidth = size.width(); |
|
23 | mWidth = size.width(); | |
24 | mHeight = size.height(); |
|
24 | mHeight = size.height(); | |
25 | layoutChanged(); |
|
25 | layoutChanged(); | |
26 | mLayoutSet = true; |
|
26 | mLayoutSet = true; | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | void StackedBarGroup::setPlotDomain(const PlotDomain& data) |
|
29 | void StackedBarGroup::setPlotDomain(const PlotDomain& data) | |
30 | { |
|
30 | { | |
31 | qDebug() << "StackedBarGroup::setPlotDomain"; |
|
31 | qDebug() << "StackedBarGroup::setPlotDomain"; | |
32 | // TODO: |
|
32 | // TODO: | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | void StackedBarGroup::themeChanged(ChartTheme *theme) |
|
35 | void StackedBarGroup::themeChanged(ChartTheme *theme) | |
36 | { |
|
36 | { | |
37 | mTheme = theme; |
|
37 | mTheme = theme; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void StackedBarGroup::setBarWidth( int w ) |
|
40 | void StackedBarGroup::setBarWidth( int w ) | |
41 | { |
|
41 | { | |
42 | mBarDefaultWidth = w; |
|
42 | mBarDefaultWidth = w; | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | int StackedBarGroup::addColor( QColor color ) |
|
45 | int StackedBarGroup::addColor( QColor color ) | |
46 | { |
|
46 | { | |
47 | int colorIndex = mColors.count(); |
|
47 | int colorIndex = mColors.count(); | |
48 | mColors.append(color); |
|
48 | mColors.append(color); | |
49 | return colorIndex; |
|
49 | return colorIndex; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void StackedBarGroup::resetColors() |
|
52 | void StackedBarGroup::resetColors() | |
53 | { |
|
53 | { | |
54 | mColors.clear(); |
|
54 | mColors.clear(); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
57 | void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
58 | { |
|
58 | { | |
59 | if (!mLayoutSet) { |
|
59 | if (!mLayoutSet) { | |
60 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
60 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
61 | return; |
|
61 | return; | |
62 | } |
|
62 | } | |
63 | if (mLayoutDirty) { |
|
63 | if (mLayoutDirty) { | |
64 | // Layout or data has changed. Need to redraw. |
|
64 | // Layout or data has changed. Need to redraw. | |
65 | foreach(QGraphicsItem* i, childItems()) { |
|
65 | foreach(QGraphicsItem* i, childItems()) { | |
66 | i->paint(painter,option,widget); |
|
66 | i->paint(painter,option,widget); | |
67 | } |
|
67 | } | |
68 | mLayoutDirty = false; |
|
68 | mLayoutDirty = false; | |
69 | //TODO: draw labels. |
|
69 | //TODO: draw labels. | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | QRectF StackedBarGroup::boundingRect() const |
|
74 | QRectF StackedBarGroup::boundingRect() const | |
75 | { |
|
75 | { | |
76 | return QRectF(0,0,mWidth,mHeight); |
|
76 | return QRectF(0,0,mWidth,mHeight); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | void StackedBarGroup::dataChanged() |
|
80 | void StackedBarGroup::dataChanged() | |
81 | { |
|
81 | { | |
82 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
82 | qDebug() << "QBarChart::dataChanged mSeries"; | |
83 |
|
83 | |||
84 | // Find out maximum and minimum of all series |
|
84 | // Find out maximum and minimum of all series | |
85 | mMax = mSeries.max(); |
|
85 | mMax = mSeries.max(); | |
86 | mMin = mSeries.min(); |
|
86 | mMin = mSeries.min(); | |
87 |
|
87 | |||
88 | // Delete old bars |
|
88 | // Delete old bars | |
89 | // Is this correct way to delete childItems? |
|
89 | // Is this correct way to delete childItems? | |
90 | foreach (QGraphicsItem* item, childItems()) { |
|
90 | foreach (QGraphicsItem* item, childItems()) { | |
91 | delete item; |
|
91 | delete item; | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | // Create new graphic items for bars |
|
94 | // Create new graphic items for bars | |
95 | int totalItems = mSeries.countTotalItems(); |
|
95 | int totalItems = mSeries.countTotalItems(); | |
96 | for (int i=0; i<totalItems; i++) { |
|
96 | for (int i=0; i<totalItems; i++) { | |
97 | Bar *bar = new Bar(this); |
|
97 | Bar *bar = new Bar(this); | |
98 | childItems().append(bar); |
|
98 | childItems().append(bar); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | // TODO: labels from series. This creates just some example labels |
|
101 | // TODO: labels from series. This creates just some example labels | |
102 | int count = mSeries.countColumns(); |
|
102 | int count = mSeries.countColumns(); | |
103 | for (int i=0; i<count; i++) { |
|
103 | for (int i=0; i<count; i++) { | |
104 | BarLabel* label = new BarLabel(this); |
|
104 | BarLabel* label = new BarLabel(this); | |
105 | QString text("Label " + QString::number(i)); |
|
105 | QString text("Label " + QString::number(i)); | |
106 | label->set(text); |
|
106 | label->set(text); | |
107 | childItems().append(label); |
|
107 | childItems().append(label); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | // TODO: if (autolayout) { layoutChanged() } or something |
|
110 | // TODO: if (autolayout) { layoutChanged() } or something | |
111 | mLayoutDirty = true; |
|
111 | mLayoutDirty = true; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void StackedBarGroup::layoutChanged() |
|
114 | void StackedBarGroup::layoutChanged() | |
115 | { |
|
115 | { | |
116 | // Scale bars to new layout |
|
116 | // Scale bars to new layout | |
117 | // Layout for bars: |
|
117 | // Layout for bars: | |
118 | if (mSeries.countRows() <= 0) { |
|
118 | if (mSeries.countRows() <= 0) { | |
119 | // Nothing to do. |
|
119 | // Nothing to do. | |
120 | return; |
|
120 | return; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | // TODO: better way to auto-layout |
|
123 | // TODO: better way to auto-layout | |
124 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
124 | // Use reals for accurancy (we might get some compiler warnings... :) | |
125 | qreal maxSum = mSeries.maxColumnSum(); |
|
125 | qreal maxSum = mSeries.maxColumnSum(); | |
126 | qreal h = mHeight; |
|
126 | qreal h = mHeight; | |
127 | qreal scale = (h / maxSum); |
|
127 | qreal scale = (h / maxSum); | |
128 |
|
128 | |||
129 | int count = mSeries.countColumns(); |
|
129 | int count = mSeries.countColumns(); | |
130 | int itemIndex(0); |
|
130 | int itemIndex(0); | |
131 | qreal tW = mWidth; |
|
131 | qreal tW = mWidth; | |
132 | qreal tC = count+1; |
|
132 | qreal tC = count+1; | |
133 | qreal xStep = (tW/tC); |
|
133 | qreal xStep = (tW/tC); | |
134 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
134 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
135 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
135 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); | |
136 |
|
136 | |||
137 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
137 | for (int column = 0; column < mSeries.countColumns(); column++) { | |
138 | qreal yPos = h; |
|
138 | qreal yPos = h; | |
139 | for (int row=0; row < mSeries.countRows(); row++) { |
|
139 | for (int row=0; row < mSeries.countRows(); row++) { | |
140 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
140 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
141 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
141 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
142 |
|
142 | |||
143 | // TODO: width settable per bar? |
|
143 | // TODO: width settable per bar? | |
144 | // TODO: how to get color for series(x) from theme? |
|
144 | // TODO: how to get color for series(x) from theme? | |
145 | // mTheme->themeForSeries(); |
|
145 | // mTheme->themeForSeries(); | |
146 | bar->resize(mBarDefaultWidth, barHeight); |
|
146 | bar->resize(mBarDefaultWidth, barHeight); | |
147 | bar->setColor(mColors.at(row)); |
|
147 | bar->setColor(mColors.at(row)); | |
148 | bar->setPos(xPos, yPos-barHeight); |
|
148 | bar->setPos(xPos, yPos-barHeight); | |
149 | itemIndex++; |
|
149 | itemIndex++; | |
150 | yPos -= barHeight; |
|
150 | yPos -= barHeight; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | // TODO: Layout for labels, remove magic number |
|
153 | // TODO: Layout for labels, remove magic number | |
154 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
154 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
155 | label->setPos(xPos, mHeight + 20); |
|
155 | label->setPos(xPos, mHeight + 20); | |
156 | labelIndex++; |
|
156 | labelIndex++; | |
157 | xPos += xStep; |
|
157 | xPos += xStep; | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | mLayoutDirty = true; |
|
160 | mLayoutDirty = true; | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | QTCOMMERCIALCHART_END_NAMESPACE |
|
163 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,65 +1,65 | |||||
1 | #ifndef STACKEDBARGROUP_H |
|
1 | #ifndef STACKEDBARGROUP_H | |
2 | #define STACKEDBARGROUP_H |
|
2 | #define STACKEDBARGROUP_H | |
3 |
|
3 | |||
4 | #include "charttheme_p.h" |
|
4 | #include "charttheme_p.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
6 | #include "barlabel_p.h" |
|
6 | #include "barlabel_p.h" | |
7 | #include "bar.h" |
|
7 | #include "bar_p.h" | |
8 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
9 | #include <QGraphicsItem> |
|
9 | #include <QGraphicsItem> | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | // TODO: derive this from ChartObjectInterface, when setSize is back in ChartItem |
|
13 | // TODO: derive this from ChartObjectInterface, when setSize is back in ChartItem | |
14 | class StackedBarGroup : public ChartItem, public ChartThemeObserver |
|
14 | class StackedBarGroup : public ChartItem, public ChartThemeObserver | |
15 | { |
|
15 | { | |
16 | public: |
|
16 | public: | |
17 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); |
|
17 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); | |
18 |
|
18 | |||
19 | public: // From ChartItem |
|
19 | public: // From ChartItem | |
20 | void setSize(const QSizeF &size); |
|
20 | void setSize(const QSizeF &size); | |
21 | void setPlotDomain(const PlotDomain& data); |
|
21 | void setPlotDomain(const PlotDomain& data); | |
22 |
|
22 | |||
23 | // From ChartThemeObserver |
|
23 | // From ChartThemeObserver | |
24 | void themeChanged(ChartTheme *theme); |
|
24 | void themeChanged(ChartTheme *theme); | |
25 |
|
25 | |||
26 | public: // Layout "api" |
|
26 | public: // Layout "api" | |
27 | void setPos(qreal x, qreal y); |
|
27 | void setPos(qreal x, qreal y); | |
28 | void setBarWidth( int w ); // Default width for each bar |
|
28 | void setBarWidth( int w ); // Default width for each bar | |
29 |
|
29 | |||
30 | int addColor( QColor color ); |
|
30 | int addColor( QColor color ); | |
31 | void resetColors(); |
|
31 | void resetColors(); | |
32 |
|
32 | |||
33 | // From QGraphicsItem |
|
33 | // From QGraphicsItem | |
34 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
34 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
35 | QRectF boundingRect() const; |
|
35 | QRectF boundingRect() const; | |
36 |
|
36 | |||
37 | private: |
|
37 | private: | |
38 |
|
38 | |||
39 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
39 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
40 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
40 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
41 |
|
41 | |||
42 | private: |
|
42 | private: | |
43 |
|
43 | |||
44 | // Data |
|
44 | // Data | |
45 | StackedBarChartSeries& mSeries; |
|
45 | StackedBarChartSeries& mSeries; | |
46 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) |
|
46 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) | |
47 | int mMax; |
|
47 | int mMax; | |
48 |
|
48 | |||
49 | int mHeight; // Layout spesific |
|
49 | int mHeight; // Layout spesific | |
50 | int mWidth; |
|
50 | int mWidth; | |
51 | int mBarDefaultWidth; |
|
51 | int mBarDefaultWidth; | |
52 |
|
52 | |||
53 | bool mLayoutSet; // True, if component has been laid out. |
|
53 | bool mLayoutSet; // True, if component has been laid out. | |
54 | bool mLayoutDirty; |
|
54 | bool mLayoutDirty; | |
55 |
|
55 | |||
56 | QList<QColor> mColors; // List of colors for series for now |
|
56 | QList<QColor> mColors; // List of colors for series for now | |
57 |
|
57 | |||
58 | ChartTheme* mTheme; |
|
58 | ChartTheme* mTheme; | |
59 | // QList<BarLabel*> mLabels; |
|
59 | // QList<BarLabel*> mLabels; | |
60 |
|
60 | |||
61 | }; |
|
61 | }; | |
62 |
|
62 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
64 | |||
65 | #endif // STACKEDBARGROUP_H |
|
65 | #endif // STACKEDBARGROUP_H |
@@ -1,115 +1,116 | |||||
1 | !include( ../common.pri ) { |
|
1 | !include( ../common.pri ) { | |
2 | error( Couldn't find the common.pri file! ) |
|
2 | error( Couldn't find the common.pri file! ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TARGET = QtCommercialChart |
|
5 | TARGET = QtCommercialChart | |
6 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
6 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
7 | TEMPLATE = lib |
|
7 | TEMPLATE = lib | |
8 | QT += core \ |
|
8 | QT += core \ | |
9 | gui |
|
9 | gui | |
10 |
|
10 | |||
11 | CONFIG += debug_and_release |
|
11 | CONFIG += debug_and_release | |
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
13 |
|
13 | |||
14 | SOURCES += \ |
|
14 | SOURCES += \ | |
15 | barchart/barchartseries.cpp \ |
|
15 | barchart/barchartseries.cpp \ | |
16 | barchart/bargroup.cpp \ |
|
16 | barchart/bargroup.cpp \ | |
17 | barchart/bar.cpp \ |
|
17 | barchart/bar.cpp \ | |
18 | barchart/stackedbarchartseries.cpp \ |
|
18 | barchart/stackedbarchartseries.cpp \ | |
19 | barchart/stackedbargroup.cpp \ |
|
19 | barchart/stackedbargroup.cpp \ | |
20 | barchart/percentbarchartseries.cpp \ |
|
20 | barchart/percentbarchartseries.cpp \ | |
21 | barchart/percentbargroup.cpp \ |
|
21 | barchart/percentbargroup.cpp \ | |
22 | barchart/barlabel.cpp \ |
|
22 | barchart/barlabel.cpp \ | |
23 | xylinechart/qxychartseries.cpp \ |
|
23 | xylinechart/qxychartseries.cpp \ | |
24 | xylinechart/xylinechartitem.cpp \ |
|
24 | xylinechart/xylinechartitem.cpp \ | |
25 | plotdomain.cpp \ |
|
25 | plotdomain.cpp \ | |
26 | qscatterseries.cpp \ |
|
26 | qscatterseries.cpp \ | |
27 | qpieseries.cpp \ |
|
27 | qpieseries.cpp \ | |
28 | qchart.cpp \ |
|
28 | qchart.cpp \ | |
29 | axisitem.cpp \ |
|
29 | axisitem.cpp \ | |
30 | qchartwidget.cpp \ |
|
30 | qchartwidget.cpp \ | |
31 | pieslice.cpp \ |
|
31 | pieslice.cpp \ | |
32 | qchartview.cpp \ |
|
32 | qchartview.cpp \ | |
33 | qchartseries.cpp \ |
|
33 | qchartseries.cpp \ | |
34 | qchartaxis.cpp \ |
|
34 | qchartaxis.cpp \ | |
35 | charttheme.cpp |
|
35 | charttheme.cpp | |
36 |
|
36 | |||
37 | PRIVATE_HEADERS += \ |
|
37 | PRIVATE_HEADERS += \ | |
38 | xylinechart/xylinechartitem_p.h \ |
|
38 | xylinechart/xylinechartitem_p.h \ | |
39 | barchart/barlabel_p.h \ |
|
39 | barchart/barlabel_p.h \ | |
|
40 | barchart/bar_p.h \ | |||
40 | plotdomain_p.h \ |
|
41 | plotdomain_p.h \ | |
41 | qscatterseries_p.h \ |
|
42 | qscatterseries_p.h \ | |
42 | qpieseries_p.h \ |
|
43 | qpieseries_p.h \ | |
43 | pieslice.h \ |
|
44 | pieslice.h \ | |
44 | axisitem_p.h \ |
|
45 | axisitem_p.h \ | |
45 | chartitem_p.h \ |
|
46 | chartitem_p.h \ | |
46 | charttheme_p.h |
|
47 | charttheme_p.h | |
47 |
|
48 | |||
48 | PUBLIC_HEADERS += \ |
|
49 | PUBLIC_HEADERS += \ | |
49 | qchartseries.h \ |
|
50 | qchartseries.h \ | |
50 | qscatterseries.h \ |
|
51 | qscatterseries.h \ | |
51 | qpieseries.h \ |
|
52 | qpieseries.h \ | |
52 | qchart.h \ |
|
53 | qchart.h \ | |
53 | qchartwidget.h \ |
|
54 | qchartwidget.h \ | |
54 | qchartglobal.h \ |
|
55 | qchartglobal.h \ | |
55 | xylinechart/qxychartseries.h \ |
|
56 | xylinechart/qxychartseries.h \ | |
56 | barchart/barchartseries.h \ |
|
57 | barchart/barchartseries.h \ | |
57 | barchart/bargroup.h \ |
|
58 | barchart/bargroup.h \ | |
58 | barchart/stackedbarchartseries.h \ |
|
59 | barchart/stackedbarchartseries.h \ | |
59 | barchart/stackedbargroup.h \ |
|
60 | barchart/stackedbargroup.h \ | |
60 | barchart/percentbarchartseries.h \ |
|
61 | barchart/percentbarchartseries.h \ | |
61 | barchart/percentbargroup.h \ |
|
62 | barchart/percentbargroup.h \ | |
62 | qchartview.h \ |
|
63 | qchartview.h \ | |
63 | qchartaxis.h |
|
64 | qchartaxis.h | |
64 |
|
65 | |||
65 | HEADERS += $$PUBLIC_HEADERS |
|
66 | HEADERS += $$PUBLIC_HEADERS | |
66 | HEADERS += $$PRIVATE_HEADERS |
|
67 | HEADERS += $$PRIVATE_HEADERS | |
67 |
|
68 | |||
68 | INCLUDEPATH += xylinechart \ |
|
69 | INCLUDEPATH += xylinechart \ | |
69 | barchart \ |
|
70 | barchart \ | |
70 | . |
|
71 | . | |
71 |
|
72 | |||
72 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
73 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
73 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
74 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
74 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
75 | UI_DIR = $$CHART_BUILD_DIR/lib | |
75 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
76 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
76 |
|
77 | |||
77 |
|
78 | |||
78 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
79 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
79 |
|
80 | |||
80 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
81 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
81 | public_headers.files = $$PUBLIC_HEADERS |
|
82 | public_headers.files = $$PUBLIC_HEADERS | |
82 | target.path = $$[QT_INSTALL_LIBS] |
|
83 | target.path = $$[QT_INSTALL_LIBS] | |
83 | INSTALLS += target \ |
|
84 | INSTALLS += target \ | |
84 | public_headers |
|
85 | public_headers | |
85 |
|
86 | |||
86 |
|
87 | |||
87 | install_build_headers.name = bild_headers |
|
88 | install_build_headers.name = bild_headers | |
88 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
89 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
89 | install_build_headers.input = PUBLIC_HEADERS |
|
90 | install_build_headers.input = PUBLIC_HEADERS | |
90 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
91 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR | |
91 | install_build_headers.CONFIG += target_predeps no_link |
|
92 | install_build_headers.CONFIG += target_predeps no_link | |
92 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
93 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
93 |
|
94 | |||
94 | chartversion.target = qchartversion_p.h |
|
95 | chartversion.target = qchartversion_p.h | |
95 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
96 | chartversion.commands = @echo "build_time" > $$chartversion.target; | |
96 | chartversion.depends = $$HEADERS $$SOURCES |
|
97 | chartversion.depends = $$HEADERS $$SOURCES | |
97 | PRE_TARGETDEPS += qchartversion_p.h |
|
98 | PRE_TARGETDEPS += qchartversion_p.h | |
98 | QMAKE_CLEAN+= qchartversion_p.h |
|
99 | QMAKE_CLEAN+= qchartversion_p.h | |
99 | QMAKE_EXTRA_TARGETS += chartversion |
|
100 | QMAKE_EXTRA_TARGETS += chartversion | |
100 |
|
101 | |||
101 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
102 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
102 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
103 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
103 |
|
104 | |||
104 |
|
105 | |||
105 |
|
106 | |||
106 |
|
107 | |||
107 |
|
108 | |||
108 |
|
109 | |||
109 |
|
110 | |||
110 |
|
111 | |||
111 |
|
112 | |||
112 |
|
113 | |||
113 |
|
114 | |||
114 |
|
115 | |||
115 |
|
116 |
General Comments 0
You need to be logged in to leave comments.
Login now