@@ -33,6 +33,7 int main(int argc, char *argv[]) | |||||
33 |
|
33 | |||
34 | QChartView* chartView = new QChartView(&window); |
|
34 | QChartView* chartView = new QChartView(&window); | |
35 | chartView->setRenderHint(QPainter::Antialiasing); |
|
35 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
36 | chartView->setTitle("Example: sin & cos functions"); | |||
36 | chartView->addSeries(series0); |
|
37 | chartView->addSeries(series0); | |
37 | chartView->addSeries(series1); |
|
38 | chartView->addSeries(series1); | |
38 |
|
39 |
@@ -17,9 +17,9 | |||||
17 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
17 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
18 |
|
18 | |||
19 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), |
|
19 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |
20 | m_background(0), |
|
20 | m_backgroundItem(0), | |
21 | m_title(0), |
|
21 | m_titleItem(0), | |
22 | m_axisX(new AxisItem(AxisItem::X_AXIS,this)), |
|
22 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)), | |
23 | m_plotDataIndex(0), |
|
23 | m_plotDataIndex(0), | |
24 | m_marginSize(0) |
|
24 | m_marginSize(0) | |
25 | { |
|
25 | { | |
@@ -28,9 +28,9 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |||||
28 |
|
28 | |||
29 | PlotDomain domain; |
|
29 | PlotDomain domain; | |
30 | m_plotDomainList<<domain; |
|
30 | m_plotDomainList<<domain; | |
31 | m_axisY << new AxisItem(AxisItem::Y_AXIS,this); |
|
31 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); | |
32 | m_chartItems<<m_axisX; |
|
32 | m_chartItems<<m_axisXItem; | |
33 | m_chartItems<<m_axisY.at(0); |
|
33 | m_chartItems<<m_axisYItem.at(0); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | QChart::~QChart(){} |
|
36 | QChart::~QChart(){} | |
@@ -164,19 +164,21 void QChart::setSize(const QSize& size) | |||||
164 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
164 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
165 |
|
165 | |||
166 | //recaculate title |
|
166 | //recaculate title | |
167 | if(m_title){ |
|
167 | if(m_titleItem){ | |
|
168 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |||
|
169 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |||
168 |
|
170 | |||
169 | } |
|
171 | } | |
170 |
|
172 | |||
171 | //recalculate background gradient |
|
173 | //recalculate background gradient | |
172 | if(m_background){ |
|
174 | if(m_backgroundItem){ | |
173 | m_background->setRect(rect); |
|
175 | m_backgroundItem->setRect(rect); | |
174 | if(m_bacgroundOrinetation==HorizonatlGradientOrientation) |
|
176 | if(m_bacgroundOrinetation==HorizonatlGradientOrientation) | |
175 | m_backgroundGradient.setFinalStop(m_background->rect().width(),0); |
|
177 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(),0); | |
176 | else |
|
178 | else | |
177 | m_backgroundGradient.setFinalStop(0,m_background->rect().height()); |
|
179 | m_backgroundGradient.setFinalStop(0,m_backgroundItem->rect().height()); | |
178 |
|
180 | |||
179 | m_background->setBrush(m_backgroundGradient); |
|
181 | m_backgroundItem->setBrush(m_backgroundGradient); | |
180 | } |
|
182 | } | |
181 |
|
183 | |||
182 | //resize elements |
|
184 | //resize elements | |
@@ -197,9 +199,9 void QChart::setSize(const QSize& size) | |||||
197 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) |
|
199 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) | |
198 | { |
|
200 | { | |
199 |
|
201 | |||
200 | if(!m_background){ |
|
202 | if(!m_backgroundItem){ | |
201 | m_background = new QGraphicsRectItem(this); |
|
203 | m_backgroundItem = new QGraphicsRectItem(this); | |
202 | m_background->setZValue(-1); |
|
204 | m_backgroundItem->setZValue(-1); | |
203 | } |
|
205 | } | |
204 |
|
206 | |||
205 | m_bacgroundOrinetation = orientation; |
|
207 | m_bacgroundOrinetation = orientation; | |
@@ -213,15 +215,16 void QChart::setBackground(const QColor& startColor, const QColor& endColor, Gra | |||||
213 | m_backgroundGradient.setFinalStop(m_rect.width(),0); |
|
215 | m_backgroundGradient.setFinalStop(m_rect.width(),0); | |
214 | } |
|
216 | } | |
215 |
|
217 | |||
216 | m_background->setBrush(m_backgroundGradient); |
|
218 | m_backgroundItem->setBrush(m_backgroundGradient); | |
217 | m_background->setPen(Qt::NoPen); |
|
219 | m_backgroundItem->setPen(Qt::NoPen); | |
218 | m_background->update(); |
|
220 | m_backgroundItem->update(); | |
219 | } |
|
221 | } | |
220 |
|
222 | |||
221 | void QChart::setTitle(const QString& title) |
|
223 | void QChart::setTitle(const QString& title,const QFont& font) | |
222 | { |
|
224 | { | |
223 | if(!m_title) m_title = new QGraphicsTextItem(this); |
|
225 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
224 | m_title->setPlainText(title); |
|
226 | m_titleItem->setPlainText(title); | |
|
227 | m_titleItem->setFont(font); | |||
225 | } |
|
228 | } | |
226 |
|
229 | |||
227 | int QChart::margin() const |
|
230 | int QChart::margin() const | |
@@ -290,9 +293,9 void QChart::setTheme(QChart::ChartThemeId theme) | |||||
290 | break; |
|
293 | break; | |
291 | } |
|
294 | } | |
292 |
|
295 | |||
293 | if(m_background){ |
|
296 | if(m_backgroundItem){ | |
294 | m_background->setBrush(m_backgroundGradient); |
|
297 | m_backgroundItem->setBrush(m_backgroundGradient); | |
295 | m_background->setPen(Qt::NoPen); |
|
298 | m_backgroundItem->setPen(Qt::NoPen); | |
296 | } |
|
299 | } | |
297 |
|
300 | |||
298 | foreach(QChartSeries* series, m_chartSeries) { |
|
301 | foreach(QChartSeries* series, m_chartSeries) { | |
@@ -370,11 +373,11 void QChart::zoomOut() | |||||
370 |
|
373 | |||
371 | void QChart::setAxisX(const QChartAxis& axis) |
|
374 | void QChart::setAxisX(const QChartAxis& axis) | |
372 | { |
|
375 | { | |
373 | setAxis(m_axisX,axis); |
|
376 | setAxis(m_axisXItem,axis); | |
374 | } |
|
377 | } | |
375 | void QChart::setAxisY(const QChartAxis& axis) |
|
378 | void QChart::setAxisY(const QChartAxis& axis) | |
376 | { |
|
379 | { | |
377 | setAxis(m_axisY.at(0),axis); |
|
380 | setAxis(m_axisYItem.at(0),axis); | |
378 | } |
|
381 | } | |
379 |
|
382 | |||
380 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
383 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
@@ -5,6 +5,7 | |||||
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsObject> |
|
6 | #include <QGraphicsObject> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
|
8 | #include <QFont> | |||
8 |
|
9 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
11 | |||
@@ -59,7 +60,7 public: | |||||
59 | int margin() const; |
|
60 | int margin() const; | |
60 | void setTheme(QChart::ChartThemeId theme); |
|
61 | void setTheme(QChart::ChartThemeId theme); | |
61 |
|
62 | |||
62 | void setTitle(const QString& title); |
|
63 | void setTitle(const QString& title,const QFont& font = QFont()); | |
63 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation); |
|
64 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation); | |
64 |
|
65 | |||
65 | void zoomInToRect(const QRect& rectangle); |
|
66 | void zoomInToRect(const QRect& rectangle); | |
@@ -82,12 +83,12 private: | |||||
82 | QColor nextColor(); |
|
83 | QColor nextColor(); | |
83 |
|
84 | |||
84 | Q_DISABLE_COPY(QChart) |
|
85 | Q_DISABLE_COPY(QChart) | |
85 | QGraphicsRectItem* m_background; |
|
86 | QGraphicsRectItem* m_backgroundItem; | |
86 | QLinearGradient m_backgroundGradient; |
|
87 | QLinearGradient m_backgroundGradient; | |
87 | GradientOrientation m_bacgroundOrinetation; |
|
88 | GradientOrientation m_bacgroundOrinetation; | |
88 | QGraphicsTextItem* m_title; |
|
89 | QGraphicsTextItem* m_titleItem; | |
89 | AxisItem* m_axisX; |
|
90 | AxisItem* m_axisXItem; | |
90 | QList<AxisItem*> m_axisY; |
|
91 | QList<AxisItem*> m_axisYItem; | |
91 | QRect m_rect; |
|
92 | QRect m_rect; | |
92 | QList<QChartSeries*> m_chartSeries; |
|
93 | QList<QChartSeries*> m_chartSeries; | |
93 | QVector<PlotDomain> m_plotDomainList; |
|
94 | QVector<PlotDomain> m_plotDomainList; |
General Comments 0
You need to be logged in to leave comments.
Login now