diff --git a/examples/barchart/main.cpp b/examples/barchart/main.cpp index 4e39e6e..724d8ee 100644 --- a/examples/barchart/main.cpp +++ b/examples/barchart/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) //![2] QBarSeries* series = new QBarSeries(); - series->setBarMargin(0.8); + series->setBarWidth(0.2); series->append(set0); series->append(set1); series->append(set2); diff --git a/src/barchart/barchartitem.cpp b/src/barchart/barchartitem.cpp index 129cd08..17817bb 100644 --- a/src/barchart/barchartitem.cpp +++ b/src/barchart/barchartitem.cpp @@ -113,7 +113,7 @@ QVector BarChartItem::calculateLayout() qreal rangeX = m_domainMaxX - m_domainMinX; qreal scaleY = (height / rangeY); qreal scaleX = (width / rangeX); - qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin(); + qreal barWidth = scaleX * m_series->d_func()->barWidth(); int itemIndex(0); for (int category = 0; category < categoryCount; category++) { diff --git a/src/barchart/groupedbarchartitem.cpp b/src/barchart/groupedbarchartitem.cpp index e636502..5f5f818 100644 --- a/src/barchart/groupedbarchartitem.cpp +++ b/src/barchart/groupedbarchartitem.cpp @@ -47,7 +47,7 @@ QVector GroupedBarChartItem::calculateLayout() qreal rangeX = m_domainMaxX - m_domainMinX; qreal scaleY = (height / rangeY); qreal scaleX = (width / rangeX); - qreal barWidth = scaleX / setCount - (scaleX / setCount) * m_series->d_func()->barMargin(); + qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth(); int itemIndex(0); for (int category = 0; category < categoryCount; category++) { diff --git a/src/barchart/percentbarchartitem.cpp b/src/barchart/percentbarchartitem.cpp index 72fc7be..4aa52bf 100644 --- a/src/barchart/percentbarchartitem.cpp +++ b/src/barchart/percentbarchartitem.cpp @@ -47,7 +47,7 @@ QVector PercentBarChartItem::calculateLayout() qreal rangeX = m_domainMaxX - m_domainMinX; qreal scaleY = (height / rangeY); qreal scaleX = (width / rangeX); - qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin(); + qreal barWidth = scaleX * m_series->d_func()->barWidth(); int itemIndex(0); for (int category = 0; category < categoryCount; category++) { diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 475ac2a..8d157cb 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -47,8 +47,14 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \property QBarSeries::barMargin - \brief Defines the margin around bars. + \property QBarSeries::barWidth + \brief Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars + is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen + is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. + Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is + because with grouped series it is more logical to set width of whole group and let the chart calculate correct + width for bar. + \sa QGroupedBarSeries */ /*! @@ -137,25 +143,27 @@ QAbstractSeries::SeriesType QBarSeries::type() const } /*! - Sets the margin of the bars of the series. The unit of \a margin is the unit of x-axis. Setting the margin to 0.0 - means there is no margin around the bars, making a single bar or bargroup to take one x-axis unit on the screen. - Setting margin to maximum value of 1.0 makes the bar width to exactly 1 pixel on the screen. Bars cannot be zero - width, otherwise they would not be visible at all. If you want to hide bars, use visible property of the series - instead. + Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars + is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen + is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. + Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is + because with grouped series it is more logical to set widht of whole group and let the chart calculate correct + width for bar. + \sa QGroupedBarSeries */ -void QBarSeries::setBarMargin(qreal margin) +void QBarSeries::setBarWidth(qreal width) { Q_D(QBarSeries); - d->setBarMargin(margin); + d->setBarWidth(width); } /*! - Returns the margin around bars + Returns the width of bars. */ -qreal QBarSeries::barMargin() const +qreal QBarSeries::barWidth() const { Q_D(const QBarSeries); - return d->barMargin(); + return d->barWidth(); } /*! @@ -280,7 +288,7 @@ bool QBarSeries::isLabelsVisible() const QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractSeriesPrivate(q), - m_barMargin(0.5), // Default value is 50% of category width + m_barWidth(0.5), // Default value is 50% of category width m_labelsVisible(false), m_visible(true) { @@ -336,21 +344,18 @@ QStringList QBarSeriesPrivate::categories() const return categories; } -void QBarSeriesPrivate::setBarMargin(qreal margin) +void QBarSeriesPrivate::setBarWidth(qreal width) { - if (margin > 1.0) { - margin = 1.0; - } else if (margin < 0.0) { - margin = 0.0; + if (width < 0.0) { + width = 0.0; } - - m_barMargin = margin; + m_barWidth = width; emit updatedBars(); } -qreal QBarSeriesPrivate::barMargin() const +qreal QBarSeriesPrivate::barWidth() const { - return m_barMargin; + return m_barWidth; } QBarSet* QBarSeriesPrivate::barsetAt(int index) diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 965ded3..ce87e42 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -33,7 +33,7 @@ class QBarSeriesPrivate; class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries { Q_OBJECT - Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin) + Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) Q_PROPERTY(int count READ barsetCount) Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible) @@ -43,8 +43,8 @@ public: QAbstractSeries::SeriesType type() const; - void setBarMargin(qreal margin); - qreal barMargin() const; + void setBarWidth(qreal width); + qreal barWidth() const; bool append(QBarSet *set); bool remove(QBarSet *set); diff --git a/src/barchart/qbarseries_p.h b/src/barchart/qbarseries_p.h index e8b7de9..cef1724 100644 --- a/src/barchart/qbarseries_p.h +++ b/src/barchart/qbarseries_p.h @@ -51,8 +51,8 @@ public: int categoryCount() const; QStringList categories() const; - void setBarMargin(qreal margin); - qreal barMargin() const; + void setBarWidth(qreal width); + qreal barWidth() const; void setVisible(bool visible); void setLabelsVisible(bool visible); @@ -89,7 +89,7 @@ Q_SIGNALS: protected: QList m_barSets; QStringList m_categories; - qreal m_barMargin; + qreal m_barWidth; bool m_labelsVisible; bool m_visible; diff --git a/src/barchart/stackedbarchartitem.cpp b/src/barchart/stackedbarchartitem.cpp index 0fa5023..15a7c9f 100644 --- a/src/barchart/stackedbarchartitem.cpp +++ b/src/barchart/stackedbarchartitem.cpp @@ -46,7 +46,7 @@ QVector StackedBarChartItem::calculateLayout() qreal rangeX = m_domainMaxX - m_domainMinX; qreal scaleY = (height / rangeY); qreal scaleX = (width / rangeX); - qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin(); + qreal barWidth = scaleX * m_series->d_func()->barWidth(); int itemIndex(0); for (int category = 0; category < categoryCount; category++) { diff --git a/tests/auto/qbarseries/tst_qbarseries.cpp b/tests/auto/qbarseries/tst_qbarseries.cpp index 05fb27a..72c5aed 100644 --- a/tests/auto/qbarseries/tst_qbarseries.cpp +++ b/tests/auto/qbarseries/tst_qbarseries.cpp @@ -335,7 +335,7 @@ void tst_QBarSeries::mouseclicked() //==================================================================================== // barset 1, bar 0 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,142)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); QCOMPARE(seriesSpy.count(), 1); @@ -347,7 +347,7 @@ void tst_QBarSeries::mouseclicked() //==================================================================================== // barset 1, bar 1 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(164,142)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); QCOMPARE(seriesSpy.count(), 1); @@ -359,7 +359,7 @@ void tst_QBarSeries::mouseclicked() //==================================================================================== // barset 1, bar 2 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(234,142)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); QCOMPARE(seriesSpy.count(), 1); @@ -371,7 +371,7 @@ void tst_QBarSeries::mouseclicked() //==================================================================================== // barset 2, bar 0 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(115,142)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); QCOMPARE(seriesSpy.count(), 1); @@ -383,7 +383,7 @@ void tst_QBarSeries::mouseclicked() //==================================================================================== // barset 2, bar 1 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(185,142)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); QCOMPARE(seriesSpy.count(), 1); @@ -395,7 +395,7 @@ void tst_QBarSeries::mouseclicked() //==================================================================================== // barset 2, bar 2 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(254,142)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); QCOMPARE(seriesSpy.count(), 1); @@ -414,12 +414,9 @@ void tst_QBarSeries::mousehovered_data() void tst_QBarSeries::mousehovered() { QBarSeries* series = new QBarSeries(); - QStringList categories; - categories << "test1" << "test2" << "test3"; -// series->setCategories(categories); QBarSet* set1 = new QBarSet(QString("set 1")); - *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10); + *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); series->append(set1); QBarSet* set2 = new QBarSet(QString("set 2")); @@ -445,7 +442,7 @@ void tst_QBarSeries::mousehovered() //======================================================================= // move mouse on top of set1 - QTest::mouseMove(view.viewport(), QPoint(95,142)); + QTest::mouseMove(view.viewport(), QPoint(102,142)); QVERIFY(seriesSpy.count() == 1); @@ -456,7 +453,7 @@ void tst_QBarSeries::mousehovered() //======================================================================= // move mouse from top of set1 to top of set2 - QTest::mouseMove(view.viewport(), QPoint(116,142)); + QTest::mouseMove(view.viewport(), QPoint(127,142)); QVERIFY(seriesSpy.count() == 2); @@ -474,7 +471,7 @@ void tst_QBarSeries::mousehovered() //======================================================================= // move mouse from top of set2 to background - QTest::mouseMove(view.viewport(), QPoint(116,0)); + QTest::mouseMove(view.viewport(), QPoint(127,0)); QVERIFY(seriesSpy.count() == 1); // should leave set2 @@ -486,14 +483,10 @@ void tst_QBarSeries::mousehovered() void tst_QBarSeries::clearWithAnimations() { - QSKIP("Known issue with the animation handling", SkipAll); QBarSeries* series = new QBarSeries(); - QStringList categories; - categories << "test1" << "test2" << "test3"; -// series->setCategories(categories); QBarSet* set1 = new QBarSet(QString("set 1")); - *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10); + *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); series->append(set1); QBarSet* set2 = new QBarSet(QString("set 2"));