@@ -24,20 +24,6 void BarGroupBase::setSeparatorsVisible(bool visible) | |||||
24 | mSeparatorsVisible = visible; |
|
24 | mSeparatorsVisible = visible; | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | void BarGroupBase::setSize(const QSizeF& size) |
|
|||
28 | { |
|
|||
29 | mWidth = size.width(); |
|
|||
30 | mHeight = size.height(); |
|
|||
31 | layoutChanged(); |
|
|||
32 | mLayoutSet = true; |
|
|||
33 | } |
|
|||
34 |
|
||||
35 | void BarGroupBase::setPlotDomain(const PlotDomain& data) |
|
|||
36 | { |
|
|||
37 | qDebug() << "BarGroupBase::setPlotDomain"; |
|
|||
38 | // TODO: |
|
|||
39 | } |
|
|||
40 |
|
||||
41 | void BarGroupBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
27 | void BarGroupBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
42 | { |
|
28 | { | |
43 | if (!mLayoutSet) { |
|
29 | if (!mLayoutSet) { | |
@@ -119,4 +105,27 void BarGroupBase::dataChanged() | |||||
119 | mLayoutDirty = true; |
|
105 | mLayoutDirty = true; | |
120 | } |
|
106 | } | |
121 |
|
107 | |||
|
108 | //handlers | |||
|
109 | ||||
|
110 | void BarGroupBase::handleModelChanged(int index) | |||
|
111 | { | |||
|
112 | qDebug() << "BarGroupBase::handleModelChanged"; | |||
|
113 | } | |||
|
114 | ||||
|
115 | void BarGroupBase::handleDomainChanged(const Domain& domain) | |||
|
116 | { | |||
|
117 | qDebug() << "BarGroupBase::handleModelChanged"; | |||
|
118 | } | |||
|
119 | ||||
|
120 | void BarGroupBase::handleGeometryChanged(const QRectF& rect) | |||
|
121 | { | |||
|
122 | mWidth = rect.width(); | |||
|
123 | mHeight = rect.height(); | |||
|
124 | layoutChanged(); | |||
|
125 | mLayoutSet = true; | |||
|
126 | setPos(rect.topLeft()); | |||
|
127 | } | |||
|
128 | ||||
|
129 | #include "moc_bargroupbase.cpp" | |||
|
130 | ||||
122 | QTCOMMERCIALCHART_END_NAMESPACE |
|
131 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -12,16 +12,16 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
12 |
|
12 | |||
13 | // Base Class for bar groups. Common implemantation of different groups. Not to be instantiated. |
|
13 | // Base Class for bar groups. Common implemantation of different groups. Not to be instantiated. | |
14 |
|
14 | |||
15 |
class BarGroupBase : public |
|
15 | class BarGroupBase : public QObject, public ChartItem | |
16 | { |
|
16 | { | |
17 |
|
17 | Q_OBJECT | ||
18 | public: |
|
18 | public: | |
19 | BarGroupBase(BarChartSeriesBase& series, QGraphicsItem *parent = 0); |
|
19 | BarGroupBase(BarChartSeriesBase& series, QGraphicsItem *parent = 0); | |
20 | void setSeparatorsVisible(bool visible = true); |
|
20 | void setSeparatorsVisible(bool visible = true); | |
21 |
|
21 | |||
22 | public: // From ChartItem |
|
22 | public: // From ChartItem | |
23 | void setSize(const QSizeF &size); |
|
23 | void setSize(const QSizeF &size){}; | |
24 | void setPlotDomain(const PlotDomain& data); |
|
24 | void setPlotDomain(const PlotDomain& data){}; | |
25 |
|
25 | |||
26 | // From QGraphicsItem |
|
26 | // From QGraphicsItem | |
27 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
27 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
@@ -38,6 +38,12 public: // From ChartItem | |||||
38 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
38 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
39 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes |
|
39 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes | |
40 |
|
40 | |||
|
41 | protected slots: | |||
|
42 | void handleModelChanged(int index); | |||
|
43 | void handleDomainChanged(const Domain& domain); | |||
|
44 | void handleGeometryChanged(const QRectF& size); | |||
|
45 | ||||
|
46 | ||||
41 | protected: |
|
47 | protected: | |
42 |
|
48 | |||
43 | BarChartSeriesBase& mSeries; |
|
49 | BarChartSeriesBase& mSeries; |
@@ -1,5 +1,9 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
|
2 | //series | |||
2 | #include "qxychartseries.h" |
|
3 | #include "qxychartseries.h" | |
|
4 | #include "barchartseries.h" | |||
|
5 | #include "stackedbarchartseries.h" | |||
|
6 | #include "percentbarchartseries.h" | |||
3 |
|
7 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
9 | |||
@@ -43,11 +47,41 void ChartDataSet::addSeries(QChartSeries* series) | |||||
43 |
|
|
47 | domain.m_maxX = qMax(domain.m_maxX,x); | |
44 |
|
|
48 | domain.m_maxY = qMax(domain.m_maxY,y); | |
45 | } |
|
49 | } | |
|
50 | break; | |||
|
51 | } | |||
|
52 | case QChartSeries::SeriesTypeBar: { | |||
46 |
|
53 | |||
47 | emit domainChanged(); |
|
54 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
|
55 | qreal x = barSeries->countColumns(); | |||
|
56 | qreal y = barSeries->max(); | |||
|
57 | domain.m_minX = qMin(domain.m_minX,x); | |||
|
58 | domain.m_minY = qMin(domain.m_minY,y); | |||
|
59 | domain.m_maxX = qMax(domain.m_maxX,x); | |||
|
60 | domain.m_maxY = qMax(domain.m_maxY,y); | |||
|
61 | } | |||
|
62 | break; | |||
|
63 | case QChartSeries::SeriesTypeStackedBar: { | |||
48 |
|
64 | |||
|
65 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |||
|
66 | qreal x = stackedBarSeries->countColumns(); | |||
|
67 | qreal y = stackedBarSeries->maxColumnSum(); | |||
|
68 | domain.m_minX = qMin(domain.m_minX,x); | |||
|
69 | domain.m_minY = qMin(domain.m_minY,y); | |||
|
70 | domain.m_maxX = qMax(domain.m_maxX,x); | |||
|
71 | domain.m_maxY = qMax(domain.m_maxY,y); | |||
|
72 | } | |||
49 | break; |
|
73 | break; | |
|
74 | case QChartSeries::SeriesTypePercentBar: { | |||
|
75 | ||||
|
76 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |||
|
77 | qreal x = percentBarSeries->countColumns(); | |||
|
78 | domain.m_minX = qMin(domain.m_minX,x); | |||
|
79 | domain.m_minY = 0; | |||
|
80 | domain.m_maxX = qMax(domain.m_maxX,x); | |||
|
81 | domain.m_maxY = 100; | |||
50 | } |
|
82 | } | |
|
83 | break; | |||
|
84 | ||||
51 |
|
|
85 | default: { | |
52 |
|
|
86 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
53 | return; |
|
87 | return; | |
@@ -57,6 +91,48 void ChartDataSet::addSeries(QChartSeries* series) | |||||
57 | } |
|
91 | } | |
58 |
|
92 | |||
59 |
|
|
93 | emit seriesAdded(series); | |
|
94 | emit domainChanged(domain); | |||
|
95 | } | |||
|
96 | ||||
|
97 | bool ChartDataSet::nextDomain() | |||
|
98 | { | |||
|
99 | if (m_domainIndex < m_domains.count() - 1) { | |||
|
100 | m_domainIndex++; | |||
|
101 | emit domainChanged(m_domains[m_domainIndex]); | |||
|
102 | return true; | |||
|
103 | } | |||
|
104 | else { | |||
|
105 | return false; | |||
|
106 | } | |||
|
107 | } | |||
|
108 | ||||
|
109 | bool ChartDataSet::previousDomain() | |||
|
110 | { | |||
|
111 | if (m_domainIndex > 0) { | |||
|
112 | m_domainIndex--; | |||
|
113 | emit domainChanged(m_domains[m_domainIndex]); | |||
|
114 | return true; | |||
|
115 | } | |||
|
116 | else { | |||
|
117 | return false; | |||
|
118 | } | |||
|
119 | } | |||
|
120 | ||||
|
121 | void ChartDataSet::clearDomains() | |||
|
122 | { | |||
|
123 | if (m_domainIndex > 0) { | |||
|
124 | m_domainIndex = 0; | |||
|
125 | emit domainChanged(m_domains[m_domainIndex]); | |||
|
126 | } | |||
|
127 | } | |||
|
128 | ||||
|
129 | void ChartDataSet::addDomain(const Domain& domain) | |||
|
130 | { | |||
|
131 | m_domains.resize(m_domainIndex + 1); | |||
|
132 | m_domains << domain; | |||
|
133 | m_domainIndex++; | |||
|
134 | ||||
|
135 | emit domainChanged(domain); | |||
60 | } |
|
136 | } | |
61 |
|
137 | |||
62 | #include "moc_chartdataset_p.cpp" |
|
138 | #include "moc_chartdataset_p.cpp" |
@@ -15,11 +15,15 public: | |||||
15 | virtual ~ChartDataSet(); |
|
15 | virtual ~ChartDataSet(); | |
16 |
|
16 | |||
17 | void addSeries(QChartSeries* series); |
|
17 | void addSeries(QChartSeries* series); | |
|
18 | void addDomain(const Domain& domain); | |||
|
19 | bool nextDomain(); | |||
|
20 | bool previousDomain(); | |||
|
21 | void clearDomains(); | |||
18 | const Domain& domain() const; |
|
22 | const Domain& domain() const; | |
19 |
|
23 | |||
20 | signals: |
|
24 | signals: | |
21 | void seriesAdded(QChartSeries* series); |
|
25 | void seriesAdded(QChartSeries* series); | |
22 | void domainChanged(); |
|
26 | void domainChanged(const Domain& domain); | |
23 |
|
27 | |||
24 | private: |
|
28 | private: | |
25 | QList<QChartSeries*> m_chartSeries; |
|
29 | QList<QChartSeries*> m_chartSeries; |
@@ -1,9 +1,17 | |||||
|
1 | #include "qchart.h" | |||
1 | #include "chartpresenter_p.h" |
|
2 | #include "chartpresenter_p.h" | |
2 | #include "chartdataset_p.h" |
|
3 | #include "chartdataset_p.h" | |
|
4 | //series | |||
|
5 | #include "barchartseries.h" | |||
|
6 | #include "stackedbarchartseries.h" | |||
|
7 | #include "percentbarchartseries.h" | |||
3 | #include "qxychartseries.h" |
|
8 | #include "qxychartseries.h" | |
|
9 | //items | |||
|
10 | #include "bargroup.h" | |||
|
11 | #include "stackedbargroup.h" | |||
4 | #include "xylinechartitem_p.h" |
|
12 | #include "xylinechartitem_p.h" | |
|
13 | #include "percentbargroup.h" | |||
5 | #include "linechartanimationitem_p.h" |
|
14 | #include "linechartanimationitem_p.h" | |
6 | #include "qchart.h" |
|
|||
7 |
|
15 | |||
8 | #include <QAbstractAnimation> |
|
16 | #include <QAbstractAnimation> | |
9 | #include <QPropertyAnimation> |
|
17 | #include <QPropertyAnimation> | |
@@ -13,6 +21,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
13 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
21 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
14 | m_chart(chart), |
|
22 | m_chart(chart), | |
15 | m_dataset(dataset), |
|
23 | m_dataset(dataset), | |
|
24 | m_domainIndex(0), | |||
|
25 | m_marginSize(0), | |||
16 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
26 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
17 | { |
|
27 | { | |
18 | creteConnections(); |
|
28 | creteConnections(); | |
@@ -26,21 +36,23 void ChartPresenter::creteConnections() | |||||
26 | { |
|
36 | { | |
27 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
37 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
28 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
38 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
29 | QObject::connect(m_dataset,SIGNAL(domainChanged()),this,SLOT(handleDomainChanged())); |
|
|||
30 | } |
|
39 | } | |
31 |
|
40 | |||
32 | void ChartPresenter::handleGeometryChanged() |
|
41 | void ChartPresenter::handleGeometryChanged() | |
33 | { |
|
42 | { | |
34 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
43 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
|
44 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |||
|
45 | emit geometryChanged(m_rect); | |||
|
46 | } | |||
35 |
|
47 | |||
36 | int margin = m_chart->margin(); |
|
48 | int ChartPresenter::margin() const | |
37 | m_rect.adjust(margin,margin, -margin, -margin); |
|
49 | { | |
38 |
|
50 | return m_marginSize; | ||
39 | foreach (ChartItem *item, m_chartItems) { |
|
|||
40 | item->setPos(m_rect.topLeft()); |
|
|||
41 | item->setSize(m_rect.size()); |
|
|||
42 | item->updateItem(); |
|
|||
43 | } |
|
51 | } | |
|
52 | ||||
|
53 | void ChartPresenter::setMargin(int margin) | |||
|
54 | { | |||
|
55 | m_marginSize = margin; | |||
44 | } |
|
56 | } | |
45 |
|
57 | |||
46 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
58 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
@@ -48,16 +60,102 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||||
48 | switch(series->type()) |
|
60 | switch(series->type()) | |
49 | { |
|
61 | { | |
50 | case QChartSeries::SeriesTypeLine: { |
|
62 | case QChartSeries::SeriesTypeLine: { | |
|
63 | QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series); | |||
|
64 | XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |||
|
65 | item->setPen(lineSeries->pen()); | |||
|
66 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |||
|
67 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |||
|
68 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |||
|
69 | m_chartItems.insert(series,item); | |||
|
70 | break; | |||
|
71 | } | |||
|
72 | ||||
|
73 | case QChartSeries::SeriesTypeBar: { | |||
|
74 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |||
|
75 | BarGroup* item = new BarGroup(*barSeries,m_chart); | |||
51 |
|
76 | |||
52 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
77 | // Add some fugly colors for 5 fist series... | |
53 | //TODO: series->createViewItem(); |
|
78 | item->addColor(QColor(255,0,0,128)); | |
54 | //XYLineChartItem* item = new XYLineChartItem(this,m_chart); |
|
79 | item->addColor(QColor(255,255,0,128)); | |
55 | XYLineChartItem* item = new LineChartAnimationItem(this,xyseries,m_chart); |
|
80 | item->addColor(QColor(0,255,0,128)); | |
56 | item->setDomain(m_dataset->domain()); |
|
81 | item->addColor(QColor(0,0,255,128)); | |
57 | item->updateItem(); |
|
82 | item->addColor(QColor(255,128,0,128)); | |
|
83 | ||||
|
84 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |||
|
85 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |||
|
86 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |||
58 | m_chartItems.insert(series,item); |
|
87 | m_chartItems.insert(series,item); | |
|
88 | // m_axisXItem->setVisible(false); | |||
|
89 | break; | |||
|
90 | } | |||
|
91 | ||||
|
92 | case QChartSeries::SeriesTypeStackedBar: { | |||
|
93 | ||||
|
94 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |||
|
95 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); | |||
|
96 | ||||
|
97 | // Add some fugly colors for 5 fist series... | |||
|
98 | item->addColor(QColor(255,0,0,128)); | |||
|
99 | item->addColor(QColor(255,255,0,128)); | |||
|
100 | item->addColor(QColor(0,255,0,128)); | |||
|
101 | item->addColor(QColor(0,0,255,128)); | |||
|
102 | item->addColor(QColor(255,128,0,128)); | |||
|
103 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |||
|
104 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |||
|
105 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |||
|
106 | m_chartItems.insert(series,item); | |||
|
107 | break; | |||
|
108 | } | |||
|
109 | ||||
|
110 | case QChartSeries::SeriesTypePercentBar: { | |||
|
111 | ||||
|
112 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |||
|
113 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); | |||
|
114 | ||||
|
115 | // Add some fugly colors for 5 fist series... | |||
|
116 | item->addColor(QColor(255,0,0,128)); | |||
|
117 | item->addColor(QColor(255,255,0,128)); | |||
|
118 | item->addColor(QColor(0,255,0,128)); | |||
|
119 | item->addColor(QColor(0,0,255,128)); | |||
|
120 | item->addColor(QColor(255,128,0,128)); | |||
|
121 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |||
|
122 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |||
|
123 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |||
|
124 | m_chartItems.insert(series,item); | |||
|
125 | break; | |||
|
126 | } | |||
|
127 | /* | |||
|
128 | case QChartSeries::SeriesTypeScatter: { | |||
|
129 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |||
|
130 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |||
|
131 | scatterSeries->d->setParentItem(this); | |||
|
132 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |||
|
133 | m_chartItems << scatterSeries->d; | |||
|
134 | m_chartTheme->addObserver(scatterSeries->d); | |||
|
135 | ||||
|
136 | foreach (qreal x, scatterSeries->d->m_x) { | |||
|
137 | domain.m_minX = qMin(domain.m_minX, x); | |||
|
138 | domain.m_maxX = qMax(domain.m_maxX, x); | |||
|
139 | } | |||
|
140 | foreach (qreal y, scatterSeries->d->m_y) { | |||
|
141 | domain.m_minY = qMin(domain.m_minY, y); | |||
|
142 | domain.m_maxY = qMax(domain.m_maxY, y); | |||
|
143 | } | |||
|
144 | ||||
|
145 | break; | |||
|
146 | } | |||
|
147 | case QChartSeries::SeriesTypePie: { | |||
|
148 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |||
|
149 | pieSeries->d->setParentItem(this); | |||
|
150 | m_chartItems << pieSeries->d; | |||
|
151 | pieSeries->d->m_chartTheme = m_chartTheme; | |||
|
152 | m_chartTheme->addObserver(pieSeries->d); | |||
59 |
|
|
153 | break; | |
60 | } |
|
154 | } | |
|
155 | default: | |||
|
156 | break; | |||
|
157 | } | |||
|
158 | */ | |||
61 |
|
159 | |||
62 | default: { |
|
160 | default: { | |
63 |
|
|
161 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
@@ -68,18 +166,61 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||||
68 |
|
166 | |||
69 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
167 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
70 | { |
|
168 | { | |
71 | switch(series->type()) |
|
169 | //TODO: | |
|
170 | } | |||
|
171 | ||||
|
172 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |||
72 | { |
|
173 | { | |
73 | case QChartSeries::SeriesTypeLine: { |
|
174 | if(!rect.isValid()) return; | |
|
175 | QRectF r = rect.normalized(); | |||
|
176 | r.translate(-m_marginSize, -m_marginSize); | |||
|
177 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |||
|
178 | m_dataset->addDomain(domain); | |||
|
179 | } | |||
74 |
|
180 | |||
75 | break; |
|
181 | ||
|
182 | void ChartPresenter::zoomIn() | |||
|
183 | { | |||
|
184 | if (!m_dataset->nextDomain()) { | |||
|
185 | QRectF rect = m_rect; | |||
|
186 | rect.setWidth(rect.width()/2); | |||
|
187 | rect.setHeight(rect.height()/2); | |||
|
188 | rect.moveCenter(m_rect.center()); | |||
|
189 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |||
|
190 | m_dataset->addDomain(domain); | |||
|
191 | } | |||
76 | } |
|
192 | } | |
77 |
|
193 | |||
|
194 | void ChartPresenter::zoomOut() | |||
|
195 | { | |||
|
196 | m_dataset->previousDomain(); | |||
78 | } |
|
197 | } | |
79 |
|
198 | |||
80 | //m_chartItems.value(series)->updateItem(); |
|
199 | void ChartPresenter::zoomReset() | |
|
200 | { | |||
|
201 | m_dataset->clearDomains(); | |||
81 | } |
|
202 | } | |
82 |
|
203 | |||
|
204 | /* | |||
|
205 | void ChartPresenter::setAxisX(const QChartAxis& axis) | |||
|
206 | { | |||
|
207 | setAxis(m_axisXItem,axis); | |||
|
208 | } | |||
|
209 | void ChartPresenter::setAxisY(const QChartAxis& axis) | |||
|
210 | { | |||
|
211 | setAxis(m_axisYItem.at(0),axis); | |||
|
212 | } | |||
|
213 | ||||
|
214 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) | |||
|
215 | { | |||
|
216 | //TODO not implemented | |||
|
217 | } | |||
|
218 | ||||
|
219 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) | |||
|
220 | { | |||
|
221 | item->setVisible(axis.isAxisVisible()); | |||
|
222 | } | |||
|
223 | */ | |||
83 | #include "moc_chartpresenter_p.cpp" |
|
224 | #include "moc_chartpresenter_p.cpp" | |
84 |
|
225 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
226 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -20,6 +20,21 class ChartPresenter: public QObject | |||||
20 | public: |
|
20 | public: | |
21 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
21 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
22 | virtual ~ChartPresenter(); |
|
22 | virtual ~ChartPresenter(); | |
|
23 | /* | |||
|
24 | void setAxisX(const QChartAxis& axis); | |||
|
25 | void setAxisY(const QChartAxis& axis); | |||
|
26 | void setAxisY(const QList<QChartAxis>& axis); | |||
|
27 | ||||
|
28 | ||||
|
29 | */ | |||
|
30 | ||||
|
31 | void setMargin(int margin); | |||
|
32 | int margin() const; | |||
|
33 | ||||
|
34 | void zoomInToRect(const QRectF& rectangle); | |||
|
35 | void zoomIn(); | |||
|
36 | void zoomOut(); | |||
|
37 | void zoomReset(); | |||
23 |
|
38 | |||
24 | private: |
|
39 | private: | |
25 | void creteConnections(); |
|
40 | void creteConnections(); | |
@@ -31,12 +46,16 public slots: | |||||
31 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); |
|
46 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); | |
32 | void handleGeometryChanged(); |
|
47 | void handleGeometryChanged(); | |
33 |
|
48 | |||
34 |
|
49 | signals: | ||
|
50 | void geometryChanged(const QRectF& rect); | |||
35 |
|
51 | |||
36 | private: |
|
52 | private: | |
37 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
53 | QMap<QChartSeries*,ChartItem*> m_chartItems; | |
38 | QChart* m_chart; |
|
54 | QChart* m_chart; | |
39 | ChartDataSet* m_dataset; |
|
55 | ChartDataSet* m_dataset; | |
|
56 | QVector<Domain> m_domains; | |||
|
57 | int m_domainIndex; | |||
|
58 | int m_marginSize; | |||
40 | QRectF m_rect; |
|
59 | QRectF m_rect; | |
41 | }; |
|
60 | }; | |
42 |
|
61 |
@@ -28,7 +28,7 qreal Domain::spanY() const | |||||
28 | return m_maxY - m_minY; |
|
28 | return m_maxY - m_minY; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | Domain Domain::subDomain(const QRect& rect, qreal maxWidth,qreal maxHeight) const |
|
31 | Domain Domain::subDomain(const QRectF& rect, qreal maxWidth,qreal maxHeight) const | |
32 | { |
|
32 | { | |
33 | Domain domain; |
|
33 | Domain domain; | |
34 |
|
34 |
@@ -13,7 +13,7 public: | |||||
13 | qreal spanX() const; |
|
13 | qreal spanX() const; | |
14 | qreal spanY() const; |
|
14 | qreal spanY() const; | |
15 |
|
15 | |||
16 | Domain subDomain(const QRect& rect, qreal maxWidth, qreal maxHeight) const; |
|
16 | Domain subDomain(const QRectF& rect, qreal maxWidth, qreal maxHeight) const; | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | qreal m_minX; |
|
19 | qreal m_minX; |
@@ -4,22 +4,21 | |||||
4 | #include "qscatterseries_p.h" |
|
4 | #include "qscatterseries_p.h" | |
5 | #include "qpieseries.h" |
|
5 | #include "qpieseries.h" | |
6 | #include "qpieseries_p.h" |
|
6 | #include "qpieseries_p.h" | |
7 | #include "qxychartseries.h" |
|
|||
8 | #include "qchartaxis.h" |
|
7 | #include "qchartaxis.h" | |
9 | #include "barchartseries.h" |
|
|||
10 | #include "bargroup.h" |
|
|||
11 | #include "stackedbarchartseries.h" |
|
|||
12 | #include "stackedbargroup.h" |
|
|||
13 | #include "percentbarchartseries.h" |
|
|||
14 | #include "percentbargroup.h" |
|
|||
15 | #include "charttheme_p.h" |
|
8 | #include "charttheme_p.h" | |
16 | #include "chartitem_p.h" |
|
9 | #include "chartitem_p.h" | |
17 |
|
||||
18 | #include "xylinechartitem_p.h" |
|
|||
19 | #include "plotdomain_p.h" |
|
10 | #include "plotdomain_p.h" | |
20 | #include "axisitem_p.h" |
|
11 | #include "axisitem_p.h" | |
21 | #include "chartpresenter_p.h" |
|
12 | #include "chartpresenter_p.h" | |
22 | #include "chartdataset_p.h" |
|
13 | #include "chartdataset_p.h" | |
|
14 | ||||
|
15 | //series | |||
|
16 | #include "barchartseries.h" | |||
|
17 | #include "stackedbarchartseries.h" | |||
|
18 | #include "percentbarchartseries.h" | |||
|
19 | #include "qxychartseries.h" | |||
|
20 | ||||
|
21 | ||||
23 | #include <QGraphicsScene> |
|
22 | #include <QGraphicsScene> | |
24 | #include <QGraphicsSceneResizeEvent> |
|
23 | #include <QGraphicsSceneResizeEvent> | |
25 | #include <QDebug> |
|
24 | #include <QDebug> | |
@@ -31,18 +30,18 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget( | |||||
31 | m_titleItem(0), |
|
30 | m_titleItem(0), | |
32 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), |
|
31 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), | |
33 | m_plotDataIndex(0), |
|
32 | m_plotDataIndex(0), | |
34 | m_marginSize(0), |
|
|||
35 | m_chartTheme(new ChartTheme(this)), |
|
33 | m_chartTheme(new ChartTheme(this)), | |
36 | m_dataset(0), |
|
34 | //m_dataset(0), | |
37 |
|
|
35 | m_dataset(new ChartDataSet(this)), | |
38 | m_presenter(0) |
|
36 | //m_presenter(0) | |
39 |
|
|
37 | m_presenter(new ChartPresenter(this,m_dataset)) | |
40 | { |
|
38 | { | |
41 | // TODO: the default theme? |
|
39 | // TODO: the default theme? | |
42 | setTheme(QChart::ChartThemeDefault); |
|
40 | setTheme(QChart::ChartThemeDefault); | |
43 |
|
41 | |||
44 | PlotDomain domain; |
|
42 | PlotDomain domain; | |
45 | m_plotDomainList << domain; |
|
43 | m_plotDomainList << domain; | |
|
44 | ||||
46 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); |
|
45 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); | |
47 | m_chartItems << m_axisXItem; |
|
46 | m_chartItems << m_axisXItem; | |
48 | m_chartItems << m_axisYItem.at(0); |
|
47 | m_chartItems << m_axisYItem.at(0); | |
@@ -52,154 +51,7 QChart::~QChart(){} | |||||
52 |
|
51 | |||
53 | void QChart::addSeries(QChartSeries* series) |
|
52 | void QChart::addSeries(QChartSeries* series) | |
54 | { |
|
53 | { | |
55 | if(m_dataset) { |
|
|||
56 |
|
|
54 | m_dataset->addSeries(series); | |
57 | return; |
|
|||
58 | } |
|
|||
59 |
|
||||
60 | Q_ASSERT(series); |
|
|||
61 | Q_ASSERT(series->type() != QChartSeries::SeriesTypeInvalid); |
|
|||
62 |
|
||||
63 | // TODO: we should check the series not already added |
|
|||
64 |
|
||||
65 |
|
||||
66 | m_chartSeries << series; |
|
|||
67 |
|
||||
68 | m_plotDataIndex = 0 ; |
|
|||
69 | m_plotDomainList.resize(1); |
|
|||
70 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
|||
71 |
|
||||
72 | switch(series->type()) |
|
|||
73 | { |
|
|||
74 | case QChartSeries::SeriesTypeLine: { |
|
|||
75 |
|
||||
76 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
|||
77 |
|
||||
78 | for (int i = 0 ; i < xyseries->count() ; i++) { |
|
|||
79 | qreal x = xyseries->x(i); |
|
|||
80 | qreal y = xyseries->y(i); |
|
|||
81 | domain.m_minX = qMin(domain.m_minX,x); |
|
|||
82 | domain.m_minY = qMin(domain.m_minY,y); |
|
|||
83 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
|||
84 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
|||
85 | } |
|
|||
86 |
|
||||
87 | //XYLineChartItem* item = new XYLineChartItem(xyseries,0,this); |
|
|||
88 |
|
||||
89 | //m_chartItems << item; |
|
|||
90 | // TODO: |
|
|||
91 | //m_chartTheme->addObserver(xyseries); |
|
|||
92 |
|
||||
93 | break; |
|
|||
94 | } |
|
|||
95 | case QChartSeries::SeriesTypeBar: { |
|
|||
96 |
|
||||
97 | qDebug() << "barSeries added"; |
|
|||
98 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
|||
99 | BarGroup* barGroup = new BarGroup(*barSeries,this); |
|
|||
100 |
|
||||
101 | // Add some fugly colors for 5 fist series... |
|
|||
102 | barGroup->addColor(QColor(255,0,0,128)); |
|
|||
103 | barGroup->addColor(QColor(255,255,0,128)); |
|
|||
104 | barGroup->addColor(QColor(0,255,0,128)); |
|
|||
105 | barGroup->addColor(QColor(0,0,255,128)); |
|
|||
106 | barGroup->addColor(QColor(255,128,0,128)); |
|
|||
107 |
|
||||
108 | m_chartItems << barGroup; |
|
|||
109 | childItems().append(barGroup); |
|
|||
110 |
|
||||
111 | qreal x = barSeries->countColumns(); |
|
|||
112 | qreal y = barSeries->max(); |
|
|||
113 | domain.m_minX = qMin(domain.m_minX,x); |
|
|||
114 | domain.m_minY = qMin(domain.m_minY,y); |
|
|||
115 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
|||
116 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
|||
117 | m_axisXItem->setVisible(false); |
|
|||
118 | break; |
|
|||
119 | } |
|
|||
120 | case QChartSeries::SeriesTypeStackedBar: { |
|
|||
121 |
|
||||
122 | qDebug() << "barSeries added"; |
|
|||
123 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
|||
124 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); |
|
|||
125 |
|
||||
126 | // Add some fugly colors for 5 fist series... |
|
|||
127 | stackedBarGroup->addColor(QColor(255,0,0,128)); |
|
|||
128 | stackedBarGroup->addColor(QColor(255,255,0,128)); |
|
|||
129 | stackedBarGroup->addColor(QColor(0,255,0,128)); |
|
|||
130 | stackedBarGroup->addColor(QColor(0,0,255,128)); |
|
|||
131 | stackedBarGroup->addColor(QColor(255,128,0,128)); |
|
|||
132 |
|
||||
133 | m_chartItems << stackedBarGroup; |
|
|||
134 | childItems().append(stackedBarGroup); |
|
|||
135 |
|
||||
136 | qreal x = stackedBarSeries->countColumns(); |
|
|||
137 | qreal y = stackedBarSeries->maxColumnSum(); |
|
|||
138 | domain.m_minX = qMin(domain.m_minX,x); |
|
|||
139 | domain.m_minY = qMin(domain.m_minY,y); |
|
|||
140 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
|||
141 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
|||
142 | m_axisXItem->setVisible(false); |
|
|||
143 | break; |
|
|||
144 | } |
|
|||
145 | case QChartSeries::SeriesTypePercentBar: { |
|
|||
146 |
|
||||
147 | qDebug() << "barSeries added"; |
|
|||
148 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
|||
149 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); |
|
|||
150 |
|
||||
151 | // Add some fugly colors for 5 fist series... |
|
|||
152 | percentBarGroup->addColor(QColor(255,0,0,128)); |
|
|||
153 | percentBarGroup->addColor(QColor(255,255,0,128)); |
|
|||
154 | percentBarGroup->addColor(QColor(0,255,0,128)); |
|
|||
155 | percentBarGroup->addColor(QColor(0,0,255,128)); |
|
|||
156 | percentBarGroup->addColor(QColor(255,128,0,128)); |
|
|||
157 |
|
||||
158 | m_chartItems << percentBarGroup; |
|
|||
159 | childItems().append(percentBarGroup); |
|
|||
160 |
|
||||
161 | qreal x = percentBarSeries->countColumns(); |
|
|||
162 | domain.m_minX = qMin(domain.m_minX,x); |
|
|||
163 | domain.m_minY = 0; |
|
|||
164 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
|||
165 | domain.m_maxY = 100; |
|
|||
166 | m_axisXItem->setVisible(false); |
|
|||
167 | break; |
|
|||
168 | } |
|
|||
169 | case QChartSeries::SeriesTypeScatter: { |
|
|||
170 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
|||
171 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
|||
172 | scatterSeries->d->setParentItem(this); |
|
|||
173 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
|||
174 | m_chartItems << scatterSeries->d; |
|
|||
175 | m_chartTheme->addObserver(scatterSeries->d); |
|
|||
176 |
|
||||
177 | foreach (qreal x, scatterSeries->d->m_x) { |
|
|||
178 | domain.m_minX = qMin(domain.m_minX, x); |
|
|||
179 | domain.m_maxX = qMax(domain.m_maxX, x); |
|
|||
180 | } |
|
|||
181 | foreach (qreal y, scatterSeries->d->m_y) { |
|
|||
182 | domain.m_minY = qMin(domain.m_minY, y); |
|
|||
183 | domain.m_maxY = qMax(domain.m_maxY, y); |
|
|||
184 | } |
|
|||
185 |
|
||||
186 | break; |
|
|||
187 | } |
|
|||
188 | case QChartSeries::SeriesTypePie: { |
|
|||
189 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
|||
190 | pieSeries->d->setParentItem(this); |
|
|||
191 | m_chartItems << pieSeries->d; |
|
|||
192 | pieSeries->d->m_chartTheme = m_chartTheme; |
|
|||
193 | m_chartTheme->addObserver(pieSeries->d); |
|
|||
194 | break; |
|
|||
195 | } |
|
|||
196 | default: |
|
|||
197 | break; |
|
|||
198 | } |
|
|||
199 |
|
||||
200 | // Update all the items to match the new visible area of the chart |
|
|||
201 | foreach(ChartItem* i, m_chartItems) |
|
|||
202 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
|||
203 | } |
|
55 | } | |
204 |
|
56 | |||
205 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
57 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
@@ -275,12 +127,12 void QChart::setTitle(const QString& title,const QFont& font) | |||||
275 |
|
127 | |||
276 | int QChart::margin() const |
|
128 | int QChart::margin() const | |
277 | { |
|
129 | { | |
278 |
|
|
130 | m_presenter->margin(); | |
279 | } |
|
131 | } | |
280 |
|
132 | |||
281 | void QChart::setMargin(int margin) |
|
133 | void QChart::setMargin(int margin) | |
282 | { |
|
134 | { | |
283 | m_marginSize = margin; |
|
135 | m_presenter->setMargin(margin); | |
284 | } |
|
136 | } | |
285 |
|
137 | |||
286 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
138 | void QChart::setTheme(QChart::ChartThemeId theme) | |
@@ -315,61 +167,22 QChart::ChartThemeId QChart::theme() | |||||
315 |
|
167 | |||
316 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
168 | void QChart::zoomInToRect(const QRectF& rectangle) | |
317 | { |
|
169 | { | |
318 |
|
170 | m_presenter->zoomInToRect(rectangle); | ||
319 | if(!rectangle.isValid()) return; |
|
|||
320 |
|
||||
321 | qreal margin = this->margin(); |
|
|||
322 |
|
||||
323 | QRectF rect = rectangle.normalized(); |
|
|||
324 | rect.translate(-margin, -margin); |
|
|||
325 |
|
||||
326 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; |
|
|||
327 |
|
||||
328 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); |
|
|||
329 |
|
||||
330 | m_plotDomainList.resize(m_plotDataIndex + 1); |
|
|||
331 | m_plotDomainList<<domain; |
|
|||
332 | m_plotDataIndex++; |
|
|||
333 |
|
||||
334 | foreach (ChartItem* item, m_chartItems) |
|
|||
335 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
|||
336 | update(); |
|
|||
337 | } |
|
171 | } | |
338 |
|
172 | |||
339 | void QChart::zoomIn() |
|
173 | void QChart::zoomIn() | |
340 | { |
|
174 | { | |
341 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { |
|
175 | m_presenter->zoomIn(); | |
342 | m_plotDataIndex++; |
|
|||
343 | foreach (ChartItem* item, m_chartItems) |
|
|||
344 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
|||
345 | update(); |
|
|||
346 | } else { |
|
|||
347 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
|||
348 | rect.setWidth(rect.width()/2); |
|
|||
349 | rect.setHeight(rect.height()/2); |
|
|||
350 | rect.moveCenter(m_rect.center()); |
|
|||
351 | zoomInToRect(rect); |
|
|||
352 | } |
|
|||
353 | } |
|
176 | } | |
354 |
|
177 | |||
355 | void QChart::zoomOut() |
|
178 | void QChart::zoomOut() | |
356 | { |
|
179 | { | |
357 | if (m_plotDataIndex > 0) { |
|
180 | m_presenter->zoomOut(); | |
358 | m_plotDataIndex--; |
|
|||
359 | foreach (ChartItem* item, m_chartItems) |
|
|||
360 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
|||
361 | update(); |
|
|||
362 | } |
|
|||
363 | } |
|
181 | } | |
364 |
|
182 | |||
365 | void QChart::zoomReset() |
|
183 | void QChart::zoomReset() | |
366 | { |
|
184 | { | |
367 | if (m_plotDataIndex > 0) { |
|
185 | m_presenter->zoomReset(); | |
368 | m_plotDataIndex = 0; |
|
|||
369 | foreach (ChartItem* item, m_chartItems) |
|
|||
370 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
|||
371 | update(); |
|
|||
372 | } |
|
|||
373 | } |
|
186 | } | |
374 |
|
187 | |||
375 | void QChart::setAxisX(const QChartAxis& axis) |
|
188 | void QChart::setAxisX(const QChartAxis& axis) | |
@@ -408,12 +221,6 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |||||
408 | m_backgroundItem->setRect(rect); |
|
221 | m_backgroundItem->setRect(rect); | |
409 | } |
|
222 | } | |
410 |
|
223 | |||
411 | // resize and reposition childs |
|
|||
412 | foreach (ChartItem *item, m_chartItems) { |
|
|||
413 | item->setPos(rect.topLeft()); |
|
|||
414 | item->setSize(rect.size()); |
|
|||
415 | } |
|
|||
416 |
|
||||
417 | QGraphicsWidget::resizeEvent(event); |
|
224 | QGraphicsWidget::resizeEvent(event); | |
418 | update(); |
|
225 | update(); | |
419 | } |
|
226 | } |
@@ -33,10 +33,6 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |||||
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | enum GradientOrientation { |
|
|||
37 | HorizonatlGradientOrientation, |
|
|||
38 | VerticalGradientOrientation |
|
|||
39 | }; |
|
|||
40 | enum ChartThemeId { |
|
36 | enum ChartThemeId { | |
41 | ChartThemeInvalid = -1, |
|
37 | ChartThemeInvalid = -1, | |
42 | /*! The default theme follows the GUI style of the Operating System */ |
|
38 | /*! The default theme follows the GUI style of the Operating System */ | |
@@ -85,7 +81,6 private: | |||||
85 | private: |
|
81 | private: | |
86 | Q_DISABLE_COPY(QChart) |
|
82 | Q_DISABLE_COPY(QChart) | |
87 | QGraphicsRectItem* m_backgroundItem; |
|
83 | QGraphicsRectItem* m_backgroundItem; | |
88 | GradientOrientation m_bacgroundOrinetation; |
|
|||
89 | QGraphicsTextItem* m_titleItem; |
|
84 | QGraphicsTextItem* m_titleItem; | |
90 | AxisItem* m_axisXItem; |
|
85 | AxisItem* m_axisXItem; | |
91 | QList<AxisItem*> m_axisYItem; |
|
86 | QList<AxisItem*> m_axisYItem; | |
@@ -94,7 +89,6 private: | |||||
94 | QList<ChartItem *> m_chartItems; |
|
89 | QList<ChartItem *> m_chartItems; | |
95 | QVector<PlotDomain> m_plotDomainList; |
|
90 | QVector<PlotDomain> m_plotDomainList; | |
96 | int m_plotDataIndex; |
|
91 | int m_plotDataIndex; | |
97 | int m_marginSize; |
|
|||
98 | ChartTheme *m_chartTheme; |
|
92 | ChartTheme *m_chartTheme; | |
99 |
|
93 | |||
100 |
|
94 |
@@ -13,7 +13,6 m_dirtyData(false), | |||||
13 | m_dirtyGeometry(false), |
|
13 | m_dirtyGeometry(false), | |
14 | m_dirtyDomain(false) |
|
14 | m_dirtyDomain(false) | |
15 | { |
|
15 | { | |
16 | QObject::connect(series,SIGNAL(changed(int)),this,SLOT(handleSeriesChanged(int))); |
|
|||
17 | } |
|
16 | } | |
18 |
|
17 | |||
19 | QRectF XYLineChartItem::boundingRect() const |
|
18 | QRectF XYLineChartItem::boundingRect() const | |
@@ -26,23 +25,6 QPainterPath XYLineChartItem::shape() const | |||||
26 | return m_path; |
|
25 | return m_path; | |
27 | } |
|
26 | } | |
28 |
|
27 | |||
29 | void XYLineChartItem::setSize(const QSizeF& size) |
|
|||
30 | { |
|
|||
31 | m_size=size; |
|
|||
32 | m_dirtyGeometry=true; |
|
|||
33 | } |
|
|||
34 |
|
||||
35 | void XYLineChartItem::setDomain(const Domain& domain) |
|
|||
36 | { |
|
|||
37 | m_domain=domain; |
|
|||
38 | m_dirtyDomain=true; |
|
|||
39 | } |
|
|||
40 |
|
||||
41 | void XYLineChartItem::setSeries(QXYChartSeries* series) |
|
|||
42 | { |
|
|||
43 | m_series = series; |
|
|||
44 | m_dirtyData=true; |
|
|||
45 | } |
|
|||
46 |
|
28 | |||
47 | void XYLineChartItem::addPoints(const QVector<QPointF>& points) |
|
29 | void XYLineChartItem::addPoints(const QVector<QPointF>& points) | |
48 | { |
|
30 | { | |
@@ -112,21 +94,11 void XYLineChartItem::clearView() | |||||
112 | m_data.clear(); |
|
94 | m_data.clear(); | |
113 | } |
|
95 | } | |
114 |
|
96 | |||
115 | void XYLineChartItem::handleSeriesChanged(int index) |
|
|||
116 | { |
|
|||
117 | Q_ASSERT(index<m_series->count()); |
|
|||
118 | if(m_hash.contains(index)){ |
|
|||
119 | int i = m_hash.value(index); |
|
|||
120 | QPointF point; |
|
|||
121 | calculatePoint(point,index,m_series,m_size,m_domain); |
|
|||
122 | setPoint(i,point); |
|
|||
123 | } |
|
|||
124 | } |
|
|||
125 |
|
||||
126 | void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
97 | void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
127 | { |
|
98 | { | |
128 | Q_UNUSED(widget); |
|
99 | Q_UNUSED(widget); | |
129 | Q_UNUSED(option); |
|
100 | Q_UNUSED(option); | |
|
101 | painter->setPen(m_pen); | |||
130 | painter->drawPath(m_path); |
|
102 | painter->drawPath(m_path); | |
131 | } |
|
103 | } | |
132 |
|
104 | |||
@@ -161,7 +133,6 void XYLineChartItem::updateDomain() | |||||
161 | clear(); |
|
133 | clear(); | |
162 | calculatePoints(m_data,m_hash,m_series,m_size, m_domain); |
|
134 | calculatePoints(m_data,m_hash,m_series,m_size, m_domain); | |
163 | addPoints(m_data); |
|
135 | addPoints(m_data); | |
164 | m_dirtyGeometry = true; |
|
|||
165 | } |
|
136 | } | |
166 |
|
137 | |||
167 | void XYLineChartItem::updateData() |
|
138 | void XYLineChartItem::updateData() | |
@@ -188,26 +159,44 void XYLineChartItem::updateGeometry() | |||||
188 | m_rect = path.boundingRect(); |
|
159 | m_rect = path.boundingRect(); | |
189 | } |
|
160 | } | |
190 |
|
161 | |||
191 |
void XYLineChartItem:: |
|
162 | void XYLineChartItem::setPen(const QPen& pen) | |
192 | { |
|
163 | { | |
193 | if(m_dirtyDomain) { |
|
164 | m_pen = pen; | |
194 | updateDomain(); |
|
|||
195 | m_dirtyData = false; |
|
|||
196 | } |
|
165 | } | |
197 |
|
166 | |||
198 | if(m_dirtyData) { |
|
167 | //handlers | |
199 | updateData(); |
|
168 | ||
200 | m_dirtyData = false; |
|
169 | void XYLineChartItem::handleModelChanged(int index) | |
|
170 | { | |||
|
171 | Q_ASSERT(index<m_series->count()); | |||
|
172 | if(m_hash.contains(index)){ | |||
|
173 | int i = m_hash.value(index); | |||
|
174 | QPointF point; | |||
|
175 | calculatePoint(point,index,m_series,m_size,m_domain); | |||
|
176 | setPoint(i,point); | |||
|
177 | } | |||
|
178 | update(); | |||
201 | } |
|
179 | } | |
202 |
|
180 | |||
203 | if(m_dirtyGeometry) { |
|
181 | void XYLineChartItem::handleDomainChanged(const Domain& domain) | |
204 | updateGeometry(); |
|
182 | { | |
205 | m_dirtyGeometry = false; |
|
183 | m_domain = domain; | |
|
184 | updateDomain(); | |||
|
185 | update(); | |||
206 | } |
|
186 | } | |
207 |
|
187 | |||
|
188 | void XYLineChartItem::handleGeometryChanged(const QRectF& rect) | |||
|
189 | { | |||
|
190 | Q_ASSERT(rect.isValid()); | |||
|
191 | ||||
|
192 | m_size=rect.size(); | |||
|
193 | updateDomain(); | |||
|
194 | updateGeometry(); | |||
|
195 | setPos(rect.topLeft()); | |||
208 | update(); |
|
196 | update(); | |
209 | } |
|
197 | } | |
210 |
|
198 | |||
|
199 | ||||
211 | #include "moc_xylinechartitem_p.cpp" |
|
200 | #include "moc_xylinechartitem_p.cpp" | |
212 |
|
201 | |||
213 | QTCOMMERCIALCHART_END_NAMESPACE |
|
202 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -3,6 +3,7 | |||||
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
|
6 | #include <QPen> | |||
6 |
|
7 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
9 | |||
@@ -21,15 +22,16 public: | |||||
21 | QRectF boundingRect() const; |
|
22 | QRectF boundingRect() const; | |
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
23 | QPainterPath shape() const; |
|
24 | QPainterPath shape() const; | |
|
25 | ||||
|
26 | ||||
|
27 | void setPen(const QPen& pen); | |||
|
28 | ||||
24 | //from ChartItem |
|
29 | //from ChartItem | |
25 | void setSize(const QSizeF& size); |
|
30 | void setSize(const QSizeF& size){}; | |
26 | void setPlotDomain(const PlotDomain& data){}; |
|
31 | void setPlotDomain(const PlotDomain& data){}; | |
27 | void setDomain(const Domain& data); |
|
|||
28 | void setSeries(QXYChartSeries* series); |
|
|||
29 | const Domain& domain() const { return m_domain;} |
|
|||
30 | //ChartAnimationManager* animationManager(); |
|
|||
31 |
|
32 | |||
32 | void updateItem(); |
|
33 | ||
|
34 | const Domain& domain() const { return m_domain;} | |||
33 |
|
35 | |||
34 | virtual void addPoint(const QPointF& ); |
|
36 | virtual void addPoint(const QPointF& ); | |
35 | virtual void addPoints(const QVector<QPointF>& points); |
|
37 | virtual void addPoints(const QVector<QPointF>& points); | |
@@ -50,8 +52,10 protected: | |||||
50 | void calculatePoint(QPointF& point, int index, const QXYChartSeries* series,const QSizeF& size, const Domain& domain) const; |
|
52 | void calculatePoint(QPointF& point, int index, const QXYChartSeries* series,const QSizeF& size, const Domain& domain) const; | |
51 | void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QXYChartSeries* series, const QSizeF& size, const Domain& domain) const; |
|
53 | void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QXYChartSeries* series, const QSizeF& size, const Domain& domain) const; | |
52 |
|
54 | |||
53 |
pr |
|
55 | protected slots: | |
54 |
void handle |
|
56 | void handleModelChanged(int index); | |
|
57 | void handleDomainChanged(const Domain& domain); | |||
|
58 | void handleGeometryChanged(const QRectF& size); | |||
55 |
|
59 | |||
56 | private: |
|
60 | private: | |
57 | ChartPresenter* m_presenter; |
|
61 | ChartPresenter* m_presenter; | |
@@ -63,6 +67,7 private: | |||||
63 | QVector<QPointF> m_data; |
|
67 | QVector<QPointF> m_data; | |
64 | QHash<int,int> m_hash; |
|
68 | QHash<int,int> m_hash; | |
65 | QXYChartSeries* m_series; |
|
69 | QXYChartSeries* m_series; | |
|
70 | QPen m_pen; | |||
66 | bool m_dirtyData; |
|
71 | bool m_dirtyData; | |
67 | bool m_dirtyGeometry; |
|
72 | bool m_dirtyGeometry; | |
68 | bool m_dirtyDomain; |
|
73 | bool m_dirtyDomain; |
General Comments 0
You need to be logged in to leave comments.
Login now