KGantt

kganttglobal.cpp
1 /*
2  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KGantt library.
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include "kganttglobal.h"
10 
11 using namespace KGantt;
12 
13 
14 DateTimeSpan::DateTimeSpan()
15 {
16 }
17 
18 DateTimeSpan::DateTimeSpan( const QDateTime& start, const QDateTime& end )
19  : m_start( start ), m_end( end )
20 {
21 }
22 
23 DateTimeSpan::DateTimeSpan( const DateTimeSpan& other )
24 {
25  *this = other;
26 }
27 
28 DateTimeSpan::~DateTimeSpan()
29 {
30 }
31 
32 DateTimeSpan& DateTimeSpan::operator=( const DateTimeSpan& other )
33 {
34  if ( this != &other ) {
35  m_start = other.m_start;
36  m_end = other.m_end;
37  }
38  return *this;
39 }
40 
41 bool DateTimeSpan::isValid() const
42 {
43  return m_start.isValid() && m_end.isValid();
44 }
45 
46 bool DateTimeSpan::equals( const DateTimeSpan& other ) const
47 {
48  return m_start==other.m_start && m_end==other.m_end;
49 }
50 
51 #ifndef QT_NO_DEBUG_STREAM
52 
54 {
55  switch (r) {
56  case KGantt::StartTimeRole: dbg << "KGantt::StartTimeRole"; break;
57  case KGantt::EndTimeRole: dbg << "KGantt::EndTimeRole"; break;
58  case KGantt::TaskCompletionRole: dbg << "KGantt::TaskCompletionRole"; break;
59  case KGantt::ItemTypeRole: dbg << "KGantt::ItemTypeRole"; break;
60  case KGantt::LegendRole: dbg << "KGantt::LegendRole"; break;
61  default: dbg << static_cast<Qt::ItemDataRole>(r);
62  }
63  return dbg;
64 }
65 
67 {
68  switch ( t ) {
69  case KGantt::TypeNone: dbg << "KGantt::TypeNone"; break;
70  case KGantt::TypeEvent: dbg << "KGantt::TypeEvent"; break;
71  case KGantt::TypeTask: dbg << "KGantt::TypeTask"; break;
72  case KGantt::TypeSummary: dbg << "KGantt::TypeSummary"; break;
73  case KGantt::TypeMulti: dbg << "KGantt::TypeMulti"; break;
74  case KGantt::TypeUser: dbg << "KGantt::TypeUser"; break;
75  default: dbg << static_cast<int>(t);
76  }
77  return dbg;
78 }
79 
80 QDebug operator<<( QDebug dbg, const KGantt::Span& s )
81 {
82  dbg << "KGantt::Span[ start="<<s.start()<<" length="<<s.length()<<"]";
83  return dbg;
84 }
85 QDebug operator<<( QDebug dbg, const KGantt::DateTimeSpan& s )
86 {
87  dbg << "KGantt::DateTimeSpan[ start="<<s.start()<<" end="<<s.end()<<"]";
88  return dbg;
89 }
90 
91 #endif /* QT_NO_DEBUG_STREAM */
92 
93 #ifndef KDAB_NO_UNIT_TESTS
94 
95 #include <ostream>
96 
97 static std::ostream& operator<<( std::ostream& os, const Span& span )
98 {
99  os << "Span[ start="<<span.start()<<", length="<<span.length()<<"]";
100  return os;
101 }
102 
103 static std::ostream& operator<<( std::ostream& os, const DateTimeSpan& span )
104 {
105 #ifdef QT_NO_STL
106  os << "DateTimeSpan[ start="<<span.start().toString().toLatin1().constData()
107  << ", end="<<span.end().toString().toLatin1().constData() << "]";
108 #else
109  os << "DateTimeSpan[ start="<<span.start().toString().toStdString()
110  << ", end="<<span.end().toString().toStdString() << "]";
111 #endif
112  return os;
113 }
114 
115 #include "unittest/test.h"
116 
117 KDAB_SCOPED_UNITTEST_SIMPLE( KGantt, Span, "test" ) {
118  Span s1;
119  assertFalse( s1.isValid() );
120  s1.setStart( 10. );
121  s1.setLength( 2. );
122 
123  Span s2( s1.start(), s1.length() );
124  assertEqual( s1, s2 );
125 }
126 
127 KDAB_SCOPED_UNITTEST_SIMPLE( KGantt, DateTimeSpan, "test" ) {
128  DateTimeSpan s1;
129  assertFalse( s1.isValid() );
131  s1.setStart( dt );
132  assertTrue( dt.isValid() );
133  s1.setEnd( dt.addDays( 1 ) );
134 
135  DateTimeSpan s2( dt, dt.addDays( 1 ) );
136 
137  assertEqual( s1, s2 );
138 
139  DateTimeSpan s3;
140 
141  assertNotEqual( s1, s3 );
142 }
143 #endif /* KDAB_NO_UNIT_TESTS */
The item type.
Definition: kganttglobal.h:217
The Legend text.
Definition: kganttglobal.h:218
Start time (or other start value) for a gantt item.
Definition: kganttglobal.h:214
End time (or other end value) for a gantt item.
Definition: kganttglobal.h:215
Global namespace.
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
QDateTime currentDateTime()
Contains KGantt macros.
A class representing a start point and a length.
Definition: kganttglobal.h:240
Task completion percentage used by Task items. Should be an integer og a qreal between 0 and 100...
Definition: kganttglobal.h:216
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 22:32:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.