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