##// END OF EJS Templates
Implements minimumMargins...
Michal Klocek -
r1883:fa0e7a49da94
parent child
Show More
@@ -224,22 +224,24 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
224 {
224 {
225 setFlag(QGraphicsItem::ItemHasNoContents, false);
225 setFlag(QGraphicsItem::ItemHasNoContents, false);
226 // m_chart->axisX()->setNiceNumbersEnabled(false);
226 // m_chart->axisX()->setNiceNumbersEnabled(false);
227 m_chartMargins = m_chart->margins();
227 //TODO: check what should be really here margins or platArea ?!
228 m_chartMargins = m_chart->minimumMargins();
228 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
229 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
229 }
230 }
230
231
231 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
232 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
232 {
233 {
234 //TODO: check what should be really here margins or platArea ?!
233 if (m_chartMargins.top() != newMargins.top())
235 if (m_chartMargins.top() != newMargins.top())
234 topMarginChanged(m_chart->margins().top());
236 topMarginChanged(m_chart->minimumMargins().top());
235 if (m_chartMargins.bottom() != newMargins.bottom())
237 if (m_chartMargins.bottom() != newMargins.bottom())
236 bottomMarginChanged(m_chart->margins().bottom());
238 bottomMarginChanged(m_chart->minimumMargins().bottom());
237 if (m_chartMargins.left() != newMargins.left())
239 if (m_chartMargins.left() != newMargins.left())
238 leftMarginChanged(m_chart->margins().left());
240 leftMarginChanged(m_chart->minimumMargins().left());
239 if (m_chartMargins.right() != newMargins.right())
241 if (m_chartMargins.right() != newMargins.right())
240 rightMarginChanged(m_chart->margins().right());
242 rightMarginChanged(m_chart->minimumMargins().right());
241
243
242 m_chartMargins = m_chart->margins();
244 m_chartMargins = m_chart->minimumMargins();
243 }
245 }
244
246
245 DeclarativeChart::~DeclarativeChart()
247 DeclarativeChart::~DeclarativeChart()
@@ -487,22 +489,22 bool DeclarativeChart::dropShadowEnabled()
487
489
488 qreal DeclarativeChart::topMargin()
490 qreal DeclarativeChart::topMargin()
489 {
491 {
490 return m_chart->margins().top();
492 return m_chart->minimumMargins().top();
491 }
493 }
492
494
493 qreal DeclarativeChart::bottomMargin()
495 qreal DeclarativeChart::bottomMargin()
494 {
496 {
495 return m_chart->margins().bottom();
497 return m_chart->minimumMargins().bottom();
496 }
498 }
497
499
498 qreal DeclarativeChart::leftMargin()
500 qreal DeclarativeChart::leftMargin()
499 {
501 {
500 return m_chart->margins().left();
502 return m_chart->minimumMargins().left();
501 }
503 }
502
504
503 qreal DeclarativeChart::rightMargin()
505 qreal DeclarativeChart::rightMargin()
504 {
506 {
505 return m_chart->margins().right();
507 return m_chart->minimumMargins().right();
506 }
508 }
507
509
508 void DeclarativeChart::zoom(qreal factor)
510 void DeclarativeChart::zoom(qreal factor)
@@ -150,7 +150,7 private:
150 // Extending QChart with DeclarativeChart is not possible because QObject does not support
150 // Extending QChart with DeclarativeChart is not possible because QObject does not support
151 // multi inheritance, so we now have a QChart as a member instead
151 // multi inheritance, so we now have a QChart as a member instead
152 QChart *m_chart;
152 QChart *m_chart;
153 QRectF m_chartMargins;
153 QMargins m_chartMargins;
154 };
154 };
155
155
156 QTCOMMERCIALCHART_END_NAMESPACE
156 QTCOMMERCIALCHART_END_NAMESPACE
@@ -22,6 +22,7
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlegend_p.h"
23 #include "qlegend_p.h"
24 #include "chartaxis_p.h"
24 #include "chartaxis_p.h"
25 #include <QDebug>
25
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
@@ -30,7 +31,7 m_presenter(presenter),
30 m_marginBig(60),
31 m_marginBig(60),
31 m_marginSmall(20),
32 m_marginSmall(20),
32 m_marginTiny(10),
33 m_marginTiny(10),
33 m_chartMargins(QPointF(m_marginBig,m_marginBig),QPointF(m_marginBig,m_marginBig)),
34 m_chartMargins(m_marginBig,m_marginBig,m_marginBig,m_marginBig),
34 m_intialized(false)
35 m_intialized(false)
35 {
36 {
36
37
@@ -74,12 +75,16 void ChartLayout::setGeometry(const QRectF& rect)
74 }
75 }
75
76
76 QLegend* legend = m_presenter->legend();
77 QLegend* legend = m_presenter->legend();
77
78 Q_ASSERT(legend);
78 Q_ASSERT(legend);
79
79
80 qreal titlePadding = m_chartMargins.top()/2;
80 qreal titlePadding = m_chartMargins.top()/2;
81
81
82 QRectF chartMargins = m_chartMargins;
82 QMargins chartMargins = m_chartMargins;
83
84 //TODO multiple axis handling;
85 chartMargins.setLeft(qMax(m_chartMargins.left(),int(axisWidth + 2*m_marginTiny)));
86 chartMargins.setBottom(qMax(m_chartMargins.bottom(),int(axisHeight + 2* m_marginTiny)));
87
83
88
84 // recalculate legend position
89 // recalculate legend position
85 if ((legend->isAttachedToChart() && legend->isVisible())) {
90 if ((legend->isAttachedToChart() && legend->isVisible())) {
@@ -88,35 +93,35 void ChartLayout::setGeometry(const QRectF& rect)
88 switch (legend->alignment()) {
93 switch (legend->alignment()) {
89
94
90 case Qt::AlignTop: {
95 case Qt::AlignTop: {
96
91 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1));
97 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1));
92 int topMargin = 2*m_marginTiny + titleSize.height() + legendSize.height() + m_marginTiny;
98 int topMargin = 2*m_marginTiny + titleSize.height() + legendSize.height() + m_marginTiny;
93 chartMargins = QRect(QPoint(m_chartMargins.left(),topMargin),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
99 chartMargins = QMargins(chartMargins.left(),topMargin,chartMargins.right(),chartMargins.bottom());
94 m_legendMargins = QRect(QPoint(chartMargins.left(),topMargin - (legendSize.height() + m_marginTiny)),QPoint(chartMargins.right(),rect.height()-topMargin + m_marginTiny));
100 m_legendMargins = QMargins(chartMargins.left(),topMargin - (legendSize.height() + m_marginTiny),chartMargins.right(),rect.height()-topMargin + m_marginTiny);
95 titlePadding = m_marginTiny + m_marginTiny;
101 titlePadding = m_marginTiny + m_marginTiny;
96 break;
102 break;
97 }
103 }
98 case Qt::AlignBottom: {
104 case Qt::AlignBottom: {
99 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1));
105 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1));
100 int bottomMargin = m_marginTiny + legendSize.height() + m_marginTiny + axisHeight;
106 int bottomMargin = m_marginTiny + legendSize.height() + m_marginTiny + axisHeight;
101 chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomMargin));
107 chartMargins = QMargins(chartMargins.left(),chartMargins.top(),chartMargins.right(),bottomMargin);
102 m_legendMargins = QRect(QPoint(chartMargins.left(),rect.height()-bottomMargin + m_marginTiny + axisHeight),QPoint(chartMargins.right(),m_marginTiny + m_marginSmall));
108 m_legendMargins = QMargins(chartMargins.left(),rect.height()-bottomMargin + m_marginTiny + axisHeight,chartMargins.right(),m_marginTiny + m_marginSmall);
103 titlePadding = chartMargins.top()/2;
109 titlePadding = chartMargins.top()/2;
104 break;
110 break;
105 }
111 }
106 case Qt::AlignLeft: {
112 case Qt::AlignLeft: {
107 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height()));
113 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height()));
108 int leftPadding = m_marginTiny + legendSize.width() + m_marginTiny + axisWidth;
114 int leftPadding = m_marginTiny + legendSize.width() + m_marginTiny + axisWidth;
109
115 chartMargins = QMargins(leftPadding,chartMargins.top(),chartMargins.right(),chartMargins.bottom());
110 chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
116 m_legendMargins = QMargins(m_marginTiny + m_marginSmall,chartMargins.top(),rect.width()-leftPadding + m_marginTiny + axisWidth,chartMargins.bottom());
111 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,chartMargins.top()),QPoint(rect.width()-leftPadding + m_marginTiny + axisWidth,chartMargins.bottom()));
112 titlePadding = chartMargins.top()/2;
117 titlePadding = chartMargins.top()/2;
113 break;
118 break;
114 }
119 }
115 case Qt::AlignRight: {
120 case Qt::AlignRight: {
116 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height()));
121 QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height()));
117 int rightPadding = m_marginTiny + legendSize.width() + m_marginTiny;
122 int rightPadding = m_marginTiny + legendSize.width() + m_marginTiny;
118 chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
123 chartMargins = QMargins(chartMargins.left(),chartMargins.top(),rightPadding,chartMargins.bottom());
119 m_legendMargins = QRect(QPoint(rect.width()- rightPadding+ m_marginTiny ,chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,chartMargins.bottom()));
124 m_legendMargins = QMargins(rect.width()- rightPadding+ m_marginTiny ,chartMargins.top(),m_marginTiny + m_marginSmall,chartMargins.bottom());
120 titlePadding = chartMargins.top()/2;
125 titlePadding = chartMargins.top()/2;
121 break;
126 break;
122 }
127 }
@@ -158,15 +163,16 QSizeF ChartLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) co
158 return QSize(-1,-1);
163 return QSize(-1,-1);
159 }
164 }
160
165
161 void ChartLayout::setMarginsMinimum(const QRectF& margins)
166 void ChartLayout::setMinimumMargins(const QMargins& margins)
162 {
167 {
168
163 if(m_chartMargins != margins){
169 if(m_chartMargins != margins){
164 m_chartMargins = margins;
170 m_chartMargins = margins;
165 updateGeometry();
171 updateGeometry();
166 }
172 }
167 }
173 }
168
174
169 QRectF ChartLayout::margins() const
175 QMargins ChartLayout::minimumMargins() const
170 {
176 {
171 return m_chartMargins;
177 return m_chartMargins;
172 }
178 }
@@ -21,6 +21,7
21 #ifndef CHARTLAYOUT_H_
21 #ifndef CHARTLAYOUT_H_
22 #define CHARTLAYOUT_H_
22 #define CHARTLAYOUT_H_
23 #include <QGraphicsLayout>
23 #include <QGraphicsLayout>
24 #include <QMargins>
24 #include "qchartglobal.h"
25 #include "qchartglobal.h"
25
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -34,8 +35,8 public:
34 ChartLayout(ChartPresenter* presenter);
35 ChartLayout(ChartPresenter* presenter);
35 virtual ~ChartLayout();
36 virtual ~ChartLayout();
36
37
37 void setMarginsMinimum(const QRectF& margins);
38 void setMinimumMargins(const QMargins& margins);
38 QRectF margins() const;
39 QMargins minimumMargins() const;
39
40
40 void setGeometry(const QRectF& rect);
41 void setGeometry(const QRectF& rect);
41
42
@@ -50,8 +51,8 private:
50 int m_marginBig;
51 int m_marginBig;
51 int m_marginSmall;
52 int m_marginSmall;
52 int m_marginTiny;
53 int m_marginTiny;
53 QRectF m_chartMargins;
54 QMargins m_chartMargins;
54 QRectF m_legendMargins;
55 QMargins m_legendMargins;
55 bool m_intialized;
56 bool m_intialized;
56
57
57
58
@@ -419,15 +419,14 QGraphicsLayout* ChartPresenter::layout()
419 return m_layout;
419 return m_layout;
420 }
420 }
421
421
422 void ChartPresenter::setMarginsMinimum(const QRectF& margins)
422 void ChartPresenter::setMinimumMargins(const QMargins& margins)
423 {
423 {
424 Q_UNUSED(margins);
424 m_layout->setMinimumMargins(margins);
425 // m_layout->setMarginsMinimum(margins);
426 }
425 }
427
426
428 QRectF ChartPresenter::margins() const
427 QMargins ChartPresenter::minimumMargins() const
429 {
428 {
430 return m_layout->margins();
429 return m_layout->minimumMargins();
431 }
430 }
432
431
433 QLegend* ChartPresenter::legend()
432 QLegend* ChartPresenter::legend()
@@ -33,6 +33,7
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
35 #include <QRectF>
35 #include <QRectF>
36 #include <QMargins>
36
37
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
39
@@ -131,8 +132,8 public:
131
132
132 void resetAllElements();
133 void resetAllElements();
133
134
134 void setMarginsMinimum(const QRectF& margins);
135 void setMinimumMargins(const QMargins& margins);
135 QRectF margins() const;
136 QMargins minimumMargins() const;
136 QGraphicsLayout* layout();
137 QGraphicsLayout* layout();
137
138
138 private:
139 private:
@@ -371,12 +371,20 QLegend* QChart::legend() const
371 }
371 }
372
372
373 /*!
373 /*!
374 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
375 */
376 void QChart::setMinimumMargins(const QMargins& margins)
377 {
378 d_ptr->m_presenter->setMinimumMargins(margins);
379 }
380
381 /*!
374 Returns the rect that contains information about margins (distance between chart widget edge and axes).
382 Returns the rect that contains information about margins (distance between chart widget edge and axes).
375 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
383 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
376 */
384 */
377 QRectF QChart::margins() const
385 QMargins QChart::minimumMargins() const
378 {
386 {
379 return d_ptr->m_presenter->margins();
387 return d_ptr->m_presenter->minimumMargins();
380 }
388 }
381
389
382 /*!
390 /*!
@@ -447,13 +455,6 QList<QAbstractSeries*> QChart::series() const
447 {
455 {
448 return d_ptr->m_dataset->series();
456 return d_ptr->m_dataset->series();
449 }
457 }
450 /*!
451 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
452 */
453 void QChart::setMarginsMinimum(const QRectF& margins)
454 {
455 d_ptr->m_presenter->setMarginsMinimum(margins);
456 }
457
458
458 /*!
459 /*!
459 Sets \a axis to the chart, which will control the presentation of the \a series
460 Sets \a axis to the chart, which will control the presentation of the \a series
@@ -24,6 +24,7
24 #include <QAbstractSeries>
24 #include <QAbstractSeries>
25 #include <QLegend>
25 #include <QLegend>
26 #include <QGraphicsWidget>
26 #include <QGraphicsWidget>
27 #include <QMargins>
27
28
28 class QGraphicsSceneResizeEvent;
29 class QGraphicsSceneResizeEvent;
29
30
@@ -42,7 +43,7 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
42 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
43 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
43 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
44 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
44 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
45 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
45 Q_PROPERTY(QRectF margins READ margins NOTIFY marginsChanged)
46 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
46 Q_ENUMS(ChartTheme)
47 Q_ENUMS(ChartTheme)
47 Q_ENUMS(AnimationOption)
48 Q_ENUMS(AnimationOption)
48
49
@@ -113,8 +114,9 public:
113
114
114 QLegend* legend() const;
115 QLegend* legend() const;
115
116
116 void setMarginsMinimum(const QRectF& margins);
117 void setMinimumMargins(const QMargins& margins);
117 QRectF margins() const;
118 QMargins minimumMargins() const;
119
118 QRectF plotArea() const;
120 QRectF plotArea() const;
119
121
120 Q_SIGNALS:
122 Q_SIGNALS:
@@ -122,10 +122,9 void QChartView::mousePressEvent(QMouseEvent *event)
122 {
122 {
123 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
123 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
124
124
125 int padding = d_ptr->m_chart->margins().top();
125 QRectF plotArea = d_ptr->m_chart->plotArea();
126 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
127
126
128 if (rect.contains(event->pos())) {
127 if (plotArea.contains(event->pos())) {
129 d_ptr->m_rubberBandOrigin = event->pos();
128 d_ptr->m_rubberBandOrigin = event->pos();
130 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
129 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
131 d_ptr->m_rubberBand->show();
130 d_ptr->m_rubberBand->show();
@@ -144,9 +143,7 void QChartView::mousePressEvent(QMouseEvent *event)
144 void QChartView::mouseMoveEvent(QMouseEvent *event)
143 void QChartView::mouseMoveEvent(QMouseEvent *event)
145 {
144 {
146 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
145 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
147 QRectF margins = d_ptr->m_chart->margins();
146 QRectF rect = d_ptr->m_chart->plotArea();
148 QRectF geometry = d_ptr->m_chart->geometry();
149 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
150 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
147 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
151 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
148 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
152 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
149 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
@@ -72,8 +72,8 private slots:
72 void isBackgroundVisible();
72 void isBackgroundVisible();
73 void legend_data();
73 void legend_data();
74 void legend();
74 void legend();
75 void margins_data();
75 void plotArea_data();
76 void margins();
76 void plotArea();
77 void removeAllSeries_data();
77 void removeAllSeries_data();
78 void removeAllSeries();
78 void removeAllSeries();
79 void removeSeries_data();
79 void removeSeries_data();
@@ -156,12 +156,10 void tst_QChart::qchart()
156 QVERIFY(m_chart->backgroundBrush()!=QBrush());
156 QVERIFY(m_chart->backgroundBrush()!=QBrush());
157 QVERIFY(m_chart->backgroundPen()!=QPen());
157 QVERIFY(m_chart->backgroundPen()!=QPen());
158 QCOMPARE(m_chart->isBackgroundVisible(), true);
158 QCOMPARE(m_chart->isBackgroundVisible(), true);
159
159 QVERIFY(m_chart->plotArea().top()==0);
160 QVERIFY(m_chart->margins().top()>0);
160 QVERIFY(m_chart->plotArea().left()==0);
161 QVERIFY(m_chart->margins().left()>0);
161 QVERIFY(m_chart->plotArea().right()==0);
162 QVERIFY(m_chart->margins().right()>0);
162 QVERIFY(m_chart->plotArea().bottom()==0);
163 QVERIFY(m_chart->margins().bottom()>0);
164
165 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
163 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
166 QCOMPARE(m_chart->title(), QString());
164 QCOMPARE(m_chart->title(), QString());
167
165
@@ -174,6 +172,13 void tst_QChart::qchart()
174 m_chart->zoomIn();
172 m_chart->zoomIn();
175 m_chart->zoomIn(QRectF());
173 m_chart->zoomIn(QRectF());
176 m_chart->zoomOut();
174 m_chart->zoomOut();
175
176 m_view->show();
177
178 QVERIFY(m_chart->plotArea().top()>0);
179 QVERIFY(m_chart->plotArea().left()>0);
180 QVERIFY(m_chart->plotArea().right()>0);
181 QVERIFY(m_chart->plotArea().bottom()>0);
177 }
182 }
178
183
179 void tst_QChart::addSeries_data()
184 void tst_QChart::addSeries_data()
@@ -391,17 +396,18 void tst_QChart::legend()
391 QCOMPARE(fontSpy.count(), 1);
396 QCOMPARE(fontSpy.count(), 1);
392 }
397 }
393
398
394 void tst_QChart::margins_data()
399 void tst_QChart::plotArea_data()
395 {
400 {
396
401
397 }
402 }
398
403
399 void tst_QChart::margins()
404 void tst_QChart::plotArea()
400 {
405 {
401 createTestData();
406 createTestData();
402 QRectF rect = m_chart->geometry();
407 QRectF rect = m_chart->geometry();
403 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
408 QVERIFY(m_chart->plotArea().isValid());
404 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
409 QVERIFY(m_chart->plotArea().height() < rect.height());
410 QVERIFY(m_chart->plotArea().width() < rect.width());
405 }
411 }
406
412
407 void tst_QChart::removeAllSeries_data()
413 void tst_QChart::removeAllSeries_data()
@@ -717,7 +723,7 void tst_QChart::zoomIn()
717 QFETCH(QRectF, rect);
723 QFETCH(QRectF, rect);
718 createTestData();
724 createTestData();
719 m_chart->createDefaultAxes();
725 m_chart->createDefaultAxes();
720 QRectF marigns = m_chart->margins();
726 QRectF marigns = m_chart->plotArea();
721 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
727 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
722 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
728 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
723 QVERIFY(axisX!=0);
729 QVERIFY(axisX!=0);
@@ -116,14 +116,12 void tst_QChartView::rubberBand_data()
116 QTest::addColumn<int>("Xcount");
116 QTest::addColumn<int>("Xcount");
117 QTest::addColumn<int>("Ycount");
117 QTest::addColumn<int>("Ycount");
118
118
119 QTest::addColumn<int>("minX");
119 QTest::addColumn<QPoint>("min");
120 QTest::addColumn<int>("maxX");
120 QTest::addColumn<QPoint>("max");
121 QTest::addColumn<int>("minY");
121
122 QTest::addColumn<int>("maxY");
122 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << QPoint(5,5) << QPoint(5,5);
123
123 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << QPoint(5,5) << QPoint(5,5);
124 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200;
124 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 << QPoint(5,5) << QPoint(5,5);
125 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180;
126 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180;
127 }
125 }
128
126
129 void tst_QChartView::rubberBand()
127 void tst_QChartView::rubberBand()
@@ -131,13 +129,11 void tst_QChartView::rubberBand()
131 QFETCH(QChartView::RubberBands, rubberBand);
129 QFETCH(QChartView::RubberBands, rubberBand);
132 QFETCH(int, Xcount);
130 QFETCH(int, Xcount);
133 QFETCH(int, Ycount);
131 QFETCH(int, Ycount);
134 QFETCH(int, minX);
132 QFETCH(QPoint, min);
135 QFETCH(int, maxX);
133 QFETCH(QPoint, max);
136 QFETCH(int, minY);
137 QFETCH(int, maxY);
138
134
139 m_view->setRubberBand(rubberBand);
135 m_view->setRubberBand(rubberBand);
140 QRectF padding = m_view->chart()->margins();
136
141 QCOMPARE(m_view->rubberBand(), rubberBand);
137 QCOMPARE(m_view->rubberBand(), rubberBand);
142
138
143 QLineSeries* line = new QLineSeries();
139 QLineSeries* line = new QLineSeries();
@@ -145,9 +141,9 void tst_QChartView::rubberBand()
145
141
146 m_view->chart()->addSeries(line);
142 m_view->chart()->addSeries(line);
147 m_view->chart()->createDefaultAxes();
143 m_view->chart()->createDefaultAxes();
148 m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom());
149 m_view->show();
144 m_view->show();
150
145
146 QRectF plotArea = m_view->chart()->plotArea();
151 //this is hack since view does not get events otherwise
147 //this is hack since view does not get events otherwise
152 m_view->setMouseTracking(true);
148 m_view->setMouseTracking(true);
153
149
@@ -156,11 +152,23 void tst_QChartView::rubberBand()
156 QAbstractAxis* axisX = m_view->chart()->axisX();
152 QAbstractAxis* axisX = m_view->chart()->axisX();
157 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal)));
153 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal)));
158
154
155
156 QValueAxis* vaxisX = qobject_cast<QValueAxis*>(axisX);
157 QValueAxis* vaxisY = qobject_cast<QValueAxis*>(axisY);
158
159 int minX = vaxisX->min();
160 int minY = vaxisY->min();
161 int maxX = vaxisX->max();
162 int maxY = vaxisY->max();
163
159 QTest::qWaitForWindowShown(m_view);
164 QTest::qWaitForWindowShown(m_view);
160 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint());
165 QTest::mouseMove(m_view->viewport(), min + plotArea.topLeft().toPoint());
161 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint());
166 QTest::qWait(2000);
162 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint());
167 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, min + plotArea.topLeft().toPoint());
163 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint());
168 QTest::qWait(2000);
169 QTest::mouseMove(m_view->viewport(), plotArea.bottomRight().toPoint() - max);
170 QTest::qWait(2000);
171 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, plotArea.bottomRight().toPoint() - max);
164
172
165 TRY_COMPARE(spy0.count(), Xcount);
173 TRY_COMPARE(spy0.count(), Xcount);
166 TRY_COMPARE(spy1.count(), Ycount);
174 TRY_COMPARE(spy1.count(), Ycount);
@@ -168,13 +176,10 void tst_QChartView::rubberBand()
168 //this is hack since view does not get events otherwise
176 //this is hack since view does not get events otherwise
169 m_view->setMouseTracking(false);
177 m_view->setMouseTracking(false);
170
178
171 QValueAxis* vaxisX = qobject_cast<QValueAxis*>(axisX);
179 QVERIFY(vaxisX->min() >= minX );
172 QValueAxis* vaxisY = qobject_cast<QValueAxis*>(axisY);
180 QVERIFY(vaxisX->max() <= maxX );
173
181 QVERIFY(vaxisY->min() >= minY );
174 QVERIFY(vaxisX->min() - minX < 1);
182 QVERIFY(vaxisY->max() <= maxY );
175 QVERIFY(vaxisX->max() - maxX < 1);
176 QVERIFY(vaxisY->min() - minY < 1);
177 QVERIFY(vaxisY->max() - maxY < 1);
178
183
179 }
184 }
180
185
General Comments 0
You need to be logged in to leave comments. Login now