##// END OF EJS Templates
removed peer object solution. Introduced marker type solution
sauimone -
r2179:8d0f04b94da2
parent child
Show More
@@ -29,6 +29,7
29 29 #include <QPieSeries>
30 30 #include <QPieSlice>
31 31 #include <QLegendMarker>
32 #include <QPieLegendMarker>
32 33
33 34 QTCOMMERCIALCHART_USE_NAMESPACE
34 35
@@ -264,9 +265,8 void MainWidget::showDebugInfo()
264 265 {
265 266 qDebug() << "marker count:" << m_chart->legend()->markers().count();
266 267 foreach (QLegendMarker* marker, m_chart->legend()->markers()) {
267 qDebug() << "marker series type:" << marker->series()->type();
268 qDebug() << "peer object:" << marker->peerObject();
269 qDebug() << "label:" << marker->label();
268 qDebug() << "marker type:" << marker->type();
269 qDebug() << "related series:" << marker->series();
270 270 }
271 271 }
272 272
@@ -291,23 +291,20 void MainWidget::updateLegendLayout()
291 291 void MainWidget::handleMarkerClicked()
292 292 {
293 293 QLegendMarker* marker = qobject_cast<QLegendMarker*> (sender());
294 Q_ASSERT(marker);
294 295
295 qDebug() << "marker clicked:" << marker;
296
297 switch (marker->series()->type())
296 switch (marker->type())
298 297 {
299 case QAbstractSeries::SeriesTypePie:
298 case QLegendMarker::LegendMarkerTypePie:
300 299 {
301 // Series type is pie.
302 // The peer object is QPieSlice
303 QPieSlice* slice = qobject_cast<QPieSlice*> (marker->peerObject());
304 Q_ASSERT(slice);
300 QPieLegendMarker *pieMarker = qobject_cast<QPieLegendMarker *> (marker);
301 QPieSlice* slice = pieMarker->slice();
305 302 slice->setExploded(!slice->isExploded());
306 303 break;
307 304 }
308 305 default:
309 306 {
310 qDebug() << "Unknown series type";
307 qDebug() << "Unknown marker type";
311 308 break;
312 309 }
313 310 }
@@ -50,12 +50,6 QAreaSeries* QAreaLegendMarker::series()
50 50 return d->m_series;
51 51 }
52 52
53 QAreaSeries* QAreaLegendMarker::peerObject()
54 {
55 Q_D(QAreaLegendMarker);
56 return d->m_series;
57 }
58
59 53 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60 54
61 55 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
@@ -38,16 +38,14 public:
38 38 explicit QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent = 0);
39 39 virtual ~QAreaLegendMarker();
40 40
41 virtual QAreaSeries* series();
42 virtual QAreaSeries* peerObject(); // TODO: rename to slice and remove these virtuals from base class?
41 virtual LegendMarkerType type() { return LegendMarkerTypeArea; }
42
43 // Related series
44 QAreaSeries* series();
43 45
44 46 protected:
45 47 QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent = 0);
46 48
47 //Q_SIGNALS:
48
49 //public Q_SLOTS:
50
51 49 private:
52 50 Q_DECLARE_PRIVATE(QAreaLegendMarker)
53 51 Q_DISABLE_COPY(QAreaLegendMarker)
@@ -50,7 +50,7 QAbstractBarSeries *QBarLegendMarker::series()
50 50 return d->m_series;
51 51 }
52 52
53 QBarSet* QBarLegendMarker::peerObject()
53 QBarSet* QBarLegendMarker::barset()
54 54 {
55 55 Q_D(QBarLegendMarker);
56 56 return d->m_barset;
@@ -37,16 +37,15 public:
37 37 explicit QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent = 0);
38 38 virtual ~QBarLegendMarker();
39 39
40 virtual QAbstractBarSeries* series();
41 virtual QBarSet* peerObject(); // TODO: rename to slice and remove these virtuals from base class?
40 virtual LegendMarkerType type() { return LegendMarkerTypeBar; }
41
42 // Related series and barset
43 QAbstractBarSeries* series();
44 QBarSet* barset();
42 45
43 46 protected:
44 47 QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = 0);
45 48
46 //Q_SIGNALS:
47
48 //public Q_SLOTS:
49
50 49 private:
51 50 Q_DECLARE_PRIVATE(QBarLegendMarker)
52 51 Q_DISABLE_COPY(QBarLegendMarker)
@@ -33,19 +33,25 class QLegendMarkerPrivate;
33 33 class QAbstractSeries;
34 34 class QLegend;
35 35
36 // TODO: should this be QAbstractLegendMarker?
37 36 class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject
38 37 {
39 38 Q_OBJECT
40 39
41 // TODO: need for these?
40 enum LegendMarkerType {
41 LegendMarkerTypeArea,
42 LegendMarkerTypeBar,
43 LegendMarkerTypePie,
44 LegendMarkerTypeXY
45 };
46
47 // TODO:
42 48 // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged);
43 49 // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged);
44 50 // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged);
45 51
46 52 public:
47 // explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0);
48 53 virtual ~QLegendMarker();
54 virtual LegendMarkerType type() = 0;
49 55
50 56 QString label() const;
51 57 void setLabel(const QString &label);
@@ -65,10 +71,6 public:
65 71 bool isVisible() const;
66 72 void setVisible(bool visible);
67 73
68 // virtual QAbstractSeries::SeriesType type() = 0; // TODO? Or use LegendMarker type enum?
69 virtual QAbstractSeries* series() = 0; // TODO: remove these and use specialised functions on derived classes?
70 virtual QObject* peerObject() = 0;
71
72 74 protected:
73 75 explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0);
74 76
@@ -50,7 +50,7 QPieSeries* QPieLegendMarker::series()
50 50 return d->m_series;
51 51 }
52 52
53 QPieSlice* QPieLegendMarker::peerObject()
53 QPieSlice* QPieLegendMarker::slice()
54 54 {
55 55 Q_D(QPieLegendMarker);
56 56 return d->m_slice;
@@ -39,16 +39,15 public:
39 39 explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0);
40 40 virtual ~QPieLegendMarker();
41 41
42 virtual QPieSeries* series();
43 virtual QPieSlice* peerObject(); // TODO: rename to slice and remove these virtuals from base class?
42 virtual LegendMarkerType type() { return LegendMarkerTypePie; }
43
44 // Related series and slice
45 QPieSeries* series();
46 QPieSlice* slice();
44 47
45 48 protected:
46 49 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
47 50
48 //Q_SIGNALS:
49
50 //public Q_SLOTS:
51
52 51 private:
53 52 Q_DECLARE_PRIVATE(QPieLegendMarker)
54 53 Q_DISABLE_COPY(QPieLegendMarker)
@@ -50,12 +50,6 QXYSeries* QXYLegendMarker::series()
50 50 return d->m_series;
51 51 }
52 52
53 QXYSeries* QXYLegendMarker::peerObject()
54 {
55 Q_D(QXYLegendMarker);
56 return d->m_series;
57 }
58
59 53 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60 54
61 55 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
@@ -36,16 +36,14 public:
36 36 explicit QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent = 0);
37 37 virtual ~QXYLegendMarker();
38 38
39 virtual QXYSeries* series();
40 virtual QXYSeries* peerObject(); // TODO: rename to slice and remove these virtuals from base class?
39 virtual LegendMarkerType type() { return LegendMarkerTypeXY; }
40
41 // Related series
42 QXYSeries* series();
41 43
42 44 protected:
43 45 QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = 0);
44 46
45 //Q_SIGNALS:
46
47 //public Q_SLOTS:
48
49 47 private:
50 48 Q_DECLARE_PRIVATE(QXYLegendMarker)
51 49 Q_DISABLE_COPY(QXYLegendMarker)
General Comments 0
You need to be logged in to leave comments. Login now