##// END OF EJS Templates
Fix padding to be int, update unit test
Michal Klocek -
r804:02c84d5a1cd8
parent child
Show More
@@ -268,7 +268,7 QLegend* QChart::legend() const
268 return d_ptr->m_legend;
268 return d_ptr->m_legend;
269 }
269 }
270
270
271 QRectF QChart::padding() const
271 QRect QChart::padding() const
272 {
272 {
273 return d_ptr->m_padding;
273 return d_ptr->m_padding;
274 }
274 }
@@ -342,7 +342,7 m_titleItem(0),
342 m_legend(0),
342 m_legend(0),
343 m_dataset(0),
343 m_dataset(0),
344 m_presenter(0),
344 m_presenter(0),
345 m_padding(QRectF(50,50,50,50))
345 m_padding(QRect(50,50,0,0))
346 {
346 {
347
347
348 }
348 }
@@ -99,14 +99,13 public:
99
99
100 QLegend* legend() const;
100 QLegend* legend() const;
101
101
102 QRectF padding() const;
102 QRect padding() const;
103
103
104 protected:
104 protected:
105 void resizeEvent(QGraphicsSceneResizeEvent *event);
105 void resizeEvent(QGraphicsSceneResizeEvent *event);
106
106
107 protected:
107 protected:
108 QScopedPointer<QChartPrivate> d_ptr;
108 QScopedPointer<QChartPrivate> d_ptr;
109 friend class QChartView;
110 friend class QLegend;
109 friend class QLegend;
111 Q_DISABLE_COPY(QChart)
110 Q_DISABLE_COPY(QChart)
112 };
111 };
@@ -57,7 +57,7 struct QChartPrivate
57 QLegend* m_legend;
57 QLegend* m_legend;
58 ChartDataSet *m_dataset;
58 ChartDataSet *m_dataset;
59 ChartPresenter *m_presenter;
59 ChartPresenter *m_presenter;
60 QRectF m_padding;
60 QRect m_padding;
61 };
61 };
62
62
63 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -59,7 +59,6 QChartView::QChartView(QChart *chart,QWidget *parent) :
59 {
59 {
60 d_ptr->m_scene = new QGraphicsScene(this);
60 d_ptr->m_scene = new QGraphicsScene(this);
61 d_ptr->m_chart = chart;
61 d_ptr->m_chart = chart;
62 d_ptr->m_presenter = chart->d_ptr->m_presenter;
63 setFrameShape(QFrame::NoFrame);
62 setFrameShape(QFrame::NoFrame);
64 setBackgroundRole(QPalette::Window);
63 setBackgroundRole(QPalette::Window);
65 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
64 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -190,14 +189,26 void QChartView::keyPressEvent(QKeyEvent *event)
190 {
189 {
191 switch (event->key()) {
190 switch (event->key()) {
192 case Qt::Key_Plus:
191 case Qt::Key_Plus:
193 d_ptr->m_chart->zoomIn();
192 d_ptr->m_chart->zoomIn();
194 break;
193 break;
195 case Qt::Key_Minus:
194 case Qt::Key_Minus:
196 d_ptr->m_chart->zoomOut();
195 d_ptr->m_chart->zoomOut();
197 break;
196 break;
197 case Qt::Key_Left:
198 d_ptr->m_chart->scrollLeft();
199 break;
200 case Qt::Key_Right:
201 d_ptr->m_chart->scrollRight();
202 break;
203 case Qt::Key_Up:
204 d_ptr->m_chart->scrollUp();
205 break;
206 case Qt::Key_Down:
207 d_ptr->m_chart->scrollDown();
208 break;
198 default:
209 default:
199 QGraphicsView::keyPressEvent(event);
210 QGraphicsView::keyPressEvent(event);
200 break;
211 break;
201 }
212 }
202 }
213 }
203
214
@@ -29,6 +29,7 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QChart*)
30 Q_DECLARE_METATYPE(QChart*)
31 Q_DECLARE_METATYPE(QChartView::RubberBands)
31 Q_DECLARE_METATYPE(QChartView::RubberBands)
32 Q_DECLARE_METATYPE(Qt::Key)
32
33
33 class tst_QChartView : public QObject
34 class tst_QChartView : public QObject
34 {
35 {
@@ -47,6 +48,8 private Q_SLOTS:
47 void chart();
48 void chart();
48 void rubberBand_data();
49 void rubberBand_data();
49 void rubberBand();
50 void rubberBand();
51 void keys_data();
52 void keys();
50
53
51 private:
54 private:
52 QChartView* m_view;
55 QChartView* m_view;
@@ -54,6 +57,8 private:
54
57
55 void tst_QChartView::initTestCase()
58 void tst_QChartView::initTestCase()
56 {
59 {
60 //test tracks mouse, give a while to user to relese it
61 QTest::qWait(1000);
57 }
62 }
58
63
59 void tst_QChartView::cleanupTestCase()
64 void tst_QChartView::cleanupTestCase()
@@ -111,8 +116,8 void tst_QChartView::rubberBand_data()
111 QTest::addColumn<int>("maxY");
116 QTest::addColumn<int>("maxY");
112
117
113 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 10 << 90 << 0<< 100;
118 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 10 << 90 << 0<< 100;
114 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 10 << 90 << 0<< 100;
119 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 100 << 10<< 90;
115 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 0<< 100;
120 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 10<< 90;
116 }
121 }
117
122
118 void tst_QChartView::rubberBand()
123 void tst_QChartView::rubberBand()
@@ -126,14 +131,17 void tst_QChartView::rubberBand()
126 QFETCH(int, maxY);
131 QFETCH(int, maxY);
127
132
128 m_view->setRubberBand(rubberBand);
133 m_view->setRubberBand(rubberBand);
134 QRect padding = m_view->chart()->padding();
129 QCOMPARE(m_view->rubberBand(), rubberBand);
135 QCOMPARE(m_view->rubberBand(), rubberBand);
130
136
131 QLineSeries* line = new QLineSeries();
137 QLineSeries* line = new QLineSeries();
132 *line << QPointF(0, 0) << QPointF(100, 100);
138 *line << QPointF(0, 0) << QPointF(100, 100);
133
139
134 m_view->chart()->addSeries(line);
140 m_view->chart()->addSeries(line);
135 m_view->resize(1000, 1000);
141 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
136 m_view->show();
142 m_view->show();
143
144 //this is hack since view does not get events otherwise
137 m_view->setMouseTracking(true);
145 m_view->setMouseTracking(true);
138
146
139 QChartAxis* axisY = m_view->chart()->axisY();
147 QChartAxis* axisY = m_view->chart()->axisY();
@@ -141,20 +149,66 void tst_QChartView::rubberBand()
141 QChartAxis* axisX = m_view->chart()->axisX();
149 QChartAxis* axisX = m_view->chart()->axisX();
142 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
150 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
143
151
152
144 QTest::qWaitForWindowShown(m_view);
153 QTest::qWaitForWindowShown(m_view);
145 QTest::mouseMove(m_view->viewport(), QPoint(250, 250));
154 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft());
146 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(250, 250));
155
147 QTest::mouseMove(m_view->viewport(), QPoint(900, 900));
156 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft());
148 QTest::qWait(3000);
157 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft());
149 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(900, 900));
158
150 QTest::qWait(3000);
159 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft());
160
151 QCOMPARE(spy0.count(), Xcount);
161 QCOMPARE(spy0.count(), Xcount);
152 QCOMPARE(spy1.count(), Ycount);
162 QCOMPARE(spy1.count(), Ycount);
153 qDebug()<<axisX->min();
163
154 QVERIFY(int(ceil(axisX->min())) - minX < 1);
164 //this is hack since view does not get events otherwise
155 QVERIFY(int(ceil(axisX->max())) - maxX < 1);
165 m_view->setMouseTracking(false);
156 QVERIFY(int(ceil(axisY->min())) - minY < 1);
166
157 QVERIFY(int(ceil(axisY->max())) - maxY < 1);
167 QVERIFY(axisX->min() - minX < 1);
168 QVERIFY(axisX->max() - maxX < 1);
169 QVERIFY(axisY->min() - minY < 1);
170 QVERIFY(axisY->max() - maxY < 1);
171 }
172
173 void tst_QChartView::keys_data()
174 {
175 QTest::addColumn<Qt::Key>("key");
176 QTest::addColumn<int>("Xcount");
177 QTest::addColumn<int>("Ycount");
178 QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1;
179 QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1;
180 QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1;
181 QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1;
182 QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0;
183 QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0;
184 }
185
186 void tst_QChartView::keys()
187 {
188 QFETCH(Qt::Key,key);
189 QFETCH(int, Xcount);
190 QFETCH(int, Ycount);
191
192 QRect padding = m_view->chart()->padding();
193
194 QLineSeries* line = new QLineSeries();
195 *line << QPointF(0, 0) << QPointF(100, 100);
196
197 m_view->chart()->addSeries(line);
198 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
199 m_view->show();
200
201 QChartAxis* axisY = m_view->chart()->axisY();
202 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
203 QChartAxis* axisX = m_view->chart()->axisX();
204 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
205
206 QTest::keyPress(m_view, key);
207 QTest::keyRelease(m_view, key);
208
209 QCOMPARE(spy0.count(), Ycount);
210 QCOMPARE(spy1.count(), Xcount);
211
158 }
212 }
159
213
160 QTEST_MAIN(tst_QChartView)
214 QTEST_MAIN(tst_QChartView)
General Comments 0
You need to be logged in to leave comments. Login now