##// END OF EJS Templates
barmargin replaced with barwidth
sauimone -
r1425:a0d2e2cf1ab3
parent child
Show More
@@ -45,7 +45,7 int main(int argc, char *argv[])
45
45
46 //![2]
46 //![2]
47 QBarSeries* series = new QBarSeries();
47 QBarSeries* series = new QBarSeries();
48 series->setBarMargin(0.8);
48 series->setBarWidth(0.2);
49 series->append(set0);
49 series->append(set0);
50 series->append(set1);
50 series->append(set1);
51 series->append(set2);
51 series->append(set2);
@@ -113,7 +113,7 QVector<QRectF> BarChartItem::calculateLayout()
113 qreal rangeX = m_domainMaxX - m_domainMinX;
113 qreal rangeX = m_domainMaxX - m_domainMinX;
114 qreal scaleY = (height / rangeY);
114 qreal scaleY = (height / rangeY);
115 qreal scaleX = (width / rangeX);
115 qreal scaleX = (width / rangeX);
116 qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin();
116 qreal barWidth = scaleX * m_series->d_func()->barWidth();
117
117
118 int itemIndex(0);
118 int itemIndex(0);
119 for (int category = 0; category < categoryCount; category++) {
119 for (int category = 0; category < categoryCount; category++) {
@@ -47,7 +47,7 QVector<QRectF> GroupedBarChartItem::calculateLayout()
47 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal scaleY = (height / rangeY);
48 qreal scaleY = (height / rangeY);
49 qreal scaleX = (width / rangeX);
49 qreal scaleX = (width / rangeX);
50 qreal barWidth = scaleX / setCount - (scaleX / setCount) * m_series->d_func()->barMargin();
50 qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
51
51
52 int itemIndex(0);
52 int itemIndex(0);
53 for (int category = 0; category < categoryCount; category++) {
53 for (int category = 0; category < categoryCount; category++) {
@@ -47,7 +47,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
47 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal scaleY = (height / rangeY);
48 qreal scaleY = (height / rangeY);
49 qreal scaleX = (width / rangeX);
49 qreal scaleX = (width / rangeX);
50 qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin();
50 qreal barWidth = scaleX * m_series->d_func()->barWidth();
51
51
52 int itemIndex(0);
52 int itemIndex(0);
53 for (int category = 0; category < categoryCount; category++) {
53 for (int category = 0; category < categoryCount; category++) {
@@ -47,8 +47,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 */
47 */
48
48
49 /*!
49 /*!
50 \property QBarSeries::barMargin
50 \property QBarSeries::barWidth
51 \brief Defines the margin around bars.
51 \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
52 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
53 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
54 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is
55 because with grouped series it is more logical to set width of whole group and let the chart calculate correct
56 width for bar.
57 \sa QGroupedBarSeries
52 */
58 */
53
59
54 /*!
60 /*!
@@ -137,25 +143,27 QAbstractSeries::SeriesType QBarSeries::type() const
137 }
143 }
138
144
139 /*!
145 /*!
140 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
146 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
141 means there is no margin around the bars, making a single bar or bargroup to take one x-axis unit on the screen.
147 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
142 Setting margin to maximum value of 1.0 makes the bar width to exactly 1 pixel on the screen. Bars cannot be zero
148 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
143 width, otherwise they would not be visible at all. If you want to hide bars, use visible property of the series
149 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is
144 instead.
150 because with grouped series it is more logical to set widht of whole group and let the chart calculate correct
151 width for bar.
152 \sa QGroupedBarSeries
145 */
153 */
146 void QBarSeries::setBarMargin(qreal margin)
154 void QBarSeries::setBarWidth(qreal width)
147 {
155 {
148 Q_D(QBarSeries);
156 Q_D(QBarSeries);
149 d->setBarMargin(margin);
157 d->setBarWidth(width);
150 }
158 }
151
159
152 /*!
160 /*!
153 Returns the margin around bars
161 Returns the width of bars.
154 */
162 */
155 qreal QBarSeries::barMargin() const
163 qreal QBarSeries::barWidth() const
156 {
164 {
157 Q_D(const QBarSeries);
165 Q_D(const QBarSeries);
158 return d->barMargin();
166 return d->barWidth();
159 }
167 }
160
168
161 /*!
169 /*!
@@ -280,7 +288,7 bool QBarSeries::isLabelsVisible() const
280
288
281 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
289 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
282 QAbstractSeriesPrivate(q),
290 QAbstractSeriesPrivate(q),
283 m_barMargin(0.5), // Default value is 50% of category width
291 m_barWidth(0.5), // Default value is 50% of category width
284 m_labelsVisible(false),
292 m_labelsVisible(false),
285 m_visible(true)
293 m_visible(true)
286 {
294 {
@@ -336,21 +344,18 QStringList QBarSeriesPrivate::categories() const
336 return categories;
344 return categories;
337 }
345 }
338
346
339 void QBarSeriesPrivate::setBarMargin(qreal margin)
347 void QBarSeriesPrivate::setBarWidth(qreal width)
340 {
348 {
341 if (margin > 1.0) {
349 if (width < 0.0) {
342 margin = 1.0;
350 width = 0.0;
343 } else if (margin < 0.0) {
344 margin = 0.0;
345 }
351 }
346
352 m_barWidth = width;
347 m_barMargin = margin;
348 emit updatedBars();
353 emit updatedBars();
349 }
354 }
350
355
351 qreal QBarSeriesPrivate::barMargin() const
356 qreal QBarSeriesPrivate::barWidth() const
352 {
357 {
353 return m_barMargin;
358 return m_barWidth;
354 }
359 }
355
360
356 QBarSet* QBarSeriesPrivate::barsetAt(int index)
361 QBarSet* QBarSeriesPrivate::barsetAt(int index)
@@ -33,7 +33,7 class QBarSeriesPrivate;
33 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
33 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin)
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 Q_PROPERTY(int count READ barsetCount)
37 Q_PROPERTY(int count READ barsetCount)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible)
39
39
@@ -43,8 +43,8 public:
43
43
44 QAbstractSeries::SeriesType type() const;
44 QAbstractSeries::SeriesType type() const;
45
45
46 void setBarMargin(qreal margin);
46 void setBarWidth(qreal width);
47 qreal barMargin() const;
47 qreal barWidth() const;
48
48
49 bool append(QBarSet *set);
49 bool append(QBarSet *set);
50 bool remove(QBarSet *set);
50 bool remove(QBarSet *set);
@@ -51,8 +51,8 public:
51 int categoryCount() const;
51 int categoryCount() const;
52 QStringList categories() const;
52 QStringList categories() const;
53
53
54 void setBarMargin(qreal margin);
54 void setBarWidth(qreal width);
55 qreal barMargin() const;
55 qreal barWidth() const;
56
56
57 void setVisible(bool visible);
57 void setVisible(bool visible);
58 void setLabelsVisible(bool visible);
58 void setLabelsVisible(bool visible);
@@ -89,7 +89,7 Q_SIGNALS:
89 protected:
89 protected:
90 QList<QBarSet *> m_barSets;
90 QList<QBarSet *> m_barSets;
91 QStringList m_categories;
91 QStringList m_categories;
92 qreal m_barMargin;
92 qreal m_barWidth;
93 bool m_labelsVisible;
93 bool m_labelsVisible;
94 bool m_visible;
94 bool m_visible;
95
95
@@ -46,7 +46,7 QVector<QRectF> StackedBarChartItem::calculateLayout()
46 qreal rangeX = m_domainMaxX - m_domainMinX;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal scaleY = (height / rangeY);
47 qreal scaleY = (height / rangeY);
48 qreal scaleX = (width / rangeX);
48 qreal scaleX = (width / rangeX);
49 qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin();
49 qreal barWidth = scaleX * m_series->d_func()->barWidth();
50
50
51 int itemIndex(0);
51 int itemIndex(0);
52 for (int category = 0; category < categoryCount; category++) {
52 for (int category = 0; category < categoryCount; category++) {
@@ -335,7 +335,7 void tst_QBarSeries::mouseclicked()
335
335
336 //====================================================================================
336 //====================================================================================
337 // barset 1, bar 0
337 // barset 1, bar 0
338 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,142));
338 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142));
339 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
339 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
340
340
341 QCOMPARE(seriesSpy.count(), 1);
341 QCOMPARE(seriesSpy.count(), 1);
@@ -347,7 +347,7 void tst_QBarSeries::mouseclicked()
347
347
348 //====================================================================================
348 //====================================================================================
349 // barset 1, bar 1
349 // barset 1, bar 1
350 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(164,142));
350 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142));
351 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
351 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
352
352
353 QCOMPARE(seriesSpy.count(), 1);
353 QCOMPARE(seriesSpy.count(), 1);
@@ -359,7 +359,7 void tst_QBarSeries::mouseclicked()
359
359
360 //====================================================================================
360 //====================================================================================
361 // barset 1, bar 2
361 // barset 1, bar 2
362 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(234,142));
362 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142));
363 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
363 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
364
364
365 QCOMPARE(seriesSpy.count(), 1);
365 QCOMPARE(seriesSpy.count(), 1);
@@ -371,7 +371,7 void tst_QBarSeries::mouseclicked()
371
371
372 //====================================================================================
372 //====================================================================================
373 // barset 2, bar 0
373 // barset 2, bar 0
374 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(115,142));
374 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142));
375 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
375 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
376
376
377 QCOMPARE(seriesSpy.count(), 1);
377 QCOMPARE(seriesSpy.count(), 1);
@@ -383,7 +383,7 void tst_QBarSeries::mouseclicked()
383
383
384 //====================================================================================
384 //====================================================================================
385 // barset 2, bar 1
385 // barset 2, bar 1
386 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(185,142));
386 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142));
387 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
387 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
388
388
389 QCOMPARE(seriesSpy.count(), 1);
389 QCOMPARE(seriesSpy.count(), 1);
@@ -395,7 +395,7 void tst_QBarSeries::mouseclicked()
395
395
396 //====================================================================================
396 //====================================================================================
397 // barset 2, bar 2
397 // barset 2, bar 2
398 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(254,142));
398 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142));
399 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
399 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
400
400
401 QCOMPARE(seriesSpy.count(), 1);
401 QCOMPARE(seriesSpy.count(), 1);
@@ -414,12 +414,9 void tst_QBarSeries::mousehovered_data()
414 void tst_QBarSeries::mousehovered()
414 void tst_QBarSeries::mousehovered()
415 {
415 {
416 QBarSeries* series = new QBarSeries();
416 QBarSeries* series = new QBarSeries();
417 QStringList categories;
418 categories << "test1" << "test2" << "test3";
419 // series->setCategories(categories);
420
417
421 QBarSet* set1 = new QBarSet(QString("set 1"));
418 QBarSet* set1 = new QBarSet(QString("set 1"));
422 *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10);
419 *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
423 series->append(set1);
420 series->append(set1);
424
421
425 QBarSet* set2 = new QBarSet(QString("set 2"));
422 QBarSet* set2 = new QBarSet(QString("set 2"));
@@ -445,7 +442,7 void tst_QBarSeries::mousehovered()
445
442
446 //=======================================================================
443 //=======================================================================
447 // move mouse on top of set1
444 // move mouse on top of set1
448 QTest::mouseMove(view.viewport(), QPoint(95,142));
445 QTest::mouseMove(view.viewport(), QPoint(102,142));
449
446
450 QVERIFY(seriesSpy.count() == 1);
447 QVERIFY(seriesSpy.count() == 1);
451
448
@@ -456,7 +453,7 void tst_QBarSeries::mousehovered()
456
453
457 //=======================================================================
454 //=======================================================================
458 // move mouse from top of set1 to top of set2
455 // move mouse from top of set1 to top of set2
459 QTest::mouseMove(view.viewport(), QPoint(116,142));
456 QTest::mouseMove(view.viewport(), QPoint(127,142));
460
457
461 QVERIFY(seriesSpy.count() == 2);
458 QVERIFY(seriesSpy.count() == 2);
462
459
@@ -474,7 +471,7 void tst_QBarSeries::mousehovered()
474
471
475 //=======================================================================
472 //=======================================================================
476 // move mouse from top of set2 to background
473 // move mouse from top of set2 to background
477 QTest::mouseMove(view.viewport(), QPoint(116,0));
474 QTest::mouseMove(view.viewport(), QPoint(127,0));
478 QVERIFY(seriesSpy.count() == 1);
475 QVERIFY(seriesSpy.count() == 1);
479
476
480 // should leave set2
477 // should leave set2
@@ -486,14 +483,10 void tst_QBarSeries::mousehovered()
486
483
487 void tst_QBarSeries::clearWithAnimations()
484 void tst_QBarSeries::clearWithAnimations()
488 {
485 {
489 QSKIP("Known issue with the animation handling", SkipAll);
490 QBarSeries* series = new QBarSeries();
486 QBarSeries* series = new QBarSeries();
491 QStringList categories;
492 categories << "test1" << "test2" << "test3";
493 // series->setCategories(categories);
494
487
495 QBarSet* set1 = new QBarSet(QString("set 1"));
488 QBarSet* set1 = new QBarSet(QString("set 1"));
496 *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10);
489 *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
497 series->append(set1);
490 series->append(set1);
498
491
499 QBarSet* set2 = new QBarSet(QString("set 2"));
492 QBarSet* set2 = new QBarSet(QString("set 2"));
General Comments 0
You need to be logged in to leave comments. Login now