##// END OF EJS Templates
Refactoring continued: restored ChartItem class
Tero Ahola -
r104:192e41096b68
parent child
Show More
@@ -0,0 +1,22
1 #ifndef CHARTITEM_H_
2 #define CHARTITEM_H_
3
4 #include "plotdomain_p.h"
5 #include "chartobjectinterface_p.h"
6 #include <QGraphicsItem>
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 class ChartItem : public QGraphicsItem, public ChartObjectInterface
11 {
12 enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM};
13 public:
14 ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){};
15 virtual ~ChartItem(){};
16 // TODO: this is a hack; integration ongoing:
17 QGraphicsItem *graphicsItem() { return this; }
18 };
19
20 QTCOMMERCIALCHART_END_NAMESPACE
21
22 #endif /* CHARTITEM_H_ */
@@ -7,7 +7,7
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) :
9 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) :
10 QGraphicsItem(parent),
10 ChartItem(parent),
11 m_ticks(4),
11 m_ticks(4),
12 m_type(type)
12 m_type(type)
13 {
13 {
@@ -43,12 +43,7 void AxisItem::setPlotDomain(const PlotDomain& plotDomain)
43 createItems();
43 createItems();
44 }
44 }
45
45
46 void AxisItem::setPos(const QPointF & pos)
46 void AxisItem::setSize(const QSize &size)
47 {
48 QGraphicsItem::setPos(pos);
49 }
50
51 void AxisItem::resize(const QSize &size)
52 {
47 {
53 m_rect = QRectF(QPoint(0,0),size);
48 m_rect = QRectF(QPoint(0,0),size);
54 createItems();
49 createItems();
@@ -2,12 +2,12
2 #define AXISITEM_H_
2 #define AXISITEM_H_
3
3
4 #include "plotdomain_p.h"
4 #include "plotdomain_p.h"
5 #include "chartitemcontrol.h"
5 #include "chartitem_p.h"
6 #include <QGraphicsItem>
6 #include <QGraphicsItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class AxisItem: public QGraphicsItem, public ChartItemControl
10 class AxisItem : public ChartItem
11 {
11 {
12 public:
12 public:
13 enum AxisType{X_AXIS,Y_AXIS};
13 enum AxisType{X_AXIS,Y_AXIS};
@@ -19,9 +19,8 public:
19 QRectF boundingRect() const;
19 QRectF boundingRect() const;
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
21
21
22 public: // from ChartItemControl
22 public: // from ChartObjectInterface
23 void setPos (const QPointF & pos);
23 void setSize(const QSize &size);
24 void resize(const QSize &size);
25 void setTheme(ChartTheme *theme);
24 void setTheme(ChartTheme *theme);
26 void setPlotDomain(const PlotDomain& data);
25 void setPlotDomain(const PlotDomain& data);
27
26
@@ -5,16 +5,11
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 Bar::Bar(QGraphicsItem *parent)
7 Bar::Bar(QGraphicsItem *parent)
8 : QGraphicsItem(parent)
8 : ChartItem(parent)
9 {
9 {
10 }
10 }
11
11
12 void Bar::setPos(const QPointF & pos)
12 void Bar::setSize(const QSize& size)
13 {
14 QGraphicsItem::setPos(pos);
15 }
16
17 void Bar::resize(const QSize& size)
18 {
13 {
19 mWidth = size.width();
14 mWidth = size.width();
20 mHeight = size.height();
15 mHeight = size.height();
@@ -1,21 +1,20
1 #ifndef BAR_H
1 #ifndef BAR_H
2 #define BAR_H
2 #define BAR_H
3
3
4 #include "chartitemcontrol.h"
4 #include "chartitem_p.h"
5 #include "qchartglobal.h"
5 #include "qchartglobal.h"
6 #include <QGraphicsItem>
6 #include <QGraphicsItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 // Single bar item of chart
10 // Single bar item of chart
11 class Bar : public QGraphicsItem, public ChartItemControl
11 class Bar : public ChartItem
12 {
12 {
13 public:
13 public:
14 Bar(QGraphicsItem *parent=0);
14 Bar(QGraphicsItem *parent=0);
15
15
16 public: // from ChartItemControl
16 public: // from ChartItemControl
17 void setPos (const QPointF & pos);
17 void setSize(const QSize &size);
18 void resize(const QSize &size);
19 void setTheme(ChartTheme *theme);
18 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
19 void setPlotDomain(const PlotDomain& data);
21
20
@@ -5,7 +5,7
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 QGraphicsItem(parent)
8 ChartItem(parent)
9 ,mSeries(series)
9 ,mSeries(series)
10 ,mLayoutSet(false)
10 ,mLayoutSet(false)
11 ,mLayoutDirty(true)
11 ,mLayoutDirty(true)
@@ -14,12 +14,7 BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) :
14 dataChanged();
14 dataChanged();
15 }
15 }
16
16
17 void BarGroup::setPos(const QPointF & pos)
17 void BarGroup::setSize(const QSize& size)
18 {
19 QGraphicsItem::setPos(pos);
20 }
21
22 void BarGroup::resize(const QSize& size)
23 {
18 {
24 qDebug() << "BarGroup::setSize";
19 qDebug() << "BarGroup::setSize";
25 mWidth = size.width();
20 mWidth = size.width();
@@ -1,21 +1,20
1 #ifndef QBARGROUP_H
1 #ifndef QBARGROUP_H
2 #define QBARGROUP_H
2 #define QBARGROUP_H
3
3
4 #include "chartitemcontrol.h"
4 #include "chartitem_p.h"
5 #include "bar.h"
5 #include "bar.h"
6 #include "barchartseries.h"
6 #include "barchartseries.h"
7 #include <QGraphicsItem>
7 #include <QGraphicsItem>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class BarGroup : public QGraphicsItem, public ChartItemControl
11 class BarGroup : public ChartItem
12 {
12 {
13 public:
13 public:
14 explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0);
14 explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0);
15
15
16 public: // from ChartItemControl
16 public: // from ChartObjectInterface
17 void setPos (const QPointF & pos);
17 void setSize(const QSize &size);
18 void resize(const QSize &size);
19 void setTheme(ChartTheme *theme);
18 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
19 void setPlotDomain(const PlotDomain& data);
21
20
@@ -7,7 +7,7
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) :
9 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) :
10 QGraphicsItem(parent)
10 ChartItem(parent)
11 ,mSeries(series)
11 ,mSeries(series)
12 ,mLayoutSet(false)
12 ,mLayoutSet(false)
13 ,mLayoutDirty(true)
13 ,mLayoutDirty(true)
@@ -16,16 +16,9 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p
16 dataChanged();
16 dataChanged();
17 }
17 }
18
18
19
19 void StackedBarGroup::setSize(const QSize& size)
20 void StackedBarGroup::setPos(const QPointF & pos)
21 {
22 qDebug() << "StackedBarGroup::setPos";
23 // TODO:
24 }
25
26 void StackedBarGroup::resize(const QSize& size)
27 {
20 {
28 qDebug() << "StackedBarGroup::resize";
21 qDebug() << "StackedBarGroup::setSize";
29 mWidth = size.width();
22 mWidth = size.width();
30 mHeight = size.height();
23 mHeight = size.height();
31 layoutChanged();
24 layoutChanged();
@@ -1,21 +1,20
1 #ifndef PERCENTBARGROUP_H
1 #ifndef PERCENTBARGROUP_H
2 #define PERCENTBARGROUP_H
2 #define PERCENTBARGROUP_H
3
3
4 #include "chartitemcontrol.h"
4 #include "chartitem_p.h"
5 #include "bar.h"
5 #include "bar.h"
6 #include "percentbarchartseries.h"
6 #include "percentbarchartseries.h"
7 #include <QGraphicsItem>
7 #include <QGraphicsItem>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class PercentBarGroup : public QGraphicsItem, public ChartItemControl
11 class PercentBarGroup : public ChartItem
12 {
12 {
13 public:
13 public:
14 PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0);
14 PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0);
15
15
16 public: // From ChartItemControl
16 public: // From ChartObjectInterface
17 void setPos(const QPointF & pos);
17 void setSize(const QSize &size);
18 void resize(const QSize &size);
19 void setTheme(ChartTheme *theme);
18 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
19 void setPlotDomain(const PlotDomain& data);
21
20
@@ -5,7 +5,7
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 QGraphicsItem(parent)
8 ChartItem(parent)
9 ,mSeries(series)
9 ,mSeries(series)
10 ,mLayoutSet(false)
10 ,mLayoutSet(false)
11 ,mLayoutDirty(true)
11 ,mLayoutDirty(true)
@@ -14,15 +14,9 PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *p
14 dataChanged();
14 dataChanged();
15 }
15 }
16
16
17 void PercentBarGroup::setPos(const QPointF & pos)
17 void PercentBarGroup::setSize(const QSize& size)
18 {
18 {
19 qDebug() << "PercentBarGroup::setPos";
19 qDebug() << "PercentBarGroup::setSize";
20 // TODO:
21 }
22
23 void PercentBarGroup::resize(const QSize& size)
24 {
25 qDebug() << "PercentBarGroup::resize";
26 mWidth = size.width();
20 mWidth = size.width();
27 mHeight = size.height();
21 mHeight = size.height();
28 layoutChanged();
22 layoutChanged();
@@ -1,21 +1,20
1 #ifndef STACKEDBARGROUP_H
1 #ifndef STACKEDBARGROUP_H
2 #define STACKEDBARGROUP_H
2 #define STACKEDBARGROUP_H
3
3
4 #include "chartitemcontrol.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 class StackedBarGroup : public QGraphicsItem, public ChartItemControl
11 class StackedBarGroup : public ChartItem
12 {
12 {
13 public:
13 public:
14 StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0);
14 StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0);
15
15
16 public: // From ChartItemControl
16 public: // From ChartObjectInterface
17 void setPos(const QPointF & pos);
17 void setSize(const QSize &size);
18 void resize(const QSize &size);
19 void setTheme(ChartTheme *theme);
18 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
19 void setPlotDomain(const PlotDomain& data);
21
20
@@ -1,24 +1,30
1 #ifndef CHARTITEMCONTROL_H
1 #ifndef CHART_OBJECT_INTERFACE_H
2 #define CHARTITEMCONTROL_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;
9
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
11
10 class ChartTheme;
12 class ChartTheme;
11 class PlotDomain;
13 class PlotDomain;
12
14
13 class ChartItemControl
15 /*!
16 * Internal abstract interface for passing updates on chart related properties.
17 */
18 class ChartObjectInterface
14 {
19 {
15 public:
20 public:
16 virtual void setPos (const QPointF & pos) = 0;
21 virtual void setSize(const QSize &size) = 0;
17 virtual void resize(const QSize &size) = 0;
18 virtual void setTheme(ChartTheme *theme) = 0;
22 virtual void setTheme(ChartTheme *theme) = 0;
19 virtual void setPlotDomain(const PlotDomain& data) = 0;
23 virtual void setPlotDomain(const PlotDomain& data) = 0;
24 // TODO: this is a hack; integration ongoing:
25 virtual QGraphicsItem *graphicsItem() { return 0; }
20 };
26 };
21
27
22 QTCOMMERCIALCHART_END_NAMESPACE
28 QTCOMMERCIALCHART_END_NAMESPACE
23
29
24 #endif // CHARTITEMCONTROL_H
30 #endif // CHART_OBJECT_INTERFACE_H
@@ -13,7 +13,7
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 "chartitemcontrol.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"
@@ -37,8 +37,8 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
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_chartItemControls << m_axisXItem;
40 m_chartObjectInterfaces << m_axisXItem;
41 m_chartItemControls << m_axisYItem.at(0);
41 m_chartObjectInterfaces << m_axisYItem.at(0);
42 }
42 }
43
43
44 QChart::~QChart(){}
44 QChart::~QChart(){}
@@ -76,11 +76,11 void QChart::addSeries(QChartSeries* series)
76
76
77 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
77 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
78
78
79 // TODO: combine ChartItemControl and ChartItem apis
79 // TODO: combine ChartObjectInterface and ChartItem apis
80 m_chartItemControls << item;
80 m_chartObjectInterfaces << item;
81 item->setTheme(m_chartTheme);
81 item->setTheme(m_chartTheme);
82
82
83 foreach(ChartItemControl* i, m_chartItemControls)
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;
@@ -98,7 +98,7 void QChart::addSeries(QChartSeries* series)
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_chartItemControls << barGroup;
101 m_chartObjectInterfaces << barGroup;
102 childItems().append(barGroup);
102 childItems().append(barGroup);
103 break;
103 break;
104 }
104 }
@@ -115,7 +115,7 void QChart::addSeries(QChartSeries* series)
115 stackedBarGroup->addColor(QColor(0,0,255,128));
115 stackedBarGroup->addColor(QColor(0,0,255,128));
116 stackedBarGroup->addColor(QColor(255,128,0,128));
116 stackedBarGroup->addColor(QColor(255,128,0,128));
117
117
118 m_chartItemControls << stackedBarGroup;
118 m_chartObjectInterfaces << stackedBarGroup;
119 childItems().append(stackedBarGroup);
119 childItems().append(stackedBarGroup);
120 break;
120 break;
121 }
121 }
@@ -132,7 +132,7 void QChart::addSeries(QChartSeries* series)
132 percentBarGroup->addColor(QColor(0,0,255,128));
132 percentBarGroup->addColor(QColor(0,0,255,128));
133 percentBarGroup->addColor(QColor(255,128,0,128));
133 percentBarGroup->addColor(QColor(255,128,0,128));
134
134
135 m_chartItemControls << percentBarGroup;
135 m_chartObjectInterfaces << percentBarGroup;
136 childItems().append(percentBarGroup);
136 childItems().append(percentBarGroup);
137 break;
137 break;
138 }
138 }
@@ -140,7 +140,7 void QChart::addSeries(QChartSeries* series)
140 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
140 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
141 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
141 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
142 scatterSeries->d->setParentItem(this);
142 scatterSeries->d->setParentItem(this);
143 m_chartItemControls << scatterSeries->d;
143 m_chartObjectInterfaces << scatterSeries->d;
144 //TODO:? scatterSeries->d->m_themeIndex = m_chartSeries.count() - 1;
144 //TODO:? scatterSeries->d->m_themeIndex = m_chartSeries.count() - 1;
145 break;
145 break;
146 }
146 }
@@ -151,7 +151,7 void QChart::addSeries(QChartSeries* series)
151 // pieSeries->setSliceColor(i, nextColor());
151 // pieSeries->setSliceColor(i, nextColor());
152 // }
152 // }
153 pieSeries->d->setTheme(m_chartTheme);
153 pieSeries->d->setTheme(m_chartTheme);
154 m_chartItemControls << pieSeries->d;
154 m_chartObjectInterfaces << pieSeries->d;
155
155
156 // Set pre-defined colors in case the series has no colors defined
156 // Set pre-defined colors in case the series has no colors defined
157 // TODO: how to define the color for all the slices of a pie?
157 // TODO: how to define the color for all the slices of a pie?
@@ -206,11 +206,10 void QChart::setSize(const QSize& size)
206 m_rect = QRect(QPoint(0,0),size);
206 m_rect = QRect(QPoint(0,0),size);
207 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
207 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
208
208
209 //recaculate title
209 // recalculate title position
210 if(m_titleItem){
210 if (m_titleItem) {
211 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
211 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
212 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
212 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
213
214 }
213 }
215
214
216 //recalculate background gradient
215 //recalculate background gradient
@@ -223,9 +222,12 void QChart::setSize(const QSize& size)
223 m_backgroundItem->setBrush(m_backgroundGradient);
222 m_backgroundItem->setBrush(m_backgroundGradient);
224 }
223 }
225
224
226 foreach (ChartItemControl *ctrl, m_chartItemControls) {
225 // resize and reposition childs
227 ctrl->setPos(rect.topLeft());
226 foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces) {
228 ctrl->resize(rect.size());
227 QGraphicsItem *item = ctrl->graphicsItem();
228 if (item)
229 item->setPos(rect.topLeft());
230 ctrl->setSize(rect.size());
229 }
231 }
230
232
231 update();
233 update();
@@ -279,7 +281,7 void QChart::setTheme(QChart::ChartThemeId theme)
279 setBackground(m_chartTheme->d->m_gradientStartColor,
281 setBackground(m_chartTheme->d->m_gradientStartColor,
280 m_chartTheme->d->m_gradientEndColor,
282 m_chartTheme->d->m_gradientEndColor,
281 m_bacgroundOrinetation);
283 m_bacgroundOrinetation);
282 foreach (ChartItemControl *ctrl, m_chartItemControls)
284 foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces)
283 ctrl->setTheme(m_chartTheme);
285 ctrl->setTheme(m_chartTheme);
284 update();
286 update();
285 }
287 }
@@ -303,7 +305,7 void QChart::zoomInToRect(const QRect& rectangle)
303 m_plotDomainList<<domain;
305 m_plotDomainList<<domain;
304 m_plotDataIndex++;
306 m_plotDataIndex++;
305
307
306 foreach (ChartItemControl* ctrl, m_chartItemControls)
308 foreach (ChartObjectInterface* ctrl, m_chartObjectInterfaces)
307 ctrl->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
309 ctrl->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
308 update();
310 update();
309 }
311 }
@@ -312,7 +314,7 void QChart::zoomIn()
312 {
314 {
313 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
315 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
314 m_plotDataIndex++;
316 m_plotDataIndex++;
315 foreach (ChartItemControl* item, m_chartItemControls)
317 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
316 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
318 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
317 update();
319 update();
318 } else {
320 } else {
@@ -328,7 +330,7 void QChart::zoomOut()
328 {
330 {
329 if (m_plotDataIndex > 0) {
331 if (m_plotDataIndex > 0) {
330 m_plotDataIndex--;
332 m_plotDataIndex--;
331 foreach (ChartItemControl* item, m_chartItemControls)
333 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
332 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
334 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
333 update();
335 update();
334 }
336 }
@@ -338,7 +340,7 void QChart::zoomReset()
338 {
340 {
339 if (m_plotDataIndex > 0) {
341 if (m_plotDataIndex > 0) {
340 m_plotDataIndex = 0;
342 m_plotDataIndex = 0;
341 foreach (ChartItemControl* item, m_chartItemControls)
343 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
342 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
344 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
343 update();
345 update();
344 }
346 }
@@ -15,7 +15,7 class PlotDomain;
15 class BarGroup;
15 class BarGroup;
16 class QChartAxis;
16 class QChartAxis;
17 class ChartTheme;
17 class ChartTheme;
18 class ChartItemControl;
18 class ChartObjectInterface;
19
19
20 // TODO: We don't need to have QChart tied to QGraphicsItem:
20 // TODO: We don't need to have QChart tied to QGraphicsItem:
21 //class QTCOMMERCIALCHART_EXPORT QChart
21 //class QTCOMMERCIALCHART_EXPORT QChart
@@ -87,7 +87,7 private:
87 QList<AxisItem*> m_axisYItem;
87 QList<AxisItem*> m_axisYItem;
88 QRect m_rect;
88 QRect m_rect;
89 QList<QChartSeries *> m_chartSeries;
89 QList<QChartSeries *> m_chartSeries;
90 QList<ChartItemControl *> m_chartItemControls;
90 QList<ChartObjectInterface *> m_chartObjectInterfaces;
91 QVector<PlotDomain> m_plotDomainList;
91 QVector<PlotDomain> m_plotDomainList;
92 int m_plotDataIndex;
92 int m_plotDataIndex;
93 int m_marginSize;
93 int m_marginSize;
@@ -47,12 +47,7 bool QPieSeriesPrivate::setData(QList<qreal> data)
47 return true;
47 return true;
48 }
48 }
49
49
50 void QPieSeriesPrivate::setPos(const QPointF & pos)
50 void QPieSeriesPrivate::setSize(const QSize &size)
51 {
52 // TODO
53 }
54
55 void QPieSeriesPrivate::resize(const QSize &size)
56 {
51 {
57 // TODO: allow user setting the size?
52 // TODO: allow user setting the size?
58 // TODO: allow user defining the margins?
53 // TODO: allow user defining the margins?
@@ -1,7 +1,7
1 #ifndef PIESERIESPRIVATE_H
1 #ifndef PIESERIESPRIVATE_H
2 #define PIESERIESPRIVATE_H
2 #define PIESERIESPRIVATE_H
3
3
4 #include "chartitemcontrol.h"
4 #include "chartobjectinterface_p.h"
5 #include "qpieseries.h"
5 #include "qpieseries.h"
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
@@ -10,16 +10,15 class QGraphicsItem;
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 class PieSlice;
11 class PieSlice;
12
12
13 class QPieSeriesPrivate : public ChartItemControl
13 class QPieSeriesPrivate : public ChartObjectInterface
14 {
14 {
15 public:
15 public:
16 // TODO: use a generic data class instead of x and y
16 // TODO: use a generic data class instead of x and y
17 QPieSeriesPrivate();
17 QPieSeriesPrivate();
18 ~QPieSeriesPrivate();
18 ~QPieSeriesPrivate();
19
19
20 public: // from ChartItemControl
20 public: // from ChartObjectInterface
21 void setPos(const QPointF & pos);
21 void setSize(const QSize &size);
22 void resize(const QSize &size);
23 void setTheme(ChartTheme *theme);
22 void setTheme(ChartTheme *theme);
24 void setPlotDomain(const PlotDomain& data);
23 void setPlotDomain(const PlotDomain& data);
25
24
@@ -10,7 +10,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 //#define QSeriesData QList<qreal>
10 //#define QSeriesData QList<qreal>
11
11
12 QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) :
12 QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) :
13 QGraphicsItem(parent),
13 ChartItem(parent),
14 m_scalex(100), // TODO: let the use define the scale (or autoscaled)
14 m_scalex(100), // TODO: let the use define the scale (or autoscaled)
15 m_scaley(100),
15 m_scaley(100),
16 m_markerColor(QColor())
16 m_markerColor(QColor())
@@ -29,8 +29,22 void QScatterSeriesPrivate::resize(QRectF rect)
29 m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley));
29 m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley));
30 }
30 }
31
31
32 // TODO:
32 void QScatterSeriesPrivate::setSize(const QSize &size)
33 //void QScatterSeriesPrivate::setAxisScale(qreal xscale, qreal yscale)
33 {
34 QGraphicsItem *parent = this->parentItem();
35 if (parent)
36 resize(QRectF(parent->pos(), size));
37 }
38
39 void QScatterSeriesPrivate::setTheme(ChartTheme *theme)
40 {
41 m_theme = theme->themeForSeries();
42 }
43
44 void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain)
45 {
46 // TODO
47 }
34
48
35 QRectF QScatterSeriesPrivate::boundingRect() const
49 QRectF QScatterSeriesPrivate::boundingRect() const
36 {
50 {
@@ -62,26 +76,6 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsI
62 }
76 }
63 }
77 }
64
78
65 void QScatterSeriesPrivate::setPos(const QPointF & pos)
66 {
67 // TODO
68 }
69
70 void QScatterSeriesPrivate::resize(const QSize &size)
71 {
72 resize(QRect(0, 0, size.width(), size.height()));
73 }
74
75 void QScatterSeriesPrivate::setTheme(ChartTheme *theme)
76 {
77 m_theme = theme->themeForSeries();
78 }
79
80 void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain)
81 {
82 // TODO
83 }
84
85 QScatterSeries::QScatterSeries(QObject *parent) :
79 QScatterSeries::QScatterSeries(QObject *parent) :
86 QChartSeries(parent),
80 QChartSeries(parent),
87 d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent)))
81 d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent)))
@@ -95,6 +89,8 bool QScatterSeries::setData(QList<qreal> x, QList<qreal> y)
95 d->m_y = y;
89 d->m_y = y;
96 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
90 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
97 Q_ASSERT(parentItem);
91 Q_ASSERT(parentItem);
92 // d->setPos(parentItem->pos());
93 // d->setSize(parentItem->boundingRect().size().toSize());
98 d->resize(parentItem->boundingRect());
94 d->resize(parentItem->boundingRect());
99 return true;
95 return true;
100 }
96 }
@@ -3,7 +3,7
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include "charttheme_p.h"
5 #include "charttheme_p.h"
6 #include "chartitemcontrol.h"
6 #include "chartitem_p.h"
7 #include <QGraphicsItem>
7 #include <QGraphicsItem>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -11,23 +11,23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 /*!
11 /*!
12 * The PIMPL class of QScatterSeries.
12 * The PIMPL class of QScatterSeries.
13 */
13 */
14 class QScatterSeriesPrivate : public QGraphicsItem, public ChartItemControl
14 class QScatterSeriesPrivate : public ChartItem
15 {
15 {
16 public:
16 public:
17 QScatterSeriesPrivate(QGraphicsItem *parent);
17 QScatterSeriesPrivate(QGraphicsItem *parent);
18
18
19 public: // from ChartObjectInterface
20 void setSize(const QSize &size);
21 void setTheme(ChartTheme *theme);
22 void setPlotDomain(const PlotDomain& data);
23
19 public: // from QGraphicsItem
24 public: // from QGraphicsItem
20 void setPos(const QPointF & pos);
21 void resize(QRectF rect);
22 QRectF boundingRect() const;
25 QRectF boundingRect() const;
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
26 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24
27
25 public: // from ChartItemControl
26 void resize(const QSize &size);
27 void setTheme(ChartTheme *theme);
28 void setPlotDomain(const PlotDomain& data);
29
30 public:
28 public:
29 void resize(QRectF rect); // TODO: replace with setSize
30
31 // TODO: use the chart data class instead of list of x and y values?
31 // TODO: use the chart data class instead of list of x and y values?
32 QList<qreal> m_x;
32 QList<qreal> m_x;
33 QList<qreal> m_y;
33 QList<qreal> m_y;
@@ -40,6 +40,7 PRIVATE_HEADERS += \
40 qpieseries_p.h \
40 qpieseries_p.h \
41 pieslice.h \
41 pieslice.h \
42 axisitem_p.h \
42 axisitem_p.h \
43 chartitem_p.h \
43 charttheme_p.h
44 charttheme_p.h
44
45
45 PUBLIC_HEADERS += \
46 PUBLIC_HEADERS += \
@@ -60,7 +61,7 PUBLIC_HEADERS += \
60 qchartaxis.h
61 qchartaxis.h
61
62
62 HEADERS += $$PUBLIC_HEADERS \
63 HEADERS += $$PUBLIC_HEADERS \
63 chartitemcontrol.h
64 chartobjectinterface_p.h
64 HEADERS += $$PRIVATE_HEADERS
65 HEADERS += $$PRIVATE_HEADERS
65
66
66 INCLUDEPATH += xylinechart \
67 INCLUDEPATH += xylinechart \
@@ -108,3 +109,5 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
108
109
109
110
110
111
112
113
@@ -8,19 +8,14
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent) :
10 XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent) :
11 QGraphicsItem(parent),
11 ChartItem(parent),
12 m_series(series),
12 m_series(series),
13 m_pathItem(new QGraphicsPathItem(this))
13 m_pathItem(new QGraphicsPathItem(this))
14 {
14 {
15 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
15 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
16 }
16 }
17
17
18 void XYLineChartItem::setPos(const QPointF & pos)
18 void XYLineChartItem::setSize(const QSize &size)
19 {
20 QGraphicsItem::setPos(pos);
21 }
22
23 void XYLineChartItem::resize(const QSize &size)
24 {
19 {
25 m_rect = QRect(0, 0, size.width(), size.height());
20 m_rect = QRect(0, 0, size.width(), size.height());
26 prepareGeometryChange();
21 prepareGeometryChange();
@@ -2,7 +2,7
2 #define XYLINECHARTITEM_H
2 #define XYLINECHARTITEM_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "chartitemcontrol.h"
5 #include "chartitem_p.h"
6 #include "charttheme_p.h"
6 #include "charttheme_p.h"
7 #include <QGraphicsItem>
7 #include <QGraphicsItem>
8
8
@@ -10,7 +10,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class QXYChartSeries;
11 class QXYChartSeries;
12
12
13 class XYLineChartItem : public QGraphicsItem, public ChartItemControl
13 class XYLineChartItem : public ChartItem
14 {
14 {
15
15
16 public:
16 public:
@@ -22,9 +22,8 public:
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
23 // virtual QPainterPath shape() const;
23 // virtual QPainterPath shape() const;
24
24
25 public: // from ChartItemControl
25 public: // from ChartObjectInterface
26 void setPos(const QPointF & pos);
26 void setSize(const QSize &size);
27 void resize(const QSize &size);
28 void setTheme(ChartTheme *theme);
27 void setTheme(ChartTheme *theme);
29 void setPlotDomain(const PlotDomain& data);
28 void setPlotDomain(const PlotDomain& data);
30
29
General Comments 0
You need to be logged in to leave comments. Login now