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