Documentation: Completed Backup section, update menu.
[kdepim.git] / kdgantt2 / kdganttglobal.h
bloba7e2cd0c30890367396470d506080e172a70b52e
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 distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file.
11 ** Licensees holding valid commercial KD Gantt licenses may use this file in
12 ** accordance with the KD Gantt Commercial License Agreement provided with
13 ** the Software.
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 ** See http://www.kdab.net/kdgantt for
19 ** information about KD Gantt Commercial License Agreements.
21 ** Contact info@kdab.net if any conditions of this
22 ** licensing are not clear to you.
24 **********************************************************************/
25 #ifndef KDGANTTGLOBAL_H
26 #define KDGANTTGLOBAL_H
28 #include <Qt>
29 #include <QDateTime>
30 #include <QDebug>
31 #include <QMetaType>
33 #include "kdgantt_export.h"
35 template <typename T>
36 inline T & __kdab__dereference_for_methodcall( T & o ) {
37 return o;
40 template <typename T>
41 inline T & __kdab__dereference_for_methodcall( T * o ) {
42 return *o;
45 #define KDAB_SET_OBJECT_NAME( x ) __kdab__dereference_for_methodcall( x ).setObjectName( QLatin1String( #x ) )
47 #if defined(_MSC_VER) && _MSC_VER <= 1300
48 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \
49 public: \
50 class Private; \
51 friend class Private; \
52 protected: \
53 inline Private * d_func(); \
54 inline const Private * d_func() const; \
55 explicit inline X( Private * ); \
56 private: \
57 void init();
58 #else
59 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \
60 protected: \
61 class Private; \
62 friend class Private; \
63 inline Private * d_func(); \
64 inline const Private * d_func() const; \
65 explicit inline X( Private * ); \
66 private: \
67 void init();
68 #endif
70 #if defined(_MSC_VER) && _MSC_VER <= 1300
71 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
72 public: \
73 class Private; \
74 friend class Private; \
75 protected: \
76 inline Private * d_func(); \
77 inline const Private * d_func() const; \
78 explicit inline X( Private *, ParentType ); \
79 private: \
80 void init();
81 #else
82 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
83 protected: \
84 class Private; \
85 friend class Private; \
86 inline Private * d_func(); \
87 inline const Private * d_func() const; \
88 explicit inline X( Private *, ParentType ); \
89 private: \
90 void init();
91 #endif
93 #define KDGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET( X ) \
94 KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, QWidget* )
96 #define KDGANTT_DECLARE_PRIVATE_BASE_VALUE( X ) \
97 public: \
98 inline void swap( X & other ) { qSwap( _d, other._d ); } \
99 protected: \
100 class Private; \
101 friend class Private; \
102 Private * d_func() { return _d; } \
103 const Private * d_func() const { return _d; } \
104 private: \
105 void init(); \
106 Private * _d;
108 #if defined(_MSC_VER) && _MSC_VER <= 1300
109 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
110 public: \
111 class Private; \
112 friend class Private; \
113 protected: \
114 Private * d_func() { return _d; } \
115 const Private * d_func() const { return _d; } \
116 explicit inline X( Private * ); \
117 private: \
118 void init(); \
119 Private * _d;
120 #else
121 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
122 protected: \
123 class Private; \
124 friend class Private; \
125 Private * d_func() { return _d; } \
126 const Private * d_func() const { return _d; } \
127 explicit inline X( Private * ); \
128 private: \
129 void init(); \
130 Private * _d;
131 #endif
133 #if defined(_MSC_VER) && _MSC_VER <= 1300
134 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
135 public: \
136 class Private; \
137 friend class Private; \
138 protected: \
139 Private * d_func() { return _d; } \
140 const Private * d_func() const { return _d; } \
141 explicit inline X( Private *, QWidget* ); \
142 private: \
143 void init(); \
144 Private * _d;
145 #else
146 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
147 protected: \
148 class Private; \
149 friend class Private; \
150 Private * d_func() { return _d; } \
151 const Private * d_func() const { return _d; } \
152 explicit inline X( Private *, QWidget* ); \
153 private: \
154 void init(); \
155 Private * _d;
156 #endif
160 // enable this for testing if KD Gantt works without STL support in Qt:
162 // #define QT_NO_STL
165 #include <QtAlgorithms> // qSwap
166 #ifndef QT_NO_STL
167 #include <algorithm>
168 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
169 template <> inline void qSwap<X>( X & lhs, X & rhs ) \
170 { lhs.swap( rhs ); } \
171 namespace std { \
172 template <> inline void swap<X>( X & lhs, X & rhs ) \
173 { lhs.swap( rhs ); } \
175 #else
176 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
177 template <> inline void qSwap<X>( X & lhs, X & rhs ) \
178 { lhs.swap( rhs ); }
179 #endif
181 #define KDGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED( X ) \
182 KDGANTT_DECLARE_SWAP_SPECIALISATION( X )
184 #define KDGANTT_DECLARE_SWAP_BASE( X ) \
185 protected: \
186 void doSwap( X& other ) \
187 { qSwap( _d, other._d); }
189 #define KDGANTT_DECLARE_SWAP_DERIVED( X ) \
190 void swap( X& other ) { doSwap( other ); }
192 #if defined(Q_OS_WIN) && defined(QT_DLL)
193 #if _MSC_VER >= 1300
194 // workaround http://support.microsoft.com/default.aspx?scid=kb;en-us;309801
195 #include <QPointF>
196 #include <QVector>
197 template class Q_DECL_IMPORT QVector<QPointF>;
198 #endif
199 #endif
201 namespace KDGantt {
202 enum ItemDataRole {
203 KDGanttRoleBase = Qt::UserRole + 1174,
204 StartTimeRole = KDGanttRoleBase + 1,
205 EndTimeRole = KDGanttRoleBase + 2,
206 TaskCompletionRole = KDGanttRoleBase + 3,
207 ItemTypeRole = KDGanttRoleBase + 4,
208 LegendRole = KDGanttRoleBase + 5,
209 TextPositionRole = KDGanttRoleBase + 6
211 enum ItemType {
212 TypeNone = 0,
213 TypeEvent = 1,
214 TypeTask = 2,
215 TypeSummary = 3,
216 TypeMulti = 4,
217 TypeUser = 1000
220 class Span {
221 qreal m_start;
222 qreal m_length;
223 public:
224 inline Span() : m_start( -1 ), m_length( 0 ) {}
225 inline Span( qreal start, qreal length ) : m_start( start ), m_length( length ) {}
226 inline Span( const Span& other ) : m_start(other.m_start), m_length(other.m_length) {}
227 ~Span();
229 inline Span& operator=( const Span& other ) { m_start=other.m_start; m_length=other.m_length; return *this; }
231 inline void setStart( qreal start ) { m_start=start; }
232 inline qreal start() const { return m_start; }
233 inline void setEnd( qreal end ) { m_length = m_start-end; }
234 inline qreal end() const { return m_start+m_length; }
236 inline void setLength( qreal length ) { m_length=length; }
237 inline qreal length() const { return m_length; }
239 inline bool isValid() const { return m_start >= 0.;}
241 inline bool equals( const Span& other ) const {
242 return m_start == other.m_start && m_length == other.m_length;
244 inline Span expandedTo( const Span& other) const {
245 const qreal new_start = qMin(start(),other.start());
246 return Span( new_start, (end()<other.end())?other.end()-new_start:end()-new_start);
250 inline bool operator==( const Span& s1, const Span& s2) { return s1.equals( s2 ); }
251 inline bool operator!=( const Span& s1, const Span& s2) { return !s1.equals( s2 ); }
254 class DateTimeSpan {
255 QDateTime m_start;
256 QDateTime m_end;
257 public:
258 DateTimeSpan();
259 DateTimeSpan( const QDateTime& start, const QDateTime& end );
260 DateTimeSpan( const DateTimeSpan& other );
261 ~DateTimeSpan();
263 DateTimeSpan& operator=( const DateTimeSpan& other );
265 inline void setStart( const QDateTime& start ) { m_start=start; }
266 inline QDateTime start() const { return m_start; }
268 inline void setEnd( const QDateTime& end ) { m_end=end; }
269 inline QDateTime end() const { return m_end; }
271 bool isValid() const;
273 bool equals( const DateTimeSpan& other ) const;
276 inline bool operator==( const DateTimeSpan& s1, const DateTimeSpan& s2) { return s1.equals( s2 ); }
277 inline bool operator!=( const DateTimeSpan& s1, const DateTimeSpan& s2) { return !s1.equals( s2 ); }
280 Q_DECLARE_METATYPE(KDGantt::ItemType)
281 Q_DECLARE_TYPEINFO(KDGantt::Span, Q_MOVABLE_TYPE);
282 Q_DECLARE_TYPEINFO(KDGantt::DateTimeSpan, Q_MOVABLE_TYPE);
284 #ifndef QT_NO_DEBUG_STREAM
287 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::ItemDataRole r);
288 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::ItemType t);
289 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, const KDGantt::Span& s );
290 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s );
292 #endif /* QT_NO_DEBUG_STREAM */
294 #endif /* KDGANTTGLOBAL_H */