##// END OF EJS Templates
Add min max constuctor to domain
Michal Klocek -
r221:ce059d3667fe
parent child
Show More
@@ -1,59 +1,57
1 #include "domain_p.h"
1 #include "domain_p.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 Domain::Domain():
5 Domain::Domain(qreal minX, qreal maxX, qreal minY, qreal maxY):
6 m_minX(0),
6 m_minX(minX),
7 m_maxX(0),
7 m_maxX(maxX),
8 m_minY(0),
8 m_minY(minY),
9 m_maxY(0)
9 m_maxY(maxY)
10 {
10 {
11
12 }
11 }
13
12
14 Domain::~Domain()
13 Domain::~Domain()
15 {
14 {
16 // TODO Auto-generated destructor stub
17 }
15 }
18
16
19 qreal Domain::spanX() const
17 qreal Domain::spanX() const
20 {
18 {
21 Q_ASSERT(m_maxX >= m_minX);
19 Q_ASSERT(m_maxX >= m_minX);
22 return m_maxX - m_minX;
20 return m_maxX - m_minX;
23 }
21 }
24
22
25 qreal Domain::spanY() const
23 qreal Domain::spanY() const
26 {
24 {
27 Q_ASSERT(m_maxY >= m_minY);
25 Q_ASSERT(m_maxY >= m_minY);
28 return m_maxY - m_minY;
26 return m_maxY - m_minY;
29 }
27 }
30
28
31 Domain Domain::subDomain(const QRectF& rect, qreal maxWidth,qreal maxHeight) const
29 Domain Domain::subDomain(const QRectF& rect, qreal maxWidth,qreal maxHeight) const
32 {
30 {
33 Domain domain;
31 Domain domain;
34
32
35 qreal dx = spanX() / maxWidth;
33 qreal dx = spanX() / maxWidth;
36 qreal dy = spanY() / maxHeight;
34 qreal dy = spanY() / maxHeight;
37
35
38 domain.m_minX = m_minX + dx * rect.left();
36 domain.m_minX = m_minX + dx * rect.left();
39 domain.m_maxX = m_minX + dx * rect.right();
37 domain.m_maxX = m_minX + dx * rect.right();
40 domain.m_minY = m_maxY - dy * rect.bottom();
38 domain.m_minY = m_maxY - dy * rect.bottom();
41 domain.m_maxY = m_maxY - dy * rect.top();
39 domain.m_maxY = m_maxY - dy * rect.top();
42
40
43 return domain;
41 return domain;
44 }
42 }
45
43
46 bool operator== (const Domain &domain1, const Domain &domain2)
44 bool operator== (const Domain &domain1, const Domain &domain2)
47 {
45 {
48 return (domain1.m_maxX == domain2.m_maxX &&
46 return (domain1.m_maxX == domain2.m_maxX &&
49 domain1.m_maxY == domain2.m_maxY &&
47 domain1.m_maxY == domain2.m_maxY &&
50 domain1.m_minX == domain2.m_minX &&
48 domain1.m_minX == domain2.m_minX &&
51 domain1.m_minY == domain2.m_minY);
49 domain1.m_minY == domain2.m_minY);
52 }
50 }
53
51
54 bool operator!= (const Domain &domain1, const Domain &domain2)
52 bool operator!= (const Domain &domain1, const Domain &domain2)
55 {
53 {
56 return !(domain1 == domain2);
54 return !(domain1 == domain2);
57 }
55 }
58
56
59 QTCOMMERCIALCHART_END_NAMESPACE
57 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,30 +1,30
1 #ifndef DOMAIN_H_
1 #ifndef DOMAIN_H_
2 #define DOMAIN_H_
2 #define DOMAIN_H_
3 #include "qchartglobal.h"
3 #include "qchartglobal.h"
4 #include <QRect>
4 #include <QRect>
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 class Domain {
8 class Domain {
9 public:
9 public:
10 Domain();
10 Domain(qreal minX=0, qreal maxX=0, qreal minY=0, qreal maxY=0);
11 virtual ~Domain();
11 virtual ~Domain();
12
12
13 qreal spanX() const;
13 qreal spanX() const;
14 qreal spanY() const;
14 qreal spanY() const;
15
15
16 friend bool operator== (const Domain &domain1, const Domain &domain2);
16 friend bool operator== (const Domain &domain1, const Domain &domain2);
17 friend bool operator!= (const Domain &domain1, const Domain &domain2);
17 friend bool operator!= (const Domain &domain1, const Domain &domain2);
18
18
19 Domain subDomain(const QRectF& rect, qreal maxWidth, qreal maxHeight) const;
19 Domain subDomain(const QRectF& rect, qreal maxWidth, qreal maxHeight) const;
20
20
21 public:
21 public:
22 qreal m_minX;
22 qreal m_minX;
23 qreal m_maxX;
23 qreal m_maxX;
24 qreal m_minY;
24 qreal m_minY;
25 qreal m_maxY;
25 qreal m_maxY;
26 };
26 };
27
27
28 QTCOMMERCIALCHART_END_NAMESPACE
28 QTCOMMERCIALCHART_END_NAMESPACE
29
29
30 #endif
30 #endif
General Comments 0
You need to be logged in to leave comments. Login now