KGantt

kganttglobal.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KGantt library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8/** \file kganttglobal.h
9\brief Contains KGantt macros.
10
11Contains KGantt macros. */
12
13#ifndef KGANTTGLOBAL_H
14#define KGANTTGLOBAL_H
15
16#include <Qt>
17#include <QDateTime>
18#include <QDebug>
19#include <QMetaType>
20
21#include "kgantt_export.h"
22
23#if (defined(__MINGW32__) || defined(__MINGW64__)) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 0)
24// workaround a mingw bug, http://sourceforge.net/tracker/index.php?func=detail&aid=2373234&group_id=2435&atid=102435
25int swprintf (wchar_t *, size_t, const wchar_t *, ...);
26int vswprintf(wchar_t *, const wchar_t *, va_list);
27#endif
28
29#ifndef KDAB_SET_OBJECT_NAME
30template <typename T>
31inline T & __kdab__dereference_for_methodcall( T & o ) {
32 return o;
33}
34
35template <typename T>
36inline T & __kdab__dereference_for_methodcall( T * o ) {
37 return *o;
38}
39
40#define KDAB_SET_OBJECT_NAME( x ) __kdab__dereference_for_methodcall( x ).setObjectName( QLatin1String( #x ) )
41#endif
42
43#if defined(_MSC_VER) && _MSC_VER <= 1300
44#define KGANTT_DECLARE_PRIVATE_DERIVED( X ) \
45public: \
46 class Private; \
47 friend class Private; \
48protected: \
49 inline Private * d_func(); \
50 inline const Private * d_func() const; \
51 explicit inline X( Private * ); \
52private: \
53 void init();
54#else
55#define KGANTT_DECLARE_PRIVATE_DERIVED( X ) \
56protected: \
57 class Private; \
58 friend class Private; \
59 inline Private * d_func(); \
60 inline const Private * d_func() const; \
61 explicit inline X( Private * ); \
62private: \
63 void init();
64#endif
65
66#if defined(_MSC_VER) && _MSC_VER <= 1300
67#define KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
68public: \
69 class Private; \
70 friend class Private; \
71protected: \
72 inline Private * d_func(); \
73 inline const Private * d_func() const; \
74 explicit inline X( Private *, ParentType ); \
75private: \
76 void init();
77#else
78#define KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
79protected: \
80 class Private; \
81 friend class Private; \
82 inline Private * d_func(); \
83 inline const Private * d_func() const; \
84 explicit inline X( Private *, ParentType ); \
85private: \
86 void init();
87#endif
88
89#define KGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET( X ) \
90 KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, QWidget* )
91
92#define KGANTT_DECLARE_PRIVATE_BASE_VALUE( X ) \
93public: \
94 inline void swap( X & other ) { qSwap( _d, other._d ); } \
95protected: \
96 class Private; \
97 friend class Private; \
98 Private * d_func() { return _d; } \
99 const Private * d_func() const { return _d; } \
100private: \
101 void init(); \
102 Private * _d;
103
104#if defined(_MSC_VER) && _MSC_VER <= 1300
105#define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
106public: \
107 class Private; \
108 friend class Private; \
109protected: \
110 Private * d_func() { return _d; } \
111 const Private * d_func() const { return _d; } \
112 explicit inline X( Private * ); \
113private: \
114 void init(); \
115 Private * _d;
116#else
117#define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
118protected: \
119 class Private; \
120 friend class Private; \
121 Private * d_func() { return _d; } \
122 const Private * d_func() const { return _d; } \
123 explicit inline X( Private * ); \
124private: \
125 void init(); \
126 Private * _d;
127#endif
128
129#if defined(_MSC_VER) && _MSC_VER <= 1300
130#define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
131public: \
132 class Private; \
133 friend class Private; \
134protected: \
135 Private * d_func() { return _d; } \
136 const Private * d_func() const { return _d; } \
137 explicit inline X( Private *, QWidget* ); \
138private: \
139 void init(); \
140 Private * _d;
141#else
142#define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
143protected: \
144 class Private; \
145 friend class Private; \
146 Private * d_func() { return _d; } \
147 const Private * d_func() const { return _d; } \
148 explicit inline X( Private *, QWidget* ); \
149private: \
150 void init(); \
151 Private * _d;
152#endif
153
154
155
156// enable this for testing if KD Gantt works without STL support in Qt:
157//
158// #define QT_NO_STL
159
160
161#include <QtAlgorithms> // qSwap
162#ifndef QT_NO_STL
163#include <algorithm>
164#define KGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
165QT_BEGIN_NAMESPACE \
166 template <> inline void qSwap<X>( X & lhs, X & rhs ) \
167 { lhs.swap( rhs ); } \
168QT_END_NAMESPACE \
169 namespace std { \
170 template <> inline void swap<X>( X & lhs, X & rhs ) \
171 { lhs.swap( rhs ); } \
172 }
173#else
174#define KGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
175QT_BEGIN_NAMESPACE \
176 template <> inline void qSwap<X>( X & lhs, X & rhs ) \
177 { lhs.swap( rhs ); } \
178QT_END_NAMESPACE
179#endif
180
181#define KGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED( X ) \
182 KGANTT_DECLARE_SWAP_SPECIALISATION( X )
183
184#define KGANTT_DECLARE_SWAP_BASE( X ) \
185protected: \
186 void doSwap( X& other ) \
187 { qSwap( _d, other._d); }
188
189#define KGANTT_DECLARE_SWAP_DERIVED( X ) \
190 void swap( X& other ) { doSwap( other ); }
191
192#if defined(Q_OS_WIN) && defined(QT_DLL)
193#if defined(_MSC_VER) && _MSC_VER >= 1300
194// workaround http://support.microsoft.com/default.aspx?scid=kb;en-us;309801
195#include <QPointF>
196#include <QVector>
197template class Q_DECL_IMPORT QVector<QPointF>;
198#endif
199#endif
200
201/*!\namespace KGantt
202 *\ingroup KGantt
203 *\brief Global namespace
204 */
205namespace KGantt {
206
207 /*!\enum KGantt::ItemDataRole
208 *\ingroup KGantt
209 * The values of this enum are used for the special data roles
210 * for gantt items
211 */
213 KGanttRoleBase = Qt::UserRole + 1174, ///< The base value used for the KGantt role enum values. The actual roles have values base+1, base+2, ...
214 StartTimeRole = KGanttRoleBase + 1, ///< Start time (or other start value) for a gantt item.
215 EndTimeRole = KGanttRoleBase + 2, ///< End time (or other end value) for a gantt item.
216 TaskCompletionRole = KGanttRoleBase + 3, ///< Task completion percentage used by Task items. Should be an integer og a qreal between 0 and 100.
217 ItemTypeRole = KGanttRoleBase + 4, ///< The item type. \see KGantt::ItemType.
218 LegendRole = KGanttRoleBase + 5, ///< The Legend text
219 TextPositionRole = KGanttRoleBase + 6 ///< The position of the text label on the item. The type of this value is KGantt::StyleOptionGanttItem::Position and the default values is Right.
220 };
221
222 /*!\enum KGantt::ItemType
223 *\ingroup KGantt
224 * The values of this enum are used to represent the different
225 * types of gantt items that KGantt understands. The itemtype
226 * is served through the KGantt::ItemTypeRole role
227 */
228 enum ItemType {
229 TypeNone = 0,
230 TypeEvent = 1,
231 TypeTask = 2,
232 TypeSummary = 3,
233 TypeMulti = 4,
234 TypeUser = 1000
235 };
236
237 /*!\class KGantt::Span kganttglobal.h KGanttGlobal
238 *\ingroup KGantt
239 * \brief A class representing a start point and a length */
240 class Span {
241 qreal m_start;
242 qreal m_length;
243 public:
244 inline Span() : m_start( -1 ), m_length( 0 ) {}
245 inline Span( qreal start, qreal length ) : m_start( start ), m_length( length ) {}
246 inline Span( const Span& other ) : m_start(other.m_start), m_length(other.m_length) {}
247
248 inline Span& operator=( const Span& other ) { m_start=other.m_start; m_length=other.m_length; return *this; }
249
250 inline void setStart( qreal start ) { m_start=start; }
251 inline qreal start() const { return m_start; }
252 inline void setEnd( qreal end ) { m_length = m_start-end; }
253 inline qreal end() const { return m_start+m_length; }
254
255 inline void setLength( qreal length ) { m_length=length; }
256 inline qreal length() const { return m_length; }
257
258 inline bool isValid() const { return m_start >= 0.;}
259
260 inline bool equals( const Span& other ) const {
261 return m_start == other.m_start && m_length == other.m_length;
262 }
263 inline Span expandedTo( const Span& other) const {
264 const qreal new_start = qMin(start(),other.start());
265 return Span( new_start, (end()<other.end())?other.end()-new_start:end()-new_start);
266 }
267 };
268
269 inline bool operator==( const Span& s1, const Span& s2) { return s1.equals( s2 ); }
270 inline bool operator!=( const Span& s1, const Span& s2) { return !s1.equals( s2 ); }
271
272
273 class DateTimeSpan {
274 QDateTime m_start;
275 QDateTime m_end;
276 public:
277 DateTimeSpan();
278 DateTimeSpan( const QDateTime& start, const QDateTime& end );
279 DateTimeSpan( const DateTimeSpan& other );
280 ~DateTimeSpan();
281
282 DateTimeSpan& operator=( const DateTimeSpan& other );
283
284 inline void setStart( const QDateTime& start ) { m_start=start; }
285 inline QDateTime start() const { return m_start; }
286
287 inline void setEnd( const QDateTime& end ) { m_end=end; }
288 inline QDateTime end() const { return m_end; }
289
290 bool isValid() const;
291
292 bool equals( const DateTimeSpan& other ) const;
293 };
294
295 inline bool operator==( const DateTimeSpan& s1, const DateTimeSpan& s2) { return s1.equals( s2 ); }
296 inline bool operator!=( const DateTimeSpan& s1, const DateTimeSpan& s2) { return !s1.equals( s2 ); }
297}
298
299Q_DECLARE_METATYPE(KGantt::ItemType)
300
301#ifndef QT_NO_DEBUG_STREAM
302QDebug KGANTT_EXPORT operator<<( QDebug dbg, KGantt::ItemDataRole r);
303QDebug KGANTT_EXPORT operator<<( QDebug dbg, KGantt::ItemType t);
304QDebug KGANTT_EXPORT operator<<( QDebug dbg, const KGantt::Span& s );
305QDebug KGANTT_EXPORT operator<<( QDebug dbg, const KGantt::DateTimeSpan& s );
306#endif /* QT_NO_DEBUG_STREAM */
307
308QT_BEGIN_NAMESPACE
309Q_DECLARE_TYPEINFO(KGantt::Span, Q_MOVABLE_TYPE);
310Q_DECLARE_TYPEINFO(KGantt::DateTimeSpan, Q_MOVABLE_TYPE);
311QT_END_NAMESPACE
312
313#endif /* KGANTTGLOBAL_H */
A class representing a start point and a length.
Q_SCRIPTABLE Q_NOREPLY void start()
Global namespace.
@ ItemTypeRole
The item type.
@ KGanttRoleBase
The base value used for the KGantt role enum values. The actual roles have values base+1,...
@ StartTimeRole
Start time (or other start value) for a gantt item.
@ TaskCompletionRole
Task completion percentage used by Task items. Should be an integer og a qreal between 0 and 100.
@ LegendRole
The Legend text.
@ EndTimeRole
End time (or other end value) for a gantt item.
@ TextPositionRole
The position of the text label on the item. The type of this value is KGantt::StyleOptionGanttItem::P...
bool isValid(QStringView ifopt)
const QList< QKeySequence > & end()
KTEXTEDITOR_EXPORT QDebug operator<<(QDebug s, const MovingCursor &cursor)
bool equals(const QVariant &lhs, const QVariant &rhs)
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
bool operator!=(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:54:55 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.