kdganttglobal.h

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

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