##// END OF EJS Templates
framework for legend
sauimone -
r524:280ce33a2f47
parent child
Show More
@@ -0,0 +1,44
1 #include "qchartglobal.h"
2 #include "qlegend.h"
3 #include "qseries.h"
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QLegend::QLegend(QGraphicsItem *parent)
7 : QGraphicsObject(parent)
8 ,mBoundingRect(0,0,0,0)
9 {
10 }
11
12
13 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
14 {
15 // TODO:
16 qDebug() << "QLegend::paint";
17 foreach(QSeries* s, mSeriesList) {
18 for (int i=0; i<s->legendEntries().count(); i++) {
19 // Paint it...
20 //qDebug() << s->legendEntries().at(i).mName;
21 }
22 }
23 }
24
25 QRectF QLegend::boundingRect() const
26 {
27 return mBoundingRect;
28 }
29
30 void QLegend::handleSeriesAdded(QSeries* series,Domain* domain)
31 {
32 // TODO: append entries
33 mSeriesList.append(series);
34 }
35
36 void QLegend::handleSeriesRemoved(QSeries* series)
37 {
38 // TODO: remove entries
39 mSeriesList.removeOne(series);
40 }
41
42
43 #include "moc_qlegend.cpp"
44 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,36
1 #ifndef QLEGEND_H
2 #define QLEGEND_H
3
4 #include "qchartglobal.h"
5 #include "qseries.h"
6 #include <QGraphicsObject>
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 class Domain;
11
12 class QLegend : public QGraphicsObject
13 {
14 Q_OBJECT
15 public:
16
17 explicit QLegend(QGraphicsItem *parent = 0);
18
19 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
20 QRectF boundingRect() const;
21
22 signals:
23
24 public slots:
25 void handleSeriesAdded(QSeries* series,Domain* domain);
26 void handleSeriesRemoved(QSeries* series);
27
28 private:
29
30 QRectF mBoundingRect;
31 QList<QSeries*> mSeriesList;
32 };
33
34 QTCOMMERCIALCHART_END_NAMESPACE
35
36 #endif // QLEGEND_H
@@ -39,12 +39,12 QList<QBarSet*> BarChartModel::barSets()
39 return mDataModel;
39 return mDataModel;
40 }
40 }
41
41
42 QList<QSeries::Legend> BarChartModel::legend()
42 QList<QSeries::LegendEntry> BarChartModel::legendEntries()
43 {
43 {
44 QList<QSeries::Legend> legend;
44 QList<QSeries::LegendEntry> legend;
45
45
46 for (int i=0; i<mDataModel.count(); i++) {
46 for (int i=0; i<mDataModel.count(); i++) {
47 QSeries::Legend l;
47 QSeries::LegendEntry l;
48 l.mName = mDataModel.at(i)->name();
48 l.mName = mDataModel.at(i)->name();
49 l.mPen = mDataModel.at(i)->pen();
49 l.mPen = mDataModel.at(i)->pen();
50 legend.append(l);
50 legend.append(l);
@@ -25,7 +25,7 public:
25 QBarSet *setAt(int index);
25 QBarSet *setAt(int index);
26 QList<QBarSet*> barSets();
26 QList<QBarSet*> barSets();
27
27
28 QList<QSeries::Legend> legend();
28 QList<QSeries::LegendEntry> legendEntries();
29
29
30 int barsetCount(); // Number of sets in model
30 int barsetCount(); // Number of sets in model
31 int categoryCount(); // Number of categories
31 int categoryCount(); // Number of categories
@@ -98,9 +98,9 QBarSet* QBarSeries::barsetAt(int index)
98 /*!
98 /*!
99 Returns legend of series.
99 Returns legend of series.
100 */
100 */
101 QList<QSeries::Legend> QBarSeries::legend()
101 QList<QSeries::LegendEntry> QBarSeries::legendEntries()
102 {
102 {
103 return mModel->legend();
103 return mModel->legendEntries();
104 }
104 }
105
105
106 /*!
106 /*!
@@ -24,7 +24,7 public:
24 int barsetCount();
24 int barsetCount();
25 int categoryCount();
25 int categoryCount();
26 QList<QBarSet*> barSets();
26 QList<QBarSet*> barSets();
27 QList<QSeries::Legend> legend();
27 QList<QSeries::LegendEntry> legendEntries();
28
28
29 public:
29 public:
30 // TODO: Functions below this are not part of api and will be moved
30 // TODO: Functions below this are not part of api and will be moved
@@ -1,5 +1,6
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "qlegend.h"
3 #include "chartpresenter_p.h"
4 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
5 #include "chartdataset_p.h"
5 #include <QGraphicsScene>
6 #include <QGraphicsScene>
@@ -49,8 +50,11 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(
49 m_backgroundItem(0),
50 m_backgroundItem(0),
50 m_titleItem(0),
51 m_titleItem(0),
51 m_dataset(new ChartDataSet(this)),
52 m_dataset(new ChartDataSet(this)),
52 m_presenter(new ChartPresenter(this,m_dataset))
53 m_presenter(new ChartPresenter(this,m_dataset)),
54 m_legend(new QLegend(this)) // TODO: is this the parent we want the legend to have?
53 {
55 {
56 connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
57 connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
54 }
58 }
55
59
56 /*!
60 /*!
@@ -58,6 +62,8 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(
58 */
62 */
59 QChart::~QChart()
63 QChart::~QChart()
60 {
64 {
65 disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
66 disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
61 }
67 }
62
68
63 /*!
69 /*!
@@ -262,6 +268,15 QChartAxis* QChart::axisY() const
262 }
268 }
263
269
264 /*!
270 /*!
271 Returns the legend object of the chart
272 */
273 QLegend* QChart::legend() const
274 {
275 return m_legend;
276 }
277
278
279 /*!
265 Resizes and updates the chart area using the \a event data
280 Resizes and updates the chart area using the \a event data
266 */
281 */
267 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
282 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
@@ -20,6 +20,7 class ChartTheme;
20 class ChartItem;
20 class ChartItem;
21 class ChartDataSet;
21 class ChartDataSet;
22 class ChartPresenter;
22 class ChartPresenter;
23 class QLegend;
23
24
24 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
25 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
25 {
26 {
@@ -75,6 +76,8 public:
75 QChartAxis* axisX() const;
76 QChartAxis* axisX() const;
76 QChartAxis* axisY() const;
77 QChartAxis* axisY() const;
77
78
79 QLegend* legend() const;
80
78 protected:
81 protected:
79 void resizeEvent(QGraphicsSceneResizeEvent *event);
82 void resizeEvent(QGraphicsSceneResizeEvent *event);
80
83
@@ -89,6 +92,7 private:
89 QRectF m_rect;
92 QRectF m_rect;
90 ChartDataSet *m_dataset;
93 ChartDataSet *m_dataset;
91 ChartPresenter *m_presenter;
94 ChartPresenter *m_presenter;
95 QLegend* m_legend;
92 };
96 };
93
97
94 QTCOMMERCIALCHART_END_NAMESPACE
98 QTCOMMERCIALCHART_END_NAMESPACE
@@ -25,8 +25,8 public:
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 as private class? Or should we expose this to user of API
27 // TODO: This as private class? Or should we expose this to user of API
28 class Legend {
28 class LegendEntry {
29 public:
29 public:
30 QString mName;
30 QString mName;
31 QPen mPen;
31 QPen mPen;
32 };
32 };
@@ -40,8 +40,7 public:
40 // TODO
40 // TODO
41 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
41 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
42
42
43 // TODO: should this be internal?
43 virtual QList<QSeries::LegendEntry> legendEntries() { QList<QSeries::LegendEntry> l; return l; }
44 virtual QList<QSeries::Legend> legend() { QList<QSeries::Legend> l; return l; }
45
44
46 void setTitle(QString title) { m_title = title; }
45 void setTitle(QString title) { m_title = title; }
47 QString title() { return m_title; }
46 QString title() { return m_title; }
@@ -13,7 +13,8 SOURCES += \
13 domain.cpp \
13 domain.cpp \
14 qchart.cpp \
14 qchart.cpp \
15 qchartview.cpp \
15 qchartview.cpp \
16 qseries.cpp
16 qseries.cpp \
17 qlegend.cpp
17 PRIVATE_HEADERS += \
18 PRIVATE_HEADERS += \
18 chartdataset_p.h \
19 chartdataset_p.h \
19 chartitem_p.h \
20 chartitem_p.h \
@@ -24,8 +25,9 PUBLIC_HEADERS += \
24 qchart.h \
25 qchart.h \
25 qchartglobal.h \
26 qchartglobal.h \
26 qseries.h \
27 qseries.h \
27 qchartview.h
28 qchartview.h \
28
29 qlegend.h
30
29 include(axis/axis.pri)
31 include(axis/axis.pri)
30 include(xychart/xychart.pri)
32 include(xychart/xychart.pri)
31 include(linechart/linechart.pri)
33 include(linechart/linechart.pri)
General Comments 0
You need to be logged in to leave comments. Login now