@@ -1,64 +1,69 | |||
|
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 | bool Domain::isEmpty() const | |
|
30 | { | |
|
31 | return spanX()==0 || spanY()==0; | |
|
32 | } | |
|
33 | ||
|
29 | 34 | Domain Domain::subDomain(const QRectF& rect, qreal maxWidth,qreal maxHeight) const |
|
30 | 35 | { |
|
31 | 36 | Domain domain; |
|
32 | 37 | |
|
33 | 38 | qreal dx = spanX() / maxWidth; |
|
34 | 39 | qreal dy = spanY() / maxHeight; |
|
35 | 40 | |
|
36 | 41 | domain.m_minX = m_minX + dx * rect.left(); |
|
37 | 42 | domain.m_maxX = m_minX + dx * rect.right(); |
|
38 | 43 | domain.m_minY = m_maxY - dy * rect.bottom(); |
|
39 | 44 | domain.m_maxY = m_maxY - dy * rect.top(); |
|
40 | 45 | |
|
41 | 46 | return domain; |
|
42 | 47 | } |
|
43 | 48 | |
|
44 | 49 | bool operator== (const Domain &domain1, const Domain &domain2) |
|
45 | 50 | { |
|
46 | 51 | return (domain1.m_maxX == domain2.m_maxX && |
|
47 | 52 | domain1.m_maxY == domain2.m_maxY && |
|
48 | 53 | domain1.m_minX == domain2.m_minX && |
|
49 | 54 | domain1.m_minY == domain2.m_minY); |
|
50 | 55 | } |
|
51 | 56 | |
|
52 | 57 | bool operator!= (const Domain &domain1, const Domain &domain2) |
|
53 | 58 | { |
|
54 | 59 | return !(domain1 == domain2); |
|
55 | 60 | } |
|
56 | 61 | |
|
57 | 62 | |
|
58 | 63 | QDebug operator<<(QDebug dbg, const Domain &domain) |
|
59 | 64 | { |
|
60 | 65 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')'; |
|
61 | 66 | return dbg.maybeSpace(); |
|
62 | 67 | } |
|
63 | 68 | |
|
64 | 69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,31 +1,32 | |||
|
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 | bool isEmpty() const; | |
|
15 | 16 | |
|
16 | 17 | friend bool operator== (const Domain &domain1, const Domain &domain2); |
|
17 | 18 | friend bool operator!= (const Domain &domain1, const Domain &domain2); |
|
18 | 19 | friend QDebug operator<<(QDebug dbg, const Domain &domain); |
|
19 | 20 | |
|
20 | 21 | Domain subDomain(const QRectF& rect, qreal maxWidth, qreal maxHeight) const; |
|
21 | 22 | |
|
22 | 23 | public: |
|
23 | 24 | qreal m_minX; |
|
24 | 25 | qreal m_maxX; |
|
25 | 26 | qreal m_minY; |
|
26 | 27 | qreal m_maxY; |
|
27 | 28 | }; |
|
28 | 29 | |
|
29 | 30 | QTCOMMERCIALCHART_END_NAMESPACE |
|
30 | 31 | |
|
31 | 32 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now