File indexing completed on 2024-05-12 15:54:24
0001 /* 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "kganttglobal.h" 0021 0022 using namespace KGantt; 0023 0024 0025 DateTimeSpan::DateTimeSpan() 0026 { 0027 } 0028 0029 DateTimeSpan::DateTimeSpan( const QDateTime& start, const QDateTime& end ) 0030 : m_start( start ), m_end( end ) 0031 { 0032 } 0033 0034 DateTimeSpan::DateTimeSpan( const DateTimeSpan& other ) 0035 { 0036 *this = other; 0037 } 0038 0039 DateTimeSpan::~DateTimeSpan() 0040 { 0041 } 0042 0043 DateTimeSpan& DateTimeSpan::operator=( const DateTimeSpan& other ) 0044 { 0045 if ( this != &other ) { 0046 m_start = other.m_start; 0047 m_end = other.m_end; 0048 } 0049 return *this; 0050 } 0051 0052 bool DateTimeSpan::isValid() const 0053 { 0054 return m_start.isValid() && m_end.isValid(); 0055 } 0056 0057 bool DateTimeSpan::equals( const DateTimeSpan& other ) const 0058 { 0059 return m_start==other.m_start && m_end==other.m_end; 0060 } 0061 0062 #ifndef QT_NO_DEBUG_STREAM 0063 0064 QDebug operator<<( QDebug dbg, KGantt::ItemDataRole r) 0065 { 0066 switch (r) { 0067 case KGantt::StartTimeRole: dbg << "KGantt::StartTimeRole"; break; 0068 case KGantt::EndTimeRole: dbg << "KGantt::EndTimeRole"; break; 0069 case KGantt::TaskCompletionRole: dbg << "KGantt::TaskCompletionRole"; break; 0070 case KGantt::ItemTypeRole: dbg << "KGantt::ItemTypeRole"; break; 0071 case KGantt::LegendRole: dbg << "KGantt::LegendRole"; break; 0072 default: dbg << static_cast<Qt::ItemDataRole>(r); 0073 } 0074 return dbg; 0075 } 0076 0077 QDebug operator<<( QDebug dbg, KGantt::ItemType t) 0078 { 0079 switch ( t ) { 0080 case KGantt::TypeNone: dbg << "KGantt::TypeNone"; break; 0081 case KGantt::TypeEvent: dbg << "KGantt::TypeEvent"; break; 0082 case KGantt::TypeTask: dbg << "KGantt::TypeTask"; break; 0083 case KGantt::TypeSummary: dbg << "KGantt::TypeSummary"; break; 0084 case KGantt::TypeMulti: dbg << "KGantt::TypeMulti"; break; 0085 case KGantt::TypeUser: dbg << "KGantt::TypeUser"; break; 0086 default: dbg << static_cast<int>(t); 0087 } 0088 return dbg; 0089 } 0090 0091 QDebug operator<<( QDebug dbg, const KGantt::Span& s ) 0092 { 0093 dbg << "KGantt::Span[ start="<<s.start()<<" length="<<s.length()<<"]"; 0094 return dbg; 0095 } 0096 QDebug operator<<( QDebug dbg, const KGantt::DateTimeSpan& s ) 0097 { 0098 dbg << "KGantt::DateTimeSpan[ start="<<s.start()<<" end="<<s.end()<<"]"; 0099 return dbg; 0100 } 0101 0102 #endif /* QT_NO_DEBUG_STREAM */ 0103 0104 #ifndef KDAB_NO_UNIT_TESTS 0105 0106 #include <ostream> 0107 0108 static std::ostream& operator<<( std::ostream& os, const Span& span ) 0109 { 0110 os << "Span[ start="<<span.start()<<", length="<<span.length()<<"]"; 0111 return os; 0112 } 0113 0114 static std::ostream& operator<<( std::ostream& os, const DateTimeSpan& span ) 0115 { 0116 #ifdef QT_NO_STL 0117 os << "DateTimeSpan[ start="<<span.start().toString().toLatin1().constData() 0118 << ", end="<<span.end().toString().toLatin1().constData() << "]"; 0119 #else 0120 os << "DateTimeSpan[ start="<<span.start().toString().toStdString() 0121 << ", end="<<span.end().toString().toStdString() << "]"; 0122 #endif 0123 return os; 0124 } 0125 0126 #include "unittest/test.h" 0127 0128 KDAB_SCOPED_UNITTEST_SIMPLE( KGantt, Span, "test" ) { 0129 Span s1; 0130 assertFalse( s1.isValid() ); 0131 s1.setStart( 10. ); 0132 s1.setLength( 2. ); 0133 0134 Span s2( s1.start(), s1.length() ); 0135 assertEqual( s1, s2 ); 0136 } 0137 0138 KDAB_SCOPED_UNITTEST_SIMPLE( KGantt, DateTimeSpan, "test" ) { 0139 DateTimeSpan s1; 0140 assertFalse( s1.isValid() ); 0141 QDateTime dt = QDateTime::currentDateTime(); 0142 s1.setStart( dt ); 0143 assertTrue( dt.isValid() ); 0144 s1.setEnd( dt.addDays( 1 ) ); 0145 0146 DateTimeSpan s2( dt, dt.addDays( 1 ) ); 0147 0148 assertEqual( s1, s2 ); 0149 0150 DateTimeSpan s3; 0151 0152 assertNotEqual( s1, s3 ); 0153 } 0154 #endif /* KDAB_NO_UNIT_TESTS */