KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
kdganttglobal.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
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.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
27 #ifndef KDGANTTGLOBAL_H
28 #define KDGANTTGLOBAL_H
29 
30 #include <Qt>
31 #include <QDateTime>
32 #include <QDebug>
33 #include <QMetaType>
34 
35 #include "kdchart_export.h"
36 
37 #if (defined(__MINGW32__) || defined(__MINGW64__)) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 0)
38 // workaround a mingw bug, http://sourceforge.net/tracker/index.php?func=detail&aid=2373234&group_id=2435&atid=102435
39 int swprintf (wchar_t *, size_t, const wchar_t *, ...);
40 int vswprintf(wchar_t *, const wchar_t *, va_list);
41 #endif
42 
43 #ifndef KDAB_SET_OBJECT_NAME
44 template <typename T>
46  return o;
47 }
48 
49 template <typename T>
51  return *o;
52 }
53 
54 #define KDAB_SET_OBJECT_NAME( x ) __kdab__dereference_for_methodcall( x ).setObjectName( QLatin1String( #x ) )
55 #endif
56 
57 #if defined(_MSC_VER) && _MSC_VER <= 1300
58 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \
59 public: \
60  class Private; \
61  friend class Private; \
62 protected: \
63  inline Private * d_func(); \
64  inline const Private * d_func() const; \
65  explicit inline X( Private * ); \
66 private: \
67  void init();
68 #else
69 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \
70 protected: \
71  class Private; \
72  friend class Private; \
73  inline Private * d_func(); \
74  inline const Private * d_func() const; \
75  explicit inline X( Private * ); \
76 private: \
77  void init();
78 #endif
79 
80 #if defined(_MSC_VER) && _MSC_VER <= 1300
81 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
82 public: \
83  class Private; \
84  friend class Private; \
85 protected: \
86  inline Private * d_func(); \
87  inline const Private * d_func() const; \
88  explicit inline X( Private *, ParentType ); \
89 private: \
90  void init();
91 #else
92 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
93 protected: \
94  class Private; \
95  friend class Private; \
96  inline Private * d_func(); \
97  inline const Private * d_func() const; \
98  explicit inline X( Private *, ParentType ); \
99 private: \
100  void init();
101 #endif
102 
103 #define KDGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET( X ) \
104  KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, QWidget* )
105 
106 #define KDGANTT_DECLARE_PRIVATE_BASE_VALUE( X ) \
107 public: \
108  inline void swap( X & other ) { qSwap( _d, other._d ); } \
109 protected: \
110  class Private; \
111  friend class Private; \
112  Private * d_func() { return _d; } \
113  const Private * d_func() const { return _d; } \
114 private: \
115  void init(); \
116  Private * _d;
117 
118 #if defined(_MSC_VER) && _MSC_VER <= 1300
119 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
120 public: \
121  class Private; \
122  friend class Private; \
123 protected: \
124  Private * d_func() { return _d; } \
125  const Private * d_func() const { return _d; } \
126  explicit inline X( Private * ); \
127 private: \
128  void init(); \
129  Private * _d;
130 #else
131 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
132 protected: \
133  class Private; \
134  friend class Private; \
135  Private * d_func() { return _d; } \
136  const Private * d_func() const { return _d; } \
137  explicit inline X( Private * ); \
138 private: \
139  void init(); \
140  Private * _d;
141 #endif
142 
143 #if defined(_MSC_VER) && _MSC_VER <= 1300
144 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
145 public: \
146  class Private; \
147  friend class Private; \
148 protected: \
149  Private * d_func() { return _d; } \
150  const Private * d_func() const { return _d; } \
151  explicit inline X( Private *, QWidget* ); \
152 private: \
153  void init(); \
154  Private * _d;
155 #else
156 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
157 protected: \
158  class Private; \
159  friend class Private; \
160  Private * d_func() { return _d; } \
161  const Private * d_func() const { return _d; } \
162  explicit inline X( Private *, QWidget* ); \
163 private: \
164  void init(); \
165  Private * _d;
166 #endif
167 
168 
169 
170 // enable this for testing if KD Gantt works without STL support in Qt:
171 //
172 // #define QT_NO_STL
173 
174 
175 #include <QtAlgorithms> // qSwap
176 #ifndef QT_NO_STL
177 #include <algorithm>
178 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
179 QT_BEGIN_NAMESPACE \
180  template <> inline void qSwap<X>( X & lhs, X & rhs ) \
181  { lhs.swap( rhs ); } \
182 QT_END_NAMESPACE \
183  namespace std { \
184  template <> inline void swap<X>( X & lhs, X & rhs ) \
185  { lhs.swap( rhs ); } \
186  }
187 #else
188 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
189 QT_BEGIN_NAMESPACE \
190  template <> inline void qSwap<X>( X & lhs, X & rhs ) \
191  { lhs.swap( rhs ); } \
192 QT_END_NAMESPACE
193 #endif
194 
195 #define KDGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED( X ) \
196  KDGANTT_DECLARE_SWAP_SPECIALISATION( X )
197 
198 #define KDGANTT_DECLARE_SWAP_BASE( X ) \
199 protected: \
200  void doSwap( X& other ) \
201  { qSwap( _d, other._d); }
202 
203 #define KDGANTT_DECLARE_SWAP_DERIVED( X ) \
204  void swap( X& other ) { doSwap( other ); }
205 
206 #if defined(Q_OS_WIN) && defined(QT_DLL)
207 #if defined(_MSC_VER) && _MSC_VER >= 1300
208 // workaround http://support.microsoft.com/default.aspx?scid=kb;en-us;309801
209 #include <QPointF>
210 #include <QVector>
211 template class Q_DECL_IMPORT QVector<QPointF>;
212 #endif
213 #endif
214 
215 namespace KDGantt {
217  KDGanttRoleBase = Qt::UserRole + 1174,
224  };
225  enum ItemType {
226  TypeNone = 0,
228  TypeTask = 2,
231  TypeUser = 1000
232  };
233 
234  class Span {
235  qreal m_start;
236  qreal m_length;
237  public:
238  inline Span() : m_start( -1 ), m_length( 0 ) {}
239  inline Span( qreal start, qreal length ) : m_start( start ), m_length( length ) {}
240  inline Span( const Span& other ) : m_start(other.m_start), m_length(other.m_length) {}
241 
242  inline Span& operator=( const Span& other ) { m_start=other.m_start; m_length=other.m_length; return *this; }
243 
244  inline void setStart( qreal start ) { m_start=start; }
245  inline qreal start() const { return m_start; }
246  inline void setEnd( qreal end ) { m_length = m_start-end; }
247  inline qreal end() const { return m_start+m_length; }
248 
249  inline void setLength( qreal length ) { m_length=length; }
250  inline qreal length() const { return m_length; }
251 
252  inline bool isValid() const { return m_start >= 0.;}
253 
254  inline bool equals( const Span& other ) const {
255  return m_start == other.m_start && m_length == other.m_length;
256  }
257  inline Span expandedTo( const Span& other) const {
258  const qreal new_start = qMin(start(),other.start());
259  return Span( new_start, (end()<other.end())?other.end()-new_start:end()-new_start);
260  }
261  };
262 
263  inline bool operator==( const Span& s1, const Span& s2) { return s1.equals( s2 ); }
264  inline bool operator!=( const Span& s1, const Span& s2) { return !s1.equals( s2 ); }
265 
266 
267  class DateTimeSpan {
268  QDateTime m_start;
269  QDateTime m_end;
270  public:
271  DateTimeSpan();
272  DateTimeSpan( const QDateTime& start, const QDateTime& end );
273  DateTimeSpan( const DateTimeSpan& other );
274  ~DateTimeSpan();
275 
276  DateTimeSpan& operator=( const DateTimeSpan& other );
277 
278  inline void setStart( const QDateTime& start ) { m_start=start; }
279  inline QDateTime start() const { return m_start; }
280 
281  inline void setEnd( const QDateTime& end ) { m_end=end; }
282  inline QDateTime end() const { return m_end; }
283 
284  bool isValid() const;
285 
286  bool equals( const DateTimeSpan& other ) const;
287  };
288 
289  inline bool operator==( const DateTimeSpan& s1, const DateTimeSpan& s2) { return s1.equals( s2 ); }
290  inline bool operator!=( const DateTimeSpan& s1, const DateTimeSpan& s2) { return !s1.equals( s2 ); }
291 }
292 
293 Q_DECLARE_METATYPE(KDGantt::ItemType)
294 
295 #ifndef QT_NO_DEBUG_STREAM
296 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::ItemDataRole r);
297 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::ItemType t);
298 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, const KDGantt::Span& s );
299 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s );
300 #endif /* QT_NO_DEBUG_STREAM */
301 
302 QT_BEGIN_NAMESPACE
303 Q_DECLARE_TYPEINFO(KDGantt::Span, Q_MOVABLE_TYPE);
305 QT_END_NAMESPACE
306 
307 #endif /* KDGANTTGLOBAL_H */

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/