##// END OF EJS Templates
fixed naming mixup with percent and stacked groups
sauimone -
r105:37fe9cea6214
parent child
Show More
@@ -1,12 +1,10
1 #include "percentbargroup.h"
1 #include "percentbargroup.h"
2
3 #include "stackedbargroup.h"
4 #include "bar.h"
2 #include "bar.h"
5 #include <QDebug>
3 #include <QDebug>
6
4
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
6
9 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) :
7 PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) :
10 ChartItem(parent)
8 ChartItem(parent)
11 ,mSeries(series)
9 ,mSeries(series)
12 ,mLayoutSet(false)
10 ,mLayoutSet(false)
@@ -16,45 +14,40 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p
16 dataChanged();
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() << "StackedBarGroup::setSize";
20 // qDebug() << "PercentBarGroup::setSize";
22 mWidth = size.width();
21 mWidth = size.width();
23 mHeight = size.height();
22 mHeight = size.height();
24 layoutChanged();
23 layoutChanged();
25 mLayoutSet = true;
24 mLayoutSet = true;
26 }
25 }
27
26
28 void StackedBarGroup::setPlotDomain(const PlotDomain& data)
27 void PercentBarGroup::setPlotDomain(const PlotDomain& data)
29 {
28 {
30 qDebug() << "StackedBarGroup::setPlotDomain";
29 qDebug() << "PercentBarGroup::setPlotDomain";
31 // TODO:
30 // TODO:
32 }
31 }
33
32
34 void StackedBarGroup::setTheme(ChartTheme *theme)
33 void PercentBarGroup::setBarWidth( int w )
35 {
36 qDebug() << "StackedBarGroup::setTheme";
37 // TODO:
38 }
39
40 void StackedBarGroup::setBarWidth( int w )
41 {
34 {
42 mBarDefaultWidth = w;
35 mBarDefaultWidth = w;
43 }
36 }
44
37
45 int StackedBarGroup::addColor( QColor color )
38 int PercentBarGroup::addColor( QColor color )
46 {
39 {
47 int colorIndex = mColors.count();
40 int colorIndex = mColors.count();
48 mColors.append(color);
41 mColors.append(color);
49 return colorIndex;
42 return colorIndex;
50 }
43 }
51
44
52 void StackedBarGroup::resetColors()
45 void PercentBarGroup::resetColors()
53 {
46 {
54 mColors.clear();
47 mColors.clear();
55 }
48 }
56
49
57 void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
50 void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
58 {
51 {
59 if (!mLayoutSet) {
52 if (!mLayoutSet) {
60 qDebug() << "QBarChart::paint called without layout set. Aborting.";
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 StackedBarGroup::boundingRect() const
64 QRectF PercentBarGroup::boundingRect() const
72 {
65 {
73 return QRectF(0,0,mWidth,mHeight);
66 return QRectF(0,0,mWidth,mHeight);
74 }
67 }
75
68
76
69
77 void StackedBarGroup::dataChanged()
70 void PercentBarGroup::dataChanged()
78 {
71 {
79 qDebug() << "QBarChart::dataChanged mSeries";
72 qDebug() << "QBarChart::dataChanged mSeries";
80
73
@@ -98,7 +91,7 void StackedBarGroup::dataChanged()
98 mLayoutDirty = true;
91 mLayoutDirty = true;
99 }
92 }
100
93
101 void StackedBarGroup::layoutChanged()
94 void PercentBarGroup::layoutChanged()
102 {
95 {
103 // Scale bars to new layout
96 // Scale bars to new layout
104 // Layout for bars:
97 // Layout for bars:
@@ -109,10 +102,6 void StackedBarGroup::layoutChanged()
109
102
110 // TODO: better way to auto-layout
103 // TODO: better way to auto-layout
111 // Use reals for accurancy (we might get some compiler warnings... :)
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 int count = mSeries.countColumns();
105 int count = mSeries.countColumns();
117 int itemIndex(0);
106 int itemIndex(0);
118 qreal tW = mWidth;
107 qreal tW = mWidth;
@@ -121,6 +110,9 void StackedBarGroup::layoutChanged()
121 qreal xPos = ((tW/tC) + mBarDefaultWidth / 2);
110 qreal xPos = ((tW/tC) + mBarDefaultWidth / 2);
122
111
123 for (int column = 0; column < mSeries.countColumns(); column++) {
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 qreal yPos = h;
116 qreal yPos = h;
125 for (int row=0; row < mSeries.countRows(); row++) {
117 for (int row=0; row < mSeries.countRows(); row++) {
126 qreal barHeight = mSeries.valueAt(row, column) * scale;
118 qreal barHeight = mSeries.valueAt(row, column) * scale;
@@ -1,10 +1,10
1 #include "percentbargroup.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 PercentBarGroup::PercentBarGroup(PercentBarChartSeries& 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)
@@ -14,45 +14,40 PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *p
14 dataChanged();
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() << "PercentBarGroup::setSize";
20 // qDebug() << "StackedBarGroup::setSize";
20 mWidth = size.width();
21 mWidth = size.width();
21 mHeight = size.height();
22 mHeight = size.height();
22 layoutChanged();
23 layoutChanged();
23 mLayoutSet = true;
24 mLayoutSet = true;
24 }
25 }
25
26
26 void PercentBarGroup::setPlotDomain(const PlotDomain& data)
27 void StackedBarGroup::setPlotDomain(const PlotDomain& data)
27 {
28 qDebug() << "PercentBarGroup::setPlotDomain";
29 // TODO:
30 }
31
32 void PercentBarGroup::setTheme(ChartTheme *theme)
33 {
28 {
34 qDebug() << "PercentBarGroup::setTheme";
29 qDebug() << "StackedBarGroup::setPlotDomain";
35 // TODO:
30 // TODO:
36 }
31 }
37
32
38 void PercentBarGroup::setBarWidth( int w )
33 void StackedBarGroup::setBarWidth( int w )
39 {
34 {
40 mBarDefaultWidth = w;
35 mBarDefaultWidth = w;
41 }
36 }
42
37
43 int PercentBarGroup::addColor( QColor color )
38 int StackedBarGroup::addColor( QColor color )
44 {
39 {
45 int colorIndex = mColors.count();
40 int colorIndex = mColors.count();
46 mColors.append(color);
41 mColors.append(color);
47 return colorIndex;
42 return colorIndex;
48 }
43 }
49
44
50 void PercentBarGroup::resetColors()
45 void StackedBarGroup::resetColors()
51 {
46 {
52 mColors.clear();
47 mColors.clear();
53 }
48 }
54
49
55 void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
50 void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
56 {
51 {
57 if (!mLayoutSet) {
52 if (!mLayoutSet) {
58 qDebug() << "QBarChart::paint called without layout set. Aborting.";
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 PercentBarGroup::boundingRect() const
64 QRectF StackedBarGroup::boundingRect() const
70 {
65 {
71 return QRectF(0,0,mWidth,mHeight);
66 return QRectF(0,0,mWidth,mHeight);
72 }
67 }
73
68
74
69
75 void PercentBarGroup::dataChanged()
70 void StackedBarGroup::dataChanged()
76 {
71 {
77 qDebug() << "QBarChart::dataChanged mSeries";
72 qDebug() << "QBarChart::dataChanged mSeries";
78
73
@@ -96,7 +91,7 void PercentBarGroup::dataChanged()
96 mLayoutDirty = true;
91 mLayoutDirty = true;
97 }
92 }
98
93
99 void PercentBarGroup::layoutChanged()
94 void StackedBarGroup::layoutChanged()
100 {
95 {
101 // Scale bars to new layout
96 // Scale bars to new layout
102 // Layout for bars:
97 // Layout for bars:
@@ -107,6 +102,10 void PercentBarGroup::layoutChanged()
107
102
108 // TODO: better way to auto-layout
103 // TODO: better way to auto-layout
109 // Use reals for accurancy (we might get some compiler warnings... :)
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 int count = mSeries.countColumns();
109 int count = mSeries.countColumns();
111 int itemIndex(0);
110 int itemIndex(0);
112 qreal tW = mWidth;
111 qreal tW = mWidth;
@@ -115,9 +114,6 void PercentBarGroup::layoutChanged()
115 qreal xPos = ((tW/tC) + mBarDefaultWidth / 2);
114 qreal xPos = ((tW/tC) + mBarDefaultWidth / 2);
116
115
117 for (int column = 0; column < mSeries.countColumns(); column++) {
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 qreal yPos = h;
117 qreal yPos = h;
122 for (int row=0; row < mSeries.countRows(); row++) {
118 for (int row=0; row < mSeries.countRows(); row++) {
123 qreal barHeight = mSeries.valueAt(row, column) * scale;
119 qreal barHeight = mSeries.valueAt(row, column) * scale;
@@ -100,6 +100,14 void QChart::addSeries(QChartSeries* series)
100
100
101 m_chartObjectInterfaces << barGroup;
101 m_chartObjectInterfaces << barGroup;
102 childItems().append(barGroup);
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 break;
111 break;
104 }
112 }
105 case QChartSeries::SeriesTypeStackedBar: {
113 case QChartSeries::SeriesTypeStackedBar: {
@@ -117,6 +125,13 void QChart::addSeries(QChartSeries* series)
117
125
118 m_chartObjectInterfaces << stackedBarGroup;
126 m_chartObjectInterfaces << stackedBarGroup;
119 childItems().append(stackedBarGroup);
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 break;
135 break;
121 }
136 }
122 case QChartSeries::SeriesTypePercentBar: {
137 case QChartSeries::SeriesTypePercentBar: {
@@ -134,6 +149,13 void QChart::addSeries(QChartSeries* series)
134
149
135 m_chartObjectInterfaces << percentBarGroup;
150 m_chartObjectInterfaces << percentBarGroup;
136 childItems().append(percentBarGroup);
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 break;
159 break;
138 }
160 }
139 case QChartSeries::SeriesTypeScatter: {
161 case QChartSeries::SeriesTypeScatter: {
General Comments 0
You need to be logged in to leave comments. Login now