##// END OF EJS Templates
Refactored themes; now enabled for line, scatter and pies...
Tero Ahola -
r103:399cbfcd557c
parent child
Show More
@@ -0,0 +1,24
1 #ifndef CHARTITEMCONTROL_H
2 #define CHARTITEMCONTROL_H
3
4 #include "plotdomain_p.h"
5 #include <qchartglobal.h>
6 #include <QSize>
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 class ChartTheme;
11 class PlotDomain;
12
13 class ChartItemControl
14 {
15 public:
16 virtual void setPos (const QPointF & pos) = 0;
17 virtual void resize(const QSize &size) = 0;
18 virtual void setTheme(ChartTheme *theme) = 0;
19 virtual void setPlotDomain(const PlotDomain& data) = 0;
20 };
21
22 QTCOMMERCIALCHART_END_NAMESPACE
23
24 #endif // CHARTITEMCONTROL_H
@@ -0,0 +1,102
1 #include "charttheme_p.h"
2 #include "qchart.h"
3
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
6 void ChartThemeData::setTheme(int theme)
7 {
8 if (theme == m_currentTheme) return;
9
10 m_seriesThemes.clear();
11 m_seriesIndex = 0;
12 m_currentTheme = theme;
13
14 switch (theme) {
15 case QChart::ChartThemeDefault:
16 // line: solid, dashed, dotted
17 // line width: 1
18 // line color (and opacity)
19 // line shadow (on/off)
20 // marker shape: "x", "o", "."
21 // 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));
24 m_gradientStartColor = QColor(QRgb(0xffffffff));
25 m_gradientEndColor = QColor(QRgb(0xffafafaf));
26 break;
27 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));
33
34 m_gradientStartColor = QColor(QRgb(0xff9d844d));
35 m_gradientEndColor = QColor(QRgb(0xffafafaf));
36 break;
37 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));
44
45 m_gradientStartColor = QColor(QRgb(0xffe4ffff));
46 m_gradientEndColor = QColor(QRgb(0xffe4ffff));
47 break;
48 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));
54
55 m_gradientStartColor = QColor(QRgb(0xffffffff));
56 m_gradientEndColor = QColor(QRgb(0xffafafaf));
57 break;
58 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));
64
65 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
66 m_gradientEndColor = QColor(QRgb(0xffafafaf));
67 break;
68 default:
69 Q_ASSERT(false);
70 break;
71 }
72
73 //themeChanged();
74 // TODO: update coloring of different elements to match the selected theme
75 }
76
77 ChartTheme::ChartTheme(QObject *parent) :
78 QObject(parent),
79 d(new ChartThemeData())
80 {
81 d->m_currentTheme = QChart::ChartThemeInvalid;
82 d->m_seriesIndex = 0;
83 }
84
85 SeriesTheme ChartTheme::themeForSeries()
86 {
87 if (d->m_seriesThemes.count() == 0) {
88 return SeriesTheme();
89 } else {
90 // Get the next available theme for the series; if no more themes available start over
91 // beginning from the first theme in the list
92 SeriesTheme nextTheme =
93 d->m_seriesThemes[d->m_seriesIndex % d->m_seriesThemes.count()];
94 d->m_seriesIndex++;
95 return nextTheme;
96 }
97 }
98
99
100 #include "moc_charttheme_p.cpp"
101
102 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,80
1 #ifndef CHARTTHEME_H
2 #define CHARTTHEME_H
3
4 #include "qchartglobal.h"
5 #include <QObject>
6 #include <QSharedData>
7 #include <QColor>
8 #include <QLinearGradient>
9 #include <QPen>
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
13 /*!
14 * The theme specific settings for the appearance of a series. TODO: These can be overridden by setting
15 * custom settings to a QChartSeries object.
16 */
17 struct SeriesTheme {
18 public:
19 // SeriesTheme() :
20 // themeIndex(-1), lineColor(QColor()) {}
21 // SeriesTheme(int index, QColor line) :
22 // themeIndex(index), lineColor(line) {}
23 SeriesTheme() :
24 themeIndex(-1), linePen(QPen()), markerPen(QPen()) {}
25 SeriesTheme(int index, QColor lineColor, qreal lineWidth/*, QPen marker*/) :
26 themeIndex(index),
27 linePen(QPen(QBrush(lineColor), lineWidth)),
28 markerPen(linePen) {}
29
30 //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:
33 //QColor lineColor;
34 QPen linePen;
35 //QBrush lineBrush;
36 QPen markerPen;
37 //QBrush markerBrush;
38 };
39
40 /*!
41 * Explicitly shared data class for the themes.
42 */
43 class ChartThemeData : public QSharedData
44 {
45 public:
46 ChartThemeData() : m_currentTheme(0) {}
47 ~ChartThemeData() {}
48
49 public:
50 void setTheme(int theme);
51
52 public:
53 int m_currentTheme;
54 QColor m_gradientStartColor;
55 QColor m_gradientEndColor;
56 QList<SeriesTheme> m_seriesThemes;
57 int m_seriesIndex;
58 };
59
60 class ChartTheme : public QObject
61 {
62 Q_OBJECT
63 public:
64 explicit ChartTheme(QObject *parent = 0);
65 explicit ChartTheme(const ChartTheme &other) : d(other.d) {}
66 void operator =(const ChartTheme &other) { d = other.d; }
67
68 //signals:
69 // void themeChanged(ChartTheme theme);
70 SeriesTheme themeForSeries();
71
72 public:
73 // All the graphical elements of a QChart share the same theme settings
74 // so let's use explicitly shared data
75 QExplicitlySharedDataPointer<ChartThemeData> d;
76 };
77
78 QTCOMMERCIALCHART_END_NAMESPACE
79
80 #endif // CHARTTHEME_H
@@ -0,0 +1,40
1 #ifndef PIESERIESPRIVATE_H
2 #define PIESERIESPRIVATE_H
3
4 #include "chartitemcontrol.h"
5 #include "qpieseries.h"
6 #include <QRectF>
7 #include <QColor>
8
9 class QGraphicsItem;
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 class PieSlice;
12
13 class QPieSeriesPrivate : public ChartItemControl
14 {
15 public:
16 // TODO: use a generic data class instead of x and y
17 QPieSeriesPrivate();
18 ~QPieSeriesPrivate();
19
20 public: // from ChartItemControl
21 void setPos(const QPointF & pos);
22 void resize(const QSize &size);
23 void setTheme(ChartTheme *theme);
24 void setPlotDomain(const PlotDomain& data);
25
26 public:
27 bool setData(QList<qreal> data);
28 void resizeSlices(QRectF rect);
29 QGraphicsItem *m_parentItem;
30 QList<qreal> m_data;
31 QList<PieSlice*> m_slices;
32 QRectF m_chartSize;
33 qreal m_sizeFactor;
34 QPieSeries::PiePosition m_position;
35 ChartTheme *m_chartTheme;
36 };
37
38 QTCOMMERCIALCHART_END_NAMESPACE
39
40 #endif // PIESERIESPRIVATE_H
@@ -6,9 +6,10
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent): ChartItem(parent),
10 m_ticks(4),
11 m_type(type)
9 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) :
10 QGraphicsItem(parent),
11 m_ticks(4),
12 m_type(type)
12 13 {
13 14 }
14 15
@@ -16,12 +17,6 AxisItem::~AxisItem()
16 17 {
17 18 }
18 19
19 void AxisItem::setSize(const QSize& size)
20 {
21 m_rect = QRectF(QPoint(0,0),size);
22 createItems();
23 }
24
25 20 void AxisItem::setLength(int length)
26 21 {
27 22 QPainterPath path;
@@ -47,6 +42,25 void AxisItem::setPlotDomain(const PlotDomain& plotDomain)
47 42 m_plotDomain = plotDomain;
48 43 createItems();
49 44 }
45
46 void AxisItem::setPos(const QPointF & pos)
47 {
48 QGraphicsItem::setPos(pos);
49 }
50
51 void AxisItem::resize(const QSize &size)
52 {
53 m_rect = QRectF(QPoint(0,0),size);
54 createItems();
55 }
56
57 void AxisItem::setTheme(ChartTheme *theme)
58 {
59 if (theme) {
60 // TODO: add axis related properties to the theme class and use them here
61 }
62 }
63
50 64 /*
51 65 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
52 66 {
@@ -1,13 +1,13
1 1 #ifndef AXISITEM_H_
2 2 #define AXISITEM_H_
3 3
4 #include "chartitem_p.h"
5 4 #include "plotdomain_p.h"
5 #include "chartitemcontrol.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 class AxisItem: public ChartItem
10 class AxisItem: public QGraphicsItem, public ChartItemControl
11 11 {
12 12 public:
13 13 enum AxisType{X_AXIS,Y_AXIS};
@@ -19,10 +19,13 public:
19 19 QRectF boundingRect() const;
20 20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
21 21
22 //from ChartItem
23 void setSize(const QSize& size);
22 public: // from ChartItemControl
23 void setPos (const QPointF & pos);
24 void resize(const QSize &size);
25 void setTheme(ChartTheme *theme);
24 26 void setPlotDomain(const PlotDomain& data);
25 27
28 public:
26 29 void setLength(int length);
27 30 void setWidth(int width);
28 31 AxisType axisType() const {return m_type;};
@@ -4,12 +4,17
4 4
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 Bar::Bar(ChartItem *parent)
8 : ChartItem(parent)
7 Bar::Bar(QGraphicsItem *parent)
8 : QGraphicsItem(parent)
9 9 {
10 10 }
11 11
12 void Bar::setSize(const QSize& size)
12 void Bar::setPos(const QPointF & pos)
13 {
14 QGraphicsItem::setPos(pos);
15 }
16
17 void Bar::resize(const QSize& size)
13 18 {
14 19 mWidth = size.width();
15 20 mHeight = size.height();
@@ -20,6 +25,11 void Bar::setPlotDomain(const PlotDomain& data)
20 25 mPlotDomain = data;
21 26 }
22 27
28 void Bar::setTheme(ChartTheme *theme)
29 {
30 // TODO
31 }
32
23 33 void Bar::resize( int w, int h )
24 34 {
25 35 // qDebug() << "bar::resize" << w << h;
@@ -1,20 +1,23
1 1 #ifndef BAR_H
2 2 #define BAR_H
3 3
4 #include "chartitem_p.h"
4 #include "chartitemcontrol.h"
5 5 #include "qchartglobal.h"
6 #include <QGraphicsItem>
6 7
7 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 9
9 10 // Single bar item of chart
10 class Bar : public ChartItem
11 class Bar : public QGraphicsItem, public ChartItemControl
11 12 {
12 13 public:
13 Bar(ChartItem *parent=0);
14 Bar(QGraphicsItem *parent=0);
14 15
15 // From ChartItem
16 virtual void setSize(const QSize& size);
17 virtual void setPlotDomain(const PlotDomain& data);
16 public: // from ChartItemControl
17 void setPos (const QPointF & pos);
18 void resize(const QSize &size);
19 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
18 21
19 22 // Layout Stuff
20 23 void resize( int w, int h ); // Size of bar. in screen coordinates.
@@ -5,7 +5,7
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 7 BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) :
8 ChartItem(parent)
8 QGraphicsItem(parent)
9 9 ,mSeries(series)
10 10 ,mLayoutSet(false)
11 11 ,mLayoutDirty(true)
@@ -14,8 +14,12 BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) :
14 14 dataChanged();
15 15 }
16 16
17 void BarGroup::setPos(const QPointF & pos)
18 {
19 QGraphicsItem::setPos(pos);
20 }
17 21
18 void BarGroup::setSize(const QSize& size)
22 void BarGroup::resize(const QSize& size)
19 23 {
20 24 qDebug() << "BarGroup::setSize";
21 25 mWidth = size.width();
@@ -31,6 +35,11 void BarGroup::setPlotDomain(const PlotDomain& data)
31 35 mPlotDomain = data;
32 36 }
33 37
38 void BarGroup::setTheme(ChartTheme *theme)
39 {
40 // TODO
41 }
42
34 43 void BarGroup::setBarWidth( int w )
35 44 {
36 45 mBarDefaultWidth = w;
@@ -1,20 +1,23
1 1 #ifndef QBARGROUP_H
2 2 #define QBARGROUP_H
3 3
4 #include "chartitem_p.h"
4 #include "chartitemcontrol.h"
5 5 #include "bar.h"
6 6 #include "barchartseries.h"
7 #include <QGraphicsItem>
7 8
8 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 10
10 class BarGroup : public ChartItem
11 class BarGroup : public QGraphicsItem, public ChartItemControl
11 12 {
12 13 public:
13 14 explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0);
14 15
15 // From ChartItem
16 virtual void setSize(const QSize& size);
17 virtual void setPlotDomain(const PlotDomain& data);
16 public: // from ChartItemControl
17 void setPos (const QPointF & pos);
18 void resize(const QSize &size);
19 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
18 21
19 22 // Layout "api"
20 23 void setPos(qreal x, qreal y);
@@ -7,19 +7,25
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) :
10 ChartItem(parent)
11 ,mSeries(series)
12 ,mLayoutSet(false)
13 ,mLayoutDirty(true)
14 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
10 QGraphicsItem(parent)
11 ,mSeries(series)
12 ,mLayoutSet(false)
13 ,mLayoutDirty(true)
14 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
15 15 {
16 16 dataChanged();
17 17 }
18 18
19 19
20 void StackedBarGroup::setSize(const QSize& size)
20 void StackedBarGroup::setPos(const QPointF & pos)
21 21 {
22 qDebug() << "StackedBarGroup::setSize";
22 qDebug() << "StackedBarGroup::setPos";
23 // TODO:
24 }
25
26 void StackedBarGroup::resize(const QSize& size)
27 {
28 qDebug() << "StackedBarGroup::resize";
23 29 mWidth = size.width();
24 30 mHeight = size.height();
25 31 layoutChanged();
@@ -32,6 +38,12 void StackedBarGroup::setPlotDomain(const PlotDomain& data)
32 38 // TODO:
33 39 }
34 40
41 void StackedBarGroup::setTheme(ChartTheme *theme)
42 {
43 qDebug() << "StackedBarGroup::setTheme";
44 // TODO:
45 }
46
35 47 void StackedBarGroup::setBarWidth( int w )
36 48 {
37 49 mBarDefaultWidth = w;
@@ -1,21 +1,25
1 1 #ifndef PERCENTBARGROUP_H
2 2 #define PERCENTBARGROUP_H
3 3
4 #include "chartitem_p.h"
4 #include "chartitemcontrol.h"
5 5 #include "bar.h"
6 6 #include "percentbarchartseries.h"
7 #include <QGraphicsItem>
7 8
8 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 10
10 class PercentBarGroup : public ChartItem
11 class PercentBarGroup : public QGraphicsItem, public ChartItemControl
11 12 {
12 13 public:
13 14 PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0);
14 15
15 // From ChartItem
16 virtual void setSize(const QSize& size);
17 virtual void setPlotDomain(const PlotDomain& data);
16 public: // From ChartItemControl
17 void setPos(const QPointF & pos);
18 void resize(const QSize &size);
19 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
18 21
22 public:
19 23 // Layout "api"
20 24 void setPos(qreal x, qreal y);
21 25 void setBarWidth( int w ); // Default width for each bar
@@ -5,19 +5,24
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 7 PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) :
8 ChartItem(parent)
9 ,mSeries(series)
10 ,mLayoutSet(false)
11 ,mLayoutDirty(true)
12 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
8 QGraphicsItem(parent)
9 ,mSeries(series)
10 ,mLayoutSet(false)
11 ,mLayoutDirty(true)
12 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
13 13 {
14 14 dataChanged();
15 15 }
16 16
17 void PercentBarGroup::setPos(const QPointF & pos)
18 {
19 qDebug() << "PercentBarGroup::setPos";
20 // TODO:
21 }
17 22
18 void PercentBarGroup::setSize(const QSize& size)
23 void PercentBarGroup::resize(const QSize& size)
19 24 {
20 qDebug() << "PercentBarGroup::setSize";
25 qDebug() << "PercentBarGroup::resize";
21 26 mWidth = size.width();
22 27 mHeight = size.height();
23 28 layoutChanged();
@@ -30,6 +35,12 void PercentBarGroup::setPlotDomain(const PlotDomain& data)
30 35 // TODO:
31 36 }
32 37
38 void PercentBarGroup::setTheme(ChartTheme *theme)
39 {
40 qDebug() << "PercentBarGroup::setTheme";
41 // TODO:
42 }
43
33 44 void PercentBarGroup::setBarWidth( int w )
34 45 {
35 46 mBarDefaultWidth = w;
@@ -1,22 +1,25
1 1 #ifndef STACKEDBARGROUP_H
2 2 #define STACKEDBARGROUP_H
3 3
4 #include "chartitem_p.h"
4 #include "chartitemcontrol.h"
5 5 #include "bar.h"
6 6 #include "stackedbarchartseries.h"
7 #include <QGraphicsItem>
7 8
8 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 10
10 class StackedBarGroup : public ChartItem
11 class StackedBarGroup : public QGraphicsItem, public ChartItemControl
11 12 {
12 13 public:
13 14 StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0);
14 15
15 // From ChartItem
16 virtual void setSize(const QSize& size);
17 virtual void setPlotDomain(const PlotDomain& data);
16 public: // From ChartItemControl
17 void setPos(const QPointF & pos);
18 void resize(const QSize &size);
19 void setTheme(ChartTheme *theme);
20 void setPlotDomain(const PlotDomain& data);
18 21
19 // Layout "api"
22 public: // Layout "api"
20 23 void setPos(qreal x, qreal y);
21 24 void setBarWidth( int w ); // Default width for each bar
22 25
@@ -46,14 +46,10 QPainterPath PieSlice::shape() const
46 46
47 47 void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
48 48 {
49 // Setup painter
50 painter->setBrush(m_color);
51 49 painter->setRenderHint(QPainter::Antialiasing);
52 QPen pen;
53 //pen.setColor(m_color.darker());
54 pen.setColor(Qt::gray);
55 pen.setWidth(1);
56 painter->setPen(pen);
50 painter->setPen(m_theme.linePen);
51 // TODO:
52 painter->setBrush(m_theme.linePen.color());
57 53
58 54 // From Qt docs:
59 55 // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360).
@@ -2,6 +2,7
2 2 #define PIESLICE_H
3 3
4 4 #include "qchartglobal.h"
5 #include "charttheme_p.h"
5 6 #include <QGraphicsItem>
6 7 #include <QRectF>
7 8 #include <QColor>
@@ -25,6 +26,7 public:
25 26 qreal m_startAngle;
26 27 qreal m_span;
27 28 QRectF m_rect;
29 SeriesTheme m_theme;
28 30 };
29 31
30 32 QTCOMMERCIALCHART_END_NAMESPACE
@@ -3,6 +3,7
3 3 #include "qscatterseries.h"
4 4 #include "qscatterseries_p.h"
5 5 #include "qpieseries.h"
6 #include "qpieseries_p.h"
6 7 #include "qxychartseries.h"
7 8 #include "qchartaxis.h"
8 9 #include "barchartseries.h"
@@ -11,6 +12,8
11 12 #include "stackedbargroup.h"
12 13 #include "percentbarchartseries.h"
13 14 #include "percentbargroup.h"
15 #include "charttheme_p.h"
16 #include "chartitemcontrol.h"
14 17
15 18 #include "xylinechartitem_p.h"
16 19 #include "plotdomain_p.h"
@@ -25,16 +28,17 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
25 28 m_titleItem(0),
26 29 m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)),
27 30 m_plotDataIndex(0),
28 m_marginSize(0)
31 m_marginSize(0),
32 m_chartTheme(new ChartTheme())
29 33 {
30 34 // TODO: the default theme?
31 35 setTheme(QChart::ChartThemeDefault);
32 36
33 37 PlotDomain domain;
34 m_plotDomainList<<domain;
38 m_plotDomainList << domain;
35 39 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
36 m_chartItems<<m_axisXItem;
37 m_chartItems<<m_axisYItem.at(0);
40 m_chartItemControls << m_axisXItem;
41 m_chartItemControls << m_axisYItem.at(0);
38 42 }
39 43
40 44 QChart::~QChart(){}
@@ -55,11 +59,6 void QChart::addSeries(QChartSeries* series)
55 59 case QChartSeries::SeriesTypeLine: {
56 60
57 61 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
58 // Use color defined by theme in case the series does not define a custom color
59
60 if (!xyseries->pen().color().isValid() && m_themeColors.count()) //TODO: wtf
61 xyseries->setPen(nextColor());
62
63 62 m_plotDataIndex = 0 ;
64 63 m_plotDomainList.resize(1);
65 64
@@ -76,9 +75,12 void QChart::addSeries(QChartSeries* series)
76 75 }
77 76
78 77 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
79 m_chartItems<<item;
80 78
81 foreach(ChartItem* i ,m_chartItems)
79 // TODO: combine ChartItemControl and ChartItem apis
80 m_chartItemControls << item;
81 item->setTheme(m_chartTheme);
82
83 foreach(ChartItemControl* i, m_chartItemControls)
82 84 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
83 85
84 86 break;
@@ -96,7 +98,7 void QChart::addSeries(QChartSeries* series)
96 98 barGroup->addColor(QColor(0,0,255,128));
97 99 barGroup->addColor(QColor(255,128,0,128));
98 100
99 m_chartItems<<barGroup;
101 m_chartItemControls << barGroup;
100 102 childItems().append(barGroup);
101 103 break;
102 104 }
@@ -113,7 +115,7 void QChart::addSeries(QChartSeries* series)
113 115 stackedBarGroup->addColor(QColor(0,0,255,128));
114 116 stackedBarGroup->addColor(QColor(255,128,0,128));
115 117
116 m_chartItems<<stackedBarGroup;
118 m_chartItemControls << stackedBarGroup;
117 119 childItems().append(stackedBarGroup);
118 120 break;
119 121 }
@@ -130,31 +132,26 void QChart::addSeries(QChartSeries* series)
130 132 percentBarGroup->addColor(QColor(0,0,255,128));
131 133 percentBarGroup->addColor(QColor(255,128,0,128));
132 134
133 m_chartItems<<percentBarGroup;
135 m_chartItemControls << percentBarGroup;
134 136 childItems().append(percentBarGroup);
135 137 break;
136 138 }
137 139 case QChartSeries::SeriesTypeScatter: {
138 140 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
141 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
139 142 scatterSeries->d->setParentItem(this);
140 // Set pre-defined colors in case the series has no colors defined
141 if (!scatterSeries->markerColor().isValid())
142 scatterSeries->setMarkerColor(nextColor());
143 connect(this, SIGNAL(sizeChanged(QRectF)),
144 scatterSeries, SLOT(chartSizeChanged(QRectF)));
145 // QColor nextColor = m_themeColors.takeFirst();
146 // nextColor.setAlpha(150); // TODO: default opacity?
147 // scatterSeries->setMarkerColor(nextColor);
143 m_chartItemControls << scatterSeries->d;
144 //TODO:? scatterSeries->d->m_themeIndex = m_chartSeries.count() - 1;
148 145 break;
149 146 }
150 147 case QChartSeries::SeriesTypePie: {
151 148 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
152 for (int i(0); i < pieSeries->sliceCount(); i++) {
153 if (!pieSeries->sliceColor(i).isValid())
154 pieSeries->setSliceColor(i, nextColor());
155 }
156 connect(this, SIGNAL(sizeChanged(QRectF)),
157 pieSeries, SLOT(chartSizeChanged(QRectF)));
149 // for (int i(0); i < pieSeries->sliceCount(); i++) {
150 // if (!pieSeries->sliceColor(i).isValid())
151 // pieSeries->setSliceColor(i, nextColor());
152 // }
153 pieSeries->d->setTheme(m_chartTheme);
154 m_chartItemControls << pieSeries->d;
158 155
159 156 // Set pre-defined colors in case the series has no colors defined
160 157 // TODO: how to define the color for all the slices of a pie?
@@ -217,27 +214,19 void QChart::setSize(const QSize& size)
217 214 }
218 215
219 216 //recalculate background gradient
220 if(m_backgroundItem){
217 if (m_backgroundItem) {
221 218 m_backgroundItem->setRect(rect);
222 if(m_bacgroundOrinetation==HorizonatlGradientOrientation)
223 m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(),0);
219 if (m_bacgroundOrinetation == HorizonatlGradientOrientation)
220 m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0);
224 221 else
225 m_backgroundGradient.setFinalStop(0,m_backgroundItem->rect().height());
226
222 m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height());
227 223 m_backgroundItem->setBrush(m_backgroundGradient);
228 224 }
229 225
230 //resize elements
231 foreach (ChartItem* item ,m_chartItems) {
232 item->setPos(rect.topLeft());
233 item->setSize(rect.size());
234
226 foreach (ChartItemControl *ctrl, m_chartItemControls) {
227 ctrl->setPos(rect.topLeft());
228 ctrl->resize(rect.size());
235 229 }
236 // TODO: TTD for setting scale
237 //emit scaleChanged(100, 100);
238 // TODO: calculate the origo
239 // TODO: not sure if emitting a signal here is the best from performance point of view
240 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
241 230
242 231 update();
243 232 }
@@ -251,8 +240,8 void QChart::setBackground(const QColor& startColor, const QColor& endColor, Gra
251 240 }
252 241
253 242 m_bacgroundOrinetation = orientation;
254 m_backgroundGradient.setColorAt( 0.0, startColor);
255 m_backgroundGradient.setColorAt( 1.0, endColor);
243 m_backgroundGradient.setColorAt(0.0, startColor);
244 m_backgroundGradient.setColorAt(1.0, endColor);
256 245 m_backgroundGradient.setStart(0,0);
257 246
258 247 if(orientation == VerticalGradientOrientation){
@@ -285,86 +274,15 void QChart::setMargin(int margin)
285 274
286 275 void QChart::setTheme(QChart::ChartThemeId theme)
287 276 {
288 // if (theme != m_currentTheme) {
289 m_themeColors.clear();
290
291 // TODO: define color themes
292 switch (theme) {
293 case QChart::ChartThemeDefault:
294 // TODO: define the default theme based on the OS
295 m_themeColors.append(QColor(QRgb(0xff000000)));
296 m_themeColors.append(QColor(QRgb(0xff707070)));
297 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
298 break;
299 case QChart::ChartThemeVanilla:
300 m_themeColors.append(QColor(217, 197, 116));
301 m_themeColors.append(QColor(214, 168, 150));
302 m_themeColors.append(QColor(160, 160, 113));
303 m_themeColors.append(QColor(210, 210, 52));
304 m_themeColors.append(QColor(136, 114, 58));
305
306 setBackground(QColor(QRgb(0xff9d844d)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
307 break;
308 case QChart::ChartThemeIcy:
309 m_themeColors.append(QColor(0, 3, 165));
310 m_themeColors.append(QColor(49, 52, 123));
311 m_themeColors.append(QColor(71, 114, 187));
312 m_themeColors.append(QColor(48, 97, 87));
313 m_themeColors.append(QColor(19, 71, 90));
314 m_themeColors.append(QColor(110, 70, 228));
315
316 setBackground(QColor(QRgb(0xffe4ffff)), QColor(QRgb(0xffe4ffff)), VerticalGradientOrientation);
317 break;
318 case QChart::ChartThemeGrayscale:
319 m_themeColors.append(QColor(0, 0, 0));
320 m_themeColors.append(QColor(50, 50, 50));
321 m_themeColors.append(QColor(100, 100, 100));
322 m_themeColors.append(QColor(140, 140, 140));
323 m_themeColors.append(QColor(180, 180, 180));
324
325 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
326 break;
327 case QChart::ChartThemeUnnamed1:
328 m_themeColors.append(QColor(QRgb(0xff3fa9f5)));
329 m_themeColors.append(QColor(QRgb(0xff7AC943)));
330 m_themeColors.append(QColor(QRgb(0xffFF931E)));
331 m_themeColors.append(QColor(QRgb(0xffFF1D25)));
332 m_themeColors.append(QColor(QRgb(0xffFF7BAC)));
333
334 setBackground(QColor(QRgb(0xfff3dc9e)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
335 break;
336 default:
337 Q_ASSERT(false);
338 break;
339 }
340
341 if(m_backgroundItem){
342 m_backgroundItem->setBrush(m_backgroundGradient);
343 m_backgroundItem->setPen(Qt::NoPen);
344 }
345
346 foreach(QChartSeries* series, m_chartSeries) {
347 // TODO: other series interested on themes?
348 if (series->type() == QChartSeries::SeriesTypeLine) {
349 QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series);
350 lineseries->setPen(nextColor());
351 } else if (series->type() == QChartSeries::SeriesTypeScatter) {
352 QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
353 scatter->setMarkerColor(nextColor());
354 } else if (series->type() == QChartSeries::SeriesTypePie) {
355 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
356 for (int i(0); i < pieSeries->sliceCount(); i++)
357 pieSeries->setSliceColor(i, nextColor());
358 }
277 if (theme != m_chartTheme->d->m_currentTheme) {
278 m_chartTheme->d->setTheme(theme);
279 setBackground(m_chartTheme->d->m_gradientStartColor,
280 m_chartTheme->d->m_gradientEndColor,
281 m_bacgroundOrinetation);
282 foreach (ChartItemControl *ctrl, m_chartItemControls)
283 ctrl->setTheme(m_chartTheme);
284 update();
359 285 }
360 update();
361 }
362
363 QColor QChart::nextColor()
364 {
365 QColor nextColor = m_themeColors.first();
366 m_themeColors.move(0, m_themeColors.size() - 1);
367 return nextColor;
368 286 }
369 287
370 288 void QChart::zoomInToRect(const QRect& rectangle)
@@ -385,8 +303,8 void QChart::zoomInToRect(const QRect& rectangle)
385 303 m_plotDomainList<<domain;
386 304 m_plotDataIndex++;
387 305
388 foreach (ChartItem* item ,m_chartItems)
389 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
306 foreach (ChartItemControl* ctrl, m_chartItemControls)
307 ctrl->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
390 308 update();
391 309 }
392 310
@@ -394,7 +312,7 void QChart::zoomIn()
394 312 {
395 313 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
396 314 m_plotDataIndex++;
397 foreach (ChartItem* item ,m_chartItems)
315 foreach (ChartItemControl* item, m_chartItemControls)
398 316 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
399 317 update();
400 318 } else {
@@ -410,7 +328,7 void QChart::zoomOut()
410 328 {
411 329 if (m_plotDataIndex > 0) {
412 330 m_plotDataIndex--;
413 foreach (ChartItem* item ,m_chartItems)
331 foreach (ChartItemControl* item, m_chartItemControls)
414 332 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
415 333 update();
416 334 }
@@ -420,7 +338,7 void QChart::zoomReset()
420 338 {
421 339 if (m_plotDataIndex > 0) {
422 340 m_plotDataIndex = 0;
423 foreach (ChartItem* item ,m_chartItems)
341 foreach (ChartItemControl* item, m_chartItemControls)
424 342 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
425 343 update();
426 344 }
@@ -12,9 +12,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 12 class AxisItem;
13 13 class QChartSeries;
14 14 class PlotDomain;
15 class ChartItem;
16 15 class BarGroup;
17 16 class QChartAxis;
17 class ChartTheme;
18 class ChartItemControl;
18 19
19 20 // TODO: We don't need to have QChart tied to QGraphicsItem:
20 21 //class QTCOMMERCIALCHART_EXPORT QChart
@@ -33,8 +34,9 public:
33 34 VerticalGradientOrientation
34 35 };
35 36 enum ChartThemeId {
37 ChartThemeInvalid = -1,
36 38 /*! The default theme follows the GUI style of the Operating System */
37 ChartThemeDefault = 0,
39 ChartThemeDefault,
38 40 ChartThemeVanilla,
39 41 ChartThemeIcy,
40 42 ChartThemeGrayscale,
@@ -75,14 +77,7 public:
75 77 private:
76 78 void setAxis(AxisItem *item, const QChartAxis& axis);
77 79
78 signals:
79 //TODO chage to const QSize& size
80 void sizeChanged(QRectF rect);
81 void scaleChanged(qreal xscale, qreal yscale);
82
83 80 private:
84 QColor nextColor();
85
86 81 Q_DISABLE_COPY(QChart)
87 82 QGraphicsRectItem* m_backgroundItem;
88 83 QLinearGradient m_backgroundGradient;
@@ -91,12 +86,12 private:
91 86 AxisItem* m_axisXItem;
92 87 QList<AxisItem*> m_axisYItem;
93 88 QRect m_rect;
94 QList<QChartSeries*> m_chartSeries;
89 QList<QChartSeries *> m_chartSeries;
90 QList<ChartItemControl *> m_chartItemControls;
95 91 QVector<PlotDomain> m_plotDomainList;
96 QList<ChartItem*> m_chartItems;
97 92 int m_plotDataIndex;
98 93 int m_marginSize;
99 QList<QColor> m_themeColors;
94 ChartTheme *m_chartTheme;
100 95 };
101 96
102 97 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,78 +1,80
1 #include "qpieseries_p.h"
1 2 #include "qpieseries.h"
2 #include "pieslice.h"
3 3 #include <QGraphicsObject>
4 #include "pieslice.h"
4 5 #include <QDebug>
5 6
6 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 8
8 QPieSeries::QPieSeries(QGraphicsObject *parent) :
9 QChartSeries(parent),
9 QPieSeriesPrivate::QPieSeriesPrivate() :
10 10 m_sizeFactor(1.0),
11 m_position(PiePositionMaximized)
11 m_position(QPieSeries::PiePositionMaximized)
12 12 {
13 13 }
14 14
15 QPieSeries::~QPieSeries()
15 QPieSeriesPrivate::~QPieSeriesPrivate()
16 16 {
17 17 while (m_slices.count())
18 18 delete m_slices.takeLast();
19 19 }
20 20
21 bool QPieSeries::setData(QList<qreal> data)
21 bool QPieSeriesPrivate::setData(QList<qreal> data)
22 22 {
23 23 m_data = data;
24 24
25 // Create slices
26 qreal fullPie = 360;
27 qreal total = 0;
28 foreach (qreal value, m_data)
29 total += value;
25 if (m_parentItem) {
26 // Create slices
27 qreal fullPie = 360;
28 qreal total = 0;
29 foreach (qreal value, m_data)
30 total += value;
31
32 m_chartSize = m_parentItem->boundingRect();
33 qreal angle = 0;
34 // TODO: no need to create new slices in case size changed; we should re-use the existing ones
35 foreach (qreal value, m_data) {
36 qreal span = value / total * fullPie;
37 PieSlice *slice = new PieSlice(QColor(), angle, span, m_parentItem->boundingRect());
38 slice->setParentItem(m_parentItem);
39 m_slices.append(slice);
40 angle += span;
41 }
30 42
31 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
32 Q_ASSERT(parentItem);
33 m_chartSize = parentItem->boundingRect();
34 qreal angle = 0;
35 // TODO: no need to create new slices in case size changed; we should re-use the existing ones
36 foreach (qreal value, m_data) {
37 qreal span = value / total * fullPie;
38 PieSlice *slice = new PieSlice(QColor(), angle, span, parentItem->boundingRect());
39 slice->setParentItem(parentItem);
40 m_slices.append(slice);
41 angle += span;
43 setTheme(m_chartTheme);
44 resizeSlices(m_chartSize);
42 45 }
43 46
44 resizeSlices(m_chartSize);
45 47 return true;
46 48 }
47 49
48 void QPieSeries::setSliceColor(int index, QColor color)
50 void QPieSeriesPrivate::setPos(const QPointF & pos)
49 51 {
50 if (index >= 0 && index < m_slices.count())
51 m_slices.at(index)->m_color = color;
52 // TODO
52 53 }
53 54
54 QColor QPieSeries::sliceColor(int index)
55 void QPieSeriesPrivate::resize(const QSize &size)
55 56 {
56 if (index >= 0 && index < m_slices.count())
57 return m_slices.at(index)->m_color;
58 else
59 return QColor();
57 // TODO: allow user setting the size?
58 // TODO: allow user defining the margins?
59 m_chartSize = QRect(0, 0, size.width(), size.height());
60 resizeSlices(m_chartSize);
60 61 }
61 62
62 int QPieSeries::sliceCount()
63 void QPieSeriesPrivate::setTheme(ChartTheme *theme)
63 64 {
64 return m_slices.count();
65 if (theme) {
66 m_chartTheme = theme;
67 for (int i(0); i < m_slices.count(); i++)
68 m_slices.at(i)->m_theme = theme->themeForSeries();
69 }
65 70 }
66 71
67 void QPieSeries::chartSizeChanged(QRectF chartRect)
72 void QPieSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain)
68 73 {
69 // TODO: allow user setting the size?
70 // TODO: allow user defining the margins?
71 m_chartSize = chartRect;
72 resizeSlices(m_chartSize);
74 // TODO
73 75 }
74 76
75 void QPieSeries::resizeSlices(QRectF rect)
77 void QPieSeriesPrivate::resizeSlices(QRectF rect)
76 78 {
77 79 QRectF tempRect = rect;
78 80 if (tempRect.width() < tempRect.height()) {
@@ -86,25 +88,25 void QPieSeries::resizeSlices(QRectF rect)
86 88 }
87 89
88 90 switch (m_position) {
89 case PiePositionTopLeft: {
91 case QPieSeries::PiePositionTopLeft: {
90 92 tempRect.setHeight(tempRect.height() / 2);
91 93 tempRect.setWidth(tempRect.height());
92 94 tempRect.moveCenter(QPointF(rect.center().x() / 2, rect.center().y() / 2));
93 95 break;
94 96 }
95 case PiePositionTopRight: {
97 case QPieSeries::PiePositionTopRight: {
96 98 tempRect.setHeight(tempRect.height() / 2);
97 99 tempRect.setWidth(tempRect.height());
98 100 tempRect.moveCenter(QPointF((rect.center().x() / 2) * 3, rect.center().y() / 2));
99 101 break;
100 102 }
101 case PiePositionBottomLeft: {
103 case QPieSeries::PiePositionBottomLeft: {
102 104 tempRect.setHeight(tempRect.height() / 2);
103 105 tempRect.setWidth(tempRect.height());
104 106 tempRect.moveCenter(QPointF(rect.center().x() / 2, (rect.center().y() / 2) * 3));
105 107 break;
106 108 }
107 case PiePositionBottomRight: {
109 case QPieSeries::PiePositionBottomRight: {
108 110 tempRect.setHeight(tempRect.height() / 2);
109 111 tempRect.setWidth(tempRect.height());
110 112 tempRect.moveCenter(QPointF((rect.center().x() / 2) * 3, (rect.center().y() / 2) * 3));
@@ -118,23 +120,65 void QPieSeries::resizeSlices(QRectF rect)
118 120 slice->m_rect = tempRect;
119 121 }
120 122
123 QPieSeries::QPieSeries(QGraphicsObject *parent) :
124 QChartSeries(parent),
125 d(new QPieSeriesPrivate())
126 {
127 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent);
128 if (parentItem)
129 d->m_parentItem = parentItem;
130 }
131
132 QPieSeries::~QPieSeries()
133 {
134 delete d;
135 }
136
137 bool QPieSeries::setData(QList<qreal> data)
138 {
139 return d->setData(data);
140 }
141
142 void QPieSeries::setSliceColor(int index, QColor color)
143 {
144 if (index >= 0 && index < d->m_slices.count())
145 d->m_slices.at(index)->m_color = color;
146 }
147
148 QColor QPieSeries::sliceColor(int index)
149 {
150 if (index >= 0 && index < d->m_slices.count())
151 return d->m_slices.at(index)->m_color;
152 else
153 return QColor();
154 }
155
156 int QPieSeries::sliceCount()
157 {
158 return d->m_slices.count();
159 }
160
121 161 void QPieSeries::setSizeFactor(qreal factor)
122 162 {
123 163 if (factor > 0.0)
124 m_sizeFactor = factor;
125 resizeSlices(m_chartSize);
164 d->m_sizeFactor = factor;
165 d->resizeSlices(d->m_chartSize);
126 166
127 167 // Initiate update via the parent graphics item
128 168 // TODO: potential issue: what if this function is called from the parent context?
129 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
130 Q_ASSERT(parentItem);
131 parentItem->update();
169 if (d->m_parentItem)
170 d->m_parentItem->update();
171 }
172
173 qreal QPieSeries::sizeFactor()
174 {
175 return d->m_sizeFactor;
132 176 }
133 177
134 178 void QPieSeries::setPosition(PiePosition position)
135 179 {
136 m_position = position;
137 resizeSlices(m_chartSize);
180 d->m_position = position;
181 d->resizeSlices(d->m_chartSize);
138 182
139 183 // Initiate update via the parent graphics item
140 184 // TODO: potential issue: what if this function is called from the parent context?
@@ -8,6 +8,7
8 8
9 9 class QGraphicsObject;
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 class QPieSeriesPrivate;
11 12 class PieSlice;
12 13
13 14 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
@@ -37,23 +38,14 public:
37 38 QColor sliceColor(int index);
38 39 int sliceCount();
39 40 void setSizeFactor(qreal sizeFactor);
40 qreal sizeFactor() { return m_sizeFactor; }
41 qreal sizeFactor();
41 42 void setPosition(PiePosition position);
42 43
43 public Q_SLOTS:
44 void chartSizeChanged(QRectF rect);
45
46 44 private:
47 void resizeSlices(QRectF rect);
48 //Q_DECLARE_PRIVATE(QPieSeries)
45 Q_DECLARE_PRIVATE(QPieSeries)
49 46 Q_DISABLE_COPY(QPieSeries)
50 47 friend class QChart;
51 // TODO: move the followin to internal impl
52 QList<qreal> m_data;
53 QList<PieSlice*> m_slices;
54 QRectF m_chartSize;
55 qreal m_sizeFactor;
56 PiePosition m_position;
48 QPieSeriesPrivate *const d;
57 49 };
58 50
59 51 QTCOMMERCIALCHART_END_NAMESPACE
@@ -39,14 +39,19 QRectF QScatterSeriesPrivate::boundingRect() const
39 39
40 40 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
41 41 {
42 QPen pen = painter->pen();
43 QBrush brush = pen.brush();
44 // TODO: The opacity should be user definable...
42 // TODO: The opacity should be user definable?
45 43 //brush.setColor(QColor(255, 82, 0, 100));
46 brush.setColor(m_markerColor);
47 pen.setBrush(brush);
48 pen.setWidth(4);
49 painter->setPen(pen);
44 if (m_markerColor.isValid()) {
45 QPen pen = painter->pen();
46 QBrush brush = pen.brush();
47 brush.setColor(m_markerColor);
48 pen.setBrush(brush);
49 pen.setWidth(4);
50 painter->setPen(pen);
51 }
52 else
53 painter->setPen(m_theme.markerPen);
54 // brush.setColor(m_theme..lineColor);
50 55
51 56 // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize
52 57 // event right after construction or maybe given a size during initialization
@@ -57,6 +62,26 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsI
57 62 }
58 63 }
59 64
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
60 85 QScatterSeries::QScatterSeries(QObject *parent) :
61 86 QChartSeries(parent),
62 87 d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent)))
@@ -74,14 +99,6 bool QScatterSeries::setData(QList<qreal> x, QList<qreal> y)
74 99 return true;
75 100 }
76 101
77 void QScatterSeries::chartSizeChanged(QRectF rect)
78 {
79 // Recalculate scatter data point locations on the scene
80 // d->transform().reset();
81 // d->transform().translate();
82 d->resize(rect);
83 }
84
85 102 void QScatterSeries::setMarkerColor(QColor color)
86 103 {
87 104 d->m_markerColor = color;
@@ -21,7 +21,6 public: // from QChartSeries
21 21 bool setData(QList<qreal> x, QList<qreal> y);
22 22
23 23 public Q_SLOTS:
24 void chartSizeChanged(QRectF rect);
25 24 // TODO: also affects opacity of the marker...? To be documented
26 25 void setMarkerColor(QColor color);
27 26 QColor markerColor();
@@ -2,6 +2,8
2 2 #define QSCATTERSERIESPRIVATE_H
3 3
4 4 #include "qchartseries.h"
5 #include "charttheme_p.h"
6 #include "chartitemcontrol.h"
5 7 #include <QGraphicsItem>
6 8
7 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -9,16 +11,22 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 11 /*!
10 12 * The PIMPL class of QScatterSeries.
11 13 */
12 class QScatterSeriesPrivate : public QGraphicsItem
14 class QScatterSeriesPrivate : public QGraphicsItem, public ChartItemControl
13 15 {
14 16 public:
15 17 QScatterSeriesPrivate(QGraphicsItem *parent);
16 18
17 19 public: // from QGraphicsItem
20 void setPos(const QPointF & pos);
18 21 void resize(QRectF rect);
19 22 QRectF boundingRect() const;
20 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
21 24
25 public: // from ChartItemControl
26 void resize(const QSize &size);
27 void setTheme(ChartTheme *theme);
28 void setPlotDomain(const PlotDomain& data);
29
22 30 public:
23 31 // TODO: use the chart data class instead of list of x and y values?
24 32 QList<qreal> m_x;
@@ -28,8 +36,9 public:
28 36 QList<qreal> m_scenex;
29 37 QList<qreal> m_sceney;
30 38 QColor m_markerColor;
39 SeriesTheme m_theme;
31 40 };
32 41
33 42 QTCOMMERCIALCHART_END_NAMESPACE
34 43
35 #endif // QSCATTERSERIES_H
44 #endif // QSCATTERSERIESPRIVATE_H
@@ -30,16 +30,18 SOURCES += \
30 30 pieslice.cpp \
31 31 qchartview.cpp \
32 32 qchartseries.cpp \
33 qchartaxis.cpp
33 qchartaxis.cpp \
34 charttheme.cpp
34 35
35 36 PRIVATE_HEADERS += \
36 37 xylinechart/xylinechartitem_p.h \
37 38 plotdomain_p.h \
38 39 qscatterseries_p.h \
40 qpieseries_p.h \
39 41 pieslice.h \
40 42 axisitem_p.h \
41 chartitem_p.h
42
43 charttheme_p.h
44
43 45 PUBLIC_HEADERS += \
44 46 qchartseries.h \
45 47 qscatterseries.h \
@@ -57,7 +59,8 PUBLIC_HEADERS += \
57 59 qchartview.h \
58 60 qchartaxis.h
59 61
60 HEADERS += $$PUBLIC_HEADERS
62 HEADERS += $$PUBLIC_HEADERS \
63 chartitemcontrol.h
61 64 HEADERS += $$PRIVATE_HEADERS
62 65
63 66 INCLUDEPATH += xylinechart \
@@ -97,3 +100,11 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
97 100 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
98 101
99 102
103
104
105
106
107
108
109
110
@@ -7,19 +7,33
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent):ChartItem(parent),
11 m_series(series),
12 m_pathItem(new QGraphicsPathItem(this))
10 XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent) :
11 QGraphicsItem(parent),
12 m_series(series),
13 m_pathItem(new QGraphicsPathItem(this))
13 14 {
14 15 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
15 16 }
16 17
17 void XYLineChartItem::setSize(const QSize& size)
18 void XYLineChartItem::setPos(const QPointF & pos)
18 19 {
19 m_rect=QRect(0,0,size.width(),size.height());
20 QGraphicsItem::setPos(pos);
21 }
22
23 void XYLineChartItem::resize(const QSize &size)
24 {
25 m_rect = QRect(0, 0, size.width(), size.height());
20 26 prepareGeometryChange();
21 27 updateGeometry();
28 }
22 29
30 void XYLineChartItem::setTheme(ChartTheme *theme)
31 {
32 if (theme) {
33 m_theme = theme->themeForSeries();
34 prepareGeometryChange();
35 updateGeometry();
36 }
23 37 }
24 38
25 39 void XYLineChartItem::setPlotDomain(const PlotDomain& data)
@@ -59,7 +73,7 void XYLineChartItem::updateGeometry()
59 73 }
60 74
61 75 m_pathItem->setPath(path);
62 m_pathItem->setPen(m_series->pen());
76 m_pathItem->setPen(m_theme.linePen);
63 77 m_pathItem->setBrush(Qt::NoBrush);
64 78 }
65 79
@@ -2,13 +2,15
2 2 #define XYLINECHARTITEM_H
3 3
4 4 #include "qchartglobal.h"
5 #include "chartitem_p.h"
5 #include "chartitemcontrol.h"
6 #include "charttheme_p.h"
7 #include <QGraphicsItem>
6 8
7 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 10
9 11 class QXYChartSeries;
10 12
11 class XYLineChartItem : public ChartItem
13 class XYLineChartItem : public QGraphicsItem, public ChartItemControl
12 14 {
13 15
14 16 public:
@@ -19,8 +21,11 public:
19 21 QRectF boundingRect() const;
20 22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
21 23 // virtual QPainterPath shape() const;
22 //from ChartItem
23 void setSize(const QSize& size);
24
25 public: // from ChartItemControl
26 void setPos(const QPointF & pos);
27 void resize(const QSize &size);
28 void setTheme(ChartTheme *theme);
24 29 void setPlotDomain(const PlotDomain& data);
25 30
26 31 private:
@@ -32,6 +37,7 private:
32 37 QXYChartSeries* m_series;
33 38 PlotDomain m_plotDomain;
34 39 QGraphicsPathItem *m_pathItem;
40 SeriesTheme m_theme;
35 41 };
36 42
37 43 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,2 +1,5
1 1 TEMPLATE = subdirs
2 2 SUBDIRS += chartwidgettest
3
4
5
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now