##// END OF EJS Templates
Added option to set labels clipping...
Titta Heikkala -
r2815:4c1d3bc34edb
parent child
Show More
@@ -39,6 +39,7 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
39 m_pointLabelsFormat(areaSeries->pointLabelsFormat()),
39 m_pointLabelsFormat(areaSeries->pointLabelsFormat()),
40 m_pointLabelsFont(areaSeries->pointLabelsFont()),
40 m_pointLabelsFont(areaSeries->pointLabelsFont()),
41 m_pointLabelsColor(areaSeries->pointLabelsColor()),
41 m_pointLabelsColor(areaSeries->pointLabelsColor()),
42 m_pointLabelsClipping(true),
42 m_mousePressed(false)
43 m_mousePressed(false)
43 {
44 {
44 setAcceptHoverEvents(true);
45 setAcceptHoverEvents(true);
@@ -66,6 +67,8 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
66 this, SLOT(handleUpdated()));
67 this, SLOT(handleUpdated()));
67 QObject::connect(areaSeries, SIGNAL(pointLabelsColorChanged(QColor)),
68 QObject::connect(areaSeries, SIGNAL(pointLabelsColorChanged(QColor)),
68 this, SLOT(handleUpdated()));
69 this, SLOT(handleUpdated()));
70 QObject::connect(areaSeries, SIGNAL(pointLabelsClippingChanged(bool)),
71 this, SLOT(handleUpdated()));
69
72
70 handleUpdated();
73 handleUpdated();
71 }
74 }
@@ -151,6 +154,7 void AreaChartItem::handleUpdated()
151 m_pointLabelsVisible = m_series->pointLabelsVisible();
154 m_pointLabelsVisible = m_series->pointLabelsVisible();
152 m_pointLabelsFont = m_series->pointLabelsFont();
155 m_pointLabelsFont = m_series->pointLabelsFont();
153 m_pointLabelsColor = m_series->pointLabelsColor();
156 m_pointLabelsColor = m_series->pointLabelsColor();
157 m_pointLabelsClipping = m_series->pointLabelsClipping();
154 update();
158 update();
155 }
159 }
156
160
@@ -202,6 +206,11 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
202 static const QString yPointTag(QLatin1String("@yPoint"));
206 static const QString yPointTag(QLatin1String("@yPoint"));
203 const int labelOffset = 2;
207 const int labelOffset = 2;
204
208
209 if (m_pointLabelsClipping)
210 painter->setClipping(true);
211 else
212 painter->setClipping(false);
213
205 painter->setFont(m_pointLabelsFont);
214 painter->setFont(m_pointLabelsFont);
206 painter->setPen(QPen(m_pointLabelsColor));
215 painter->setPen(QPen(m_pointLabelsColor));
207 QFontMetrics fm(painter->font());
216 QFontMetrics fm(painter->font());
@@ -90,6 +90,7 private:
90 QString m_pointLabelsFormat;
90 QString m_pointLabelsFormat;
91 QFont m_pointLabelsFont;
91 QFont m_pointLabelsFont;
92 QColor m_pointLabelsColor;
92 QColor m_pointLabelsColor;
93 bool m_pointLabelsClipping;
93
94
94 QPointF m_lastMousePos;
95 QPointF m_lastMousePos;
95 bool m_mousePressed;
96 bool m_mousePressed;
@@ -269,13 +269,13 QT_CHARTS_BEGIN_NAMESPACE
269 \property QAreaSeries::pointLabelsVisible
269 \property QAreaSeries::pointLabelsVisible
270 Defines the visibility for data point labels. False by default.
270 Defines the visibility for data point labels. False by default.
271
271
272 \sa QAreaSeries::pointLabelsFormat
272 \sa QAreaSeries::pointLabelsFormat, QAreaSeries::pointLabelsClipping
273 */
273 */
274 /*!
274 /*!
275 \qmlproperty bool AreaSeries::pointLabelsVisible
275 \qmlproperty bool AreaSeries::pointLabelsVisible
276 Defines the visibility for data point labels.
276 Defines the visibility for data point labels.
277
277
278 \sa pointLabelsFormat
278 \sa pointLabelsFormat, pointLabelsClipping
279 */
279 */
280 /*!
280 /*!
281 \fn void QAreaSeries::pointLabelsVisibilityChanged(bool visible)
281 \fn void QAreaSeries::pointLabelsVisibilityChanged(bool visible)
@@ -331,6 +331,29 QT_CHARTS_BEGIN_NAMESPACE
331 */
331 */
332
332
333 /*!
333 /*!
334 \property QAreaSeries::pointLabelsClipping
335 Defines the clipping for data point labels. True by default. The labels on the edge of the plot
336 area are cut when clipping is enabled.
337
338 \sa pointLabelsVisible
339 */
340 /*!
341 \qmlproperty bool AreaSeries::pointLabelsClipping
342 Defines the clipping for data point labels. True by default. The labels on the edge of the plot
343 area are cut when clipping is enabled.
344
345 \sa pointLabelsVisible
346 */
347 /*!
348 \fn void QAreaSeries::pointLabelsClippintChanged(bool clipping)
349 The clipping of the data point labels is changed to \a clipping.
350 */
351 /*!
352 \qmlsignal AreaSeries::onPointLabelsClippingChanged(bool clipping)
353 The clipping of the data point labels is changed to \a clipping.
354 */
355
356 /*!
334 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
357 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
335 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
358 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
336 When series object is added to QChartView or QChart instance ownerships is transferred.
359 When series object is added to QChartView or QChart instance ownerships is transferred.
@@ -556,6 +579,21 QColor QAreaSeries::pointLabelsColor() const
556 return d->m_pointLabelsColor;
579 return d->m_pointLabelsColor;
557 }
580 }
558
581
582 void QAreaSeries::setPointLabelsClipping(bool enabled)
583 {
584 Q_D(QAreaSeries);
585 if (d->m_pointLabelsClipping != enabled) {
586 d->m_pointLabelsClipping = enabled;
587 emit pointLabelsClippingChanged(enabled);
588 }
589 }
590
591 bool QAreaSeries::pointLabelsClipping() const
592 {
593 Q_D(const QAreaSeries);
594 return d->m_pointLabelsClipping;
595 }
596
559 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
597 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
560
598
561 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
599 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
@@ -568,7 +606,8 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lo
568 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
606 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
569 m_pointLabelsVisible(false),
607 m_pointLabelsVisible(false),
570 m_pointLabelsFont(QChartPrivate::defaultFont()),
608 m_pointLabelsFont(QChartPrivate::defaultFont()),
571 m_pointLabelsColor(QChartPrivate::defaultPen().color())
609 m_pointLabelsColor(QChartPrivate::defaultPen().color()),
610 m_pointLabelsClipping(true)
572 {
611 {
573 }
612 }
574
613
@@ -39,6 +39,7 class QT_CHARTS_EXPORT QAreaSeries : public QAbstractSeries
39 Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged)
39 Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged)
40 Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged)
40 Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged)
41 Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged)
41 Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged)
42 Q_PROPERTY(bool pointLabelsClipping READ pointLabelsClipping WRITE setPointLabelsClipping NOTIFY pointLabelsClippingChanged)
42
43
43 public:
44 public:
44 explicit QAreaSeries(QObject *parent = 0);
45 explicit QAreaSeries(QObject *parent = 0);
@@ -80,6 +81,9 public:
80 void setPointLabelsColor(const QColor &color);
81 void setPointLabelsColor(const QColor &color);
81 QColor pointLabelsColor() const;
82 QColor pointLabelsColor() const;
82
83
84 void setPointLabelsClipping(bool enabled = true);
85 bool pointLabelsClipping() const;
86
83 Q_SIGNALS:
87 Q_SIGNALS:
84 void clicked(const QPointF &point);
88 void clicked(const QPointF &point);
85 void hovered(const QPointF &point, bool state);
89 void hovered(const QPointF &point, bool state);
@@ -93,6 +97,7 Q_SIGNALS:
93 void pointLabelsVisibilityChanged(bool visible);
97 void pointLabelsVisibilityChanged(bool visible);
94 void pointLabelsFontChanged(const QFont &font);
98 void pointLabelsFontChanged(const QFont &font);
95 void pointLabelsColorChanged(const QColor &color);
99 void pointLabelsColorChanged(const QColor &color);
100 void pointLabelsClippingChanged(bool clipping);
96
101
97 private:
102 private:
98 Q_DECLARE_PRIVATE(QAreaSeries)
103 Q_DECLARE_PRIVATE(QAreaSeries)
@@ -67,6 +67,8 protected:
67 bool m_pointLabelsVisible;
67 bool m_pointLabelsVisible;
68 QFont m_pointLabelsFont;
68 QFont m_pointLabelsFont;
69 QColor m_pointLabelsColor;
69 QColor m_pointLabelsColor;
70 bool m_pointLabelsClipping;
71
70 private:
72 private:
71 Q_DECLARE_PUBLIC(QAreaSeries);
73 Q_DECLARE_PUBLIC(QAreaSeries);
72 };
74 };
@@ -39,6 +39,7 LineChartItem::LineChartItem(QLineSeries *series, QGraphicsItem *item)
39 m_pointLabelsFormat(series->pointLabelsFormat()),
39 m_pointLabelsFormat(series->pointLabelsFormat()),
40 m_pointLabelsFont(series->pointLabelsFont()),
40 m_pointLabelsFont(series->pointLabelsFont()),
41 m_pointLabelsColor(series->pointLabelsColor()),
41 m_pointLabelsColor(series->pointLabelsColor()),
42 m_pointLabelsClipping(true),
42 m_mousePressed(false)
43 m_mousePressed(false)
43 {
44 {
44 setAcceptHoverEvents(true);
45 setAcceptHoverEvents(true);
@@ -53,6 +54,7 LineChartItem::LineChartItem(QLineSeries *series, QGraphicsItem *item)
53 this, SLOT(handleUpdated()));
54 this, SLOT(handleUpdated()));
54 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
55 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
55 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
56 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
57 QObject::connect(series, SIGNAL(pointLabelsClippingChanged(bool)), this, SLOT(handleUpdated()));
56 handleUpdated();
58 handleUpdated();
57 }
59 }
58
60
@@ -330,6 +332,7 void LineChartItem::handleUpdated()
330 m_pointLabelsVisible = m_series->pointLabelsVisible();
332 m_pointLabelsVisible = m_series->pointLabelsVisible();
331 m_pointLabelsFont = m_series->pointLabelsFont();
333 m_pointLabelsFont = m_series->pointLabelsFont();
332 m_pointLabelsColor = m_series->pointLabelsColor();
334 m_pointLabelsColor = m_series->pointLabelsColor();
335 m_pointLabelsClipping = m_series->pointLabelsClipping();
333 if (doGeometryUpdate)
336 if (doGeometryUpdate)
334 updateGeometry();
337 updateGeometry();
335 update();
338 update();
@@ -382,8 +385,13 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
382
385
383 reversePainter(painter, clipRect);
386 reversePainter(painter, clipRect);
384
387
385 if (m_pointLabelsVisible)
388 if (m_pointLabelsVisible) {
389 if (m_pointLabelsClipping)
390 painter->setClipping(true);
391 else
392 painter->setClipping(false);
386 m_series->d_func()->drawSeriesPointLabels(painter, m_points, m_linePen.width() / 2);
393 m_series->d_func()->drawSeriesPointLabels(painter, m_points, m_linePen.width() / 2);
394 }
387
395
388 painter->restore();
396 painter->restore();
389
397
@@ -84,6 +84,7 private:
84 QString m_pointLabelsFormat;
84 QString m_pointLabelsFormat;
85 QFont m_pointLabelsFont;
85 QFont m_pointLabelsFont;
86 QColor m_pointLabelsColor;
86 QColor m_pointLabelsColor;
87 bool m_pointLabelsClipping;
87
88
88 QPointF m_lastMousePos;
89 QPointF m_lastMousePos;
89 bool m_mousePressed;
90 bool m_mousePressed;
@@ -40,6 +40,7 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
40 m_pointLabelsFormat(series->pointLabelsFormat()),
40 m_pointLabelsFormat(series->pointLabelsFormat()),
41 m_pointLabelsFont(series->pointLabelsFont()),
41 m_pointLabelsFont(series->pointLabelsFont()),
42 m_pointLabelsColor(series->pointLabelsColor()),
42 m_pointLabelsColor(series->pointLabelsColor()),
43 m_pointLabelsClipping(true),
43 m_mousePressed(false)
44 m_mousePressed(false)
44 {
45 {
45 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
46 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
@@ -51,6 +52,7 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
51 this, SLOT(handleUpdated()));
52 this, SLOT(handleUpdated()));
52 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
53 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
53 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
54 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
55 QObject::connect(series, SIGNAL(pointLabelsClippingChanged(bool)), this, SLOT(handleUpdated()));
54
56
55 setZValue(ChartPresenter::ScatterSeriesZValue);
57 setZValue(ChartPresenter::ScatterSeriesZValue);
56 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
58 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
@@ -203,6 +205,10 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
203 painter->setClipRect(clipRect);
205 painter->setClipRect(clipRect);
204
206
205 if (m_pointLabelsVisible) {
207 if (m_pointLabelsVisible) {
208 if (m_pointLabelsClipping)
209 painter->setClipping(true);
210 else
211 painter->setClipping(false);
206 m_series->d_func()->drawSeriesPointLabels(painter, m_points,
212 m_series->d_func()->drawSeriesPointLabels(painter, m_points,
207 m_series->markerSize() / 2
213 m_series->markerSize() / 2
208 + m_series->pen().width());
214 + m_series->pen().width());
@@ -242,6 +248,7 void ScatterChartItem::handleUpdated()
242 m_pointLabelsVisible = m_series->pointLabelsVisible();
248 m_pointLabelsVisible = m_series->pointLabelsVisible();
243 m_pointLabelsFont = m_series->pointLabelsFont();
249 m_pointLabelsFont = m_series->pointLabelsFont();
244 m_pointLabelsColor = m_series->pointLabelsColor();
250 m_pointLabelsColor = m_series->pointLabelsColor();
251 m_pointLabelsClipping = m_series->pointLabelsClipping();
245
252
246 if (recreate) {
253 if (recreate) {
247 deletePoints(count);
254 deletePoints(count);
@@ -86,6 +86,7 private:
86 QString m_pointLabelsFormat;
86 QString m_pointLabelsFormat;
87 QFont m_pointLabelsFont;
87 QFont m_pointLabelsFont;
88 QColor m_pointLabelsColor;
88 QColor m_pointLabelsColor;
89 bool m_pointLabelsClipping;
89
90
90 bool m_mousePressed;
91 bool m_mousePressed;
91 };
92 };
@@ -35,6 +35,7 SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem *item)
35 m_pointLabelsFormat(series->pointLabelsFormat()),
35 m_pointLabelsFormat(series->pointLabelsFormat()),
36 m_pointLabelsFont(series->pointLabelsFont()),
36 m_pointLabelsFont(series->pointLabelsFont()),
37 m_pointLabelsColor(series->pointLabelsColor()),
37 m_pointLabelsColor(series->pointLabelsColor()),
38 m_pointLabelsClipping(true),
38 m_mousePressed(false)
39 m_mousePressed(false)
39 {
40 {
40 setAcceptHoverEvents(true);
41 setAcceptHoverEvents(true);
@@ -49,6 +50,7 SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem *item)
49 this, SLOT(handleUpdated()));
50 this, SLOT(handleUpdated()));
50 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
51 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
51 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
52 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
53 QObject::connect(series, SIGNAL(pointLabelsClippingChanged(bool)), this, SLOT(handleUpdated()));
52 handleUpdated();
54 handleUpdated();
53 }
55 }
54
56
@@ -414,6 +416,7 void SplineChartItem::handleUpdated()
414 m_pointLabelsVisible = m_series->pointLabelsVisible();
416 m_pointLabelsVisible = m_series->pointLabelsVisible();
415 m_pointLabelsFont = m_series->pointLabelsFont();
417 m_pointLabelsFont = m_series->pointLabelsFont();
416 m_pointLabelsColor = m_series->pointLabelsColor();
418 m_pointLabelsColor = m_series->pointLabelsColor();
419 m_pointLabelsClipping = m_series->pointLabelsClipping();
417 update();
420 update();
418 }
421 }
419
422
@@ -460,8 +463,13 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
460
463
461 reversePainter(painter, clipRect);
464 reversePainter(painter, clipRect);
462
465
463 if (m_pointLabelsVisible)
466 if (m_pointLabelsVisible) {
467 if (m_pointLabelsClipping)
468 painter->setClipping(true);
469 else
470 painter->setClipping(false);
464 m_series->d_func()->drawSeriesPointLabels(painter, m_points, m_linePen.width() / 2);
471 m_series->d_func()->drawSeriesPointLabels(painter, m_points, m_linePen.width() / 2);
472 }
465
473
466 painter->restore();
474 painter->restore();
467 }
475 }
@@ -85,6 +85,7 private:
85 QString m_pointLabelsFormat;
85 QString m_pointLabelsFormat;
86 QFont m_pointLabelsFont;
86 QFont m_pointLabelsFont;
87 QColor m_pointLabelsColor;
87 QColor m_pointLabelsColor;
88 bool m_pointLabelsClipping;
88
89
89 QPointF m_lastMousePos;
90 QPointF m_lastMousePos;
90 bool m_mousePressed;
91 bool m_mousePressed;
@@ -162,13 +162,13 QT_CHARTS_BEGIN_NAMESPACE
162 \property QXYSeries::pointLabelsVisible
162 \property QXYSeries::pointLabelsVisible
163 Defines the visibility for data point labels. False by default.
163 Defines the visibility for data point labels. False by default.
164
164
165 \sa pointLabelsFormat
165 \sa pointLabelsFormat, pointLabelsClipping
166 */
166 */
167 /*!
167 /*!
168 \qmlproperty bool XYSeries::pointLabelsVisible
168 \qmlproperty bool XYSeries::pointLabelsVisible
169 Defines the visibility for data point labels.
169 Defines the visibility for data point labels.
170
170
171 \sa pointLabelsFormat
171 \sa pointLabelsFormat, pointLabelsClipping
172 */
172 */
173 /*!
173 /*!
174 \fn void QXYSeries::pointLabelsVisibilityChanged(bool visible)
174 \fn void QXYSeries::pointLabelsVisibilityChanged(bool visible)
@@ -224,6 +224,29 QT_CHARTS_BEGIN_NAMESPACE
224 */
224 */
225
225
226 /*!
226 /*!
227 \property QXYSeries::pointLabelsClipping
228 Defines the clipping for data point labels. True by default. The labels on the edge of the plot
229 area are cut when clipping is enabled.
230
231 \sa pointLabelsVisible
232 */
233 /*!
234 \qmlproperty bool XYSeries::pointLabelsClipping
235 Defines the clipping for data point labels. True by default. The labels on the edge of the plot
236 area are cut when clipping is enabled.
237
238 \sa pointLabelsVisible
239 */
240 /*!
241 \fn void QXYSeries::pointLabelsClippintChanged(bool clipping)
242 The clipping of the data point labels is changed to \a clipping.
243 */
244 /*!
245 \qmlsignal XYSeries::onPointLabelsClippingChanged(bool clipping)
246 The clipping of the data point labels is changed to \a clipping.
247 */
248
249 /*!
227 \fn void QXYSeries::clicked(const QPointF& point)
250 \fn void QXYSeries::clicked(const QPointF& point)
228 \brief Signal is emitted when user clicks the \a point on chart. The \a point is the point
251 \brief Signal is emitted when user clicks the \a point on chart. The \a point is the point
229 where the press was triggered.
252 where the press was triggered.
@@ -779,6 +802,21 QColor QXYSeries::pointLabelsColor() const
779 return d->m_pointLabelsColor;
802 return d->m_pointLabelsColor;
780 }
803 }
781
804
805 void QXYSeries::setPointLabelsClipping(bool enabled)
806 {
807 Q_D(QXYSeries);
808 if (d->m_pointLabelsClipping != enabled) {
809 d->m_pointLabelsClipping = enabled;
810 emit pointLabelsClippingChanged(enabled);
811 }
812 }
813
814 bool QXYSeries::pointLabelsClipping() const
815 {
816 Q_D(const QXYSeries);
817 return d->m_pointLabelsClipping;
818 }
819
782 /*!
820 /*!
783 Stream operator for adding a data \a point to the series.
821 Stream operator for adding a data \a point to the series.
784 \sa append()
822 \sa append()
@@ -812,7 +850,8 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
812 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
850 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
813 m_pointLabelsVisible(false),
851 m_pointLabelsVisible(false),
814 m_pointLabelsFont(QChartPrivate::defaultFont()),
852 m_pointLabelsFont(QChartPrivate::defaultFont()),
815 m_pointLabelsColor(QChartPrivate::defaultPen().color())
853 m_pointLabelsColor(QChartPrivate::defaultPen().color()),
854 m_pointLabelsClipping(true)
816 {
855 {
817 }
856 }
818
857
@@ -42,6 +42,7 class QT_CHARTS_EXPORT QXYSeries : public QAbstractSeries
42 Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged)
42 Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged)
43 Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged)
43 Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged)
44 Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged)
44 Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged)
45 Q_PROPERTY(bool pointLabelsClipping READ pointLabelsClipping WRITE setPointLabelsClipping NOTIFY pointLabelsClippingChanged)
45
46
46 protected:
47 protected:
47 explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = 0);
48 explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = 0);
@@ -93,6 +94,9 public:
93 void setPointLabelsColor(const QColor &color);
94 void setPointLabelsColor(const QColor &color);
94 QColor pointLabelsColor() const;
95 QColor pointLabelsColor() const;
95
96
97 void setPointLabelsClipping(bool enabled = true);
98 bool pointLabelsClipping() const;
99
96 void replace(QList<QPointF> points);
100 void replace(QList<QPointF> points);
97 void replace(QVector<QPointF> points);
101 void replace(QVector<QPointF> points);
98
102
@@ -111,6 +115,7 Q_SIGNALS:
111 void pointLabelsVisibilityChanged(bool visible);
115 void pointLabelsVisibilityChanged(bool visible);
112 void pointLabelsFontChanged(const QFont &font);
116 void pointLabelsFontChanged(const QFont &font);
113 void pointLabelsColorChanged(const QColor &color);
117 void pointLabelsColorChanged(const QColor &color);
118 void pointLabelsClippingChanged(bool clipping);
114 void pointsRemoved(int index, int count);
119 void pointsRemoved(int index, int count);
115
120
116 private:
121 private:
@@ -67,6 +67,7 protected:
67 bool m_pointLabelsVisible;
67 bool m_pointLabelsVisible;
68 QFont m_pointLabelsFont;
68 QFont m_pointLabelsFont;
69 QColor m_pointLabelsColor;
69 QColor m_pointLabelsColor;
70 bool m_pointLabelsClipping;
70
71
71 private:
72 private:
72 Q_DECLARE_PUBLIC(QXYSeries)
73 Q_DECLARE_PUBLIC(QXYSeries)
@@ -2256,6 +2256,7 Module {
2256 Property { name: "pointLabelsVisible"; type: "bool" }
2256 Property { name: "pointLabelsVisible"; type: "bool" }
2257 Property { name: "pointLabelsFont"; type: "QFont" }
2257 Property { name: "pointLabelsFont"; type: "QFont" }
2258 Property { name: "pointLabelsColor"; type: "QColor" }
2258 Property { name: "pointLabelsColor"; type: "QColor" }
2259 Property { name: "pointLabelsClipping"; type: "bool" }
2259 Signal {
2260 Signal {
2260 name: "clicked"
2261 name: "clicked"
2261 Parameter { name: "point"; type: "QPointF" }
2262 Parameter { name: "point"; type: "QPointF" }
@@ -2302,6 +2303,10 Module {
2302 name: "pointLabelsColorChanged"
2303 name: "pointLabelsColorChanged"
2303 Parameter { name: "color"; type: "QColor" }
2304 Parameter { name: "color"; type: "QColor" }
2304 }
2305 }
2306 Signal {
2307 name: "pointLabelsClippingChanged"
2308 Parameter { name: "clipping"; type: "bool" }
2309 }
2305 }
2310 }
2306 Component {
2311 Component {
2307 name: "QtCharts::QBarCategoryAxis"
2312 name: "QtCharts::QBarCategoryAxis"
@@ -2899,6 +2904,7 Module {
2899 Property { name: "pointLabelsVisible"; type: "bool" }
2904 Property { name: "pointLabelsVisible"; type: "bool" }
2900 Property { name: "pointLabelsFont"; type: "QFont" }
2905 Property { name: "pointLabelsFont"; type: "QFont" }
2901 Property { name: "pointLabelsColor"; type: "QColor" }
2906 Property { name: "pointLabelsColor"; type: "QColor" }
2907 Property { name: "pointLabelsClipping"; type: "bool" }
2902 Signal {
2908 Signal {
2903 name: "clicked"
2909 name: "clicked"
2904 Parameter { name: "point"; type: "QPointF" }
2910 Parameter { name: "point"; type: "QPointF" }
@@ -2954,6 +2960,10 Module {
2954 Parameter { name: "color"; type: "QColor" }
2960 Parameter { name: "color"; type: "QColor" }
2955 }
2961 }
2956 Signal {
2962 Signal {
2963 name: "pointLabelsClippingChanged"
2964 Parameter { name: "clipping"; type: "bool" }
2965 }
2966 Signal {
2957 name: "pointsRemoved"
2967 name: "pointsRemoved"
2958 Parameter { name: "index"; type: "int" }
2968 Parameter { name: "index"; type: "int" }
2959 Parameter { name: "count"; type: "int" }
2969 Parameter { name: "count"; type: "int" }
@@ -80,6 +80,7 void tst_QLineSeries::qlineseries()
80 QCOMPARE(series.pointsVisible(), false);
80 QCOMPARE(series.pointsVisible(), false);
81 QCOMPARE(series.pointLabelsVisible(), false);
81 QCOMPARE(series.pointLabelsVisible(), false);
82 QCOMPARE(series.pointLabelsFormat(), QLatin1String("@xPoint, @yPoint"));
82 QCOMPARE(series.pointLabelsFormat(), QLatin1String("@xPoint, @yPoint"));
83 QCOMPARE(series.pointLabelsClipping(), true);
83
84
84 series.append(QList<QPointF>());
85 series.append(QList<QPointF>());
85 series.append(0.0,0.0);
86 series.append(0.0,0.0);
@@ -152,6 +152,24 void tst_QXYSeries::pointLabelsColor()
152 QVERIFY(arguments.at(0).value<QColor>() == defaultColor);
152 QVERIFY(arguments.at(0).value<QColor>() == defaultColor);
153 }
153 }
154
154
155 void tst_QXYSeries::pointLabelsClipping()
156 {
157 QSignalSpy labelsClippingSpy(m_series, SIGNAL(pointLabelsClippingChanged(bool)));
158 QCOMPARE(m_series->pointLabelsClipping(), true);
159
160 m_series->setPointLabelsClipping(false);
161 QCOMPARE(m_series->pointLabelsClipping(), false);
162 TRY_COMPARE(labelsClippingSpy.count(), 1);
163 QList<QVariant> arguments = labelsClippingSpy.takeFirst();
164 QVERIFY(arguments.at(0).toBool() == false);
165
166 m_series->setPointLabelsClipping();
167 QCOMPARE(m_series->pointLabelsClipping(), true);
168 TRY_COMPARE(labelsClippingSpy.count(), 1);
169 arguments = labelsClippingSpy.takeFirst();
170 QVERIFY(arguments.at(0).toBool() == true);
171 }
172
155 void tst_QXYSeries::append_data()
173 void tst_QXYSeries::append_data()
156 {
174 {
157 QTest::addColumn< QList<QPointF> >("points");
175 QTest::addColumn< QList<QPointF> >("points");
@@ -44,6 +44,7 private slots:
44 void pointLabelsVisible();
44 void pointLabelsVisible();
45 void pointLabelsFont();
45 void pointLabelsFont();
46 void pointLabelsColor();
46 void pointLabelsColor();
47 void pointLabelsClipping();
47 void seriesOpacity();
48 void seriesOpacity();
48 void oper_data();
49 void oper_data();
49 void oper();
50 void oper();
@@ -79,6 +79,8 ChartView {
79 + font.family);
79 + font.family);
80 onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: "
80 onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: "
81 + color);
81 + color);
82 onPointLabelsClippingChanged: console.log(name + ".onPointLabelsClippingChanged: "
83 + clipping);
82 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
84 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
83 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
85 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
84 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
86 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
@@ -79,6 +79,10 Flow {
79 onClicked: series.pointLabelsColor = main.nextColor();
79 onClicked: series.pointLabelsColor = main.nextColor();
80 }
80 }
81 Button {
81 Button {
82 text: "point labels clipping"
83 onClicked: series.pointLabelsClipping = !series.pointLabelsClipping;
84 }
85 Button {
82 id: upperButton
86 id: upperButton
83 text: "upper series"
87 text: "upper series"
84 unpressedColor: "#79bd8f"
88 unpressedColor: "#79bd8f"
@@ -60,6 +60,8 ChartView {
60 + font.family);
60 + font.family);
61 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
61 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
62 + color);
62 + color);
63 onPointLabelsClippingChanged: console.log("lineSeries.onPointLabelsClippingChanged: "
64 + clipping);
63 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
65 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
64 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
66 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
65 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
67 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
@@ -96,6 +96,10 Flow {
96 onClicked: series.pointLabelsColor = main.nextColor();
96 onClicked: series.pointLabelsColor = main.nextColor();
97 }
97 }
98 Button {
98 Button {
99 text: "point labels clipping"
100 onClicked: series.pointLabelsClipping = !series.pointLabelsClipping;
101 }
102 Button {
99 text: "append point"
103 text: "append point"
100 onClicked: series.append(series.count - 1, series.count - 1);
104 onClicked: series.append(series.count - 1, series.count - 1);
101 }
105 }
@@ -57,6 +57,8 ChartView {
57 + font.family);
57 + font.family);
58 onPointLabelsColorChanged: console.log("scatterSeries.onPointLabelsColorChanged: "
58 onPointLabelsColorChanged: console.log("scatterSeries.onPointLabelsColorChanged: "
59 + color);
59 + color);
60 onPointLabelsClippingChanged: console.log("scatterSeries.onPointLabelsClippingChanged: "
61 + clipping);
60 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
62 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
61 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
63 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
62 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
64 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
@@ -69,6 +69,10 Flow {
69 onClicked: series.pointLabelsVisible = !series.pointLabelsVisible;
69 onClicked: series.pointLabelsVisible = !series.pointLabelsVisible;
70 }
70 }
71 Button {
71 Button {
72 text: "point labels clipping"
73 onClicked: series.pointLabelsClipping = !series.pointLabelsClipping;
74 }
75 Button {
72 text: "point labels format"
76 text: "point labels format"
73 onClicked: {
77 onClicked: {
74 if (series.pointLabelsFormat === "@xPoint, @yPoint")
78 if (series.pointLabelsFormat === "@xPoint, @yPoint")
@@ -91,6 +95,10 Flow {
91 onClicked: series.pointLabelsColor = main.nextColor();
95 onClicked: series.pointLabelsColor = main.nextColor();
92 }
96 }
93 Button {
97 Button {
98 text: "point labels clipping"
99 onClicked: series.pointLabelsClipping = !series.pointLabelsClipping;
100 }
101 Button {
94 text: "append point"
102 text: "append point"
95 onClicked: series.append(series.count - 1, series.count - 1);
103 onClicked: series.append(series.count - 1, series.count - 1);
96 }
104 }
@@ -59,6 +59,8 ChartView {
59 + font.family);
59 + font.family);
60 onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: "
60 onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: "
61 + color);
61 + color);
62 onPointLabelsClippingChanged: console.log("splineSeries.onPointLabelsClippingChanged: "
63 + clipping);
62 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
64 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
63 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
65 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
64 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
66 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
General Comments 0
You need to be logged in to leave comments. Login now