##// END OF EJS Templates
Increses margins prescision
Michal Klocek -
r874:fcf207f30c3f
parent child
Show More
@@ -84,7 +84,7 public: //TODO: fix me
84 84 void resetAllElements();
85 85 void createChartBackgroundItem();
86 86 void createChartTitleItem();
87 QRect margins() const { return m_chartMargins;}
87 QRectF margins() const { return m_chartMargins;}
88 88
89 89 public Q_SLOTS:
90 90 void handleSeriesAdded(QSeries* series,Domain* domain);
@@ -116,8 +116,8 public: //TODO: fixme
116 116 int m_marginBig;
117 117 int m_marginSmall;
118 118 int m_marginTiny;
119 QRect m_chartMargins;
120 QRect m_legendMargins;
119 QRectF m_chartMargins;
120 QRectF m_legendMargins;
121 121
122 122 };
123 123
@@ -275,7 +275,7 QLegend* QChart::legend() const
275 275 return d_ptr->m_legend;
276 276 }
277 277
278 QRect QChart::margins() const
278 QRectF QChart::margins() const
279 279 {
280 280 return d_ptr->m_presenter->margins();
281 281 }
@@ -76,6 +76,7 public:
76 76 QFont titleFont() const;
77 77 void setTitleBrush(const QBrush &brush);
78 78 QBrush titleBrush() const;
79
79 80 void setBackgroundBrush(const QBrush &brush);
80 81 QBrush backgroundBrush() const;
81 82 void setBackgroundPen(const QPen &pen);
@@ -99,7 +100,7 public:
99 100 QChartAxis* axisY() const;
100 101
101 102 QLegend* legend() const;
102 QRect margins() const;
103 QRectF margins() const;
103 104
104 105 protected:
105 106 void resizeEvent(QGraphicsSceneResizeEvent *event);
@@ -138,8 +138,9 void QChartView::mousePressEvent(QMouseEvent *event)
138 138 void QChartView::mouseMoveEvent(QMouseEvent *event)
139 139 {
140 140 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
141 int padding = d_ptr->m_chart->margins().top();
142 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
141 QRectF margins = d_ptr->m_chart->margins();
142 QRectF geometry = d_ptr->m_chart->geometry();
143 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
143 144 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
144 145 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
145 146 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
@@ -22,6 +22,7
22 22 #include <QtTest/QtTest>
23 23 #include <qchartview.h>
24 24 #include <qlineseries.h>
25 #include <qlegend.h>
25 26 #include <cmath>
26 27
27 28 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -68,6 +69,7 void tst_QChartView::cleanupTestCase()
68 69 void tst_QChartView::init()
69 70 {
70 71 m_view = new QChartView(new QChart());
72 m_view->chart()->legend()->setVisible(false);
71 73 }
72 74
73 75 void tst_QChartView::cleanup()
@@ -131,7 +133,7 void tst_QChartView::rubberBand()
131 133 QFETCH(int, maxY);
132 134
133 135 m_view->setRubberBand(rubberBand);
134 QRect padding = m_view->chart()->margins();
136 QRectF padding = m_view->chart()->margins();
135 137 QCOMPARE(m_view->rubberBand(), rubberBand);
136 138
137 139 QLineSeries* line = new QLineSeries();
@@ -150,10 +152,11 void tst_QChartView::rubberBand()
150 152 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
151 153
152 154 QTest::qWaitForWindowShown(m_view);
153 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft());
154 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft());
155 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft());
156 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft());
155 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint());
156 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint());
157 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint());
158 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint());
159
157 160
158 161 QCOMPARE(spy0.count(), Xcount);
159 162 QCOMPARE(spy1.count(), Ycount);
@@ -186,7 +189,7 void tst_QChartView::keys()
186 189 QFETCH(int, Xcount);
187 190 QFETCH(int, Ycount);
188 191
189 QRect padding = m_view->chart()->margins();
192 QRectF padding = m_view->chart()->margins();
190 193
191 194 QLineSeries* line = new QLineSeries();
192 195 *line << QPointF(0, 0) << QPointF(100, 100);
General Comments 0
You need to be logged in to leave comments. Login now