@@ -26,36 +26,32 m_dataset(dataset), | |||
|
26 | 26 | m_chartTheme(0), |
|
27 | 27 | m_domainIndex(0), |
|
28 | 28 | m_marginSize(0), |
|
29 | m_axisX(new QChartAxis(this)), | |
|
30 | m_axisY(new QChartAxis(this)), | |
|
29 | 31 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
30 | 32 | { |
|
31 | 33 | setChartTheme(QChart::ChartThemeDefault); |
|
34 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); | |
|
35 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); | |
|
32 | 36 | createConnections(); |
|
33 | createDeafultAxis(); | |
|
34 | 37 | } |
|
35 | 38 | |
|
36 | 39 | ChartPresenter::~ChartPresenter() |
|
37 | 40 | { |
|
38 | 41 | } |
|
39 | 42 | |
|
40 | void ChartPresenter::createDeafultAxis() | |
|
41 | { | |
|
42 | //default axis | |
|
43 | QChartAxis* axisX = new QChartAxis(this); | |
|
44 | QChartAxis* axisY = new QChartAxis(this); | |
|
45 | ||
|
46 | m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart); | |
|
47 | m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart); | |
|
48 | ||
|
49 | foreach(AxisItem* item, m_axis) { | |
|
50 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
|
51 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
|
52 | } | |
|
53 | } | |
|
54 | ||
|
55 | 43 | void ChartPresenter::createConnections() |
|
56 | 44 | { |
|
57 | 45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
58 | 46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
47 | ||
|
48 | QMapIterator<QChartAxis*,AxisItem*> i(m_axisItems); | |
|
49 | ||
|
50 | while (i.hasNext()) { | |
|
51 | i.next(); | |
|
52 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),i.value(),SLOT(handleGeometryChanged(const QRectF&))); | |
|
53 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),i.value(),SLOT(handleDomainChanged(const Domain&))); | |
|
54 | } | |
|
59 | 55 | } |
|
60 | 56 | |
|
61 | 57 | void ChartPresenter::handleGeometryChanged() |
@@ -226,14 +222,49 QChart::ChartTheme ChartPresenter::chartTheme() | |||
|
226 | 222 | return m_chartTheme->id(); |
|
227 | 223 | } |
|
228 | 224 | |
|
229 | void ChartPresenter::setAxisX(QChartAxis* axis) | |
|
225 | QChartAxis* ChartPresenter::axisX() | |
|
230 | 226 | { |
|
227 | return m_axisX; | |
|
228 | } | |
|
231 | 229 | |
|
230 | QChartAxis* ChartPresenter::axisY() | |
|
231 | { | |
|
232 | return m_axisY; | |
|
232 | 233 | } |
|
233 | 234 | |
|
234 |
|
|
|
235 | QChartAxis* ChartPresenter::addAxisX() | |
|
235 | 236 | { |
|
237 | //only one axis | |
|
238 | if(m_axisX==0){ | |
|
239 | m_axisX = new QChartAxis(this); | |
|
240 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); | |
|
241 | } | |
|
242 | return m_axisX; | |
|
243 | } | |
|
236 | 244 | |
|
245 | QChartAxis* ChartPresenter::addAxisY() | |
|
246 | { | |
|
247 | if(m_axisY==0){ | |
|
248 | m_axisY = new QChartAxis(this); | |
|
249 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); | |
|
250 | return m_axisY; | |
|
251 | } | |
|
252 | ||
|
253 | QChartAxis* axis = new QChartAxis(this); | |
|
254 | m_axisItems[axis] = new AxisItem(axis,AxisItem::Y_AXIS,m_chart); | |
|
255 | return axis; | |
|
256 | } | |
|
257 | ||
|
258 | void ChartPresenter::removeAxis(QChartAxis* axis) | |
|
259 | { | |
|
260 | AxisItem* item = m_axisItems.take(axis); | |
|
261 | if(item){ | |
|
262 | delete item; | |
|
263 | delete axis; | |
|
264 | } | |
|
265 | //reset pointers to default ones | |
|
266 | if(axis == m_axisX) m_axisX=0; | |
|
267 | else if(axis == m_axisY) m_axisY=0; | |
|
237 | 268 | } |
|
238 | 269 | |
|
239 | 270 | /* |
@@ -33,11 +33,14 public: | |||
|
33 | 33 | void setChartTheme(QChart::ChartTheme theme); |
|
34 | 34 | QChart::ChartTheme chartTheme(); |
|
35 | 35 | |
|
36 |
|
|
|
37 |
|
|
|
36 | QChartAxis* axisX(); | |
|
37 | QChartAxis* axisY(); | |
|
38 | QChartAxis* addAxisX(); | |
|
39 | QChartAxis* addAxisY(); | |
|
40 | void removeAxis(QChartAxis* axis); | |
|
41 | ||
|
38 | 42 | private: |
|
39 | 43 | void createConnections(); |
|
40 | void createDeafultAxis(); | |
|
41 | 44 | |
|
42 | 45 | public slots: |
|
43 | 46 | void handleSeriesAdded(QChartSeries* series); |
@@ -51,11 +54,13 signals: | |||
|
51 | 54 | |
|
52 | 55 | private: |
|
53 | 56 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
57 | QMap<QChartAxis*,AxisItem*> m_axisItems; | |
|
54 | 58 | QChart* m_chart; |
|
55 | 59 | ChartDataSet* m_dataset; |
|
56 | 60 | QVector<Domain> m_domains; |
|
57 | QList<AxisItem*> m_axis; | |
|
58 | 61 | ChartTheme *m_chartTheme; |
|
62 | QChartAxis* m_axisX; | |
|
63 | QChartAxis* m_axisY; | |
|
59 | 64 | int m_domainIndex; |
|
60 | 65 | int m_marginSize; |
|
61 | 66 | QRectF m_rect; |
@@ -145,13 +145,29 void QChart::zoomReset() | |||
|
145 | 145 | m_presenter->zoomReset(); |
|
146 | 146 | } |
|
147 | 147 | |
|
148 | void QChart::setAxisX(QChartAxis* axis) | |
|
148 | QChartAxis* QChart::axisX() | |
|
149 | 149 | { |
|
150 |
m_presenter-> |
|
|
150 | return m_presenter->axisX(); | |
|
151 | 151 | } |
|
152 | void QChart::addAxisY(QChartAxis* axis) | |
|
152 | ||
|
153 | QChartAxis* QChart::axisY() | |
|
154 | { | |
|
155 | return m_presenter->axisY(); | |
|
156 | } | |
|
157 | ||
|
158 | QChartAxis* QChart::addAxisX() | |
|
159 | { | |
|
160 | return m_presenter->addAxisX(); | |
|
161 | } | |
|
162 | ||
|
163 | QChartAxis* QChart::addAxisY() | |
|
164 | { | |
|
165 | return m_presenter->addAxisY(); | |
|
166 | } | |
|
167 | ||
|
168 | void QChart::removeAxis(QChartAxis* axis) | |
|
153 | 169 | { |
|
154 |
m_presenter-> |
|
|
170 | m_presenter->removeAxis(axis); | |
|
155 | 171 | } |
|
156 | 172 | |
|
157 | 173 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
@@ -67,16 +67,16 public: | |||
|
67 | 67 | void zoomOut(); |
|
68 | 68 | void zoomReset(); |
|
69 | 69 | |
|
70 |
|
|
|
71 |
|
|
|
70 | QChartAxis* axisX(); | |
|
71 | QChartAxis* axisY(); | |
|
72 | QChartAxis* addAxisX(); | |
|
73 | QChartAxis* addAxisY(); | |
|
74 | void removeAxis(QChartAxis* axis); | |
|
72 | 75 | |
|
73 | 76 | protected: |
|
74 | 77 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
75 | 78 | |
|
76 | 79 | private: |
|
77 | void setAxis(AxisItem *item, const QChartAxis& axis); | |
|
78 | ||
|
79 | private: | |
|
80 | 80 | Q_DISABLE_COPY(QChart) |
|
81 | 81 | QGraphicsRectItem* m_backgroundItem; |
|
82 | 82 | QGraphicsTextItem* m_titleItem; |
@@ -54,6 +54,7 public: | |||
|
54 | 54 | const QBrush& gridBrush(); |
|
55 | 55 | */ |
|
56 | 56 | |
|
57 | ||
|
57 | 58 | signals: |
|
58 | 59 | void axisVisibilityChanged(); |
|
59 | 60 | void axisPenChanged(); |
@@ -199,4 +199,29 QChart::ChartTheme QChartView::chartTheme() const | |||
|
199 | 199 | return m_chart->chartTheme(); |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | QChartAxis* QChartView::axisX() | |
|
203 | { | |
|
204 | return m_chart->axisX(); | |
|
205 | } | |
|
206 | ||
|
207 | QChartAxis* QChartView::axisY() | |
|
208 | { | |
|
209 | return m_chart->axisY(); | |
|
210 | } | |
|
211 | ||
|
212 | QChartAxis* QChartView::addAxisX() | |
|
213 | { | |
|
214 | return m_chart->addAxisX(); | |
|
215 | } | |
|
216 | ||
|
217 | QChartAxis* QChartView::addAxisY() | |
|
218 | { | |
|
219 | return m_chart->addAxisY(); | |
|
220 | } | |
|
221 | ||
|
222 | void QChartView::removeAxis(QChartAxis* axis) | |
|
223 | { | |
|
224 | m_chart->removeAxis(axis); | |
|
225 | } | |
|
226 | ||
|
202 | 227 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -45,6 +45,12 public: | |||
|
45 | 45 | void setChartTheme(QChart::ChartTheme theme); |
|
46 | 46 | QChart::ChartTheme chartTheme() const; |
|
47 | 47 | |
|
48 | QChartAxis* axisX(); | |
|
49 | QChartAxis* axisY(); | |
|
50 | QChartAxis* addAxisX(); | |
|
51 | QChartAxis* addAxisY(); | |
|
52 | void removeAxis(QChartAxis* axis); | |
|
53 | ||
|
48 | 54 | protected: |
|
49 | 55 | void mousePressEvent(QMouseEvent *event); |
|
50 | 56 | void mouseMoveEvent(QMouseEvent *event); |
General Comments 0
You need to be logged in to leave comments.
Login now