kdganttglobal.h

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

Generated on Thu Mar 4 23:19:13 2010 for KD Chart 2 by  doxygen 1.5.4