kdganttglobal.cpp

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 #include "kdganttglobal.h"
00026 
00027 using namespace KDGantt;
00028 
00029 /* Older Qt dont have this macro, so define it... */
00030 #ifndef QT_VERSION_CHECK
00031 #  define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
00032 #endif
00033 
00034 /* Version check */
00035 #if QT_VERSION < QT_VERSION_CHECK(4,3,0)
00036 #  error "The minimum required version of Qt for KD Gantt is 4.3.0"
00037 #endif
00038 
00084 DateTimeSpan::DateTimeSpan()
00085 {
00086 }
00087 
00088 DateTimeSpan::DateTimeSpan( const QDateTime& start, const QDateTime& end )
00089     : m_start( start ), m_end( end )
00090 {
00091 }
00092 
00093 DateTimeSpan::DateTimeSpan( const DateTimeSpan& other )
00094 {
00095     *this = other;
00096 }
00097 
00098 DateTimeSpan::~DateTimeSpan()
00099 {
00100 }
00101 
00102 DateTimeSpan& DateTimeSpan::operator=( const DateTimeSpan& other )
00103 {
00104     if ( this != &other ) {
00105         m_start = other.m_start;
00106         m_end = other.m_end;
00107     }
00108     return *this;
00109 }
00110 
00111 bool DateTimeSpan::isValid() const
00112 {
00113     return m_start.isValid() && m_end.isValid();
00114 }
00115 
00116 bool DateTimeSpan::equals( const DateTimeSpan& other ) const
00117 {
00118     return m_start==other.m_start && m_end==other.m_end;
00119 }
00120 
00121 #ifndef QT_NO_DEBUG_STREAM
00122 
00123 QDebug operator<<( QDebug dbg, KDGantt::ItemDataRole r)
00124 {
00125   switch(r){
00126   case KDGantt::StartTimeRole:      dbg << "KDGantt::StartTimeRole"; break;
00127   case KDGantt::EndTimeRole:        dbg << "KDGantt::EndTimeRole"; break;
00128   case KDGantt::TaskCompletionRole: dbg << "KDGantt::TaskCompletionRole"; break;
00129   case KDGantt::ItemTypeRole:       dbg << "KDGantt::ItemTypeRole"; break;
00130   case KDGantt::LegendRole:         dbg << "KDGantt::LegendRole"; break;
00131   default: dbg << static_cast<Qt::ItemDataRole>(r);
00132   }
00133   return dbg;
00134 }
00135 
00136 QDebug operator<<( QDebug dbg, KDGantt::ItemType t)
00137 {
00138     switch( t ) {
00139     case KDGantt::TypeNone:        dbg << "KDGantt::TypeNone"; break;
00140     case KDGantt::TypeEvent:       dbg << "KDGantt::TypeEvent"; break;
00141     case KDGantt::TypeTask:       dbg << "KDGantt::TypeTask"; break;
00142     case KDGantt::TypeSummary:     dbg << "KDGantt::TypeSummary"; break;
00143     case KDGantt::TypeMulti:       dbg << "KDGantt::TypeMulti"; break;
00144     case KDGantt::TypeUser:        dbg << "KDGantt::TypeUser"; break;
00145     default: dbg << static_cast<int>(t);
00146     }
00147     return dbg;
00148 }
00149 
00150 QDebug operator<<( QDebug dbg, const KDGantt::Span& s )
00151 {
00152     dbg << "KDGantt::Span[ start="<<s.start()<<" length="<<s.length()<<"]";
00153     return dbg;
00154 }
00155 QDebug operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s )
00156 {
00157     dbg << "KDGantt::DateTimeSpan[ start="<<s.start()<<" end="<<s.end()<<"]";
00158     return dbg;
00159 }
00160 
00161 #endif /* QT_NO_DEBUG_STREAM */
00162 
00163 #ifndef KDAB_NO_UNIT_TESTS
00164 #include "unittest/test.h"
00165 
00166 namespace {
00167     std::ostream& operator<<( std::ostream& os, const Span& span )
00168     {
00169         os << "Span[ start="<<span.start()<<", length="<<span.length()<<"]";
00170         return os;
00171     }
00172     std::ostream& operator<<( std::ostream& os, const DateTimeSpan& span )
00173     {
00174 #ifdef QT_NO_STL
00175         os << "DateTimeSpan[ start="<<span.start().toString().toLatin1().constData()
00176            << ", end="<<span.end().toString().toLatin1().constData() << "]";
00177 #else
00178         os << "DateTimeSpan[ start="<<span.start().toString().toStdString()
00179            << ", end="<<span.end().toString().toStdString() << "]";
00180 #endif
00181         return os;
00182     }
00183 }
00184 
00185 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, Span, "test" ) {
00186     Span s1;
00187     assertFalse( s1.isValid() );
00188     s1.setStart( 10. );
00189     s1.setLength( 2. );
00190 
00191     Span s2( s1.start(), s1.length() );
00192     assertEqual( s1, s2 );
00193 }
00194 
00195 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, DateTimeSpan, "test" ) {
00196     DateTimeSpan s1;
00197     assertFalse( s1.isValid() );
00198     QDateTime dt = QDateTime::currentDateTime();
00199     s1.setStart( dt );
00200     assertTrue( dt.isValid() );
00201     s1.setEnd( dt.addDays( 1 ) );
00202 
00203     DateTimeSpan s2( dt, dt.addDays( 1 ) );
00204 
00205     assertEqual( s1, s2 );
00206 
00207     DateTimeSpan s3;
00208 
00209     assertNotEqual( s1, s3 );
00210 }
00211 #endif /* KDAB_NO_UNIT_TESTS */

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