1 | /**************************************************************************** |
2 | ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved. |
3 | ** |
4 | ** This file is part of the KD Gantt library. |
5 | ** |
6 | ** This file may be used under the terms of the GNU General Public |
7 | ** License versions 2.0 or 3.0 as published by the Free Software |
8 | ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3 |
9 | ** included in the packaging of this file. Alternatively you may (at |
10 | ** your option) use any later version of the GNU General Public |
11 | ** License if such license has been publicly approved by |
12 | ** Klarälvdalens Datakonsult AB (or its successors, if any). |
13 | ** |
14 | ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, |
15 | ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR |
16 | ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights |
17 | ** not expressly granted herein. |
18 | ** |
19 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
20 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
21 | ** |
22 | **********************************************************************/ |
23 | #ifndef KDGANTTGLOBAL_H |
24 | #define KDGANTTGLOBAL_H |
25 | |
26 | #include <Qt> |
27 | #include <QDateTime> |
28 | #include <QDebug> |
29 | #include <QMetaType> |
30 | |
31 | #include "kdgantt_export.h" |
32 | |
33 | template <typename T> |
34 | inline T & __kdab__dereference_for_methodcall( T & o ) { |
35 | return o; |
36 | } |
37 | |
38 | template <typename T> |
39 | inline T & __kdab__dereference_for_methodcall( T * o ) { |
40 | return *o; |
41 | } |
42 | |
43 | #define KDAB_SET_OBJECT_NAME( x ) __kdab__dereference_for_methodcall( x ).setObjectName( QLatin1String( #x ) ) |
44 | |
45 | #if defined(_MSC_VER) && _MSC_VER <= 1300 |
46 | #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \ |
47 | public: \ |
48 | class Private; \ |
49 | friend class Private; \ |
50 | protected: \ |
51 | inline Private * d_func(); \ |
52 | inline const Private * d_func() const; \ |
53 | explicit inline X( Private * ); \ |
54 | private: \ |
55 | void init(); |
56 | #else |
57 | #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \ |
58 | protected: \ |
59 | class Private; \ |
60 | friend class Private; \ |
61 | inline Private * d_func(); \ |
62 | inline const Private * d_func() const; \ |
63 | explicit inline X( Private * ); \ |
64 | private: \ |
65 | void init(); |
66 | #endif |
67 | |
68 | #if defined(_MSC_VER) && _MSC_VER <= 1300 |
69 | #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \ |
70 | public: \ |
71 | class Private; \ |
72 | friend class Private; \ |
73 | protected: \ |
74 | inline Private * d_func(); \ |
75 | inline const Private * d_func() const; \ |
76 | explicit inline X( Private *, ParentType ); \ |
77 | private: \ |
78 | void init(); |
79 | #else |
80 | #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \ |
81 | protected: \ |
82 | class Private; \ |
83 | friend class Private; \ |
84 | inline Private * d_func(); \ |
85 | inline const Private * d_func() const; \ |
86 | explicit inline X( Private *, ParentType ); \ |
87 | private: \ |
88 | void init(); |
89 | #endif |
90 | |
91 | #define KDGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET( X ) \ |
92 | KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, QWidget* ) |
93 | |
94 | #define KDGANTT_DECLARE_PRIVATE_BASE_VALUE( X ) \ |
95 | public: \ |
96 | inline void swap( X & other ) { qSwap( _d, other._d ); } \ |
97 | protected: \ |
98 | class Private; \ |
99 | friend class Private; \ |
100 | Private * d_func() { return _d; } \ |
101 | const Private * d_func() const { return _d; } \ |
102 | private: \ |
103 | void init(); \ |
104 | Private * _d; |
105 | |
106 | #if defined(_MSC_VER) && _MSC_VER <= 1300 |
107 | #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \ |
108 | public: \ |
109 | class Private; \ |
110 | friend class Private; \ |
111 | protected: \ |
112 | Private * d_func() { return _d; } \ |
113 | const Private * d_func() const { return _d; } \ |
114 | explicit inline X( Private * ); \ |
115 | private: \ |
116 | void init(); \ |
117 | Private * _d; |
118 | #else |
119 | #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \ |
120 | protected: \ |
121 | class Private; \ |
122 | friend class Private; \ |
123 | Private * d_func() { return _d; } \ |
124 | const Private * d_func() const { return _d; } \ |
125 | explicit inline X( Private * ); \ |
126 | private: \ |
127 | void init(); \ |
128 | Private * _d; |
129 | #endif |
130 | |
131 | #if defined(_MSC_VER) && _MSC_VER <= 1300 |
132 | #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \ |
133 | public: \ |
134 | class Private; \ |
135 | friend class Private; \ |
136 | protected: \ |
137 | Private * d_func() { return _d; } \ |
138 | const Private * d_func() const { return _d; } \ |
139 | explicit inline X( Private *, QWidget* ); \ |
140 | private: \ |
141 | void init(); \ |
142 | Private * _d; |
143 | #else |
144 | #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \ |
145 | protected: \ |
146 | class Private; \ |
147 | friend class Private; \ |
148 | Private * d_func() { return _d; } \ |
149 | const Private * d_func() const { return _d; } \ |
150 | explicit inline X( Private *, QWidget* ); \ |
151 | private: \ |
152 | void init(); \ |
153 | Private * _d; |
154 | #endif |
155 | |
156 | #include <QtAlgorithms> // qSwap |
157 | #ifndef QT_NO_STL |
158 | #include <algorithm> |
159 | #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \ |
160 | template <> inline void qSwap<X>( X & lhs, X & rhs ) \ |
161 | { lhs.swap( rhs ); } \ |
162 | namespace std { \ |
163 | template <> inline void swap<X>( X & lhs, X & rhs ) \ |
164 | { lhs.swap( rhs ); } \ |
165 | } |
166 | #else |
167 | #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \ |
168 | template <> inline void qSwap<X>( X & lhs, X & rhs ) \ |
169 | { lhs.swap( rhs ); } |
170 | #endif |
171 | |
172 | #define KDGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED( X ) \ |
173 | KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) |
174 | |
175 | #define KDGANTT_DECLARE_SWAP_BASE( X ) \ |
176 | protected: \ |
177 | void doSwap( X& other ) \ |
178 | { qSwap( _d, other._d); } |
179 | |
180 | #define KDGANTT_DECLARE_SWAP_DERIVED( X ) \ |
181 | void swap( X& other ) { doSwap( other ); } |
182 | |
183 | #if defined(Q_OS_WIN) && defined(QT_DLL) |
184 | #if _MSC_VER >= 1300 |
185 | // workaround http://support.microsoft.com/default.aspx?scid=kb;en-us;309801 |
186 | #include <QPointF> |
187 | #include <QVector> |
188 | template class Q_DECL_IMPORT QVector<QPointF>; |
189 | #endif |
190 | #endif |
191 | |
192 | namespace KDGantt { |
193 | enum ItemDataRole { |
194 | KDGanttRoleBase = Qt::UserRole + 1174, |
195 | StartTimeRole = KDGanttRoleBase + 1, |
196 | EndTimeRole = KDGanttRoleBase + 2, |
197 | TaskCompletionRole = KDGanttRoleBase + 3, |
198 | ItemTypeRole = KDGanttRoleBase + 4, |
199 | LegendRole = KDGanttRoleBase + 5 |
200 | }; |
201 | enum ItemType { |
202 | TypeNone = 0, |
203 | TypeEvent = 1, |
204 | TypeTask = 2, |
205 | TypeSummary = 3, |
206 | TypeMulti = 4, |
207 | TypeUser = 1000 |
208 | }; |
209 | |
210 | class Span { |
211 | qreal m_start; |
212 | qreal m_length; |
213 | public: |
214 | inline Span() : m_start( -1 ), m_length( 0 ) {} |
215 | inline Span( qreal start, qreal length ) : m_start( start ), m_length( length ) {} |
216 | inline Span( const Span& other ) : m_start(other.m_start), m_length(other.m_length) {} |
217 | inline ~Span() {} |
218 | |
219 | inline Span& operator=( const Span& other ) { m_start=other.m_start; m_length=other.m_length; return *this; } |
220 | |
221 | inline void setStart( qreal start ) { m_start=start; } |
222 | inline qreal start() const { return m_start; } |
223 | inline void setEnd( qreal end ) { m_length = m_start-end; } |
224 | inline qreal end() const { return m_start+m_length; } |
225 | |
226 | inline void setLength( qreal length ) { m_length=length; } |
227 | inline qreal length() const { return m_length; } |
228 | |
229 | inline bool isValid() const { return m_start >= 0.;} |
230 | |
231 | inline bool equals( const Span& other ) const { |
232 | return m_start == other.m_start && m_length == other.m_length; |
233 | } |
234 | }; |
235 | |
236 | inline bool operator==( const Span& s1, const Span& s2) { return s1.equals( s2 ); } |
237 | inline bool operator!=( const Span& s1, const Span& s2) { return !s1.equals( s2 ); } |
238 | |
239 | |
240 | class DateTimeSpan { |
241 | QDateTime m_start; |
242 | QDateTime m_end; |
243 | public: |
244 | DateTimeSpan(); |
245 | DateTimeSpan( const QDateTime& start, const QDateTime& end ); |
246 | DateTimeSpan( const DateTimeSpan& other ); |
247 | ~DateTimeSpan(); |
248 | |
249 | DateTimeSpan& operator=( const DateTimeSpan& other ); |
250 | |
251 | inline void setStart( const QDateTime& start ) { m_start=start; } |
252 | inline QDateTime start() const { return m_start; } |
253 | |
254 | inline void setEnd( const QDateTime& end ) { m_end=end; } |
255 | inline QDateTime end() const { return m_end; } |
256 | |
257 | bool isValid() const; |
258 | |
259 | bool equals( const DateTimeSpan& other ) const; |
260 | }; |
261 | |
262 | inline bool operator==( const DateTimeSpan& s1, const DateTimeSpan& s2) { return s1.equals( s2 ); } |
263 | inline bool operator!=( const DateTimeSpan& s1, const DateTimeSpan& s2) { return !s1.equals( s2 ); } |
264 | } |
265 | |
266 | Q_DECLARE_METATYPE(KDGantt::ItemType) |
267 | Q_DECLARE_TYPEINFO(KDGantt::Span, Q_MOVABLE_TYPE); |
268 | Q_DECLARE_TYPEINFO(KDGantt::DateTimeSpan, Q_MOVABLE_TYPE); |
269 | |
270 | #ifndef QT_NO_DEBUG_STREAM |
271 | |
272 | |
273 | QDebug operator<<( QDebug dbg, KDGantt::ItemDataRole r); |
274 | QDebug operator<<( QDebug dbg, const KDGantt::Span& s ); |
275 | QDebug operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s ); |
276 | |
277 | #endif /* QT_NO_DEBUG_STREAM */ |
278 | |
279 | #endif /* KDGANTTGLOBAL_H */ |
280 | |