##// END OF EJS Templates
Implementing slice label
Jani Honkonen -
r181:f52f5b858a82
parent child
Show More
@@ -1,135 +1,142
1 #include "pieslice.h"
1 #include "pieslice.h"
2 #include "pieslicelabel.h"
2 #include "pieslicelabel.h"
3 #include "piepresenter.h"
3 #include "piepresenter.h"
4 #include "qpieseries.h"
4 #include "qpieseries.h"
5 #include <QPainter>
5 #include <QPainter>
6 #include <QDebug>
6 #include <QDebug>
7 #include <qmath.h>
7 #include <qmath.h>
8 #include <QGraphicsSceneEvent>
8 #include <QGraphicsSceneEvent>
9 #include <QTime>
9 #include <QTime>
10
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
12
13 #define PI 3.14159265
13 #define PI 3.14159265
14 #define EXPLODE_OFFSET 20
14 #define EXPLODE_OFFSET 20
15
15
16 QPointF offset(qreal angle, qreal length)
16 QPointF offset(qreal angle, qreal length)
17 {
17 {
18 qreal dx = qSin(angle*(PI/180)) * length;
18 qreal dx = qSin(angle*(PI/180)) * length;
19 qreal dy = qCos(angle*(PI/180)) * length;
19 qreal dy = qCos(angle*(PI/180)) * length;
20 return QPointF(dx, -dy);
20 return QPointF(dx, -dy);
21 }
21 }
22
22
23 PieSlice::PieSlice(QPieSliceId id, QPieSeries *series, QGraphicsItem* parent)
23 PieSlice::PieSlice(QPieSliceId id, QPieSeries *series, QGraphicsItem* parent)
24 :QGraphicsObject(parent),
24 :QGraphicsObject(parent),
25 m_id(id),
25 m_id(id),
26 m_series(series),
26 m_series(series),
27 m_slicelabel(new PieSliceLabel(this)),
27 m_slicelabel(new PieSliceLabel(this)),
28 m_isHovering(false)
28 m_isHovering(false)
29 {
29 {
30 Q_ASSERT(series);
30 Q_ASSERT(series);
31 setAcceptHoverEvents(true);
31 setAcceptHoverEvents(true);
32 setAcceptedMouseButtons(Qt::LeftButton);
32 setAcceptedMouseButtons(Qt::LeftButton);
33 updateData();
33 updateData();
34 }
34 }
35
35
36 PieSlice::~PieSlice()
36 PieSlice::~PieSlice()
37 {
37 {
38 qDebug() << "~PieSlice()" << m_id;
38 qDebug() << "~PieSlice()" << m_id;
39 }
39 }
40
40
41 QRectF PieSlice::boundingRect() const
41 QRectF PieSlice::boundingRect() const
42 {
42 {
43 return m_rect;
43 return m_rect;
44 }
44 }
45
45
46 QPainterPath PieSlice::shape() const
46 QPainterPath PieSlice::shape() const
47 {
47 {
48 return m_path;
48 return m_path;
49 }
49 }
50
50
51 void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
51 void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
52 {
52 {
53 // set hover brush
53 // set hover brush
54 // TODO: what if we are using gradients...
54 // TODO: what if we are using gradients...
55 QBrush brush = m_data.brush();
55 QBrush brush = m_data.brush();
56 if (m_isHovering)
56 if (m_isHovering)
57 brush.setColor(brush.color().lighter());
57 brush.setColor(brush.color().lighter());
58
58
59 painter->setRenderHint(QPainter::Antialiasing);
59 painter->setRenderHint(QPainter::Antialiasing);
60 painter->setPen(m_data.pen());
60 painter->setPen(m_data.pen());
61 painter->setBrush(brush);
61 painter->setBrush(brush);
62 painter->drawPath(m_path);
62 painter->drawPath(m_path);
63 }
63 }
64
64
65 void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
65 void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
66 {
66 {
67 m_isHovering = true;
67 m_isHovering = true;
68 update();
68 update();
69 // TODO: emit hoverEnter()
69 // TODO: emit hoverEnter()
70 }
70 }
71
71
72 void PieSlice::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
72 void PieSlice::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
73 {
73 {
74 m_isHovering = false;
74 m_isHovering = false;
75 update();
75 update();
76 // TODO: emit hoverLeave()
76 // TODO: emit hoverLeave()
77 }
77 }
78
78
79 void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
79 void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
80 {
80 {
81 // TODO: emit clicked
81 // TODO: emit clicked
82 // TODO: should we let the user decide if this can be exploded?
82 // TODO: should we let the user decide if this can be exploded?
83 m_data.setExploded(!m_data.isExploded());
83 m_data.setExploded(!m_data.isExploded());
84 m_series->update(m_data);
84 m_series->update(m_data);
85 }
85 }
86
86
87 void PieSlice::updateGeometry(QRectF rect, qreal startAngle, qreal span)
87 void PieSlice::updateGeometry(QRectF rect, qreal startAngle, qreal span)
88 {
88 {
89 prepareGeometryChange();
89 prepareGeometryChange();
90
90
91 // calculate center angle
91 // calculate center angle
92 qreal centerAngle = startAngle + (span/2);
92 qreal centerAngle = startAngle + (span/2);
93
93
94 // adjust rect for exploding
94 // adjust rect for exploding
95 rect.adjust(EXPLODE_OFFSET, EXPLODE_OFFSET, -EXPLODE_OFFSET ,-EXPLODE_OFFSET);
95 rect.adjust(EXPLODE_OFFSET, EXPLODE_OFFSET, -EXPLODE_OFFSET ,-EXPLODE_OFFSET);
96 if (m_data.isExploded()) {
96 if (m_data.isExploded()) {
97 QPointF d = offset((centerAngle), EXPLODE_OFFSET);
97 QPointF d = offset((centerAngle), EXPLODE_OFFSET);
98 rect.translate(d.x(), d.y());
98 rect.translate(d.x(), d.y());
99 }
99 }
100
100
101 // update slice path
101 // update slice path
102 // TODO: draw the shape so that it might have a hole in the center
102 // TODO: draw the shape so that it might have a hole in the center
103 QPainterPath path;
103 QPainterPath path;
104 path.moveTo(rect.center());
104 path.moveTo(rect.center());
105 path.arcTo(rect, -startAngle + 90, -span);
105 path.arcTo(rect, -startAngle + 90, -span);
106 m_path = path;
106 m_path = path;
107 m_rect = path.boundingRect();
107 m_rect = path.boundingRect();
108
108
109 // update label position
109 // update label position
110 qreal radius = rect.height() / 2;
110 qreal radius = rect.height() / 2;
111 QPointF edgeCenter = rect.center() + offset(centerAngle, radius + 5);
111 QPointF edgeCenter = rect.center() + offset(centerAngle, radius + 5);
112 m_slicelabel->updateGeometry(edgeCenter, centerAngle, 50);
112
113 m_slicelabel->setArmStartPoint(edgeCenter);
114 m_slicelabel->setArmAngle(centerAngle);
115 m_slicelabel->setArmLength(50);
116 m_slicelabel->updateGeometry();
113
117
114 //qDebug() << "PieSlice::updateGeometry" << m_rect;
118 //qDebug() << "PieSlice::updateGeometry" << m_rect;
115 }
119 }
116
120
117 void PieSlice::updateData()
121 void PieSlice::updateData()
118 {
122 {
119 if (!m_series->m_slices.contains(m_id))
123 if (!m_series->m_slices.contains(m_id))
120 qWarning() << "PieSlice::updateData(): cannot find slice data!" << m_id;
124 qWarning() << "PieSlice::updateData(): cannot find slice data!" << m_id;
121
125
122 QPieSlice data = m_series->slice(m_id);
126 QPieSlice data = m_series->slice(m_id);
123 // TODO: find out what has changed and trigger some animation
127 // TODO: find out what has changed and trigger some animation
124 m_data = data;
128 m_data = data;
125
129
126 update();
130 update();
127
131
128 m_slicelabel->setLabel(m_data.label());
129 m_slicelabel->setVisible(m_data.isLabelVisible());
132 m_slicelabel->setVisible(m_data.isLabelVisible());
133 m_slicelabel->setText(m_data.label());
134 //m_slicelabel->setPen(m_data.labelPen());
135 //m_slicelabel->setFont(m_data.labelFont());
136 m_slicelabel->updateGeometry(); // text size & font modifies the geometry
130 m_slicelabel->update();
137 m_slicelabel->update();
131 }
138 }
132
139
133 #include "moc_pieslice.cpp"
140 #include "moc_pieslice.cpp"
134
141
135 QTCOMMERCIALCHART_END_NAMESPACE
142 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,76 +1,64
1 #include "pieslicelabel.h"
1 #include "pieslicelabel.h"
2 #include <QPainter>
2 #include <QPainter>
3 #include <qmath.h>
3 #include <qmath.h>
4 #include <QGraphicsTextItem>
4
5
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
7
7 #define PI 3.14159265
8 #define PI 3.14159265
8
9
9 PieSliceLabel::PieSliceLabel(QGraphicsItem* parent)
10 PieSliceLabel::PieSliceLabel(QGraphicsItem* parent)
10 :QGraphicsItem(parent)
11 :QGraphicsItem(parent)
11 {
12 {
13 // set defaults
12 m_pen = QPen(Qt::black);
14 m_pen = QPen(Qt::black);
13 }
15 }
14
16
15 PieSliceLabel::~PieSliceLabel()
16 {
17
18 }
19
20 QRectF PieSliceLabel::boundingRect() const
21 {
22 return m_rect;
23 }
24
25 QPainterPath PieSliceLabel::shape() const
26 {
27 return m_path;
28 }
29
30 void PieSliceLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
17 void PieSliceLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
31 {
18 {
32 painter->setRenderHint(QPainter::Antialiasing);
19 painter->setRenderHint(QPainter::Antialiasing);
20
33 painter->setPen(m_pen);
21 painter->setPen(m_pen);
34 painter->drawPath(m_path);
22 painter->drawPath(m_armPath);
23
24 // TODO: do we need a pen for text?
25 painter->setFont(m_font);
26 painter->drawText(m_textRect, m_text);
35 }
27 }
36
28
37 void PieSliceLabel::updateGeometry(const QPointF& startPoint, qreal armAngle, qreal armLength)
29 void PieSliceLabel::updateGeometry()
38 {
30 {
39 prepareGeometryChange();
31 prepareGeometryChange();
40
32
41 QPainterPath path;
33 // calculate text size
42 path.moveTo(startPoint);
34 QFontMetricsF fm(m_font);
35 QRectF textRect = fm.boundingRect(m_text);
43
36
44 // draw arm
37 // calculate path for arm and text start point
45 qreal dx = qSin(armAngle*(PI/180)) * armLength;
38 qreal dx = qSin(m_armAngle*(PI/180)) * m_armLength;
46 qreal dy = -qCos(armAngle*(PI/180)) * armLength;
39 qreal dy = -qCos(m_armAngle*(PI/180)) * m_armLength;
47 QPointF p1 = startPoint + QPointF(dx, dy);
40 QPointF parm1 = m_armStartPoint + QPointF(dx, dy);
48 path.lineTo(p1);
49
41
50 QPointF p2 = p1;
42 // calculate horizontal arm and text position
51 QPointF pt = p1;
43 QPointF parm2 = parm1;
52 if (armAngle < 180) {
44 textRect.moveBottomLeft(parm1);
53 p2 += QPointF(50, 0);
45 if (m_armAngle < 180) { // arm swings the other way on the left side
46 parm2 += QPointF(m_textRect.width(), 0);
54 } else {
47 } else {
55 p2 += QPointF(-50,0);
48 parm2 += QPointF(-m_textRect.width(),0);
56 pt = p2;
49 textRect.moveBottomLeft(parm2);
57 }
58 path.lineTo(p2);
59
60 QFont font;
61 pt += QPointF(0,-2);
62 path.addText(pt, font, m_label);
63
64 m_path = path;
65 m_rect = path.boundingRect();
66 }
50 }
67
51
68 void PieSliceLabel::setLabel(QString label)
52 // update arm path
69 {
53 QPainterPath path;
70 m_label = label;
54 path.moveTo(m_armStartPoint);
71 // TODO: animation?
55 path.lineTo(parm1);
56 path.lineTo(parm2);
57
58 // update paths & rects
59 m_armPath = path;
60 m_textRect = textRect;
61 m_rect = path.boundingRect().united(m_textRect);
72 }
62 }
73
63
74
75
76 QTCOMMERCIALCHART_END_NAMESPACE
64 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,36 +1,57
1 #ifndef PIELABEL_H
1 #ifndef PIELABEL_H
2 #define PIELABEL_H
2 #define PIELABEL_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QGraphicsItem>
5 #include <QGraphicsItem>
6 #include <QPen>
6 #include <QPen>
7 #include <QFontMetricsF>
7
8
9 class QGraphicsTextItem;
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
11
10 class PieSliceLabel : public QGraphicsItem
12 class PieSliceLabel : public QGraphicsItem
11 {
13 {
12 public:
14 public:
13 PieSliceLabel(QGraphicsItem* parent = 0);
15 PieSliceLabel(QGraphicsItem* parent = 0);
14 ~PieSliceLabel();
16 ~PieSliceLabel() {};
15
17
16 public: // from QGraphicsItem
18 public: // from QGraphicsItem
17 QRectF boundingRect() const;
19 QRectF boundingRect() const { return m_rect; }
18 QPainterPath shape() const;
19 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
20
21
21 public:
22 public:
22 void updateGeometry(const QPointF& startPoint, qreal armAngle, qreal armLength);
23 void updateGeometry();
23 void setLabel(QString label);
24
24 QString label() const {return m_label;}
25 void setArmStartPoint(QPointF point) { m_armStartPoint = point; }
25 void setPen(QPen pen);
26 QPointF armStartPoint() const { return m_armStartPoint; }
27
28 void setArmAngle(qreal angle) { m_armAngle = angle; }
29 qreal armAngle() const { return m_armAngle; }
30
31 void setArmLength(qreal len) { m_armLength = len; }
32 qreal armLength() const { return m_armLength; }
33
34 void setText(QString text) { m_text = text; }
35 QString text() const { return m_text; }
36
37 void setPen(QPen pen) { m_pen = pen; }
38 QPen pen() const { return m_pen; }
39
40 void setFont(QFont font) { m_font = font; }
41 QFont font() const { return m_font; }
26
42
27 private:
43 private:
28 QString m_label;
44 QPointF m_armStartPoint;
29 QPainterPath m_path;
45 qreal m_armAngle;
46 qreal m_armLength;
47 QString m_text;
30 QRectF m_rect;
48 QRectF m_rect;
49 QPainterPath m_armPath;
50 QRectF m_textRect;
31 QPen m_pen;
51 QPen m_pen;
52 QFont m_font;
32 };
53 };
33
54
34 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
35
56
36 #endif // PIELABEL_H
57 #endif // PIELABEL_H
@@ -1,157 +1,163
1 #ifndef PIESERIES_H
1 #ifndef PIESERIES_H
2 #define PIESERIES_H
2 #define PIESERIES_H
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
8 #include <QPen>
8 #include <QPen>
9 #include <QBrush>
9 #include <QBrush>
10
10
11 class QGraphicsObject;
11 class QGraphicsObject;
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 class PiePresenter;
13 class PiePresenter;
14 class PieSlice;
14 class PieSlice;
15
15
16 typedef quint64 QPieSliceId;
16 typedef quint64 QPieSliceId;
17
17
18 class QPieSlice
18 class QPieSlice
19 {
19 {
20 public:
20 public:
21 QPieSlice()
21 QPieSlice()
22 :m_id(-1), m_value(0), m_isLabelVisible(true), m_isExploded(false), m_percentage(0) {}
22 :m_id(-1), m_value(0), m_isLabelVisible(true), m_isExploded(false), m_percentage(0) {}
23
23
24 QPieSlice(qreal value, QString label = QString(), bool labelVisible = true, bool exploded = false, QPen pen = QPen(), QBrush brush = QBrush())
24 QPieSlice(qreal value, QString label = QString(), bool labelVisible = true, bool exploded = false, QPen pen = QPen(), QBrush brush = QBrush())
25 :m_id(-1), m_value(value), m_label(label), m_isLabelVisible(labelVisible), m_isExploded(exploded), m_pen(pen), m_brush(brush), m_percentage(0) {}
25 :m_id(-1), m_value(value), m_label(label), m_isLabelVisible(labelVisible), m_isExploded(exploded), m_pen(pen), m_brush(brush), m_percentage(0) {}
26
26
27 QPieSliceId id() const { return m_id; }
27 QPieSliceId id() const { return m_id; }
28
28
29 void setValue(qreal value) { m_value = value; }
29 void setValue(qreal value) { m_value = value; }
30 qreal value() const { return m_value; }
30 qreal value() const { return m_value; }
31
31
32 void setLabel(QString label) { m_label = label; }
32 void setLabel(QString label) { m_label = label; }
33 QString label() const { return m_label; }
33 QString label() const { return m_label; }
34
34
35 void setLabelVisible(bool visible) { m_isLabelVisible = visible; }
35 void setLabelVisible(bool visible) { m_isLabelVisible = visible; }
36 bool isLabelVisible() const { return m_isLabelVisible; }
36 bool isLabelVisible() const { return m_isLabelVisible; }
37
37
38 // TODO:
39 //void setLabelPen(QPen pen) {};
40 //QPen labelPen() const {};
41 //void setLabelFont(QFont font);
42 //QFont labelFont() const;
43 //void setLabelArmLenght(qreal len) {};
44 //qreal labelArmLenght() const {};
45
38 void setExploded(bool exploded) { m_isExploded = exploded; }
46 void setExploded(bool exploded) { m_isExploded = exploded; }
39 bool isExploded() const { return m_isExploded; }
47 bool isExploded() const { return m_isExploded; }
40
48
41 void setPen(QPen pen) { m_pen = pen; }
49 void setPen(QPen pen) { m_pen = pen; }
42 QPen pen() const { return m_pen; }
50 QPen pen() const { return m_pen; }
43
51
44 void setBrush(QBrush brush) { m_brush = brush; }
52 void setBrush(QBrush brush) { m_brush = brush; }
45 QBrush brush() const { return m_brush; }
53 QBrush brush() const { return m_brush; }
46
54
47 qreal percentage() const { return m_percentage; }
55 qreal percentage() const { return m_percentage; }
48
56
49 private:
57 private:
50
58
51 // TODO: use private class
59 // TODO: use private class
52 friend class QPieSeries;
60 friend class QPieSeries;
53
61
54 QPieSliceId m_id;
62 QPieSliceId m_id;
55 qreal m_value;
63 qreal m_value;
56 QString m_label;
64 QString m_label;
57 bool m_isLabelVisible;
65 bool m_isLabelVisible;
58 bool m_isExploded;
66 bool m_isExploded;
59
67
60 QPen m_pen;
68 QPen m_pen;
61 QBrush m_brush;
69 QBrush m_brush;
62
70
63 qreal m_percentage; // generated content
71 qreal m_percentage; // generated content
64 };
72 };
65
73
66 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
74 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
67 {
75 {
68 Q_OBJECT
76 Q_OBJECT
69
77
70 public:
78 public:
71 enum PiePosition {
79 enum PiePosition {
72 PiePositionMaximized = 0,
80 PiePositionMaximized = 0,
73 PiePositionTopLeft,
81 PiePositionTopLeft,
74 PiePositionTopRight,
82 PiePositionTopRight,
75 PiePositionBottomLeft,
83 PiePositionBottomLeft,
76 PiePositionBottomRight
84 PiePositionBottomRight
77 };
85 };
78
86
79 class ChangeSet
87 class ChangeSet
80 {
88 {
81 public:
89 public:
82 QList<QPieSliceId> m_added;
90 QList<QPieSliceId> m_added;
83 QList<QPieSliceId> m_removed;
91 QList<QPieSliceId> m_removed;
84 QList<QPieSliceId> m_changed;
92 QList<QPieSliceId> m_changed;
85 };
93 };
86
94
87 public:
95 public:
88 QPieSeries(QObject *parent = 0);
96 QPieSeries(QObject *parent = 0);
89 ~QPieSeries();
97 ~QPieSeries();
90
98
91 public: // from QChartSeries
99 public: // from QChartSeries
92 QChartSeriesType type() const { return QChartSeries::SeriesTypePie; }
100 QChartSeriesType type() const { return QChartSeries::SeriesTypePie; }
93 virtual bool setData(QList<qreal> data); // TODO: remove this
101 virtual bool setData(QList<qreal> data); // TODO: remove this
94
102
95 public:
103 public:
96 // TODO: should we return id/bool or what?
104 // TODO: should we return id/bool or what?
97 // TODO: should we prefer passing a modifiable reference?
105 // TODO: should we prefer passing a modifiable reference?
98 bool set(const QList<QPieSlice>& slices);
106 bool set(const QList<QPieSlice>& slices);
99 bool add(const QList<QPieSlice>& slices);
107 bool add(const QList<QPieSlice>& slices);
100 bool add(const QPieSlice& slice);
108 bool add(const QPieSlice& slice);
101 bool update(const QPieSlice& slice);
109 bool update(const QPieSlice& slice);
102 bool remove(QPieSliceId id);
110 bool remove(QPieSliceId id);
103
111
104 int count() const { return m_slices.count(); }
112 int count() const { return m_slices.count(); }
105
113
106 QList<QPieSlice> slices() const { return m_slices.values(); }
114 QList<QPieSlice> slices() const { return m_slices.values(); }
107 QList<QPieSliceId> ids() const { return m_slices.keys(); }
115 QList<QPieSliceId> ids() const { return m_slices.keys(); }
108 QPieSlice slice(QPieSliceId id) const;
116 QPieSlice slice(QPieSliceId id) const;
109
117
110 // TODO: sorting?
118 // TODO: sorting?
111
119
112 // TODO: convenience functions
120 // TODO: convenience functions?
113 //void updateValue(int sliceIndex, qreal value);
121 //void setValue(QPieSliceId id, qreal value);
114 //void updateLabel(int sliceIndex, QString label);
122 //void setLabel(QPieSliceId id, QString label);
115 //void updateColor(int sliceIndex, QColor color);
123 //void setPen(QPieSliceId id, QPen pen);
116 //void updateExploded(int slizeIndex, bool exploded);
124 //void setBrush(QPieSliceId id, QBrush brush);
117
125 //void setExploded(QPieSliceId id, bool exploded);
118 // TODO: customization
119 // set/get pen/brush
120 // - for label
121 // - for whole pie/slice
122
126
123 void setSizeFactor(qreal sizeFactor);
127 void setSizeFactor(qreal sizeFactor);
124 qreal sizeFactor() const { return m_sizeFactor; }
128 qreal sizeFactor() const { return m_sizeFactor; }
125
129
126 void setPosition(PiePosition position);
130 void setPosition(PiePosition position);
127 PiePosition position() const { return m_position; }
131 PiePosition position() const { return m_position; }
128
132
129 Q_SIGNALS:
133 Q_SIGNALS:
130 void changed(const QPieSeries::ChangeSet& changeSet);
134 void changed(const QPieSeries::ChangeSet& changeSet);
131 void sizeFactorChanged();
135 void sizeFactorChanged();
132 void positionChanged();
136 void positionChanged();
137
138 // TODO:
133 //void sliceClicked(QPieSliceId id);
139 //void sliceClicked(QPieSliceId id);
134 //void sliceHoverEnter(QPieSliceId id);
140 // ?? void sliceHoverEnter(QPieSliceId id);
135 //void sliceHoverLeave(QPieSliceId id);
141 // ?? void sliceHoverLeave(QPieSliceId id);
136
142
137 private:
143 private:
138 QPieSliceId generateSliceId();
144 QPieSliceId generateSliceId();
139 void updateDerivativeData();
145 void updateDerivativeData();
140
146
141 private:
147 private:
142 Q_DISABLE_COPY(QPieSeries)
148 Q_DISABLE_COPY(QPieSeries)
143
149
144 // TODO: use PIML
150 // TODO: use PIML
145 friend class PiePresenter;
151 friend class PiePresenter;
146 friend class PieSlice;
152 friend class PieSlice;
147
153
148 QHash<QPieSliceId, QPieSlice> m_slices;
154 QHash<QPieSliceId, QPieSlice> m_slices;
149 qreal m_sizeFactor;
155 qreal m_sizeFactor;
150 PiePosition m_position;
156 PiePosition m_position;
151 qreal m_total;
157 qreal m_total;
152 QPieSliceId m_sliceIdSeed;
158 QPieSliceId m_sliceIdSeed;
153 };
159 };
154
160
155 QTCOMMERCIALCHART_END_NAMESPACE
161 QTCOMMERCIALCHART_END_NAMESPACE
156
162
157 #endif // PIESERIES_H
163 #endif // PIESERIES_H
General Comments 0
You need to be logged in to leave comments. Login now