diff --git a/plugins/quick2/plugins.qmltypes b/plugins/quick2/plugins.qmltypes index 4233d81..6b8dfc8 100644 --- a/plugins/quick2/plugins.qmltypes +++ b/plugins/quick2/plugins.qmltypes @@ -1561,9 +1561,20 @@ Module { prototype: "QtCommercialChart::QAbstractSeries" exports: ["QtCommercial.Chart/AbstractBarSeries 1.0"] exportMetaObjectRevisions: [0] + Enum { + name: "LabelsPosition" + values: { + "LabelsCenter": 0, + "LabelsInsideEnd": 1, + "LabelsInsideBase": 2, + "LabelsOutsideEnd": 3 + } + } Property { name: "barWidth"; type: "double" } Property { name: "count"; type: "int"; isReadonly: true } Property { name: "labelsVisible"; type: "bool" } + Property { name: "labelsFormat"; type: "string" } + Property { name: "labelsPosition"; type: "LabelsPosition" } Signal { name: "clicked" Parameter { name: "index"; type: "int" } @@ -1581,6 +1592,14 @@ Module { Parameter { name: "barset"; type: "QBarSet"; isPointer: true } } Signal { + name: "labelsFormatChanged" + Parameter { name: "format"; type: "string" } + } + Signal { + name: "labelsPositionChanged" + Parameter { name: "position"; type: "QAbstractBarSeries::LabelsPosition" } + } + Signal { name: "barsetsAdded" Parameter { name: "sets"; type: "QList" } } @@ -1623,6 +1642,10 @@ Module { Property { name: "lowerSeries"; type: "QLineSeries"; isReadonly: true; isPointer: true } Property { name: "color"; type: "QColor" } Property { name: "borderColor"; type: "QColor" } + Property { name: "pointLabelsFormat"; type: "string" } + Property { name: "pointLabelsVisible"; type: "bool" } + Property { name: "pointLabelsFont"; type: "QFont" } + Property { name: "pointLabelsColor"; type: "QColor" } Signal { name: "clicked" Parameter { name: "point"; type: "QPointF" } @@ -1641,6 +1664,22 @@ Module { name: "borderColorChanged" Parameter { name: "color"; type: "QColor" } } + Signal { + name: "pointLabelsFormatChanged" + Parameter { name: "format"; type: "string" } + } + Signal { + name: "pointLabelsVisibilityChanged" + Parameter { name: "visible"; type: "bool" } + } + Signal { + name: "pointLabelsFontChanged" + Parameter { name: "font"; type: "QFont" } + } + Signal { + name: "pointLabelsColorChanged" + Parameter { name: "color"; type: "QColor" } + } } Component { name: "QtCommercialChart::QBarCategoryAxis" @@ -2140,6 +2179,10 @@ Module { exportMetaObjectRevisions: [0] Property { name: "pointsVisible"; type: "bool" } Property { name: "color"; type: "QColor" } + Property { name: "pointLabelsFormat"; type: "string" } + Property { name: "pointLabelsVisible"; type: "bool" } + Property { name: "pointLabelsFont"; type: "QFont" } + Property { name: "pointLabelsColor"; type: "QColor" } Signal { name: "clicked" Parameter { name: "point"; type: "QPointF" } @@ -2166,5 +2209,21 @@ Module { Parameter { name: "color"; type: "QColor" } } Signal { name: "pointsReplaced" } + Signal { + name: "pointLabelsFormatChanged" + Parameter { name: "format"; type: "string" } + } + Signal { + name: "pointLabelsVisibilityChanged" + Parameter { name: "visible"; type: "bool" } + } + Signal { + name: "pointLabelsFontChanged" + Parameter { name: "font"; type: "QFont" } + } + Signal { + name: "pointLabelsColorChanged" + Parameter { name: "color"; type: "QColor" } + } } } diff --git a/src/areachart/areachartitem.cpp b/src/areachart/areachartitem.cpp index 46dacd9..225cab7 100644 --- a/src/areachart/areachartitem.cpp +++ b/src/areachart/areachartitem.cpp @@ -36,7 +36,11 @@ AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item) m_series(areaSeries), m_upper(0), m_lower(0), - m_pointsVisible(false) + m_pointsVisible(false), + m_pointLabelsFormat(areaSeries->pointLabelsFormat()), + m_pointLabelsVisible(false), + m_pointLabelsFont(areaSeries->pointLabelsFont()), + m_pointLabelsColor(areaSeries->pointLabelsColor()) { setAcceptHoverEvents(true); setZValue(ChartPresenter::LineChartZValue); @@ -50,6 +54,14 @@ AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item) QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF))); QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool))); + QObject::connect(areaSeries, SIGNAL(pointLabelsFormatChanged(QString)), + this, SLOT(handleUpdated())); + QObject::connect(areaSeries, SIGNAL(pointLabelsVisibilityChanged(bool)), + this, SLOT(handleUpdated())); + QObject::connect(areaSeries, SIGNAL(pointLabelsFontChanged(QFont)), + this, SLOT(handleUpdated())); + QObject::connect(areaSeries, SIGNAL(pointLabelsColorChanged(QColor)), + this, SLOT(handleUpdated())); handleUpdated(); } @@ -131,6 +143,10 @@ void AreaChartItem::handleUpdated() m_pointPen = m_series->pen(); m_pointPen.setWidthF(2 * m_pointPen.width()); setOpacity(m_series->opacity()); + m_pointLabelsFormat = m_series->pointLabelsFormat(); + m_pointLabelsVisible = m_series->pointLabelsVisible(); + m_pointLabelsFont = m_series->pointLabelsFont(); + m_pointLabelsColor = m_series->pointLabelsColor(); update(); } @@ -170,6 +186,50 @@ void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt if (m_lower) painter->drawPoints(m_lower->geometryPoints()); } + + // Draw series point label + if (m_pointLabelsVisible) { + static const QString xPointTag(QLatin1String("@xPoint")); + static const QString yPointTag(QLatin1String("@yPoint")); + const int labelOffset = 2; + + painter->setFont(m_pointLabelsFont); + painter->setPen(QPen(m_pointLabelsColor)); + QFontMetrics fm(painter->font()); + + QString pointLabel = m_pointLabelsFormat; + + if (m_series->upperSeries()) { + for (int i(0); i < m_series->upperSeries()->count(); i++) { + pointLabel.replace(xPointTag, QString::number(m_series->upperSeries()->at(i).x())); + pointLabel.replace(yPointTag, QString::number(m_series->upperSeries()->at(i).y())); + + // Position text in relation to the point + int pointLabelWidth = fm.width(pointLabel); + QPointF position(m_upper->geometryPoints().at(i)); + position.setX(position.x() - pointLabelWidth / 2); + position.setY(position.y() - m_series->upperSeries()->pen().width() / 2 - labelOffset); + + painter->drawText(position, pointLabel); + } + } + + if (m_series->lowerSeries()) { + for (int i(0); i < m_series->lowerSeries()->count(); i++) { + pointLabel.replace(xPointTag, QString::number(m_series->lowerSeries()->at(i).x())); + pointLabel.replace(yPointTag, QString::number(m_series->lowerSeries()->at(i).y())); + + // Position text in relation to the point + int pointLabelWidth = fm.width(pointLabel); + QPointF position(m_lower->geometryPoints().at(i)); + position.setX(position.x() - pointLabelWidth / 2); + position.setY(position.y() - m_series->lowerSeries()->pen().width() / 2 - labelOffset); + + painter->drawText(position, pointLabel); + } + } + } + painter->restore(); } diff --git a/src/areachart/areachartitem_p.h b/src/areachart/areachartitem_p.h index 2a16a6f..25ef891 100644 --- a/src/areachart/areachartitem_p.h +++ b/src/areachart/areachartitem_p.h @@ -83,6 +83,11 @@ private: QBrush m_brush; bool m_pointsVisible; + bool m_pointLabelsVisible; + QString m_pointLabelsFormat; + QFont m_pointLabelsFont; + QColor m_pointLabelsColor; + }; class AreaBoundItem : public LineChartItem diff --git a/src/areachart/qareaseries.cpp b/src/areachart/qareaseries.cpp index 37d2edf..92d7be2 100644 --- a/src/areachart/qareaseries.cpp +++ b/src/areachart/qareaseries.cpp @@ -182,6 +182,110 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \property QAreaSeries::pointLabelsFormat + The \a format used for showing labels with series points. + + QAreaSeries supports the following format tags: + \table + \row + \li @xPoint \li The x value of the data point + \row + \li @yPoint \li The y value of the data point + \endtable + + For example, the following usage of the format tags would produce labels that have the data + point (x, y) shown inside brackets separated by a comma: + \code + series->setPointLabelsFormat("(@xPoint, @yPoint)"); + \endcode + + By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot + area, labels on the edge of the plot area are cut. If the points are close to each other the + labels may overlap. + + \sa QAreaSeries::pointLabelsVisible, QAreaSeries::pointLabelsFont, QAreaSeries::pointLabelsColor +*/ +/*! + \qmlproperty string AreaSeries::pointLabelsFormat + The \a format used for showing labels with series points. + + \sa QAreaSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor +*/ +/*! + \fn void QAreaSeries::pointLabelsFormatChanged(const QString &format) + Signal is emitted when the \a format of data point labels is changed. +*/ +/*! + \qmlsignal AreaSeries::onPointLabelsFormatChanged(string format) + Signal is emitted when the \a format of data point labels is changed. +*/ + +/*! + \property QAreaSeries::pointLabelsVisible + Defines the visibility for data point labels. False by default. + + \sa QAreaSeries::pointLabelsFormat +*/ +/*! + \qmlproperty bool AreaSeries::pointLabelsVisible + Defines the visibility for data point labels. + + \sa pointLabelsFormat +*/ +/*! + \fn void QAreaSeries::pointLabelsVisibilityChanged(bool visible) + The visibility of the data point labels is changed to \a visible. +*/ +/*! + \qmlsignal AreaSeries::onPointLabelsVisibilityChanged(bool visible) + The visibility of the data point labels is changed to \a visible. +*/ + +/*! + \property QAreaSeries::pointLabelsFont + Defines the font used for data point labels. + + \sa QAreaSeries::pointLabelsFormat +*/ +/*! + \qmlproperty font AreaSeries::pointLabelsFont + Defines the font used for data point labels. + + \sa pointLabelsFormat +*/ +/*! + \fn void QAreaSeries::pointLabelsFontChanged(const QFont &font); + The font used for data point labels is changed to \a font. +*/ +/*! + \qmlsignal AreaSeries::onPointLabelsFontChanged(Font font) + The font used for data point labels is changed to \a font. +*/ + +/*! + \property QAreaSeries::pointLabelsColor + Defines the color used for data point labels. By default, the color is the color of the brush + defined in theme for labels. + + \sa QAreaSeries::pointLabelsFormat +*/ +/*! + \qmlproperty font AreaSeries::pointLabelsColor + Defines the color used for data point labels. By default, the color is the color of the brush + defined in theme for labels. + + \sa pointLabelsFormat +*/ +/*! + \fn void QAreaSeries::pointLabelsColorChanged(const QColor &color); + The color used for data point labels is changed to \a color. +*/ +/*! + \qmlsignal AreaSeries::onPointLabelsColorChanged(Color color) + The color used for data point labels is changed to \a color. +*/ + +/*! Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. When series object is added to QChartView or QChart instance ownerships is transferred. @@ -344,6 +448,69 @@ bool QAreaSeries::pointsVisible() const return d->m_pointsVisible; } +void QAreaSeries::setPointLabelsFormat(const QString &format) +{ + Q_D(QAreaSeries); + if (d->m_pointLabelsFormat != format) { + d->m_pointLabelsFormat = format; + emit pointLabelsFormatChanged(format); + } +} + +QString QAreaSeries::pointLabelsFormat() const +{ + Q_D(const QAreaSeries); + return d->m_pointLabelsFormat; +} + +void QAreaSeries::setPointLabelsVisible(bool visible) +{ + Q_D(QAreaSeries); + if (d->m_pointLabelsVisible != visible) { + d->m_pointLabelsVisible = visible; + emit pointLabelsVisibilityChanged(visible); + } +} + +bool QAreaSeries::pointLabelsVisible() const +{ + Q_D(const QAreaSeries); + return d->m_pointLabelsVisible; +} + +void QAreaSeries::setPointLabelsFont(const QFont &font) +{ + Q_D(QAreaSeries); + if (d->m_pointLabelsFont != font) { + d->m_pointLabelsFont = font; + emit pointLabelsFontChanged(font); + } +} + +QFont QAreaSeries::pointLabelsFont() const +{ + Q_D(const QAreaSeries); + return d->m_pointLabelsFont; +} + +void QAreaSeries::setPointLabelsColor(const QColor &color) +{ + Q_D(QAreaSeries); + if (d->m_pointLabelsColor != color) { + d->m_pointLabelsColor = color; + emit pointLabelsColorChanged(color); + } +} + +QColor QAreaSeries::pointLabelsColor() const +{ + Q_D(const QAreaSeries); + if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color()) + return QPen().color(); + else + return d->m_pointLabelsColor; +} + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) @@ -352,7 +519,11 @@ QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lo m_pen(QChartPrivate::defaultPen()), m_upperSeries(upperSeries), m_lowerSeries(lowerSeries), - m_pointsVisible(false) + m_pointsVisible(false), + m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")), + m_pointLabelsVisible(false), + m_pointLabelsFont(QChartPrivate::defaultFont()), + m_pointLabelsColor(QChartPrivate::defaultPen().color()) { } @@ -470,6 +641,11 @@ void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forc QBrush brush(colors.at(index % colors.size())); q->setBrush(brush); } + + if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { + QColor color = theme->labelBrush().color(); + q->setPointLabelsColor(color); + } } diff --git a/src/areachart/qareaseries.h b/src/areachart/qareaseries.h index 9f29903..034c5fc 100644 --- a/src/areachart/qareaseries.h +++ b/src/areachart/qareaseries.h @@ -37,6 +37,14 @@ class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QAbstractSeries Q_PROPERTY(QLineSeries *lowerSeries READ lowerSeries) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) + Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat + NOTIFY pointLabelsFormatChanged) + Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible + NOTIFY pointLabelsVisibilityChanged) + Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont + NOTIFY pointLabelsFontChanged) + Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor + NOTIFY pointLabelsColorChanged) public: explicit QAreaSeries(QObject *parent = 0); @@ -66,12 +74,28 @@ public: void setPointsVisible(bool visible = true); bool pointsVisible() const; + void setPointLabelsFormat(const QString &format); + QString pointLabelsFormat() const; + + void setPointLabelsVisible(bool visible = true); + bool pointLabelsVisible() const; + + void setPointLabelsFont(const QFont &font); + QFont pointLabelsFont() const; + + void setPointLabelsColor(const QColor &color); + QColor pointLabelsColor() const; + Q_SIGNALS: void clicked(const QPointF &point); void hovered(const QPointF &point, bool state); void selected(); void colorChanged(QColor color); void borderColorChanged(QColor color); + void pointLabelsFormatChanged(const QString &format); + void pointLabelsVisibilityChanged(bool visible); + void pointLabelsFontChanged(const QFont &font); + void pointLabelsColorChanged(const QColor &color); private: Q_DECLARE_PRIVATE(QAreaSeries) diff --git a/src/areachart/qareaseries_p.h b/src/areachart/qareaseries_p.h index 11ebacb..4efe7a9 100644 --- a/src/areachart/qareaseries_p.h +++ b/src/areachart/qareaseries_p.h @@ -63,6 +63,10 @@ protected: QLineSeries *m_upperSeries; QLineSeries *m_lowerSeries; bool m_pointsVisible; + QString m_pointLabelsFormat; + bool m_pointLabelsVisible; + QFont m_pointLabelsFont; + QColor m_pointLabelsColor; private: Q_DECLARE_PUBLIC(QAreaSeries); }; diff --git a/src/barchart/abstractbarchartitem.cpp b/src/barchart/abstractbarchartitem.cpp index 5ca6da6..70c647c 100644 --- a/src/barchart/abstractbarchartitem.cpp +++ b/src/barchart/abstractbarchartitem.cpp @@ -47,6 +47,10 @@ AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphics connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged())); + connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(handleUpdatedBars())); + connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels())); + connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)), + this, SLOT(handleLabelsPositionChanged())); setZValue(ChartPresenter::BarSeriesZValue); handleDataStructureChanged(); handleVisibleChanged(); @@ -99,12 +103,10 @@ void AbstractBarChartItem::setLayout(const QVector &layout) m_layout = layout; - for (int i = 0; i < m_bars.count(); i++) { + for (int i = 0; i < m_bars.count(); i++) m_bars.at(i)->setRect(layout.at(i)); - QGraphicsTextItem *label = m_labels.at(i); - label->setPos(layout.at(i).center() - label->boundingRect().center()); - } + positionLabels(); } //handlers @@ -203,6 +205,7 @@ void AbstractBarChartItem::handleUpdatedBars() int categoryCount = m_series->d_func()->categoryCount(); int setCount = m_series->count(); int itemIndex(0); + static const QString valueTag(QLatin1String("@value")); for (int category = 0; category < categoryCount; category++) { for (int set = 0; set < setCount; set++) { @@ -213,7 +216,14 @@ void AbstractBarChartItem::handleUpdatedBars() bar->update(); QGraphicsTextItem *label = m_labels.at(itemIndex); - label->setHtml(QString("%1").arg(barSet->value(category))); + QString valueLabel; + if (m_series->labelsFormat().isEmpty()) { + valueLabel = QString("%1").arg(barSet->value(category)); + } else { + valueLabel = m_series->labelsFormat(); + valueLabel.replace(valueTag, QString::number(barSet->value(category))); + } + label->setHtml(valueLabel); label->setFont(barSet->m_labelFont); label->setDefaultTextColor(barSet->m_labelBrush.color()); label->update(); @@ -223,6 +233,32 @@ void AbstractBarChartItem::handleUpdatedBars() } } +void AbstractBarChartItem::handleLabelsPositionChanged() +{ + positionLabels(); +} + +void AbstractBarChartItem::positionLabels() +{ + for (int i = 0; i < m_layout.count(); i++) { + QGraphicsTextItem *label = m_labels.at(i); + qreal xPos = 0; + qreal yPos = m_layout.at(i).center().y() - label->boundingRect().center().y(); + + if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter) + xPos = m_layout.at(i).center().x() - label->boundingRect().center().x(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd) + xPos = m_layout.at(i).right() - label->boundingRect().width(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase) + xPos = m_layout.at(i).left(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd) + xPos = m_layout.at(i).right(); + + label->setPos(xPos, yPos); + label->setZValue(zValue() + 1); + } +} + #include "moc_abstractbarchartitem_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/abstractbarchartitem_p.h b/src/barchart/abstractbarchartitem_p.h index 87a80b3..2aa00ac 100644 --- a/src/barchart/abstractbarchartitem_p.h +++ b/src/barchart/abstractbarchartitem_p.h @@ -70,6 +70,8 @@ public Q_SLOTS: void handleVisibleChanged(); void handleOpacityChanged(); virtual void handleUpdatedBars(); + void handleLabelsPositionChanged(); + virtual void positionLabels(); protected: diff --git a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp index c6ed34c..775bfba 100644 --- a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp +++ b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp @@ -97,6 +97,7 @@ void HorizontalPercentBarChartItem::handleUpdatedBars() int categoryCount = m_series->d_func()->categoryCount(); int setCount = m_series->count(); int itemIndex(0); + static const QString valueTag(QLatin1String("@value")); for (int category = 0; category < categoryCount; category++) { for (int set = 0; set < setCount; set++) { @@ -111,7 +112,14 @@ void HorizontalPercentBarChartItem::handleUpdatedBars() QString vString(QString::number(p)); vString.truncate(3); vString.append("%"); - label->setHtml(vString); + QString valueLabel; + if (m_series->labelsFormat().isEmpty()) { + valueLabel = vString; + } else { + valueLabel = m_series->labelsFormat(); + valueLabel.replace(valueTag, QString::number(barSet->value(category))); + } + label->setHtml(valueLabel); label->setFont(barSet->m_labelFont); label->setDefaultTextColor(barSet->m_labelBrush.color()); label->update(); diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp index 2c2db60..6b40197 100644 --- a/src/barchart/qabstractbarseries.cpp +++ b/src/barchart/qabstractbarseries.cpp @@ -129,6 +129,75 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \property QAbstractBarSeries::labelsFormat + The \a format used for showing labels in series. + + QAbstractBarSeries supports the following format tag: + \table + \row + \li @value \li The value of the bar + \endtable + + For example, the following usage of the format tags would produce labels that show the value + followed by unit ('u'): + \code + series->setLabelsFormat("@value u"); + \endcode + + By default, the labels shows the value of the bar. For percent bar series '%' is added after + the value. The labels are shown on the plot area, labels on the edge of the plot area are cut. + If the bars are close to each other the labels may overlap. + + \sa QAbstractBarSeries::labelsVisible, QAbstractBarSeries::labelsPosition +*/ +/*! + \qmlproperty string AbstractBarSeries::labelsFormat + The format used for showing labels in series. + + \sa QAbstractBarSeries::labelsFormat, labelsVisible, labelsPosition +*/ +/*! + \fn void QAbstractBarSeries::labelsFormatChanged(const QString &format) + Signal is emitted when the \a format of data value labels is changed. +*/ +/*! + \qmlsignal XYSeries::onLabelsFormatChanged(string format) + Signal is emitted when the \a format of data value labels is changed. +*/ + +/*! + \enum QAbstractBarSeries::LabelsPosition + + This enum describes the position of the data value labels. + + \value LabelsCenter Label is in the center of the bar. + \value LabelsInsideEnd Label is inside the bar at the high end of it. + \value LabelsInsideBase Label is inside the bar at the low end of it. + \value LabelsOutsideEnd Label is outside the bar at the high end of it. + */ + +/*! + \property QAbstractBarSeries::labelsPosition + Defines the \a position of value labels. + + \sa QAbstractBarSeries::labelsVisible, QAbstractBarSeries::labelsFormat +*/ +/*! + \qmlproperty string AbstractBarSeries::labelsPosition + Defines the \a position of value labels. + + \sa labelsVisible, labelsFormat +*/ +/*! + \fn void QAbstractBarSeries::labelsPositionChanged(QAbstractBarSeries::LabelsPosition position) + Signal is emitted when the \a position of value labels is changed. +*/ +/*! + \qmlsignal AbstractBarSeries::onLabelsPositionChanged(LabelsPosition position) + Signal is emitted when the \a position of value labels is changed. +*/ + +/*! \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. Clicked bar inside set is indexed by \a index @@ -421,6 +490,36 @@ bool QAbstractBarSeries::isLabelsVisible() const return d->m_labelsVisible; } +void QAbstractBarSeries::setLabelsFormat(const QString &format) +{ + Q_D(QAbstractBarSeries); + if (d->m_labelsFormat != format) { + d->m_labelsFormat = format; + emit labelsFormatChanged(format); + } +} + +QString QAbstractBarSeries::labelsFormat() const +{ + Q_D(const QAbstractBarSeries); + return d->m_labelsFormat; +} + +void QAbstractBarSeries::setLabelsPosition(QAbstractBarSeries::LabelsPosition position) +{ + Q_D(QAbstractBarSeries); + if (d->m_labelsPosition != position) { + d->m_labelsPosition = position; + emit labelsPositionChanged(position); + } +} + +QAbstractBarSeries::LabelsPosition QAbstractBarSeries::labelsPosition() const +{ + Q_D(const QAbstractBarSeries); + return d->m_labelsPosition; +} + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : @@ -428,7 +527,9 @@ QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : m_barWidth(0.5), // Default value is 50% of category width m_labelsVisible(false), m_visible(true), - m_blockBarUpdate(false) + m_blockBarUpdate(false), + m_labelsFormat(), + m_labelsPosition(QAbstractBarSeries::LabelsCenter) { } diff --git a/src/barchart/qabstractbarseries.h b/src/barchart/qabstractbarseries.h index 6d35ce3..93627f6 100644 --- a/src/barchart/qabstractbarseries.h +++ b/src/barchart/qabstractbarseries.h @@ -36,6 +36,19 @@ class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) + Q_PROPERTY(QString labelsFormat READ labelsFormat WRITE setLabelsFormat + NOTIFY labelsFormatChanged) + Q_PROPERTY(LabelsPosition labelsPosition READ labelsPosition + WRITE setLabelsPosition NOTIFY labelsPositionChanged) + Q_ENUMS(LabelsPosition) + +public: + enum LabelsPosition { + LabelsCenter = 0, + LabelsInsideEnd, + LabelsInsideBase, + LabelsOutsideEnd + }; public: virtual ~QAbstractBarSeries(); @@ -55,6 +68,12 @@ public: void setLabelsVisible(bool visible = true); bool isLabelsVisible() const; + void setLabelsFormat(const QString &format); + QString labelsFormat() const; + + void setLabelsPosition(QAbstractBarSeries::LabelsPosition position); + QAbstractBarSeries::LabelsPosition labelsPosition() const; + protected: explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent = 0); @@ -64,6 +83,8 @@ Q_SIGNALS: void hovered(bool status, int index, QBarSet *barset); void countChanged(); void labelsVisibleChanged(); + void labelsFormatChanged(const QString &format); + void labelsPositionChanged(QAbstractBarSeries::LabelsPosition position); void barsetsAdded(QList sets); void barsetsRemoved(QList sets); diff --git a/src/barchart/qabstractbarseries_p.h b/src/barchart/qabstractbarseries_p.h index f2bd2ce..0cedc33 100644 --- a/src/barchart/qabstractbarseries_p.h +++ b/src/barchart/qabstractbarseries_p.h @@ -104,6 +104,8 @@ protected: bool m_labelsVisible; bool m_visible; bool m_blockBarUpdate; + QString m_labelsFormat; + QAbstractBarSeries::LabelsPosition m_labelsPosition; private: Q_DECLARE_PUBLIC(QAbstractBarSeries) diff --git a/src/barchart/vertical/bar/barchartitem.cpp b/src/barchart/vertical/bar/barchartitem.cpp index e9258ae..eae5be1 100644 --- a/src/barchart/vertical/bar/barchartitem.cpp +++ b/src/barchart/vertical/bar/barchartitem.cpp @@ -29,6 +29,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : AbstractBarChartItem(series, item) { + connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)), + this, SLOT(handleLabelsPositionChanged())); + connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels())); } void BarChartItem::initializeLayout() @@ -86,9 +89,36 @@ QVector BarChartItem::calculateLayout() layout.append(rect.normalized()); } } + return layout; } +void BarChartItem::handleLabelsPositionChanged() +{ + positionLabels(); +} + +void BarChartItem::positionLabels() +{ + for (int i = 0; i < m_layout.count(); i++) { + QGraphicsTextItem *label = m_labels.at(i); + qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x(); + qreal yPos = 0; + + if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter) + yPos = m_layout.at(i).center().y() - label->boundingRect().center().y(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd) + yPos = m_layout.at(i).top(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase) + yPos = m_layout.at(i).bottom() - label->boundingRect().height(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd) + yPos = m_layout.at(i).top() - label->boundingRect().height(); + + label->setPos(xPos, yPos); + label->setZValue(zValue() + 1); + } +} + #include "moc_barchartitem_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/bar/barchartitem_p.h b/src/barchart/vertical/bar/barchartitem_p.h index 7d37fd1..b94e9c3 100644 --- a/src/barchart/vertical/bar/barchartitem_p.h +++ b/src/barchart/vertical/bar/barchartitem_p.h @@ -43,6 +43,10 @@ class BarChartItem : public AbstractBarChartItem public: BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); +private slots: + void handleLabelsPositionChanged(); + void positionLabels(); + private: virtual QVector calculateLayout(); void initializeLayout(); diff --git a/src/barchart/vertical/percent/percentbarchartitem.cpp b/src/barchart/vertical/percent/percentbarchartitem.cpp index 45875e2..1c595e9 100644 --- a/src/barchart/vertical/percent/percentbarchartitem.cpp +++ b/src/barchart/vertical/percent/percentbarchartitem.cpp @@ -29,6 +29,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : AbstractBarChartItem(series, item) { + connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)), + this, SLOT(handleLabelsPositionChanged())); + connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels())); } void PercentBarChartItem::initializeLayout() @@ -99,6 +102,7 @@ void PercentBarChartItem::handleUpdatedBars() int categoryCount = m_series->d_func()->categoryCount(); int setCount = m_series->count(); int itemIndex(0); + static const QString valueTag(QLatin1String("@value")); for (int category = 0; category < categoryCount; category++) { for (int set = 0; set < setCount; set++) { @@ -113,7 +117,14 @@ void PercentBarChartItem::handleUpdatedBars() QString vString(QString::number(p)); vString.truncate(3); vString.append("%"); - label->setHtml(vString); + QString valueLabel; + if (m_series->labelsFormat().isEmpty()) { + valueLabel = vString; + } else { + valueLabel = m_series->labelsFormat(); + valueLabel.replace(valueTag, QString::number(barSet->value(category))); + } + label->setHtml(valueLabel); label->setFont(barSet->m_labelFont); label->setDefaultTextColor(barSet->m_labelBrush.color()); label->update(); @@ -122,6 +133,32 @@ void PercentBarChartItem::handleUpdatedBars() } } +void PercentBarChartItem::handleLabelsPositionChanged() +{ + positionLabels(); +} + +void PercentBarChartItem::positionLabels() +{ + for (int i = 0; i < m_layout.count(); i++) { + QGraphicsTextItem *label = m_labels.at(i); + qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x(); + qreal yPos = 0; + + if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter) + yPos = m_layout.at(i).center().y() - label->boundingRect().center().y(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd) + yPos = m_layout.at(i).top(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase) + yPos = m_layout.at(i).bottom() - label->boundingRect().height(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd) + yPos = m_layout.at(i).top() - label->boundingRect().height(); + + label->setPos(xPos, yPos); + label->setZValue(zValue() + 1); + } +} + #include "moc_percentbarchartitem_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/percent/percentbarchartitem_p.h b/src/barchart/vertical/percent/percentbarchartitem_p.h index 2656c3a..da9fb89 100644 --- a/src/barchart/vertical/percent/percentbarchartitem_p.h +++ b/src/barchart/vertical/percent/percentbarchartitem_p.h @@ -45,6 +45,10 @@ public: PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); void handleUpdatedBars(); +private slots: + void handleLabelsPositionChanged(); + void positionLabels(); + private: virtual QVector calculateLayout(); void initializeLayout(); diff --git a/src/barchart/vertical/stacked/stackedbarchartitem.cpp b/src/barchart/vertical/stacked/stackedbarchartitem.cpp index 7c11870..8232919 100644 --- a/src/barchart/vertical/stacked/stackedbarchartitem.cpp +++ b/src/barchart/vertical/stacked/stackedbarchartitem.cpp @@ -29,6 +29,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : AbstractBarChartItem(series, item) { + connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)), + this, SLOT(handleLabelsPositionChanged())); + connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels())); } void StackedBarChartItem::initializeLayout() @@ -102,6 +105,32 @@ QVector StackedBarChartItem::calculateLayout() return layout; } +void StackedBarChartItem::handleLabelsPositionChanged() +{ + positionLabels(); +} + +void StackedBarChartItem::positionLabels() +{ + for (int i = 0; i < m_layout.count(); i++) { + QGraphicsTextItem *label = m_labels.at(i); + qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x(); + qreal yPos = 0; + + if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter) + yPos = m_layout.at(i).center().y() - label->boundingRect().center().y(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd) + yPos = m_layout.at(i).top(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase) + yPos = m_layout.at(i).bottom() - label->boundingRect().height(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd) + yPos = m_layout.at(i).top() - label->boundingRect().height(); + + label->setPos(xPos, yPos); + label->setZValue(zValue() + 1); + } +} + #include "moc_stackedbarchartitem_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/stacked/stackedbarchartitem_p.h b/src/barchart/vertical/stacked/stackedbarchartitem_p.h index a85b98c..f6f645a 100644 --- a/src/barchart/vertical/stacked/stackedbarchartitem_p.h +++ b/src/barchart/vertical/stacked/stackedbarchartitem_p.h @@ -43,6 +43,10 @@ class StackedBarChartItem : public AbstractBarChartItem public: StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item =0); +private slots: + void handleLabelsPositionChanged(); + void positionLabels(); + private: virtual QVector calculateLayout(); void initializeLayout(); diff --git a/src/linechart/linechartitem.cpp b/src/linechart/linechartitem.cpp index ad942c9..4aa154e 100644 --- a/src/linechart/linechartitem.cpp +++ b/src/linechart/linechartitem.cpp @@ -23,6 +23,8 @@ #include "qlineseries_p.h" #include "chartpresenter_p.h" #include "polardomain_p.h" +#include "chartthememanager_p.h" +#include "charttheme_p.h" #include #include @@ -34,13 +36,23 @@ LineChartItem::LineChartItem(QLineSeries *series, QGraphicsItem *item) : XYChart(series,item), m_series(series), m_pointsVisible(false), - m_chartType(QChart::ChartTypeUndefined) + m_chartType(QChart::ChartTypeUndefined), + m_pointLabelsFormat(series->pointLabelsFormat()), + m_pointLabelsVisible(false), + m_pointLabelsFont(series->pointLabelsFont()), + m_pointLabelsColor(series->pointLabelsColor()) { setAcceptHoverEvents(true); setZValue(ChartPresenter::LineChartZValue); QObject::connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); QObject::connect(series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsFormatChanged(QString)), + this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsVisibilityChanged(bool)), + this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated())); handleUpdated(); } @@ -300,7 +312,7 @@ void LineChartItem::updateGeometry() void LineChartItem::handleUpdated() { - // If points visiblity has changed, a geometry update is needed. + // If points visibility has changed, a geometry update is needed. // Also, if pen changes when points are visible, geometry update is needed. bool doGeometryUpdate = (m_pointsVisible != m_series->pointsVisible()) @@ -309,6 +321,10 @@ void LineChartItem::handleUpdated() setOpacity(m_series->opacity()); m_pointsVisible = m_series->pointsVisible(); m_linePen = m_series->pen(); + m_pointLabelsFormat = m_series->pointLabelsFormat(); + m_pointLabelsVisible = m_series->pointLabelsVisible(); + m_pointLabelsFont = m_series->pointLabelsFont(); + m_pointLabelsColor = m_series->pointLabelsColor(); if (doGeometryUpdate) updateGeometry(); update(); @@ -357,7 +373,11 @@ void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt } } + if (m_pointLabelsVisible) + m_series->d_func()->drawSeriesPointLabels(painter, m_points); + painter->restore(); + } void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/src/linechart/linechartitem_p.h b/src/linechart/linechartitem_p.h index b7ba731..f127247 100644 --- a/src/linechart/linechartitem_p.h +++ b/src/linechart/linechartitem_p.h @@ -79,6 +79,11 @@ private: QPen m_linePen; bool m_pointsVisible; QChart::ChartType m_chartType; + + bool m_pointLabelsVisible; + QString m_pointLabelsFormat; + QFont m_pointLabelsFont; + QColor m_pointLabelsColor; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/linechart/qlineseries.cpp b/src/linechart/qlineseries.cpp index 4d4f0f1..6fe7719 100644 --- a/src/linechart/qlineseries.cpp +++ b/src/linechart/qlineseries.cpp @@ -160,6 +160,11 @@ void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forc pen.setWidthF(2); q->setPen(pen); } + + if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { + QColor color = theme->labelBrush().color(); + q->setPointLabelsColor(color); + } } #include "moc_qlineseries.cpp" diff --git a/src/scatterchart/qscatterseries.cpp b/src/scatterchart/qscatterseries.cpp index ea62f12..f5805e2 100644 --- a/src/scatterchart/qscatterseries.cpp +++ b/src/scatterchart/qscatterseries.cpp @@ -306,6 +306,11 @@ void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool f QBrush brush(colors.at(index % colors.size())); q->setBrush(brush); } + + if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { + QColor color = theme->labelBrush().color(); + q->setPointLabelsColor(color); + } } void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) diff --git a/src/scatterchart/scatterchartitem.cpp b/src/scatterchart/scatterchartitem.cpp index d9d637d..cb7ebc6 100644 --- a/src/scatterchart/scatterchartitem.cpp +++ b/src/scatterchart/scatterchartitem.cpp @@ -37,11 +37,21 @@ ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item) m_items(this), m_visible(true), m_shape(QScatterSeries::MarkerShapeRectangle), - m_size(15) + m_size(15), + m_pointLabelsFormat(series->pointLabelsFormat()), + m_pointLabelsVisible(false), + m_pointLabelsFont(series->pointLabelsFont()), + m_pointLabelsColor(series->pointLabelsColor()) { QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsFormatChanged(QString)), + this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsVisibilityChanged(bool)), + this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated())); setZValue(ChartPresenter::ScatterSeriesZValue); setFlags(QGraphicsItem::ItemClipsChildrenToShape); @@ -160,9 +170,18 @@ void ScatterChartItem::updateGeometry() void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - Q_UNUSED(painter) Q_UNUSED(option) Q_UNUSED(widget) + + QRectF clipRect = QRectF(QPointF(0, 0), domain()->size()); + + painter->save(); + painter->setClipRect(clipRect); + + if (m_pointLabelsVisible) + m_series->d_func()->drawSeriesPointLabels(painter, m_points); + + painter->restore(); } void ScatterChartItem::setPen(const QPen &pen) @@ -192,6 +211,10 @@ void ScatterChartItem::handleUpdated() m_size = m_series->markerSize(); m_shape = m_series->markerShape(); setOpacity(m_series->opacity()); + m_pointLabelsFormat = m_series->pointLabelsFormat(); + m_pointLabelsVisible = m_series->pointLabelsVisible(); + m_pointLabelsFont = m_series->pointLabelsFont(); + m_pointLabelsColor = m_series->pointLabelsColor(); if (recreate) { deletePoints(count); diff --git a/src/scatterchart/scatterchartitem_p.h b/src/scatterchart/scatterchartitem_p.h index b08bfa6..4c5e9f2 100644 --- a/src/scatterchart/scatterchartitem_p.h +++ b/src/scatterchart/scatterchartitem_p.h @@ -75,6 +75,11 @@ private: int m_size; QRectF m_rect; QMap m_markerMap; + + bool m_pointLabelsVisible; + QString m_pointLabelsFormat; + QFont m_pointLabelsFont; + QColor m_pointLabelsColor; }; class CircleMarker: public QGraphicsEllipseItem diff --git a/src/splinechart/qsplineseries.cpp b/src/splinechart/qsplineseries.cpp index a4b6543..b8c9d58 100644 --- a/src/splinechart/qsplineseries.cpp +++ b/src/splinechart/qsplineseries.cpp @@ -137,6 +137,11 @@ void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool fo pen.setWidthF(2); q->setPen(pen); } + + if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { + QColor color = theme->labelBrush().color(); + q->setPointLabelsColor(color); + } } void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) diff --git a/src/splinechart/splinechartitem.cpp b/src/splinechart/splinechartitem.cpp index 5e244e7..11554c3 100644 --- a/src/splinechart/splinechartitem.cpp +++ b/src/splinechart/splinechartitem.cpp @@ -32,13 +32,23 @@ SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem *item) : XYChart(series,item), m_series(series), m_pointsVisible(false), - m_animation(0) + m_animation(0), + m_pointLabelsFormat(series->pointLabelsFormat()), + m_pointLabelsVisible(false), + m_pointLabelsFont(series->pointLabelsFont()), + m_pointLabelsColor(series->pointLabelsColor()) { setAcceptHoverEvents(true); setZValue(ChartPresenter::SplineChartZValue); QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated())); QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); QObject::connect(series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsFormatChanged(QString)), + this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsVisibilityChanged(bool)), + this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated())); + QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated())); handleUpdated(); } @@ -400,6 +410,10 @@ void SplineChartItem::handleUpdated() m_linePen = m_series->pen(); m_pointPen = m_series->pen(); m_pointPen.setWidthF(2 * m_pointPen.width()); + m_pointLabelsFormat = m_series->pointLabelsFormat(); + m_pointLabelsVisible = m_series->pointLabelsVisible(); + m_pointLabelsFont = m_series->pointLabelsFont(); + m_pointLabelsColor = m_series->pointLabelsColor(); update(); } @@ -442,6 +456,9 @@ void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->drawPoints(geometryPoints()); } + if (m_pointLabelsVisible) + m_series->d_func()->drawSeriesPointLabels(painter, m_points); + painter->restore(); } diff --git a/src/splinechart/splinechartitem_p.h b/src/splinechart/splinechartitem_p.h index c8fa558..e171f26 100644 --- a/src/splinechart/splinechartitem_p.h +++ b/src/splinechart/splinechartitem_p.h @@ -81,6 +81,11 @@ private: QVector m_visiblePoints; SplineAnimation *m_animation; + bool m_pointLabelsVisible; + QString m_pointLabelsFormat; + QFont m_pointLabelsFont; + QColor m_pointLabelsColor; + friend class SplineAnimation; }; diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index a879805..6c56a7b 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -26,6 +26,7 @@ #include "qxylegendmarker.h" #include "charthelpers_p.h" #include "qchart_p.h" +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -124,6 +125,110 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \property QXYSeries::pointLabelsFormat + The \a format used for showing labels with series points. + + QXYSeries supports the following format tags: + \table + \row + \li @xPoint \li The x value of the data point + \row + \li @yPoint \li The y value of the data point + \endtable + + For example, the following usage of the format tags would produce labels that have the data + point (x, y) shown inside brackets separated by a comma: + \code + series->setPointLabelsFormat("(@xPoint, @yPoint)"); + \endcode + + By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot + area, labels on the edge of the plot area are cut. If the points are close to each other the + labels may overlap. + + \sa QXYSeries::pointLabelsVisible, QXYSeries::pointLabelsFont, QXYSeries::pointLabelsColor +*/ +/*! + \qmlproperty string XYSeries::pointLabelsFormat + The \a format used for showing labels with series points. + + \sa QXYSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor +*/ +/*! + \fn void QXYSeries::pointLabelsFormatChanged(const QString &format) + Signal is emitted when the \a format of data point labels is changed. +*/ +/*! + \qmlsignal XYSeries::onPointLabelsFormatChanged(string format) + Signal is emitted when the \a format of data point labels is changed. +*/ + +/*! + \property QXYSeries::pointLabelsVisible + Defines the visibility for data point labels. False by default. + + \sa QXYSeries::pointLabelsFormat +*/ +/*! + \qmlproperty bool XYSeries::pointLabelsVisible + Defines the visibility for data point labels. + + \sa pointLabelsFormat +*/ +/*! + \fn void QXYSeries::pointLabelsVisibilityChanged(bool visible) + The visibility of the data point labels is changed to \a visible. +*/ +/*! + \qmlsignal XYSeries::onPointLabelsVisibilityChanged(bool visible) + The visibility of the data point labels is changed to \a visible. +*/ + +/*! + \property QXYSeries::pointLabelsFont + Defines the font used for data point labels. + + \sa QXYSeries::pointLabelsFormat +*/ +/*! + \qmlproperty font XYSeries::pointLabelsFont + Defines the font used for data point labels. + + \sa pointLabelsFormat +*/ +/*! + \fn void QXYSeries::pointLabelsFontChanged(const QFont &font); + The font used for data point labels is changed to \a font. +*/ +/*! + \qmlsignal XYSeries::onPointLabelsFontChanged(Font font) + The font used for data point labels is changed to \a font. +*/ + +/*! + \property QXYSeries::pointLabelsColor + Defines the color used for data point labels. By default, the color is the color of the brush + defined in theme for labels. + + \sa QXYSeries::pointLabelsFormat +*/ +/*! + \qmlproperty font XYSeries::pointLabelsColor + Defines the color used for data point labels. By default, the color is the color of the brush + defined in theme for labels. + + \sa pointLabelsFormat +*/ +/*! + \fn void QXYSeries::pointLabelsColorChanged(const QColor &color); + The color used for data point labels is changed to \a color. +*/ +/*! + \qmlsignal XYSeries::onPointLabelsColorChanged(Color color) + The color used for data point labels is changed to \a color. +*/ + +/*! \fn void QXYSeries::clicked(const QPointF& point) \brief Signal is emitted when user clicks the \a point on chart. */ @@ -499,6 +604,68 @@ bool QXYSeries::pointsVisible() const return d->m_pointsVisible; } +void QXYSeries::setPointLabelsFormat(const QString &format) +{ + Q_D(QXYSeries); + if (d->m_pointLabelsFormat != format) { + d->m_pointLabelsFormat = format; + emit pointLabelsFormatChanged(format); + } +} + +QString QXYSeries::pointLabelsFormat() const +{ + Q_D(const QXYSeries); + return d->m_pointLabelsFormat; +} + +void QXYSeries::setPointLabelsVisible(bool visible) +{ + Q_D(QXYSeries); + if (d->m_pointLabelsVisible != visible) { + d->m_pointLabelsVisible = visible; + emit pointLabelsVisibilityChanged(visible); + } +} + +bool QXYSeries::pointLabelsVisible() const +{ + Q_D(const QXYSeries); + return d->m_pointLabelsVisible; +} + +void QXYSeries::setPointLabelsFont(const QFont &font) +{ + Q_D(QXYSeries); + if (d->m_pointLabelsFont != font) { + d->m_pointLabelsFont = font; + emit pointLabelsFontChanged(font); + } +} + +QFont QXYSeries::pointLabelsFont() const +{ + Q_D(const QXYSeries); + return d->m_pointLabelsFont; +} + +void QXYSeries::setPointLabelsColor(const QColor &color) +{ + Q_D(QXYSeries); + if (d->m_pointLabelsColor != color) { + d->m_pointLabelsColor = color; + emit pointLabelsColorChanged(color); + } +} + +QColor QXYSeries::pointLabelsColor() const +{ + Q_D(const QXYSeries); + if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color()) + return QPen().color(); + else + return d->m_pointLabelsColor; +} /*! Stream operator for adding a data \a point to the series. @@ -529,7 +696,11 @@ QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q), m_pen(QChartPrivate::defaultPen()), m_brush(QChartPrivate::defaultBrush()), - m_pointsVisible(false) + m_pointsVisible(false), + m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")), + m_pointLabelsVisible(false), + m_pointLabelsFont(QChartPrivate::defaultFont()), + m_pointLabelsColor(QChartPrivate::defaultPen().color()) { } @@ -601,6 +772,31 @@ void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::Animation QAbstractSeriesPrivate::initializeAnimations(options); } +void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVector &points) +{ + static const QString xPointTag(QLatin1String("@xPoint")); + static const QString yPointTag(QLatin1String("@yPoint")); + const int labelOffset = 2; + + painter->setFont(m_pointLabelsFont); + painter->setPen(QPen(m_pointLabelsColor)); + QFontMetrics fm(painter->font()); + + for (int i(0); i < m_points.size(); i++) { + QString pointLabel = m_pointLabelsFormat; + pointLabel.replace(xPointTag, QString::number(m_points.at(i).x())); + pointLabel.replace(yPointTag, QString::number(m_points.at(i).y())); + + // Position text in relation to the point + int pointLabelWidth = fm.width(pointLabel); + QPointF position(points.at(i)); + position.setX(position.x() - pointLabelWidth / 2); + position.setY(position.y() - painter->pen().width() / 2 - labelOffset); + + painter->drawText(position, pointLabel); + } +} + #include "moc_qxyseries.cpp" #include "moc_qxyseries_p.cpp" diff --git a/src/xychart/qxyseries.h b/src/xychart/qxyseries.h index 47739ba..1e8a721 100644 --- a/src/xychart/qxyseries.h +++ b/src/xychart/qxyseries.h @@ -38,6 +38,14 @@ class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries Q_OBJECT Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat + NOTIFY pointLabelsFormatChanged) + Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible + NOTIFY pointLabelsVisibilityChanged) + Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont + NOTIFY pointLabelsFontChanged) + Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor + NOTIFY pointLabelsColorChanged) protected: explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = 0); @@ -76,6 +84,18 @@ public: void setPointsVisible(bool visible = true); bool pointsVisible() const; + void setPointLabelsFormat(const QString &format); + QString pointLabelsFormat() const; + + void setPointLabelsVisible(bool visible = true); + bool pointLabelsVisible() const; + + void setPointLabelsFont(const QFont &font); + QFont pointLabelsFont() const; + + void setPointLabelsColor(const QColor &color); + QColor pointLabelsColor() const; + void replace(QList points); Q_SIGNALS: @@ -86,6 +106,10 @@ Q_SIGNALS: void pointAdded(int index); void colorChanged(QColor color); void pointsReplaced(); + void pointLabelsFormatChanged(const QString &format); + void pointLabelsVisibilityChanged(bool visible); + void pointLabelsFontChanged(const QFont &font); + void pointLabelsColorChanged(const QColor &color); private: Q_DECLARE_PRIVATE(QXYSeries) diff --git a/src/xychart/qxyseries_p.h b/src/xychart/qxyseries_p.h index 9086e46..64dec64 100644 --- a/src/xychart/qxyseries_p.h +++ b/src/xychart/qxyseries_p.h @@ -53,6 +53,8 @@ public: QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; QAbstractAxis* createDefaultAxis(Qt::Orientation orientation) const; + void drawSeriesPointLabels(QPainter *painter, const QVector &points); + Q_SIGNALS: void updated(); @@ -61,6 +63,10 @@ protected: QPen m_pen; QBrush m_brush; bool m_pointsVisible; + QString m_pointLabelsFormat; + bool m_pointLabelsVisible; + QFont m_pointLabelsFont; + QColor m_pointLabelsColor; private: Q_DECLARE_PUBLIC(QXYSeries) diff --git a/tests/auto/qbarseries/tst_qbarseries.cpp b/tests/auto/qbarseries/tst_qbarseries.cpp index 3dcc30d..f2c056a 100644 --- a/tests/auto/qbarseries/tst_qbarseries.cpp +++ b/tests/auto/qbarseries/tst_qbarseries.cpp @@ -29,6 +29,7 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(QBarSet*) Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition) class tst_QBarSeries : public QObject { @@ -59,6 +60,8 @@ private slots: void barSets(); void setLabelsVisible_data(); void setLabelsVisible(); + void setLabelsFormat(); + void setLabelsPosition(); void opacity(); void mouseclicked_data(); void mouseclicked(); @@ -79,6 +82,7 @@ void tst_QBarSeries::initTestCase() { qRegisterMetaType("QBarSet*"); qRegisterMetaType >("QList"); + qRegisterMetaType("QAbstractBarSeries::LabelsPosition"); } void tst_QBarSeries::cleanupTestCase() @@ -343,6 +347,60 @@ void tst_QBarSeries::setLabelsVisible() QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); } +void tst_QBarSeries::setLabelsFormat() +{ + QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString))); + QCOMPARE(m_barseries->labelsFormat(), QString()); + + QString format("(@value)"); + m_barseries->setLabelsFormat(format); + TRY_COMPARE(labelsFormatSpy.count(), 1); + QList arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == format); + QCOMPARE(m_barseries->labelsFormat(), format); + + m_barseries->setLabelsFormat(QString()); + TRY_COMPARE(labelsFormatSpy.count(), 1); + arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == QString()); + QCOMPARE(m_barseries->labelsFormat(), QString()); +} + +void tst_QBarSeries::setLabelsPosition() +{ + QSignalSpy labelsPositionSpy(m_barseries, + SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition))); + QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsCenter); + + m_barseries->setLabelsPosition(QBarSeries::LabelsInsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + QList arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QBarSeries::LabelsInsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsInsideEnd); + + m_barseries->setLabelsPosition(QBarSeries::LabelsInsideBase); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QBarSeries::LabelsInsideBase); + QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsInsideBase); + + m_barseries->setLabelsPosition(QBarSeries::LabelsOutsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QBarSeries::LabelsOutsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsOutsideEnd); + + m_barseries->setLabelsPosition(QBarSeries::LabelsCenter); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QBarSeries::LabelsCenter); + QCOMPARE(m_barseries->labelsPosition(), QBarSeries::LabelsCenter); +} + void tst_QBarSeries::opacity() { QSignalSpy opacitySpy(m_barseries, SIGNAL(opacityChanged())); diff --git a/tests/auto/qhorizontalbarseries/tst_qhorizontalbarseries.cpp b/tests/auto/qhorizontalbarseries/tst_qhorizontalbarseries.cpp index fc6c497..de5b868 100644 --- a/tests/auto/qhorizontalbarseries/tst_qhorizontalbarseries.cpp +++ b/tests/auto/qhorizontalbarseries/tst_qhorizontalbarseries.cpp @@ -28,6 +28,7 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(QBarSet*) +Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition) class tst_QHorizontalBarSeries : public QObject { @@ -56,6 +57,8 @@ private slots: void barSets(); void setLabelsVisible_data(); void setLabelsVisible(); + void setLabelsFormat(); + void setLabelsPosition(); void mouseclicked_data(); void mouseclicked(); void mousehovered_data(); @@ -73,6 +76,7 @@ private: void tst_QHorizontalBarSeries::initTestCase() { qRegisterMetaType("QBarSet*"); + qRegisterMetaType("QAbstractBarSeries::LabelsPosition"); } void tst_QHorizontalBarSeries::cleanupTestCase() @@ -308,6 +312,60 @@ void tst_QHorizontalBarSeries::setLabelsVisible() QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); } +void tst_QHorizontalBarSeries::setLabelsFormat() +{ + QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString))); + QCOMPARE(m_barseries->labelsFormat(), QString()); + + QString format("(@value)"); + m_barseries->setLabelsFormat(format); + TRY_COMPARE(labelsFormatSpy.count(), 1); + QList arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == format); + QCOMPARE(m_barseries->labelsFormat(), format); + + m_barseries->setLabelsFormat(QString()); + TRY_COMPARE(labelsFormatSpy.count(), 1); + arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == QString()); + QCOMPARE(m_barseries->labelsFormat(), QString()); +} + +void tst_QHorizontalBarSeries::setLabelsPosition() +{ + QSignalSpy labelsPositionSpy(m_barseries, + SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition))); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsCenter); + + m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsInsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + QList arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalBarSeries::LabelsInsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsInsideEnd); + + m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsInsideBase); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalBarSeries::LabelsInsideBase); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsInsideBase); + + m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsOutsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalBarSeries::LabelsOutsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsOutsideEnd); + + m_barseries->setLabelsPosition(QHorizontalBarSeries::LabelsCenter); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalBarSeries::LabelsCenter); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalBarSeries::LabelsCenter); +} + void tst_QHorizontalBarSeries::mouseclicked_data() { diff --git a/tests/auto/qhorizontalpercentbarseries/tst_qhorizontalpercentbarseries.cpp b/tests/auto/qhorizontalpercentbarseries/tst_qhorizontalpercentbarseries.cpp index 1812196..7ff2181 100644 --- a/tests/auto/qhorizontalpercentbarseries/tst_qhorizontalpercentbarseries.cpp +++ b/tests/auto/qhorizontalpercentbarseries/tst_qhorizontalpercentbarseries.cpp @@ -28,6 +28,7 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(QBarSet*) +Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition) class tst_QHorizontalPercentBarSeries : public QObject { @@ -44,6 +45,8 @@ private slots: void qhorizontalpercentbarseries(); void type_data(); void type(); + void setLabelsFormat(); + void setLabelsPosition(); void mouseclicked_data(); void mouseclicked(); void mousehovered_data(); @@ -56,6 +59,7 @@ private: void tst_QHorizontalPercentBarSeries::initTestCase() { qRegisterMetaType("QBarSet*"); + qRegisterMetaType("QAbstractBarSeries::LabelsPosition"); } void tst_QHorizontalPercentBarSeries::cleanupTestCase() @@ -93,6 +97,60 @@ void tst_QHorizontalPercentBarSeries::type() QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalPercentBar); } +void tst_QHorizontalPercentBarSeries::setLabelsFormat() +{ + QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString))); + QCOMPARE(m_barseries->labelsFormat(), QString()); + + QString format("(@value)"); + m_barseries->setLabelsFormat(format); + TRY_COMPARE(labelsFormatSpy.count(), 1); + QList arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == format); + QCOMPARE(m_barseries->labelsFormat(), format); + + m_barseries->setLabelsFormat(QString()); + TRY_COMPARE(labelsFormatSpy.count(), 1); + arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == QString()); + QCOMPARE(m_barseries->labelsFormat(), QString()); +} + +void tst_QHorizontalPercentBarSeries::setLabelsPosition() +{ + QSignalSpy labelsPositionSpy(m_barseries, + SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition))); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsCenter); + + m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsInsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + QList arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalPercentBarSeries::LabelsInsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsInsideEnd); + + m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsInsideBase); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalPercentBarSeries::LabelsInsideBase); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsInsideBase); + + m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsOutsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalPercentBarSeries::LabelsOutsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsOutsideEnd); + + m_barseries->setLabelsPosition(QHorizontalPercentBarSeries::LabelsCenter); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalPercentBarSeries::LabelsCenter); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalPercentBarSeries::LabelsCenter); +} + void tst_QHorizontalPercentBarSeries::mouseclicked_data() { diff --git a/tests/auto/qhorizontalstackedbarseries/tst_qhorizontalstackedbarseries.cpp b/tests/auto/qhorizontalstackedbarseries/tst_qhorizontalstackedbarseries.cpp index f1940c6..b25df76 100644 --- a/tests/auto/qhorizontalstackedbarseries/tst_qhorizontalstackedbarseries.cpp +++ b/tests/auto/qhorizontalstackedbarseries/tst_qhorizontalstackedbarseries.cpp @@ -28,6 +28,7 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(QBarSet*) +Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition) class tst_QHorizontalStackedBarSeries : public QObject { @@ -44,6 +45,8 @@ private slots: void qhorizontalstackedbarseries(); void type_data(); void type(); + void setLabelsFormat(); + void setLabelsPosition(); void mouseclicked_data(); void mouseclicked(); void mousehovered_data(); @@ -56,6 +59,7 @@ private: void tst_QHorizontalStackedBarSeries::initTestCase() { qRegisterMetaType("QBarSet*"); + qRegisterMetaType("QAbstractBarSeries::LabelsPosition"); } void tst_QHorizontalStackedBarSeries::cleanupTestCase() @@ -93,6 +97,60 @@ void tst_QHorizontalStackedBarSeries::type() QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalStackedBar); } +void tst_QHorizontalStackedBarSeries::setLabelsFormat() +{ + QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString))); + QCOMPARE(m_barseries->labelsFormat(), QString()); + + QString format("(@value)"); + m_barseries->setLabelsFormat(format); + TRY_COMPARE(labelsFormatSpy.count(), 1); + QList arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == format); + QCOMPARE(m_barseries->labelsFormat(), format); + + m_barseries->setLabelsFormat(QString()); + TRY_COMPARE(labelsFormatSpy.count(), 1); + arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == QString()); + QCOMPARE(m_barseries->labelsFormat(), QString()); +} + +void tst_QHorizontalStackedBarSeries::setLabelsPosition() +{ + QSignalSpy labelsPositionSpy(m_barseries, + SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition))); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsCenter); + + m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsInsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + QList arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalStackedBarSeries::LabelsInsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsInsideEnd); + + m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsInsideBase); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalStackedBarSeries::LabelsInsideBase); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsInsideBase); + + m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsOutsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalStackedBarSeries::LabelsOutsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsOutsideEnd); + + m_barseries->setLabelsPosition(QHorizontalStackedBarSeries::LabelsCenter); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QHorizontalStackedBarSeries::LabelsCenter); + QCOMPARE(m_barseries->labelsPosition(), QHorizontalStackedBarSeries::LabelsCenter); +} + void tst_QHorizontalStackedBarSeries::mouseclicked_data() { diff --git a/tests/auto/qlineseries/tst_qlineseries.cpp b/tests/auto/qlineseries/tst_qlineseries.cpp index 0781932..4d27061 100644 --- a/tests/auto/qlineseries/tst_qlineseries.cpp +++ b/tests/auto/qlineseries/tst_qlineseries.cpp @@ -75,6 +75,8 @@ void tst_QLineSeries::qlineseries() QCOMPARE(series.points(), QList()); QCOMPARE(series.pen(), QPen()); QCOMPARE(series.pointsVisible(), false); + QCOMPARE(series.pointLabelsVisible(), false); + QCOMPARE(series.pointLabelsFormat(), QLatin1String("@xPoint, @yPoint")); series.append(QList()); series.append(0.0,0.0); @@ -91,6 +93,9 @@ void tst_QLineSeries::qlineseries() series.setPen(QPen()); series.setPointsVisible(false); + series.setPointLabelsVisible(false); + series.setPointLabelsFormat(QString()); + m_chart->addSeries(&series); m_view->show(); QTest::qWaitForWindowShown(m_view); diff --git a/tests/auto/qml-qtquicktest/tst_barseries.qml b/tests/auto/qml-qtquicktest/tst_barseries.qml index 169a749..c5a5cfb 100644 --- a/tests/auto/qml-qtquicktest/tst_barseries.qml +++ b/tests/auto/qml-qtquicktest/tst_barseries.qml @@ -34,6 +34,7 @@ Rectangle { function test_properties() { compare(barSeries.barWidth, 0.5); compare(barSeries.labelsVisible, false); + compare(barSeries.labelsPosition, BarSeries.LabelsCenter); } function test_setproperties() { @@ -92,6 +93,12 @@ Rectangle { compare(barSeries.count, 0); } + function test_signals() { + labelsPositionSpy.clear(); + barSeries.labelsPosition = BarSeries.LabelsOutsideEnd; + compare(labelsPositionSpy.count, 1, "onLabelsPositionChanged") + } + function test_remove() { var setCount = 5; var valueCount = 50; @@ -136,6 +143,11 @@ Rectangle { target: barSeries signalName: "barsetsRemoved" } + SignalSpy { + id: labelsPositionSpy + target: barSeries + signalName: "labelsPositionChanged" + } } StackedBarSeries { diff --git a/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp b/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp index 569e72e..2d0cef9 100644 --- a/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp +++ b/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp @@ -28,6 +28,7 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(QBarSet*) +Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition) class tst_QPercentBarSeries : public QObject { @@ -44,6 +45,8 @@ private slots: void qpercentbarseries(); void type_data(); void type(); + void setLabelsFormat(); + void setLabelsPosition(); void mouseclicked_data(); void mouseclicked(); void mousehovered_data(); @@ -56,6 +59,7 @@ private: void tst_QPercentBarSeries::initTestCase() { qRegisterMetaType("QBarSet*"); + qRegisterMetaType("QAbstractBarSeries::LabelsPosition"); } void tst_QPercentBarSeries::cleanupTestCase() @@ -98,6 +102,60 @@ void tst_QPercentBarSeries::mouseclicked_data() } +void tst_QPercentBarSeries::setLabelsFormat() +{ + QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString))); + QCOMPARE(m_barseries->labelsFormat(), QString()); + + QString format("(@value)"); + m_barseries->setLabelsFormat(format); + TRY_COMPARE(labelsFormatSpy.count(), 1); + QList arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == format); + QCOMPARE(m_barseries->labelsFormat(), format); + + m_barseries->setLabelsFormat(QString()); + TRY_COMPARE(labelsFormatSpy.count(), 1); + arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == QString()); + QCOMPARE(m_barseries->labelsFormat(), QString()); +} + +void tst_QPercentBarSeries::setLabelsPosition() +{ + QSignalSpy labelsPositionSpy(m_barseries, + SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition))); + QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsCenter); + + m_barseries->setLabelsPosition(QPercentBarSeries::LabelsInsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + QList arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QPercentBarSeries::LabelsInsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsInsideEnd); + + m_barseries->setLabelsPosition(QPercentBarSeries::LabelsInsideBase); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QPercentBarSeries::LabelsInsideBase); + QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsInsideBase); + + m_barseries->setLabelsPosition(QPercentBarSeries::LabelsOutsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QPercentBarSeries::LabelsOutsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsOutsideEnd); + + m_barseries->setLabelsPosition(QPercentBarSeries::LabelsCenter); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QPercentBarSeries::LabelsCenter); + QCOMPARE(m_barseries->labelsPosition(), QPercentBarSeries::LabelsCenter); +} + void tst_QPercentBarSeries::mouseclicked() { SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); diff --git a/tests/auto/qstackedbarseries/tst_qstackedbarseries.cpp b/tests/auto/qstackedbarseries/tst_qstackedbarseries.cpp index 6e848a2..6285aaa 100644 --- a/tests/auto/qstackedbarseries/tst_qstackedbarseries.cpp +++ b/tests/auto/qstackedbarseries/tst_qstackedbarseries.cpp @@ -28,6 +28,7 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(QBarSet*) +Q_DECLARE_METATYPE(QAbstractBarSeries::LabelsPosition) class tst_QStackedBarSeries : public QObject { @@ -44,6 +45,8 @@ private slots: void qstackedbarseries(); void type_data(); void type(); + void setLabelsFormat(); + void setLabelsPosition(); void mouseclicked_data(); void mouseclicked(); void mousehovered_data(); @@ -56,6 +59,7 @@ private: void tst_QStackedBarSeries::initTestCase() { qRegisterMetaType("QBarSet*"); + qRegisterMetaType("QAbstractBarSeries::LabelsPosition"); } void tst_QStackedBarSeries::cleanupTestCase() @@ -93,6 +97,60 @@ void tst_QStackedBarSeries::type() QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar); } +void tst_QStackedBarSeries::setLabelsFormat() +{ + QSignalSpy labelsFormatSpy(m_barseries, SIGNAL(labelsFormatChanged(QString))); + QCOMPARE(m_barseries->labelsFormat(), QString()); + + QString format("(@value)"); + m_barseries->setLabelsFormat(format); + TRY_COMPARE(labelsFormatSpy.count(), 1); + QList arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == format); + QCOMPARE(m_barseries->labelsFormat(), format); + + m_barseries->setLabelsFormat(QString()); + TRY_COMPARE(labelsFormatSpy.count(), 1); + arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == QString()); + QCOMPARE(m_barseries->labelsFormat(), QString()); +} + +void tst_QStackedBarSeries::setLabelsPosition() +{ + QSignalSpy labelsPositionSpy(m_barseries, + SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition))); + QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsCenter); + + m_barseries->setLabelsPosition(QStackedBarSeries::LabelsInsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + QList arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QStackedBarSeries::LabelsInsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsInsideEnd); + + m_barseries->setLabelsPosition(QStackedBarSeries::LabelsInsideBase); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QStackedBarSeries::LabelsInsideBase); + QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsInsideBase); + + m_barseries->setLabelsPosition(QStackedBarSeries::LabelsOutsideEnd); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QStackedBarSeries::LabelsOutsideEnd); + QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsOutsideEnd); + + m_barseries->setLabelsPosition(QStackedBarSeries::LabelsCenter); + TRY_COMPARE(labelsPositionSpy.count(), 1); + arguments = labelsPositionSpy.takeFirst(); + QVERIFY(arguments.at(0).value() + == QStackedBarSeries::LabelsCenter); + QCOMPARE(m_barseries->labelsPosition(), QStackedBarSeries::LabelsCenter); +} + void tst_QStackedBarSeries::mouseclicked_data() { diff --git a/tests/auto/qxyseries/tst_qxyseries.cpp b/tests/auto/qxyseries/tst_qxyseries.cpp index 34c4f5f..c0721a3 100644 --- a/tests/auto/qxyseries/tst_qxyseries.cpp +++ b/tests/auto/qxyseries/tst_qxyseries.cpp @@ -81,6 +81,78 @@ void tst_QXYSeries::seriesOpacity() QCOMPARE(opacitySpy.count(), 3); } +void tst_QXYSeries::pointLabelsFormat() +{ + QSignalSpy labelsFormatSpy(m_series, SIGNAL(pointLabelsFormatChanged(QString))); + QCOMPARE(m_series->pointLabelsFormat(), QLatin1String("@xPoint, @yPoint")); + + QString format("@yPoint"); + m_series->setPointLabelsFormat(format); + TRY_COMPARE(labelsFormatSpy.count(), 1); + QList arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == format); + + m_series->setPointLabelsFormat(QString()); + TRY_COMPARE(labelsFormatSpy.count(), 1); + arguments = labelsFormatSpy.takeFirst(); + QVERIFY(arguments.at(0).toString() == QString()); + +} + +void tst_QXYSeries::pointLabelsVisible() +{ + QSignalSpy labelsVisibleSpy(m_series, SIGNAL(pointLabelsVisibilityChanged(bool))); + QCOMPARE(m_series->pointLabelsVisible(), false); + + m_series->setPointLabelsVisible(); + QCOMPARE(m_series->pointLabelsVisible(), true); + TRY_COMPARE(labelsVisibleSpy.count(), 1); + QList arguments = labelsVisibleSpy.takeFirst(); + QVERIFY(arguments.at(0).toBool() == true); + + m_series->setPointLabelsVisible(false); + QCOMPARE(m_series->pointLabelsVisible(), false); + TRY_COMPARE(labelsVisibleSpy.count(), 1); + arguments = labelsVisibleSpy.takeFirst(); + QVERIFY(arguments.at(0).toBool() == false); +} + +void tst_QXYSeries::pointLabelsFont() +{ + QFont defaultFont(m_series->pointLabelsFont()); + QSignalSpy labelsFontSpy(m_series, SIGNAL(pointLabelsFontChanged(QFont))); + + QFont font("Times", 10); + m_series->setPointLabelsFont(font); + TRY_COMPARE(labelsFontSpy.count(), 1); + QList arguments = labelsFontSpy.takeFirst(); + QVERIFY(arguments.at(0).value() == font); + + m_series->setPointLabelsFont(defaultFont); + TRY_COMPARE(labelsFontSpy.count(), 1); + arguments = labelsFontSpy.takeFirst(); + QVERIFY(arguments.at(0).value() == defaultFont); + +} + +void tst_QXYSeries::pointLabelsColor() +{ + QColor defaultColor(QPen().color()); + QSignalSpy labelsColorSpy(m_series, SIGNAL(pointLabelsColorChanged(QColor))); + QCOMPARE(m_series->pointLabelsColor(), defaultColor); + + QColor color(Qt::blue); + m_series->setPointLabelsColor(color); + TRY_COMPARE(labelsColorSpy.count(), 1); + QList arguments = labelsColorSpy.takeFirst(); + QVERIFY(arguments.at(0).value() == color); + + m_series->setPointLabelsColor(defaultColor); + TRY_COMPARE(labelsColorSpy.count(), 1); + arguments = labelsColorSpy.takeFirst(); + QVERIFY(arguments.at(0).value() == defaultColor); +} + void tst_QXYSeries::append_data() { QTest::addColumn< QList >("points"); diff --git a/tests/auto/qxyseries/tst_qxyseries.h b/tests/auto/qxyseries/tst_qxyseries.h index 701f682..0fad782 100644 --- a/tests/auto/qxyseries/tst_qxyseries.h +++ b/tests/auto/qxyseries/tst_qxyseries.h @@ -42,6 +42,10 @@ public slots: private slots: void seriesName(); void seriesVisible(); + void pointLabelsFormat(); + void pointLabelsVisible(); + void pointLabelsFont(); + void pointLabelsColor(); void seriesOpacity(); void oper_data(); void oper(); diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml index 51c37ca..46959f7 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "area series" @@ -61,6 +61,8 @@ ChartView { XYPoint { x: 11; y: 0 } } + pointLabelsFormat: "@xPoint, @yPoint"; + onNameChanged: console.log(name + ".onNameChanged: " + name); onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible); onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); @@ -71,6 +73,14 @@ ChartView { onBorderWidthChanged: console.log(name + ".onBorderChanged: " + borderWidth); // onCountChanged: console.log(name + ".onCountChanged: " + count); onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state); + onPointLabelsVisibilityChanged: console.log(name + ".onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log(name + ".onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log(name + ".onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: " + + color); } AreaSeries { diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/AreaEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/AreaEditor.qml index d7b3478..69b2761 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/AreaEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/AreaEditor.qml @@ -55,6 +55,32 @@ Flow { onClicked: series.borderWidth -= 0.5; } Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { id: upperButton text: "upper series" unpressedColor: "#79bd8f" diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml index a7fc489..d0e3432 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Bar series" @@ -34,6 +34,7 @@ ChartView { BarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -62,5 +63,14 @@ ChartView { + " " + index); onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("barSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("barSeries.onLabelsFormatChanged: " + format); + onLabelsPositionChanged: console.log("barSeries.onLabelsPositionChanged: " + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml index 1a4cad6..439d7f9 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml @@ -172,6 +172,19 @@ Row { onClicked: series.labelsVisible = !series.labelsVisible; } Button { + text: "labels format" + onClicked: { + if (series.labelsFormat === "@value") + series.labelsFormat = "@value%" + else + series.labelsFormat = "@value" + } + } + Button { + text: "labels position" + onClicked: series.changeLabelsPosition(); + } + Button { text: "set 1 label color" onClicked: series.at(0).labelColor = main.nextColor(); } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalBarChart.qml index 7ceaa96..7d24d2e 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Bar series" @@ -33,6 +33,7 @@ ChartView { HorizontalBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -61,5 +62,16 @@ ChartView { + status + " " + index); onLabelsVisibleChanged: console.log("horizontalBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("horizontalBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("horizontalBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("horizontalBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalPercentBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalPercentBarChart.qml index 2ea9963..7032488 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalPercentBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalPercentBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Percent bar series" @@ -61,5 +61,18 @@ ChartView { + " " + status + " " + index); onLabelsVisibleChanged: console.log("horizontalPercentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("horizontalPercentBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log( + "horizontalPercentBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log( + "horizontalPercentBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalStackedBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalStackedBarChart.qml index fc65186..0367037 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalStackedBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/HorizontalStackedBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Stacked bar series" @@ -33,6 +33,7 @@ ChartView { HorizontalStackedBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -61,5 +62,18 @@ ChartView { + " " + status + " " + index); onLabelsVisibleChanged: console.log("horizontalStackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("horizontalStackedBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log( + "horizontalStackedBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log( + "horizontalStackedBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml index 0402498..dedeebc 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { property variant series: lineSeries @@ -39,6 +39,8 @@ ChartView { XYPoint { x: 3.4; y: 3.0 } XYPoint { x: 4.1; y: 3.3 } + pointLabelsFormat: "@xPoint, @yPoint"; + onNameChanged: console.log("lineSeries.onNameChanged: " + name); onVisibleChanged: console.log("lineSeries.onVisibleChanged: " + visible); onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); @@ -52,6 +54,14 @@ ChartView { onCapStyleChanged: console.log("lineSeries.onCapStyleChanged: " + capStyle); onCountChanged: console.log("lineSeries.onCountChanged: " + count); onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state); + onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: " + + color); } LineSeries { diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml index 526bffc..f49dddc 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml @@ -72,6 +72,32 @@ Flow { onClicked: series.pointsVisible = !series.pointsVisible; } Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { text: "append point" onClicked: series.append(series.count - 1, series.count - 1); } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml index ce138c3..a9879c5 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Percent bar series" @@ -33,6 +33,7 @@ ChartView { PercentBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] @@ -62,5 +63,16 @@ ChartView { + " " + status + " " + index); onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("percentBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("percentBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("percentBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml index ebb3406..cd89891 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "scatter series" @@ -37,6 +37,8 @@ ChartView { XYPoint { x: 2.1; y: 1.3 } XYPoint { x: 2.5; y: 2.1 } + pointLabelsFormat: "@xPoint, @yPoint"; + onNameChanged: console.log("scatterSeries.onNameChanged: " + name); onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible); onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); @@ -48,6 +50,14 @@ ChartView { onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor); onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth); onCountChanged: console.log("scatterSeries.onCountChanged: " + count); + onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: " + + color); } ScatterSeries { diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml index 75ae946..753ab19 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml @@ -67,6 +67,32 @@ Flow { onClicked: series.markerShape = ((series.markerShape + 1) % 2); } Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { text: "append point" onClicked: series.append(series.count - 1, series.count - 1); } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml index 87d6fb5..5f534b9 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "spline series" @@ -38,6 +38,8 @@ ChartView { XYPoint { x: 3.4; y: 3.0 } XYPoint { x: 4.1; y: 3.3 } + pointLabelsFormat: "@xPoint, @yPoint"; + onNameChanged: console.log("splineSeries.onNameChanged: " + name); onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible); onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); @@ -50,6 +52,14 @@ ChartView { onStyleChanged: console.log("splineSeries.onStyleChanged: " + style); onCapStyleChanged: console.log("splineSeries.onCapStyleChanged: " + capStyle); onCountChanged: console.log("splineSeries.onCountChanged: " + count); + onPointLabelsVisibilityChanged: console.log("splineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("splineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("splineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: " + + color); } SplineSeries { diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml index 26d156b..5757a95 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Stacked bar series" @@ -33,6 +33,7 @@ ChartView { StackedBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -61,5 +62,16 @@ ChartView { + " " + status + " " + index); onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("stackedBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("stackedBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/AreaChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/AreaChart.qml index f502fe8..c942b28 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/AreaChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/AreaChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "area series" @@ -61,6 +61,8 @@ ChartView { XYPoint { x: 11; y: 0 } } + pointLabelsFormat: "@xPoint, @yPoint"; + onNameChanged: console.log(name + ".onNameChanged: " + name); onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible); onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); @@ -71,6 +73,14 @@ ChartView { onBorderWidthChanged: console.log(name + ".onBorderChanged: " + borderWidth); // onCountChanged: console.log(name + ".onCountChanged: " + count); onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state); + onPointLabelsVisibilityChanged: console.log(name + ".onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log(name + ".onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log(name + ".onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log(name + ".onPointLabelsColorChanged: " + + color); } AreaSeries { diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/AreaEditor.qml b/tests/quick2chartproperties/qml/quick2chartproperties/AreaEditor.qml index 249c7c2..168dc95 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/AreaEditor.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/AreaEditor.qml @@ -55,6 +55,32 @@ Flow { onClicked: series.borderWidth -= 0.5; } Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { id: upperButton text: "upper series" unpressedColor: "#79bd8f" diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/BarChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/BarChart.qml index 1774ef4..8a91cdb 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/BarChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/BarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Bar series" @@ -34,6 +34,7 @@ ChartView { BarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -62,5 +63,14 @@ ChartView { + " " + index); onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("barSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("barSeries.onLabelsFormatChanged: " + format); + onLabelsPositionChanged: console.log("barSeries.onLabelsPositionChanged: " + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/BarEditor.qml b/tests/quick2chartproperties/qml/quick2chartproperties/BarEditor.qml index 38b2e4b..cdd847a 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/BarEditor.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/BarEditor.qml @@ -172,6 +172,19 @@ Row { onClicked: series.labelsVisible = !series.labelsVisible; } Button { + text: "labels format" + onClicked: { + if (series.labelsFormat === "@value") + series.labelsFormat = "@value%" + else + series.labelsFormat = "@value" + } + } + Button { + text: "labels position" + onClicked: series.changeLabelsPosition(); + } + Button { text: "set 1 label color" onClicked: series.at(0).labelColor = main.nextColor(); } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalBarChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalBarChart.qml index 42ba0c8..342995c 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalBarChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Bar series" @@ -33,6 +33,7 @@ ChartView { HorizontalBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -61,5 +62,16 @@ ChartView { + status + " " + index); onLabelsVisibleChanged: console.log("horizontalBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("horizontalBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("horizontalBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("horizontalBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalPercentBarChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalPercentBarChart.qml index 8d00b76..0ef7e17 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalPercentBarChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalPercentBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Percent bar series" @@ -33,6 +33,7 @@ ChartView { HorizontalPercentBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -61,5 +62,18 @@ ChartView { + " " + status + " " + index); onLabelsVisibleChanged: console.log("horizontalPercentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("horizontalPercentBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log( + "horizontalPercentBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log( + "horizontalPercentBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalStackedBarChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalStackedBarChart.qml index e468259..c1ef51b 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalStackedBarChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/HorizontalStackedBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Stacked bar series" @@ -33,6 +33,7 @@ ChartView { HorizontalStackedBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -61,5 +62,18 @@ ChartView { + " " + status + " " + index); onLabelsVisibleChanged: console.log("horizontalStackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("horizontalStackedBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log( + "horizontalStackedBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log( + "horizontalStackedBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/LineChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/LineChart.qml index 3545c66..3190ac3 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/LineChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/LineChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { property variant series: lineSeries @@ -39,6 +39,8 @@ ChartView { XYPoint { x: 3.4; y: 3.0 } XYPoint { x: 4.1; y: 3.3 } + pointLabelsFormat: "@xPoint, @yPoint"; + onNameChanged: console.log("lineSeries.onNameChanged: " + name); onVisibleChanged: console.log("lineSeries.onVisibleChanged: " + visible); onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); @@ -52,6 +54,14 @@ ChartView { onCapStyleChanged: console.log("lineSeries.onCapStyleChanged: " + capStyle); onCountChanged: console.log("lineSeries.onCountChanged: " + count); onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state); + onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: " + + color); } LineSeries { diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/LineEditor.qml b/tests/quick2chartproperties/qml/quick2chartproperties/LineEditor.qml index f9eafed..7960b4a 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/LineEditor.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/LineEditor.qml @@ -72,6 +72,32 @@ Flow { onClicked: series.pointsVisible = !series.pointsVisible; } Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { text: "append point" onClicked: series.append(series.count - 1, series.count - 1); } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/PercentBarChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/PercentBarChart.qml index d2aa881..822a183 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/PercentBarChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/PercentBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Percent bar series" @@ -33,6 +33,7 @@ ChartView { PercentBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] @@ -62,5 +63,16 @@ ChartView { + " " + status + " " + index); onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("percentBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("percentBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("percentBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/ScatterChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/ScatterChart.qml index cd39a5c..64785d2 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/ScatterChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/ScatterChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "scatter series" @@ -37,6 +37,8 @@ ChartView { XYPoint { x: 2.1; y: 1.3 } XYPoint { x: 2.5; y: 2.1 } + pointLabelsFormat: "@xPoint, @yPoint"; + onNameChanged: console.log("scatterSeries.onNameChanged: " + name); onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible); onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); @@ -49,6 +51,14 @@ ChartView { onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor); onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth); onCountChanged: console.log("scatterSeries.onCountChanged: " + count); + onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: " + + color); } ScatterSeries { diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/ScatterEditor.qml b/tests/quick2chartproperties/qml/quick2chartproperties/ScatterEditor.qml index 23690c1..23afdb7 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/ScatterEditor.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/ScatterEditor.qml @@ -67,6 +67,32 @@ Flow { onClicked: series.markerShape = ((series.markerShape + 1) % 2); } Button { + text: "point labels visible" + onClicked: series.pointLabelsVisible = !series.pointLabelsVisible; + } + Button { + text: "point labels format" + onClicked: { + if (series.pointLabelsFormat === "@xPoint, @yPoint") + series.pointLabelsFormat = "(@xPoint)" + else + series.pointLabelsFormat = "@xPoint, @yPoint" + } + } + Button { + text: "point labels font" + onClicked: { + if (series.pointLabelsFont.family === "Times") + series.pointLabelsFont.family = "Courier"; + else + series.pointLabelsFont.family = "Times"; + } + } + Button { + text: "point labels color" + onClicked: series.pointLabelsColor = main.nextColor(); + } + Button { text: "append point" onClicked: series.append(series.count - 1, series.count - 1); } diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/SplineChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/SplineChart.qml index 840055b..e7c8793 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/SplineChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/SplineChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "spline series" @@ -38,6 +38,8 @@ ChartView { XYPoint { x: 3.4; y: 3.0 } XYPoint { x: 4.1; y: 3.3 } + pointLabelsFormat: "@xPoint, @yPoint"; + onNameChanged: console.log("splineSeries.onNameChanged: " + name); onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible); onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); @@ -51,6 +53,14 @@ ChartView { onStyleChanged: console.log("splineSeries.onStyleChanged: " + style); onCapStyleChanged: console.log("splineSeries.onCapStyleChanged: " + capStyle); onCountChanged: console.log("splineSeries.onCountChanged: " + count); + onPointLabelsVisibilityChanged: console.log("splineSeries.onPointLabelsVisibilityChanged: " + + visible); + onPointLabelsFormatChanged: console.log("splineSeries.onPointLabelsFormatChanged: " + + format); + onPointLabelsFontChanged: console.log("splineSeries.onPointLabelsFontChanged: " + + font.family); + onPointLabelsColorChanged: console.log("splineSeries.onPointLabelsColorChanged: " + + color); } SplineSeries { diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/StackedBarChart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/StackedBarChart.qml index 50adeda..0890884 100644 --- a/tests/quick2chartproperties/qml/quick2chartproperties/StackedBarChart.qml +++ b/tests/quick2chartproperties/qml/quick2chartproperties/StackedBarChart.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.4 ChartView { title: "Stacked bar series" @@ -33,6 +33,7 @@ ChartView { StackedBarSeries { id: mySeries name: "bar" + labelsFormat: "@value"; axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); @@ -61,5 +62,16 @@ ChartView { + " " + status + " " + index); onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count); + onLabelsFormatChanged: console.log("stackedBarSeries.onLabelsFormatChanged: " + + format); + onLabelsPositionChanged: console.log("stackedBarSeries.onLabelsPositionChanged: " + + series.labelsPosition); + + function changeLabelsPosition() { + if (labelsPosition === BarSeries.LabelsCenter) + labelsPosition = BarSeries.LabelsInsideEnd; + else + labelsPosition = BarSeries.LabelsCenter; + } } }