KD Chart 2
[rev.2.5]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00027 #ifndef KDGANTTGLOBAL_H 00028 #define KDGANTTGLOBAL_H 00029 00030 #include <Qt> 00031 #include <QDateTime> 00032 #include <QDebug> 00033 #include <QMetaType> 00034 00035 #include "kdchart_export.h" 00036 00037 #if (defined(__MINGW32__) || defined(__MINGW64__)) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 0) 00038 // workaround a mingw bug, http://sourceforge.net/tracker/index.php?func=detail&aid=2373234&group_id=2435&atid=102435 00039 int swprintf (wchar_t *, size_t, const wchar_t *, ...); 00040 int vswprintf(wchar_t *, const wchar_t *, va_list); 00041 #endif 00042 00043 #ifndef KDAB_SET_OBJECT_NAME 00044 template <typename T> 00045 inline T & __kdab__dereference_for_methodcall( T & o ) { 00046 return o; 00047 } 00048 00049 template <typename T> 00050 inline T & __kdab__dereference_for_methodcall( T * o ) { 00051 return *o; 00052 } 00053 00054 #define KDAB_SET_OBJECT_NAME( x ) __kdab__dereference_for_methodcall( x ).setObjectName( QLatin1String( #x ) ) 00055 #endif 00056 00057 #if defined(_MSC_VER) && _MSC_VER <= 1300 00058 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \ 00059 public: \ 00060 class Private; \ 00061 friend class Private; \ 00062 protected: \ 00063 inline Private * d_func(); \ 00064 inline const Private * d_func() const; \ 00065 explicit inline X( Private * ); \ 00066 private: \ 00067 void init(); 00068 #else 00069 #define KDGANTT_DECLARE_PRIVATE_DERIVED( X ) \ 00070 protected: \ 00071 class Private; \ 00072 friend class Private; \ 00073 inline Private * d_func(); \ 00074 inline const Private * d_func() const; \ 00075 explicit inline X( Private * ); \ 00076 private: \ 00077 void init(); 00078 #endif 00079 00080 #if defined(_MSC_VER) && _MSC_VER <= 1300 00081 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \ 00082 public: \ 00083 class Private; \ 00084 friend class Private; \ 00085 protected: \ 00086 inline Private * d_func(); \ 00087 inline const Private * d_func() const; \ 00088 explicit inline X( Private *, ParentType ); \ 00089 private: \ 00090 void init(); 00091 #else 00092 #define KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \ 00093 protected: \ 00094 class Private; \ 00095 friend class Private; \ 00096 inline Private * d_func(); \ 00097 inline const Private * d_func() const; \ 00098 explicit inline X( Private *, ParentType ); \ 00099 private: \ 00100 void init(); 00101 #endif 00102 00103 #define KDGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET( X ) \ 00104 KDGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, QWidget* ) 00105 00106 #define KDGANTT_DECLARE_PRIVATE_BASE_VALUE( X ) \ 00107 public: \ 00108 inline void swap( X & other ) { qSwap( _d, other._d ); } \ 00109 protected: \ 00110 class Private; \ 00111 friend class Private; \ 00112 Private * d_func() { return _d; } \ 00113 const Private * d_func() const { return _d; } \ 00114 private: \ 00115 void init(); \ 00116 Private * _d; 00117 00118 #if defined(_MSC_VER) && _MSC_VER <= 1300 00119 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \ 00120 public: \ 00121 class Private; \ 00122 friend class Private; \ 00123 protected: \ 00124 Private * d_func() { return _d; } \ 00125 const Private * d_func() const { return _d; } \ 00126 explicit inline X( Private * ); \ 00127 private: \ 00128 void init(); \ 00129 Private * _d; 00130 #else 00131 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \ 00132 protected: \ 00133 class Private; \ 00134 friend class Private; \ 00135 Private * d_func() { return _d; } \ 00136 const Private * d_func() const { return _d; } \ 00137 explicit inline X( Private * ); \ 00138 private: \ 00139 void init(); \ 00140 Private * _d; 00141 #endif 00142 00143 #if defined(_MSC_VER) && _MSC_VER <= 1300 00144 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \ 00145 public: \ 00146 class Private; \ 00147 friend class Private; \ 00148 protected: \ 00149 Private * d_func() { return _d; } \ 00150 const Private * d_func() const { return _d; } \ 00151 explicit inline X( Private *, QWidget* ); \ 00152 private: \ 00153 void init(); \ 00154 Private * _d; 00155 #else 00156 #define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \ 00157 protected: \ 00158 class Private; \ 00159 friend class Private; \ 00160 Private * d_func() { return _d; } \ 00161 const Private * d_func() const { return _d; } \ 00162 explicit inline X( Private *, QWidget* ); \ 00163 private: \ 00164 void init(); \ 00165 Private * _d; 00166 #endif 00167 00168 00169 00170 // enable this for testing if KD Gantt works without STL support in Qt: 00171 // 00172 // #define QT_NO_STL 00173 00174 00175 #include <QtAlgorithms> // qSwap 00176 #ifndef QT_NO_STL 00177 #include <algorithm> 00178 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \ 00179 QT_BEGIN_NAMESPACE \ 00180 template <> inline void qSwap<X>( X & lhs, X & rhs ) \ 00181 { lhs.swap( rhs ); } \ 00182 QT_END_NAMESPACE \ 00183 namespace std { \ 00184 template <> inline void swap<X>( X & lhs, X & rhs ) \ 00185 { lhs.swap( rhs ); } \ 00186 } 00187 #else 00188 #define KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) \ 00189 QT_BEGIN_NAMESPACE \ 00190 template <> inline void qSwap<X>( X & lhs, X & rhs ) \ 00191 { lhs.swap( rhs ); } \ 00192 QT_END_NAMESPACE 00193 #endif 00194 00195 #define KDGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED( X ) \ 00196 KDGANTT_DECLARE_SWAP_SPECIALISATION( X ) 00197 00198 #define KDGANTT_DECLARE_SWAP_BASE( X ) \ 00199 protected: \ 00200 void doSwap( X& other ) \ 00201 { qSwap( _d, other._d); } 00202 00203 #define KDGANTT_DECLARE_SWAP_DERIVED( X ) \ 00204 void swap( X& other ) { doSwap( other ); } 00205 00206 #if defined(Q_OS_WIN) && defined(QT_DLL) 00207 #if defined(_MSC_VER) && _MSC_VER >= 1300 00208 // workaround http://support.microsoft.com/default.aspx?scid=kb;en-us;309801 00209 #include <QPointF> 00210 #include <QVector> 00211 template class Q_DECL_IMPORT QVector<QPointF>; 00212 #endif 00213 #endif 00214 00215 namespace KDGantt { 00216 enum ItemDataRole { 00217 KDGanttRoleBase = Qt::UserRole + 1174, 00218 StartTimeRole = KDGanttRoleBase + 1, 00219 EndTimeRole = KDGanttRoleBase + 2, 00220 TaskCompletionRole = KDGanttRoleBase + 3, 00221 ItemTypeRole = KDGanttRoleBase + 4, 00222 LegendRole = KDGanttRoleBase + 5, 00223 TextPositionRole = KDGanttRoleBase + 6 00224 }; 00225 enum ItemType { 00226 TypeNone = 0, 00227 TypeEvent = 1, 00228 TypeTask = 2, 00229 TypeSummary = 3, 00230 TypeMulti = 4, 00231 TypeUser = 1000 00232 }; 00233 00234 class Span { 00235 qreal m_start; 00236 qreal m_length; 00237 public: 00238 inline Span() : m_start( -1 ), m_length( 0 ) {} 00239 inline Span( qreal start, qreal length ) : m_start( start ), m_length( length ) {} 00240 inline Span( const Span& other ) : m_start(other.m_start), m_length(other.m_length) {} 00241 00242 inline Span& operator=( const Span& other ) { m_start=other.m_start; m_length=other.m_length; return *this; } 00243 00244 inline void setStart( qreal start ) { m_start=start; } 00245 inline qreal start() const { return m_start; } 00246 inline void setEnd( qreal end ) { m_length = m_start-end; } 00247 inline qreal end() const { return m_start+m_length; } 00248 00249 inline void setLength( qreal length ) { m_length=length; } 00250 inline qreal length() const { return m_length; } 00251 00252 inline bool isValid() const { return m_start >= 0.;} 00253 00254 inline bool equals( const Span& other ) const { 00255 return m_start == other.m_start && m_length == other.m_length; 00256 } 00257 inline Span expandedTo( const Span& other) const { 00258 const qreal new_start = qMin(start(),other.start()); 00259 return Span( new_start, (end()<other.end())?other.end()-new_start:end()-new_start); 00260 } 00261 }; 00262 00263 inline bool operator==( const Span& s1, const Span& s2) { return s1.equals( s2 ); } 00264 inline bool operator!=( const Span& s1, const Span& s2) { return !s1.equals( s2 ); } 00265 00266 00267 class DateTimeSpan { 00268 QDateTime m_start; 00269 QDateTime m_end; 00270 public: 00271 DateTimeSpan(); 00272 DateTimeSpan( const QDateTime& start, const QDateTime& end ); 00273 DateTimeSpan( const DateTimeSpan& other ); 00274 ~DateTimeSpan(); 00275 00276 DateTimeSpan& operator=( const DateTimeSpan& other ); 00277 00278 inline void setStart( const QDateTime& start ) { m_start=start; } 00279 inline QDateTime start() const { return m_start; } 00280 00281 inline void setEnd( const QDateTime& end ) { m_end=end; } 00282 inline QDateTime end() const { return m_end; } 00283 00284 bool isValid() const; 00285 00286 bool equals( const DateTimeSpan& other ) const; 00287 }; 00288 00289 inline bool operator==( const DateTimeSpan& s1, const DateTimeSpan& s2) { return s1.equals( s2 ); } 00290 inline bool operator!=( const DateTimeSpan& s1, const DateTimeSpan& s2) { return !s1.equals( s2 ); } 00291 } 00292 00293 Q_DECLARE_METATYPE(KDGantt::ItemType) 00294 00295 #ifndef QT_NO_DEBUG_STREAM 00296 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::ItemDataRole r); 00297 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::ItemType t); 00298 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, const KDGantt::Span& s ); 00299 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s ); 00300 #endif /* QT_NO_DEBUG_STREAM */ 00301 00302 QT_BEGIN_NAMESPACE 00303 Q_DECLARE_TYPEINFO(KDGantt::Span, Q_MOVABLE_TYPE); 00304 Q_DECLARE_TYPEINFO(KDGantt::DateTimeSpan, Q_MOVABLE_TYPE); 00305 QT_END_NAMESPACE 00306 00307 #endif /* KDGANTTGLOBAL_H */