00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00026 #ifndef KDGANTTGLOBAL_H
00027 #define KDGANTTGLOBAL_H
00028
00029 #include <Qt>
00030 #include <QDateTime>
00031 #include <QDebug>
00032 #include <QMetaType>
00033
00034 #include "kdchart_export.h"
00035
00036 #if (defined(__MINGW32__) || defined(__MINGW64__)) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 0)
00037
00038 int swprintf (wchar_t *, size_t, const wchar_t *, ...);
00039 int vswprintf(wchar_t *, const wchar_t *, va_list);
00040 #endif
00041
00042 #ifndef KDAB_SET_OBJECT_NAME
00043 template <typename T>
00044 inline T & __kdab__dereference_for_methodcall( T & o ) {
00045 return o;
00046 }
00047
00048 template <typename T>
00049 inline T & __kdab__dereference_for_methodcall( T * o ) {
00050 return *o;
00051 }
00052
00053 #define KDAB_SET_OBJECT_NAME( x ) __kdab__dereference_for_methodcall( x ).setObjectName( QLatin1String( #x ) )
00054 #endif
00055
00056 #if defined(_MSC_VER) && _MSC_VER <= 1300
00057 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \
00058 public: \
00059 class Private; \
00060 friend class Private; \
00061 protected: \
00062 inline Private * d_func(); \
00063 inline const Private * d_func() const; \
00064 explicit inline X( Private * ); \
00065 private: \
00066 void init();
00067 #else
00068 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \
00069 protected: \
00070 class Private; \
00071 friend class Private; \
00072 inline Private * d_func(); \
00073 inline const Private * d_func() const; \
00074 explicit inline X( Private * ); \
00075 private: \
00076 void init();
00077 #endif
00078
00079 #if defined(_MSC_VER) && _MSC_VER <= 1300
00080 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
00081 public: \
00082 class Private; \
00083 friend class Private; \
00084 protected: \
00085 inline Private * d_func(); \
00086 inline const Private * d_func() const; \
00087 explicit inline X( Private *, ParentType ); \
00088 private: \
00089 void init();
00090 #else
00091 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \
00092 protected: \
00093 class Private; \
00094 friend class Private; \
00095 inline Private * d_func(); \
00096 inline const Private * d_func() const; \
00097 explicit inline X( Private *, ParentType ); \
00098 private: \
00099 void init();
00100 #endif
00101
00102 #define KDGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET( X ) \
00103 KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, QWidget* )
00104
00105 #define KDGANTT_DECLARE_PRIVATE_BASE_VALUE( X ) \
00106 public: \
00107 inline void swap( X & other ) { qSwap( _d, other._d ); } \
00108 protected: \
00109 class Private; \
00110 friend class Private; \
00111 Private * d_func() { return _d; } \
00112 const Private * d_func() const { return _d; } \
00113 private: \
00114 void init(); \
00115 Private * _d;
00116
00117 #if defined(_MSC_VER) && _MSC_VER <= 1300
00118 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
00119 public: \
00120 class Private; \
00121 friend class Private; \
00122 protected: \
00123 Private * d_func() { return _d; } \
00124 const Private * d_func() const { return _d; } \
00125 explicit inline X( Private * ); \
00126 private: \
00127 void init(); \
00128 Private * _d;
00129 #else
00130 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \
00131 protected: \
00132 class Private; \
00133 friend class Private; \
00134 Private * d_func() { return _d; } \
00135 const Private * d_func() const { return _d; } \
00136 explicit inline X( Private * ); \
00137 private: \
00138 void init(); \
00139 Private * _d;
00140 #endif
00141
00142 #if defined(_MSC_VER) && _MSC_VER <= 1300
00143 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
00144 public: \
00145 class Private; \
00146 friend class Private; \
00147 protected: \
00148 Private * d_func() { return _d; } \
00149 const Private * d_func() const { return _d; } \
00150 explicit inline X( Private *, QWidget* ); \
00151 private: \
00152 void init(); \
00153 Private * _d;
00154 #else
00155 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \
00156 protected: \
00157 class Private; \
00158 friend class Private; \
00159 Private * d_func() { return _d; } \
00160 const Private * d_func() const { return _d; } \
00161 explicit inline X( Private *, QWidget* ); \
00162 private: \
00163 void init(); \
00164 Private * _d;
00165 #endif
00166
00167
00168
00169
00170
00171
00172
00173
00174 #include <QtAlgorithms>
00175 #ifndef QT_NO_STL
00176 #include <algorithm>
00177 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
00178 template <> inline void qSwap<X>( X & lhs, X & rhs ) \
00179 { lhs.swap( rhs ); } \
00180 namespace std { \
00181 template <> inline void swap<X>( X & lhs, X & rhs ) \
00182 { lhs.swap( rhs ); } \
00183 }
00184 #else
00185 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \
00186 template <> inline void qSwap<X>( X & lhs, X & rhs ) \
00187 { lhs.swap( rhs ); }
00188 #endif
00189
00190 #define KDGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED( X ) \
00191 KDGANTT_DECLARE_SWAP_SPECIALISATION( X )
00192
00193 #define KDGANTT_DECLARE_SWAP_BASE( X ) \
00194 protected: \
00195 void doSwap( X& other ) \
00196 { qSwap( _d, other._d); }
00197
00198 #define KDGANTT_DECLARE_SWAP_DERIVED( X ) \
00199 void swap( X& other ) { doSwap( other ); }
00200
00201 #if defined(Q_OS_WIN) && defined(QT_DLL)
00202 #if defined(_MSC_VER) && _MSC_VER >= 1300
00203
00204 #include <QPointF>
00205 #include <QVector>
00206 template class Q_DECL_IMPORT QVector<QPointF>;
00207 #endif
00208 #endif
00209
00210 namespace KDGantt {
00211 enum ItemDataRole {
00212 KDGanttRoleBase = Qt::UserRole + 1174,
00213 StartTimeRole = KDGanttRoleBase + 1,
00214 EndTimeRole = KDGanttRoleBase + 2,
00215 TaskCompletionRole = KDGanttRoleBase + 3,
00216 ItemTypeRole = KDGanttRoleBase + 4,
00217 LegendRole = KDGanttRoleBase + 5,
00218 TextPositionRole = KDGanttRoleBase + 6
00219 };
00220 enum ItemType {
00221 TypeNone = 0,
00222 TypeEvent = 1,
00223 TypeTask = 2,
00224 TypeSummary = 3,
00225 TypeMulti = 4,
00226 TypeUser = 1000
00227 };
00228
00229 class Span {
00230 qreal m_start;
00231 qreal m_length;
00232 public:
00233 inline Span() : m_start( -1 ), m_length( 0 ) {}
00234 inline Span( qreal start, qreal length ) : m_start( start ), m_length( length ) {}
00235 inline Span( const Span& other ) : m_start(other.m_start), m_length(other.m_length) {}
00236
00237 inline Span& operator=( const Span& other ) { m_start=other.m_start; m_length=other.m_length; return *this; }
00238
00239 inline void setStart( qreal start ) { m_start=start; }
00240 inline qreal start() const { return m_start; }
00241 inline void setEnd( qreal end ) { m_length = m_start-end; }
00242 inline qreal end() const { return m_start+m_length; }
00243
00244 inline void setLength( qreal length ) { m_length=length; }
00245 inline qreal length() const { return m_length; }
00246
00247 inline bool isValid() const { return m_start >= 0.;}
00248
00249 inline bool equals( const Span& other ) const {
00250 return m_start == other.m_start && m_length == other.m_length;
00251 }
00252 inline Span expandedTo( const Span& other) const {
00253 const qreal new_start = qMin(start(),other.start());
00254 return Span( new_start, (end()<other.end())?other.end()-new_start:end()-new_start);
00255 }
00256 };
00257
00258 inline bool operator==( const Span& s1, const Span& s2) { return s1.equals( s2 ); }
00259 inline bool operator!=( const Span& s1, const Span& s2) { return !s1.equals( s2 ); }
00260
00261
00262 class DateTimeSpan {
00263 QDateTime m_start;
00264 QDateTime m_end;
00265 public:
00266 DateTimeSpan();
00267 DateTimeSpan( const QDateTime& start, const QDateTime& end );
00268 DateTimeSpan( const DateTimeSpan& other );
00269 ~DateTimeSpan();
00270
00271 DateTimeSpan& operator=( const DateTimeSpan& other );
00272
00273 inline void setStart( const QDateTime& start ) { m_start=start; }
00274 inline QDateTime start() const { return m_start; }
00275
00276 inline void setEnd( const QDateTime& end ) { m_end=end; }
00277 inline QDateTime end() const { return m_end; }
00278
00279 bool isValid() const;
00280
00281 bool equals( const DateTimeSpan& other ) const;
00282 };
00283
00284 inline bool operator==( const DateTimeSpan& s1, const DateTimeSpan& s2) { return s1.equals( s2 ); }
00285 inline bool operator!=( const DateTimeSpan& s1, const DateTimeSpan& s2) { return !s1.equals( s2 ); }
00286 }
00287
00288 Q_DECLARE_METATYPE(KDGantt::ItemType)
00289 Q_DECLARE_TYPEINFO(KDGantt::Span, Q_MOVABLE_TYPE);
00290 Q_DECLARE_TYPEINFO(KDGantt::DateTimeSpan, Q_MOVABLE_TYPE);
00291
00292 #ifndef QT_NO_DEBUG_STREAM
00293
00294 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::ItemDataRole r);
00295 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::ItemType t);
00296 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, const KDGantt::Span& s );
00297 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s );
00298
00299 #endif
00300
00301 #endif