kdgantt
kdganttglobal.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "kdganttglobal.h"
00024
00025 using namespace KDGantt;
00026
00066 Span::~Span()
00067 {
00068 }
00069
00070 DateTimeSpan::DateTimeSpan()
00071 {
00072 }
00073
00074 DateTimeSpan::DateTimeSpan( const QDateTime& start, const QDateTime& end )
00075 : m_start( start ), m_end( end )
00076 {
00077 }
00078
00079 DateTimeSpan::DateTimeSpan( const DateTimeSpan& other )
00080 {
00081 *this = other;
00082 }
00083
00084 DateTimeSpan::~DateTimeSpan()
00085 {
00086 }
00087
00088 DateTimeSpan& DateTimeSpan::operator=( const DateTimeSpan& other )
00089 {
00090 if ( this != &other ) {
00091 m_start = other.m_start;
00092 m_end = other.m_end;
00093 }
00094 return *this;
00095 }
00096
00097 bool DateTimeSpan::isValid() const
00098 {
00099 return m_start.isValid() && m_end.isValid();
00100 }
00101
00102 bool DateTimeSpan::equals( const DateTimeSpan& other ) const
00103 {
00104 return m_start==other.m_start && m_end==other.m_end;
00105 }
00106
00107 #ifndef QT_NO_DEBUG_STREAM
00108
00109 QDebug operator<<( QDebug dbg, KDGantt::ItemDataRole r)
00110 {
00111 switch(r){
00112 case KDGantt::StartTimeRole: dbg << "KDGantt::StartTimeRole"; break;
00113 case KDGantt::EndTimeRole: dbg << "KDGantt::EndTimeRole"; break;
00114 case KDGantt::TaskCompletionRole: dbg << "KDGantt::TaskCompletionRole"; break;
00115 case KDGantt::ItemTypeRole: dbg << "KDGantt::ItemTypeRole"; break;
00116 case KDGantt::LegendRole: dbg << "KDGantt::LegendRole"; break;
00117 default: dbg << static_cast<Qt::ItemDataRole>(r);
00118 }
00119 return dbg;
00120 }
00121
00122 QDebug operator<<( QDebug dbg, const KDGantt::Span& s )
00123 {
00124 dbg << "KDGantt::Span[ start="<<s.start()<<" length="<<s.length()<<"]";
00125 return dbg;
00126 }
00127 QDebug operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s )
00128 {
00129 dbg << "KDGantt::DateTimeSpan[ start="<<s.start()<<" end="<<s.end()<<"]";
00130 return dbg;
00131 }
00132
00133 #endif
00134
00135 #ifndef KDAB_NO_UNIT_TESTS
00136 #include "unittest/test.h"
00137
00138 namespace {
00139 std::ostream& operator<<( std::ostream& os, const Span& span )
00140 {
00141 os << "Span[ start="<<span.start()<<", length="<<span.length()<<"]";
00142 return os;
00143 }
00144 std::ostream& operator<<( std::ostream& os, const DateTimeSpan& span )
00145 {
00146 os << "DateTimeSpan[ start="<<span.start().toString().toStdString()
00147 << ", end="<<span.end().toString().toStdString() << "]";
00148 return os;
00149 }
00150 }
00151
00152 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, Span, "test" ) {
00153 Span s1;
00154 assertFalse( s1.isValid() );
00155 s1.setStart( 10. );
00156 s1.setLength( 2. );
00157
00158 Span s2( s1.start(), s1.length() );
00159 assertEqual( s1, s2 );
00160 }
00161
00162 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, DateTimeSpan, "test" ) {
00163 DateTimeSpan s1;
00164 assertFalse( s1.isValid() );
00165 QDateTime dt = QDateTime::currentDateTime();
00166 s1.setStart( dt );
00167 assertTrue( dt.isValid() );
00168 s1.setEnd( dt.addDays( 1 ) );
00169
00170 DateTimeSpan s2( dt, dt.addDays( 1 ) );
00171
00172 assertEqual( s1, s2 );
00173
00174 DateTimeSpan s3;
00175
00176 assertNotEqual( s1, s3 );
00177 }
00178 #endif