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