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