@@ -0,0 +1,63 | |||||
|
1 | #include "qchartglobal.h" | |||
|
2 | #include "legendmarker_p.h" | |||
|
3 | #include <QPainter> | |||
|
4 | #include <QGraphicsSceneEvent> | |||
|
5 | ||||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
7 | ||||
|
8 | LegendMarker::LegendMarker(QSeries* series, QGraphicsItem *parent) | |||
|
9 | : QGraphicsObject(parent) | |||
|
10 | ,mSeries(series) | |||
|
11 | ,mBoundingRect(0,0,1,1) | |||
|
12 | { | |||
|
13 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |||
|
14 | } | |||
|
15 | ||||
|
16 | void LegendMarker::setBoundingRect(const QRectF rect) | |||
|
17 | { | |||
|
18 | mBoundingRect = rect; | |||
|
19 | } | |||
|
20 | ||||
|
21 | void LegendMarker::setBrush(const QBrush brush) | |||
|
22 | { | |||
|
23 | mBrush = brush; | |||
|
24 | } | |||
|
25 | ||||
|
26 | void LegendMarker::setName(const QString name) | |||
|
27 | { | |||
|
28 | mName = name; | |||
|
29 | } | |||
|
30 | ||||
|
31 | QString LegendMarker::name() const | |||
|
32 | { | |||
|
33 | return mName; | |||
|
34 | } | |||
|
35 | ||||
|
36 | QColor LegendMarker::color() const | |||
|
37 | { | |||
|
38 | return mBrush.color(); | |||
|
39 | } | |||
|
40 | ||||
|
41 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
|
42 | { | |||
|
43 | painter->setBrush(mBrush); | |||
|
44 | painter->drawRect(mBoundingRect); | |||
|
45 | } | |||
|
46 | ||||
|
47 | QRectF LegendMarker::boundingRect() const | |||
|
48 | { | |||
|
49 | return mBoundingRect; | |||
|
50 | } | |||
|
51 | ||||
|
52 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
53 | { | |||
|
54 | if (event->button() == Qt::LeftButton) { | |||
|
55 | emit clicked(mSeries, mName); | |||
|
56 | } else if (event->button() == Qt::RightButton) { | |||
|
57 | emit rightClicked(mSeries, mName); | |||
|
58 | } | |||
|
59 | } | |||
|
60 | ||||
|
61 | #include "moc_legendmarker_p.cpp" | |||
|
62 | ||||
|
63 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,44 | |||||
|
1 | #ifndef LEGENDMARKER_P_H | |||
|
2 | #define LEGENDMARKER_P_H | |||
|
3 | ||||
|
4 | #include "qchartglobal.h" | |||
|
5 | #include <QGraphicsObject> | |||
|
6 | #include <QBrush> | |||
|
7 | ||||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | ||||
|
10 | class QSeries; | |||
|
11 | ||||
|
12 | ||||
|
13 | class LegendMarker : public QGraphicsObject | |||
|
14 | { | |||
|
15 | Q_OBJECT | |||
|
16 | public: | |||
|
17 | LegendMarker(QSeries* series, QGraphicsItem *parent = 0); | |||
|
18 | void setBoundingRect(const QRectF rect); | |||
|
19 | void setBrush(const QBrush brush); | |||
|
20 | void setName(const QString name); | |||
|
21 | QString name() const; | |||
|
22 | QColor color() const; | |||
|
23 | ||||
|
24 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |||
|
25 | ||||
|
26 | QRectF boundingRect() const; | |||
|
27 | ||||
|
28 | public: | |||
|
29 | // From QGraphicsObject | |||
|
30 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |||
|
31 | ||||
|
32 | Q_SIGNALS: | |||
|
33 | void clicked(QSeries* series, QString name); | |||
|
34 | void rightClicked(QSeries* series, QString name); | |||
|
35 | ||||
|
36 | private: | |||
|
37 | QRectF mBoundingRect; | |||
|
38 | QBrush mBrush; | |||
|
39 | QString mName; | |||
|
40 | QSeries* mSeries; | |||
|
41 | }; | |||
|
42 | ||||
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
44 | #endif // LEGENDMARKER_P_H |
@@ -1,390 +1,390 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | #include "chartanimator_p.h" |
|
6 | #include "chartanimator_p.h" | |
7 | //series |
|
7 | //series | |
8 | #include "qbarseries.h" |
|
8 | #include "qbarseries.h" | |
9 | #include "qstackedbarseries.h" |
|
9 | #include "qstackedbarseries.h" | |
10 | #include "qpercentbarseries.h" |
|
10 | #include "qpercentbarseries.h" | |
11 | #include "qlineseries.h" |
|
11 | #include "qlineseries.h" | |
12 | #include "qareaseries.h" |
|
12 | #include "qareaseries.h" | |
13 | #include "qpieseries.h" |
|
13 | #include "qpieseries.h" | |
14 | #include "qscatterseries.h" |
|
14 | #include "qscatterseries.h" | |
15 | #include "qsplineseries.h" |
|
15 | #include "qsplineseries.h" | |
16 | //items |
|
16 | //items | |
17 | #include "axisitem_p.h" |
|
17 | #include "axisitem_p.h" | |
18 | #include "areachartitem_p.h" |
|
18 | #include "areachartitem_p.h" | |
19 | #include "barpresenter_p.h" |
|
19 | #include "barpresenter_p.h" | |
20 | #include "stackedbarpresenter_p.h" |
|
20 | #include "stackedbarpresenter_p.h" | |
21 | #include "percentbarpresenter_p.h" |
|
21 | #include "percentbarpresenter_p.h" | |
22 | #include "linechartitem_p.h" |
|
22 | #include "linechartitem_p.h" | |
23 | #include "piepresenter_p.h" |
|
23 | #include "piepresenter_p.h" | |
24 | #include "scatterchartitem_p.h" |
|
24 | #include "scatterchartitem_p.h" | |
25 | #include "splinechartitem_p.h" |
|
25 | #include "splinechartitem_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
29 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
30 | m_chart(chart), |
|
30 | m_chart(chart), | |
31 | m_animator(0), |
|
31 | m_animator(0), | |
32 | m_dataset(dataset), |
|
32 | m_dataset(dataset), | |
33 | m_chartTheme(0), |
|
33 | m_chartTheme(0), | |
34 | m_zoomIndex(0), |
|
34 | m_zoomIndex(0), | |
35 | m_marginSize(0), |
|
35 | m_marginSize(0), | |
36 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
36 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
37 | m_options(QChart::NoAnimation) |
|
37 | m_options(QChart::NoAnimation) | |
38 | { |
|
38 | { | |
39 | createConnections(); |
|
39 | createConnections(); | |
40 | setChartTheme(QChart::ChartThemeDefault); |
|
40 | setChartTheme(QChart::ChartThemeDefault); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | ChartPresenter::~ChartPresenter() |
|
43 | ChartPresenter::~ChartPresenter() | |
44 | { |
|
44 | { | |
45 | delete m_chartTheme; |
|
45 | delete m_chartTheme; | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | void ChartPresenter::createConnections() |
|
48 | void ChartPresenter::createConnections() | |
49 | { |
|
49 | { | |
50 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
50 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
51 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
51 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
52 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
52 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
53 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
53 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
54 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
54 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | QRectF ChartPresenter::geometry() const |
|
58 | QRectF ChartPresenter::geometry() const | |
59 | { |
|
59 | { | |
60 | return m_rect; |
|
60 | return m_rect; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void ChartPresenter::handleGeometryChanged() |
|
63 | void ChartPresenter::handleGeometryChanged() | |
64 | { |
|
64 | { | |
65 | QRectF rect(QPoint(0,0),m_chart->size()); |
|
65 | QRectF rect(QPoint(0,0),m_chart->size()); | |
66 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
66 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
67 |
|
67 | |||
68 | //rewrite zoom stack |
|
68 | //rewrite zoom stack | |
69 | for(int i=0;i<m_zoomStack.count();i++){ |
|
69 | for(int i=0;i<m_zoomStack.count();i++){ | |
70 | QRectF r = m_zoomStack[i]; |
|
70 | QRectF r = m_zoomStack[i]; | |
71 | qreal w = rect.width()/m_rect.width(); |
|
71 | qreal w = rect.width()/m_rect.width(); | |
72 | qreal h = rect.height()/m_rect.height(); |
|
72 | qreal h = rect.height()/m_rect.height(); | |
73 | QPointF tl = r.topLeft(); |
|
73 | QPointF tl = r.topLeft(); | |
74 | tl.setX(tl.x()*w); |
|
74 | tl.setX(tl.x()*w); | |
75 | tl.setY(tl.y()*h); |
|
75 | tl.setY(tl.y()*h); | |
76 | QPointF br = r.bottomRight(); |
|
76 | QPointF br = r.bottomRight(); | |
77 | br.setX(br.x()*w); |
|
77 | br.setX(br.x()*w); | |
78 | br.setY(br.y()*h); |
|
78 | br.setY(br.y()*h); | |
79 | r.setTopLeft(tl); |
|
79 | r.setTopLeft(tl); | |
80 | r.setBottomRight(br); |
|
80 | r.setBottomRight(br); | |
81 | m_zoomStack[i]=r; |
|
81 | m_zoomStack[i]=r; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | m_rect = rect; |
|
84 | m_rect = rect; | |
85 | Q_ASSERT(m_rect.isValid()); |
|
85 | Q_ASSERT(m_rect.isValid()); | |
86 | emit geometryChanged(m_rect); |
|
86 | emit geometryChanged(m_rect); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | int ChartPresenter::margin() const |
|
89 | int ChartPresenter::margin() const | |
90 | { |
|
90 | { | |
91 | return m_marginSize; |
|
91 | return m_marginSize; | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void ChartPresenter::setMargin(int margin) |
|
94 | void ChartPresenter::setMargin(int margin) | |
95 | { |
|
95 | { | |
96 | m_marginSize = margin; |
|
96 | m_marginSize = margin; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) |
|
99 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
100 | { |
|
100 | { | |
101 | AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
101 | AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
102 |
|
102 | |||
103 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
103 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
104 | m_animator->addAnimation(item); |
|
104 | m_animator->addAnimation(item); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | if(axis==m_dataset->axisX()){ |
|
107 | if(axis==m_dataset->axisX()){ | |
108 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
108 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
109 | //initialize |
|
109 | //initialize | |
110 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
110 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
111 | } |
|
111 | } | |
112 | else{ |
|
112 | else{ | |
113 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
113 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
114 | //initialize |
|
114 | //initialize | |
115 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
115 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
118 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
119 | //initialize |
|
119 | //initialize | |
120 | item->handleGeometryChanged(m_rect); |
|
120 | item->handleGeometryChanged(m_rect); | |
121 | m_chartTheme->decorate(axis,item); |
|
121 | m_chartTheme->decorate(axis,item); | |
122 | m_axisItems.insert(axis,item); |
|
122 | m_axisItems.insert(axis,item); | |
123 |
|
123 | |||
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
126 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
127 | { |
|
127 | { | |
128 | AxisItem* item = m_axisItems.take(axis); |
|
128 | AxisItem* item = m_axisItems.take(axis); | |
129 | Q_ASSERT(item); |
|
129 | Q_ASSERT(item); | |
130 | if(m_animator) m_animator->removeAnimation(item); |
|
130 | if(m_animator) m_animator->removeAnimation(item); | |
131 | delete item; |
|
131 | delete item; | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 |
|
134 | |||
135 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
135 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
136 | { |
|
136 | { | |
137 | ChartItem *item = 0 ; |
|
137 | ChartItem *item = 0 ; | |
138 |
|
138 | |||
139 | switch(series->type()) |
|
139 | switch(series->type()) | |
140 | { |
|
140 | { | |
141 | case QSeries::SeriesTypeLine: { |
|
141 | case QSeries::SeriesTypeLine: { | |
142 |
|
142 | |||
143 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
143 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
144 | LineChartItem* line = new LineChartItem(lineSeries,m_chart); |
|
144 | LineChartItem* line = new LineChartItem(lineSeries,m_chart); | |
145 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
145 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
146 | m_animator->addAnimation(line); |
|
146 | m_animator->addAnimation(line); | |
147 | } |
|
147 | } | |
148 | m_chartTheme->decorate(line, lineSeries, m_dataset->seriesIndex(series)); |
|
148 | m_chartTheme->decorate(line, lineSeries, m_dataset->seriesIndex(series)); | |
149 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); |
|
149 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); | |
150 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
150 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
151 | item = line; |
|
151 | item = line; | |
152 | break; |
|
152 | break; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | case QSeries::SeriesTypeArea: { |
|
155 | case QSeries::SeriesTypeArea: { | |
156 |
|
156 | |||
157 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
157 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
158 | AreaChartItem* area = new AreaChartItem(areaSeries,m_chart); |
|
158 | AreaChartItem* area = new AreaChartItem(areaSeries,m_chart); | |
159 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
159 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
160 | // m_animator->addAnimation(area); |
|
160 | // m_animator->addAnimation(area); | |
161 | } |
|
161 | } | |
162 | m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series)); |
|
162 | m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series)); | |
163 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); |
|
163 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); | |
164 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
164 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
165 | item=area; |
|
165 | item=area; | |
166 | break; |
|
166 | break; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | case QSeries::SeriesTypeBar: { |
|
169 | case QSeries::SeriesTypeBar: { | |
170 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
170 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
171 | BarPresenter* bar = new BarPresenter(barSeries,m_chart); |
|
171 | BarPresenter* bar = new BarPresenter(barSeries,m_chart); | |
172 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
172 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
173 | // m_animator->addAnimation(bar); |
|
173 | // m_animator->addAnimation(bar); | |
174 | } |
|
174 | } | |
175 | m_chartTheme->decorate(bar, barSeries, m_dataset->seriesIndex(barSeries)); |
|
175 | m_chartTheme->decorate(bar, barSeries, m_dataset->seriesIndex(barSeries)); | |
176 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
176 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
177 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
177 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
178 | item=bar; |
|
178 | item=bar; | |
179 | break; |
|
179 | break; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | case QSeries::SeriesTypeStackedBar: { |
|
182 | case QSeries::SeriesTypeStackedBar: { | |
183 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
183 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
184 | StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
184 | StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart); | |
185 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
185 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
186 | // m_animator->addAnimation(bar); |
|
186 | // m_animator->addAnimation(bar); | |
187 | } |
|
187 | } | |
188 | m_chartTheme->decorate(bar, stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); |
|
188 | m_chartTheme->decorate(bar, stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); | |
189 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
189 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
190 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
190 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
191 | item=bar; |
|
191 | item=bar; | |
192 | break; |
|
192 | break; | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | case QSeries::SeriesTypePercentBar: { |
|
195 | case QSeries::SeriesTypePercentBar: { | |
196 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
196 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
197 | PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart); |
|
197 | PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart); | |
198 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
198 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
199 | // m_animator->addAnimation(bar); |
|
199 | // m_animator->addAnimation(bar); | |
200 | } |
|
200 | } | |
201 | m_chartTheme->decorate(bar, percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); |
|
201 | m_chartTheme->decorate(bar, percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); | |
202 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
202 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
203 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
203 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
204 | item=bar; |
|
204 | item=bar; | |
205 | break; |
|
205 | break; | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | case QSeries::SeriesTypeScatter: { |
|
208 | case QSeries::SeriesTypeScatter: { | |
209 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
209 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
210 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart); |
|
210 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart); | |
211 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
211 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
212 | m_animator->addAnimation(scatter); |
|
212 | m_animator->addAnimation(scatter); | |
213 | } |
|
213 | } | |
214 | m_chartTheme->decorate(scatter, scatterSeries, m_dataset->seriesIndex(series)); |
|
214 | m_chartTheme->decorate(scatter, scatterSeries, m_dataset->seriesIndex(series)); | |
215 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); |
|
215 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); | |
216 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
216 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
217 | item = scatter; |
|
217 | item = scatter; | |
218 | break; |
|
218 | break; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | case QSeries::SeriesTypePie: { |
|
221 | case QSeries::SeriesTypePie: { | |
222 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
222 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
223 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); |
|
223 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); | |
224 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
224 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
225 | // m_animator->addAnimation(pie); |
|
225 | // m_animator->addAnimation(pie); | |
226 | } |
|
226 | } | |
227 | m_chartTheme->decorate(pie, pieSeries, m_dataset->seriesIndex(series)); |
|
227 | m_chartTheme->decorate(pie, pieSeries, m_dataset->seriesIndex(series)); | |
228 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); |
|
228 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); | |
229 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
229 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
230 | // Hide all from background when there is only piechart |
|
230 | // Hide all from background when there is only piechart | |
231 | // TODO: refactor this ugly code... should be one setting for this |
|
231 | // TODO: refactor this ugly code... should be one setting for this | |
232 | if (m_chartItems.count() == 0) { |
|
232 | if (m_chartItems.count() == 0) { | |
233 | m_chart->axisX()->hide(); |
|
233 | m_chart->axisX()->hide(); | |
234 | m_chart->axisY()->hide(); |
|
234 | m_chart->axisY()->hide(); | |
235 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
235 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
236 | } |
|
236 | } | |
237 | item=pie; |
|
237 | item=pie; | |
238 | break; |
|
238 | break; | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | case QSeries::SeriesTypeSpline: { |
|
241 | case QSeries::SeriesTypeSpline: { | |
242 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
242 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
243 | SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart); |
|
243 | SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart); | |
244 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
244 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
245 | m_animator->addAnimation(spline); |
|
245 | m_animator->addAnimation(spline); | |
246 | } |
|
246 | } | |
247 | m_chartTheme->decorate(spline, splineSeries, m_dataset->seriesIndex(series)); |
|
247 | m_chartTheme->decorate(spline, splineSeries, m_dataset->seriesIndex(series)); | |
248 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); |
|
248 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); | |
249 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
249 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
250 | item=spline; |
|
250 | item=spline; | |
251 | break; |
|
251 | break; | |
252 | } |
|
252 | } | |
253 | default: { |
|
253 | default: { | |
254 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
254 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
255 | break; |
|
255 | break; | |
256 | } |
|
256 | } | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | //initialize |
|
259 | //initialize | |
260 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
260 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
261 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
261 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
262 | m_chartItems.insert(series,item); |
|
262 | m_chartItems.insert(series,item); | |
263 | zoomReset(); |
|
263 | zoomReset(); | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
266 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
267 | { |
|
267 | { | |
268 | ChartItem* item = m_chartItems.take(series); |
|
268 | ChartItem* item = m_chartItems.take(series); | |
269 | Q_ASSERT(item); |
|
269 | Q_ASSERT(item); | |
270 | if(m_animator) m_animator->removeAnimation(item); |
|
270 | if(m_animator) m_animator->removeAnimation(item); | |
271 | delete item; |
|
271 | delete item; | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
274 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
275 | { |
|
275 | { | |
276 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
276 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
277 | delete m_chartTheme; |
|
277 | delete m_chartTheme; | |
278 | m_chartTheme = ChartTheme::createTheme(theme); |
|
278 | m_chartTheme = ChartTheme::createTheme(theme); | |
279 | m_chartTheme->decorate(m_chart); |
|
279 | m_chartTheme->decorate(m_chart); | |
280 | m_chartTheme->decorate(m_chart->legend()); |
|
280 | m_chartTheme->decorate(m_chart->legend()); | |
281 | resetAllElements(); |
|
281 | resetAllElements(); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
284 | QChart::ChartTheme ChartPresenter::chartTheme() | |
285 | { |
|
285 | { | |
286 | return m_chartTheme->id(); |
|
286 | return m_chartTheme->id(); | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
289 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
290 | { |
|
290 | { | |
291 | if(m_options!=options) { |
|
291 | if(m_options!=options) { | |
292 |
|
292 | |||
293 | m_options=options; |
|
293 | m_options=options; | |
294 |
|
294 | |||
295 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
295 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
296 | m_animator= new ChartAnimator(this); |
|
296 | m_animator= new ChartAnimator(this); | |
297 |
|
297 | |||
298 | } |
|
298 | } | |
299 | resetAllElements(); |
|
299 | resetAllElements(); | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void ChartPresenter::resetAllElements() |
|
304 | void ChartPresenter::resetAllElements() | |
305 | { |
|
305 | { | |
306 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
306 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
307 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
307 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
308 |
|
308 | |||
309 | foreach(QChartAxis* axis, axisList) { |
|
309 | foreach(QChartAxis* axis, axisList) { | |
310 | handleAxisRemoved(axis); |
|
310 | handleAxisRemoved(axis); | |
311 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
311 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
312 | } |
|
312 | } | |
313 | foreach(QSeries* series, seriesList) { |
|
313 | foreach(QSeries* series, seriesList) { | |
314 | handleSeriesRemoved(series); |
|
314 | handleSeriesRemoved(series); | |
315 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
315 | handleSeriesAdded(series,m_dataset->domain(series)); | |
316 | } |
|
316 | } | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | void ChartPresenter::zoomIn() |
|
319 | void ChartPresenter::zoomIn() | |
320 | { |
|
320 | { | |
321 | QRectF rect = geometry(); |
|
321 | QRectF rect = geometry(); | |
322 | rect.setWidth(rect.width()/2); |
|
322 | rect.setWidth(rect.width()/2); | |
323 | rect.setHeight(rect.height()/2); |
|
323 | rect.setHeight(rect.height()/2); | |
324 | rect.moveCenter(geometry().center()); |
|
324 | rect.moveCenter(geometry().center()); | |
325 | zoomIn(rect); |
|
325 | zoomIn(rect); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
328 | void ChartPresenter::zoomIn(const QRectF& rect) | |
329 | { |
|
329 | { | |
330 | QRectF r = rect.normalized(); |
|
330 | QRectF r = rect.normalized(); | |
331 | r.translate(-m_marginSize, -m_marginSize); |
|
331 | r.translate(-m_marginSize, -m_marginSize); | |
332 | if(m_animator) { |
|
332 | if(m_animator) { | |
333 |
|
333 | |||
334 | QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height()); |
|
334 | QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height()); | |
335 | m_animator->setState(ChartAnimator::ZoomInState,point); |
|
335 | m_animator->setState(ChartAnimator::ZoomInState,point); | |
336 | } |
|
336 | } | |
337 | m_dataset->zoomInDomain(r,geometry().size()); |
|
337 | m_dataset->zoomInDomain(r,geometry().size()); | |
338 | m_zoomStack<<r; |
|
338 | m_zoomStack<<r; | |
339 | m_zoomIndex++; |
|
339 | m_zoomIndex++; | |
340 | if(m_animator) { |
|
340 | if(m_animator) { | |
341 | m_animator->setState(ChartAnimator::ShowState); |
|
341 | m_animator->setState(ChartAnimator::ShowState); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | void ChartPresenter::zoomOut() |
|
345 | void ChartPresenter::zoomOut() | |
346 | { |
|
346 | { | |
347 | if(m_zoomIndex==0) return; |
|
347 | if(m_zoomIndex==0) return; | |
348 | if(m_animator) |
|
348 | if(m_animator) | |
349 | { |
|
349 | { | |
350 | m_animator->setState(ChartAnimator::ZoomOutState); |
|
350 | m_animator->setState(ChartAnimator::ZoomOutState); | |
351 | } |
|
351 | } | |
352 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
352 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
353 | m_zoomIndex--; |
|
353 | m_zoomIndex--; | |
354 | m_zoomStack.resize(m_zoomIndex); |
|
354 | m_zoomStack.resize(m_zoomIndex); | |
355 | if(m_animator){ |
|
355 | if(m_animator){ | |
356 | m_animator->setState(ChartAnimator::ShowState); |
|
356 | m_animator->setState(ChartAnimator::ShowState); | |
357 | } |
|
357 | } | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | void ChartPresenter::zoomReset() |
|
360 | void ChartPresenter::zoomReset() | |
361 | { |
|
361 | { | |
362 | m_zoomIndex=0; |
|
362 | m_zoomIndex=0; | |
363 | m_zoomStack.resize(m_zoomIndex); |
|
363 | m_zoomStack.resize(m_zoomIndex); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | void ChartPresenter::scroll(int dx,int dy) |
|
366 | void ChartPresenter::scroll(int dx,int dy) | |
367 | { |
|
367 | { | |
368 | if(m_animator){ |
|
368 | if(m_animator){ | |
369 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); |
|
369 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | |
370 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); |
|
370 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | |
371 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); |
|
371 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | |
372 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); |
|
372 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | m_dataset->scrollDomain(dx,dy,geometry().size()); |
|
375 | m_dataset->scrollDomain(dx,dy,geometry().size()); | |
376 |
|
376 | |||
377 |
|
|
377 | if(m_animator){ | |
378 | m_animator->setState(ChartAnimator::ShowState); |
|
378 | m_animator->setState(ChartAnimator::ShowState); | |
379 | } |
|
379 | } | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
382 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
383 | { |
|
383 | { | |
384 | return m_options; |
|
384 | return m_options; | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 |
|
387 | |||
388 | #include "moc_chartpresenter_p.cpp" |
|
388 | #include "moc_chartpresenter_p.cpp" | |
389 |
|
389 | |||
390 | QTCOMMERCIALCHART_END_NAMESPACE |
|
390 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,140 +1,119 | |||||
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 <QPainter> |
|
5 | #include <QPainter> | |
5 | #include <QPen> |
|
6 | #include <QPen> | |
6 |
|
7 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | #include <QGraphicsSceneEvent> | |
8 |
|
||||
9 | // TODO: this to legendmarker_p.h header |
|
|||
10 | class LegendMarker : public QGraphicsItem |
|
|||
11 | { |
|
|||
12 | public: |
|
|||
13 | LegendMarker(QGraphicsItem *parent = 0) : QGraphicsItem(parent) |
|
|||
14 | ,mBoundingRect(0,0,1,1) |
|
|||
15 | {} |
|
|||
16 |
|
||||
17 | void setBoundingRect(const QRectF rect) { mBoundingRect = rect; } |
|
|||
18 | void setBrush(const QBrush brush) { mBrush = brush; } |
|
|||
19 | void setName(const QString name) { mName = name; } |
|
|||
20 | QString name() const { return mName; } |
|
|||
21 | QColor color() const { return mBrush.color(); } |
|
|||
22 |
|
||||
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) |
|
|||
24 | { |
|
|||
25 | painter->setBrush(mBrush); |
|
|||
26 | painter->drawRect(mBoundingRect); |
|
|||
27 | } |
|
|||
28 |
|
||||
29 | QRectF boundingRect() const { return mBoundingRect; } |
|
|||
30 |
|
9 | |||
31 | private: |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 | QRectF mBoundingRect; |
|
|||
33 | QBrush mBrush; |
|
|||
34 | QString mName; |
|
|||
35 | }; |
|
|||
36 |
|
11 | |||
37 | QLegend::QLegend(QGraphicsItem *parent) |
|
12 | QLegend::QLegend(QGraphicsItem *parent) | |
38 | : QGraphicsObject(parent) |
|
13 | : QGraphicsObject(parent) | |
39 | ,mBoundingRect(0,0,1,1) |
|
14 | ,mBoundingRect(0,0,1,1) | |
40 | ,mBackgroundBrush(Qt::darkGray) // TODO: from theme? |
|
15 | ,mBackgroundBrush(Qt::darkGray) // TODO: from theme? | |
41 | { |
|
16 | { | |
42 | } |
|
17 | } | |
43 |
|
18 | |||
44 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
19 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
45 | { |
|
20 | { | |
46 | painter->setBrush(mBackgroundBrush); |
|
21 | painter->setBrush(mBackgroundBrush); | |
47 | painter->drawRect(mBoundingRect); |
|
22 | painter->drawRect(mBoundingRect); | |
48 |
|
23 | |||
49 | foreach(LegendMarker* m, mMarkers) { |
|
24 | foreach(LegendMarker* m, mMarkers) { | |
50 | QRectF r = m->boundingRect(); |
|
25 | QRectF r = m->boundingRect(); | |
51 | painter->setPen(m->color()); |
|
26 | painter->setPen(m->color()); | |
52 |
painter->drawText(r.x() + 2 |
|
27 | painter->drawText(r.x() + r.width()*2, r.y() + r.height(), m->name()); | |
53 | } |
|
28 | } | |
54 | } |
|
29 | } | |
55 |
|
30 | |||
56 | QRectF QLegend::boundingRect() const |
|
31 | QRectF QLegend::boundingRect() const | |
57 | { |
|
32 | { | |
58 | return mBoundingRect; |
|
33 | return mBoundingRect; | |
59 | } |
|
34 | } | |
60 |
|
35 | |||
61 | void QLegend::setBackgroundBrush(const QBrush& brush) |
|
36 | void QLegend::setBackgroundBrush(const QBrush& brush) | |
62 | { |
|
37 | { | |
63 | mBackgroundBrush = brush; |
|
38 | mBackgroundBrush = brush; | |
64 | } |
|
39 | } | |
65 |
|
40 | |||
66 | QBrush QLegend::backgroundBrush() const |
|
41 | QBrush QLegend::backgroundBrush() const | |
67 | { |
|
42 | { | |
68 | return mBackgroundBrush; |
|
43 | return mBackgroundBrush; | |
69 | } |
|
44 | } | |
70 |
|
45 | |||
71 | void QLegend::handleSeriesAdded(QSeries* series,Domain* domain) |
|
46 | void QLegend::handleSeriesAdded(QSeries* series,Domain* domain) | |
72 | { |
|
47 | { | |
73 | mSeriesList.append(series); |
|
48 | mSeriesList.append(series); | |
74 | dataChanged(); |
|
49 | dataChanged(); | |
75 | layoutChanged(); |
|
50 | layoutChanged(); | |
76 | } |
|
51 | } | |
77 |
|
52 | |||
78 | void QLegend::handleSeriesRemoved(QSeries* series) |
|
53 | void QLegend::handleSeriesRemoved(QSeries* series) | |
79 | { |
|
54 | { | |
80 | mSeriesList.removeOne(series); |
|
55 | mSeriesList.removeOne(series); | |
81 | dataChanged(); |
|
56 | dataChanged(); | |
82 | layoutChanged(); |
|
57 | layoutChanged(); | |
83 | } |
|
58 | } | |
84 |
|
59 | |||
85 | void QLegend::handleGeometryChanged(const QRectF& size) |
|
60 | void QLegend::handleGeometryChanged(const QRectF& size) | |
86 | { |
|
61 | { | |
87 | mBoundingRect = size; |
|
62 | mBoundingRect = size; | |
88 | layoutChanged(); |
|
63 | layoutChanged(); | |
89 | } |
|
64 | } | |
90 |
|
65 | |||
91 | void QLegend::dataChanged() |
|
66 | void QLegend::dataChanged() | |
92 | { |
|
67 | { | |
93 | foreach (QGraphicsItem* i, childItems()) { |
|
68 | foreach (LegendMarker* marker, mMarkers) { | |
94 | delete i; |
|
69 | disconnect(marker,SIGNAL(clicked(QSeries*,QString)),this,SIGNAL(clicked(QSeries*,QString))); | |
|
70 | disconnect(marker,SIGNAL(rightClicked(QSeries*,QString)),this,SIGNAL(rightClicked(QSeries*,QString))); | |||
|
71 | delete marker; | |||
95 | } |
|
72 | } | |
96 |
|
73 | |||
97 | mMarkers.clear(); |
|
74 | mMarkers.clear(); | |
98 |
|
75 | |||
99 | foreach (QSeries* s, mSeriesList) { |
|
76 | foreach (QSeries* s, mSeriesList) { | |
100 | for (int i=0; i<s->legendEntries().count(); i++) { |
|
77 | for (int i=0; i<s->legendEntries().count(); i++) { | |
101 | LegendMarker *marker = new LegendMarker(this); |
|
78 | LegendMarker *marker = new LegendMarker(s, this); | |
102 | marker->setBrush(s->legendEntries().at(i).mBrush); |
|
79 | marker->setBrush(s->legendEntries().at(i).mBrush); | |
103 | marker->setName(s->legendEntries().at(i).mName); |
|
80 | marker->setName(s->legendEntries().at(i).mName); | |
104 | mMarkers.append(marker); |
|
81 | mMarkers.append(marker); | |
105 |
|
|
82 | 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))); | |||
106 | } |
|
85 | } | |
107 | } |
|
86 | } | |
108 | } |
|
87 | } | |
109 |
|
88 | |||
110 | void QLegend::layoutChanged() |
|
89 | void QLegend::layoutChanged() | |
111 | { |
|
90 | { | |
112 | // Calculate layout for markers and text |
|
91 | // Calculate layout for markers and text | |
113 | if (mMarkers.count() <= 0) { |
|
92 | if (mMarkers.count() <= 0) { | |
114 | // Nothing to do |
|
93 | // Nothing to do | |
115 | return; |
|
94 | return; | |
116 | } |
|
95 | } | |
117 |
|
96 | |||
118 | // TODO: marker defined by series. |
|
97 | // TODO: marker defined by series. | |
119 | QSizeF markerSize(10,10); |
|
98 | QSizeF markerSize(10,10); | |
120 |
|
99 | |||
121 | // TODO: better layout, this is just concept. |
|
100 | // TODO: better layout, this is just concept. | |
122 | // Leave some space around markers like this: | x x x x | |
|
101 | // Leave some space around markers like this: | x x x x | | |
123 | qreal steps = mMarkers.count(); |
|
102 | qreal steps = mMarkers.count(); | |
124 |
|
103 | |||
125 | qreal xStep = mBoundingRect.width() / steps; |
|
104 | qreal xStep = mBoundingRect.width() / steps; | |
126 | qreal yStep = mBoundingRect.height() / steps; |
|
105 | qreal yStep = mBoundingRect.height() / steps; | |
127 | qreal x = mBoundingRect.x() + 5; |
|
106 | qreal x = mBoundingRect.x() + 5; | |
128 | qreal y = mBoundingRect.y() + (mBoundingRect.height() - markerSize.height())/2; |
|
107 | qreal y = mBoundingRect.y() + (mBoundingRect.height() - markerSize.height())/2; | |
129 | foreach (LegendMarker* m, mMarkers) { |
|
108 | foreach (LegendMarker* m, mMarkers) { | |
130 | qDebug() << "marker x:" << x; |
|
109 | qDebug() << "marker x:" << x; | |
131 | qDebug() << "marker y:" << y; |
|
110 | qDebug() << "marker y:" << y; | |
132 | m->setBoundingRect(QRectF(x,y,markerSize.width(),markerSize.height())); |
|
111 | m->setBoundingRect(QRectF(x,y,markerSize.width(),markerSize.height())); | |
133 | x += xStep; |
|
112 | x += xStep; | |
134 | } |
|
113 | } | |
135 | } |
|
114 | } | |
136 |
|
115 | |||
137 |
|
116 | |||
138 |
|
117 | |||
139 | #include "moc_qlegend.cpp" |
|
118 | #include "moc_qlegend.cpp" | |
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,49 | |||||
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 |
|
12 | |||
13 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject |
|
13 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 | public: |
|
16 | public: | |
17 |
|
17 | |||
18 | explicit QLegend(QGraphicsItem *parent = 0); |
|
18 | explicit QLegend(QGraphicsItem *parent = 0); | |
19 |
|
19 | |||
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
21 | QRectF boundingRect() const; |
|
21 | QRectF boundingRect() const; | |
22 |
|
22 | |||
23 | void setBackgroundBrush(const QBrush& brush); |
|
23 | void setBackgroundBrush(const QBrush& brush); | |
24 | QBrush backgroundBrush() const; |
|
24 | QBrush backgroundBrush() const; | |
25 |
|
25 | |||
26 | signals: |
|
26 | signals: | |
27 |
|
27 | // for interactions. | ||
|
28 | void clicked(QSeries* series, QString name); | |||
|
29 | void rightClicked(QSeries* series, QString name); | |||
|
30 | ||||
28 | public slots: |
|
31 | public slots: | |
29 | void handleSeriesAdded(QSeries* series,Domain* domain); |
|
32 | void handleSeriesAdded(QSeries* series,Domain* domain); | |
30 | void handleSeriesRemoved(QSeries* series); |
|
33 | void handleSeriesRemoved(QSeries* series); | |
31 | void handleGeometryChanged(const QRectF& size); |
|
34 | void handleGeometryChanged(const QRectF& size); | |
32 |
|
35 | |||
33 | private: |
|
36 | private: | |
34 | void dataChanged(); |
|
37 | void dataChanged(); | |
35 | void layoutChanged(); |
|
38 | void layoutChanged(); | |
36 |
|
39 | |||
37 | QRectF mBoundingRect; |
|
40 | QRectF mBoundingRect; | |
38 | QList<QSeries*> mSeriesList; |
|
41 | QList<QSeries*> mSeriesList; | |
39 | QList<LegendMarker*> mMarkers; |
|
42 | QList<LegendMarker*> mMarkers; | |
40 |
|
43 | |||
41 | QBrush mBackgroundBrush; |
|
44 | QBrush mBackgroundBrush; | |
42 | }; |
|
45 | }; | |
43 |
|
46 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
47 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
48 | |||
46 | #endif // QLEGEND_H |
|
49 | #endif // QLEGEND_H |
@@ -1,96 +1,98 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | CONFIG += debug_and_release |
|
7 | CONFIG += debug_and_release | |
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
9 | SOURCES += \ |
|
9 | SOURCES += \ | |
10 | chartdataset.cpp \ |
|
10 | chartdataset.cpp \ | |
11 | chartpresenter.cpp \ |
|
11 | chartpresenter.cpp \ | |
12 | charttheme.cpp \ |
|
12 | charttheme.cpp \ | |
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 | qlegend.cpp \ | |
|
18 | legendmarker.cpp | |||
18 | PRIVATE_HEADERS += \ |
|
19 | PRIVATE_HEADERS += \ | |
19 | chartdataset_p.h \ |
|
20 | chartdataset_p.h \ | |
20 | chartitem_p.h \ |
|
21 | chartitem_p.h \ | |
21 | chartpresenter_p.h \ |
|
22 | chartpresenter_p.h \ | |
22 | charttheme_p.h \ |
|
23 | charttheme_p.h \ | |
23 | domain_p.h |
|
24 | domain_p.h \ | |
24 | PUBLIC_HEADERS += \ |
|
25 | legendmarker_p.h | |
|
26 | PUBLIC_HEADERS += \ | |||
25 | qchart.h \ |
|
27 | qchart.h \ | |
26 | qchartglobal.h \ |
|
28 | qchartglobal.h \ | |
27 | qseries.h \ |
|
29 | qseries.h \ | |
28 | qchartview.h \ |
|
30 | qchartview.h \ | |
29 | qlegend.h |
|
31 | qlegend.h | |
30 |
|
32 | |||
31 | include(animations/animations.pri) |
|
33 | include(animations/animations.pri) | |
32 | include(axis/axis.pri) |
|
34 | include(axis/axis.pri) | |
33 | include(xychart/xychart.pri) |
|
35 | include(xychart/xychart.pri) | |
34 | include(linechart/linechart.pri) |
|
36 | include(linechart/linechart.pri) | |
35 | include(areachart/areachart.pri) |
|
37 | include(areachart/areachart.pri) | |
36 | include(barchart/barchart.pri) |
|
38 | include(barchart/barchart.pri) | |
37 | include(piechart/piechart.pri) |
|
39 | include(piechart/piechart.pri) | |
38 | include(scatterseries/scatter.pri) |
|
40 | include(scatterseries/scatter.pri) | |
39 | include(splinechart/splinechart.pri) |
|
41 | include(splinechart/splinechart.pri) | |
40 |
|
42 | |||
41 | THEMES += themes/chartthemedefault_p.h \ |
|
43 | THEMES += themes/chartthemedefault_p.h \ | |
42 | themes/chartthemeicy_p.h \ |
|
44 | themes/chartthemeicy_p.h \ | |
43 | themes/chartthemegrayscale_p.h \ |
|
45 | themes/chartthemegrayscale_p.h \ | |
44 | themes/chartthemescientific_p.h \ |
|
46 | themes/chartthemescientific_p.h \ | |
45 | themes/chartthemevanilla_p.h |
|
47 | themes/chartthemevanilla_p.h | |
46 | HEADERS += $$PUBLIC_HEADERS |
|
48 | HEADERS += $$PUBLIC_HEADERS | |
47 | HEADERS += $$PRIVATE_HEADERS |
|
49 | HEADERS += $$PRIVATE_HEADERS | |
48 | HEADERS += $$THEMES |
|
50 | HEADERS += $$THEMES | |
49 | INCLUDEPATH += linechart \ |
|
51 | INCLUDEPATH += linechart \ | |
50 | barchart \ |
|
52 | barchart \ | |
51 | themes \ |
|
53 | themes \ | |
52 | . |
|
54 | . | |
53 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
55 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
54 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
56 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
55 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
57 | UI_DIR = $$CHART_BUILD_DIR/lib | |
56 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
58 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
57 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
59 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
58 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
60 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
59 | public_headers.files = $$PUBLIC_HEADERS |
|
61 | public_headers.files = $$PUBLIC_HEADERS | |
60 | target.path = $$[QT_INSTALL_LIBS] |
|
62 | target.path = $$[QT_INSTALL_LIBS] | |
61 | INSTALLS += target \ |
|
63 | INSTALLS += target \ | |
62 | public_headers |
|
64 | public_headers | |
63 | install_build_public_headers.name = bild_public_headers |
|
65 | install_build_public_headers.name = bild_public_headers | |
64 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
66 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
65 | install_build_public_headers.input = PUBLIC_HEADERS |
|
67 | install_build_public_headers.input = PUBLIC_HEADERS | |
66 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
68 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
67 | ${QMAKE_FILE_NAME} \ |
|
69 | ${QMAKE_FILE_NAME} \ | |
68 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
70 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
69 | install_build_public_headers.CONFIG += target_predeps \ |
|
71 | install_build_public_headers.CONFIG += target_predeps \ | |
70 | no_link |
|
72 | no_link | |
71 | install_build_private_headers.name = bild_private_headers |
|
73 | install_build_private_headers.name = bild_private_headers | |
72 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
74 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
73 | install_build_private_headers.input = PRIVATE_HEADERS |
|
75 | install_build_private_headers.input = PRIVATE_HEADERS | |
74 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
76 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
75 | ${QMAKE_FILE_NAME} \ |
|
77 | ${QMAKE_FILE_NAME} \ | |
76 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
78 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
77 | install_build_private_headers.CONFIG += target_predeps \ |
|
79 | install_build_private_headers.CONFIG += target_predeps \ | |
78 | no_link |
|
80 | no_link | |
79 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
81 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
80 | install_build_private_headers |
|
82 | install_build_private_headers | |
81 | chartversion.target = qchartversion_p.h |
|
83 | chartversion.target = qchartversion_p.h | |
82 | chartversion.commands = @echo \ |
|
84 | chartversion.commands = @echo \ | |
83 | "build_time" \ |
|
85 | "build_time" \ | |
84 | > \ |
|
86 | > \ | |
85 | $$chartversion.target; |
|
87 | $$chartversion.target; | |
86 | chartversion.depends = $$HEADERS \ |
|
88 | chartversion.depends = $$HEADERS \ | |
87 | $$SOURCES |
|
89 | $$SOURCES | |
88 | PRE_TARGETDEPS += qchartversion_p.h |
|
90 | PRE_TARGETDEPS += qchartversion_p.h | |
89 | QMAKE_CLEAN += qchartversion_p.h |
|
91 | QMAKE_CLEAN += qchartversion_p.h | |
90 | QMAKE_EXTRA_TARGETS += chartversion |
|
92 | QMAKE_EXTRA_TARGETS += chartversion | |
91 | unix:QMAKE_DISTCLEAN += -r \ |
|
93 | unix:QMAKE_DISTCLEAN += -r \ | |
92 | $$CHART_BUILD_HEADER_DIR \ |
|
94 | $$CHART_BUILD_HEADER_DIR \ | |
93 | $$CHART_BUILD_LIB_DIR |
|
95 | $$CHART_BUILD_LIB_DIR | |
94 | win32:QMAKE_DISTCLEAN += /Q \ |
|
96 | win32:QMAKE_DISTCLEAN += /Q \ | |
95 | $$CHART_BUILD_HEADER_DIR \ |
|
97 | $$CHART_BUILD_HEADER_DIR \ | |
96 | $$CHART_BUILD_LIB_DIR |
|
98 | $$CHART_BUILD_LIB_DIR |
General Comments 0
You need to be logged in to leave comments.
Login now