@@ -1,143 +1,144 | |||||
1 | #include "bargroup.h" |
|
1 | #include "bargroup.h" | |
2 | #include "bar.h" |
|
2 | #include "bar.h" | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : |
|
7 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : | |
8 | ChartItem(parent) |
|
8 | ChartItem(parent) | |
9 | ,mSeries(series) |
|
9 | ,mSeries(series) | |
10 | ,mLayoutSet(false) |
|
10 | ,mLayoutSet(false) | |
11 | ,mLayoutDirty(true) |
|
11 | ,mLayoutDirty(true) | |
12 | ,mBarDefaultWidth(10) |
|
12 | ,mBarDefaultWidth(10) | |
13 | { |
|
13 | { | |
14 | dataChanged(); |
|
14 | dataChanged(); | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 | void BarGroup::setSize(const QSize& size) |
|
17 | void BarGroup::setSize(const QSize& size) | |
18 | { |
|
18 | { | |
19 | qDebug() << "BarGroup::setSize"; |
|
19 | qDebug() << "BarGroup::setSize"; | |
20 | mWidth = size.width(); |
|
20 | mWidth = size.width(); | |
21 | mHeight = size.height(); |
|
21 | mHeight = size.height(); | |
22 | layoutChanged(); |
|
22 | layoutChanged(); | |
23 | mLayoutSet = true; |
|
23 | mLayoutSet = true; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void BarGroup::setPlotDomain(const PlotDomain& data) |
|
26 | void BarGroup::setPlotDomain(const PlotDomain& data) | |
27 | { |
|
27 | { | |
28 | qDebug() << "BarGroup::setPlotDomain"; |
|
28 | qDebug() << "BarGroup::setPlotDomain"; | |
29 | // TODO: |
|
29 | // TODO: | |
30 | mPlotDomain = data; |
|
30 | mPlotDomain = data; | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void BarGroup::setTheme(ChartTheme *theme) |
|
33 | void BarGroup::setTheme(ChartTheme *theme) | |
34 | { |
|
34 | { | |
35 | // TODO |
|
35 | qDebug() << "BarGroup::setTheme"; | |
|
36 | // TODO: | |||
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 | void BarGroup::setBarWidth( int w ) |
|
39 | void BarGroup::setBarWidth( int w ) | |
39 | { |
|
40 | { | |
40 | mBarDefaultWidth = w; |
|
41 | mBarDefaultWidth = w; | |
41 | } |
|
42 | } | |
42 |
|
43 | |||
43 | int BarGroup::addColor( QColor color ) |
|
44 | int BarGroup::addColor( QColor color ) | |
44 | { |
|
45 | { | |
45 | int colorIndex = mColors.count(); |
|
46 | int colorIndex = mColors.count(); | |
46 | mColors.append(color); |
|
47 | mColors.append(color); | |
47 | return colorIndex; |
|
48 | return colorIndex; | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 | void BarGroup::resetColors() |
|
51 | void BarGroup::resetColors() | |
51 | { |
|
52 | { | |
52 | mColors.clear(); |
|
53 | mColors.clear(); | |
53 | } |
|
54 | } | |
54 |
|
55 | |||
55 | void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
56 | void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
56 | { |
|
57 | { | |
57 | if (!mLayoutSet) { |
|
58 | if (!mLayoutSet) { | |
58 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
59 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
59 | return; |
|
60 | return; | |
60 | } |
|
61 | } | |
61 | if (mLayoutDirty) { |
|
62 | if (mLayoutDirty) { | |
62 | // Layout or data has changed. Need to redraw. |
|
63 | // Layout or data has changed. Need to redraw. | |
63 | foreach(QGraphicsItem* i, childItems()) { |
|
64 | foreach(QGraphicsItem* i, childItems()) { | |
64 | i->paint(painter,option,widget); |
|
65 | i->paint(painter,option,widget); | |
65 | } |
|
66 | } | |
66 | } |
|
67 | } | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | QRectF BarGroup::boundingRect() const |
|
70 | QRectF BarGroup::boundingRect() const | |
70 | { |
|
71 | { | |
71 | return QRectF(0,0,mWidth,mHeight); |
|
72 | return QRectF(0,0,mWidth,mHeight); | |
72 | } |
|
73 | } | |
73 |
|
74 | |||
74 |
|
75 | |||
75 | void BarGroup::dataChanged() |
|
76 | void BarGroup::dataChanged() | |
76 | { |
|
77 | { | |
77 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
78 | qDebug() << "QBarChart::dataChanged mSeries"; | |
78 |
|
79 | |||
79 | // Find out maximum and minimum of all series |
|
80 | // Find out maximum and minimum of all series | |
80 | mMax = mSeries.max(); |
|
81 | mMax = mSeries.max(); | |
81 | mMin = mSeries.min(); |
|
82 | mMin = mSeries.min(); | |
82 |
|
83 | |||
83 | // Delete old bars |
|
84 | // Delete old bars | |
84 | // Is this correct way to delete childItems? |
|
85 | // Is this correct way to delete childItems? | |
85 | foreach (QGraphicsItem* item, childItems()) { |
|
86 | foreach (QGraphicsItem* item, childItems()) { | |
86 | delete item; |
|
87 | delete item; | |
87 | } |
|
88 | } | |
88 |
|
89 | |||
89 | // Create new graphic items for bars |
|
90 | // Create new graphic items for bars | |
90 | int totalItems = mSeries.countTotalItems(); |
|
91 | int totalItems = mSeries.countTotalItems(); | |
91 | for (int i=0; i<totalItems; i++) { |
|
92 | for (int i=0; i<totalItems; i++) { | |
92 | Bar *bar = new Bar(this); |
|
93 | Bar *bar = new Bar(this); | |
93 | childItems().append(bar); |
|
94 | childItems().append(bar); | |
94 | } |
|
95 | } | |
95 |
|
96 | |||
96 | mLayoutDirty = true; |
|
97 | mLayoutDirty = true; | |
97 | } |
|
98 | } | |
98 |
|
99 | |||
99 | void BarGroup::layoutChanged() |
|
100 | void BarGroup::layoutChanged() | |
100 | { |
|
101 | { | |
101 | // Scale bars to new layout |
|
102 | // Scale bars to new layout | |
102 | // Layout for bars: |
|
103 | // Layout for bars: | |
103 | if (mSeries.countRows() <= 0) { |
|
104 | if (mSeries.countRows() <= 0) { | |
104 | // Nothing to do. |
|
105 | // Nothing to do. | |
105 | return; |
|
106 | return; | |
106 | } |
|
107 | } | |
107 |
|
108 | |||
108 | // TODO: better way to auto-layout? |
|
109 | // TODO: better way to auto-layout? | |
109 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
110 | // Use reals for accurancy (we might get some compiler warnings... :) | |
110 | int columnCount = mSeries.countColumns(); |
|
111 | int columnCount = mSeries.countColumns(); | |
111 | int rowCount = mSeries.countRows(); |
|
112 | int rowCount = mSeries.countRows(); | |
112 |
|
113 | |||
113 | qreal tW = mWidth; |
|
114 | qreal tW = mWidth; | |
114 | qreal tH = mHeight; |
|
115 | qreal tH = mHeight; | |
115 | qreal tM = mMax; |
|
116 | qreal tM = mMax; | |
116 | qreal scale = (tH/tM); |
|
117 | qreal scale = (tH/tM); | |
117 |
|
118 | |||
118 | qreal tC = columnCount+1; |
|
119 | qreal tC = columnCount+1; | |
119 | qreal xStepPerSeries = (tW/tC); |
|
120 | qreal xStepPerSeries = (tW/tC); | |
120 |
|
121 | |||
121 | qDebug() << "XSTEP:" << xStepPerSeries; |
|
122 | qDebug() << "XSTEP:" << xStepPerSeries; | |
122 |
|
123 | |||
123 | // Scaling. |
|
124 | // Scaling. | |
124 | int itemIndex(0); |
|
125 | int itemIndex(0); | |
125 | for (int column=0; column < columnCount; column++) { |
|
126 | for (int column=0; column < columnCount; column++) { | |
126 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); |
|
127 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); | |
127 | for (int row = 0; row < rowCount; row++) { |
|
128 | for (int row = 0; row < rowCount; row++) { | |
128 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
129 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
129 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
130 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
130 |
|
131 | |||
131 | // TODO: width settable per bar? |
|
132 | // TODO: width settable per bar? | |
132 | bar->resize(mBarDefaultWidth, barHeight); |
|
133 | bar->resize(mBarDefaultWidth, barHeight); | |
133 | bar->setColor(mColors.at(row)); |
|
134 | bar->setColor(mColors.at(row)); | |
134 | bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); |
|
135 | bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
135 | itemIndex++; |
|
136 | itemIndex++; | |
136 | xPos += mBarDefaultWidth; |
|
137 | xPos += mBarDefaultWidth; | |
137 | } |
|
138 | } | |
138 | } |
|
139 | } | |
139 |
|
140 | |||
140 | mLayoutDirty = true; |
|
141 | mLayoutDirty = true; | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | QTCOMMERCIALCHART_END_NAMESPACE |
|
144 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,133 +1,139 | |||||
1 | #include "percentbargroup.h" |
|
1 | #include "percentbargroup.h" | |
2 | #include "bar.h" |
|
2 | #include "bar.h" | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : |
|
7 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : | |
8 | ChartItem(parent) |
|
8 | ChartItem(parent) | |
9 | ,mSeries(series) |
|
9 | ,mSeries(series) | |
10 | ,mLayoutSet(false) |
|
10 | ,mLayoutSet(false) | |
11 | ,mLayoutDirty(true) |
|
11 | ,mLayoutDirty(true) | |
12 | ,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 | |
13 | { |
|
13 | { | |
14 | dataChanged(); |
|
14 | dataChanged(); | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | void PercentBarGroup::setSize(const QSize& size) |
|
18 | void PercentBarGroup::setSize(const QSize& size) | |
19 | { |
|
19 | { | |
20 | // qDebug() << "PercentBarGroup::setSize"; |
|
20 | // qDebug() << "PercentBarGroup::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 PercentBarGroup::setPlotDomain(const PlotDomain& data) |
|
27 | void PercentBarGroup::setPlotDomain(const PlotDomain& data) | |
28 | { |
|
28 | { | |
29 | qDebug() << "PercentBarGroup::setPlotDomain"; |
|
29 | qDebug() << "PercentBarGroup::setPlotDomain"; | |
30 | // TODO: |
|
30 | // TODO: | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
|
33 | void PercentBarGroup::setTheme(ChartTheme *theme) | |||
|
34 | { | |||
|
35 | qDebug() << "PercentBarGroup::setTheme"; | |||
|
36 | // TODO: | |||
|
37 | } | |||
|
38 | ||||
33 | void PercentBarGroup::setBarWidth( int w ) |
|
39 | void PercentBarGroup::setBarWidth( int w ) | |
34 | { |
|
40 | { | |
35 | mBarDefaultWidth = w; |
|
41 | mBarDefaultWidth = w; | |
36 | } |
|
42 | } | |
37 |
|
43 | |||
38 | int PercentBarGroup::addColor( QColor color ) |
|
44 | int PercentBarGroup::addColor( QColor color ) | |
39 | { |
|
45 | { | |
40 | int colorIndex = mColors.count(); |
|
46 | int colorIndex = mColors.count(); | |
41 | mColors.append(color); |
|
47 | mColors.append(color); | |
42 | return colorIndex; |
|
48 | return colorIndex; | |
43 | } |
|
49 | } | |
44 |
|
50 | |||
45 | void PercentBarGroup::resetColors() |
|
51 | void PercentBarGroup::resetColors() | |
46 | { |
|
52 | { | |
47 | mColors.clear(); |
|
53 | mColors.clear(); | |
48 | } |
|
54 | } | |
49 |
|
55 | |||
50 | void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
56 | void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
51 | { |
|
57 | { | |
52 | if (!mLayoutSet) { |
|
58 | if (!mLayoutSet) { | |
53 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
59 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
54 | return; |
|
60 | return; | |
55 | } |
|
61 | } | |
56 | if (mLayoutDirty) { |
|
62 | if (mLayoutDirty) { | |
57 | // Layout or data has changed. Need to redraw. |
|
63 | // Layout or data has changed. Need to redraw. | |
58 | foreach(QGraphicsItem* i, childItems()) { |
|
64 | foreach(QGraphicsItem* i, childItems()) { | |
59 | i->paint(painter,option,widget); |
|
65 | i->paint(painter,option,widget); | |
60 | } |
|
66 | } | |
61 | } |
|
67 | } | |
62 | } |
|
68 | } | |
63 |
|
69 | |||
64 | QRectF PercentBarGroup::boundingRect() const |
|
70 | QRectF PercentBarGroup::boundingRect() const | |
65 | { |
|
71 | { | |
66 | return QRectF(0,0,mWidth,mHeight); |
|
72 | return QRectF(0,0,mWidth,mHeight); | |
67 | } |
|
73 | } | |
68 |
|
74 | |||
69 |
|
75 | |||
70 | void PercentBarGroup::dataChanged() |
|
76 | void PercentBarGroup::dataChanged() | |
71 | { |
|
77 | { | |
72 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
78 | qDebug() << "QBarChart::dataChanged mSeries"; | |
73 |
|
79 | |||
74 | // Find out maximum and minimum of all series |
|
80 | // Find out maximum and minimum of all series | |
75 | mMax = mSeries.max(); |
|
81 | mMax = mSeries.max(); | |
76 | mMin = mSeries.min(); |
|
82 | mMin = mSeries.min(); | |
77 |
|
83 | |||
78 | // Delete old bars |
|
84 | // Delete old bars | |
79 | // Is this correct way to delete childItems? |
|
85 | // Is this correct way to delete childItems? | |
80 | foreach (QGraphicsItem* item, childItems()) { |
|
86 | foreach (QGraphicsItem* item, childItems()) { | |
81 | delete item; |
|
87 | delete item; | |
82 | } |
|
88 | } | |
83 |
|
89 | |||
84 | // Create new graphic items for bars |
|
90 | // Create new graphic items for bars | |
85 | int totalItems = mSeries.countTotalItems(); |
|
91 | int totalItems = mSeries.countTotalItems(); | |
86 | for (int i=0; i<totalItems; i++) { |
|
92 | for (int i=0; i<totalItems; i++) { | |
87 | Bar *bar = new Bar(this); |
|
93 | Bar *bar = new Bar(this); | |
88 | childItems().append(bar); |
|
94 | childItems().append(bar); | |
89 | } |
|
95 | } | |
90 |
|
96 | |||
91 | mLayoutDirty = true; |
|
97 | mLayoutDirty = true; | |
92 | } |
|
98 | } | |
93 |
|
99 | |||
94 | void PercentBarGroup::layoutChanged() |
|
100 | void PercentBarGroup::layoutChanged() | |
95 | { |
|
101 | { | |
96 | // Scale bars to new layout |
|
102 | // Scale bars to new layout | |
97 | // Layout for bars: |
|
103 | // Layout for bars: | |
98 | if (mSeries.countRows() <= 0) { |
|
104 | if (mSeries.countRows() <= 0) { | |
99 | // Nothing to do. |
|
105 | // Nothing to do. | |
100 | return; |
|
106 | return; | |
101 | } |
|
107 | } | |
102 |
|
108 | |||
103 | // TODO: better way to auto-layout |
|
109 | // TODO: better way to auto-layout | |
104 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
110 | // Use reals for accurancy (we might get some compiler warnings... :) | |
105 | int count = mSeries.countColumns(); |
|
111 | int count = mSeries.countColumns(); | |
106 | int itemIndex(0); |
|
112 | int itemIndex(0); | |
107 | qreal tW = mWidth; |
|
113 | qreal tW = mWidth; | |
108 | qreal tC = count+1; |
|
114 | qreal tC = count+1; | |
109 | qreal xStep = (tW/tC); |
|
115 | qreal xStep = (tW/tC); | |
110 | qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); |
|
116 | qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); | |
111 |
|
117 | |||
112 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
118 | for (int column = 0; column < mSeries.countColumns(); column++) { | |
113 | qreal colSum = mSeries.columnSum(column); |
|
119 | qreal colSum = mSeries.columnSum(column); | |
114 | qreal h = mHeight; |
|
120 | qreal h = mHeight; | |
115 | qreal scale = (h / colSum); |
|
121 | qreal scale = (h / colSum); | |
116 | qreal yPos = h; |
|
122 | qreal yPos = h; | |
117 | for (int row=0; row < mSeries.countRows(); row++) { |
|
123 | for (int row=0; row < mSeries.countRows(); row++) { | |
118 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
124 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
119 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
125 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
120 |
|
126 | |||
121 | // TODO: width settable per bar? |
|
127 | // TODO: width settable per bar? | |
122 | bar->resize(mBarDefaultWidth, barHeight); |
|
128 | bar->resize(mBarDefaultWidth, barHeight); | |
123 | bar->setColor(mColors.at(row)); |
|
129 | bar->setColor(mColors.at(row)); | |
124 | bar->setPos(xPos, yPos); |
|
130 | bar->setPos(xPos, yPos); | |
125 | itemIndex++; |
|
131 | itemIndex++; | |
126 | yPos -= barHeight; |
|
132 | yPos -= barHeight; | |
127 | } |
|
133 | } | |
128 | xPos += xStep; |
|
134 | xPos += xStep; | |
129 | } |
|
135 | } | |
130 | mLayoutDirty = true; |
|
136 | mLayoutDirty = true; | |
131 | } |
|
137 | } | |
132 |
|
138 | |||
133 | QTCOMMERCIALCHART_END_NAMESPACE |
|
139 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,134 +1,140 | |||||
1 | #include "stackedbargroup.h" |
|
1 | #include "stackedbargroup.h" | |
2 | #include "bar.h" |
|
2 | #include "bar.h" | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : |
|
7 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : | |
8 | ChartItem(parent) |
|
8 | ChartItem(parent) | |
9 | ,mSeries(series) |
|
9 | ,mSeries(series) | |
10 | ,mLayoutSet(false) |
|
10 | ,mLayoutSet(false) | |
11 | ,mLayoutDirty(true) |
|
11 | ,mLayoutDirty(true) | |
12 | ,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 | |
13 | { |
|
13 | { | |
14 | dataChanged(); |
|
14 | dataChanged(); | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | void StackedBarGroup::setSize(const QSize& size) |
|
18 | void StackedBarGroup::setSize(const QSize& size) | |
19 | { |
|
19 | { | |
20 | // qDebug() << "StackedBarGroup::setSize"; |
|
20 | // qDebug() << "StackedBarGroup::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 StackedBarGroup::setPlotDomain(const PlotDomain& data) |
|
27 | void StackedBarGroup::setPlotDomain(const PlotDomain& data) | |
28 | { |
|
28 | { | |
29 | qDebug() << "StackedBarGroup::setPlotDomain"; |
|
29 | qDebug() << "StackedBarGroup::setPlotDomain"; | |
30 | // TODO: |
|
30 | // TODO: | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
|
33 | void StackedBarGroup::setTheme(ChartTheme *theme) | |||
|
34 | { | |||
|
35 | qDebug() << "StackedBarGroup::setTheme"; | |||
|
36 | // TODO: | |||
|
37 | } | |||
|
38 | ||||
33 | void StackedBarGroup::setBarWidth( int w ) |
|
39 | void StackedBarGroup::setBarWidth( int w ) | |
34 | { |
|
40 | { | |
35 | mBarDefaultWidth = w; |
|
41 | mBarDefaultWidth = w; | |
36 | } |
|
42 | } | |
37 |
|
43 | |||
38 | int StackedBarGroup::addColor( QColor color ) |
|
44 | int StackedBarGroup::addColor( QColor color ) | |
39 | { |
|
45 | { | |
40 | int colorIndex = mColors.count(); |
|
46 | int colorIndex = mColors.count(); | |
41 | mColors.append(color); |
|
47 | mColors.append(color); | |
42 | return colorIndex; |
|
48 | return colorIndex; | |
43 | } |
|
49 | } | |
44 |
|
50 | |||
45 | void StackedBarGroup::resetColors() |
|
51 | void StackedBarGroup::resetColors() | |
46 | { |
|
52 | { | |
47 | mColors.clear(); |
|
53 | mColors.clear(); | |
48 | } |
|
54 | } | |
49 |
|
55 | |||
50 | void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
56 | void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
51 | { |
|
57 | { | |
52 | if (!mLayoutSet) { |
|
58 | if (!mLayoutSet) { | |
53 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
59 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
54 | return; |
|
60 | return; | |
55 | } |
|
61 | } | |
56 | if (mLayoutDirty) { |
|
62 | if (mLayoutDirty) { | |
57 | // Layout or data has changed. Need to redraw. |
|
63 | // Layout or data has changed. Need to redraw. | |
58 | foreach(QGraphicsItem* i, childItems()) { |
|
64 | foreach(QGraphicsItem* i, childItems()) { | |
59 | i->paint(painter,option,widget); |
|
65 | i->paint(painter,option,widget); | |
60 | } |
|
66 | } | |
61 | } |
|
67 | } | |
62 | } |
|
68 | } | |
63 |
|
69 | |||
64 | QRectF StackedBarGroup::boundingRect() const |
|
70 | QRectF StackedBarGroup::boundingRect() const | |
65 | { |
|
71 | { | |
66 | return QRectF(0,0,mWidth,mHeight); |
|
72 | return QRectF(0,0,mWidth,mHeight); | |
67 | } |
|
73 | } | |
68 |
|
74 | |||
69 |
|
75 | |||
70 | void StackedBarGroup::dataChanged() |
|
76 | void StackedBarGroup::dataChanged() | |
71 | { |
|
77 | { | |
72 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
78 | qDebug() << "QBarChart::dataChanged mSeries"; | |
73 |
|
79 | |||
74 | // Find out maximum and minimum of all series |
|
80 | // Find out maximum and minimum of all series | |
75 | mMax = mSeries.max(); |
|
81 | mMax = mSeries.max(); | |
76 | mMin = mSeries.min(); |
|
82 | mMin = mSeries.min(); | |
77 |
|
83 | |||
78 | // Delete old bars |
|
84 | // Delete old bars | |
79 | // Is this correct way to delete childItems? |
|
85 | // Is this correct way to delete childItems? | |
80 | foreach (QGraphicsItem* item, childItems()) { |
|
86 | foreach (QGraphicsItem* item, childItems()) { | |
81 | delete item; |
|
87 | delete item; | |
82 | } |
|
88 | } | |
83 |
|
89 | |||
84 | // Create new graphic items for bars |
|
90 | // Create new graphic items for bars | |
85 | int totalItems = mSeries.countTotalItems(); |
|
91 | int totalItems = mSeries.countTotalItems(); | |
86 | for (int i=0; i<totalItems; i++) { |
|
92 | for (int i=0; i<totalItems; i++) { | |
87 | Bar *bar = new Bar(this); |
|
93 | Bar *bar = new Bar(this); | |
88 | childItems().append(bar); |
|
94 | childItems().append(bar); | |
89 | } |
|
95 | } | |
90 |
|
96 | |||
91 | mLayoutDirty = true; |
|
97 | mLayoutDirty = true; | |
92 | } |
|
98 | } | |
93 |
|
99 | |||
94 | void StackedBarGroup::layoutChanged() |
|
100 | void StackedBarGroup::layoutChanged() | |
95 | { |
|
101 | { | |
96 | // Scale bars to new layout |
|
102 | // Scale bars to new layout | |
97 | // Layout for bars: |
|
103 | // Layout for bars: | |
98 | if (mSeries.countRows() <= 0) { |
|
104 | if (mSeries.countRows() <= 0) { | |
99 | // Nothing to do. |
|
105 | // Nothing to do. | |
100 | return; |
|
106 | return; | |
101 | } |
|
107 | } | |
102 |
|
108 | |||
103 | // TODO: better way to auto-layout |
|
109 | // TODO: better way to auto-layout | |
104 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
110 | // Use reals for accurancy (we might get some compiler warnings... :) | |
105 | qreal maxSum = mSeries.maxColumnSum(); |
|
111 | qreal maxSum = mSeries.maxColumnSum(); | |
106 | qreal h = mHeight; |
|
112 | qreal h = mHeight; | |
107 | qreal scale = (h / maxSum); |
|
113 | qreal scale = (h / maxSum); | |
108 |
|
114 | |||
109 | int count = mSeries.countColumns(); |
|
115 | int count = mSeries.countColumns(); | |
110 | int itemIndex(0); |
|
116 | int itemIndex(0); | |
111 | qreal tW = mWidth; |
|
117 | qreal tW = mWidth; | |
112 | qreal tC = count+1; |
|
118 | qreal tC = count+1; | |
113 | qreal xStep = (tW/tC); |
|
119 | qreal xStep = (tW/tC); | |
114 | qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); |
|
120 | qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); | |
115 |
|
121 | |||
116 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
122 | for (int column = 0; column < mSeries.countColumns(); column++) { | |
117 | qreal yPos = h; |
|
123 | qreal yPos = h; | |
118 | for (int row=0; row < mSeries.countRows(); row++) { |
|
124 | for (int row=0; row < mSeries.countRows(); row++) { | |
119 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
125 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
120 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
126 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
121 |
|
127 | |||
122 | // TODO: width settable per bar? |
|
128 | // TODO: width settable per bar? | |
123 | bar->resize(mBarDefaultWidth, barHeight); |
|
129 | bar->resize(mBarDefaultWidth, barHeight); | |
124 | bar->setColor(mColors.at(row)); |
|
130 | bar->setColor(mColors.at(row)); | |
125 | bar->setPos(xPos, yPos); |
|
131 | bar->setPos(xPos, yPos); | |
126 | itemIndex++; |
|
132 | itemIndex++; | |
127 | yPos -= barHeight; |
|
133 | yPos -= barHeight; | |
128 | } |
|
134 | } | |
129 | xPos += xStep; |
|
135 | xPos += xStep; | |
130 | } |
|
136 | } | |
131 | mLayoutDirty = true; |
|
137 | mLayoutDirty = true; | |
132 | } |
|
138 | } | |
133 |
|
139 | |||
134 | QTCOMMERCIALCHART_END_NAMESPACE |
|
140 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,58 | |||||
1 | #ifndef STACKEDBARGROUP_H |
|
1 | #ifndef STACKEDBARGROUP_H | |
2 | #define STACKEDBARGROUP_H |
|
2 | #define STACKEDBARGROUP_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include "bar.h" |
|
5 | #include "bar.h" | |
6 | #include "stackedbarchartseries.h" |
|
6 | #include "stackedbarchartseries.h" | |
7 | #include <QGraphicsItem> |
|
7 | #include <QGraphicsItem> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
|
11 | // TODO: derive this from ChartObjectInterface, when setSize is back in ChartItem | |||
11 | class StackedBarGroup : public ChartItem |
|
12 | class StackedBarGroup : public ChartItem | |
12 | { |
|
13 | { | |
13 | public: |
|
14 | public: | |
14 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); |
|
15 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); | |
15 |
|
16 | |||
16 | public: // From ChartObjectInterface |
|
17 | public: // From ChartObjectInterface | |
17 | void setSize(const QSize &size); |
|
18 | void setSize(const QSize &size); | |
18 | void setTheme(ChartTheme *theme); |
|
19 | void setTheme(ChartTheme *theme); | |
19 | void setPlotDomain(const PlotDomain& data); |
|
20 | void setPlotDomain(const PlotDomain& data); | |
20 |
|
21 | |||
21 | public: // Layout "api" |
|
22 | public: // Layout "api" | |
22 | void setPos(qreal x, qreal y); |
|
23 | void setPos(qreal x, qreal y); | |
23 | void setBarWidth( int w ); // Default width for each bar |
|
24 | void setBarWidth( int w ); // Default width for each bar | |
24 |
|
25 | |||
25 | int addColor( QColor color ); |
|
26 | int addColor( QColor color ); | |
26 | void resetColors(); |
|
27 | void resetColors(); | |
27 |
|
28 | |||
28 | // From QGraphicsItem |
|
29 | // From QGraphicsItem | |
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
30 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
30 | QRectF boundingRect() const; |
|
31 | QRectF boundingRect() const; | |
31 |
|
32 | |||
32 | private: |
|
33 | private: | |
33 |
|
34 | |||
34 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
35 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
35 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
36 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
36 |
|
37 | |||
37 | private: |
|
38 | private: | |
38 |
|
39 | |||
39 | // Data |
|
40 | // Data | |
40 | StackedBarChartSeries& mSeries; |
|
41 | StackedBarChartSeries& mSeries; | |
41 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) |
|
42 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) | |
42 | int mMax; |
|
43 | int mMax; | |
43 |
|
44 | |||
44 | int mHeight; // Layout spesific |
|
45 | int mHeight; // Layout spesific | |
45 | int mWidth; |
|
46 | int mWidth; | |
46 | int mBarDefaultWidth; |
|
47 | int mBarDefaultWidth; | |
47 |
|
48 | |||
48 | bool mLayoutSet; // True, if component has been laid out. |
|
49 | bool mLayoutSet; // True, if component has been laid out. | |
49 | bool mLayoutDirty; |
|
50 | bool mLayoutDirty; | |
50 |
|
51 | |||
51 | QList<QColor> mColors; // List of colors for series for now |
|
52 | QList<QColor> mColors; // List of colors for series for now | |
52 |
|
53 | |||
53 | }; |
|
54 | }; | |
54 |
|
55 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
57 | |||
57 | #endif // STACKEDBARGROUP_H |
|
58 | #endif // STACKEDBARGROUP_H |
@@ -1,22 +1,23 | |||||
1 | #ifndef CHARTITEM_H_ |
|
1 | #ifndef CHARTITEM_H_ | |
2 | #define CHARTITEM_H_ |
|
2 | #define CHARTITEM_H_ | |
3 |
|
3 | |||
4 | #include "plotdomain_p.h" |
|
4 | #include "plotdomain_p.h" | |
5 | #include "chartobjectinterface_p.h" |
|
5 | #include "chartobjectinterface_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | // TODO: setSize and set plotDomain back here. Derive this only from QGraphicsItem | ||
|
10 | // class ChartItem : public QGraphicsItem | |||
10 | class ChartItem : public QGraphicsItem, public ChartObjectInterface |
|
11 | class ChartItem : public QGraphicsItem, public ChartObjectInterface | |
11 | { |
|
12 | { | |
12 | enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; |
|
13 | enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; | |
13 | public: |
|
14 | public: | |
14 | ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){}; |
|
15 | ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){}; | |
15 | virtual ~ChartItem(){}; |
|
16 | virtual ~ChartItem(){}; | |
16 | // TODO: this is a hack; integration ongoing: |
|
17 | // TODO: this is a hack; integration ongoing: | |
17 | QGraphicsItem *graphicsItem() { return this; } |
|
18 | QGraphicsItem *graphicsItem() { return this; } | |
18 | }; |
|
19 | }; | |
19 |
|
20 | |||
20 | QTCOMMERCIALCHART_END_NAMESPACE |
|
21 | QTCOMMERCIALCHART_END_NAMESPACE | |
21 |
|
22 | |||
22 | #endif /* CHARTITEM_H_ */ |
|
23 | #endif /* CHARTITEM_H_ */ |
@@ -1,30 +1,31 | |||||
1 | #ifndef CHART_OBJECT_INTERFACE_H |
|
1 | #ifndef CHART_OBJECT_INTERFACE_H | |
2 | #define CHART_OBJECT_INTERFACE_H |
|
2 | #define CHART_OBJECT_INTERFACE_H | |
3 |
|
3 | |||
4 | #include "plotdomain_p.h" |
|
4 | #include "plotdomain_p.h" | |
5 | #include <qchartglobal.h> |
|
5 | #include <qchartglobal.h> | |
6 | #include <QSize> |
|
6 | #include <QSize> | |
7 |
|
7 | |||
8 | class QGraphicsItem; |
|
8 | class QGraphicsItem; | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class ChartTheme; |
|
12 | class ChartTheme; | |
13 | class PlotDomain; |
|
13 | class PlotDomain; | |
14 |
|
14 | |||
15 | /*! |
|
15 | /*! | |
16 | * Internal abstract interface for passing updates on chart related properties. |
|
16 | * Internal abstract interface for passing updates on chart related properties. | |
17 | */ |
|
17 | */ | |
18 | class ChartObjectInterface |
|
18 | class ChartObjectInterface | |
19 | { |
|
19 | { | |
20 | public: |
|
20 | public: | |
|
21 | // TODO: move setSize and setPlotDomain back to ChartItem. This interface should be only about handling themes. | |||
21 | virtual void setSize(const QSize &size) = 0; |
|
22 | virtual void setSize(const QSize &size) = 0; | |
22 | virtual void setTheme(ChartTheme *theme) = 0; |
|
23 | virtual void setTheme(ChartTheme *theme) = 0; | |
23 | virtual void setPlotDomain(const PlotDomain& data) = 0; |
|
24 | virtual void setPlotDomain(const PlotDomain& data) = 0; | |
24 | // TODO: this is a hack; integration ongoing: |
|
25 | // TODO: this is a hack; integration ongoing: | |
25 | virtual QGraphicsItem *graphicsItem() { return 0; } |
|
26 | virtual QGraphicsItem *graphicsItem() { return 0; } | |
26 | }; |
|
27 | }; | |
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_END_NAMESPACE |
|
29 | QTCOMMERCIALCHART_END_NAMESPACE | |
29 |
|
30 | |||
30 | #endif // CHART_OBJECT_INTERFACE_H |
|
31 | #endif // CHART_OBJECT_INTERFACE_H |
@@ -1,392 +1,394 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include "qscatterseries.h" |
|
3 | #include "qscatterseries.h" | |
4 | #include "qscatterseries_p.h" |
|
4 | #include "qscatterseries_p.h" | |
5 | #include "qpieseries.h" |
|
5 | #include "qpieseries.h" | |
6 | #include "qpieseries_p.h" |
|
6 | #include "qpieseries_p.h" | |
7 | #include "qxychartseries.h" |
|
7 | #include "qxychartseries.h" | |
8 | #include "qchartaxis.h" |
|
8 | #include "qchartaxis.h" | |
9 | #include "barchartseries.h" |
|
9 | #include "barchartseries.h" | |
10 | #include "bargroup.h" |
|
10 | #include "bargroup.h" | |
11 | #include "stackedbarchartseries.h" |
|
11 | #include "stackedbarchartseries.h" | |
12 | #include "stackedbargroup.h" |
|
12 | #include "stackedbargroup.h" | |
13 | #include "percentbarchartseries.h" |
|
13 | #include "percentbarchartseries.h" | |
14 | #include "percentbargroup.h" |
|
14 | #include "percentbargroup.h" | |
15 | #include "charttheme_p.h" |
|
15 | #include "charttheme_p.h" | |
16 | #include "chartobjectinterface_p.h" |
|
16 | #include "chartobjectinterface_p.h" | |
17 |
|
17 | |||
18 | #include "xylinechartitem_p.h" |
|
18 | #include "xylinechartitem_p.h" | |
19 | #include "plotdomain_p.h" |
|
19 | #include "plotdomain_p.h" | |
20 | #include "axisitem_p.h" |
|
20 | #include "axisitem_p.h" | |
21 | #include <QGraphicsScene> |
|
21 | #include <QGraphicsScene> | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), |
|
26 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |
27 | m_backgroundItem(0), |
|
27 | m_backgroundItem(0), | |
28 | m_titleItem(0), |
|
28 | m_titleItem(0), | |
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)), |
|
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)), | |
30 | m_plotDataIndex(0), |
|
30 | m_plotDataIndex(0), | |
31 | m_marginSize(0), |
|
31 | m_marginSize(0), | |
32 | m_chartTheme(new ChartTheme()) |
|
32 | m_chartTheme(new ChartTheme()) | |
33 | { |
|
33 | { | |
34 | // TODO: the default theme? |
|
34 | // TODO: the default theme? | |
35 | setTheme(QChart::ChartThemeDefault); |
|
35 | setTheme(QChart::ChartThemeDefault); | |
36 |
|
36 | |||
37 | PlotDomain domain; |
|
37 | PlotDomain domain; | |
38 | m_plotDomainList << domain; |
|
38 | m_plotDomainList << domain; | |
39 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); |
|
39 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); | |
40 | m_chartObjectInterfaces << m_axisXItem; |
|
40 | m_chartObjectInterfaces << m_axisXItem; | |
41 | m_chartObjectInterfaces << m_axisYItem.at(0); |
|
41 | m_chartObjectInterfaces << m_axisYItem.at(0); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QChart::~QChart(){} |
|
44 | QChart::~QChart(){} | |
45 |
|
45 | |||
46 | QRectF QChart::boundingRect() const |
|
46 | QRectF QChart::boundingRect() const | |
47 | { |
|
47 | { | |
48 | return m_rect; |
|
48 | return m_rect; | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void QChart::addSeries(QChartSeries* series) |
|
51 | void QChart::addSeries(QChartSeries* series) | |
52 | { |
|
52 | { | |
53 | // TODO: we should check the series not already added |
|
53 | // TODO: we should check the series not already added | |
54 |
|
54 | |||
55 | m_chartSeries << series; |
|
55 | m_chartSeries << series; | |
56 |
|
56 | |||
57 | switch(series->type()) |
|
57 | switch(series->type()) | |
58 | { |
|
58 | { | |
59 | case QChartSeries::SeriesTypeLine: { |
|
59 | case QChartSeries::SeriesTypeLine: { | |
60 |
|
60 | |||
61 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
61 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
62 | m_plotDataIndex = 0 ; |
|
62 | m_plotDataIndex = 0 ; | |
63 | m_plotDomainList.resize(1); |
|
63 | m_plotDomainList.resize(1); | |
64 |
|
64 | |||
65 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
65 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
66 |
|
66 | |||
67 | for (int i = 0 ; i < xyseries->count() ; i++) |
|
67 | for (int i = 0 ; i < xyseries->count() ; i++) | |
68 | { |
|
68 | { | |
69 | qreal x = xyseries->x(i); |
|
69 | qreal x = xyseries->x(i); | |
70 | qreal y = xyseries->y(i); |
|
70 | qreal y = xyseries->y(i); | |
71 | domain.m_minX = qMin(domain.m_minX,x); |
|
71 | domain.m_minX = qMin(domain.m_minX,x); | |
72 | domain.m_minY = qMin(domain.m_minY,y); |
|
72 | domain.m_minY = qMin(domain.m_minY,y); | |
73 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
73 | domain.m_maxX = qMax(domain.m_maxX,x); | |
74 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
74 | domain.m_maxY = qMax(domain.m_maxY,y); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); |
|
77 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
78 |
|
78 | |||
79 | // TODO: combine ChartObjectInterface and ChartItem apis |
|
79 | // TODO: combine ChartObjectInterface and ChartItem apis | |
80 | m_chartObjectInterfaces << item; |
|
80 | m_chartObjectInterfaces << item; | |
81 | item->setTheme(m_chartTheme); |
|
81 | item->setTheme(m_chartTheme); | |
82 |
|
82 | |||
83 | foreach(ChartObjectInterface* i, m_chartObjectInterfaces) |
|
83 | foreach(ChartObjectInterface* i, m_chartObjectInterfaces) | |
84 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
84 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
85 |
|
85 | |||
86 | break; |
|
86 | break; | |
87 | } |
|
87 | } | |
88 | case QChartSeries::SeriesTypeBar: { |
|
88 | case QChartSeries::SeriesTypeBar: { | |
89 |
|
89 | |||
90 | qDebug() << "barSeries added"; |
|
90 | qDebug() << "barSeries added"; | |
91 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
91 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
92 | BarGroup* barGroup = new BarGroup(*barSeries,this); |
|
92 | BarGroup* barGroup = new BarGroup(*barSeries,this); | |
93 |
|
93 | |||
94 | // Add some fugly colors for 5 fist series... |
|
94 | // Add some fugly colors for 5 fist series... | |
95 | barGroup->addColor(QColor(255,0,0,128)); |
|
95 | barGroup->addColor(QColor(255,0,0,128)); | |
96 | barGroup->addColor(QColor(255,255,0,128)); |
|
96 | barGroup->addColor(QColor(255,255,0,128)); | |
97 | barGroup->addColor(QColor(0,255,0,128)); |
|
97 | barGroup->addColor(QColor(0,255,0,128)); | |
98 | barGroup->addColor(QColor(0,0,255,128)); |
|
98 | barGroup->addColor(QColor(0,0,255,128)); | |
99 | barGroup->addColor(QColor(255,128,0,128)); |
|
99 | barGroup->addColor(QColor(255,128,0,128)); | |
100 |
|
100 | |||
101 | m_chartObjectInterfaces << barGroup; |
|
101 | m_chartObjectInterfaces << barGroup; | |
102 | childItems().append(barGroup); |
|
102 | childItems().append(barGroup); | |
103 |
|
103 | /* | ||
104 | m_plotDataIndex = 0 ; |
|
104 | m_plotDataIndex = 0 ; | |
105 | m_plotDomainList.resize(1); |
|
105 | m_plotDomainList.resize(1); | |
106 |
|
|
106 | ||
107 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
107 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
108 | foreach(ChartItem* i ,m_chartItems) |
|
108 | foreach(ChartItem* i ,m_chartItems) | |
109 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
109 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
110 |
|
110 | */ | ||
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 | case QChartSeries::SeriesTypeStackedBar: { |
|
113 | case QChartSeries::SeriesTypeStackedBar: { | |
114 |
|
114 | |||
115 | qDebug() << "barSeries added"; |
|
115 | qDebug() << "barSeries added"; | |
116 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
116 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
117 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); |
|
117 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); | |
118 |
|
118 | |||
119 | // Add some fugly colors for 5 fist series... |
|
119 | // Add some fugly colors for 5 fist series... | |
120 | stackedBarGroup->addColor(QColor(255,0,0,128)); |
|
120 | stackedBarGroup->addColor(QColor(255,0,0,128)); | |
121 | stackedBarGroup->addColor(QColor(255,255,0,128)); |
|
121 | stackedBarGroup->addColor(QColor(255,255,0,128)); | |
122 | stackedBarGroup->addColor(QColor(0,255,0,128)); |
|
122 | stackedBarGroup->addColor(QColor(0,255,0,128)); | |
123 | stackedBarGroup->addColor(QColor(0,0,255,128)); |
|
123 | stackedBarGroup->addColor(QColor(0,0,255,128)); | |
124 | stackedBarGroup->addColor(QColor(255,128,0,128)); |
|
124 | stackedBarGroup->addColor(QColor(255,128,0,128)); | |
125 |
|
125 | |||
126 | m_chartObjectInterfaces << stackedBarGroup; |
|
126 | m_chartObjectInterfaces << stackedBarGroup; | |
127 | childItems().append(stackedBarGroup); |
|
127 | childItems().append(stackedBarGroup); | |
|
128 | /* | |||
128 | m_plotDataIndex = 0 ; |
|
129 | m_plotDataIndex = 0 ; | |
129 | m_plotDomainList.resize(1); |
|
130 | m_plotDomainList.resize(1); | |
130 |
|
|
131 | ||
131 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
132 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
132 | foreach(ChartItem* i ,m_chartItems) |
|
133 | foreach(ChartItem* i ,m_chartItems) | |
133 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
134 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
134 |
|
135 | */ | ||
135 | break; |
|
136 | break; | |
136 | } |
|
137 | } | |
137 | case QChartSeries::SeriesTypePercentBar: { |
|
138 | case QChartSeries::SeriesTypePercentBar: { | |
138 |
|
139 | |||
139 | qDebug() << "barSeries added"; |
|
140 | qDebug() << "barSeries added"; | |
140 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
141 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
141 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); |
|
142 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); | |
142 |
|
143 | |||
143 | // Add some fugly colors for 5 fist series... |
|
144 | // Add some fugly colors for 5 fist series... | |
144 | percentBarGroup->addColor(QColor(255,0,0,128)); |
|
145 | percentBarGroup->addColor(QColor(255,0,0,128)); | |
145 | percentBarGroup->addColor(QColor(255,255,0,128)); |
|
146 | percentBarGroup->addColor(QColor(255,255,0,128)); | |
146 | percentBarGroup->addColor(QColor(0,255,0,128)); |
|
147 | percentBarGroup->addColor(QColor(0,255,0,128)); | |
147 | percentBarGroup->addColor(QColor(0,0,255,128)); |
|
148 | percentBarGroup->addColor(QColor(0,0,255,128)); | |
148 | percentBarGroup->addColor(QColor(255,128,0,128)); |
|
149 | percentBarGroup->addColor(QColor(255,128,0,128)); | |
149 |
|
150 | |||
150 | m_chartObjectInterfaces << percentBarGroup; |
|
151 | m_chartObjectInterfaces << percentBarGroup; | |
151 | childItems().append(percentBarGroup); |
|
152 | childItems().append(percentBarGroup); | |
|
153 | /* | |||
152 | m_plotDataIndex = 0 ; |
|
154 | m_plotDataIndex = 0 ; | |
153 | m_plotDomainList.resize(1); |
|
155 | m_plotDomainList.resize(1); | |
154 |
|
|
156 | ||
155 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
157 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
156 | foreach(ChartItem* i ,m_chartItems) |
|
158 | foreach(ChartItem* i ,m_chartItems) | |
157 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
159 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
158 |
|
160 | */ | ||
159 | break; |
|
161 | break; | |
160 | } |
|
162 | } | |
161 | case QChartSeries::SeriesTypeScatter: { |
|
163 | case QChartSeries::SeriesTypeScatter: { | |
162 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
164 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
163 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
165 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
164 | scatterSeries->d->setParentItem(this); |
|
166 | scatterSeries->d->setParentItem(this); | |
165 | m_chartObjectInterfaces << scatterSeries->d; |
|
167 | m_chartObjectInterfaces << scatterSeries->d; | |
166 | //TODO:? scatterSeries->d->m_themeIndex = m_chartSeries.count() - 1; |
|
168 | //TODO:? scatterSeries->d->m_themeIndex = m_chartSeries.count() - 1; | |
167 | break; |
|
169 | break; | |
168 | } |
|
170 | } | |
169 | case QChartSeries::SeriesTypePie: { |
|
171 | case QChartSeries::SeriesTypePie: { | |
170 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
172 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
171 | // for (int i(0); i < pieSeries->sliceCount(); i++) { |
|
173 | // for (int i(0); i < pieSeries->sliceCount(); i++) { | |
172 | // if (!pieSeries->sliceColor(i).isValid()) |
|
174 | // if (!pieSeries->sliceColor(i).isValid()) | |
173 | // pieSeries->setSliceColor(i, nextColor()); |
|
175 | // pieSeries->setSliceColor(i, nextColor()); | |
174 | // } |
|
176 | // } | |
175 | pieSeries->d->setTheme(m_chartTheme); |
|
177 | pieSeries->d->setTheme(m_chartTheme); | |
176 | m_chartObjectInterfaces << pieSeries->d; |
|
178 | m_chartObjectInterfaces << pieSeries->d; | |
177 |
|
179 | |||
178 | // Set pre-defined colors in case the series has no colors defined |
|
180 | // Set pre-defined colors in case the series has no colors defined | |
179 | // TODO: how to define the color for all the slices of a pie? |
|
181 | // TODO: how to define the color for all the slices of a pie? | |
180 | // for (int (i); i < pieSeries.sliceCount(); i++) |
|
182 | // for (int (i); i < pieSeries.sliceCount(); i++) | |
181 | break; |
|
183 | break; | |
182 | } |
|
184 | } | |
183 | } |
|
185 | } | |
184 | } |
|
186 | } | |
185 |
|
187 | |||
186 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
188 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
187 | { |
|
189 | { | |
188 | // TODO: support also other types; not only scatter and pie |
|
190 | // TODO: support also other types; not only scatter and pie | |
189 |
|
191 | |||
190 | QChartSeries *series(0); |
|
192 | QChartSeries *series(0); | |
191 |
|
193 | |||
192 | switch (type) { |
|
194 | switch (type) { | |
193 | case QChartSeries::SeriesTypeLine: { |
|
195 | case QChartSeries::SeriesTypeLine: { | |
194 | series = QXYChartSeries::create(); |
|
196 | series = QXYChartSeries::create(); | |
195 | break; |
|
197 | break; | |
196 | } |
|
198 | } | |
197 | case QChartSeries::SeriesTypeBar: { |
|
199 | case QChartSeries::SeriesTypeBar: { | |
198 | series = new BarChartSeries(this); |
|
200 | series = new BarChartSeries(this); | |
199 | break; |
|
201 | break; | |
200 | } |
|
202 | } | |
201 | case QChartSeries::SeriesTypeStackedBar: { |
|
203 | case QChartSeries::SeriesTypeStackedBar: { | |
202 | series = new StackedBarChartSeries(this); |
|
204 | series = new StackedBarChartSeries(this); | |
203 | break; |
|
205 | break; | |
204 | } |
|
206 | } | |
205 | case QChartSeries::SeriesTypePercentBar: { |
|
207 | case QChartSeries::SeriesTypePercentBar: { | |
206 | series = new PercentBarChartSeries(this); |
|
208 | series = new PercentBarChartSeries(this); | |
207 | break; |
|
209 | break; | |
208 | } |
|
210 | } | |
209 | case QChartSeries::SeriesTypeScatter: { |
|
211 | case QChartSeries::SeriesTypeScatter: { | |
210 | series = new QScatterSeries(this); |
|
212 | series = new QScatterSeries(this); | |
211 | break; |
|
213 | break; | |
212 | } |
|
214 | } | |
213 | case QChartSeries::SeriesTypePie: { |
|
215 | case QChartSeries::SeriesTypePie: { | |
214 | series = new QPieSeries(this); |
|
216 | series = new QPieSeries(this); | |
215 | break; |
|
217 | break; | |
216 | } |
|
218 | } | |
217 | default: |
|
219 | default: | |
218 | Q_ASSERT(false); |
|
220 | Q_ASSERT(false); | |
219 | break; |
|
221 | break; | |
220 | } |
|
222 | } | |
221 |
|
223 | |||
222 | addSeries(series); |
|
224 | addSeries(series); | |
223 | return series; |
|
225 | return series; | |
224 | } |
|
226 | } | |
225 |
|
227 | |||
226 | void QChart::setSize(const QSize& size) |
|
228 | void QChart::setSize(const QSize& size) | |
227 | { |
|
229 | { | |
228 | m_rect = QRect(QPoint(0,0),size); |
|
230 | m_rect = QRect(QPoint(0,0),size); | |
229 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
231 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
230 |
|
232 | |||
231 | // recalculate title position |
|
233 | // recalculate title position | |
232 | if (m_titleItem) { |
|
234 | if (m_titleItem) { | |
233 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
235 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
234 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
236 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
235 | } |
|
237 | } | |
236 |
|
238 | |||
237 | //recalculate background gradient |
|
239 | //recalculate background gradient | |
238 | if (m_backgroundItem) { |
|
240 | if (m_backgroundItem) { | |
239 | m_backgroundItem->setRect(rect); |
|
241 | m_backgroundItem->setRect(rect); | |
240 | if (m_bacgroundOrinetation == HorizonatlGradientOrientation) |
|
242 | if (m_bacgroundOrinetation == HorizonatlGradientOrientation) | |
241 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0); |
|
243 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0); | |
242 | else |
|
244 | else | |
243 | m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height()); |
|
245 | m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height()); | |
244 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
246 | m_backgroundItem->setBrush(m_backgroundGradient); | |
245 | } |
|
247 | } | |
246 |
|
248 | |||
247 | // resize and reposition childs |
|
249 | // resize and reposition childs | |
248 | foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces) { |
|
250 | foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces) { | |
249 | QGraphicsItem *item = ctrl->graphicsItem(); |
|
251 | QGraphicsItem *item = ctrl->graphicsItem(); | |
250 | if (item) |
|
252 | if (item) | |
251 | item->setPos(rect.topLeft()); |
|
253 | item->setPos(rect.topLeft()); | |
252 | ctrl->setSize(rect.size()); |
|
254 | ctrl->setSize(rect.size()); | |
253 | } |
|
255 | } | |
254 |
|
256 | |||
255 | update(); |
|
257 | update(); | |
256 | } |
|
258 | } | |
257 |
|
259 | |||
258 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) |
|
260 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) | |
259 | { |
|
261 | { | |
260 |
|
262 | |||
261 | if(!m_backgroundItem){ |
|
263 | if(!m_backgroundItem){ | |
262 | m_backgroundItem = new QGraphicsRectItem(this); |
|
264 | m_backgroundItem = new QGraphicsRectItem(this); | |
263 | m_backgroundItem->setZValue(-1); |
|
265 | m_backgroundItem->setZValue(-1); | |
264 | } |
|
266 | } | |
265 |
|
267 | |||
266 | m_bacgroundOrinetation = orientation; |
|
268 | m_bacgroundOrinetation = orientation; | |
267 | m_backgroundGradient.setColorAt(0.0, startColor); |
|
269 | m_backgroundGradient.setColorAt(0.0, startColor); | |
268 | m_backgroundGradient.setColorAt(1.0, endColor); |
|
270 | m_backgroundGradient.setColorAt(1.0, endColor); | |
269 | m_backgroundGradient.setStart(0,0); |
|
271 | m_backgroundGradient.setStart(0,0); | |
270 |
|
272 | |||
271 | if(orientation == VerticalGradientOrientation){ |
|
273 | if(orientation == VerticalGradientOrientation){ | |
272 | m_backgroundGradient.setFinalStop(0,m_rect.height()); |
|
274 | m_backgroundGradient.setFinalStop(0,m_rect.height()); | |
273 | }else{ |
|
275 | }else{ | |
274 | m_backgroundGradient.setFinalStop(m_rect.width(),0); |
|
276 | m_backgroundGradient.setFinalStop(m_rect.width(),0); | |
275 | } |
|
277 | } | |
276 |
|
278 | |||
277 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
279 | m_backgroundItem->setBrush(m_backgroundGradient); | |
278 | m_backgroundItem->setPen(Qt::NoPen); |
|
280 | m_backgroundItem->setPen(Qt::NoPen); | |
279 | m_backgroundItem->update(); |
|
281 | m_backgroundItem->update(); | |
280 | } |
|
282 | } | |
281 |
|
283 | |||
282 | void QChart::setTitle(const QString& title,const QFont& font) |
|
284 | void QChart::setTitle(const QString& title,const QFont& font) | |
283 | { |
|
285 | { | |
284 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
286 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
285 | m_titleItem->setPlainText(title); |
|
287 | m_titleItem->setPlainText(title); | |
286 | m_titleItem->setFont(font); |
|
288 | m_titleItem->setFont(font); | |
287 | } |
|
289 | } | |
288 |
|
290 | |||
289 | int QChart::margin() const |
|
291 | int QChart::margin() const | |
290 | { |
|
292 | { | |
291 | return m_marginSize; |
|
293 | return m_marginSize; | |
292 | } |
|
294 | } | |
293 |
|
295 | |||
294 | void QChart::setMargin(int margin) |
|
296 | void QChart::setMargin(int margin) | |
295 | { |
|
297 | { | |
296 | m_marginSize = margin; |
|
298 | m_marginSize = margin; | |
297 | } |
|
299 | } | |
298 |
|
300 | |||
299 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
301 | void QChart::setTheme(QChart::ChartThemeId theme) | |
300 | { |
|
302 | { | |
301 | if (theme != m_chartTheme->d->m_currentTheme) { |
|
303 | if (theme != m_chartTheme->d->m_currentTheme) { | |
302 | m_chartTheme->d->setTheme(theme); |
|
304 | m_chartTheme->d->setTheme(theme); | |
303 | setBackground(m_chartTheme->d->m_gradientStartColor, |
|
305 | setBackground(m_chartTheme->d->m_gradientStartColor, | |
304 | m_chartTheme->d->m_gradientEndColor, |
|
306 | m_chartTheme->d->m_gradientEndColor, | |
305 | m_bacgroundOrinetation); |
|
307 | m_bacgroundOrinetation); | |
306 | foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces) |
|
308 | foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces) | |
307 | ctrl->setTheme(m_chartTheme); |
|
309 | ctrl->setTheme(m_chartTheme); | |
308 | update(); |
|
310 | update(); | |
309 | } |
|
311 | } | |
310 | } |
|
312 | } | |
311 |
|
313 | |||
312 | void QChart::zoomInToRect(const QRect& rectangle) |
|
314 | void QChart::zoomInToRect(const QRect& rectangle) | |
313 | { |
|
315 | { | |
314 |
|
316 | |||
315 | if(!rectangle.isValid()) return; |
|
317 | if(!rectangle.isValid()) return; | |
316 |
|
318 | |||
317 | qreal margin = this->margin(); |
|
319 | qreal margin = this->margin(); | |
318 |
|
320 | |||
319 | QRect rect = rectangle.normalized(); |
|
321 | QRect rect = rectangle.normalized(); | |
320 | rect.translate(-margin, -margin); |
|
322 | rect.translate(-margin, -margin); | |
321 |
|
323 | |||
322 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; |
|
324 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; | |
323 |
|
325 | |||
324 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); |
|
326 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); | |
325 |
|
327 | |||
326 | m_plotDomainList.resize(m_plotDataIndex + 1); |
|
328 | m_plotDomainList.resize(m_plotDataIndex + 1); | |
327 | m_plotDomainList<<domain; |
|
329 | m_plotDomainList<<domain; | |
328 | m_plotDataIndex++; |
|
330 | m_plotDataIndex++; | |
329 |
|
331 | |||
330 | foreach (ChartObjectInterface* ctrl, m_chartObjectInterfaces) |
|
332 | foreach (ChartObjectInterface* ctrl, m_chartObjectInterfaces) | |
331 | ctrl->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
333 | ctrl->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
332 | update(); |
|
334 | update(); | |
333 | } |
|
335 | } | |
334 |
|
336 | |||
335 | void QChart::zoomIn() |
|
337 | void QChart::zoomIn() | |
336 | { |
|
338 | { | |
337 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { |
|
339 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { | |
338 | m_plotDataIndex++; |
|
340 | m_plotDataIndex++; | |
339 | foreach (ChartObjectInterface* item, m_chartObjectInterfaces) |
|
341 | foreach (ChartObjectInterface* item, m_chartObjectInterfaces) | |
340 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
342 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
341 | update(); |
|
343 | update(); | |
342 | } else { |
|
344 | } else { | |
343 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
345 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
344 | rect.setWidth(rect.width()/2); |
|
346 | rect.setWidth(rect.width()/2); | |
345 | rect.setHeight(rect.height()/2); |
|
347 | rect.setHeight(rect.height()/2); | |
346 | rect.moveCenter(m_rect.center()); |
|
348 | rect.moveCenter(m_rect.center()); | |
347 | zoomInToRect(rect); |
|
349 | zoomInToRect(rect); | |
348 | } |
|
350 | } | |
349 | } |
|
351 | } | |
350 |
|
352 | |||
351 | void QChart::zoomOut() |
|
353 | void QChart::zoomOut() | |
352 | { |
|
354 | { | |
353 | if (m_plotDataIndex > 0) { |
|
355 | if (m_plotDataIndex > 0) { | |
354 | m_plotDataIndex--; |
|
356 | m_plotDataIndex--; | |
355 | foreach (ChartObjectInterface* item, m_chartObjectInterfaces) |
|
357 | foreach (ChartObjectInterface* item, m_chartObjectInterfaces) | |
356 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
358 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
357 | update(); |
|
359 | update(); | |
358 | } |
|
360 | } | |
359 | } |
|
361 | } | |
360 |
|
362 | |||
361 | void QChart::zoomReset() |
|
363 | void QChart::zoomReset() | |
362 | { |
|
364 | { | |
363 | if (m_plotDataIndex > 0) { |
|
365 | if (m_plotDataIndex > 0) { | |
364 | m_plotDataIndex = 0; |
|
366 | m_plotDataIndex = 0; | |
365 | foreach (ChartObjectInterface* item, m_chartObjectInterfaces) |
|
367 | foreach (ChartObjectInterface* item, m_chartObjectInterfaces) | |
366 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
368 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
367 | update(); |
|
369 | update(); | |
368 | } |
|
370 | } | |
369 | } |
|
371 | } | |
370 |
|
372 | |||
371 | void QChart::setAxisX(const QChartAxis& axis) |
|
373 | void QChart::setAxisX(const QChartAxis& axis) | |
372 | { |
|
374 | { | |
373 | setAxis(m_axisXItem,axis); |
|
375 | setAxis(m_axisXItem,axis); | |
374 | } |
|
376 | } | |
375 | void QChart::setAxisY(const QChartAxis& axis) |
|
377 | void QChart::setAxisY(const QChartAxis& axis) | |
376 | { |
|
378 | { | |
377 | setAxis(m_axisYItem.at(0),axis); |
|
379 | setAxis(m_axisYItem.at(0),axis); | |
378 | } |
|
380 | } | |
379 |
|
381 | |||
380 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
382 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
381 | { |
|
383 | { | |
382 | //TODO not implemented |
|
384 | //TODO not implemented | |
383 | } |
|
385 | } | |
384 |
|
386 | |||
385 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
387 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
386 | { |
|
388 | { | |
387 | item->setVisible(axis.isAxisVisible()); |
|
389 | item->setVisible(axis.isAxisVisible()); | |
388 | } |
|
390 | } | |
389 |
|
391 | |||
390 | #include "moc_qchart.cpp" |
|
392 | #include "moc_qchart.cpp" | |
391 |
|
393 | |||
392 | QTCOMMERCIALCHART_END_NAMESPACE |
|
394 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now