##// END OF EJS Templates
Add overloaded comparison operators to domain
Michal Klocek -
r220:94c82e0171bd
parent child
Show More
@@ -1,45 +1,59
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():
6 m_minX(0),
6 m_minX(0),
7 m_maxX(0),
7 m_maxX(0),
8 m_minY(0),
8 m_minY(0),
9 m_maxY(0)
9 m_maxY(0)
10 {
10 {
11
11
12 }
12 }
13
13
14 Domain::~Domain()
14 Domain::~Domain()
15 {
15 {
16 // TODO Auto-generated destructor stub
16 // TODO Auto-generated destructor stub
17 }
17 }
18
18
19 qreal Domain::spanX() const
19 qreal Domain::spanX() const
20 {
20 {
21 Q_ASSERT(m_maxX >= m_minX);
21 Q_ASSERT(m_maxX >= m_minX);
22 return m_maxX - m_minX;
22 return m_maxX - m_minX;
23 }
23 }
24
24
25 qreal Domain::spanY() const
25 qreal Domain::spanY() const
26 {
26 {
27 Q_ASSERT(m_maxY >= m_minY);
27 Q_ASSERT(m_maxY >= m_minY);
28 return m_maxY - m_minY;
28 return m_maxY - m_minY;
29 }
29 }
30
30
31 Domain Domain::subDomain(const QRectF& rect, qreal maxWidth,qreal maxHeight) const
31 Domain Domain::subDomain(const QRectF& rect, qreal maxWidth,qreal maxHeight) const
32 {
32 {
33 Domain domain;
33 Domain domain;
34
34
35 qreal dx = spanX() / maxWidth;
35 qreal dx = spanX() / maxWidth;
36 qreal dy = spanY() / maxHeight;
36 qreal dy = spanY() / maxHeight;
37
37
38 domain.m_minX = m_minX + dx * rect.left();
38 domain.m_minX = m_minX + dx * rect.left();
39 domain.m_maxX = m_minX + dx * rect.right();
39 domain.m_maxX = m_minX + dx * rect.right();
40 domain.m_minY = m_maxY - dy * rect.bottom();
40 domain.m_minY = m_maxY - dy * rect.bottom();
41 domain.m_maxY = m_maxY - dy * rect.top();
41 domain.m_maxY = m_maxY - dy * rect.top();
42
42
43 return domain;
43 return domain;
44 }
44 }
45
46 bool operator== (const Domain &domain1, const Domain &domain2)
47 {
48 return (domain1.m_maxX == domain2.m_maxX &&
49 domain1.m_maxY == domain2.m_maxY &&
50 domain1.m_minX == domain2.m_minX &&
51 domain1.m_minY == domain2.m_minY);
52 }
53
54 bool operator!= (const Domain &domain1, const Domain &domain2)
55 {
56 return !(domain1 == domain2);
57 }
58
45 QTCOMMERCIALCHART_END_NAMESPACE
59 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,27 +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();
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);
17 friend bool operator!= (const Domain &domain1, const Domain &domain2);
18
16 Domain subDomain(const QRectF& rect, qreal maxWidth, qreal maxHeight) const;
19 Domain subDomain(const QRectF& rect, qreal maxWidth, qreal maxHeight) const;
17
20
18 public:
21 public:
19 qreal m_minX;
22 qreal m_minX;
20 qreal m_maxX;
23 qreal m_maxX;
21 qreal m_minY;
24 qreal m_minY;
22 qreal m_maxY;
25 qreal m_maxY;
23 };
26 };
24
27
25 QTCOMMERCIALCHART_END_NAMESPACE
28 QTCOMMERCIALCHART_END_NAMESPACE
26
29
27 #endif
30 #endif
General Comments 0
You need to be logged in to leave comments. Login now