@@ -1,184 +1,202 | |||||
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 <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QGraphicsSceneResizeEvent> |
|
6 | #include <QGraphicsSceneResizeEvent> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
9 | /*! |
|
9 | /*! | |
10 | \class QChart |
|
10 | \class QChart | |
11 | \brief QtCommercial chart API. |
|
11 | \brief QtCommercial chart API. | |
12 |
|
12 | |||
13 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
13 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
14 | representation of different types of QChartSeries and other chart related objects like |
|
14 | representation of different types of QChartSeries and other chart related objects like | |
15 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
15 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
16 | convenience class QChartView instead of QChart. |
|
16 | convenience class QChartView instead of QChart. | |
|
17 | \sa QChartView | |||
17 | */ |
|
18 | */ | |
18 |
|
19 | |||
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
20 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
20 |
|
21 | |||
21 | /*! |
|
22 | /*! | |
22 | Constructs a chart object which is a child of parent. |
|
23 | Constructs a chart object which is a child of parent. | |
23 | */ |
|
24 | */ | |
24 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
25 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
25 | m_backgroundItem(0), |
|
26 | m_backgroundItem(0), | |
26 | m_titleItem(0), |
|
27 | m_titleItem(0), | |
27 | m_dataset(new ChartDataSet(this)), |
|
28 | m_dataset(new ChartDataSet(this)), | |
28 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
29 | m_presenter(new ChartPresenter(this,m_dataset)) | |
29 | { |
|
30 | { | |
30 | } |
|
31 | } | |
31 |
|
32 | |||
32 | /*! |
|
33 | /*! | |
33 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
34 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
34 | */ |
|
35 | */ | |
35 | QChart::~QChart() |
|
36 | QChart::~QChart() | |
36 | { |
|
37 | { | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | /*! |
|
40 | /*! | |
40 | Adds the series and optional y axis onto the chart and takes the ownership of the objects. |
|
41 | Adds the series and optional y axis onto the chart and takes the ownership of the objects. | |
41 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
42 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
42 | the y axis). |
|
43 | the y axis). | |
43 | */ |
|
44 | */ | |
44 | void QChart::addSeries(QChartSeries* series, QChartAxis* axisY) |
|
45 | void QChart::addSeries(QChartSeries* series, QChartAxis* axisY) | |
45 | { |
|
46 | { | |
46 | m_dataset->addSeries(series, axisY); |
|
47 | m_dataset->addSeries(series, axisY); | |
47 | } |
|
48 | } | |
48 |
|
49 | |||
|
50 | /*! | |||
|
51 | Removes the QChartSeries specified in a perameter from the QChartView. | |||
|
52 | It releses its ownership of the specified QChartSeries object. | |||
|
53 | It does not delete the pointed QChartSeries data object | |||
|
54 | \sa removeSeries(), removeAllSeries() | |||
|
55 | */ | |||
49 | void QChart::removeSeries(QChartSeries* series) |
|
56 | void QChart::removeSeries(QChartSeries* series) | |
50 | { |
|
57 | { | |
51 | m_dataset->removeSeries(series); |
|
58 | m_dataset->removeSeries(series); | |
52 | } |
|
59 | } | |
53 |
|
60 | |||
|
61 | /*! | |||
|
62 | Removes all the QChartSeries that have been added to the QChartView | |||
|
63 | It also deletes the pointed QChartSeries data objects | |||
|
64 | \sa addSeries(), removeSeries() | |||
|
65 | */ | |||
54 | void QChart::removeAllSeries() |
|
66 | void QChart::removeAllSeries() | |
55 | { |
|
67 | { | |
56 | m_dataset->removeAllSeries(); |
|
68 | m_dataset->removeAllSeries(); | |
57 | } |
|
69 | } | |
58 |
|
70 | |||
59 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
71 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
60 | { |
|
72 | { | |
61 | createChartBackgroundItem(); |
|
73 | createChartBackgroundItem(); | |
62 | m_backgroundItem->setBrush(brush); |
|
74 | m_backgroundItem->setBrush(brush); | |
63 | m_backgroundItem->update(); |
|
75 | m_backgroundItem->update(); | |
64 | } |
|
76 | } | |
65 |
|
77 | |||
66 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
78 | void QChart::setChartBackgroundPen(const QPen& pen) | |
67 | { |
|
79 | { | |
68 | createChartBackgroundItem(); |
|
80 | createChartBackgroundItem(); | |
69 | m_backgroundItem->setPen(pen); |
|
81 | m_backgroundItem->setPen(pen); | |
70 | m_backgroundItem->update(); |
|
82 | m_backgroundItem->update(); | |
71 | } |
|
83 | } | |
72 |
|
84 | |||
|
85 | /*! | |||
|
86 | Sets the title description text that is rendered above the chart. | |||
|
87 | */ | |||
73 | void QChart::setChartTitle(const QString& title) |
|
88 | void QChart::setChartTitle(const QString& title) | |
74 | { |
|
89 | { | |
75 | createChartTitleItem(); |
|
90 | createChartTitleItem(); | |
76 | m_titleItem->setPlainText(title); |
|
91 | m_titleItem->setPlainText(title); | |
77 | } |
|
92 | } | |
78 |
|
93 | |||
|
94 | /*! | |||
|
95 | Sets the font that is used for rendering the description text that is rendered above the chart. | |||
|
96 | */ | |||
79 | void QChart::setChartTitleFont(const QFont& font) |
|
97 | void QChart::setChartTitleFont(const QFont& font) | |
80 | { |
|
98 | { | |
81 | createChartTitleItem(); |
|
99 | createChartTitleItem(); | |
82 | m_titleItem->setFont(font); |
|
100 | m_titleItem->setFont(font); | |
83 | } |
|
101 | } | |
84 |
|
102 | |||
85 | void QChart::createChartBackgroundItem() |
|
103 | void QChart::createChartBackgroundItem() | |
86 | { |
|
104 | { | |
87 | if(!m_backgroundItem) { |
|
105 | if(!m_backgroundItem) { | |
88 | m_backgroundItem = new QGraphicsRectItem(this); |
|
106 | m_backgroundItem = new QGraphicsRectItem(this); | |
89 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
107 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
90 | } |
|
108 | } | |
91 | } |
|
109 | } | |
92 |
|
110 | |||
93 | void QChart::createChartTitleItem() |
|
111 | void QChart::createChartTitleItem() | |
94 | { |
|
112 | { | |
95 | if(!m_titleItem) { |
|
113 | if(!m_titleItem) { | |
96 | m_titleItem = new QGraphicsTextItem(this); |
|
114 | m_titleItem = new QGraphicsTextItem(this); | |
97 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
115 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
98 | } |
|
116 | } | |
99 | } |
|
117 | } | |
100 |
|
118 | |||
101 | int QChart::margin() const |
|
119 | int QChart::margin() const | |
102 | { |
|
120 | { | |
103 | return m_presenter->margin(); |
|
121 | return m_presenter->margin(); | |
104 | } |
|
122 | } | |
105 |
|
123 | |||
106 | void QChart::setMargin(int margin) |
|
124 | void QChart::setMargin(int margin) | |
107 | { |
|
125 | { | |
108 | m_presenter->setMargin(margin); |
|
126 | m_presenter->setMargin(margin); | |
109 | } |
|
127 | } | |
110 |
|
128 | |||
111 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
129 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
112 | { |
|
130 | { | |
113 | m_presenter->setChartTheme(theme); |
|
131 | m_presenter->setChartTheme(theme); | |
114 | } |
|
132 | } | |
115 |
|
133 | |||
116 | QChart::ChartTheme QChart::chartTheme() const |
|
134 | QChart::ChartTheme QChart::chartTheme() const | |
117 | { |
|
135 | { | |
118 | return m_presenter->chartTheme(); |
|
136 | return m_presenter->chartTheme(); | |
119 | } |
|
137 | } | |
120 |
|
138 | |||
121 | void QChart::zoomIn() |
|
139 | void QChart::zoomIn() | |
122 | { |
|
140 | { | |
123 | if (!m_dataset->nextDomain()) { |
|
141 | if (!m_dataset->nextDomain()) { | |
124 | QRectF rect = m_presenter->geometry(); |
|
142 | QRectF rect = m_presenter->geometry(); | |
125 | rect.setWidth(rect.width()/2); |
|
143 | rect.setWidth(rect.width()/2); | |
126 | rect.setHeight(rect.height()/2); |
|
144 | rect.setHeight(rect.height()/2); | |
127 | rect.moveCenter(m_presenter->geometry().center()); |
|
145 | rect.moveCenter(m_presenter->geometry().center()); | |
128 | zoomIn(rect); |
|
146 | zoomIn(rect); | |
129 | } |
|
147 | } | |
130 | } |
|
148 | } | |
131 |
|
149 | |||
132 | void QChart::zoomIn(const QRectF& rect) |
|
150 | void QChart::zoomIn(const QRectF& rect) | |
133 | { |
|
151 | { | |
134 | if(!rect.isValid()) return; |
|
152 | if(!rect.isValid()) return; | |
135 | QRectF r = rect.normalized(); |
|
153 | QRectF r = rect.normalized(); | |
136 | int margin = m_presenter->margin(); |
|
154 | int margin = m_presenter->margin(); | |
137 | r.translate(-margin, -margin); |
|
155 | r.translate(-margin, -margin); | |
138 | m_dataset->addDomain(r,m_presenter->geometry()); |
|
156 | m_dataset->addDomain(r,m_presenter->geometry()); | |
139 | } |
|
157 | } | |
140 |
|
158 | |||
141 | void QChart::zoomOut() |
|
159 | void QChart::zoomOut() | |
142 | { |
|
160 | { | |
143 | m_dataset->previousDomain(); |
|
161 | m_dataset->previousDomain(); | |
144 | } |
|
162 | } | |
145 |
|
163 | |||
146 | void QChart::zoomReset() |
|
164 | void QChart::zoomReset() | |
147 | { |
|
165 | { | |
148 | m_dataset->clearDomains(); |
|
166 | m_dataset->clearDomains(); | |
149 | } |
|
167 | } | |
150 |
|
168 | |||
151 | QChartAxis* QChart::axisX() const |
|
169 | QChartAxis* QChart::axisX() const | |
152 | { |
|
170 | { | |
153 | return m_dataset->axisX(); |
|
171 | return m_dataset->axisX(); | |
154 | } |
|
172 | } | |
155 |
|
173 | |||
156 | QChartAxis* QChart::axisY() const |
|
174 | QChartAxis* QChart::axisY() const | |
157 | { |
|
175 | { | |
158 | return m_dataset->axisY(); |
|
176 | return m_dataset->axisY(); | |
159 | } |
|
177 | } | |
160 |
|
178 | |||
161 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
179 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
162 | { |
|
180 | { | |
163 |
|
181 | |||
164 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
182 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
165 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
183 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
166 |
|
184 | |||
167 | // recalculate title position |
|
185 | // recalculate title position | |
168 | if (m_titleItem) { |
|
186 | if (m_titleItem) { | |
169 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
187 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
170 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
188 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
171 | } |
|
189 | } | |
172 |
|
190 | |||
173 | //recalculate background gradient |
|
191 | //recalculate background gradient | |
174 | if (m_backgroundItem) { |
|
192 | if (m_backgroundItem) { | |
175 | m_backgroundItem->setRect(rect); |
|
193 | m_backgroundItem->setRect(rect); | |
176 | } |
|
194 | } | |
177 |
|
195 | |||
178 | QGraphicsWidget::resizeEvent(event); |
|
196 | QGraphicsWidget::resizeEvent(event); | |
179 | update(); |
|
197 | update(); | |
180 | } |
|
198 | } | |
181 |
|
199 | |||
182 | #include "moc_qchart.cpp" |
|
200 | #include "moc_qchart.cpp" | |
183 |
|
201 | |||
184 | QTCOMMERCIALCHART_END_NAMESPACE |
|
202 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,226 +1,264 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 | #include <QGraphicsView> |
|
4 | #include <QGraphicsView> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QRubberBand> |
|
6 | #include <QRubberBand> | |
7 | #include <QResizeEvent> |
|
7 | #include <QResizeEvent> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | \class QChartView |
|
11 | \class QChartView | |
12 |
\brief Chart widget |
|
12 | \brief Chart widget | |
|
13 | ||||
|
14 | QChartView is a standalone widget that can display charts. It does not require QGraphicsScene to work. It manages the graphical | |||
|
15 | representation of different types of QChartSeries and other chart related objects like | |||
|
16 | QChartAxis and QChartLegend. If you want to display a chart in your existing QGraphicsScene, you can use the QChart class instead. | |||
|
17 | ||||
|
18 | \sa QChart | |||
13 | */ |
|
19 | */ | |
14 |
|
20 | |||
15 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
21 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
16 |
|
22 | |||
17 | QChartView::QChartView(QWidget *parent) : |
|
23 | QChartView::QChartView(QWidget *parent) : | |
18 | QGraphicsView(parent), |
|
24 | QGraphicsView(parent), | |
19 | m_scene(new QGraphicsScene(this)), |
|
25 | m_scene(new QGraphicsScene(this)), | |
20 | m_chart(new QChart()), |
|
26 | m_chart(new QChart()), | |
21 | m_rubberBand(0), |
|
27 | m_rubberBand(0), | |
22 | m_verticalRubberBand(false), |
|
28 | m_verticalRubberBand(false), | |
23 | m_horizonalRubberBand(false) |
|
29 | m_horizonalRubberBand(false) | |
24 | { |
|
30 | { | |
25 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
31 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
26 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
32 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
27 | setScene(m_scene); |
|
33 | setScene(m_scene); | |
28 | m_chart->setMargin(50); |
|
34 | m_chart->setMargin(50); | |
29 | m_scene->addItem(m_chart); |
|
35 | m_scene->addItem(m_chart); | |
30 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
36 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
31 | } |
|
37 | } | |
32 |
|
38 | |||
33 | QChartView::~QChartView() |
|
39 | QChartView::~QChartView() | |
34 | { |
|
40 | { | |
35 | } |
|
41 | } | |
36 |
|
42 | |||
37 | void QChartView::resizeEvent(QResizeEvent *event) |
|
43 | void QChartView::resizeEvent(QResizeEvent *event) | |
38 | { |
|
44 | { | |
39 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
45 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
40 | m_chart->resize(size()); |
|
46 | m_chart->resize(size()); | |
41 | QWidget::resizeEvent(event); |
|
47 | QWidget::resizeEvent(event); | |
42 | } |
|
48 | } | |
43 |
|
49 | |||
|
50 | /*! | |||
|
51 | Adds the series and optional y axis onto the chart and takes the ownership of the objects. | |||
|
52 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |||
|
53 | the y axis). | |||
|
54 | \sa removeSeries, removeAllSeries | |||
|
55 | */ | |||
44 | void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY) |
|
56 | void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY) | |
45 | { |
|
57 | { | |
46 | m_chart->addSeries(series,axisY); |
|
58 | m_chart->addSeries(series,axisY); | |
47 | } |
|
59 | } | |
48 |
|
60 | |||
|
61 | /*! | |||
|
62 | Removes the QChartSeries specified in a perameter from the QChartView. | |||
|
63 | It releses its ownership of the specified QChartSeries object. | |||
|
64 | It does not delete the pointed QChartSeries data object | |||
|
65 | \sa removeSeries(), removeAllSeries() | |||
|
66 | */ | |||
49 | void QChartView::removeSeries(QChartSeries* series) |
|
67 | void QChartView::removeSeries(QChartSeries* series) | |
50 | { |
|
68 | { | |
51 | m_chart->removeSeries(series); |
|
69 | m_chart->removeSeries(series); | |
52 | } |
|
70 | } | |
53 |
|
71 | |||
|
72 | /*! | |||
|
73 | Removes all the QChartSeries that have been added to the QChartView | |||
|
74 | It also deletes the pointed QChartSeries data objects | |||
|
75 | \sa addSeries(), removeSeries() | |||
|
76 | */ | |||
54 | void QChartView::removeAllSeries() |
|
77 | void QChartView::removeAllSeries() | |
55 | { |
|
78 | { | |
56 | m_chart->removeAllSeries(); |
|
79 | m_chart->removeAllSeries(); | |
57 | } |
|
80 | } | |
58 |
|
81 | |||
59 | void QChartView::zoomIn() |
|
82 | void QChartView::zoomIn() | |
60 | { |
|
83 | { | |
61 | m_chart->zoomIn(); |
|
84 | m_chart->zoomIn(); | |
62 | } |
|
85 | } | |
63 |
|
86 | |||
64 | void QChartView::zoomIn(const QRect& rect) |
|
87 | void QChartView::zoomIn(const QRect& rect) | |
65 | { |
|
88 | { | |
66 | m_chart->zoomIn(rect); |
|
89 | m_chart->zoomIn(rect); | |
67 | } |
|
90 | } | |
68 |
|
91 | |||
69 | void QChartView::zoomOut() |
|
92 | void QChartView::zoomOut() | |
70 | { |
|
93 | { | |
71 | m_chart->zoomOut(); |
|
94 | m_chart->zoomOut(); | |
72 | } |
|
95 | } | |
73 |
|
96 | |||
|
97 | /*! | |||
|
98 | Returns the chart margin, which is the distance between the widget edge and the axis lines or the chart. | |||
|
99 | */ | |||
74 | int QChartView::margin() const |
|
100 | int QChartView::margin() const | |
75 | { |
|
101 | { | |
76 | return m_chart->margin(); |
|
102 | return m_chart->margin(); | |
77 | } |
|
103 | } | |
78 |
|
104 | |||
|
105 | /*! | |||
|
106 | Sets the title description text that is rendered above the chart. | |||
|
107 | */ | |||
79 | void QChartView::setChartTitle(const QString& title) |
|
108 | void QChartView::setChartTitle(const QString& title) | |
80 | { |
|
109 | { | |
81 | m_chart->setChartTitle(title); |
|
110 | m_chart->setChartTitle(title); | |
82 | } |
|
111 | } | |
83 |
|
112 | |||
|
113 | /*! | |||
|
114 | Sets the font that is used for rendering the description text that is rendered above the chart. | |||
|
115 | */ | |||
84 | void QChartView::setChartTitleFont(const QFont& font) |
|
116 | void QChartView::setChartTitleFont(const QFont& font) | |
85 | { |
|
117 | { | |
86 | m_chart->setChartTitleFont(font); |
|
118 | m_chart->setChartTitleFont(font); | |
87 | } |
|
119 | } | |
88 |
|
120 | |||
89 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
121 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |
90 | { |
|
122 | { | |
91 | m_chart->setChartBackgroundBrush(brush); |
|
123 | m_chart->setChartBackgroundBrush(brush); | |
92 | } |
|
124 | } | |
93 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
125 | void QChartView::setChartBackgroundPen(const QPen& pen) | |
94 | { |
|
126 | { | |
95 | m_chart->setChartBackgroundPen(pen); |
|
127 | m_chart->setChartBackgroundPen(pen); | |
96 | } |
|
128 | } | |
97 |
|
129 | |||
98 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
130 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |
99 | { |
|
131 | { | |
100 | switch(policy) { |
|
132 | switch(policy) { | |
101 | case VerticalRubberBand: |
|
133 | case VerticalRubberBand: | |
102 | m_verticalRubberBand = true; |
|
134 | m_verticalRubberBand = true; | |
103 | m_horizonalRubberBand = false; |
|
135 | m_horizonalRubberBand = false; | |
104 | break; |
|
136 | break; | |
105 | case HorizonalRubberBand: |
|
137 | case HorizonalRubberBand: | |
106 | m_verticalRubberBand = false; |
|
138 | m_verticalRubberBand = false; | |
107 | m_horizonalRubberBand = true; |
|
139 | m_horizonalRubberBand = true; | |
108 | break; |
|
140 | break; | |
109 | case RectangleRubberBand: |
|
141 | case RectangleRubberBand: | |
110 | m_verticalRubberBand = true; |
|
142 | m_verticalRubberBand = true; | |
111 | m_horizonalRubberBand = true; |
|
143 | m_horizonalRubberBand = true; | |
112 | break; |
|
144 | break; | |
113 | case NoRubberBand: |
|
145 | case NoRubberBand: | |
114 | default: |
|
146 | default: | |
115 | delete m_rubberBand; |
|
147 | delete m_rubberBand; | |
116 | m_rubberBand=0; |
|
148 | m_rubberBand=0; | |
117 | m_horizonalRubberBand = false; |
|
149 | m_horizonalRubberBand = false; | |
118 | m_verticalRubberBand = false; |
|
150 | m_verticalRubberBand = false; | |
119 | return; |
|
151 | return; | |
120 | } |
|
152 | } | |
121 | if(!m_rubberBand) { |
|
153 | if(!m_rubberBand) { | |
122 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
154 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
123 | m_rubberBand->setEnabled(true); |
|
155 | m_rubberBand->setEnabled(true); | |
124 | } |
|
156 | } | |
125 | } |
|
157 | } | |
126 |
|
158 | |||
127 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
159 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |
128 | { |
|
160 | { | |
129 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
161 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; | |
130 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
162 | if(m_horizonalRubberBand) return HorizonalRubberBand; | |
131 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
163 | if(m_verticalRubberBand) return VerticalRubberBand; | |
132 | return NoRubberBand; |
|
164 | return NoRubberBand; | |
133 | } |
|
165 | } | |
134 |
|
166 | |||
135 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
167 | void QChartView::mousePressEvent(QMouseEvent *event) | |
136 | { |
|
168 | { | |
137 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
169 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
138 |
|
170 | |||
139 | int margin = m_chart->margin(); |
|
171 | int margin = m_chart->margin(); | |
140 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
172 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
141 |
|
173 | |||
142 | if (rect.contains(event->pos())) { |
|
174 | if (rect.contains(event->pos())) { | |
143 | m_rubberBandOrigin = event->pos(); |
|
175 | m_rubberBandOrigin = event->pos(); | |
144 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
176 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); | |
145 | m_rubberBand->show(); |
|
177 | m_rubberBand->show(); | |
146 | event->accept(); |
|
178 | event->accept(); | |
147 | } |
|
179 | } | |
148 | } |
|
180 | } | |
149 | } |
|
181 | } | |
150 |
|
182 | |||
151 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
183 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
152 | { |
|
184 | { | |
153 | if(m_rubberBand && m_rubberBand->isVisible()) { |
|
185 | if(m_rubberBand && m_rubberBand->isVisible()) { | |
154 | int margin = m_chart->margin(); |
|
186 | int margin = m_chart->margin(); | |
155 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
187 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
156 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
188 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |
157 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
189 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |
158 | if(!m_verticalRubberBand) { |
|
190 | if(!m_verticalRubberBand) { | |
159 | m_rubberBandOrigin.setY(rect.top()); |
|
191 | m_rubberBandOrigin.setY(rect.top()); | |
160 | height = rect.height(); |
|
192 | height = rect.height(); | |
161 | } |
|
193 | } | |
162 | if(!m_horizonalRubberBand) { |
|
194 | if(!m_horizonalRubberBand) { | |
163 | m_rubberBandOrigin.setX(rect.left()); |
|
195 | m_rubberBandOrigin.setX(rect.left()); | |
164 | width= rect.width(); |
|
196 | width= rect.width(); | |
165 | } |
|
197 | } | |
166 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
198 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |
167 | } |
|
199 | } | |
168 | else { |
|
200 | else { | |
169 | QGraphicsView::mouseMoveEvent(event); |
|
201 | QGraphicsView::mouseMoveEvent(event); | |
170 | } |
|
202 | } | |
171 | } |
|
203 | } | |
172 |
|
204 | |||
173 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
205 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
174 | { |
|
206 | { | |
175 | if(m_rubberBand) { |
|
207 | if(m_rubberBand) { | |
176 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
208 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { | |
177 | m_rubberBand->hide(); |
|
209 | m_rubberBand->hide(); | |
178 | QRect rect = m_rubberBand->geometry(); |
|
210 | QRect rect = m_rubberBand->geometry(); | |
179 | m_chart->zoomIn(rect); |
|
211 | m_chart->zoomIn(rect); | |
180 | event->accept(); |
|
212 | event->accept(); | |
181 | } |
|
213 | } | |
182 |
|
214 | |||
183 | if(event->button()==Qt::RightButton) |
|
215 | if(event->button()==Qt::RightButton) | |
184 | m_chart->zoomReset(); |
|
216 | m_chart->zoomReset(); | |
185 | } |
|
217 | } | |
186 | else { |
|
218 | else { | |
187 | QGraphicsView::mouseReleaseEvent(event); |
|
219 | QGraphicsView::mouseReleaseEvent(event); | |
188 | } |
|
220 | } | |
189 | } |
|
221 | } | |
190 |
|
222 | |||
191 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
223 | void QChartView::keyPressEvent(QKeyEvent *event) | |
192 | { |
|
224 | { | |
193 | switch (event->key()) { |
|
225 | switch (event->key()) { | |
194 | case Qt::Key_Plus: |
|
226 | case Qt::Key_Plus: | |
195 | zoomIn(); |
|
227 | zoomIn(); | |
196 | break; |
|
228 | break; | |
197 | case Qt::Key_Minus: |
|
229 | case Qt::Key_Minus: | |
198 | zoomOut(); |
|
230 | zoomOut(); | |
199 | break; |
|
231 | break; | |
200 | default: |
|
232 | default: | |
201 | QGraphicsView::keyPressEvent(event); |
|
233 | QGraphicsView::keyPressEvent(event); | |
202 | break; |
|
234 | break; | |
203 | } |
|
235 | } | |
204 | } |
|
236 | } | |
205 |
|
237 | |||
206 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
238 | void QChartView::setChartTheme(QChart::ChartTheme theme) | |
207 | { |
|
239 | { | |
208 | m_chart->setChartTheme(theme); |
|
240 | m_chart->setChartTheme(theme); | |
209 | } |
|
241 | } | |
210 |
|
242 | |||
211 | QChart::ChartTheme QChartView::chartTheme() const |
|
243 | QChart::ChartTheme QChartView::chartTheme() const | |
212 | { |
|
244 | { | |
213 | return m_chart->chartTheme(); |
|
245 | return m_chart->chartTheme(); | |
214 | } |
|
246 | } | |
215 |
|
247 | |||
|
248 | /*! | |||
|
249 | Returns the pointer to the x axis object of the chart | |||
|
250 | */ | |||
216 | QChartAxis* QChartView::axisX() const |
|
251 | QChartAxis* QChartView::axisX() const | |
217 | { |
|
252 | { | |
218 | return m_chart->axisX(); |
|
253 | return m_chart->axisX(); | |
219 | } |
|
254 | } | |
220 |
|
255 | |||
|
256 | /*! | |||
|
257 | Returns the pointer to the y axis object of the chart | |||
|
258 | */ | |||
221 | QChartAxis* QChartView::axisY() const |
|
259 | QChartAxis* QChartView::axisY() const | |
222 | { |
|
260 | { | |
223 | return m_chart->axisY(); |
|
261 | return m_chart->axisY(); | |
224 | } |
|
262 | } | |
225 |
|
263 | |||
226 | QTCOMMERCIALCHART_END_NAMESPACE |
|
264 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now