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 
11 Contains 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
25 int swprintf (wchar_t *, size_t, const wchar_t *, ...);
26 int vswprintf(wchar_t *, const wchar_t *, va_list);
27 #endif
28 
29 #ifndef KDAB_SET_OBJECT_NAME
30 template <typename T>
31 inline T & __kdab__dereference_for_methodcall( T & o ) {
32  return o;
33 }
34 
35 template <typename T>
36 inline 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 ) \
45 public: \
46  class Private; \
47  friend class Private; \
48 protected: \
49  inline Private * d_func(); \
50  inline const Private * d_func() const; \
51  explicit inline X( Private * ); \
52 private: \
53  void init();
54 #else
55 #define KGANTT_DECLARE_PRIVATE_DERIVED( X ) \
56 protected: \
57  class Private; \
58  friend class Private; \
59  inline Private * d_func(); \
60  inline const Private * d_func() const; \
61  explicit inline X( Private * ); \
62 private: \
63  void init();
64 #endif
65 
66 #if defined(_MSC_VER) && _MSC_VER <= 1300
67 #define KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
68 public: \
69  class Private; \
70  friend class Private; \
71 protected: \
72  inline Private * d_func(); \
73  inline const Private * d_func() const; \
74  explicit inline X( Private *, ParentType ); \
75 private: \
76  void init();
77 #else
78 #define KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
79 protected: \
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 ); \
85 private: \
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 ) \
93 public: \
94  inline void swap( X & other ) { qSwap( _d, other._d ); } \
95 protected: \
96  class Private; \
97  friend class Private; \
98  Private * d_func() { return _d; } \
99  const Private * d_func() const { return _d; } \
100 private: \
101  void init(); \
102  Private * _d;
103 
104 #if defined(_MSC_VER) && _MSC_VER <= 1300
105 #define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
106 public: \
107  class Private; \
108  friend class Private; \
109 protected: \
110  Private * d_func() { return _d; } \
111  const Private * d_func() const { return _d; } \
112  explicit inline X( Private * ); \
113 private: \
114  void init(); \
115  Private * _d;
116 #else
117 #define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
118 protected: \
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 * ); \
124 private: \
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 ) \
131 public: \
132  class Private; \
133  friend class Private; \
134 protected: \
135  Private * d_func() { return _d; } \
136  const Private * d_func() const { return _d; } \
137  explicit inline X( Private *, QWidget* ); \
138 private: \
139  void init(); \
140  Private * _d;
141 #else
142 #define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
143 protected: \
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* ); \
149 private: \
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 ) \
165 QT_BEGIN_NAMESPACE \
166  template <> inline void qSwap<X>( X & lhs, X & rhs ) \
167  { lhs.swap( rhs ); } \
168 QT_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 ) \
175 QT_BEGIN_NAMESPACE \
176  template <> inline void qSwap<X>( X & lhs, X & rhs ) \
177  { lhs.swap( rhs ); } \
178 QT_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 ) \
185 protected: \
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>
197 template class Q_DECL_IMPORT QVector<QPointF>;
198 #endif
199 #endif
200 
201 /*!\namespace KGantt
202  *\ingroup KGantt
203  *\brief Global namespace
204  */
205 namespace 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 
299 Q_DECLARE_METATYPE(KGantt::ItemType)
300 
301 #ifndef QT_NO_DEBUG_STREAM
302 QDebug KGANTT_EXPORT operator<<( QDebug dbg, KGantt::ItemDataRole r);
303 QDebug KGANTT_EXPORT operator<<( QDebug dbg, KGantt::ItemType t);
304 QDebug KGANTT_EXPORT operator<<( QDebug dbg, const KGantt::Span& s );
305 QDebug KGANTT_EXPORT operator<<( QDebug dbg, const KGantt::DateTimeSpan& s );
306 #endif /* QT_NO_DEBUG_STREAM */
307 
308 QT_BEGIN_NAMESPACE
309 Q_DECLARE_TYPEINFO(KGantt::Span, Q_MOVABLE_TYPE);
310 Q_DECLARE_TYPEINFO(KGantt::DateTimeSpan, Q_MOVABLE_TYPE);
311 QT_END_NAMESPACE
312 
313 #endif /* KGANTTGLOBAL_H */
The item type.
Definition: kganttglobal.h:217
The Legend text.
Definition: kganttglobal.h:218
Start time (or other start value) for a gantt item.
Definition: kganttglobal.h:214
The base value used for the KGantt role enum values. The actual roles have values base+1...
Definition: kganttglobal.h:213
The position of the text label on the item. The type of this value is KGantt::StyleOptionGanttItem::P...
Definition: kganttglobal.h:219
UserRole
End time (or other end value) for a gantt item.
Definition: kganttglobal.h:215
Global namespace.
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
A class representing a start point and a length.
Definition: kganttglobal.h:240
Task completion percentage used by Task items. Should be an integer og a qreal between 0 and 100...
Definition: kganttglobal.h:216
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 22:32:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.