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