KD Chart 2  [rev.2.8]
kdganttglobal.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2021 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include "kdganttglobal.h"
24 
25 using namespace KDGantt;
26 
73 {
74 }
75 
76 DateTimeSpan::DateTimeSpan( const QDateTime& start, const QDateTime& end )
77  : m_start( start ), m_end( end )
78 {
79 }
80 
82 {
83  *this = other;
84 }
85 
87 {
88 }
89 
91 {
92  if ( this != &other ) {
93  m_start = other.m_start;
94  m_end = other.m_end;
95  }
96  return *this;
97 }
98 
100 {
101  return m_start.isValid() && m_end.isValid();
102 }
103 
104 bool DateTimeSpan::equals( const DateTimeSpan& other ) const
105 {
106  return m_start==other.m_start && m_end==other.m_end;
107 }
108 
109 #ifndef QT_NO_DEBUG_STREAM
110 
111 QDebug operator<<( QDebug dbg, KDGantt::ItemDataRole r)
112 {
113  switch (r) {
114  case KDGantt::StartTimeRole: dbg << "KDGantt::StartTimeRole"; break;
115  case KDGantt::EndTimeRole: dbg << "KDGantt::EndTimeRole"; break;
116  case KDGantt::TaskCompletionRole: dbg << "KDGantt::TaskCompletionRole"; break;
117  case KDGantt::ItemTypeRole: dbg << "KDGantt::ItemTypeRole"; break;
118  case KDGantt::LegendRole: dbg << "KDGantt::LegendRole"; break;
119  default: dbg << static_cast<Qt::ItemDataRole>(r);
120  }
121  return dbg;
122 }
123 
124 QDebug operator<<( QDebug dbg, KDGantt::ItemType t)
125 {
126  switch ( t ) {
127  case KDGantt::TypeNone: dbg << "KDGantt::TypeNone"; break;
128  case KDGantt::TypeEvent: dbg << "KDGantt::TypeEvent"; break;
129  case KDGantt::TypeTask: dbg << "KDGantt::TypeTask"; break;
130  case KDGantt::TypeSummary: dbg << "KDGantt::TypeSummary"; break;
131  case KDGantt::TypeMulti: dbg << "KDGantt::TypeMulti"; break;
132  case KDGantt::TypeUser: dbg << "KDGantt::TypeUser"; break;
133  default: dbg << static_cast<int>(t);
134  }
135  return dbg;
136 }
137 
138 QDebug operator<<( QDebug dbg, const KDGantt::Span& s )
139 {
140  dbg << "KDGantt::Span[ start="<<s.start()<<" length="<<s.length()<<"]";
141  return dbg;
142 }
143 QDebug operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s )
144 {
145  dbg << "KDGantt::DateTimeSpan[ start="<<s.start()<<" end="<<s.end()<<"]";
146  return dbg;
147 }
148 
149 #endif /* QT_NO_DEBUG_STREAM */
150 
151 #ifndef KDAB_NO_UNIT_TESTS
152 
153 #include <ostream>
154 
155 static std::ostream& operator<<( std::ostream& os, const Span& span )
156 {
157  os << "Span[ start="<<span.start()<<", length="<<span.length()<<"]";
158  return os;
159 }
160 
161 static std::ostream& operator<<( std::ostream& os, const DateTimeSpan& span )
162 {
163 #ifdef QT_NO_STL
164  os << "DateTimeSpan[ start="<<span.start().toString().toLatin1().constData()
165  << ", end="<<span.end().toString().toLatin1().constData() << "]";
166 #else
167  os << "DateTimeSpan[ start="<<span.start().toString().toStdString()
168  << ", end="<<span.end().toString().toStdString() << "]";
169 #endif
170  return os;
171 }
172 
173 #include "unittest/test.h"
174 
176  Span s1;
177  assertFalse( s1.isValid() );
178  s1.setStart( 10. );
179  s1.setLength( 2. );
180 
181  Span s2( s1.start(), s1.length() );
182  assertEqual( s1, s2 );
183 }
184 
186  DateTimeSpan s1;
187  assertFalse( s1.isValid() );
188  QDateTime dt = QDateTime::currentDateTime();
189  s1.setStart( dt );
190  assertTrue( dt.isValid() );
191  s1.setEnd( dt.addDays( 1 ) );
192 
193  DateTimeSpan s2( dt, dt.addDays( 1 ) );
194 
195  assertEqual( s1, s2 );
196 
197  DateTimeSpan s3;
198 
199  assertNotEqual( s1, s3 );
200 }
201 #endif /* KDAB_NO_UNIT_TESTS */
KDGantt::ItemDataRole
ItemDataRole
Definition: kdganttglobal.h:216
KDGantt::Span::start
qreal start() const
Definition: kdganttglobal.h:245
KDGantt::TypeSummary
@ TypeSummary
Definition: kdganttglobal.h:229
operator<<
QDebug operator<<(QDebug dbg, KDGantt::ItemDataRole r)
Definition: kdganttglobal.cpp:111
KDGantt::Span::setStart
void setStart(qreal start)
Definition: kdganttglobal.h:244
assertFalse
#define assertFalse(x)
Definition: test.h:42
KDGantt::DateTimeSpan::DateTimeSpan
DateTimeSpan()
Definition: kdganttglobal.cpp:72
KDGantt::Span::isValid
bool isValid() const
Definition: kdganttglobal.h:252
assertEqual
#define assertEqual(x, y)
Definition: test.h:43
KDGantt::LegendRole
@ LegendRole
Definition: kdganttglobal.h:222
KDGantt::DateTimeSpan::operator=
DateTimeSpan & operator=(const DateTimeSpan &other)
Definition: kdganttglobal.cpp:90
kdganttglobal.h
assertNotEqual
#define assertNotEqual(x, y)
Definition: test.h:44
KDGantt::DateTimeSpan
Definition: kdganttglobal.h:267
KDGantt::TypeUser
@ TypeUser
Definition: kdganttglobal.h:231
KDGantt
Definition: kdganttabstractrowcontroller.h:33
KDGantt::DateTimeSpan::~DateTimeSpan
~DateTimeSpan()
Definition: kdganttglobal.cpp:86
KDAB_SCOPED_UNITTEST_SIMPLE
KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, Span, "test")
Definition: kdganttglobal.cpp:175
KDGantt::Span::length
qreal length() const
Definition: kdganttglobal.h:250
KDGantt::TypeMulti
@ TypeMulti
Definition: kdganttglobal.h:230
KDGantt::ItemTypeRole
@ ItemTypeRole
Definition: kdganttglobal.h:221
KDGantt::Span
A class representing a start point and a length.
Definition: kdganttglobal.h:234
test.h
KDGantt::DateTimeSpan::equals
bool equals(const DateTimeSpan &other) const
Definition: kdganttglobal.cpp:104
KDGantt::TypeEvent
@ TypeEvent
Definition: kdganttglobal.h:227
KDGantt::DateTimeSpan::setEnd
void setEnd(const QDateTime &end)
Definition: kdganttglobal.h:281
KDGantt::DateTimeSpan::isValid
bool isValid() const
Definition: kdganttglobal.cpp:99
KDGantt::EndTimeRole
@ EndTimeRole
Definition: kdganttglobal.h:219
KDGantt::TypeNone
@ TypeNone
Definition: kdganttglobal.h:226
assertTrue
#define assertTrue(x)
Definition: test.h:41
KDGantt::TaskCompletionRole
@ TaskCompletionRole
Definition: kdganttglobal.h:220
KDGantt::TypeTask
@ TypeTask
Definition: kdganttglobal.h:228
KDGantt::ItemType
ItemType
Definition: kdganttglobal.h:225
KDGantt::DateTimeSpan::start
QDateTime start() const
Definition: kdganttglobal.h:279
KDGantt::DateTimeSpan::end
QDateTime end() const
Definition: kdganttglobal.h:282
KDGantt::StartTimeRole
@ StartTimeRole
Definition: kdganttglobal.h:218
KDGantt::DateTimeSpan::setStart
void setStart(const QDateTime &start)
Definition: kdganttglobal.h:278
KDGantt::Span::setLength
void setLength(qreal length)
Definition: kdganttglobal.h:249

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/