##// END OF EJS Templates
Added possibility to show series value...
Titta Heikkala -
r2689:db3eff743f50
parent child
Show More
@@ -1561,9 +1561,20 Module {
1561 1561 prototype: "QtCommercialChart::QAbstractSeries"
1562 1562 exports: ["QtCommercial.Chart/AbstractBarSeries 1.0"]
1563 1563 exportMetaObjectRevisions: [0]
1564 Enum {
1565 name: "LabelsPosition"
1566 values: {
1567 "LabelsCenter": 0,
1568 "LabelsInsideEnd": 1,
1569 "LabelsInsideBase": 2,
1570 "LabelsOutsideEnd": 3
1571 }
1572 }
1564 1573 Property { name: "barWidth"; type: "double" }
1565 1574 Property { name: "count"; type: "int"; isReadonly: true }
1566 1575 Property { name: "labelsVisible"; type: "bool" }
1576 Property { name: "labelsFormat"; type: "string" }
1577 Property { name: "labelsPosition"; type: "LabelsPosition" }
1567 1578 Signal {
1568 1579 name: "clicked"
1569 1580 Parameter { name: "index"; type: "int" }
@@ -1581,6 +1592,14 Module {
1581 1592 Parameter { name: "barset"; type: "QBarSet"; isPointer: true }
1582 1593 }
1583 1594 Signal {
1595 name: "labelsFormatChanged"
1596 Parameter { name: "format"; type: "string" }
1597 }
1598 Signal {
1599 name: "labelsPositionChanged"
1600 Parameter { name: "position"; type: "QAbstractBarSeries::LabelsPosition" }
1601 }
1602 Signal {
1584 1603 name: "barsetsAdded"
1585 1604 Parameter { name: "sets"; type: "QList<QBarSet*>" }
1586 1605 }
@@ -1623,6 +1642,10 Module {
1623 1642 Property { name: "lowerSeries"; type: "QLineSeries"; isReadonly: true; isPointer: true }
1624 1643 Property { name: "color"; type: "QColor" }
1625 1644 Property { name: "borderColor"; type: "QColor" }
1645 Property { name: "pointLabelsFormat"; type: "string" }
1646 Property { name: "pointLabelsVisible"; type: "bool" }
1647 Property { name: "pointLabelsFont"; type: "QFont" }
1648 Property { name: "pointLabelsColor"; type: "QColor" }
1626 1649 Signal {
1627 1650 name: "clicked"
1628 1651 Parameter { name: "point"; type: "QPointF" }
@@ -1641,6 +1664,22 Module {
1641 1664 name: "borderColorChanged"
1642 1665 Parameter { name: "color"; type: "QColor" }
1643 1666 }
1667 Signal {
1668 name: "pointLabelsFormatChanged"
1669 Parameter { name: "format"; type: "string" }
1670 }
1671 Signal {
1672 name: "pointLabelsVisibilityChanged"
1673 Parameter { name: "visible"; type: "bool" }
1674 }
1675 Signal {
1676 name: "pointLabelsFontChanged"
1677 Parameter { name: "font"; type: "QFont" }
1678 }
1679 Signal {
1680 name: "pointLabelsColorChanged"
1681 Parameter { name: "color"; type: "QColor" }
1682 }
1644 1683 }
1645 1684 Component {
1646 1685 name: "QtCommercialChart::QBarCategoryAxis"
@@ -2140,6 +2179,10 Module {
2140 2179 exportMetaObjectRevisions: [0]
2141 2180 Property { name: "pointsVisible"; type: "bool" }
2142 2181 Property { name: "color"; type: "QColor" }
2182 Property { name: "pointLabelsFormat"; type: "string" }
2183 Property { name: "pointLabelsVisible"; type: "bool" }
2184 Property { name: "pointLabelsFont"; type: "QFont" }
2185 Property { name: "pointLabelsColor"; type: "QColor" }
2143 2186 Signal {
2144 2187 name: "clicked"
2145 2188 Parameter { name: "point"; type: "QPointF" }
@@ -2166,5 +2209,21 Module {
2166 2209 Parameter { name: "color"; type: "QColor" }
2167 2210 }
2168 2211 Signal { name: "pointsReplaced" }
2212 Signal {
2213 name: "pointLabelsFormatChanged"
2214 Parameter { name: "format"; type: "string" }
2215 }
2216 Signal {
2217 name: "pointLabelsVisibilityChanged"
2218 Parameter { name: "visible"; type: "bool" }
2219 }
2220 Signal {
2221 name: "pointLabelsFontChanged"
2222 Parameter { name: "font"; type: "QFont" }
2223 }
2224 Signal {
2225 name: "pointLabelsColorChanged"
2226 Parameter { name: "color"; type: "QColor" }
2227 }
2169 2228 }
2170 2229 }
@@ -36,7 +36,11 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
36 36 m_series(areaSeries),
37 37 m_upper(0),
38 38 m_lower(0),
39 m_pointsVisible(false)
39 m_pointsVisible(false),
40 m_pointLabelsFormat(areaSeries->pointLabelsFormat()),
41 m_pointLabelsVisible(false),
42 m_pointLabelsFont(areaSeries->pointLabelsFont()),
43 m_pointLabelsColor(areaSeries->pointLabelsColor())
40 44 {
41 45 setAcceptHoverEvents(true);
42 46 setZValue(ChartPresenter::LineChartZValue);
@@ -50,6 +54,14 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
50 54 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
51 55 QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF)));
52 56 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool)));
57 QObject::connect(areaSeries, SIGNAL(pointLabelsFormatChanged(QString)),
58 this, SLOT(handleUpdated()));
59 QObject::connect(areaSeries, SIGNAL(pointLabelsVisibilityChanged(bool)),
60 this, SLOT(handleUpdated()));
61 QObject::connect(areaSeries, SIGNAL(pointLabelsFontChanged(QFont)),
62 this, SLOT(handleUpdated()));
63 QObject::connect(areaSeries, SIGNAL(pointLabelsColorChanged(QColor)),
64 this, SLOT(handleUpdated()));
53 65
54 66 handleUpdated();
55 67 }
@@ -131,6 +143,10 void AreaChartItem::handleUpdated()
131 143 m_pointPen = m_series->pen();
132 144 m_pointPen.setWidthF(2 * m_pointPen.width());
133 145 setOpacity(m_series->opacity());
146 m_pointLabelsFormat = m_series->pointLabelsFormat();
147 m_pointLabelsVisible = m_series->pointLabelsVisible();
148 m_pointLabelsFont = m_series->pointLabelsFont();
149 m_pointLabelsColor = m_series->pointLabelsColor();
134 150 update();
135 151 }
136 152
@@ -170,6 +186,50 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
170 186 if (m_lower)
171 187 painter->drawPoints(m_lower->geometryPoints());
172 188 }
189
190 // Draw series point label
191 if (m_pointLabelsVisible) {
192 static const QString xPointTag(QLatin1String("@xPoint"));
193 static const QString yPointTag(QLatin1String("@yPoint"));
194 const int labelOffset = 2;
195
196 painter->setFont(m_pointLabelsFont);
197 painter->setPen(QPen(m_pointLabelsColor));
198 QFontMetrics fm(painter->font());
199
200 QString pointLabel = m_pointLabelsFormat;
201
202 if (m_series->upperSeries()) {
203 for (int i(0); i < m_series->upperSeries()->count(); i++) {
204 pointLabel.replace(xPointTag, QString::number(m_series->upperSeries()->at(i).x()));
205 pointLabel.replace(yPointTag, QString::number(m_series->upperSeries()->at(i).y()));
206
207 // Position text in relation to the point
208 int pointLabelWidth = fm.width(pointLabel);
209 QPointF position(m_upper->geometryPoints().at(i));
210 position.setX(position.x() - pointLabelWidth / 2);
211 position.setY(position.y() - m_series->upperSeries()->pen().width() / 2 - labelOffset);
212
213 painter->drawText(position, pointLabel);
214 }
215 }
216
217 if (m_series->lowerSeries()) {
218 for (int i(0); i < m_series->lowerSeries()->count(); i++) {
219 pointLabel.replace(xPointTag, QString::number(m_series->lowerSeries()->at(i).x()));
220 pointLabel.replace(yPointTag, QString::number(m_series->lowerSeries()->at(i).y()));
221
222 // Position text in relation to the point
223 int pointLabelWidth = fm.width(pointLabel);
224 QPointF position(m_lower->geometryPoints().at(i));
225 position.setX(position.x() - pointLabelWidth / 2);
226 position.setY(position.y() - m_series->lowerSeries()->pen().width() / 2 - labelOffset);
227
228 painter->drawText(position, pointLabel);
229 }
230 }
231 }
232
173 233 painter->restore();
174 234 }
175 235
@@ -83,6 +83,11 private:
83 83 QBrush m_brush;
84 84 bool m_pointsVisible;
85 85
86 bool m_pointLabelsVisible;
87 QString m_pointLabelsFormat;
88 QFont m_pointLabelsFont;
89 QColor m_pointLabelsColor;
90
86 91 };
87 92
88 93 class AreaBoundItem : public LineChartItem
@@ -182,6 +182,110 QTCOMMERCIALCHART_BEGIN_NAMESPACE
182 182 */
183 183
184 184 /*!
185 \property QAreaSeries::pointLabelsFormat
186 The \a format used for showing labels with series points.
187
188 QAreaSeries supports the following format tags:
189 \table
190 \row
191 \li @xPoint \li The x value of the data point
192 \row
193 \li @yPoint \li The y value of the data point
194 \endtable
195
196 For example, the following usage of the format tags would produce labels that have the data
197 point (x, y) shown inside brackets separated by a comma:
198 \code
199 series->setPointLabelsFormat("(@xPoint, @yPoint)");
200 \endcode
201
202 By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot
203 area, labels on the edge of the plot area are cut. If the points are close to each other the
204 labels may overlap.
205
206 \sa QAreaSeries::pointLabelsVisible, QAreaSeries::pointLabelsFont, QAreaSeries::pointLabelsColor
207 */
208 /*!
209 \qmlproperty string AreaSeries::pointLabelsFormat
210 The \a format used for showing labels with series points.
211
212 \sa QAreaSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor
213 */
214 /*!
215 \fn void QAreaSeries::pointLabelsFormatChanged(const QString &format)
216 Signal is emitted when the \a format of data point labels is changed.
217 */
218 /*!
219 \qmlsignal AreaSeries::onPointLabelsFormatChanged(string format)
220 Signal is emitted when the \a format of data point labels is changed.
221 */
222
223 /*!
224 \property QAreaSeries::pointLabelsVisible
225 Defines the visibility for data point labels. False by default.
226
227 \sa QAreaSeries::pointLabelsFormat
228 */
229 /*!
230 \qmlproperty bool AreaSeries::pointLabelsVisible
231 Defines the visibility for data point labels.
232
233 \sa pointLabelsFormat
234 */
235 /*!
236 \fn void QAreaSeries::pointLabelsVisibilityChanged(bool visible)
237 The visibility of the data point labels is changed to \a visible.
238 */
239 /*!
240 \qmlsignal AreaSeries::onPointLabelsVisibilityChanged(bool visible)
241 The visibility of the data point labels is changed to \a visible.
242 */
243
244 /*!
245 \property QAreaSeries::pointLabelsFont
246 Defines the font used for data point labels.
247
248 \sa QAreaSeries::pointLabelsFormat
249 */
250 /*!
251 \qmlproperty font AreaSeries::pointLabelsFont
252 Defines the font used for data point labels.
253
254 \sa pointLabelsFormat
255 */
256 /*!
257 \fn void QAreaSeries::pointLabelsFontChanged(const QFont &font);
258 The font used for data point labels is changed to \a font.
259 */
260 /*!
261 \qmlsignal AreaSeries::onPointLabelsFontChanged(Font font)
262 The font used for data point labels is changed to \a font.
263 */
264
265 /*!
266 \property QAreaSeries::pointLabelsColor
267 Defines the color used for data point labels. By default, the color is the color of the brush
268 defined in theme for labels.
269
270 \sa QAreaSeries::pointLabelsFormat
271 */
272 /*!
273 \qmlproperty font AreaSeries::pointLabelsColor
274 Defines the color used for data point labels. By default, the color is the color of the brush
275 defined in theme for labels.
276
277 \sa pointLabelsFormat
278 */
279 /*!
280 \fn void QAreaSeries::pointLabelsColorChanged(const QColor &color);
281 The color used for data point labels is changed to \a color.
282 */
283 /*!
284 \qmlsignal AreaSeries::onPointLabelsColorChanged(Color color)
285 The color used for data point labels is changed to \a color.
286 */
287
288 /*!
185 289 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
186 290 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
187 291 When series object is added to QChartView or QChart instance ownerships is transferred.
@@ -344,6 +448,69 bool QAreaSeries::pointsVisible() const
344 448 return d->m_pointsVisible;
345 449 }
346 450
451 void QAreaSeries::setPointLabelsFormat(const QString &format)
452 {
453 Q_D(QAreaSeries);
454 if (d->m_pointLabelsFormat != format) {
455 d->m_pointLabelsFormat = format;
456 emit pointLabelsFormatChanged(format);
457 }
458 }
459
460 QString QAreaSeries::pointLabelsFormat() const
461 {
462 Q_D(const QAreaSeries);
463 return d->m_pointLabelsFormat;
464 }
465
466 void QAreaSeries::setPointLabelsVisible(bool visible)
467 {
468 Q_D(QAreaSeries);
469 if (d->m_pointLabelsVisible != visible) {
470 d->m_pointLabelsVisible = visible;
471 emit pointLabelsVisibilityChanged(visible);
472 }
473 }
474
475 bool QAreaSeries::pointLabelsVisible() const
476 {
477 Q_D(const QAreaSeries);
478 return d->m_pointLabelsVisible;
479 }
480
481 void QAreaSeries::setPointLabelsFont(const QFont &font)
482 {
483 Q_D(QAreaSeries);
484 if (d->m_pointLabelsFont != font) {
485 d->m_pointLabelsFont = font;
486 emit pointLabelsFontChanged(font);
487 }
488 }
489
490 QFont QAreaSeries::pointLabelsFont() const
491 {
492 Q_D(const QAreaSeries);
493 return d->m_pointLabelsFont;
494 }
495
496 void QAreaSeries::setPointLabelsColor(const QColor &color)
497 {
498 Q_D(QAreaSeries);
499 if (d->m_pointLabelsColor != color) {
500 d->m_pointLabelsColor = color;
501 emit pointLabelsColorChanged(color);
502 }
503 }
504
505 QColor QAreaSeries::pointLabelsColor() const
506 {
507 Q_D(const QAreaSeries);
508 if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color())
509 return QPen().color();
510 else
511 return d->m_pointLabelsColor;
512 }
513
347 514 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
348 515
349 516 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
@@ -352,7 +519,11 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lo
352 519 m_pen(QChartPrivate::defaultPen()),
353 520 m_upperSeries(upperSeries),
354 521 m_lowerSeries(lowerSeries),
355 m_pointsVisible(false)
522 m_pointsVisible(false),
523 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
524 m_pointLabelsVisible(false),
525 m_pointLabelsFont(QChartPrivate::defaultFont()),
526 m_pointLabelsColor(QChartPrivate::defaultPen().color())
356 527 {
357 528 }
358 529
@@ -470,6 +641,11 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forc
470 641 QBrush brush(colors.at(index % colors.size()));
471 642 q->setBrush(brush);
472 643 }
644
645 if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
646 QColor color = theme->labelBrush().color();
647 q->setPointLabelsColor(color);
648 }
473 649 }
474 650
475 651
@@ -37,6 +37,14 class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QAbstractSeries
37 37 Q_PROPERTY(QLineSeries *lowerSeries READ lowerSeries)
38 38 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
39 39 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
40 Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat
41 NOTIFY pointLabelsFormatChanged)
42 Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible
43 NOTIFY pointLabelsVisibilityChanged)
44 Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont
45 NOTIFY pointLabelsFontChanged)
46 Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor
47 NOTIFY pointLabelsColorChanged)
40 48
41 49 public:
42 50 explicit QAreaSeries(QObject *parent = 0);
@@ -66,12 +74,28 public:
66 74 void setPointsVisible(bool visible = true);
67 75 bool pointsVisible() const;
68 76
77 void setPointLabelsFormat(const QString &format);
78 QString pointLabelsFormat() const;
79
80 void setPointLabelsVisible(bool visible = true);
81 bool pointLabelsVisible() const;
82
83 void setPointLabelsFont(const QFont &font);
84 QFont pointLabelsFont() const;
85
86 void setPointLabelsColor(const QColor &color);
87 QColor pointLabelsColor() const;
88
69 89 Q_SIGNALS:
70 90 void clicked(const QPointF &point);
71 91 void hovered(const QPointF &point, bool state);
72 92 void selected();
73 93 void colorChanged(QColor color);
74 94 void borderColorChanged(QColor color);
95 void pointLabelsFormatChanged(const QString &format);
96 void pointLabelsVisibilityChanged(bool visible);
97 void pointLabelsFontChanged(const QFont &font);
98 void pointLabelsColorChanged(const QColor &color);
75 99
76 100 private:
77 101 Q_DECLARE_PRIVATE(QAreaSeries)
@@ -63,6 +63,10 protected:
63 63 QLineSeries *m_upperSeries;
64 64 QLineSeries *m_lowerSeries;
65 65 bool m_pointsVisible;
66 QString m_pointLabelsFormat;
67 bool m_pointLabelsVisible;
68 QFont m_pointLabelsFont;
69 QColor m_pointLabelsColor;
66 70 private:
67 71 Q_DECLARE_PUBLIC(QAreaSeries);
68 72 };
@@ -47,6 +47,10 AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphics
47 47 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
48 48 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
49 49 connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged()));
50 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(handleUpdatedBars()));
51 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels()));
52 connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)),
53 this, SLOT(handleLabelsPositionChanged()));
50 54 setZValue(ChartPresenter::BarSeriesZValue);
51 55 handleDataStructureChanged();
52 56 handleVisibleChanged();
@@ -99,12 +103,10 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
99 103
100 104 m_layout = layout;
101 105
102 for (int i = 0; i < m_bars.count(); i++) {
106 for (int i = 0; i < m_bars.count(); i++)
103 107 m_bars.at(i)->setRect(layout.at(i));
104 QGraphicsTextItem *label = m_labels.at(i);
105 label->setPos(layout.at(i).center() - label->boundingRect().center());
106 108
107 }
109 positionLabels();
108 110 }
109 111 //handlers
110 112
@@ -203,6 +205,7 void AbstractBarChartItem::handleUpdatedBars()
203 205 int categoryCount = m_series->d_func()->categoryCount();
204 206 int setCount = m_series->count();
205 207 int itemIndex(0);
208 static const QString valueTag(QLatin1String("@value"));
206 209
207 210 for (int category = 0; category < categoryCount; category++) {
208 211 for (int set = 0; set < setCount; set++) {
@@ -213,7 +216,14 void AbstractBarChartItem::handleUpdatedBars()
213 216 bar->update();
214 217
215 218 QGraphicsTextItem *label = m_labels.at(itemIndex);
216 label->setHtml(QString("%1").arg(barSet->value(category)));
219 QString valueLabel;
220 if (m_series->labelsFormat().isEmpty()) {
221 valueLabel = QString("%1").arg(barSet->value(category));
222 } else {
223 valueLabel = m_series->labelsFormat();
224 valueLabel.replace(valueTag, QString::number(barSet->value(category)));
225 }
226 label->setHtml(valueLabel);
217 227 label->setFont(barSet->m_labelFont);
218 228 label->setDefaultTextColor(barSet->m_labelBrush.color());
219 229 label->update();
@@ -223,6 +233,32 void AbstractBarChartItem::handleUpdatedBars()
223 233 }
224 234 }
225 235
236 void AbstractBarChartItem::handleLabelsPositionChanged()
237 {
238 positionLabels();
239 }
240
241 void AbstractBarChartItem::positionLabels()
242 {
243 for (int i = 0; i < m_layout.count(); i++) {
244 QGraphicsTextItem *label = m_labels.at(i);
245 qreal xPos = 0;
246 qreal yPos = m_layout.at(i).center().y() - label->boundingRect().center().y();
247
248 if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter)
249 xPos = m_layout.at(i).center().x() - label->boundingRect().center().x();
250 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd)
251 xPos = m_layout.at(i).right() - label->boundingRect().width();
252 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase)
253 xPos = m_layout.at(i).left();
254 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd)
255 xPos = m_layout.at(i).right();
256
257 label->setPos(xPos, yPos);
258 label->setZValue(zValue() + 1);
259 }
260 }
261
226 262 #include "moc_abstractbarchartitem_p.cpp"
227 263
228 264 QTCOMMERCIALCHART_END_NAMESPACE
@@ -70,6 +70,8 public Q_SLOTS:
70 70 void handleVisibleChanged();
71 71 void handleOpacityChanged();
72 72 virtual void handleUpdatedBars();
73 void handleLabelsPositionChanged();
74 virtual void positionLabels();
73 75
74 76 protected:
75 77
@@ -97,6 +97,7 void HorizontalPercentBarChartItem::handleUpdatedBars()
97 97 int categoryCount = m_series->d_func()->categoryCount();
98 98 int setCount = m_series->count();
99 99 int itemIndex(0);
100 static const QString valueTag(QLatin1String("@value"));
100 101
101 102 for (int category = 0; category < categoryCount; category++) {
102 103 for (int set = 0; set < setCount; set++) {
@@ -111,7 +112,14 void HorizontalPercentBarChartItem::handleUpdatedBars()
111 112 QString vString(QString::number(p));
112 113 vString.truncate(3);
113 114 vString.append("%");
114 label->setHtml(vString);
115 QString valueLabel;
116 if (m_series->labelsFormat().isEmpty()) {
117 valueLabel = vString;
118 } else {
119 valueLabel = m_series->labelsFormat();
120 valueLabel.replace(valueTag, QString::number(barSet->value(category)));
121 }
122 label->setHtml(valueLabel);
115 123 label->setFont(barSet->m_labelFont);
116 124 label->setDefaultTextColor(barSet->m_labelBrush.color());
117 125 label->update();
@@ -129,6 +129,75 QTCOMMERCIALCHART_BEGIN_NAMESPACE
129 129 */
130 130
131 131 /*!
132 \property QAbstractBarSeries::labelsFormat
133 The \a format used for showing labels in series.
134
135 QAbstractBarSeries supports the following format tag:
136 \table
137 \row
138 \li @value \li The value of the bar
139 \endtable
140
141 For example, the following usage of the format tags would produce labels that show the value
142 followed by unit ('u'):
143 \code
144 series->setLabelsFormat("@value u");
145 \endcode
146
147 By default, the labels shows the value of the bar. For percent bar series '%' is added after
148 the value. The labels are shown on the plot area, labels on the edge of the plot area are cut.
149 If the bars are close to each other the labels may overlap.
150
151 \sa QAbstractBarSeries::labelsVisible, QAbstractBarSeries::labelsPosition
152 */
153 /*!
154 \qmlproperty string AbstractBarSeries::labelsFormat
155 The format used for showing labels in series.
156
157 \sa QAbstractBarSeries::labelsFormat, labelsVisible, labelsPosition
158 */
159 /*!
160 \fn void QAbstractBarSeries::labelsFormatChanged(const QString &format)
161 Signal is emitted when the \a format of data value labels is changed.
162 */
163 /*!
164 \qmlsignal XYSeries::onLabelsFormatChanged(string format)
165 Signal is emitted when the \a format of data value labels is changed.
166 */
167
168 /*!
169 \enum QAbstractBarSeries::LabelsPosition
170
171 This enum describes the position of the data value labels.
172
173 \value LabelsCenter Label is in the center of the bar.
174 \value LabelsInsideEnd Label is inside the bar at the high end of it.
175 \value LabelsInsideBase Label is inside the bar at the low end of it.
176 \value LabelsOutsideEnd Label is outside the bar at the high end of it.
177 */
178
179 /*!
180 \property QAbstractBarSeries::labelsPosition
181 Defines the \a position of value labels.
182
183 \sa QAbstractBarSeries::labelsVisible, QAbstractBarSeries::labelsFormat
184 */
185 /*!
186 \qmlproperty string AbstractBarSeries::labelsPosition
187 Defines the \a position of value labels.
188
189 \sa labelsVisible, labelsFormat
190 */
191 /*!
192 \fn void QAbstractBarSeries::labelsPositionChanged(QAbstractBarSeries::LabelsPosition position)
193 Signal is emitted when the \a position of value labels is changed.
194 */
195 /*!
196 \qmlsignal AbstractBarSeries::onLabelsPositionChanged(LabelsPosition position)
197 Signal is emitted when the \a position of value labels is changed.
198 */
199
200 /*!
132 201 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
133 202 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
134 203 Clicked bar inside set is indexed by \a index
@@ -421,6 +490,36 bool QAbstractBarSeries::isLabelsVisible() const
421 490 return d->m_labelsVisible;
422 491 }
423 492
493 void QAbstractBarSeries::setLabelsFormat(const QString &format)
494 {
495 Q_D(QAbstractBarSeries);
496 if (d->m_labelsFormat != format) {
497 d->m_labelsFormat = format;
498 emit labelsFormatChanged(format);
499 }
500 }
501
502 QString QAbstractBarSeries::labelsFormat() const
503 {
504 Q_D(const QAbstractBarSeries);
505 return d->m_labelsFormat;
506 }
507
508 void QAbstractBarSeries::setLabelsPosition(QAbstractBarSeries::LabelsPosition position)
509 {
510 Q_D(QAbstractBarSeries);
511 if (d->m_labelsPosition != position) {
512 d->m_labelsPosition = position;
513 emit labelsPositionChanged(position);
514 }
515 }
516
517 QAbstractBarSeries::LabelsPosition QAbstractBarSeries::labelsPosition() const
518 {
519 Q_D(const QAbstractBarSeries);
520 return d->m_labelsPosition;
521 }
522
424 523 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
425 524
426 525 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
@@ -428,7 +527,9 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
428 527 m_barWidth(0.5), // Default value is 50% of category width
429 528 m_labelsVisible(false),
430 529 m_visible(true),
431 m_blockBarUpdate(false)
530 m_blockBarUpdate(false),
531 m_labelsFormat(),
532 m_labelsPosition(QAbstractBarSeries::LabelsCenter)
432 533 {
433 534 }
434 535
@@ -36,6 +36,19 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
36 36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39 Q_PROPERTY(QString labelsFormat READ labelsFormat WRITE setLabelsFormat
40 NOTIFY labelsFormatChanged)
41 Q_PROPERTY(LabelsPosition labelsPosition READ labelsPosition
42 WRITE setLabelsPosition NOTIFY labelsPositionChanged)
43 Q_ENUMS(LabelsPosition)
44
45 public:
46 enum LabelsPosition {
47 LabelsCenter = 0,
48 LabelsInsideEnd,
49 LabelsInsideBase,
50 LabelsOutsideEnd
51 };
39 52
40 53 public:
41 54 virtual ~QAbstractBarSeries();
@@ -55,6 +68,12 public:
55 68 void setLabelsVisible(bool visible = true);
56 69 bool isLabelsVisible() const;
57 70
71 void setLabelsFormat(const QString &format);
72 QString labelsFormat() const;
73
74 void setLabelsPosition(QAbstractBarSeries::LabelsPosition position);
75 QAbstractBarSeries::LabelsPosition labelsPosition() const;
76
58 77 protected:
59 78 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent = 0);
60 79
@@ -64,6 +83,8 Q_SIGNALS:
64 83 void hovered(bool status, int index, QBarSet *barset);
65 84 void countChanged();
66 85 void labelsVisibleChanged();
86 void labelsFormatChanged(const QString &format);
87 void labelsPositionChanged(QAbstractBarSeries::LabelsPosition position);
67 88
68 89 void barsetsAdded(QList<QBarSet *> sets);
69 90 void barsetsRemoved(QList<QBarSet *> sets);
@@ -104,6 +104,8 protected:
104 104 bool m_labelsVisible;
105 105 bool m_visible;
106 106 bool m_blockBarUpdate;
107 QString m_labelsFormat;
108 QAbstractBarSeries::LabelsPosition m_labelsPosition;
107 109
108 110 private:
109 111 Q_DECLARE_PUBLIC(QAbstractBarSeries)
@@ -29,6 +29,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
30 30 AbstractBarChartItem(series, item)
31 31 {
32 connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)),
33 this, SLOT(handleLabelsPositionChanged()));
34 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels()));
32 35 }
33 36
34 37 void BarChartItem::initializeLayout()
@@ -86,9 +89,36 QVector<QRectF> BarChartItem::calculateLayout()
86 89 layout.append(rect.normalized());
87 90 }
88 91 }
92
89 93 return layout;
90 94 }
91 95
96 void BarChartItem::handleLabelsPositionChanged()
97 {
98 positionLabels();
99 }
100
101 void BarChartItem::positionLabels()
102 {
103 for (int i = 0; i < m_layout.count(); i++) {
104 QGraphicsTextItem *label = m_labels.at(i);
105 qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x();
106 qreal yPos = 0;
107
108 if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter)
109 yPos = m_layout.at(i).center().y() - label->boundingRect().center().y();
110 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd)
111 yPos = m_layout.at(i).top();
112 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase)
113 yPos = m_layout.at(i).bottom() - label->boundingRect().height();
114 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd)
115 yPos = m_layout.at(i).top() - label->boundingRect().height();
116
117 label->setPos(xPos, yPos);
118 label->setZValue(zValue() + 1);
119 }
120 }
121
92 122 #include "moc_barchartitem_p.cpp"
93 123
94 124 QTCOMMERCIALCHART_END_NAMESPACE
@@ -43,6 +43,10 class BarChartItem : public AbstractBarChartItem
43 43 public:
44 44 BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
45 45
46 private slots:
47 void handleLabelsPositionChanged();
48 void positionLabels();
49
46 50 private:
47 51 virtual QVector<QRectF> calculateLayout();
48 52 void initializeLayout();
@@ -29,6 +29,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
30 30 AbstractBarChartItem(series, item)
31 31 {
32 connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)),
33 this, SLOT(handleLabelsPositionChanged()));
34 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels()));
32 35 }
33 36
34 37 void PercentBarChartItem::initializeLayout()
@@ -99,6 +102,7 void PercentBarChartItem::handleUpdatedBars()
99 102 int categoryCount = m_series->d_func()->categoryCount();
100 103 int setCount = m_series->count();
101 104 int itemIndex(0);
105 static const QString valueTag(QLatin1String("@value"));
102 106
103 107 for (int category = 0; category < categoryCount; category++) {
104 108 for (int set = 0; set < setCount; set++) {
@@ -113,7 +117,14 void PercentBarChartItem::handleUpdatedBars()
113 117 QString vString(QString::number(p));
114 118 vString.truncate(3);
115 119 vString.append("%");
116 label->setHtml(vString);
120 QString valueLabel;
121 if (m_series->labelsFormat().isEmpty()) {
122 valueLabel = vString;
123 } else {
124 valueLabel = m_series->labelsFormat();
125 valueLabel.replace(valueTag, QString::number(barSet->value(category)));
126 }
127 label->setHtml(valueLabel);
117 128 label->setFont(barSet->m_labelFont);
118 129 label->setDefaultTextColor(barSet->m_labelBrush.color());
119 130 label->update();
@@ -122,6 +133,32 void PercentBarChartItem::handleUpdatedBars()
122 133 }
123 134 }
124 135
136 void PercentBarChartItem::handleLabelsPositionChanged()
137 {
138 positionLabels();
139 }
140
141 void PercentBarChartItem::positionLabels()
142 {
143 for (int i = 0; i < m_layout.count(); i++) {
144 QGraphicsTextItem *label = m_labels.at(i);
145 qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x();
146 qreal yPos = 0;
147
148 if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter)
149 yPos = m_layout.at(i).center().y() - label->boundingRect().center().y();
150 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd)
151 yPos = m_layout.at(i).top();
152 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase)
153 yPos = m_layout.at(i).bottom() - label->boundingRect().height();
154 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd)
155 yPos = m_layout.at(i).top() - label->boundingRect().height();
156
157 label->setPos(xPos, yPos);
158 label->setZValue(zValue() + 1);
159 }
160 }
161
125 162 #include "moc_percentbarchartitem_p.cpp"
126 163
127 164 QTCOMMERCIALCHART_END_NAMESPACE
@@ -45,6 +45,10 public:
45 45 PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0);
46 46 void handleUpdatedBars();
47 47
48 private slots:
49 void handleLabelsPositionChanged();
50 void positionLabels();
51
48 52 private:
49 53 virtual QVector<QRectF> calculateLayout();
50 54 void initializeLayout();
@@ -29,6 +29,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) :
30 30 AbstractBarChartItem(series, item)
31 31 {
32 connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)),
33 this, SLOT(handleLabelsPositionChanged()));
34 connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels()));
32 35 }
33 36
34 37 void StackedBarChartItem::initializeLayout()
@@ -102,6 +105,32 QVector<QRectF> StackedBarChartItem::calculateLayout()
102 105 return layout;
103 106 }
104 107
108 void StackedBarChartItem::handleLabelsPositionChanged()
109 {
110 positionLabels();
111 }
112
113 void StackedBarChartItem::positionLabels()
114 {
115 for (int i = 0; i < m_layout.count(); i++) {
116 QGraphicsTextItem *label = m_labels.at(i);
117 qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x();
118 qreal yPos = 0;
119
120 if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter)
121 yPos = m_layout.at(i).center().y() - label->boundingRect().center().y();
122 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd)
123 yPos = m_layout.at(i).top();
124 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase)
125 yPos = m_layout.at(i).bottom() - label->boundingRect().height();
126 else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd)
127 yPos = m_layout.at(i).top() - label->boundingRect().height();
128
129 label->setPos(xPos, yPos);
130 label->setZValue(zValue() + 1);
131 }
132 }
133
105 134 #include "moc_stackedbarchartitem_p.cpp"
106 135
107 136 QTCOMMERCIALCHART_END_NAMESPACE
@@ -43,6 +43,10 class StackedBarChartItem : public AbstractBarChartItem
43 43 public:
44 44 StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item =0);
45 45
46 private slots:
47 void handleLabelsPositionChanged();
48 void positionLabels();
49
46 50 private:
47 51 virtual QVector<QRectF> calculateLayout();
48 52 void initializeLayout();
@@ -23,6 +23,8
23 23 #include "qlineseries_p.h"
24 24 #include "chartpresenter_p.h"
25 25 #include "polardomain_p.h"
26 #include "chartthememanager_p.h"
27 #include "charttheme_p.h"
26 28 #include <QPainter>
27 29 #include <QGraphicsSceneMouseEvent>
28 30
@@ -34,13 +36,23 LineChartItem::LineChartItem(QLineSeries *series, QGraphicsItem *item)
34 36 : XYChart(series,item),
35 37 m_series(series),
36 38 m_pointsVisible(false),
37 m_chartType(QChart::ChartTypeUndefined)
39 m_chartType(QChart::ChartTypeUndefined),
40 m_pointLabelsFormat(series->pointLabelsFormat()),
41 m_pointLabelsVisible(false),
42 m_pointLabelsFont(series->pointLabelsFont()),
43 m_pointLabelsColor(series->pointLabelsColor())
38 44 {
39 45 setAcceptHoverEvents(true);
40 46 setZValue(ChartPresenter::LineChartZValue);
41 47 QObject::connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
42 48 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
43 49 QObject::connect(series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
50 QObject::connect(series, SIGNAL(pointLabelsFormatChanged(QString)),
51 this, SLOT(handleUpdated()));
52 QObject::connect(series, SIGNAL(pointLabelsVisibilityChanged(bool)),
53 this, SLOT(handleUpdated()));
54 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
55 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
44 56 handleUpdated();
45 57 }
46 58
@@ -300,7 +312,7 void LineChartItem::updateGeometry()
300 312
301 313 void LineChartItem::handleUpdated()
302 314 {
303 // If points visiblity has changed, a geometry update is needed.
315 // If points visibility has changed, a geometry update is needed.
304 316 // Also, if pen changes when points are visible, geometry update is needed.
305 317 bool doGeometryUpdate =
306 318 (m_pointsVisible != m_series->pointsVisible())
@@ -309,6 +321,10 void LineChartItem::handleUpdated()
309 321 setOpacity(m_series->opacity());
310 322 m_pointsVisible = m_series->pointsVisible();
311 323 m_linePen = m_series->pen();
324 m_pointLabelsFormat = m_series->pointLabelsFormat();
325 m_pointLabelsVisible = m_series->pointLabelsVisible();
326 m_pointLabelsFont = m_series->pointLabelsFont();
327 m_pointLabelsColor = m_series->pointLabelsColor();
312 328 if (doGeometryUpdate)
313 329 updateGeometry();
314 330 update();
@@ -357,7 +373,11 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
357 373 }
358 374 }
359 375
376 if (m_pointLabelsVisible)
377 m_series->d_func()->drawSeriesPointLabels(painter, m_points);
378
360 379 painter->restore();
380
361 381 }
362 382
363 383 void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -79,6 +79,11 private:
79 79 QPen m_linePen;
80 80 bool m_pointsVisible;
81 81 QChart::ChartType m_chartType;
82
83 bool m_pointLabelsVisible;
84 QString m_pointLabelsFormat;
85 QFont m_pointLabelsFont;
86 QColor m_pointLabelsColor;
82 87 };
83 88
84 89 QTCOMMERCIALCHART_END_NAMESPACE
@@ -160,6 +160,11 void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forc
160 160 pen.setWidthF(2);
161 161 q->setPen(pen);
162 162 }
163
164 if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
165 QColor color = theme->labelBrush().color();
166 q->setPointLabelsColor(color);
167 }
163 168 }
164 169
165 170 #include "moc_qlineseries.cpp"
@@ -306,6 +306,11 void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool f
306 306 QBrush brush(colors.at(index % colors.size()));
307 307 q->setBrush(brush);
308 308 }
309
310 if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
311 QColor color = theme->labelBrush().color();
312 q->setPointLabelsColor(color);
313 }
309 314 }
310 315
311 316 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
@@ -37,11 +37,21 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
37 37 m_items(this),
38 38 m_visible(true),
39 39 m_shape(QScatterSeries::MarkerShapeRectangle),
40 m_size(15)
40 m_size(15),
41 m_pointLabelsFormat(series->pointLabelsFormat()),
42 m_pointLabelsVisible(false),
43 m_pointLabelsFont(series->pointLabelsFont()),
44 m_pointLabelsColor(series->pointLabelsColor())
41 45 {
42 46 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
43 47 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
44 48 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
49 QObject::connect(series, SIGNAL(pointLabelsFormatChanged(QString)),
50 this, SLOT(handleUpdated()));
51 QObject::connect(series, SIGNAL(pointLabelsVisibilityChanged(bool)),
52 this, SLOT(handleUpdated()));
53 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
54 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
45 55
46 56 setZValue(ChartPresenter::ScatterSeriesZValue);
47 57 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
@@ -160,9 +170,18 void ScatterChartItem::updateGeometry()
160 170
161 171 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
162 172 {
163 Q_UNUSED(painter)
164 173 Q_UNUSED(option)
165 174 Q_UNUSED(widget)
175
176 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
177
178 painter->save();
179 painter->setClipRect(clipRect);
180
181 if (m_pointLabelsVisible)
182 m_series->d_func()->drawSeriesPointLabels(painter, m_points);
183
184 painter->restore();
166 185 }
167 186
168 187 void ScatterChartItem::setPen(const QPen &pen)
@@ -192,6 +211,10 void ScatterChartItem::handleUpdated()
192 211 m_size = m_series->markerSize();
193 212 m_shape = m_series->markerShape();
194 213 setOpacity(m_series->opacity());
214 m_pointLabelsFormat = m_series->pointLabelsFormat();
215 m_pointLabelsVisible = m_series->pointLabelsVisible();
216 m_pointLabelsFont = m_series->pointLabelsFont();
217 m_pointLabelsColor = m_series->pointLabelsColor();
195 218
196 219 if (recreate) {
197 220 deletePoints(count);
@@ -75,6 +75,11 private:
75 75 int m_size;
76 76 QRectF m_rect;
77 77 QMap<QGraphicsItem *, QPointF> m_markerMap;
78
79 bool m_pointLabelsVisible;
80 QString m_pointLabelsFormat;
81 QFont m_pointLabelsFont;
82 QColor m_pointLabelsColor;
78 83 };
79 84
80 85 class CircleMarker: public QGraphicsEllipseItem
@@ -137,6 +137,11 void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool fo
137 137 pen.setWidthF(2);
138 138 q->setPen(pen);
139 139 }
140
141 if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
142 QColor color = theme->labelBrush().color();
143 q->setPointLabelsColor(color);
144 }
140 145 }
141 146
142 147 void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
@@ -32,13 +32,23 SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem *item)
32 32 : XYChart(series,item),
33 33 m_series(series),
34 34 m_pointsVisible(false),
35 m_animation(0)
35 m_animation(0),
36 m_pointLabelsFormat(series->pointLabelsFormat()),
37 m_pointLabelsVisible(false),
38 m_pointLabelsFont(series->pointLabelsFont()),
39 m_pointLabelsColor(series->pointLabelsColor())
36 40 {
37 41 setAcceptHoverEvents(true);
38 42 setZValue(ChartPresenter::SplineChartZValue);
39 43 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
40 44 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
41 45 QObject::connect(series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
46 QObject::connect(series, SIGNAL(pointLabelsFormatChanged(QString)),
47 this, SLOT(handleUpdated()));
48 QObject::connect(series, SIGNAL(pointLabelsVisibilityChanged(bool)),
49 this, SLOT(handleUpdated()));
50 QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
51 QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
42 52 handleUpdated();
43 53 }
44 54
@@ -400,6 +410,10 void SplineChartItem::handleUpdated()
400 410 m_linePen = m_series->pen();
401 411 m_pointPen = m_series->pen();
402 412 m_pointPen.setWidthF(2 * m_pointPen.width());
413 m_pointLabelsFormat = m_series->pointLabelsFormat();
414 m_pointLabelsVisible = m_series->pointLabelsVisible();
415 m_pointLabelsFont = m_series->pointLabelsFont();
416 m_pointLabelsColor = m_series->pointLabelsColor();
403 417 update();
404 418 }
405 419
@@ -442,6 +456,9 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
442 456 painter->drawPoints(geometryPoints());
443 457 }
444 458
459 if (m_pointLabelsVisible)
460 m_series->d_func()->drawSeriesPointLabels(painter, m_points);
461
445 462 painter->restore();
446 463 }
447 464
@@ -81,6 +81,11 private:
81 81 QVector<QPointF> m_visiblePoints;
82 82 SplineAnimation *m_animation;
83 83
84 bool m_pointLabelsVisible;
85 QString m_pointLabelsFormat;
86 QFont m_pointLabelsFont;
87 QColor m_pointLabelsColor;
88
84 89 friend class SplineAnimation;
85 90 };
86 91
@@ -26,6 +26,7
26 26 #include "qxylegendmarker.h"
27 27 #include "charthelpers_p.h"
28 28 #include "qchart_p.h"
29 #include <QPainter>
29 30
30 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 32
@@ -124,6 +125,110 QTCOMMERCIALCHART_BEGIN_NAMESPACE
124 125 */
125 126
126 127 /*!
128 \property QXYSeries::pointLabelsFormat
129 The \a format used for showing labels with series points.
130
131 QXYSeries supports the following format tags:
132 \table
133 \row
134 \li @xPoint \li The x value of the data point
135 \row
136 \li @yPoint \li The y value of the data point
137 \endtable
138
139 For example, the following usage of the format tags would produce labels that have the data
140 point (x, y) shown inside brackets separated by a comma:
141 \code
142 series->setPointLabelsFormat("(@xPoint, @yPoint)");
143 \endcode
144
145 By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot
146 area, labels on the edge of the plot area are cut. If the points are close to each other the
147 labels may overlap.
148
149 \sa QXYSeries::pointLabelsVisible, QXYSeries::pointLabelsFont, QXYSeries::pointLabelsColor
150 */
151 /*!
152 \qmlproperty string XYSeries::pointLabelsFormat
153 The \a format used for showing labels with series points.
154
155 \sa QXYSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor
156 */
157 /*!
158 \fn void QXYSeries::pointLabelsFormatChanged(const QString &format)
159 Signal is emitted when the \a format of data point labels is changed.
160 */
161 /*!
162 \qmlsignal XYSeries::onPointLabelsFormatChanged(string format)
163 Signal is emitted when the \a format of data point labels is changed.
164 */
165
166 /*!
167 \property QXYSeries::pointLabelsVisible
168 Defines the visibility for data point labels. False by default.
169
170 \sa QXYSeries::pointLabelsFormat
171 */
172 /*!
173 \qmlproperty bool XYSeries::pointLabelsVisible
174 Defines the visibility for data point labels.
175
176 \sa pointLabelsFormat
177 */
178 /*!
179 \fn void QXYSeries::pointLabelsVisibilityChanged(bool visible)
180 The visibility of the data point labels is changed to \a visible.
181 */
182 /*!
183 \qmlsignal XYSeries::onPointLabelsVisibilityChanged(bool visible)
184 The visibility of the data point labels is changed to \a visible.
185 */
186
187 /*!
188 \property QXYSeries::pointLabelsFont
189 Defines the font used for data point labels.
190
191 \sa QXYSeries::pointLabelsFormat
192 */
193 /*!
194 \qmlproperty font XYSeries::pointLabelsFont
195 Defines the font used for data point labels.
196
197 \sa pointLabelsFormat
198 */
199 /*!
200 \fn void QXYSeries::pointLabelsFontChanged(const QFont &font);
201 The font used for data point labels is changed to \a font.
202 */
203 /*!
204 \qmlsignal XYSeries::onPointLabelsFontChanged(Font font)
205 The font used for data point labels is changed to \a font.
206 */
207
208 /*!
209 \property QXYSeries::pointLabelsColor
210 Defines the color used for data point labels. By default, the color is the color of the brush
211 defined in theme for labels.
212
213 \sa QXYSeries::pointLabelsFormat
214 */
215 /*!
216 \qmlproperty font XYSeries::pointLabelsColor
217 Defines the color used for data point labels. By default, the color is the color of the brush
218 defined in theme for labels.
219
220 \sa pointLabelsFormat
221 */
222 /*!
223 \fn void QXYSeries::pointLabelsColorChanged(const QColor &color);
224 The color used for data point labels is changed to \a color.
225 */
226 /*!
227 \qmlsignal XYSeries::onPointLabelsColorChanged(Color color)
228 The color used for data point labels is changed to \a color.
229 */
230
231 /*!
127 232 \fn void QXYSeries::clicked(const QPointF& point)
128 233 \brief Signal is emitted when user clicks the \a point on chart.
129 234 */
@@ -499,6 +604,68 bool QXYSeries::pointsVisible() const
499 604 return d->m_pointsVisible;
500 605 }
501 606
607 void QXYSeries::setPointLabelsFormat(const QString &format)
608 {
609 Q_D(QXYSeries);
610 if (d->m_pointLabelsFormat != format) {
611 d->m_pointLabelsFormat = format;
612 emit pointLabelsFormatChanged(format);
613 }
614 }
615
616 QString QXYSeries::pointLabelsFormat() const
617 {
618 Q_D(const QXYSeries);
619 return d->m_pointLabelsFormat;
620 }
621
622 void QXYSeries::setPointLabelsVisible(bool visible)
623 {
624 Q_D(QXYSeries);
625 if (d->m_pointLabelsVisible != visible) {
626 d->m_pointLabelsVisible = visible;
627 emit pointLabelsVisibilityChanged(visible);
628 }
629 }
630
631 bool QXYSeries::pointLabelsVisible() const
632 {
633 Q_D(const QXYSeries);
634 return d->m_pointLabelsVisible;
635 }
636
637 void QXYSeries::setPointLabelsFont(const QFont &font)
638 {
639 Q_D(QXYSeries);
640 if (d->m_pointLabelsFont != font) {
641 d->m_pointLabelsFont = font;
642 emit pointLabelsFontChanged(font);
643 }
644 }
645
646 QFont QXYSeries::pointLabelsFont() const
647 {
648 Q_D(const QXYSeries);
649 return d->m_pointLabelsFont;
650 }
651
652 void QXYSeries::setPointLabelsColor(const QColor &color)
653 {
654 Q_D(QXYSeries);
655 if (d->m_pointLabelsColor != color) {
656 d->m_pointLabelsColor = color;
657 emit pointLabelsColorChanged(color);
658 }
659 }
660
661 QColor QXYSeries::pointLabelsColor() const
662 {
663 Q_D(const QXYSeries);
664 if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color())
665 return QPen().color();
666 else
667 return d->m_pointLabelsColor;
668 }
502 669
503 670 /*!
504 671 Stream operator for adding a data \a point to the series.
@@ -529,7 +696,11 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
529 696 : QAbstractSeriesPrivate(q),
530 697 m_pen(QChartPrivate::defaultPen()),
531 698 m_brush(QChartPrivate::defaultBrush()),
532 m_pointsVisible(false)
699 m_pointsVisible(false),
700 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
701 m_pointLabelsVisible(false),
702 m_pointLabelsFont(QChartPrivate::defaultFont()),
703 m_pointLabelsColor(QChartPrivate::defaultPen().color())
533 704 {
534 705 }
535 706
@@ -601,6 +772,31 void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::Animation
601 772 QAbstractSeriesPrivate::initializeAnimations(options);
602 773 }
603 774
775 void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVector<QPointF> &points)
776 {
777 static const QString xPointTag(QLatin1String("@xPoint"));
778 static const QString yPointTag(QLatin1String("@yPoint"));
779 const int labelOffset = 2;
780
781 painter->setFont(m_pointLabelsFont);
782 painter->setPen(QPen(m_pointLabelsColor));
783 QFontMetrics fm(painter->font());
784
785 for (int i(0); i < m_points.size(); i++) {
786 QString pointLabel = m_pointLabelsFormat;
787 pointLabel.replace(xPointTag, QString::number(m_points.at(i).x()));
788 pointLabel.replace(yPointTag, QString::number(m_points.at(i).y()));
789
790 // Position text in relation to the point
791 int pointLabelWidth = fm.width(pointLabel);
792 QPointF position(points.at(i));
793 position.setX(position.x() - pointLabelWidth / 2);
794 position.setY(position.y() - painter->pen().width() / 2 - labelOffset);
795
796 painter->drawText(position, pointLabel);
797 }
798 }
799
604 800 #include "moc_qxyseries.cpp"
605 801 #include "moc_qxyseries_p.cpp"
606 802
@@ -38,6 +38,14 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries
38 38 Q_OBJECT
39 39 Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible)
40 40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
41 Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat
42 NOTIFY pointLabelsFormatChanged)
43 Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible
44 NOTIFY pointLabelsVisibilityChanged)
45 Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont
46 NOTIFY pointLabelsFontChanged)
47 Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor
48 NOTIFY pointLabelsColorChanged)
41 49
42 50 protected:
43 51 explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = 0);
@@ -76,6 +84,18 public:
76 84 void setPointsVisible(bool visible = true);
77 85 bool pointsVisible() const;
78 86
87 void setPointLabelsFormat(const QString &format);
88 QString pointLabelsFormat() const;
89
90 void setPointLabelsVisible(bool visible = true);
91 bool pointLabelsVisible() const;
92
93 void setPointLabelsFont(const QFont &font);
94 QFont pointLabelsFont() const;
95
96 void setPointLabelsColor(const QColor &color);
97 QColor pointLabelsColor() const;
98
79 99 void replace(QList<QPointF> points);
80 100
81 101 Q_SIGNALS:
@@ -86,6 +106,10 Q_SIGNALS:
86 106 void pointAdded(int index);
87 107 void colorChanged(QColor color);
88 108 void pointsReplaced();
109 void pointLabelsFormatChanged(const QString &format);
110 void pointLabelsVisibilityChanged(bool visible);
111 void pointLabelsFontChanged(const QFont &font);
112 void pointLabelsColorChanged(const QColor &color);
89 113
90 114 private:
91 115 Q_DECLARE_PRIVATE(QXYSeries)
@@ -53,6 +53,8 public:
53 53 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
54 54 QAbstractAxis* createDefaultAxis(Qt::Orientation orientation) const;
55 55
56 void drawSeriesPointLabels(QPainter *painter, const QVector<QPointF> &points);
57
56 58 Q_SIGNALS:
57 59 void updated();
58 60
@@ -61,6 +63,10 protected:
61 63 QPen m_pen;
62 64 QBrush m_brush;
63 65 bool m_pointsVisible;
66 QString m_pointLabelsFormat;
67 bool m_pointLabelsVisible;
68 QFont m_pointLabelsFont;
69 QColor m_pointLabelsColor;
64 70
65 71 private:
66 72 Q_DECLARE_PUBLIC(QXYSeries)
@@ -29,6 +29,7 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 Q_DECLARE_METATYPE(QBarSet*)
31 31 Q_DECLARE_METATYPE(QList<QBarSet*>)
32 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
32 33
33 34 class tst_QBarSeries : public QObject
34 35 {
@@ -59,6 +60,8 private slots:
59 60 void barSets();
60 61 void setLabelsVisible_data();
61 62 void setLabelsVisible();
63 void setLabelsFormat();
64 void setLabelsPosition();
62 65 void opacity();
63 66 void mouseclicked_data();
64 67 void mouseclicked();
@@ -79,6 +82,7 void tst_QBarSeries::initTestCase()
79 82 {
80 83 qRegisterMetaType<QBarSet*>("QBarSet*");
81 84 qRegisterMetaType<QList<QBarSet*> >("QList<QBarSet*>");
85 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
82 86 }
83 87
84 88 void tst_QBarSeries::cleanupTestCase()
@@ -343,6 +347,60 void tst_QBarSeries::setLabelsVisible()
343 347 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
344 348 }
345 349
350 void tst_QBarSeries::setLabelsFormat()
351 {
352 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
353 QCOMPARE(m_barseries->labelsFormat(), QString());
354
355 QString format("(@value)");
356 m_barseries->setLabelsFormat(format);
357 TRY_COMPARE(labelsFormatSpy.count(), 1);
358 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
359 QVERIFY(arguments.at(0).toString() == format);
360 QCOMPARE(m_barseries->labelsFormat(), format);
361
362 m_barseries->setLabelsFormat(QString());
363 TRY_COMPARE(labelsFormatSpy.count(), 1);
364 arguments = labelsFormatSpy.takeFirst();
365 QVERIFY(arguments.at(0).toString() == QString());
366 QCOMPARE(m_barseries->labelsFormat(), QString());
367 }
368
369 void tst_QBarSeries::setLabelsPosition()
370 {
371 QSignalSpy labelsPositionSpy(m_barseries,
372 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
373 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsCenter);
374
375 m_barseries->setLabelsPosition(QBarSeries::LabelsInsideEnd);
376 TRY_COMPARE(labelsPositionSpy.count(), 1);
377 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
378 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
379 == QBarSeries::LabelsInsideEnd);
380 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsInsideEnd);
381
382 m_barseries->setLabelsPosition(QBarSeries::LabelsInsideBase);
383 TRY_COMPARE(labelsPositionSpy.count(), 1);
384 arguments = labelsPositionSpy.takeFirst();
385 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
386 == QBarSeries::LabelsInsideBase);
387 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsInsideBase);
388
389 m_barseries->setLabelsPosition(QBarSeries::LabelsOutsideEnd);
390 TRY_COMPARE(labelsPositionSpy.count(), 1);
391 arguments = labelsPositionSpy.takeFirst();
392 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
393 == QBarSeries::LabelsOutsideEnd);
394 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsOutsideEnd);
395
396 m_barseries->setLabelsPosition(QBarSeries::LabelsCenter);
397 TRY_COMPARE(labelsPositionSpy.count(), 1);
398 arguments = labelsPositionSpy.takeFirst();
399 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
400 == QBarSeries::LabelsCenter);
401 QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsCenter);
402 }
403
346 404 void tst_QBarSeries::opacity()
347 405 {
348 406 QSignalSpy opacitySpy(m_barseries, SIGNAL(opacityChanged()));
@@ -28,6 +28,7
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 32
32 33 class tst_QHorizontalBarSeries : public QObject
33 34 {
@@ -56,6 +57,8 private slots:
56 57 void barSets();
57 58 void setLabelsVisible_data();
58 59 void setLabelsVisible();
60 void setLabelsFormat();
61 void setLabelsPosition();
59 62 void mouseclicked_data();
60 63 void mouseclicked();
61 64 void mousehovered_data();
@@ -73,6 +76,7 private:
73 76 void tst_QHorizontalBarSeries::initTestCase()
74 77 {
75 78 qRegisterMetaType<QBarSet*>("QBarSet*");
79 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
76 80 }
77 81
78 82 void tst_QHorizontalBarSeries::cleanupTestCase()
@@ -308,6 +312,60 void tst_QHorizontalBarSeries::setLabelsVisible()
308 312 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
309 313 }
310 314
315 void tst_QHorizontalBarSeries::setLabelsFormat()
316 {
317 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
318 QCOMPARE(m_barseries->labelsFormat(), QString());
319
320 QString format("(@value)");
321 m_barseries->setLabelsFormat(format);
322 TRY_COMPARE(labelsFormatSpy.count(), 1);
323 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
324 QVERIFY(arguments.at(0).toString() == format);
325 QCOMPARE(m_barseries->labelsFormat(), format);
326
327 m_barseries->setLabelsFormat(QString());
328 TRY_COMPARE(labelsFormatSpy.count(), 1);
329 arguments = labelsFormatSpy.takeFirst();
330 QVERIFY(arguments.at(0).toString() == QString());
331 QCOMPARE(m_barseries->labelsFormat(), QString());
332 }
333
334 void tst_QHorizontalBarSeries::setLabelsPosition()
335 {
336 QSignalSpy labelsPositionSpy(m_barseries,
337 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
338 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsCenter);
339
340 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsInsideEnd);
341 TRY_COMPARE(labelsPositionSpy.count(), 1);
342 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
343 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
344 == QHorizontalBarSeries::LabelsInsideEnd);
345 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsInsideEnd);
346
347 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsInsideBase);
348 TRY_COMPARE(labelsPositionSpy.count(), 1);
349 arguments = labelsPositionSpy.takeFirst();
350 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
351 == QHorizontalBarSeries::LabelsInsideBase);
352 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsInsideBase);
353
354 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsOutsideEnd);
355 TRY_COMPARE(labelsPositionSpy.count(), 1);
356 arguments = labelsPositionSpy.takeFirst();
357 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
358 == QHorizontalBarSeries::LabelsOutsideEnd);
359 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsOutsideEnd);
360
361 m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsCenter);
362 TRY_COMPARE(labelsPositionSpy.count(), 1);
363 arguments = labelsPositionSpy.takeFirst();
364 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
365 == QHorizontalBarSeries::LabelsCenter);
366 QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsCenter);
367 }
368
311 369 void tst_QHorizontalBarSeries::mouseclicked_data()
312 370 {
313 371
@@ -28,6 +28,7
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 32
32 33 class tst_QHorizontalPercentBarSeries : public QObject
33 34 {
@@ -44,6 +45,8 private slots:
44 45 void qhorizontalpercentbarseries();
45 46 void type_data();
46 47 void type();
48 void setLabelsFormat();
49 void setLabelsPosition();
47 50 void mouseclicked_data();
48 51 void mouseclicked();
49 52 void mousehovered_data();
@@ -56,6 +59,7 private:
56 59 void tst_QHorizontalPercentBarSeries::initTestCase()
57 60 {
58 61 qRegisterMetaType<QBarSet*>("QBarSet*");
62 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
59 63 }
60 64
61 65 void tst_QHorizontalPercentBarSeries::cleanupTestCase()
@@ -93,6 +97,60 void tst_QHorizontalPercentBarSeries::type()
93 97 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalPercentBar);
94 98 }
95 99
100 void tst_QHorizontalPercentBarSeries::setLabelsFormat()
101 {
102 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
103 QCOMPARE(m_barseries->labelsFormat(), QString());
104
105 QString format("(@value)");
106 m_barseries->setLabelsFormat(format);
107 TRY_COMPARE(labelsFormatSpy.count(), 1);
108 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
109 QVERIFY(arguments.at(0).toString() == format);
110 QCOMPARE(m_barseries->labelsFormat(), format);
111
112 m_barseries->setLabelsFormat(QString());
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
114 arguments = labelsFormatSpy.takeFirst();
115 QVERIFY(arguments.at(0).toString() == QString());
116 QCOMPARE(m_barseries->labelsFormat(), QString());
117 }
118
119 void tst_QHorizontalPercentBarSeries::setLabelsPosition()
120 {
121 QSignalSpy labelsPositionSpy(m_barseries,
122 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
123 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsCenter);
124
125 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsInsideEnd);
126 TRY_COMPARE(labelsPositionSpy.count(), 1);
127 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
128 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
129 == QHorizontalPercentBarSeries::LabelsInsideEnd);
130 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsInsideEnd);
131
132 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsInsideBase);
133 TRY_COMPARE(labelsPositionSpy.count(), 1);
134 arguments = labelsPositionSpy.takeFirst();
135 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
136 == QHorizontalPercentBarSeries::LabelsInsideBase);
137 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsInsideBase);
138
139 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsOutsideEnd);
140 TRY_COMPARE(labelsPositionSpy.count(), 1);
141 arguments = labelsPositionSpy.takeFirst();
142 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
143 == QHorizontalPercentBarSeries::LabelsOutsideEnd);
144 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsOutsideEnd);
145
146 m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsCenter);
147 TRY_COMPARE(labelsPositionSpy.count(), 1);
148 arguments = labelsPositionSpy.takeFirst();
149 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
150 == QHorizontalPercentBarSeries::LabelsCenter);
151 QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsCenter);
152 }
153
96 154 void tst_QHorizontalPercentBarSeries::mouseclicked_data()
97 155 {
98 156
@@ -28,6 +28,7
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 32
32 33 class tst_QHorizontalStackedBarSeries : public QObject
33 34 {
@@ -44,6 +45,8 private slots:
44 45 void qhorizontalstackedbarseries();
45 46 void type_data();
46 47 void type();
48 void setLabelsFormat();
49 void setLabelsPosition();
47 50 void mouseclicked_data();
48 51 void mouseclicked();
49 52 void mousehovered_data();
@@ -56,6 +59,7 private:
56 59 void tst_QHorizontalStackedBarSeries::initTestCase()
57 60 {
58 61 qRegisterMetaType<QBarSet*>("QBarSet*");
62 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
59 63 }
60 64
61 65 void tst_QHorizontalStackedBarSeries::cleanupTestCase()
@@ -93,6 +97,60 void tst_QHorizontalStackedBarSeries::type()
93 97 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalStackedBar);
94 98 }
95 99
100 void tst_QHorizontalStackedBarSeries::setLabelsFormat()
101 {
102 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
103 QCOMPARE(m_barseries->labelsFormat(), QString());
104
105 QString format("(@value)");
106 m_barseries->setLabelsFormat(format);
107 TRY_COMPARE(labelsFormatSpy.count(), 1);
108 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
109 QVERIFY(arguments.at(0).toString() == format);
110 QCOMPARE(m_barseries->labelsFormat(), format);
111
112 m_barseries->setLabelsFormat(QString());
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
114 arguments = labelsFormatSpy.takeFirst();
115 QVERIFY(arguments.at(0).toString() == QString());
116 QCOMPARE(m_barseries->labelsFormat(), QString());
117 }
118
119 void tst_QHorizontalStackedBarSeries::setLabelsPosition()
120 {
121 QSignalSpy labelsPositionSpy(m_barseries,
122 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
123 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsCenter);
124
125 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsInsideEnd);
126 TRY_COMPARE(labelsPositionSpy.count(), 1);
127 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
128 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
129 == QHorizontalStackedBarSeries::LabelsInsideEnd);
130 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsInsideEnd);
131
132 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsInsideBase);
133 TRY_COMPARE(labelsPositionSpy.count(), 1);
134 arguments = labelsPositionSpy.takeFirst();
135 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
136 == QHorizontalStackedBarSeries::LabelsInsideBase);
137 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsInsideBase);
138
139 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsOutsideEnd);
140 TRY_COMPARE(labelsPositionSpy.count(), 1);
141 arguments = labelsPositionSpy.takeFirst();
142 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
143 == QHorizontalStackedBarSeries::LabelsOutsideEnd);
144 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsOutsideEnd);
145
146 m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsCenter);
147 TRY_COMPARE(labelsPositionSpy.count(), 1);
148 arguments = labelsPositionSpy.takeFirst();
149 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
150 == QHorizontalStackedBarSeries::LabelsCenter);
151 QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsCenter);
152 }
153
96 154 void tst_QHorizontalStackedBarSeries::mouseclicked_data()
97 155 {
98 156
@@ -75,6 +75,8 void tst_QLineSeries::qlineseries()
75 75 QCOMPARE(series.points(), QList<QPointF>());
76 76 QCOMPARE(series.pen(), QPen());
77 77 QCOMPARE(series.pointsVisible(), false);
78 QCOMPARE(series.pointLabelsVisible(), false);
79 QCOMPARE(series.pointLabelsFormat(), QLatin1String("@xPoint, @yPoint"));
78 80
79 81 series.append(QList<QPointF>());
80 82 series.append(0.0,0.0);
@@ -91,6 +93,9 void tst_QLineSeries::qlineseries()
91 93 series.setPen(QPen());
92 94 series.setPointsVisible(false);
93 95
96 series.setPointLabelsVisible(false);
97 series.setPointLabelsFormat(QString());
98
94 99 m_chart->addSeries(&series);
95 100 m_view->show();
96 101 QTest::qWaitForWindowShown(m_view);
@@ -34,6 +34,7 Rectangle {
34 34 function test_properties() {
35 35 compare(barSeries.barWidth, 0.5);
36 36 compare(barSeries.labelsVisible, false);
37 compare(barSeries.labelsPosition, BarSeries.LabelsCenter);
37 38 }
38 39
39 40 function test_setproperties() {
@@ -92,6 +93,12 Rectangle {
92 93 compare(barSeries.count, 0);
93 94 }
94 95
96 function test_signals() {
97 labelsPositionSpy.clear();
98 barSeries.labelsPosition = BarSeries.LabelsOutsideEnd;
99 compare(labelsPositionSpy.count, 1, "onLabelsPositionChanged")
100 }
101
95 102 function test_remove() {
96 103 var setCount = 5;
97 104 var valueCount = 50;
@@ -136,6 +143,11 Rectangle {
136 143 target: barSeries
137 144 signalName: "barsetsRemoved"
138 145 }
146 SignalSpy {
147 id: labelsPositionSpy
148 target: barSeries
149 signalName: "labelsPositionChanged"
150 }
139 151 }
140 152
141 153 StackedBarSeries {
@@ -28,6 +28,7
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 32
32 33 class tst_QPercentBarSeries : public QObject
33 34 {
@@ -44,6 +45,8 private slots:
44 45 void qpercentbarseries();
45 46 void type_data();
46 47 void type();
48 void setLabelsFormat();
49 void setLabelsPosition();
47 50 void mouseclicked_data();
48 51 void mouseclicked();
49 52 void mousehovered_data();
@@ -56,6 +59,7 private:
56 59 void tst_QPercentBarSeries::initTestCase()
57 60 {
58 61 qRegisterMetaType<QBarSet*>("QBarSet*");
62 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
59 63 }
60 64
61 65 void tst_QPercentBarSeries::cleanupTestCase()
@@ -98,6 +102,60 void tst_QPercentBarSeries::mouseclicked_data()
98 102
99 103 }
100 104
105 void tst_QPercentBarSeries::setLabelsFormat()
106 {
107 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
108 QCOMPARE(m_barseries->labelsFormat(), QString());
109
110 QString format("(@value)");
111 m_barseries->setLabelsFormat(format);
112 TRY_COMPARE(labelsFormatSpy.count(), 1);
113 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
114 QVERIFY(arguments.at(0).toString() == format);
115 QCOMPARE(m_barseries->labelsFormat(), format);
116
117 m_barseries->setLabelsFormat(QString());
118 TRY_COMPARE(labelsFormatSpy.count(), 1);
119 arguments = labelsFormatSpy.takeFirst();
120 QVERIFY(arguments.at(0).toString() == QString());
121 QCOMPARE(m_barseries->labelsFormat(), QString());
122 }
123
124 void tst_QPercentBarSeries::setLabelsPosition()
125 {
126 QSignalSpy labelsPositionSpy(m_barseries,
127 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
128 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsCenter);
129
130 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsInsideEnd);
131 TRY_COMPARE(labelsPositionSpy.count(), 1);
132 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
133 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
134 == QPercentBarSeries::LabelsInsideEnd);
135 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsInsideEnd);
136
137 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsInsideBase);
138 TRY_COMPARE(labelsPositionSpy.count(), 1);
139 arguments = labelsPositionSpy.takeFirst();
140 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
141 == QPercentBarSeries::LabelsInsideBase);
142 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsInsideBase);
143
144 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsOutsideEnd);
145 TRY_COMPARE(labelsPositionSpy.count(), 1);
146 arguments = labelsPositionSpy.takeFirst();
147 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
148 == QPercentBarSeries::LabelsOutsideEnd);
149 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsOutsideEnd);
150
151 m_barseries->setLabelsPosition(QPercentBarSeries::LabelsCenter);
152 TRY_COMPARE(labelsPositionSpy.count(), 1);
153 arguments = labelsPositionSpy.takeFirst();
154 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
155 == QPercentBarSeries::LabelsCenter);
156 QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsCenter);
157 }
158
101 159 void tst_QPercentBarSeries::mouseclicked()
102 160 {
103 161 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
@@ -28,6 +28,7
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 Q_DECLARE_METATYPE(QBarSet*)
31 Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition)
31 32
32 33 class tst_QStackedBarSeries : public QObject
33 34 {
@@ -44,6 +45,8 private slots:
44 45 void qstackedbarseries();
45 46 void type_data();
46 47 void type();
48 void setLabelsFormat();
49 void setLabelsPosition();
47 50 void mouseclicked_data();
48 51 void mouseclicked();
49 52 void mousehovered_data();
@@ -56,6 +59,7 private:
56 59 void tst_QStackedBarSeries::initTestCase()
57 60 {
58 61 qRegisterMetaType<QBarSet*>("QBarSet*");
62 qRegisterMetaType<QAbstractBarSeries::LabelsPosition>("QAbstractBarSeries::LabelsPosition");
59 63 }
60 64
61 65 void tst_QStackedBarSeries::cleanupTestCase()
@@ -93,6 +97,60 void tst_QStackedBarSeries::type()
93 97 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar);
94 98 }
95 99
100 void tst_QStackedBarSeries::setLabelsFormat()
101 {
102 QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString)));
103 QCOMPARE(m_barseries->labelsFormat(), QString());
104
105 QString format("(@value)");
106 m_barseries->setLabelsFormat(format);
107 TRY_COMPARE(labelsFormatSpy.count(), 1);
108 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
109 QVERIFY(arguments.at(0).toString() == format);
110 QCOMPARE(m_barseries->labelsFormat(), format);
111
112 m_barseries->setLabelsFormat(QString());
113 TRY_COMPARE(labelsFormatSpy.count(), 1);
114 arguments = labelsFormatSpy.takeFirst();
115 QVERIFY(arguments.at(0).toString() == QString());
116 QCOMPARE(m_barseries->labelsFormat(), QString());
117 }
118
119 void tst_QStackedBarSeries::setLabelsPosition()
120 {
121 QSignalSpy labelsPositionSpy(m_barseries,
122 SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)));
123 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsCenter);
124
125 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsInsideEnd);
126 TRY_COMPARE(labelsPositionSpy.count(), 1);
127 QList<QVariant> arguments = labelsPositionSpy.takeFirst();
128 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
129 == QStackedBarSeries::LabelsInsideEnd);
130 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsInsideEnd);
131
132 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsInsideBase);
133 TRY_COMPARE(labelsPositionSpy.count(), 1);
134 arguments = labelsPositionSpy.takeFirst();
135 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
136 == QStackedBarSeries::LabelsInsideBase);
137 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsInsideBase);
138
139 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsOutsideEnd);
140 TRY_COMPARE(labelsPositionSpy.count(), 1);
141 arguments = labelsPositionSpy.takeFirst();
142 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
143 == QStackedBarSeries::LabelsOutsideEnd);
144 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsOutsideEnd);
145
146 m_barseries->setLabelsPosition(QStackedBarSeries::LabelsCenter);
147 TRY_COMPARE(labelsPositionSpy.count(), 1);
148 arguments = labelsPositionSpy.takeFirst();
149 QVERIFY(arguments.at(0).value<QAbstractBarSeries::LabelsPosition>()
150 == QStackedBarSeries::LabelsCenter);
151 QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsCenter);
152 }
153
96 154 void tst_QStackedBarSeries::mouseclicked_data()
97 155 {
98 156
@@ -81,6 +81,78 void tst_QXYSeries::seriesOpacity()
81 81 QCOMPARE(opacitySpy.count(), 3);
82 82 }
83 83
84 void tst_QXYSeries::pointLabelsFormat()
85 {
86 QSignalSpy labelsFormatSpy(m_series, SIGNAL(pointLabelsFormatChanged(QString)));
87 QCOMPARE(m_series->pointLabelsFormat(), QLatin1String("@xPoint, @yPoint"));
88
89 QString format("@yPoint");
90 m_series->setPointLabelsFormat(format);
91 TRY_COMPARE(labelsFormatSpy.count(), 1);
92 QList<QVariant> arguments = labelsFormatSpy.takeFirst();
93 QVERIFY(arguments.at(0).toString() == format);
94
95 m_series->setPointLabelsFormat(QString());
96 TRY_COMPARE(labelsFormatSpy.count(), 1);
97 arguments = labelsFormatSpy.takeFirst();
98 QVERIFY(arguments.at(0).toString() == QString());
99
100 }
101
102 void tst_QXYSeries::pointLabelsVisible()
103 {
104 QSignalSpy labelsVisibleSpy(m_series, SIGNAL(pointLabelsVisibilityChanged(bool)));
105 QCOMPARE(m_series->pointLabelsVisible(), false);
106
107 m_series->setPointLabelsVisible();
108 QCOMPARE(m_series->pointLabelsVisible(), true);
109 TRY_COMPARE(labelsVisibleSpy.count(), 1);
110 QList<QVariant> arguments = labelsVisibleSpy.takeFirst();
111 QVERIFY(arguments.at(0).toBool() == true);
112
113 m_series->setPointLabelsVisible(false);
114 QCOMPARE(m_series->pointLabelsVisible(), false);
115 TRY_COMPARE(labelsVisibleSpy.count(), 1);
116 arguments = labelsVisibleSpy.takeFirst();
117 QVERIFY(arguments.at(0).toBool() == false);
118 }
119
120 void tst_QXYSeries::pointLabelsFont()
121 {
122 QFont defaultFont(m_series->pointLabelsFont());
123 QSignalSpy labelsFontSpy(m_series, SIGNAL(pointLabelsFontChanged(QFont)));
124
125 QFont font("Times", 10);
126 m_series->setPointLabelsFont(font);
127 TRY_COMPARE(labelsFontSpy.count(), 1);
128 QList<QVariant> arguments = labelsFontSpy.takeFirst();
129 QVERIFY(arguments.at(0).value<QFont>() == font);
130
131 m_series->setPointLabelsFont(defaultFont);
132 TRY_COMPARE(labelsFontSpy.count(), 1);
133 arguments = labelsFontSpy.takeFirst();
134 QVERIFY(arguments.at(0).value<QFont>() == defaultFont);
135
136 }
137
138 void tst_QXYSeries::pointLabelsColor()
139 {
140 QColor defaultColor(QPen().color());
141 QSignalSpy labelsColorSpy(m_series, SIGNAL(pointLabelsColorChanged(QColor)));
142 QCOMPARE(m_series->pointLabelsColor(), defaultColor);
143
144 QColor color(Qt::blue);
145 m_series->setPointLabelsColor(color);
146 TRY_COMPARE(labelsColorSpy.count(), 1);
147 QList<QVariant> arguments = labelsColorSpy.takeFirst();
148 QVERIFY(arguments.at(0).value<QColor>() == color);
149
150 m_series->setPointLabelsColor(defaultColor);
151 TRY_COMPARE(labelsColorSpy.count(), 1);
152 arguments = labelsColorSpy.takeFirst();
153 QVERIFY(arguments.at(0).value<QColor>() == defaultColor);
154 }
155
84 156 void tst_QXYSeries::append_data()
85 157 {
86 158 QTest::addColumn< QList<QPointF> >("points");
@@ -42,6 +42,10 public slots:
42 42 private slots:
43 43 void seriesName();
44 44 void seriesVisible();
45 void pointLabelsFormat();
46 void pointLabelsVisible();
47 void pointLabelsFont();
48 void pointLabelsColor();
45 49 void seriesOpacity();
46 50 void oper_data();
47 51 void oper();
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "area series"
@@ -61,6 +61,8 ChartView {
61 61 XYPoint { x: 11; y: 0 }
62 62 }
63 63
64 pointLabelsFormat: "@xPoint, @yPoint";
65
64 66 onNameChanged: console.log(name + ".onNameChanged: " + name);
65 67 onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible);
66 68 onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity);
@@ -71,6 +73,14 ChartView {
71 73 onBorderWidthChanged: console.log(name + ".onBorderChanged: " + borderWidth);
72 74 // onCountChanged: console.log(name + ".onCountChanged: " + count);
73 75 onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state);
76 onPointLabelsVisibilityChanged: console.log(name + ".onPointLabelsVisibilityChanged: "
77 + visible);
78 onPointLabelsFormatChanged: console.log(name + ".onPointLabelsFormatChanged: "
79 + format);
80 onPointLabelsFontChanged: console.log(name + ".onPointLabelsFontChanged: "
81 + font.family);
82 onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: "
83 + color);
74 84 }
75 85
76 86 AreaSeries {
@@ -55,6 +55,32 Flow {
55 55 onClicked: series.borderWidth -= 0.5;
56 56 }
57 57 Button {
58 text: "point labels visible"
59 onClicked: series.pointLabelsVisible = !series.pointLabelsVisible;
60 }
61 Button {
62 text: "point labels format"
63 onClicked: {
64 if (series.pointLabelsFormat === "@xPoint, @yPoint")
65 series.pointLabelsFormat = "(@xPoint)"
66 else
67 series.pointLabelsFormat = "@xPoint, @yPoint"
68 }
69 }
70 Button {
71 text: "point labels font"
72 onClicked: {
73 if (series.pointLabelsFont.family === "Times")
74 series.pointLabelsFont.family = "Courier";
75 else
76 series.pointLabelsFont.family = "Times";
77 }
78 }
79 Button {
80 text: "point labels color"
81 onClicked: series.pointLabelsColor = main.nextColor();
82 }
83 Button {
58 84 id: upperButton
59 85 text: "upper series"
60 86 unpressedColor: "#79bd8f"
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Bar series"
@@ -34,6 +34,7 ChartView {
34 34 BarSeries {
35 35 id: mySeries
36 36 name: "bar"
37 labelsFormat: "@value";
37 38 axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
38 39 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
39 40 onClicked: console.log("barset.onClicked: " + index);
@@ -62,5 +63,14 ChartView {
62 63 + " " + index);
63 64 onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible);
64 65 onCountChanged: console.log("barSeries.onCountChanged: " + count);
66 onLabelsFormatChanged: console.log("barSeries.onLabelsFormatChanged: " + format);
67 onLabelsPositionChanged: console.log("barSeries.onLabelsPositionChanged: " + series.labelsPosition);
68
69 function changeLabelsPosition() {
70 if (labelsPosition === BarSeries.LabelsCenter)
71 labelsPosition = BarSeries.LabelsInsideEnd;
72 else
73 labelsPosition = BarSeries.LabelsCenter;
74 }
65 75 }
66 76 }
@@ -172,6 +172,19 Row {
172 172 onClicked: series.labelsVisible = !series.labelsVisible;
173 173 }
174 174 Button {
175 text: "labels format"
176 onClicked: {
177 if (series.labelsFormat === "@value")
178 series.labelsFormat = "@value%"
179 else
180 series.labelsFormat = "@value"
181 }
182 }
183 Button {
184 text: "labels position"
185 onClicked: series.changeLabelsPosition();
186 }
187 Button {
175 188 text: "set 1 label color"
176 189 onClicked: series.at(0).labelColor = main.nextColor();
177 190 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Bar series"
@@ -33,6 +33,7 ChartView {
33 33 HorizontalBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
38 39 onClicked: console.log("barset.onClicked: " + index);
@@ -61,5 +62,16 ChartView {
61 62 + status + " " + index);
62 63 onLabelsVisibleChanged: console.log("horizontalBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
63 64 onCountChanged: console.log("horizontalBarSeries.onCountChanged: " + count);
65 onLabelsFormatChanged: console.log("horizontalBarSeries.onLabelsFormatChanged: "
66 + format);
67 onLabelsPositionChanged: console.log("horizontalBarSeries.onLabelsPositionChanged: "
68 + series.labelsPosition);
69
70 function changeLabelsPosition() {
71 if (labelsPosition === BarSeries.LabelsCenter)
72 labelsPosition = BarSeries.LabelsInsideEnd;
73 else
74 labelsPosition = BarSeries.LabelsCenter;
75 }
64 76 }
65 77 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Percent bar series"
@@ -61,5 +61,18 ChartView {
61 61 + " " + status + " " + index);
62 62 onLabelsVisibleChanged: console.log("horizontalPercentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
63 63 onCountChanged: console.log("horizontalPercentBarSeries.onCountChanged: " + count);
64 onLabelsFormatChanged: console.log(
65 "horizontalPercentBarSeries.onLabelsFormatChanged: "
66 + format);
67 onLabelsPositionChanged: console.log(
68 "horizontalPercentBarSeries.onLabelsPositionChanged: "
69 + series.labelsPosition);
70
71 function changeLabelsPosition() {
72 if (labelsPosition === BarSeries.LabelsCenter)
73 labelsPosition = BarSeries.LabelsInsideEnd;
74 else
75 labelsPosition = BarSeries.LabelsCenter;
76 }
64 77 }
65 78 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Stacked bar series"
@@ -33,6 +33,7 ChartView {
33 33 HorizontalStackedBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
38 39 onClicked: console.log("barset.onClicked: " + index);
@@ -61,5 +62,18 ChartView {
61 62 + " " + status + " " + index);
62 63 onLabelsVisibleChanged: console.log("horizontalStackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
63 64 onCountChanged: console.log("horizontalStackedBarSeries.onCountChanged: " + count);
65 onLabelsFormatChanged: console.log(
66 "horizontalStackedBarSeries.onLabelsFormatChanged: "
67 + format);
68 onLabelsPositionChanged: console.log(
69 "horizontalStackedBarSeries.onLabelsPositionChanged: "
70 + series.labelsPosition);
71
72 function changeLabelsPosition() {
73 if (labelsPosition === BarSeries.LabelsCenter)
74 labelsPosition = BarSeries.LabelsInsideEnd;
75 else
76 labelsPosition = BarSeries.LabelsCenter;
77 }
64 78 }
65 79 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 property variant series: lineSeries
@@ -39,6 +39,8 ChartView {
39 39 XYPoint { x: 3.4; y: 3.0 }
40 40 XYPoint { x: 4.1; y: 3.3 }
41 41
42 pointLabelsFormat: "@xPoint, @yPoint";
43
42 44 onNameChanged: console.log("lineSeries.onNameChanged: " + name);
43 45 onVisibleChanged: console.log("lineSeries.onVisibleChanged: " + visible);
44 46 onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity);
@@ -52,6 +54,14 ChartView {
52 54 onCapStyleChanged: console.log("lineSeries.onCapStyleChanged: " + capStyle);
53 55 onCountChanged: console.log("lineSeries.onCountChanged: " + count);
54 56 onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state);
57 onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: "
58 + visible);
59 onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: "
60 + format);
61 onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: "
62 + font.family);
63 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
64 + color);
55 65 }
56 66
57 67 LineSeries {
@@ -72,6 +72,32 Flow {
72 72 onClicked: series.pointsVisible = !series.pointsVisible;
73 73 }
74 74 Button {
75 text: "point labels visible"
76 onClicked: series.pointLabelsVisible = !series.pointLabelsVisible;
77 }
78 Button {
79 text: "point labels format"
80 onClicked: {
81 if (series.pointLabelsFormat === "@xPoint, @yPoint")
82 series.pointLabelsFormat = "(@xPoint)"
83 else
84 series.pointLabelsFormat = "@xPoint, @yPoint"
85 }
86 }
87 Button {
88 text: "point labels font"
89 onClicked: {
90 if (series.pointLabelsFont.family === "Times")
91 series.pointLabelsFont.family = "Courier";
92 else
93 series.pointLabelsFont.family = "Times";
94 }
95 }
96 Button {
97 text: "point labels color"
98 onClicked: series.pointLabelsColor = main.nextColor();
99 }
100 Button {
75 101 text: "append point"
76 102 onClicked: series.append(series.count - 1, series.count - 1);
77 103 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Percent bar series"
@@ -33,6 +33,7 ChartView {
33 33 PercentBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38
38 39 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
@@ -62,5 +63,16 ChartView {
62 63 + " " + status + " " + index);
63 64 onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
64 65 onCountChanged: console.log("percentBarSeries.onCountChanged: " + count);
66 onLabelsFormatChanged: console.log("percentBarSeries.onLabelsFormatChanged: "
67 + format);
68 onLabelsPositionChanged: console.log("percentBarSeries.onLabelsPositionChanged: "
69 + series.labelsPosition);
70
71 function changeLabelsPosition() {
72 if (labelsPosition === BarSeries.LabelsCenter)
73 labelsPosition = BarSeries.LabelsInsideEnd;
74 else
75 labelsPosition = BarSeries.LabelsCenter;
76 }
65 77 }
66 78 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "scatter series"
@@ -37,6 +37,8 ChartView {
37 37 XYPoint { x: 2.1; y: 1.3 }
38 38 XYPoint { x: 2.5; y: 2.1 }
39 39
40 pointLabelsFormat: "@xPoint, @yPoint";
41
40 42 onNameChanged: console.log("scatterSeries.onNameChanged: " + name);
41 43 onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible);
42 44 onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity);
@@ -48,6 +50,14 ChartView {
48 50 onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor);
49 51 onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth);
50 52 onCountChanged: console.log("scatterSeries.onCountChanged: " + count);
53 onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: "
54 + visible);
55 onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: "
56 + format);
57 onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: "
58 + font.family);
59 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
60 + color);
51 61 }
52 62
53 63 ScatterSeries {
@@ -67,6 +67,32 Flow {
67 67 onClicked: series.markerShape = ((series.markerShape + 1) % 2);
68 68 }
69 69 Button {
70 text: "point labels visible"
71 onClicked: series.pointLabelsVisible = !series.pointLabelsVisible;
72 }
73 Button {
74 text: "point labels format"
75 onClicked: {
76 if (series.pointLabelsFormat === "@xPoint, @yPoint")
77 series.pointLabelsFormat = "(@xPoint)"
78 else
79 series.pointLabelsFormat = "@xPoint, @yPoint"
80 }
81 }
82 Button {
83 text: "point labels font"
84 onClicked: {
85 if (series.pointLabelsFont.family === "Times")
86 series.pointLabelsFont.family = "Courier";
87 else
88 series.pointLabelsFont.family = "Times";
89 }
90 }
91 Button {
92 text: "point labels color"
93 onClicked: series.pointLabelsColor = main.nextColor();
94 }
95 Button {
70 96 text: "append point"
71 97 onClicked: series.append(series.count - 1, series.count - 1);
72 98 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "spline series"
@@ -38,6 +38,8 ChartView {
38 38 XYPoint { x: 3.4; y: 3.0 }
39 39 XYPoint { x: 4.1; y: 3.3 }
40 40
41 pointLabelsFormat: "@xPoint, @yPoint";
42
41 43 onNameChanged: console.log("splineSeries.onNameChanged: " + name);
42 44 onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible);
43 45 onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity);
@@ -50,6 +52,14 ChartView {
50 52 onStyleChanged: console.log("splineSeries.onStyleChanged: " + style);
51 53 onCapStyleChanged: console.log("splineSeries.onCapStyleChanged: " + capStyle);
52 54 onCountChanged: console.log("splineSeries.onCountChanged: " + count);
55 onPointLabelsVisibilityChanged: console.log("splineSeries.onPointLabelsVisibilityChanged: "
56 + visible);
57 onPointLabelsFormatChanged: console.log("splineSeries.onPointLabelsFormatChanged: "
58 + format);
59 onPointLabelsFontChanged: console.log("splineSeries.onPointLabelsFontChanged: "
60 + font.family);
61 onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: "
62 + color);
53 63 }
54 64
55 65 SplineSeries {
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Stacked bar series"
@@ -33,6 +33,7 ChartView {
33 33 StackedBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
38 39 onClicked: console.log("barset.onClicked: " + index);
@@ -61,5 +62,16 ChartView {
61 62 + " " + status + " " + index);
62 63 onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
63 64 onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count);
65 onLabelsFormatChanged: console.log("stackedBarSeries.onLabelsFormatChanged: "
66 + format);
67 onLabelsPositionChanged: console.log("stackedBarSeries.onLabelsPositionChanged: "
68 + series.labelsPosition);
69
70 function changeLabelsPosition() {
71 if (labelsPosition === BarSeries.LabelsCenter)
72 labelsPosition = BarSeries.LabelsInsideEnd;
73 else
74 labelsPosition = BarSeries.LabelsCenter;
75 }
64 76 }
65 77 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "area series"
@@ -61,6 +61,8 ChartView {
61 61 XYPoint { x: 11; y: 0 }
62 62 }
63 63
64 pointLabelsFormat: "@xPoint, @yPoint";
65
64 66 onNameChanged: console.log(name + ".onNameChanged: " + name);
65 67 onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible);
66 68 onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity);
@@ -71,6 +73,14 ChartView {
71 73 onBorderWidthChanged: console.log(name + ".onBorderChanged: " + borderWidth);
72 74 // onCountChanged: console.log(name + ".onCountChanged: " + count);
73 75 onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state);
76 onPointLabelsVisibilityChanged: console.log(name + ".onPointLabelsVisibilityChanged: "
77 + visible);
78 onPointLabelsFormatChanged: console.log(name + ".onPointLabelsFormatChanged: "
79 + format);
80 onPointLabelsFontChanged: console.log(name + ".onPointLabelsFontChanged: "
81 + font.family);
82 onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: "
83 + color);
74 84 }
75 85
76 86 AreaSeries {
@@ -55,6 +55,32 Flow {
55 55 onClicked: series.borderWidth -= 0.5;
56 56 }
57 57 Button {
58 text: "point labels visible"
59 onClicked: series.pointLabelsVisible = !series.pointLabelsVisible;
60 }
61 Button {
62 text: "point labels format"
63 onClicked: {
64 if (series.pointLabelsFormat === "@xPoint, @yPoint")
65 series.pointLabelsFormat = "(@xPoint)"
66 else
67 series.pointLabelsFormat = "@xPoint, @yPoint"
68 }
69 }
70 Button {
71 text: "point labels font"
72 onClicked: {
73 if (series.pointLabelsFont.family === "Times")
74 series.pointLabelsFont.family = "Courier";
75 else
76 series.pointLabelsFont.family = "Times";
77 }
78 }
79 Button {
80 text: "point labels color"
81 onClicked: series.pointLabelsColor = main.nextColor();
82 }
83 Button {
58 84 id: upperButton
59 85 text: "upper series"
60 86 unpressedColor: "#79bd8f"
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Bar series"
@@ -34,6 +34,7 ChartView {
34 34 BarSeries {
35 35 id: mySeries
36 36 name: "bar"
37 labelsFormat: "@value";
37 38 axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
38 39 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
39 40 onClicked: console.log("barset.onClicked: " + index);
@@ -62,5 +63,14 ChartView {
62 63 + " " + index);
63 64 onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible);
64 65 onCountChanged: console.log("barSeries.onCountChanged: " + count);
66 onLabelsFormatChanged: console.log("barSeries.onLabelsFormatChanged: " + format);
67 onLabelsPositionChanged: console.log("barSeries.onLabelsPositionChanged: " + series.labelsPosition);
68
69 function changeLabelsPosition() {
70 if (labelsPosition === BarSeries.LabelsCenter)
71 labelsPosition = BarSeries.LabelsInsideEnd;
72 else
73 labelsPosition = BarSeries.LabelsCenter;
74 }
65 75 }
66 76 }
@@ -172,6 +172,19 Row {
172 172 onClicked: series.labelsVisible = !series.labelsVisible;
173 173 }
174 174 Button {
175 text: "labels format"
176 onClicked: {
177 if (series.labelsFormat === "@value")
178 series.labelsFormat = "@value%"
179 else
180 series.labelsFormat = "@value"
181 }
182 }
183 Button {
184 text: "labels position"
185 onClicked: series.changeLabelsPosition();
186 }
187 Button {
175 188 text: "set 1 label color"
176 189 onClicked: series.at(0).labelColor = main.nextColor();
177 190 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Bar series"
@@ -33,6 +33,7 ChartView {
33 33 HorizontalBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
38 39 onClicked: console.log("barset.onClicked: " + index);
@@ -61,5 +62,16 ChartView {
61 62 + status + " " + index);
62 63 onLabelsVisibleChanged: console.log("horizontalBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
63 64 onCountChanged: console.log("horizontalBarSeries.onCountChanged: " + count);
65 onLabelsFormatChanged: console.log("horizontalBarSeries.onLabelsFormatChanged: "
66 + format);
67 onLabelsPositionChanged: console.log("horizontalBarSeries.onLabelsPositionChanged: "
68 + series.labelsPosition);
69
70 function changeLabelsPosition() {
71 if (labelsPosition === BarSeries.LabelsCenter)
72 labelsPosition = BarSeries.LabelsInsideEnd;
73 else
74 labelsPosition = BarSeries.LabelsCenter;
75 }
64 76 }
65 77 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Percent bar series"
@@ -33,6 +33,7 ChartView {
33 33 HorizontalPercentBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
38 39 onClicked: console.log("barset.onClicked: " + index);
@@ -61,5 +62,18 ChartView {
61 62 + " " + status + " " + index);
62 63 onLabelsVisibleChanged: console.log("horizontalPercentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
63 64 onCountChanged: console.log("horizontalPercentBarSeries.onCountChanged: " + count);
65 onLabelsFormatChanged: console.log(
66 "horizontalPercentBarSeries.onLabelsFormatChanged: "
67 + format);
68 onLabelsPositionChanged: console.log(
69 "horizontalPercentBarSeries.onLabelsPositionChanged: "
70 + series.labelsPosition);
71
72 function changeLabelsPosition() {
73 if (labelsPosition === BarSeries.LabelsCenter)
74 labelsPosition = BarSeries.LabelsInsideEnd;
75 else
76 labelsPosition = BarSeries.LabelsCenter;
77 }
64 78 }
65 79 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Stacked bar series"
@@ -33,6 +33,7 ChartView {
33 33 HorizontalStackedBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
38 39 onClicked: console.log("barset.onClicked: " + index);
@@ -61,5 +62,18 ChartView {
61 62 + " " + status + " " + index);
62 63 onLabelsVisibleChanged: console.log("horizontalStackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
63 64 onCountChanged: console.log("horizontalStackedBarSeries.onCountChanged: " + count);
65 onLabelsFormatChanged: console.log(
66 "horizontalStackedBarSeries.onLabelsFormatChanged: "
67 + format);
68 onLabelsPositionChanged: console.log(
69 "horizontalStackedBarSeries.onLabelsPositionChanged: "
70 + series.labelsPosition);
71
72 function changeLabelsPosition() {
73 if (labelsPosition === BarSeries.LabelsCenter)
74 labelsPosition = BarSeries.LabelsInsideEnd;
75 else
76 labelsPosition = BarSeries.LabelsCenter;
77 }
64 78 }
65 79 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 property variant series: lineSeries
@@ -39,6 +39,8 ChartView {
39 39 XYPoint { x: 3.4; y: 3.0 }
40 40 XYPoint { x: 4.1; y: 3.3 }
41 41
42 pointLabelsFormat: "@xPoint, @yPoint";
43
42 44 onNameChanged: console.log("lineSeries.onNameChanged: " + name);
43 45 onVisibleChanged: console.log("lineSeries.onVisibleChanged: " + visible);
44 46 onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity);
@@ -52,6 +54,14 ChartView {
52 54 onCapStyleChanged: console.log("lineSeries.onCapStyleChanged: " + capStyle);
53 55 onCountChanged: console.log("lineSeries.onCountChanged: " + count);
54 56 onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state);
57 onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: "
58 + visible);
59 onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: "
60 + format);
61 onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: "
62 + font.family);
63 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
64 + color);
55 65 }
56 66
57 67 LineSeries {
@@ -72,6 +72,32 Flow {
72 72 onClicked: series.pointsVisible = !series.pointsVisible;
73 73 }
74 74 Button {
75 text: "point labels visible"
76 onClicked: series.pointLabelsVisible = !series.pointLabelsVisible;
77 }
78 Button {
79 text: "point labels format"
80 onClicked: {
81 if (series.pointLabelsFormat === "@xPoint, @yPoint")
82 series.pointLabelsFormat = "(@xPoint)"
83 else
84 series.pointLabelsFormat = "@xPoint, @yPoint"
85 }
86 }
87 Button {
88 text: "point labels font"
89 onClicked: {
90 if (series.pointLabelsFont.family === "Times")
91 series.pointLabelsFont.family = "Courier";
92 else
93 series.pointLabelsFont.family = "Times";
94 }
95 }
96 Button {
97 text: "point labels color"
98 onClicked: series.pointLabelsColor = main.nextColor();
99 }
100 Button {
75 101 text: "append point"
76 102 onClicked: series.append(series.count - 1, series.count - 1);
77 103 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Percent bar series"
@@ -33,6 +33,7 ChartView {
33 33 PercentBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38
38 39 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
@@ -62,5 +63,16 ChartView {
62 63 + " " + status + " " + index);
63 64 onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
64 65 onCountChanged: console.log("percentBarSeries.onCountChanged: " + count);
66 onLabelsFormatChanged: console.log("percentBarSeries.onLabelsFormatChanged: "
67 + format);
68 onLabelsPositionChanged: console.log("percentBarSeries.onLabelsPositionChanged: "
69 + series.labelsPosition);
70
71 function changeLabelsPosition() {
72 if (labelsPosition === BarSeries.LabelsCenter)
73 labelsPosition = BarSeries.LabelsInsideEnd;
74 else
75 labelsPosition = BarSeries.LabelsCenter;
76 }
65 77 }
66 78 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "scatter series"
@@ -37,6 +37,8 ChartView {
37 37 XYPoint { x: 2.1; y: 1.3 }
38 38 XYPoint { x: 2.5; y: 2.1 }
39 39
40 pointLabelsFormat: "@xPoint, @yPoint";
41
40 42 onNameChanged: console.log("scatterSeries.onNameChanged: " + name);
41 43 onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible);
42 44 onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity);
@@ -49,6 +51,14 ChartView {
49 51 onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor);
50 52 onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth);
51 53 onCountChanged: console.log("scatterSeries.onCountChanged: " + count);
54 onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: "
55 + visible);
56 onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: "
57 + format);
58 onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: "
59 + font.family);
60 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
61 + color);
52 62 }
53 63
54 64 ScatterSeries {
@@ -67,6 +67,32 Flow {
67 67 onClicked: series.markerShape = ((series.markerShape + 1) % 2);
68 68 }
69 69 Button {
70 text: "point labels visible"
71 onClicked: series.pointLabelsVisible = !series.pointLabelsVisible;
72 }
73 Button {
74 text: "point labels format"
75 onClicked: {
76 if (series.pointLabelsFormat === "@xPoint, @yPoint")
77 series.pointLabelsFormat = "(@xPoint)"
78 else
79 series.pointLabelsFormat = "@xPoint, @yPoint"
80 }
81 }
82 Button {
83 text: "point labels font"
84 onClicked: {
85 if (series.pointLabelsFont.family === "Times")
86 series.pointLabelsFont.family = "Courier";
87 else
88 series.pointLabelsFont.family = "Times";
89 }
90 }
91 Button {
92 text: "point labels color"
93 onClicked: series.pointLabelsColor = main.nextColor();
94 }
95 Button {
70 96 text: "append point"
71 97 onClicked: series.append(series.count - 1, series.count - 1);
72 98 }
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "spline series"
@@ -38,6 +38,8 ChartView {
38 38 XYPoint { x: 3.4; y: 3.0 }
39 39 XYPoint { x: 4.1; y: 3.3 }
40 40
41 pointLabelsFormat: "@xPoint, @yPoint";
42
41 43 onNameChanged: console.log("splineSeries.onNameChanged: " + name);
42 44 onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible);
43 45 onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity);
@@ -51,6 +53,14 ChartView {
51 53 onStyleChanged: console.log("splineSeries.onStyleChanged: " + style);
52 54 onCapStyleChanged: console.log("splineSeries.onCapStyleChanged: " + capStyle);
53 55 onCountChanged: console.log("splineSeries.onCountChanged: " + count);
56 onPointLabelsVisibilityChanged: console.log("splineSeries.onPointLabelsVisibilityChanged: "
57 + visible);
58 onPointLabelsFormatChanged: console.log("splineSeries.onPointLabelsFormatChanged: "
59 + format);
60 onPointLabelsFontChanged: console.log("splineSeries.onPointLabelsFontChanged: "
61 + font.family);
62 onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: "
63 + color);
54 64 }
55 65
56 66 SplineSeries {
@@ -19,7 +19,7
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 2.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.4
23 23
24 24 ChartView {
25 25 title: "Stacked bar series"
@@ -33,6 +33,7 ChartView {
33 33 StackedBarSeries {
34 34 id: mySeries
35 35 name: "bar"
36 labelsFormat: "@value";
36 37 axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
37 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
38 39 onClicked: console.log("barset.onClicked: " + index);
@@ -61,5 +62,16 ChartView {
61 62 + " " + status + " " + index);
62 63 onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
63 64 onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count);
65 onLabelsFormatChanged: console.log("stackedBarSeries.onLabelsFormatChanged: "
66 + format);
67 onLabelsPositionChanged: console.log("stackedBarSeries.onLabelsPositionChanged: "
68 + series.labelsPosition);
69
70 function changeLabelsPosition() {
71 if (labelsPosition === BarSeries.LabelsCenter)
72 labelsPosition = BarSeries.LabelsInsideEnd;
73 else
74 labelsPosition = BarSeries.LabelsCenter;
75 }
64 76 }
65 77 }
General Comments 0
You need to be logged in to leave comments. Login now