##// END OF EJS Templates
more intelligent legend. fixed compiler warning in bar.cpp
sauimone -
r565:b4a66ce9ee2b
parent child
Show More
@@ -1,56 +1,56
1 #ifndef BAR_H
1 #ifndef BAR_H
2 #define BAR_H
2 #define BAR_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QGraphicsObject>
5 #include <QGraphicsObject>
6 #include <QPen>
6 #include <QPen>
7 #include <QBrush>
7 #include <QBrush>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 // Single visual bar item of chart
11 // Single visual bar item of chart
12 class Bar : public QGraphicsObject
12 class Bar : public QGraphicsObject
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 Bar(QString category, QGraphicsItem *parent=0);
16 Bar(QString category, QGraphicsItem *parent=0);
17
17
18 public: // from ChartItem
18 public: // from ChartItem
19 void setSize(const QSizeF &size);
19 void setSize(const QSizeF &size);
20
20
21 // Layout Stuff
21 // Layout Stuff
22 void resize(qreal w, qreal h);
22 void resize(qreal w, qreal h);
23 void setPos(qreal x, qreal y);
23 void setPos(qreal x, qreal y);
24 void setPen(QPen pen);
24 void setPen(QPen pen);
25 void setBrush(QBrush brush);
25 void setBrush(QBrush brush);
26
26
27 public:
27 public:
28 // From QGraphicsItem
28 // From QGraphicsItem
29 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
29 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
30 QRectF boundingRect() const;
30 QRectF boundingRect() const;
31 void mousePressEvent(QGraphicsSceneMouseEvent *event);
31 void mousePressEvent(QGraphicsSceneMouseEvent *event);
32 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
32 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
33 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
33 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
34
34
35 Q_SIGNALS:
35 Q_SIGNALS:
36 void clicked(QString category);
36 void clicked(QString category);
37 void rightClicked(QString category);
37 void rightClicked(QString category);
38 void hoverEntered(QPoint pos);
38 void hoverEntered(QPoint pos);
39 void hoverLeaved();
39 void hoverLeaved();
40
40
41 private:
41 private:
42
42
43 qreal mHeight;
44 qreal mWidth;
45 qreal mXpos;
43 qreal mXpos;
46 qreal mYpos;
44 qreal mYpos;
45 qreal mWidth;
46 qreal mHeight;
47
47
48 QBrush mBrush;
48 QBrush mBrush;
49 QPen mPen;
49 QPen mPen;
50
50
51 QString mCategory;
51 QString mCategory;
52 };
52 };
53
53
54 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
55
55
56 #endif // BAR_H
56 #endif // BAR_H
@@ -1,63 +1,121
1 #include "qchartglobal.h"
1 #include "qchartglobal.h"
2 #include "legendmarker_p.h"
2 #include "legendmarker_p.h"
3 #include <QPainter>
3 #include <QPainter>
4 #include <QGraphicsSceneEvent>
4 #include <QGraphicsSceneEvent>
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 LegendMarker::LegendMarker(QSeries* series, QGraphicsItem *parent)
8 LegendMarker::LegendMarker(QSeries* series, QGraphicsItem *parent)
9 : QGraphicsObject(parent)
9 : QGraphicsObject(parent)
10 ,mBoundingRect(0,0,1,1)
11 ,mName("")
10 ,mSeries(series)
12 ,mSeries(series)
13 ,mBarset(0)
14 ,mPieslice(0)
15 ,mType(LegendMarkerTypeSeries)
16 {
17 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
18 }
19
20 LegendMarker::LegendMarker(QBarSet* barset, QGraphicsItem *parent)
21 : QGraphicsObject(parent)
22 ,mBoundingRect(0,0,1,1)
23 ,mName("")
24 ,mSeries(0)
25 ,mBarset(barset)
26 ,mPieslice(0)
27 ,mType(LegendMarkerTypeBarset)
28 {
29 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
30 }
31
32 LegendMarker::LegendMarker(QPieSlice* pieslice, QGraphicsItem *parent)
33 : QGraphicsObject(parent)
11 ,mBoundingRect(0,0,1,1)
34 ,mBoundingRect(0,0,1,1)
35 ,mName("")
36 ,mSeries(0)
37 ,mBarset(0)
38 ,mPieslice(pieslice)
39 ,mType(LegendMarkerTypePieslice)
12 {
40 {
13 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
41 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
14 }
42 }
15
43
16 void LegendMarker::setBoundingRect(const QRectF rect)
44 void LegendMarker::setBoundingRect(const QRectF rect)
17 {
45 {
18 mBoundingRect = rect;
46 mBoundingRect = rect;
19 }
47 }
20
48
21 void LegendMarker::setBrush(const QBrush brush)
49 void LegendMarker::setBrush(const QBrush brush)
22 {
50 {
23 mBrush = brush;
51 mBrush = brush;
24 }
52 }
25
53
54 QBrush LegendMarker::brush() const
55 {
56 return mBrush;
57 }
58
26 void LegendMarker::setName(const QString name)
59 void LegendMarker::setName(const QString name)
27 {
60 {
28 mName = name;
61 mName = name;
29 }
62 }
30
63
31 QString LegendMarker::name() const
64 QString LegendMarker::name() const
32 {
65 {
33 return mName;
66 return mName;
34 }
67 }
35
68
36 QColor LegendMarker::color() const
37 {
38 return mBrush.color();
39 }
40
41 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
69 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
42 {
70 {
43 painter->setBrush(mBrush);
71 painter->setBrush(mBrush);
44 painter->drawRect(mBoundingRect);
72 painter->drawRect(mBoundingRect);
45 }
73 }
46
74
47 QRectF LegendMarker::boundingRect() const
75 QRectF LegendMarker::boundingRect() const
48 {
76 {
49 return mBoundingRect;
77 return mBoundingRect;
50 }
78 }
51
79
52 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
80 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
53 {
81 {
82 switch (mType)
83 {
84 case LegendMarkerTypeSeries: {
85
54 if (event->button() == Qt::LeftButton) {
86 if (event->button() == Qt::LeftButton) {
55 emit clicked(mSeries, mName);
87 emit clicked(mSeries);
56 } else if (event->button() == Qt::RightButton) {
88 } else if (event->button() == Qt::RightButton) {
57 emit rightClicked(mSeries, mName);
89 emit rightClicked(mSeries);
90 }
91 break;
58 }
92 }
93 case LegendMarkerTypeBarset: {
94
95 if (event->button() == Qt::LeftButton) {
96 emit clicked(mBarset);
97 } else if (event->button() == Qt::RightButton) {
98 emit rightClicked(mBarset);
99 }
100 break;
101 }
102
103 case LegendMarkerTypePieslice: {
104
105 if (event->button() == Qt::LeftButton) {
106 emit clicked(mPieslice);
107 } else if (event->button() == Qt::RightButton) {
108 emit rightClicked(mPieslice);
109 }
110 break;
111 }
112 default: {
113 break;
114 }
115 }
116
59 }
117 }
60
118
61 #include "moc_legendmarker_p.cpp"
119 #include "moc_legendmarker_p.cpp"
62
120
63 QTCOMMERCIALCHART_END_NAMESPACE
121 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,44 +1,65
1 #ifndef LEGENDMARKER_P_H
1 #ifndef LEGENDMARKER_P_H
2 #define LEGENDMARKER_P_H
2 #define LEGENDMARKER_P_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QGraphicsObject>
5 #include <QGraphicsObject>
6 #include <QBrush>
6 #include <QBrush>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QSeries;
10 class QSeries;
11 class QBarSet;
12 class QPieSlice;
11
13
12
14 // TODO: split this to 3 different markers for series, barset and pieslice. Current implementation is easier to misuse...
13 class LegendMarker : public QGraphicsObject
15 class LegendMarker : public QGraphicsObject
14 {
16 {
15 Q_OBJECT
17 Q_OBJECT
18
19 enum LegendMarkerType {
20 LegendMarkerTypeSeries,
21 LegendMarkerTypeBarset,
22 LegendMarkerTypePieslice
23 };
24
16 public:
25 public:
17 LegendMarker(QSeries* series, QGraphicsItem *parent = 0);
26 LegendMarker(QSeries* series, QGraphicsItem *parent = 0);
27 LegendMarker(QBarSet* barset, QGraphicsItem *parent = 0);
28 LegendMarker(QPieSlice* pieslice, QGraphicsItem *parent = 0);
18 void setBoundingRect(const QRectF rect);
29 void setBoundingRect(const QRectF rect);
30
19 void setBrush(const QBrush brush);
31 void setBrush(const QBrush brush);
32 QBrush brush() const;
33
20 void setName(const QString name);
34 void setName(const QString name);
21 QString name() const;
35 QString name() const;
22 QColor color() const;
23
36
24 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
37 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
25
38
26 QRectF boundingRect() const;
39 QRectF boundingRect() const;
27
40
28 public:
41 public:
29 // From QGraphicsObject
42 // From QGraphicsObject
30 void mousePressEvent(QGraphicsSceneMouseEvent *event);
43 void mousePressEvent(QGraphicsSceneMouseEvent *event);
31
44
32 Q_SIGNALS:
45 Q_SIGNALS:
33 void clicked(QSeries* series, QString name);
46 void clicked(QSeries* series);
34 void rightClicked(QSeries* series, QString name);
47 void rightClicked(QSeries* series);
48 void clicked(QBarSet* barset);
49 void rightClicked(QBarSet* barset);
50 void clicked(QPieSlice* pieslice);
51 void rightClicked(QPieSlice* pieslice);
35
52
36 private:
53 private:
37 QRectF mBoundingRect;
54 QRectF mBoundingRect;
38 QBrush mBrush;
55 QBrush mBrush;
39 QString mName;
56 QString mName;
40 QSeries* mSeries;
57 QSeries* mSeries;
58 QBarSet* mBarset;
59 QPieSlice* mPieslice;
60
61 LegendMarkerType mType;
41 };
62 };
42
63
43 QTCOMMERCIALCHART_END_NAMESPACE
64 QTCOMMERCIALCHART_END_NAMESPACE
44 #endif // LEGENDMARKER_P_H
65 #endif // LEGENDMARKER_P_H
@@ -1,119 +1,206
1 #include "qchartglobal.h"
1 #include "qchartglobal.h"
2 #include "qlegend.h"
2 #include "qlegend.h"
3 #include "qseries.h"
3 #include "qseries.h"
4 #include "legendmarker_p.h"
4 #include "legendmarker_p.h"
5 #include "qxyseries.h"
6 #include "qlineseries.h"
7 #include "qareaseries.h"
8 #include "qscatterseries.h"
9 #include "qsplineseries.h"
10 #include "qbarseries.h"
11 #include "qstackedbarseries.h"
12 #include "qpercentbarseries.h"
13 #include "qbarset.h"
14 #include "qpieseries.h"
15 #include "qpieslice.h"
5 #include <QPainter>
16 #include <QPainter>
6 #include <QPen>
17 #include <QPen>
7
18
8 #include <QGraphicsSceneEvent>
19 #include <QGraphicsSceneEvent>
9
20
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
22
12 QLegend::QLegend(QGraphicsItem *parent)
23 QLegend::QLegend(QGraphicsItem *parent)
13 : QGraphicsObject(parent)
24 : QGraphicsObject(parent)
14 ,mBoundingRect(0,0,1,1)
25 ,mBoundingRect(0,0,1,1)
15 ,mBackgroundBrush(Qt::darkGray) // TODO: from theme?
26 ,mBackgroundBrush(Qt::darkGray) // TODO: from theme?
16 {
27 {
17 }
28 }
18
29
19 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
30 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
20 {
31 {
21 painter->setBrush(mBackgroundBrush);
32 painter->setBrush(mBackgroundBrush);
22 painter->drawRect(mBoundingRect);
33 painter->drawRect(mBoundingRect);
23
34
24 foreach(LegendMarker* m, mMarkers) {
35 foreach(LegendMarker* m, mMarkers) {
25 QRectF r = m->boundingRect();
36 QRectF r = m->boundingRect();
26 painter->setPen(m->color());
37 painter->setBrush(m->brush());
27 painter->drawText(r.x() + r.width()*2, r.y() + r.height(), m->name());
38 painter->drawText(r.x() + r.width()*2, r.y() + r.height(), m->name());
28 }
39 }
29 }
40 }
30
41
31 QRectF QLegend::boundingRect() const
42 QRectF QLegend::boundingRect() const
32 {
43 {
33 return mBoundingRect;
44 return mBoundingRect;
34 }
45 }
35
46
36 void QLegend::setBackgroundBrush(const QBrush& brush)
47 void QLegend::setBackgroundBrush(const QBrush& brush)
37 {
48 {
38 mBackgroundBrush = brush;
49 mBackgroundBrush = brush;
39 }
50 }
40
51
41 QBrush QLegend::backgroundBrush() const
52 QBrush QLegend::backgroundBrush() const
42 {
53 {
43 return mBackgroundBrush;
54 return mBackgroundBrush;
44 }
55 }
45
56
46 void QLegend::handleSeriesAdded(QSeries* series,Domain* domain)
57 void QLegend::handleSeriesAdded(QSeries* series,Domain* domain)
47 {
58 {
48 mSeriesList.append(series);
59 mSeriesList.append(series);
49 dataChanged();
60
61 switch (series->type())
62 {
63 case QSeries::SeriesTypeLine: {
64
65 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
66 createMarker(lineSeries);
67 break;
68 }
69 case QSeries::SeriesTypeArea: {
70
71 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
72 createMarker(areaSeries->upperSeries());
73 createMarker(areaSeries->lowerSeries());
74 break;
75 }
76
77 case QSeries::SeriesTypeBar: {
78
79 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
80 createMarkers(barSeries);
81 break;
82 }
83
84 case QSeries::SeriesTypeStackedBar: {
85
86 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
87 createMarkers(stackedBarSeries);
88 break;
89 }
90
91 case QSeries::SeriesTypePercentBar: {
92
93 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
94 createMarkers(percentBarSeries);
95 break;
96 }
97
98 case QSeries::SeriesTypeScatter: {
99
100 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
101 createMarker(scatterSeries);
102 break;
103 }
104
105 case QSeries::SeriesTypePie: {
106
107 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
108 createMarkers(pieSeries);
109 break;
110 }
111
112 case QSeries::SeriesTypeSpline: {
113
114 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
115 break;
116 }
117 default: {
118 qDebug()<< "QLegend::handleSeriesAdded" << series->type() << "not implemented.";
119 break;
120 }
121 }
122
50 layoutChanged();
123 layoutChanged();
51 }
124 }
52
125
53 void QLegend::handleSeriesRemoved(QSeries* series)
126 void QLegend::handleSeriesRemoved(QSeries* series)
54 {
127 {
128 // TODO: delete markers, disconnect.
55 mSeriesList.removeOne(series);
129 mSeriesList.removeOne(series);
56 dataChanged();
57 layoutChanged();
130 layoutChanged();
58 }
131 }
59
132
60 void QLegend::handleGeometryChanged(const QRectF& size)
133 void QLegend::handleGeometryChanged(const QRectF& size)
61 {
134 {
62 mBoundingRect = size;
135 mBoundingRect = size;
63 layoutChanged();
136 layoutChanged();
64 }
137 }
65
138
66 void QLegend::dataChanged()
139 void QLegend::createMarker(QXYSeries* series)
67 {
140 {
68 foreach (LegendMarker* marker, mMarkers) {
141 LegendMarker* marker = new LegendMarker(series,this);
69 disconnect(marker,SIGNAL(clicked(QSeries*,QString)),this,SIGNAL(clicked(QSeries*,QString)));
142 marker->setName(series->name());
70 disconnect(marker,SIGNAL(rightClicked(QSeries*,QString)),this,SIGNAL(rightClicked(QSeries*,QString)));
143 marker->setBrush(series->brush());
71 delete marker;
144 connect(marker,SIGNAL(clicked(QSeries*)),this,SIGNAL(markerClicked(QSeries*)));
145 connect(marker,SIGNAL(rightClicked(QSeries*)),this,SIGNAL(markerRightClicked(QSeries*)));
146 mMarkers.append(marker);
147 childItems().append(marker);
72 }
148 }
73
149
74 mMarkers.clear();
150 void QLegend::createMarkers(QBarSeries *series)
75
151 {
76 foreach (QSeries* s, mSeriesList) {
152 foreach(QBarSet* s, series->barSets()) {
77 for (int i=0; i<s->legendEntries().count(); i++) {
153 LegendMarker* marker = new LegendMarker(series,this);
78 LegendMarker *marker = new LegendMarker(s, this);
154 marker->setName(s->name());
79 marker->setBrush(s->legendEntries().at(i).mBrush);
155 marker->setBrush(s->brush());
80 marker->setName(s->legendEntries().at(i).mName);
156 connect(marker,SIGNAL(clicked(QBarSet*)),this,SIGNAL(markerClicked(QBarSet*)));
157 connect(marker,SIGNAL(rightClicked(QBarSet*)),this,SIGNAL(markerRightClicked(QBarSet*)));
81 mMarkers.append(marker);
158 mMarkers.append(marker);
82 childItems().append(marker);
159 childItems().append(marker);
83 connect(marker,SIGNAL(clicked(QSeries*,QString)),this,SIGNAL(clicked(QSeries*,QString)));
84 connect(marker,SIGNAL(rightClicked(QSeries*,QString)),this,SIGNAL(rightClicked(QSeries*,QString)));
85 }
160 }
86 }
161 }
162
163 void QLegend::createMarkers(QPieSeries *series)
164 {
165 foreach(QPieSlice* s, series->slices()) {
166 LegendMarker* marker = new LegendMarker(series,this);
167 marker->setName(s->label());
168 marker->setBrush(s->sliceBrush());
169 connect(marker,SIGNAL(clicked(QPieSlice*)),this,SIGNAL(markerClicked(QPieSlice*)));
170 connect(marker,SIGNAL(rightClicked(QPieSlice*)),this,SIGNAL(markerRightClicked(QPieSlice*)));
171 mMarkers.append(marker);
172 childItems().append(marker);
173 }
87 }
174 }
88
175
89 void QLegend::layoutChanged()
176 void QLegend::layoutChanged()
90 {
177 {
91 // Calculate layout for markers and text
178 // Calculate layout for markers and text
92 if (mMarkers.count() <= 0) {
179 if (mMarkers.count() <= 0) {
93 // Nothing to do
180 // Nothing to do
94 return;
181 return;
95 }
182 }
96
183
97 // TODO: marker defined by series.
184 // TODO: marker defined by series.
98 QSizeF markerSize(10,10);
185 QSizeF markerSize(10,10);
99
186
100 // TODO: better layout, this is just concept.
187 // TODO: better layout, this is just concept.
101 // Leave some space around markers like this: | x x x x |
188 // Leave some space around markers like this: | x x x x |
102 qreal steps = mMarkers.count();
189 qreal steps = mMarkers.count();
103
190
104 qreal xStep = mBoundingRect.width() / steps;
191 qreal xStep = mBoundingRect.width() / steps;
105 qreal yStep = mBoundingRect.height() / steps;
192 qreal yStep = mBoundingRect.height() / steps;
106 qreal x = mBoundingRect.x() + 5;
193 qreal x = mBoundingRect.x() + 5;
107 qreal y = mBoundingRect.y() + (mBoundingRect.height() - markerSize.height())/2;
194 qreal y = mBoundingRect.y() + (mBoundingRect.height() - markerSize.height())/2;
108 foreach (LegendMarker* m, mMarkers) {
195 foreach (LegendMarker* m, mMarkers) {
109 qDebug() << "marker x:" << x;
196 qDebug() << "marker x:" << x;
110 qDebug() << "marker y:" << y;
197 qDebug() << "marker y:" << y;
111 m->setBoundingRect(QRectF(x,y,markerSize.width(),markerSize.height()));
198 m->setBoundingRect(QRectF(x,y,markerSize.width(),markerSize.height()));
112 x += xStep;
199 x += xStep;
113 }
200 }
114 }
201 }
115
202
116
203
117
204
118 #include "moc_qlegend.cpp"
205 #include "moc_qlegend.cpp"
119 QTCOMMERCIALCHART_END_NAMESPACE
206 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,49 +1,63
1 #ifndef QLEGEND_H
1 #ifndef QLEGEND_H
2 #define QLEGEND_H
2 #define QLEGEND_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qseries.h"
5 #include "qseries.h"
6 #include <QGraphicsObject>
6 #include <QGraphicsObject>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class Domain;
10 class Domain;
11 class LegendMarker;
11 class LegendMarker;
12 class QPieSlice;
13 class QXYSeries;
14 class QBarSet;
15 class QBarSeries;
16 class QPieSeries;
12
17
13 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject
18 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject
14 {
19 {
15 Q_OBJECT
20 Q_OBJECT
16 public:
21 public:
17
22
18 explicit QLegend(QGraphicsItem *parent = 0);
23 explicit QLegend(QGraphicsItem *parent = 0);
19
24
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
25 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
21 QRectF boundingRect() const;
26 QRectF boundingRect() const;
22
27
23 void setBackgroundBrush(const QBrush& brush);
28 void setBackgroundBrush(const QBrush& brush);
24 QBrush backgroundBrush() const;
29 QBrush backgroundBrush() const;
25
30
26 signals:
31 signals:
27 // for interactions.
32 // for interactions.
28 void clicked(QSeries* series, QString name);
33 void clicked(QSeries* series);
29 void rightClicked(QSeries* series, QString name);
34 void rightClicked(QSeries* series);
35 void clicked(QBarSet* barset);
36 void rightClicked(QBarSet* series);
37 void clicked(QPieSlice* slice);
38 void rightClicked(QPieSlice* series);
30
39
31 public slots:
40 public slots:
32 void handleSeriesAdded(QSeries* series,Domain* domain);
41 void handleSeriesAdded(QSeries* series,Domain* domain);
33 void handleSeriesRemoved(QSeries* series);
42 void handleSeriesRemoved(QSeries* series);
34 void handleGeometryChanged(const QRectF& size);
43 void handleGeometryChanged(const QRectF& size);
35
44
36 private:
45 private:
37 void dataChanged();
46 // PIMPL --->
47 void createMarker(QXYSeries* series);
48 void createMarkers(QBarSeries* series);
49 void createMarkers(QPieSeries* series);
38 void layoutChanged();
50 void layoutChanged();
51 // <--- PIMPL
52
39
53
40 QRectF mBoundingRect;
54 QRectF mBoundingRect;
41 QList<QSeries*> mSeriesList;
55 QList<QSeries*> mSeriesList;
42 QList<LegendMarker*> mMarkers;
56 QList<LegendMarker*> mMarkers;
43
57
44 QBrush mBackgroundBrush;
58 QBrush mBackgroundBrush;
45 };
59 };
46
60
47 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
48
62
49 #endif // QLEGEND_H
63 #endif // QLEGEND_H
@@ -1,54 +1,55
1 #ifndef QSERIES_H
1 #ifndef QSERIES_H
2 #define QSERIES_H
2 #define QSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QAbstractItemModel>
6 #include <QAbstractItemModel>
7 #include <QPen>
7 #include <QPen>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class QTCOMMERCIALCHART_EXPORT QSeries : public QObject
11 class QTCOMMERCIALCHART_EXPORT QSeries : public QObject
12 {
12 {
13 Q_OBJECT
13 Q_OBJECT
14 public:
14 public:
15 enum QSeriesType {
15 enum QSeriesType {
16 SeriesTypeLine,
16 SeriesTypeLine,
17 SeriesTypeArea,
17 SeriesTypeArea,
18 SeriesTypeBar,
18 SeriesTypeBar,
19 SeriesTypeStackedBar,
19 SeriesTypeStackedBar,
20 SeriesTypePercentBar,
20 SeriesTypePercentBar,
21 SeriesTypePie,
21 SeriesTypePie,
22 SeriesTypeScatter,
22 SeriesTypeScatter,
23 SeriesTypeSpline
23 SeriesTypeSpline
24 };
24 };
25
25
26 // Helper class to contain legend and color for it
26 // Helper class to contain legend and color for it
27 // TODO: This is actually quite close to current LegendMarker.. combine them?
27 // TODO: This is actually quite close to current LegendMarker.. combine them?
28 class LegendEntry {
28 class LegendEntry {
29 public:
29 public:
30 QString mName;
30 QString mName;
31 QBrush mBrush;
31 QBrush mBrush;
32 };
32 };
33
33
34 protected:
34 protected:
35 QSeries(QObject *parent = 0) : QObject(parent) {}
35 QSeries(QObject *parent = 0) : QObject(parent) {}
36
36
37 public:
37 public:
38 virtual ~QSeries() {}
38 virtual ~QSeries() {}
39 virtual QSeriesType type() const = 0;
39 virtual QSeriesType type() const = 0;
40 QString name() { return QString("TODO: Name QSeries"); }
40 // TODO
41 // TODO
41 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
42 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
42
43
43 virtual QList<QSeries::LegendEntry> legendEntries() { QList<QSeries::LegendEntry> l; return l; }
44 virtual QList<QSeries::LegendEntry> legendEntries() { QList<QSeries::LegendEntry> l; return l; }
44
45
45 void setTitle(QString title) { m_title = title; }
46 void setTitle(QString title) { m_title = title; }
46 QString title() { return m_title; }
47 QString title() { return m_title; }
47
48
48 private:
49 private:
49 QString m_title;
50 QString m_title;
50 };
51 };
51
52
52 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
53
54
54 #endif
55 #endif
General Comments 0
You need to be logged in to leave comments. Login now