KD Chart API Documentation 3.0
Loading...
Searching...
No Matches
kdganttglobal.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Chart library.
4**
5** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
15#ifndef KDGANTTGLOBAL_H
16#define KDGANTTGLOBAL_H
17
18#include <QDateTime>
19#include <QDebug>
20#include <QMetaType>
21#include <Qt>
22
23#include "kdchart_export.h"
24
25#if (defined(__MINGW32__) || defined(__MINGW64__)) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 0)
26// workaround a mingw bug, https://sourceforge.net/p/mingw/bugs/1220/
27int swprintf(wchar_t *, size_t, const wchar_t *, ...);
28int vswprintf(wchar_t *, const wchar_t *, va_list);
29#endif
30
31#ifndef KDAB_SET_OBJECT_NAME
32template<typename T>
34{
35 return o;
36}
37
38template<typename T>
40{
41 return *o;
42}
43
44#define KDAB_SET_OBJECT_NAME(x) __kdab__dereference_for_methodcall(x).setObjectName(QLatin1String(#x))
45#endif
46
47#if defined(_MSC_VER) && _MSC_VER <= 1300
48#define KDGANTT_DECLARE_PRIVATE_DERIVED(X) \
49public: \
50 class Private; \
51 friend class Private; \
52 \
53protected: \
54 inline Private *d_func(); \
55 inline const Private *d_func() const; \
56 explicit inline X(Private *); \
57 \
58private: \
59 void init();
60#else
61#define KDGANTT_DECLARE_PRIVATE_DERIVED(X) \
62protected: \
63 class Private; \
64 friend class Private; \
65 inline Private *d_func(); \
66 inline const Private *d_func() const; \
67 explicit inline X(Private *); \
68 \
69private: \
70 void init();
71#endif
72
73#if defined(_MSC_VER) && _MSC_VER <= 1300
74#define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT(X, ParentType) \
75public: \
76 class Private; \
77 friend class Private; \
78 \
79protected: \
80 inline Private *d_func(); \
81 inline const Private *d_func() const; \
82 explicit inline X(Private *, ParentType); \
83 \
84private: \
85 void init();
86#else
87#define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT(X, ParentType) \
88protected: \
89 class Private; \
90 friend class Private; \
91 inline Private *d_func(); \
92 inline const Private *d_func() const; \
93 explicit inline X(Private *, ParentType); \
94 \
95private: \
96 void init();
97#endif
98
99#define KDGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET(X) \
100 KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT(X, QWidget *)
101
102#define KDGANTT_DECLARE_PRIVATE_BASE_VALUE(X) \
103public: \
104 inline void swap(X &other) \
105 { \
106 qSwap(_d, other._d); \
107 } \
108 \
109protected: \
110 class Private; \
111 friend class Private; \
112 Private *d_func() \
113 { \
114 return _d; \
115 } \
116 const Private *d_func() const \
117 { \
118 return _d; \
119 } \
120 \
121private: \
122 void init(); \
123 Private *_d;
124
125#if defined(_MSC_VER) && _MSC_VER <= 1300
126#define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC(X) \
127public: \
128 class Private; \
129 friend class Private; \
130 \
131protected: \
132 Private *d_func() \
133 { \
134 return _d; \
135 } \
136 const Private *d_func() const \
137 { \
138 return _d; \
139 } \
140 explicit inline X(Private *); \
141 \
142private: \
143 void init(); \
144 Private *_d;
145#else
146#define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC(X) \
147protected: \
148 class Private; \
149 friend class Private; \
150 Private *d_func() \
151 { \
152 return _d; \
153 } \
154 const Private *d_func() const \
155 { \
156 return _d; \
157 } \
158 explicit inline X(Private *); \
159 \
160private: \
161 void init(); \
162 Private *_d;
163#endif
164
165#if defined(_MSC_VER) && _MSC_VER <= 1300
166#define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET(X) \
167public: \
168 class Private; \
169 friend class Private; \
170 \
171protected: \
172 Private *d_func() \
173 { \
174 return _d; \
175 } \
176 const Private *d_func() const \
177 { \
178 return _d; \
179 } \
180 explicit inline X(Private *, QWidget *); \
181 \
182private: \
183 void init(); \
184 Private *_d;
185#else
186#define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET(X) \
187protected: \
188 class Private; \
189 friend class Private; \
190 Private *d_func() \
191 { \
192 return _d; \
193 } \
194 const Private *d_func() const \
195 { \
196 return _d; \
197 } \
198 explicit inline X(Private *, QWidget *); \
199 \
200private: \
201 void init(); \
202 Private *_d;
203#endif
204
205// enable this for testing if KD Gantt works without STL support in Qt:
206//
207// #define QT_NO_STL
208
209#include <QtAlgorithms> // qSwap
210#ifndef QT_NO_STL
211#include <algorithm>
212#define KDGANTT_DECLARE_SWAP_SPECIALISATION(X) \
213 QT_BEGIN_NAMESPACE \
214 template<> \
215 inline void qSwap<X>(X & lhs, X & rhs) \
216 { \
217 lhs.swap(rhs); \
218 } \
219 QT_END_NAMESPACE \
220 namespace std { \
221 template<> \
222 inline void swap<X>(X & lhs, X &rhs) \
223 { \
224 lhs.swap(rhs); \
225 } \
226 }
227#else
228#define KDGANTT_DECLARE_SWAP_SPECIALISATION(X) \
229 QT_BEGIN_NAMESPACE \
230 template<> \
231 inline void qSwap<X>(X & lhs, X & rhs) \
232 { \
233 lhs.swap(rhs); \
234 } \
235 QT_END_NAMESPACE
236#endif
237
238#define KDGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED(X) \
239 KDGANTT_DECLARE_SWAP_SPECIALISATION(X)
240
241#define KDGANTT_DECLARE_SWAP_BASE(X) \
242protected: \
243 void doSwap(X &other) \
244 { \
245 qSwap(_d, other._d); \
246 }
247
248#define KDGANTT_DECLARE_SWAP_DERIVED(X) \
249 void swap(X &other) \
250 { \
251 doSwap(other); \
252 }
253
254#if defined(Q_OS_WIN) && defined(QT_DLL)
255#if defined(_MSC_VER) && _MSC_VER >= 1300
256// workaround old msvc bug 309801 (link under support.microsoft.com no longer exists)
257#include <QPointF>
258#include <QVector>
259template class Q_DECL_IMPORT QVector<QPointF>;
260#endif
261#endif
262
263namespace KDGantt {
283
284class Span
285{
286 qreal m_start = -1;
287 qreal m_length = 0;
288
289public:
290 inline Span()
291 {
292 }
293 inline Span(qreal start, qreal length)
294 : m_start(start)
295 , m_length(length)
296 {
297 }
298 inline Span(const Span &other)
299 : m_start(other.m_start)
300 , m_length(other.m_length)
301 {
302 }
303
304 inline Span &operator=(const Span &other)
305 {
306 m_start = other.m_start;
307 m_length = other.m_length;
308 return *this;
309 }
310
311 inline void setStart(qreal start)
312 {
313 m_start = start;
314 }
315 inline qreal start() const
316 {
317 return m_start;
318 }
319 inline void setEnd(qreal end)
320 {
321 m_length = m_start - end;
322 }
323 inline qreal end() const
324 {
325 return m_start + m_length;
326 }
327
328 inline void setLength(qreal length)
329 {
330 m_length = length;
331 }
332 inline qreal length() const
333 {
334 return m_length;
335 }
336
337 inline bool isValid() const
338 {
339 return m_start >= 0.;
340 }
341
342 inline bool equals(const Span &other) const
343 {
344 return m_start == other.m_start && m_length == other.m_length;
345 }
346 inline Span expandedTo(const Span &other) const
347 {
348 const qreal new_start = qMin(start(), other.start());
349 return Span(new_start, (end() < other.end()) ? other.end() - new_start : end() - new_start);
350 }
351};
352
353inline bool operator==(const Span &s1, const Span &s2)
354{
355 return s1.equals(s2);
356}
357inline bool operator!=(const Span &s1, const Span &s2)
358{
359 return !s1.equals(s2);
360}
361
363{
364 QDateTime m_start;
365 QDateTime m_end;
366
367public:
368 DateTimeSpan();
369 DateTimeSpan(const QDateTime &start, const QDateTime &end);
370 DateTimeSpan(const DateTimeSpan &other);
372
373 DateTimeSpan &operator=(const DateTimeSpan &other);
374
375 inline void setStart(const QDateTime &start)
376 {
377 m_start = start;
378 }
379 inline QDateTime start() const
380 {
381 return m_start;
382 }
383
384 inline void setEnd(const QDateTime &end)
385 {
386 m_end = end;
387 }
388 inline QDateTime end() const
389 {
390 return m_end;
391 }
392
393 bool isValid() const;
394
395 bool equals(const DateTimeSpan &other) const;
396};
397
398inline bool operator==(const DateTimeSpan &s1, const DateTimeSpan &s2)
399{
400 return s1.equals(s2);
401}
402inline bool operator!=(const DateTimeSpan &s1, const DateTimeSpan &s2)
403{
404 return !s1.equals(s2);
405}
406}
407
408Q_DECLARE_METATYPE(KDGantt::ItemType)
409
410#ifndef QT_NO_DEBUG_STREAM
411QDebug KDGANTT_EXPORT operator<<(QDebug dbg, KDGantt::ItemDataRole r);
412QDebug KDGANTT_EXPORT operator<<(QDebug dbg, KDGantt::ItemType t);
413QDebug KDGANTT_EXPORT operator<<(QDebug dbg, const KDGantt::Span &s);
414QDebug KDGANTT_EXPORT operator<<(QDebug dbg, const KDGantt::DateTimeSpan &s);
415#endif /* QT_NO_DEBUG_STREAM */
416
417QT_BEGIN_NAMESPACE
420QT_END_NAMESPACE
421
422#endif /* KDGANTTGLOBAL_H */
QDateTime end() const
QDateTime start() const
bool equals(const DateTimeSpan &other) const
void setStart(const QDateTime &start)
void setEnd(const QDateTime &end)
A class representing a start point and a length.
Span & operator=(const Span &other)
Span expandedTo(const Span &other) const
qreal length() const
bool equals(const Span &other) const
void setStart(qreal start)
Span(qreal start, qreal length)
bool isValid() const
qreal end() const
Span(const Span &other)
void setEnd(qreal end)
qreal start() const
void setLength(qreal length)
QDebug KDGANTT_EXPORT operator<<(QDebug dbg, KDGantt::ItemDataRole r)
QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(KDGantt::Span, Q_MOVABLE_TYPE)
T & __kdab__dereference_for_methodcall(T &o)
bool operator!=(const Span &s1, const Span &s2)
ItemDataRole
KDGantt::KDGanttRoleBase The base value used for the KDGantt role enum values.
@ TaskCompletionRole
UserRole

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Sat Mar 23 2024 00:06:52 for KD Chart API Documentation by doxygen 1.9.8