##// 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 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 46 for (int i=0; i<mDataModel.count(); i++) {
47 QSeries::Legend l;
47 QSeries::LegendEntry l;
48 48 l.mName = mDataModel.at(i)->name();
49 49 l.mPen = mDataModel.at(i)->pen();
50 50 legend.append(l);
@@ -25,7 +25,7 public:
25 25 QBarSet *setAt(int index);
26 26 QList<QBarSet*> barSets();
27 27
28 QList<QSeries::Legend> legend();
28 QList<QSeries::LegendEntry> legendEntries();
29 29
30 30 int barsetCount(); // Number of sets in model
31 31 int categoryCount(); // Number of categories
@@ -98,9 +98,9 QBarSet* QBarSeries::barsetAt(int index)
98 98 /*!
99 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 24 int barsetCount();
25 25 int categoryCount();
26 26 QList<QBarSet*> barSets();
27 QList<QSeries::Legend> legend();
27 QList<QSeries::LegendEntry> legendEntries();
28 28
29 29 public:
30 30 // TODO: Functions below this are not part of api and will be moved
@@ -1,5 +1,6
1 1 #include "qchart.h"
2 2 #include "qchartaxis.h"
3 #include "qlegend.h"
3 4 #include "chartpresenter_p.h"
4 5 #include "chartdataset_p.h"
5 6 #include <QGraphicsScene>
@@ -49,8 +50,11 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(
49 50 m_backgroundItem(0),
50 51 m_titleItem(0),
51 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 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 280 Resizes and updates the chart area using the \a event data
266 281 */
267 282 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
@@ -20,6 +20,7 class ChartTheme;
20 20 class ChartItem;
21 21 class ChartDataSet;
22 22 class ChartPresenter;
23 class QLegend;
23 24
24 25 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
25 26 {
@@ -75,6 +76,8 public:
75 76 QChartAxis* axisX() const;
76 77 QChartAxis* axisY() const;
77 78
79 QLegend* legend() const;
80
78 81 protected:
79 82 void resizeEvent(QGraphicsSceneResizeEvent *event);
80 83
@@ -89,6 +92,7 private:
89 92 QRectF m_rect;
90 93 ChartDataSet *m_dataset;
91 94 ChartPresenter *m_presenter;
95 QLegend* m_legend;
92 96 };
93 97
94 98 QTCOMMERCIALCHART_END_NAMESPACE
@@ -25,8 +25,8 public:
25 25
26 26 // Helper class to contain legend and color for it
27 27 // TODO: This as private class? Or should we expose this to user of API
28 class Legend {
29 public:
28 class LegendEntry {
29 public:
30 30 QString mName;
31 31 QPen mPen;
32 32 };
@@ -40,8 +40,7 public:
40 40 // TODO
41 41 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
42 42
43 // TODO: should this be internal?
44 virtual QList<QSeries::Legend> legend() { QList<QSeries::Legend> l; return l; }
43 virtual QList<QSeries::LegendEntry> legendEntries() { QList<QSeries::LegendEntry> l; return l; }
45 44
46 45 void setTitle(QString title) { m_title = title; }
47 46 QString title() { return m_title; }
@@ -13,7 +13,8 SOURCES += \
13 13 domain.cpp \
14 14 qchart.cpp \
15 15 qchartview.cpp \
16 qseries.cpp
16 qseries.cpp \
17 qlegend.cpp
17 18 PRIVATE_HEADERS += \
18 19 chartdataset_p.h \
19 20 chartitem_p.h \
@@ -24,8 +25,9 PUBLIC_HEADERS += \
24 25 qchart.h \
25 26 qchartglobal.h \
26 27 qseries.h \
27 qchartview.h
28
28 qchartview.h \
29 qlegend.h
30
29 31 include(axis/axis.pri)
30 32 include(xychart/xychart.pri)
31 33 include(linechart/linechart.pri)
General Comments 0
You need to be logged in to leave comments. Login now