@@ -32,7 +32,6 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char | |||||
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), |
|
|||
36 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
35 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
37 | m_options(QChart::NoAnimation) |
|
36 | m_options(QChart::NoAnimation) | |
38 | { |
|
37 | { | |
@@ -63,7 +62,7 QRectF ChartPresenter::geometry() const | |||||
63 | void ChartPresenter::handleGeometryChanged() |
|
62 | void ChartPresenter::handleGeometryChanged() | |
64 | { |
|
63 | { | |
65 | QRectF rect(QPoint(0,0),m_chart->size()); |
|
64 | QRectF rect(QPoint(0,0),m_chart->size()); | |
66 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
65 | rect.adjust(m_chart->padding(),m_chart->padding(), -m_chart->padding(), -m_chart->padding()); | |
67 |
|
66 | |||
68 | //rewrite zoom stack |
|
67 | //rewrite zoom stack | |
69 | for(int i=0;i<m_zoomStack.count();i++){ |
|
68 | for(int i=0;i<m_zoomStack.count();i++){ | |
@@ -86,16 +85,6 void ChartPresenter::handleGeometryChanged() | |||||
86 | emit geometryChanged(m_rect); |
|
85 | emit geometryChanged(m_rect); | |
87 | } |
|
86 | } | |
88 |
|
87 | |||
89 | int ChartPresenter::margin() const |
|
|||
90 | { |
|
|||
91 | return m_marginSize; |
|
|||
92 | } |
|
|||
93 |
|
||||
94 | void ChartPresenter::setMargin(int margin) |
|
|||
95 | { |
|
|||
96 | m_marginSize = margin; |
|
|||
97 | } |
|
|||
98 |
|
||||
99 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) |
|
88 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
100 | { |
|
89 | { | |
101 | AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
90 | AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
@@ -339,7 +328,7 void ChartPresenter::zoomIn() | |||||
339 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
328 | void ChartPresenter::zoomIn(const QRectF& rect) | |
340 | { |
|
329 | { | |
341 | QRectF r = rect.normalized(); |
|
330 | QRectF r = rect.normalized(); | |
342 |
r.translate(-m_ |
|
331 | r.translate(-m_chart->padding(), -m_chart->padding()); | |
343 | if(m_animator) { |
|
332 | if(m_animator) { | |
344 |
|
333 | |||
345 | 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()); |
@@ -72,7 +72,6 private: | |||||
72 | ChartDataSet* m_dataset; |
|
72 | ChartDataSet* m_dataset; | |
73 | ChartTheme *m_chartTheme; |
|
73 | ChartTheme *m_chartTheme; | |
74 | int m_zoomIndex; |
|
74 | int m_zoomIndex; | |
75 | int m_marginSize; |
|
|||
76 | QMap<QSeries*,ChartItem*> m_chartItems; |
|
75 | QMap<QSeries*,ChartItem*> m_chartItems; | |
77 | QMap<QChartAxis*,AxisItem*> m_axisItems; |
|
76 | QMap<QChartAxis*,AxisItem*> m_axisItems; | |
78 | QVector<QRectF> m_zoomStack; |
|
77 | QVector<QRectF> m_zoomStack; |
@@ -3,6 +3,7 | |||||
3 | #include "qlegend.h" |
|
3 | #include "qlegend.h" | |
4 | #include "chartpresenter_p.h" |
|
4 | #include "chartpresenter_p.h" | |
5 | #include "chartdataset_p.h" |
|
5 | #include "chartdataset_p.h" | |
|
6 | #include "chartbackground_p.h" | |||
6 | #include <QGraphicsScene> |
|
7 | #include <QGraphicsScene> | |
7 | #include <QGraphicsSceneResizeEvent> |
|
8 | #include <QGraphicsSceneResizeEvent> | |
8 | #include <QDebug> |
|
9 | #include <QDebug> | |
@@ -54,7 +55,9 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget( | |||||
54 | m_titleItem(0), |
|
55 | m_titleItem(0), | |
55 | m_legend(new QLegend(this)), |
|
56 | m_legend(new QLegend(this)), | |
56 | m_dataset(new ChartDataSet(this)), |
|
57 | m_dataset(new ChartDataSet(this)), | |
57 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
58 | m_presenter(new ChartPresenter(this,m_dataset)), | |
|
59 | m_padding(50), | |||
|
60 | m_backgroundPadding(10) | |||
58 | { |
|
61 | { | |
59 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
62 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
60 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
63 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
@@ -173,7 +176,7 QBrush QChart::chartTitleBrush() | |||||
173 | void QChart::createChartBackgroundItem() |
|
176 | void QChart::createChartBackgroundItem() | |
174 | { |
|
177 | { | |
175 | if(!m_backgroundItem) { |
|
178 | if(!m_backgroundItem) { | |
176 |
m_backgroundItem = new |
|
179 | m_backgroundItem = new ChartBackground(this); | |
177 | m_backgroundItem->setPen(Qt::NoPen); |
|
180 | m_backgroundItem->setPen(Qt::NoPen); | |
178 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
181 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
179 | } |
|
182 | } | |
@@ -188,25 +191,6 void QChart::createChartTitleItem() | |||||
188 | } |
|
191 | } | |
189 |
|
192 | |||
190 | /*! |
|
193 | /*! | |
191 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
|||
192 | \sa setMargin() |
|
|||
193 | */ |
|
|||
194 | int QChart::margin() const |
|
|||
195 | { |
|
|||
196 | return m_presenter->margin(); |
|
|||
197 | } |
|
|||
198 |
|
||||
199 | /*! |
|
|||
200 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
|||
201 | \sa margin() |
|
|||
202 | */ |
|
|||
203 | void QChart::setMargin(int margin) |
|
|||
204 | { |
|
|||
205 | m_presenter->setMargin(margin); |
|
|||
206 | updateLayout(); |
|
|||
207 | } |
|
|||
208 |
|
||||
209 | /*! |
|
|||
210 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
194 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
211 | \sa ChartTheme, chartTheme() |
|
195 | \sa ChartTheme, chartTheme() | |
212 | */ |
|
196 | */ | |
@@ -332,17 +316,17 void QChart::updateLayout() | |||||
332 | { |
|
316 | { | |
333 | if(!m_rect.isValid()) return; |
|
317 | if(!m_rect.isValid()) return; | |
334 |
|
318 | |||
335 |
QRectF rect = m_rect.adjusted(m |
|
319 | QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding); | |
336 |
|
320 | |||
337 | // recalculate title position |
|
321 | // recalculate title position | |
338 | if (m_titleItem) { |
|
322 | if (m_titleItem) { | |
339 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
323 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
340 |
m_titleItem->setPos(center.x(),m_rect.top()/2 + m |
|
324 | m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2); | |
341 | } |
|
325 | } | |
342 |
|
326 | |||
343 | //recalculate background gradient |
|
327 | //recalculate background gradient | |
344 | if (m_backgroundItem) { |
|
328 | if (m_backgroundItem) { | |
345 | m_backgroundItem->setRect(rect); |
|
329 | m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding)); | |
346 | } |
|
330 | } | |
347 |
|
331 | |||
348 | // recalculate legend position |
|
332 | // recalculate legend position | |
@@ -352,6 +336,37 void QChart::updateLayout() | |||||
352 | m_legend->setPreferredLayout(QLegend::PreferredLayoutHorizontal); |
|
336 | m_legend->setPreferredLayout(QLegend::PreferredLayoutHorizontal); | |
353 | } |
|
337 | } | |
354 | } |
|
338 | } | |
|
339 | ||||
|
340 | ||||
|
341 | int QChart::padding() const | |||
|
342 | { | |||
|
343 | return m_padding; | |||
|
344 | } | |||
|
345 | ||||
|
346 | void QChart::setPadding(int padding) | |||
|
347 | { | |||
|
348 | if(m_padding==padding){ | |||
|
349 | m_padding = padding; | |||
|
350 | m_presenter->handleGeometryChanged(); | |||
|
351 | updateLayout(); | |||
|
352 | } | |||
|
353 | } | |||
|
354 | ||||
|
355 | void QChart::setBackgroundPadding(int padding) | |||
|
356 | { | |||
|
357 | if(m_backgroundPadding!=padding){ | |||
|
358 | m_backgroundPadding = padding; | |||
|
359 | updateLayout(); | |||
|
360 | } | |||
|
361 | } | |||
|
362 | ||||
|
363 | void QChart::setBackgroundDiameter(int diameter) | |||
|
364 | { | |||
|
365 | createChartBackgroundItem(); | |||
|
366 | m_backgroundItem->setDimeter(diameter); | |||
|
367 | m_backgroundItem->update(); | |||
|
368 | } | |||
|
369 | ||||
355 | #include "moc_qchart.cpp" |
|
370 | #include "moc_qchart.cpp" | |
356 |
|
371 | |||
357 | QTCOMMERCIALCHART_END_NAMESPACE |
|
372 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -21,6 +21,8 class ChartItem; | |||||
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 | class QLegend; |
|
23 | class QLegend; | |
|
24 | class ChartBackground; | |||
|
25 | ||||
24 |
|
26 | |||
25 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
27 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
26 | { |
|
28 | { | |
@@ -53,8 +55,6 public: | |||||
53 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
55 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
54 | void removeAllSeries(); // deletes series and axis |
|
56 | void removeAllSeries(); // deletes series and axis | |
55 |
|
57 | |||
56 | void setMargin(int margin); |
|
|||
57 | int margin() const; |
|
|||
58 | void setChartTheme(QChart::ChartTheme theme); |
|
58 | void setChartTheme(QChart::ChartTheme theme); | |
59 | QChart::ChartTheme chartTheme() const; |
|
59 | QChart::ChartTheme chartTheme() const; | |
60 |
|
60 | |||
@@ -84,22 +84,30 public: | |||||
84 | // TODO: take (and give) legend instead of this. |
|
84 | // TODO: take (and give) legend instead of this. | |
85 | QLegend* legend(); |
|
85 | QLegend* legend(); | |
86 |
|
86 | |||
|
87 | ||||
|
88 | int padding() const; | |||
|
89 | ||||
87 | protected: |
|
90 | protected: | |
88 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
91 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
89 |
|
92 | |||
90 | private: |
|
93 | private: | |
91 | inline void createChartBackgroundItem(); |
|
94 | inline void createChartBackgroundItem(); | |
92 | inline void createChartTitleItem(); |
|
95 | inline void createChartTitleItem(); | |
|
96 | void setPadding(int padding); | |||
|
97 | void setBackgroundPadding(int padding); | |||
|
98 | void setBackgroundDiameter(int diameter); | |||
93 | void updateLayout(); |
|
99 | void updateLayout(); | |
94 |
|
100 | |||
95 | private: |
|
101 | private: | |
96 | Q_DISABLE_COPY(QChart) |
|
102 | Q_DISABLE_COPY(QChart) | |
97 |
|
|
103 | ChartBackground* m_backgroundItem; | |
98 | QGraphicsSimpleTextItem* m_titleItem; |
|
104 | QGraphicsSimpleTextItem* m_titleItem; | |
99 | QRectF m_rect; |
|
105 | QRectF m_rect; | |
100 | QLegend* m_legend; |
|
106 | QLegend* m_legend; | |
101 | ChartDataSet *m_dataset; |
|
107 | ChartDataSet *m_dataset; | |
102 | ChartPresenter *m_presenter; |
|
108 | ChartPresenter *m_presenter; | |
|
109 | int m_padding; | |||
|
110 | int m_backgroundPadding; | |||
103 | }; |
|
111 | }; | |
104 |
|
112 | |||
105 | QTCOMMERCIALCHART_END_NAMESPACE |
|
113 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -46,7 +46,6 QChartView::QChartView(QWidget *parent) : | |||||
46 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
46 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
47 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
47 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
48 | setScene(m_scene); |
|
48 | setScene(m_scene); | |
49 | m_chart->setMargin(50); |
|
|||
50 | m_scene->addItem(m_chart); |
|
49 | m_scene->addItem(m_chart); | |
51 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
50 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
52 | } |
|
51 | } | |
@@ -126,14 +125,6 void QChartView::zoomOut() | |||||
126 | } |
|
125 | } | |
127 |
|
126 | |||
128 | /*! |
|
127 | /*! | |
129 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
|||
130 | */ |
|
|||
131 | int QChartView::margin() const |
|
|||
132 | { |
|
|||
133 | return m_chart->margin(); |
|
|||
134 | } |
|
|||
135 |
|
||||
136 | /*! |
|
|||
137 | Sets the chart \a title. A description text that is drawn above the chart. |
|
128 | Sets the chart \a title. A description text that is drawn above the chart. | |
138 | */ |
|
129 | */ | |
139 | void QChartView::setChartTitle(const QString& title) |
|
130 | void QChartView::setChartTitle(const QString& title) | |
@@ -240,8 +231,8 void QChartView::mousePressEvent(QMouseEvent *event) | |||||
240 | { |
|
231 | { | |
241 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
232 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
242 |
|
233 | |||
243 |
int |
|
234 | int padding = m_chart->padding(); | |
244 |
QRect rect( |
|
235 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
245 |
|
236 | |||
246 | if (rect.contains(event->pos())) { |
|
237 | if (rect.contains(event->pos())) { | |
247 | m_rubberBandOrigin = event->pos(); |
|
238 | m_rubberBandOrigin = event->pos(); | |
@@ -262,8 +253,8 void QChartView::mousePressEvent(QMouseEvent *event) | |||||
262 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
253 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
263 | { |
|
254 | { | |
264 | if(m_rubberBand && m_rubberBand->isVisible()) { |
|
255 | if(m_rubberBand && m_rubberBand->isVisible()) { | |
265 |
int |
|
256 | int padding = m_chart->padding(); | |
266 |
QRect rect( |
|
257 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
267 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
258 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |
268 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
259 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |
269 | if(!m_verticalRubberBand) { |
|
260 | if(!m_verticalRubberBand) { |
@@ -30,7 +30,6 public: | |||||
30 | void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership |
|
30 | void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership | |
31 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
31 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
32 | void removeAllSeries(); // deletes series and axis |
|
32 | void removeAllSeries(); // deletes series and axis | |
33 | int margin() const; |
|
|||
34 |
|
33 | |||
35 | void setChartTitle(const QString& title); |
|
34 | void setChartTitle(const QString& title); | |
36 | QString chartTitle() const; |
|
35 | QString chartTitle() const; |
@@ -16,20 +16,22 SOURCES += \ | |||||
16 | qchartview.cpp \ |
|
16 | qchartview.cpp \ | |
17 | qseries.cpp \ |
|
17 | qseries.cpp \ | |
18 | qlegend.cpp \ |
|
18 | qlegend.cpp \ | |
19 | legendmarker.cpp |
|
19 | legendmarker.cpp \ | |
|
20 | chartbackground.cpp | |||
20 | PRIVATE_HEADERS += \ |
|
21 | PRIVATE_HEADERS += \ | |
21 | chartdataset_p.h \ |
|
22 | chartdataset_p.h \ | |
22 | chartitem_p.h \ |
|
23 | chartitem_p.h \ | |
23 | chartpresenter_p.h \ |
|
24 | chartpresenter_p.h \ | |
24 | charttheme_p.h \ |
|
25 | charttheme_p.h \ | |
25 | domain_p.h \ |
|
26 | domain_p.h \ | |
26 | legendmarker_p.h |
|
27 | legendmarker_p.h \ | |
|
28 | chartbackground_p.h | |||
27 | PUBLIC_HEADERS += \ |
|
29 | PUBLIC_HEADERS += \ | |
28 | qchart.h \ |
|
30 | qchart.h \ | |
29 | qchartglobal.h \ |
|
31 | qchartglobal.h \ | |
30 | qseries.h \ |
|
32 | qseries.h \ | |
31 | qchartview.h \ |
|
33 | qchartview.h \ | |
32 | qlegend.h |
|
34 | qlegend.h | |
33 |
|
35 | |||
34 | include(animations/animations.pri) |
|
36 | include(animations/animations.pri) | |
35 | include(axis/axis.pri) |
|
37 | include(axis/axis.pri) |
General Comments 0
You need to be logged in to leave comments.
Login now