##// END OF EJS Templates
One more alternative for changing themes
Tero Ahola -
r108:4cbe204cc325
parent child
Show More
@@ -49,13 +49,6 void AxisItem::setSize(const QSize &size)
49 createItems();
49 createItems();
50 }
50 }
51
51
52 void AxisItem::setTheme(ChartTheme *theme)
53 {
54 if (theme) {
55 // TODO: add axis related properties to the theme class and use them here
56 }
57 }
58
59 /*
52 /*
60 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
53 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
61 {
54 {
@@ -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 ChartObjectInterface
22 public: // from ChartItem
23 void setSize(const QSize &size);
23 void setSize(const QSize &size);
24 void setTheme(ChartTheme *theme);
25 void setPlotDomain(const PlotDomain& data);
24 void setPlotDomain(const PlotDomain& data);
26
25
27 public:
26 public:
@@ -20,11 +20,6 void Bar::setPlotDomain(const PlotDomain& data)
20 mPlotDomain = data;
20 mPlotDomain = data;
21 }
21 }
22
22
23 void Bar::setTheme(ChartTheme *theme)
24 {
25 // TODO
26 }
27
28 void Bar::resize( int w, int h )
23 void Bar::resize( int w, int h )
29 {
24 {
30 // qDebug() << "bar::resize" << w << h;
25 // qDebug() << "bar::resize" << w << h;
@@ -15,7 +15,6 public:
15
15
16 public: // from ChartItemControl
16 public: // from ChartItemControl
17 void setSize(const QSize &size);
17 void setSize(const QSize &size);
18 void setTheme(ChartTheme *theme);
19 void setPlotDomain(const PlotDomain& data);
18 void setPlotDomain(const PlotDomain& data);
20
19
21 // Layout Stuff
20 // Layout Stuff
@@ -30,12 +30,6 void BarGroup::setPlotDomain(const PlotDomain& data)
30 mPlotDomain = data;
30 mPlotDomain = data;
31 }
31 }
32
32
33 void BarGroup::setTheme(ChartTheme *theme)
34 {
35 qDebug() << "BarGroup::setTheme";
36 // TODO:
37 }
38
39 void BarGroup::setBarWidth( int w )
33 void BarGroup::setBarWidth( int w )
40 {
34 {
41 mBarDefaultWidth = w;
35 mBarDefaultWidth = w;
@@ -13,9 +13,8 class BarGroup : public ChartItem
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 ChartObjectInterface
16 public: // from ChartItem
17 void setSize(const QSize &size);
17 void setSize(const QSize &size);
18 void setTheme(ChartTheme *theme);
19 void setPlotDomain(const PlotDomain& data);
18 void setPlotDomain(const PlotDomain& data);
20
19
21 // Layout "api"
20 // Layout "api"
@@ -30,12 +30,6 void PercentBarGroup::setPlotDomain(const PlotDomain& data)
30 // TODO:
30 // TODO:
31 }
31 }
32
32
33 void PercentBarGroup::setTheme(ChartTheme *theme)
34 {
35 qDebug() << "PercentBarGroup::setTheme";
36 // TODO:
37 }
38
39 void PercentBarGroup::setBarWidth( int w )
33 void PercentBarGroup::setBarWidth( int w )
40 {
34 {
41 mBarDefaultWidth = w;
35 mBarDefaultWidth = w;
@@ -13,9 +13,8 class PercentBarGroup : public ChartItem
13 public:
13 public:
14 PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0);
14 PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0);
15
15
16 public: // From ChartObjectInterface
16 public: // From ChartItem
17 void setSize(const QSize &size);
17 void setSize(const QSize &size);
18 void setTheme(ChartTheme *theme);
19 void setPlotDomain(const PlotDomain& data);
18 void setPlotDomain(const PlotDomain& data);
20
19
21 public:
20 public:
@@ -30,12 +30,6 void StackedBarGroup::setPlotDomain(const PlotDomain& data)
30 // TODO:
30 // TODO:
31 }
31 }
32
32
33 void StackedBarGroup::setTheme(ChartTheme *theme)
34 {
35 qDebug() << "StackedBarGroup::setTheme";
36 // TODO:
37 }
38
39 void StackedBarGroup::setBarWidth( int w )
33 void StackedBarGroup::setBarWidth( int w )
40 {
34 {
41 mBarDefaultWidth = w;
35 mBarDefaultWidth = w;
@@ -14,9 +14,8 class StackedBarGroup : public ChartItem
14 public:
14 public:
15 StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0);
15 StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0);
16
16
17 public: // From ChartObjectInterface
17 public: // From ChartItem
18 void setSize(const QSize &size);
18 void setSize(const QSize &size);
19 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
19 void setPlotDomain(const PlotDomain& data);
21
20
22 public: // Layout "api"
21 public: // Layout "api"
@@ -2,20 +2,18
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"
6 #include <QGraphicsItem>
5 #include <QGraphicsItem>
7
6
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 // TODO: setSize and set plotDomain back here. Derive this only from QGraphicsItem
8
10 // class ChartItem : public QGraphicsItem
9 class ChartItem : public QGraphicsItem
11 class ChartItem : public QGraphicsItem, public ChartObjectInterface
12 {
10 {
13 enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM};
11 enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM};
14 public:
12 public:
15 ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){};
13 ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){};
16 virtual ~ChartItem(){};
14 virtual ~ChartItem(){};
17 // TODO: this is a hack; integration ongoing:
15 virtual void setSize(const QSize &size) = 0;
18 QGraphicsItem *graphicsItem() { return this; }
16 virtual void setPlotDomain(const PlotDomain& data) = 0;
19 };
17 };
20
18
21 QTCOMMERCIALCHART_END_NAMESPACE
19 QTCOMMERCIALCHART_END_NAMESPACE
@@ -5,8 +5,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
5
6 void ChartThemeData::setTheme(int theme)
6 void ChartThemeData::setTheme(int theme)
7 {
7 {
8 if (theme == m_currentTheme) return;
9
10 m_seriesThemes.clear();
8 m_seriesThemes.clear();
11 m_seriesIndex = 0;
9 m_seriesIndex = 0;
12 m_currentTheme = theme;
10 m_currentTheme = theme;
@@ -19,48 +17,48 void ChartThemeData::setTheme(int theme)
19 // line shadow (on/off)
17 // line shadow (on/off)
20 // marker shape: "x", "o", "."
18 // marker shape: "x", "o", "."
21 // TODO: define the default theme based on the OS
19 // TODO: define the default theme based on the OS
22 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QRgb(0xff000000), 2));
20 m_seriesThemes.append(SeriesTheme(QRgb(0xff000000), 2));
23 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QRgb(0xff707070), 2));
21 m_seriesThemes.append(SeriesTheme(QRgb(0xff707070), 2));
24 m_gradientStartColor = QColor(QRgb(0xffffffff));
22 m_gradientStartColor = QColor(QRgb(0xffffffff));
25 m_gradientEndColor = QColor(QRgb(0xffafafaf));
23 m_gradientEndColor = QColor(QRgb(0xffafafaf));
26 break;
24 break;
27 case QChart::ChartThemeVanilla:
25 case QChart::ChartThemeVanilla:
28 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(217, 197, 116), 10));
26 m_seriesThemes.append(SeriesTheme(QColor(217, 197, 116), 6));
29 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(214, 168, 150), 10));
27 m_seriesThemes.append(SeriesTheme(QColor(214, 168, 150), 4));
30 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(160, 160, 113), 10));
28 m_seriesThemes.append(SeriesTheme(QColor(160, 160, 113), 6));
31 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(210, 210, 52), 10));
29 m_seriesThemes.append(SeriesTheme(QColor(210, 210, 52), 4));
32 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(136, 114, 58), 10));
30 m_seriesThemes.append(SeriesTheme(QColor(136, 114, 58), 6));
33
31
34 m_gradientStartColor = QColor(QRgb(0xff9d844d));
32 m_gradientStartColor = QColor(QRgb(0xff9d844d));
35 m_gradientEndColor = QColor(QRgb(0xffafafaf));
33 m_gradientEndColor = QColor(QRgb(0xffafafaf));
36 break;
34 break;
37 case QChart::ChartThemeIcy:
35 case QChart::ChartThemeIcy:
38 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(0, 3, 165), 2));
36 m_seriesThemes.append(SeriesTheme(QColor(0, 3, 165), 2));
39 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(49, 52, 123), 2));
37 m_seriesThemes.append(SeriesTheme(QColor(49, 52, 123), 2));
40 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(71, 114, 187), 2));
38 m_seriesThemes.append(SeriesTheme(QColor(71, 114, 187), 2));
41 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(48, 97, 87), 2));
39 m_seriesThemes.append(SeriesTheme(QColor(48, 97, 87), 2));
42 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(19, 71, 90), 2));
40 m_seriesThemes.append(SeriesTheme(QColor(19, 71, 90), 2));
43 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(110, 70, 228), 2));
41 m_seriesThemes.append(SeriesTheme(QColor(110, 70, 228), 2));
44
42
45 m_gradientStartColor = QColor(QRgb(0xffe4ffff));
43 m_gradientStartColor = QColor(QRgb(0xffe4ffff));
46 m_gradientEndColor = QColor(QRgb(0xffe4ffff));
44 m_gradientEndColor = QColor(QRgb(0xffe4ffff));
47 break;
45 break;
48 case QChart::ChartThemeGrayscale:
46 case QChart::ChartThemeGrayscale:
49 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(0, 0, 0), 2));
47 m_seriesThemes.append(SeriesTheme(QColor(0, 0, 0), 2));
50 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(50, 50, 50), 2));
48 m_seriesThemes.append(SeriesTheme(QColor(50, 50, 50), 2));
51 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(100, 100, 100), 2));
49 m_seriesThemes.append(SeriesTheme(QColor(100, 100, 100), 2));
52 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(140, 140, 140), 2));
50 m_seriesThemes.append(SeriesTheme(QColor(140, 140, 140), 2));
53 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(180, 180, 180), 2));
51 m_seriesThemes.append(SeriesTheme(QColor(180, 180, 180), 2));
54
52
55 m_gradientStartColor = QColor(QRgb(0xffffffff));
53 m_gradientStartColor = QColor(QRgb(0xffffffff));
56 m_gradientEndColor = QColor(QRgb(0xffafafaf));
54 m_gradientEndColor = QColor(QRgb(0xffafafaf));
57 break;
55 break;
58 case QChart::ChartThemeUnnamed1:
56 case QChart::ChartThemeUnnamed1:
59 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(QRgb(0xff3fa9f5)), 2));
57 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
60 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(QRgb(0xff7AC943)), 2));
58 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
61 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(QRgb(0xffFF931E)), 2));
59 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
62 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(QRgb(0xffFF1D25)), 2));
60 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
63 m_seriesThemes.append(SeriesTheme(m_seriesThemes.count(), QColor(QRgb(0xffFF7BAC)), 2));
61 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
64
62
65 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
63 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
66 m_gradientEndColor = QColor(QRgb(0xffafafaf));
64 m_gradientEndColor = QColor(QRgb(0xffafafaf));
@@ -69,9 +67,6 void ChartThemeData::setTheme(int theme)
69 Q_ASSERT(false);
67 Q_ASSERT(false);
70 break;
68 break;
71 }
69 }
72
73 //themeChanged();
74 // TODO: update coloring of different elements to match the selected theme
75 }
70 }
76
71
77 ChartTheme::ChartTheme(QObject *parent) :
72 ChartTheme::ChartTheme(QObject *parent) :
@@ -82,6 +77,15 ChartTheme::ChartTheme(QObject *parent) :
82 d->m_seriesIndex = 0;
77 d->m_seriesIndex = 0;
83 }
78 }
84
79
80 void ChartTheme::setTheme(int theme)
81 {
82 if (theme != d->m_currentTheme) {
83 d->setTheme(theme);
84 foreach (ChartThemeObserver *o, d->m_observers)
85 o->themeChanged(this);
86 }
87 }
88
85 SeriesTheme ChartTheme::themeForSeries()
89 SeriesTheme ChartTheme::themeForSeries()
86 {
90 {
87 if (d->m_seriesThemes.count() == 0) {
91 if (d->m_seriesThemes.count() == 0) {
@@ -10,25 +10,28
10
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
12
13 class ChartTheme;
14
15 class ChartThemeObserver
16 {
17 public:
18 virtual void themeChanged(ChartTheme *theme) = 0;
19 };
20
13 /*!
21 /*!
14 * The theme specific settings for the appearance of a series. TODO: These can be overridden by setting
22 * The theme specific settings for the appearance of a series. TODO: These can be overridden by setting
15 * custom settings to a QChartSeries object.
23 * custom settings to a QChartSeries object.
16 */
24 */
17 struct SeriesTheme {
25 struct SeriesTheme {
18 public:
26 public:
19 // SeriesTheme() :
20 // themeIndex(-1), lineColor(QColor()) {}
21 // SeriesTheme(int index, QColor line) :
22 // themeIndex(index), lineColor(line) {}
23 SeriesTheme() :
27 SeriesTheme() :
24 themeIndex(-1), linePen(QPen()), markerPen(QPen()) {}
28 linePen(QPen()),
25 SeriesTheme(int index, QColor lineColor, qreal lineWidth/*, QPen marker*/) :
29 markerPen(QPen()) {}
26 themeIndex(index),
30 SeriesTheme(QColor lineColor, qreal lineWidth/*, QPen marker*/) :
27 linePen(QPen(QBrush(lineColor), lineWidth)),
31 linePen(QPen(QBrush(lineColor), lineWidth)),
28 markerPen(linePen) {}
32 markerPen(linePen) {}
29
33
30 //const QBrush & brush, qreal width, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap, Qt::PenJoinStyle join = Qt::BevelJo
34 //const QBrush & brush, qreal width, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap, Qt::PenJoinStyle join = Qt::BevelJo
31 int themeIndex;
32 // TODO:
35 // TODO:
33 //QColor lineColor;
36 //QColor lineColor;
34 QPen linePen;
37 QPen linePen;
@@ -51,6 +54,7 public:
51
54
52 public:
55 public:
53 int m_currentTheme;
56 int m_currentTheme;
57 QList<ChartThemeObserver *> m_observers;
54 QColor m_gradientStartColor;
58 QColor m_gradientStartColor;
55 QColor m_gradientEndColor;
59 QColor m_gradientEndColor;
56 QList<SeriesTheme> m_seriesThemes;
60 QList<SeriesTheme> m_seriesThemes;
@@ -65,9 +69,9 public:
65 explicit ChartTheme(const ChartTheme &other) : d(other.d) {}
69 explicit ChartTheme(const ChartTheme &other) : d(other.d) {}
66 void operator =(const ChartTheme &other) { d = other.d; }
70 void operator =(const ChartTheme &other) { d = other.d; }
67
71
68 //signals:
72 void setTheme(int theme);
69 // void themeChanged(ChartTheme theme);
70 SeriesTheme themeForSeries();
73 SeriesTheme themeForSeries();
74 void addObserver(ChartThemeObserver *o) { d->m_observers << o; }
71
75
72 public:
76 public:
73 // All the graphical elements of a QChart share the same theme settings
77 // All the graphical elements of a QChart share the same theme settings
@@ -47,7 +47,8 QPainterPath PieSlice::shape() const
47 void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
47 void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
48 {
48 {
49 painter->setRenderHint(QPainter::Antialiasing);
49 painter->setRenderHint(QPainter::Antialiasing);
50 painter->setPen(m_theme.linePen);
50 // TODO: how to map theme settings to a pie slice? Now we
51 //painter->setPen(m_theme.linePen);
51 // TODO:
52 // TODO:
52 painter->setBrush(m_theme.linePen.color());
53 painter->setBrush(m_theme.linePen.color());
53
54
@@ -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 "chartobjectinterface_p.h"
16 #include "chartitem_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_chartObjectInterfaces << m_axisXItem;
40 m_chartItems << m_axisXItem;
41 m_chartObjectInterfaces << m_axisYItem.at(0);
41 m_chartItems << m_axisYItem.at(0);
42 }
42 }
43
43
44 QChart::~QChart(){}
44 QChart::~QChart(){}
@@ -64,8 +64,7 void QChart::addSeries(QChartSeries* series)
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 {
69 qreal x = xyseries->x(i);
68 qreal x = xyseries->x(i);
70 qreal y = xyseries->y(i);
69 qreal y = xyseries->y(i);
71 domain.m_minX = qMin(domain.m_minX,x);
70 domain.m_minX = qMin(domain.m_minX,x);
@@ -76,12 +75,9 void QChart::addSeries(QChartSeries* series)
76
75
77 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
76 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
78
77
79 // TODO: combine ChartObjectInterface and ChartItem apis
78 m_chartItems << item;
80 m_chartObjectInterfaces << item;
79 // TODO:
81 item->setTheme(m_chartTheme);
80 //m_chartTheme->addObserver(xyseries);
82
83 foreach(ChartObjectInterface* i, m_chartObjectInterfaces)
84 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
85
81
86 break;
82 break;
87 }
83 }
@@ -98,7 +94,7 void QChart::addSeries(QChartSeries* series)
98 barGroup->addColor(QColor(0,0,255,128));
94 barGroup->addColor(QColor(0,0,255,128));
99 barGroup->addColor(QColor(255,128,0,128));
95 barGroup->addColor(QColor(255,128,0,128));
100
96
101 m_chartObjectInterfaces << barGroup;
97 m_chartItems << barGroup;
102 childItems().append(barGroup);
98 childItems().append(barGroup);
103
99
104 // TODO: setting of domain should this be somewhere else.
100 // TODO: setting of domain should this be somewhere else.
@@ -114,10 +110,6 void QChart::addSeries(QChartSeries* series)
114 domain.m_minY = qMin(domain.m_minY,y);
110 domain.m_minY = qMin(domain.m_minY,y);
115 domain.m_maxX = qMax(domain.m_maxX,x);
111 domain.m_maxX = qMax(domain.m_maxX,x);
116 domain.m_maxY = qMax(domain.m_maxY,y);
112 domain.m_maxY = qMax(domain.m_maxY,y);
117
118 foreach(ChartObjectInterface* i ,m_chartObjectInterfaces)
119 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
120
121 break;
113 break;
122 }
114 }
123 case QChartSeries::SeriesTypeStackedBar: {
115 case QChartSeries::SeriesTypeStackedBar: {
@@ -133,7 +125,7 void QChart::addSeries(QChartSeries* series)
133 stackedBarGroup->addColor(QColor(0,0,255,128));
125 stackedBarGroup->addColor(QColor(0,0,255,128));
134 stackedBarGroup->addColor(QColor(255,128,0,128));
126 stackedBarGroup->addColor(QColor(255,128,0,128));
135
127
136 m_chartObjectInterfaces << stackedBarGroup;
128 m_chartItems << stackedBarGroup;
137 childItems().append(stackedBarGroup);
129 childItems().append(stackedBarGroup);
138
130
139 // TODO: setting of domain should this be somewhere else.
131 // TODO: setting of domain should this be somewhere else.
@@ -149,10 +141,6 void QChart::addSeries(QChartSeries* series)
149 domain.m_minY = qMin(domain.m_minY,y);
141 domain.m_minY = qMin(domain.m_minY,y);
150 domain.m_maxX = qMax(domain.m_maxX,x);
142 domain.m_maxX = qMax(domain.m_maxX,x);
151 domain.m_maxY = qMax(domain.m_maxY,y);
143 domain.m_maxY = qMax(domain.m_maxY,y);
152
153 foreach(ChartObjectInterface* i ,m_chartObjectInterfaces)
154 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
155
156 break;
144 break;
157 }
145 }
158 case QChartSeries::SeriesTypePercentBar: {
146 case QChartSeries::SeriesTypePercentBar: {
@@ -168,7 +156,7 void QChart::addSeries(QChartSeries* series)
168 percentBarGroup->addColor(QColor(0,0,255,128));
156 percentBarGroup->addColor(QColor(0,0,255,128));
169 percentBarGroup->addColor(QColor(255,128,0,128));
157 percentBarGroup->addColor(QColor(255,128,0,128));
170
158
171 m_chartObjectInterfaces << percentBarGroup;
159 m_chartItems << percentBarGroup;
172 childItems().append(percentBarGroup);
160 childItems().append(percentBarGroup);
173
161
174 // TODO: setting of domain should this be somewhere else.
162 // TODO: setting of domain should this be somewhere else.
@@ -183,35 +171,29 void QChart::addSeries(QChartSeries* series)
183 domain.m_minY = 0;
171 domain.m_minY = 0;
184 domain.m_maxX = qMax(domain.m_maxX,x);
172 domain.m_maxX = qMax(domain.m_maxX,x);
185 domain.m_maxY = 100;
173 domain.m_maxY = 100;
186
187 foreach(ChartObjectInterface* i ,m_chartObjectInterfaces)
188 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
189
190 break;
174 break;
191 }
175 }
192 case QChartSeries::SeriesTypeScatter: {
176 case QChartSeries::SeriesTypeScatter: {
193 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
177 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
194 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
178 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
195 scatterSeries->d->setParentItem(this);
179 scatterSeries->d->setParentItem(this);
196 m_chartObjectInterfaces << scatterSeries->d;
180 m_chartItems << scatterSeries->d;
197 //TODO:? scatterSeries->d->m_themeIndex = m_chartSeries.count() - 1;
181 m_chartTheme->addObserver(scatterSeries->d);
198 break;
182 break;
199 }
183 }
200 case QChartSeries::SeriesTypePie: {
184 case QChartSeries::SeriesTypePie: {
201 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
185 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
202 // for (int i(0); i < pieSeries->sliceCount(); i++) {
186 pieSeries->d->setParentItem(this);
203 // if (!pieSeries->sliceColor(i).isValid())
187 m_chartItems << pieSeries->d;
204 // pieSeries->setSliceColor(i, nextColor());
188 pieSeries->d->m_chartTheme = m_chartTheme;
205 // }
189 m_chartTheme->addObserver(pieSeries->d);
206 pieSeries->d->setTheme(m_chartTheme);
207 m_chartObjectInterfaces << pieSeries->d;
208
209 // Set pre-defined colors in case the series has no colors defined
210 // TODO: how to define the color for all the slices of a pie?
211 // for (int (i); i < pieSeries.sliceCount(); i++)
212 break;
190 break;
213 }
191 }
214 }
192 }
193
194 // Update all the items to match the new visible area of the chart
195 foreach(ChartItem* i, m_chartItems)
196 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
215 }
197 }
216
198
217 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
199 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
@@ -276,11 +258,9 void QChart::setSize(const QSize& size)
276 }
258 }
277
259
278 // resize and reposition childs
260 // resize and reposition childs
279 foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces) {
261 foreach (ChartItem *item, m_chartItems) {
280 QGraphicsItem *item = ctrl->graphicsItem();
281 if (item)
282 item->setPos(rect.topLeft());
262 item->setPos(rect.topLeft());
283 ctrl->setSize(rect.size());
263 item->setSize(rect.size());
284 }
264 }
285
265
286 update();
266 update();
@@ -329,17 +309,26 void QChart::setMargin(int margin)
329
309
330 void QChart::setTheme(QChart::ChartThemeId theme)
310 void QChart::setTheme(QChart::ChartThemeId theme)
331 {
311 {
332 if (theme != m_chartTheme->d->m_currentTheme) {
312 m_chartTheme->setTheme(theme);
333 m_chartTheme->d->setTheme(theme);
334 setBackground(m_chartTheme->d->m_gradientStartColor,
313 setBackground(m_chartTheme->d->m_gradientStartColor,
335 m_chartTheme->d->m_gradientEndColor,
314 m_chartTheme->d->m_gradientEndColor,
336 m_bacgroundOrinetation);
315 m_bacgroundOrinetation);
337 foreach (ChartObjectInterface *ctrl, m_chartObjectInterfaces)
316
338 ctrl->setTheme(m_chartTheme);
317 // TODO: Move the controlling of the series presentations into private implementation of the
339 update();
318 // series instead of QChart controlling themes for each
319 // In other words, the following should be used when creating xy series:
320 // m_chartTheme->addObserver(xyseries)
321 foreach (QChartSeries *series, m_chartSeries) {
322 if (series->type() == QChartSeries::SeriesTypeLine) {
323 QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series);
324 SeriesTheme seriesTheme = m_chartTheme->themeForSeries();
325 xyseries->setPen(seriesTheme.linePen);
340 }
326 }
341 }
327 }
342
328
329 update();
330 }
331
343 void QChart::zoomInToRect(const QRect& rectangle)
332 void QChart::zoomInToRect(const QRect& rectangle)
344 {
333 {
345
334
@@ -358,8 +347,8 void QChart::zoomInToRect(const QRect& rectangle)
358 m_plotDomainList<<domain;
347 m_plotDomainList<<domain;
359 m_plotDataIndex++;
348 m_plotDataIndex++;
360
349
361 foreach (ChartObjectInterface* ctrl, m_chartObjectInterfaces)
350 foreach (ChartItem* item, m_chartItems)
362 ctrl->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
351 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
363 update();
352 update();
364 }
353 }
365
354
@@ -367,7 +356,7 void QChart::zoomIn()
367 {
356 {
368 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
357 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
369 m_plotDataIndex++;
358 m_plotDataIndex++;
370 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
359 foreach (ChartItem* item, m_chartItems)
371 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
360 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
372 update();
361 update();
373 } else {
362 } else {
@@ -383,7 +372,7 void QChart::zoomOut()
383 {
372 {
384 if (m_plotDataIndex > 0) {
373 if (m_plotDataIndex > 0) {
385 m_plotDataIndex--;
374 m_plotDataIndex--;
386 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
375 foreach (ChartItem* item, m_chartItems)
387 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
376 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
388 update();
377 update();
389 }
378 }
@@ -393,7 +382,7 void QChart::zoomReset()
393 {
382 {
394 if (m_plotDataIndex > 0) {
383 if (m_plotDataIndex > 0) {
395 m_plotDataIndex = 0;
384 m_plotDataIndex = 0;
396 foreach (ChartObjectInterface* item, m_chartObjectInterfaces)
385 foreach (ChartItem* item, m_chartItems)
397 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
386 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
398 update();
387 update();
399 }
388 }
@@ -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 ChartObjectInterface;
18 class ChartItem;
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<ChartObjectInterface *> m_chartObjectInterfaces;
90 QList<ChartItem *> m_chartItems;
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;
@@ -6,9 +6,11
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 QPieSeriesPrivate::QPieSeriesPrivate() :
9 QPieSeriesPrivate::QPieSeriesPrivate(QGraphicsItem *parent) :
10 ChartItem(parent),
10 m_sizeFactor(1.0),
11 m_sizeFactor(1.0),
11 m_position(QPieSeries::PiePositionMaximized)
12 m_position(QPieSeries::PiePositionMaximized),
13 m_chartTheme(0)
12 {
14 {
13 }
15 }
14
16
@@ -22,25 +24,25 bool QPieSeriesPrivate::setData(QList<qreal> data)
22 {
24 {
23 m_data = data;
25 m_data = data;
24
26
25 if (m_parentItem) {
27 if (parentItem()) {
26 // Create slices
28 // Create slices
27 qreal fullPie = 360;
29 qreal fullPie = 360;
28 qreal total = 0;
30 qreal total = 0;
29 foreach (qreal value, m_data)
31 foreach (qreal value, m_data)
30 total += value;
32 total += value;
31
33
32 m_chartSize = m_parentItem->boundingRect();
34 m_chartSize = parentItem()->boundingRect();
33 qreal angle = 0;
35 qreal angle = 0;
34 // TODO: no need to create new slices in case size changed; we should re-use the existing ones
36 // TODO: no need to create new slices in case size changed; we should re-use the existing ones
35 foreach (qreal value, m_data) {
37 foreach (qreal value, m_data) {
36 qreal span = value / total * fullPie;
38 qreal span = value / total * fullPie;
37 PieSlice *slice = new PieSlice(QColor(), angle, span, m_parentItem->boundingRect());
39 PieSlice *slice = new PieSlice(QColor(), angle, span, parentItem()->boundingRect());
38 slice->setParentItem(m_parentItem);
40 slice->setParentItem(parentItem());
39 m_slices.append(slice);
41 m_slices.append(slice);
40 angle += span;
42 angle += span;
41 }
43 }
42
44
43 setTheme(m_chartTheme);
45 themeChanged(m_chartTheme);
44 resizeSlices(m_chartSize);
46 resizeSlices(m_chartSize);
45 }
47 }
46
48
@@ -55,7 +57,12 void QPieSeriesPrivate::setSize(const QSize &size)
55 resizeSlices(m_chartSize);
57 resizeSlices(m_chartSize);
56 }
58 }
57
59
58 void QPieSeriesPrivate::setTheme(ChartTheme *theme)
60 void QPieSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain)
61 {
62 // TODO
63 }
64
65 void QPieSeriesPrivate::themeChanged(ChartTheme *theme)
59 {
66 {
60 if (theme) {
67 if (theme) {
61 m_chartTheme = theme;
68 m_chartTheme = theme;
@@ -64,11 +71,6 void QPieSeriesPrivate::setTheme(ChartTheme *theme)
64 }
71 }
65 }
72 }
66
73
67 void QPieSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain)
68 {
69 // TODO
70 }
71
72 void QPieSeriesPrivate::resizeSlices(QRectF rect)
74 void QPieSeriesPrivate::resizeSlices(QRectF rect)
73 {
75 {
74 QRectF tempRect = rect;
76 QRectF tempRect = rect;
@@ -117,11 +119,8 void QPieSeriesPrivate::resizeSlices(QRectF rect)
117
119
118 QPieSeries::QPieSeries(QGraphicsObject *parent) :
120 QPieSeries::QPieSeries(QGraphicsObject *parent) :
119 QChartSeries(parent),
121 QChartSeries(parent),
120 d(new QPieSeriesPrivate())
122 d(new QPieSeriesPrivate(parent))
121 {
123 {
122 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent);
123 if (parentItem)
124 d->m_parentItem = parentItem;
125 }
124 }
126
125
127 QPieSeries::~QPieSeries()
126 QPieSeries::~QPieSeries()
@@ -161,8 +160,8 void QPieSeries::setSizeFactor(qreal factor)
161
160
162 // Initiate update via the parent graphics item
161 // Initiate update via the parent graphics item
163 // TODO: potential issue: what if this function is called from the parent context?
162 // TODO: potential issue: what if this function is called from the parent context?
164 if (d->m_parentItem)
163 if (d->parentItem())
165 d->m_parentItem->update();
164 d->parentItem()->update();
166 }
165 }
167
166
168 qreal QPieSeries::sizeFactor()
167 qreal QPieSeries::sizeFactor()
@@ -1,7 +1,8
1 #ifndef PIESERIESPRIVATE_H
1 #ifndef PIESERIESPRIVATE_H
2 #define PIESERIESPRIVATE_H
2 #define PIESERIESPRIVATE_H
3
3
4 #include "chartobjectinterface_p.h"
4 #include "chartitem_p.h"
5 #include "charttheme_p.h"
5 #include "qpieseries.h"
6 #include "qpieseries.h"
6 #include <QRectF>
7 #include <QRectF>
7 #include <QColor>
8 #include <QColor>
@@ -10,22 +11,27 class QGraphicsItem;
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 class PieSlice;
12 class PieSlice;
12
13
13 class QPieSeriesPrivate : public ChartObjectInterface
14 class QPieSeriesPrivate : public ChartItem, public ChartThemeObserver
14 {
15 {
15 public:
16 public:
16 // TODO: use a generic data class instead of x and y
17 // TODO: use a generic data class instead of x and y
17 QPieSeriesPrivate();
18 QPieSeriesPrivate(QGraphicsItem *parent);
18 ~QPieSeriesPrivate();
19 ~QPieSeriesPrivate();
19
20
20 public: // from ChartObjectInterface
21 public: // from ChartItem
21 void setSize(const QSize &size);
22 void setSize(const QSize &size);
22 void setTheme(ChartTheme *theme);
23 void setPlotDomain(const PlotDomain& data);
23 void setPlotDomain(const PlotDomain& data);
24 // This is a dummy QGraphicsItem; dummy implementation
25 QRectF boundingRect() const { return parentItem()->boundingRect(); }
26 // This is a dummy QGraphicsItem; no implementation
27 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
28
29 public: // from ChartThemeObserver
30 void themeChanged(ChartTheme *theme);
24
31
25 public:
32 public:
26 bool setData(QList<qreal> data);
33 bool setData(QList<qreal> data);
27 void resizeSlices(QRectF rect);
34 void resizeSlices(QRectF rect);
28 QGraphicsItem *m_parentItem;
29 QList<qreal> m_data;
35 QList<qreal> m_data;
30 QList<PieSlice*> m_slices;
36 QList<PieSlice*> m_slices;
31 QRectF m_chartSize;
37 QRectF m_chartSize;
@@ -11,22 +11,25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) :
12 QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) :
13 ChartItem(parent),
13 ChartItem(parent),
14 m_scalex(100), // TODO: let the use define the scale (or autoscaled)
14 m_markerColor(QColor()),
15 m_scaley(100),
15 m_visibleChartArea()
16 m_markerColor(QColor())
17 {
16 {
18 }
17 }
19
18
20 void QScatterSeriesPrivate::resize(QRectF rect)
19 void QScatterSeriesPrivate::resize(QRectF rect)
21 {
20 {
21 qreal scalex = rect.width() / m_visibleChartArea.spanX();
22 qreal scaley = rect.height() / m_visibleChartArea.spanY();
23
22 m_scenex.clear();
24 m_scenex.clear();
23 m_sceney.clear();
25 m_sceney.clear();
24
26
27 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
25 foreach(qreal x, m_x)
28 foreach(qreal x, m_x)
26 m_scenex.append(rect.left() + x * (rect.width() / m_scalex));
29 m_scenex.append(rect.left() + x * scalex - m_visibleChartArea.m_minX * scalex);
27
30
28 foreach(qreal y, m_y)
31 foreach(qreal y, m_y)
29 m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley));
32 m_sceney.append(rect.bottom() - y * scaley - m_visibleChartArea.m_minY * scaley);
30 }
33 }
31
34
32 void QScatterSeriesPrivate::setSize(const QSize &size)
35 void QScatterSeriesPrivate::setSize(const QSize &size)
@@ -36,14 +39,15 void QScatterSeriesPrivate::setSize(const QSize &size)
36 resize(QRectF(parent->pos(), size));
39 resize(QRectF(parent->pos(), size));
37 }
40 }
38
41
39 void QScatterSeriesPrivate::setTheme(ChartTheme *theme)
42 void QScatterSeriesPrivate::themeChanged(ChartTheme *theme)
40 {
43 {
41 m_theme = theme->themeForSeries();
44 m_theme = theme->themeForSeries();
42 }
45 }
43
46
44 void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain)
47 void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain)
45 {
48 {
46 // TODO
49 m_visibleChartArea = plotDomain;
50 resize(parentItem()->boundingRect());
47 }
51 }
48
52
49 QRectF QScatterSeriesPrivate::boundingRect() const
53 QRectF QScatterSeriesPrivate::boundingRect() const
@@ -4,6 +4,7
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include "charttheme_p.h"
5 #include "charttheme_p.h"
6 #include "chartitem_p.h"
6 #include "chartitem_p.h"
7 #include "plotdomain_p.h"
7 #include <QGraphicsItem>
8 #include <QGraphicsItem>
8
9
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -11,16 +12,18 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 /*!
12 /*!
12 * The PIMPL class of QScatterSeries.
13 * The PIMPL class of QScatterSeries.
13 */
14 */
14 class QScatterSeriesPrivate : public ChartItem
15 class QScatterSeriesPrivate : public ChartItem, public ChartThemeObserver
15 {
16 {
16 public:
17 public:
17 QScatterSeriesPrivate(QGraphicsItem *parent);
18 QScatterSeriesPrivate(QGraphicsItem *parent);
18
19
19 public: // from ChartObjectInterface
20 public: // from ChartObjectInterface
20 void setSize(const QSize &size);
21 void setSize(const QSize &size);
21 void setTheme(ChartTheme *theme);
22 void setPlotDomain(const PlotDomain& data);
22 void setPlotDomain(const PlotDomain& data);
23
23
24 public: // from ChartThemeObserver
25 void themeChanged(ChartTheme *theme);
26
24 public: // from QGraphicsItem
27 public: // from QGraphicsItem
25 QRectF boundingRect() const;
28 QRectF boundingRect() const;
26 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
29 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@@ -37,6 +40,7 public:
37 QList<qreal> m_sceney;
40 QList<qreal> m_sceney;
38 QColor m_markerColor;
41 QColor m_markerColor;
39 SeriesTheme m_theme;
42 SeriesTheme m_theme;
43 PlotDomain m_visibleChartArea;
40 };
44 };
41
45
42 QTCOMMERCIALCHART_END_NAMESPACE
46 QTCOMMERCIALCHART_END_NAMESPACE
@@ -60,8 +60,7 PUBLIC_HEADERS += \
60 qchartview.h \
60 qchartview.h \
61 qchartaxis.h
61 qchartaxis.h
62
62
63 HEADERS += $$PUBLIC_HEADERS \
63 HEADERS += $$PUBLIC_HEADERS
64 chartobjectinterface_p.h
65 HEADERS += $$PRIVATE_HEADERS
64 HEADERS += $$PRIVATE_HEADERS
66
65
67 INCLUDEPATH += xylinechart \
66 INCLUDEPATH += xylinechart \
@@ -111,3 +110,4 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
111
110
112
111
113
112
113
@@ -18,10 +18,11 private:
18 public:
18 public:
19 virtual ~QXYChartSeries();
19 virtual ~QXYChartSeries();
20
20
21 //implemented from QChartSeries
21 public: // from QChartSeries
22 static QXYChartSeries* create(QObject* parent=0);
22 static QXYChartSeries* create(QObject* parent=0);
23 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;}
23 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;}
24
24
25 public:
25 void add(qreal x, qreal y);
26 void add(qreal x, qreal y);
26 void clear();
27 void clear();
27
28
@@ -37,7 +38,6 private:
37 QList<qreal> m_x;
38 QList<qreal> m_x;
38 QList<qreal> m_y;
39 QList<qreal> m_y;
39 QPen m_pen;
40 QPen m_pen;
40
41 };
41 };
42
42
43 QTCOMMERCIALCHART_END_NAMESPACE
43 QTCOMMERCIALCHART_END_NAMESPACE
@@ -22,15 +22,6 void XYLineChartItem::setSize(const QSize &size)
22 updateGeometry();
22 updateGeometry();
23 }
23 }
24
24
25 void XYLineChartItem::setTheme(ChartTheme *theme)
26 {
27 if (theme) {
28 m_theme = theme->themeForSeries();
29 prepareGeometryChange();
30 updateGeometry();
31 }
32 }
33
34 void XYLineChartItem::setPlotDomain(const PlotDomain& data)
25 void XYLineChartItem::setPlotDomain(const PlotDomain& data)
35 {
26 {
36 m_plotDomain=data;
27 m_plotDomain=data;
@@ -43,6 +34,12 QRectF XYLineChartItem::boundingRect() const
43 {
34 {
44 return m_rect;
35 return m_rect;
45 }
36 }
37
38 void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
39 {
40 m_pathItem->setPen(m_series->pen());
41 }
42
46 /*
43 /*
47 QPainterPath XYLineChartItem::shape() const
44 QPainterPath XYLineChartItem::shape() const
48 {
45 {
@@ -68,9 +65,8 void XYLineChartItem::updateGeometry()
68 }
65 }
69
66
70 m_pathItem->setPath(path);
67 m_pathItem->setPath(path);
71 m_pathItem->setPen(m_theme.linePen);
68 m_pathItem->setPen(m_series->pen());
72 m_pathItem->setBrush(Qt::NoBrush);
69 m_pathItem->setBrush(Qt::NoBrush);
73 }
70 }
74
71
75
76 QTCOMMERCIALCHART_END_NAMESPACE
72 QTCOMMERCIALCHART_END_NAMESPACE
@@ -3,7 +3,6
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "chartitem_p.h"
5 #include "chartitem_p.h"
6 #include "charttheme_p.h"
7 #include <QGraphicsItem>
6 #include <QGraphicsItem>
8
7
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -19,12 +18,11 public:
19
18
20 //from QGraphicsItem
19 //from QGraphicsItem
21 QRectF boundingRect() const;
20 QRectF boundingRect() const;
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
21 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 // virtual QPainterPath shape() const;
22 // virtual QPainterPath shape() const;
24
23
25 public: // from ChartObjectInterface
24 public: // from ChartItem
26 void setSize(const QSize &size);
25 void setSize(const QSize &size);
27 void setTheme(ChartTheme *theme);
28 void setPlotDomain(const PlotDomain& data);
26 void setPlotDomain(const PlotDomain& data);
29
27
30 private:
28 private:
@@ -36,7 +34,6 private:
36 QXYChartSeries* m_series;
34 QXYChartSeries* m_series;
37 PlotDomain m_plotDomain;
35 PlotDomain m_plotDomain;
38 QGraphicsPathItem *m_pathItem;
36 QGraphicsPathItem *m_pathItem;
39 SeriesTheme m_theme;
40 };
37 };
41
38
42 QTCOMMERCIALCHART_END_NAMESPACE
39 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now