kdganttglobal.cpp

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 #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   case Qt::DisplayRole:             dbg << "Qt::DisplayRole"; break;
00130   case Qt::DecorationRole:          dbg << "Qt::DecorationRole"; 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 */
 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/