KD Chart 2 [rev.2.4]

kdganttglobal.cpp

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