1 /****************************************************************************
2 ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved.
4 ** This file is part of the KD Gantt library.
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
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
33 #include "kdgantt_export.h"
36 inline T
& __kdab__dereference_for_methodcall( T
& o
) {
41 inline T
& __kdab__dereference_for_methodcall( T
* 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 ) \
51 friend class Private; \
53 inline Private * d_func(); \
54 inline const Private * d_func() const; \
55 explicit inline X( Private * ); \
59 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \
62 friend class Private; \
63 inline Private * d_func(); \
64 inline const Private * d_func() const; \
65 explicit inline X( Private * ); \
70 #if defined(_MSC_VER) && _MSC_VER <= 1300
71 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
74 friend class Private; \
76 inline Private * d_func(); \
77 inline const Private * d_func() const; \
78 explicit inline X( Private *, ParentType ); \
82 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
85 friend class Private; \
86 inline Private * d_func(); \
87 inline const Private * d_func() const; \
88 explicit inline X( Private *, ParentType ); \
93 #define KDGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET( X ) \
94 KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, QWidget* )
96 #define KDGANTT_DECLARE_PRIVATE_BASE_VALUE( X ) \
98 inline void swap( X & other ) { qSwap( _d, other._d ); } \
101 friend class Private; \
102 Private * d_func() { return _d; } \
103 const Private * d_func() const { return _d; } \
108 #if defined(_MSC_VER) && _MSC_VER <= 1300
109 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
112 friend class Private; \
114 Private * d_func() { return _d; } \
115 const Private * d_func() const { return _d; } \
116 explicit inline X( Private * ); \
121 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
124 friend class Private; \
125 Private * d_func() { return _d; } \
126 const Private * d_func() const { return _d; } \
127 explicit inline X( Private * ); \
133 #if defined(_MSC_VER) && _MSC_VER <= 1300
134 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
137 friend class Private; \
139 Private * d_func() { return _d; } \
140 const Private * d_func() const { return _d; } \
141 explicit inline X( Private *, QWidget* ); \
146 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
149 friend class Private; \
150 Private * d_func() { return _d; } \
151 const Private * d_func() const { return _d; } \
152 explicit inline X( Private *, QWidget* ); \
160 // enable this for testing if KD Gantt works without STL support in Qt:
165 #include <QtAlgorithms> // qSwap
168 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
169 template <> inline void qSwap<X>( X & lhs, X & rhs ) \
170 { lhs.swap( rhs ); } \
172 template <> inline void swap<X>( X & lhs, X & rhs ) \
173 { lhs.swap( rhs ); } \
176 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
177 template <> inline void qSwap<X>( X & lhs, X & rhs ) \
181 #define KDGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED( X ) \
182 KDGANTT_DECLARE_SWAP_SPECIALISATION( X )
184 #define KDGANTT_DECLARE_SWAP_BASE( X ) \
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)
194 // workaround http://support.microsoft.com/default.aspx?scid=kb;en-us;309801
197 template class Q_DECL_IMPORT QVector
<QPointF
>;
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
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
) {}
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
); }
259 DateTimeSpan( const QDateTime
& start
, const QDateTime
& end
);
260 DateTimeSpan( const DateTimeSpan
& other
);
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 */