@@ -1,60 +1,53 | |||
|
1 | 1 | #include "percentbargroup.h" |
|
2 | ||
|
3 | #include "stackedbargroup.h" | |
|
4 | 2 | #include "bar.h" |
|
5 | 3 | #include <QDebug> |
|
6 | 4 | |
|
7 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 6 | |
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
7 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : | |
|
8 | ChartItem(parent) | |
|
9 | ,mSeries(series) | |
|
10 | ,mLayoutSet(false) | |
|
11 | ,mLayoutDirty(true) | |
|
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
|
15 | 13 | { |
|
16 | 14 | dataChanged(); |
|
17 | 15 | } |
|
18 | 16 | |
|
19 | void StackedBarGroup::setSize(const QSize& size) | |
|
17 | ||
|
18 | void PercentBarGroup::setSize(const QSize& size) | |
|
20 | 19 | { |
|
21 |
qDebug() << " |
|
|
20 | // qDebug() << "PercentBarGroup::setSize"; | |
|
22 | 21 | mWidth = size.width(); |
|
23 | 22 | mHeight = size.height(); |
|
24 | 23 | layoutChanged(); |
|
25 | 24 | mLayoutSet = true; |
|
26 | 25 | } |
|
27 | 26 | |
|
28 |
void |
|
|
27 | void PercentBarGroup::setPlotDomain(const PlotDomain& data) | |
|
29 | 28 | { |
|
30 |
qDebug() << " |
|
|
29 | qDebug() << "PercentBarGroup::setPlotDomain"; | |
|
31 | 30 | // TODO: |
|
32 | 31 | } |
|
33 | 32 | |
|
34 | void StackedBarGroup::setTheme(ChartTheme *theme) | |
|
35 | { | |
|
36 | qDebug() << "StackedBarGroup::setTheme"; | |
|
37 | // TODO: | |
|
38 | } | |
|
39 | ||
|
40 | void StackedBarGroup::setBarWidth( int w ) | |
|
33 | void PercentBarGroup::setBarWidth( int w ) | |
|
41 | 34 | { |
|
42 | 35 | mBarDefaultWidth = w; |
|
43 | 36 | } |
|
44 | 37 | |
|
45 |
int |
|
|
38 | int PercentBarGroup::addColor( QColor color ) | |
|
46 | 39 | { |
|
47 | 40 | int colorIndex = mColors.count(); |
|
48 | 41 | mColors.append(color); |
|
49 | 42 | return colorIndex; |
|
50 | 43 | } |
|
51 | 44 | |
|
52 |
void |
|
|
45 | void PercentBarGroup::resetColors() | |
|
53 | 46 | { |
|
54 | 47 | mColors.clear(); |
|
55 | 48 | } |
|
56 | 49 | |
|
57 |
void |
|
|
50 | void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
58 | 51 | { |
|
59 | 52 | if (!mLayoutSet) { |
|
60 | 53 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
@@ -68,13 +61,13 void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||
|
68 | 61 | } |
|
69 | 62 | } |
|
70 | 63 | |
|
71 |
QRectF |
|
|
64 | QRectF PercentBarGroup::boundingRect() const | |
|
72 | 65 | { |
|
73 | 66 | return QRectF(0,0,mWidth,mHeight); |
|
74 | 67 | } |
|
75 | 68 | |
|
76 | 69 | |
|
77 |
void |
|
|
70 | void PercentBarGroup::dataChanged() | |
|
78 | 71 | { |
|
79 | 72 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
80 | 73 | |
@@ -98,7 +91,7 void StackedBarGroup::dataChanged() | |||
|
98 | 91 | mLayoutDirty = true; |
|
99 | 92 | } |
|
100 | 93 | |
|
101 |
void |
|
|
94 | void PercentBarGroup::layoutChanged() | |
|
102 | 95 | { |
|
103 | 96 | // Scale bars to new layout |
|
104 | 97 | // Layout for bars: |
@@ -109,10 +102,6 void StackedBarGroup::layoutChanged() | |||
|
109 | 102 | |
|
110 | 103 | // TODO: better way to auto-layout |
|
111 | 104 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
112 | qreal maxSum = mSeries.maxColumnSum(); | |
|
113 | qreal h = mHeight; | |
|
114 | qreal scale = (h / maxSum); | |
|
115 | ||
|
116 | 105 | int count = mSeries.countColumns(); |
|
117 | 106 | int itemIndex(0); |
|
118 | 107 | qreal tW = mWidth; |
@@ -121,6 +110,9 void StackedBarGroup::layoutChanged() | |||
|
121 | 110 | qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); |
|
122 | 111 | |
|
123 | 112 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
113 | qreal colSum = mSeries.columnSum(column); | |
|
114 | qreal h = mHeight; | |
|
115 | qreal scale = (h / colSum); | |
|
124 | 116 | qreal yPos = h; |
|
125 | 117 | for (int row=0; row < mSeries.countRows(); row++) { |
|
126 | 118 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
@@ -1,58 +1,53 | |||
|
1 |
#include " |
|
|
1 | #include "stackedbargroup.h" | |
|
2 | 2 | #include "bar.h" |
|
3 | 3 | #include <QDebug> |
|
4 | 4 | |
|
5 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 6 | |
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
7 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : | |
|
8 | ChartItem(parent) | |
|
9 | ,mSeries(series) | |
|
10 | ,mLayoutSet(false) | |
|
11 | ,mLayoutDirty(true) | |
|
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
|
13 | 13 | { |
|
14 | 14 | dataChanged(); |
|
15 | 15 | } |
|
16 | 16 | |
|
17 | void PercentBarGroup::setSize(const QSize& size) | |
|
17 | ||
|
18 | void StackedBarGroup::setSize(const QSize& size) | |
|
18 | 19 | { |
|
19 |
qDebug() << " |
|
|
20 | // qDebug() << "StackedBarGroup::setSize"; | |
|
20 | 21 | mWidth = size.width(); |
|
21 | 22 | mHeight = size.height(); |
|
22 | 23 | layoutChanged(); |
|
23 | 24 | mLayoutSet = true; |
|
24 | 25 | } |
|
25 | 26 | |
|
26 |
void |
|
|
27 | { | |
|
28 | qDebug() << "PercentBarGroup::setPlotDomain"; | |
|
29 | // TODO: | |
|
30 | } | |
|
31 | ||
|
32 | void PercentBarGroup::setTheme(ChartTheme *theme) | |
|
27 | void StackedBarGroup::setPlotDomain(const PlotDomain& data) | |
|
33 | 28 | { |
|
34 |
qDebug() << " |
|
|
29 | qDebug() << "StackedBarGroup::setPlotDomain"; | |
|
35 | 30 | // TODO: |
|
36 | 31 | } |
|
37 | 32 | |
|
38 |
void |
|
|
33 | void StackedBarGroup::setBarWidth( int w ) | |
|
39 | 34 | { |
|
40 | 35 | mBarDefaultWidth = w; |
|
41 | 36 | } |
|
42 | 37 | |
|
43 |
int |
|
|
38 | int StackedBarGroup::addColor( QColor color ) | |
|
44 | 39 | { |
|
45 | 40 | int colorIndex = mColors.count(); |
|
46 | 41 | mColors.append(color); |
|
47 | 42 | return colorIndex; |
|
48 | 43 | } |
|
49 | 44 | |
|
50 |
void |
|
|
45 | void StackedBarGroup::resetColors() | |
|
51 | 46 | { |
|
52 | 47 | mColors.clear(); |
|
53 | 48 | } |
|
54 | 49 | |
|
55 |
void |
|
|
50 | void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
56 | 51 | { |
|
57 | 52 | if (!mLayoutSet) { |
|
58 | 53 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
@@ -66,13 +61,13 void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||
|
66 | 61 | } |
|
67 | 62 | } |
|
68 | 63 | |
|
69 |
QRectF |
|
|
64 | QRectF StackedBarGroup::boundingRect() const | |
|
70 | 65 | { |
|
71 | 66 | return QRectF(0,0,mWidth,mHeight); |
|
72 | 67 | } |
|
73 | 68 | |
|
74 | 69 | |
|
75 |
void |
|
|
70 | void StackedBarGroup::dataChanged() | |
|
76 | 71 | { |
|
77 | 72 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
78 | 73 | |
@@ -96,7 +91,7 void PercentBarGroup::dataChanged() | |||
|
96 | 91 | mLayoutDirty = true; |
|
97 | 92 | } |
|
98 | 93 | |
|
99 |
void |
|
|
94 | void StackedBarGroup::layoutChanged() | |
|
100 | 95 | { |
|
101 | 96 | // Scale bars to new layout |
|
102 | 97 | // Layout for bars: |
@@ -107,6 +102,10 void PercentBarGroup::layoutChanged() | |||
|
107 | 102 | |
|
108 | 103 | // TODO: better way to auto-layout |
|
109 | 104 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
105 | qreal maxSum = mSeries.maxColumnSum(); | |
|
106 | qreal h = mHeight; | |
|
107 | qreal scale = (h / maxSum); | |
|
108 | ||
|
110 | 109 | int count = mSeries.countColumns(); |
|
111 | 110 | int itemIndex(0); |
|
112 | 111 | qreal tW = mWidth; |
@@ -115,9 +114,6 void PercentBarGroup::layoutChanged() | |||
|
115 | 114 | qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); |
|
116 | 115 | |
|
117 | 116 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
118 | qreal colSum = mSeries.columnSum(column); | |
|
119 | qreal h = mHeight; | |
|
120 | qreal scale = (h / colSum); | |
|
121 | 117 | qreal yPos = h; |
|
122 | 118 | for (int row=0; row < mSeries.countRows(); row++) { |
|
123 | 119 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
@@ -100,6 +100,14 void QChart::addSeries(QChartSeries* series) | |||
|
100 | 100 | |
|
101 | 101 | m_chartObjectInterfaces << barGroup; |
|
102 | 102 | childItems().append(barGroup); |
|
103 | ||
|
104 | m_plotDataIndex = 0 ; | |
|
105 | m_plotDomainList.resize(1); | |
|
106 | ||
|
107 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
|
108 | foreach(ChartItem* i ,m_chartItems) | |
|
109 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
|
110 | ||
|
103 | 111 | break; |
|
104 | 112 | } |
|
105 | 113 | case QChartSeries::SeriesTypeStackedBar: { |
@@ -117,6 +125,13 void QChart::addSeries(QChartSeries* series) | |||
|
117 | 125 | |
|
118 | 126 | m_chartObjectInterfaces << stackedBarGroup; |
|
119 | 127 | childItems().append(stackedBarGroup); |
|
128 | m_plotDataIndex = 0 ; | |
|
129 | m_plotDomainList.resize(1); | |
|
130 | ||
|
131 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
|
132 | foreach(ChartItem* i ,m_chartItems) | |
|
133 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
|
134 | ||
|
120 | 135 | break; |
|
121 | 136 | } |
|
122 | 137 | case QChartSeries::SeriesTypePercentBar: { |
@@ -134,6 +149,13 void QChart::addSeries(QChartSeries* series) | |||
|
134 | 149 | |
|
135 | 150 | m_chartObjectInterfaces << percentBarGroup; |
|
136 | 151 | childItems().append(percentBarGroup); |
|
152 | m_plotDataIndex = 0 ; | |
|
153 | m_plotDomainList.resize(1); | |
|
154 | ||
|
155 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
|
156 | foreach(ChartItem* i ,m_chartItems) | |
|
157 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
|
158 | ||
|
137 | 159 | break; |
|
138 | 160 | } |
|
139 | 161 | case QChartSeries::SeriesTypeScatter: { |
General Comments 0
You need to be logged in to leave comments.
Login now