KD Chart API Documentation  3.1
kdganttglobal.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Chart library.
4 **
5 ** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
11 #include "kdganttglobal.h"
12 
13 using namespace KDGantt;
14 
61 {
62 }
63 
64 DateTimeSpan::DateTimeSpan(const QDateTime &start, const QDateTime &end)
65  : m_start(start)
66  , m_end(end)
67 {
68 }
69 
71 {
72  *this = other;
73 }
74 
76 {
77 }
78 
80 {
81  if (this != &other) {
82  m_start = other.m_start;
83  m_end = other.m_end;
84  }
85  return *this;
86 }
87 
89 {
90  return m_start.isValid() && m_end.isValid();
91 }
92 
93 bool DateTimeSpan::equals(const DateTimeSpan &other) const
94 {
95  return m_start == other.m_start && m_end == other.m_end;
96 }
97 
98 #ifndef QT_NO_DEBUG_STREAM
99 
100 QDebug operator<<(QDebug dbg, KDGantt::ItemDataRole r)
101 {
102  switch (r) {
104  dbg << "KDGantt::StartTimeRole";
105  break;
107  dbg << "KDGantt::EndTimeRole";
108  break;
110  dbg << "KDGantt::TaskCompletionRole";
111  break;
113  dbg << "KDGantt::ItemTypeRole";
114  break;
115  case KDGantt::LegendRole:
116  dbg << "KDGantt::LegendRole";
117  break;
118  default:
119  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:
128  dbg << "KDGantt::TypeNone";
129  break;
130  case KDGantt::TypeEvent:
131  dbg << "KDGantt::TypeEvent";
132  break;
133  case KDGantt::TypeTask:
134  dbg << "KDGantt::TypeTask";
135  break;
137  dbg << "KDGantt::TypeSummary";
138  break;
139  case KDGantt::TypeMulti:
140  dbg << "KDGantt::TypeMulti";
141  break;
142  case KDGantt::TypeUser:
143  dbg << "KDGantt::TypeUser";
144  break;
145  default:
146  dbg << static_cast<int>(t);
147  }
148  return dbg;
149 }
150 
151 QDebug operator<<(QDebug dbg, const KDGantt::Span &s)
152 {
153  dbg << "KDGantt::Span[ start=" << s.start() << " length=" << s.length() << "]";
154  return dbg;
155 }
156 QDebug operator<<(QDebug dbg, const KDGantt::DateTimeSpan &s)
157 {
158  dbg << "KDGantt::DateTimeSpan[ start=" << s.start() << " end=" << s.end() << "]";
159  return dbg;
160 }
161 
162 #endif /* QT_NO_DEBUG_STREAM */
163 
164 #ifndef KDAB_NO_UNIT_TESTS
165 
166 #include <ostream>
167 
168 static std::ostream &operator<<(std::ostream &os, const Span &span)
169 {
170  os << "Span[ start=" << span.start() << ", length=" << span.length() << "]";
171  return os;
172 }
173 
174 static std::ostream &operator<<(std::ostream &os, const DateTimeSpan &span)
175 {
176 #ifdef QT_NO_STL
177  os << "DateTimeSpan[ start=" << span.start().toString().toLatin1().constData()
178  << ", end=" << span.end().toString().toLatin1().constData() << "]";
179 #else
180  os << "DateTimeSpan[ start=" << span.start().toString().toStdString()
181  << ", end=" << span.end().toString().toStdString() << "]";
182 #endif
183  return os;
184 }
185 
186 #include "unittest/test.h"
187 
189 {
190  Span s1;
191  assertFalse(s1.isValid());
192  s1.setStart(10.);
193  s1.setLength(2.);
194 
195  Span s2(s1.start(), s1.length());
196  assertEqual(s1, s2);
197 }
198 
200 {
201  DateTimeSpan s1;
202  assertFalse(s1.isValid());
203  QDateTime dt = QDateTime::currentDateTime();
204  s1.setStart(dt);
205  assertTrue(dt.isValid());
206  s1.setEnd(dt.addDays(1));
207 
208  DateTimeSpan s2(dt, dt.addDays(1));
209 
210  assertEqual(s1, s2);
211 
212  DateTimeSpan s3;
213 
214  assertNotEqual(s1, s3);
215 }
216 #endif /* KDAB_NO_UNIT_TESTS */
QDateTime end() const
QDateTime start() const
bool equals(const DateTimeSpan &other) const
void setStart(const QDateTime &start)
DateTimeSpan & operator=(const DateTimeSpan &other)
void setEnd(const QDateTime &end)
A class representing a start point and a length.
qreal length() const
void setStart(qreal start)
bool isValid() const
qreal start() const
void setLength(qreal length)
KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, Span, "test")
QDebug operator<<(QDebug dbg, KDGantt::ItemDataRole r)
Contains KDGantt macros.
ItemDataRole
The values of this enum are used for the special data roles for gantt items.
@ TaskCompletionRole
ItemType
The values of this enum are used to represent the different types of gantt items that KDGantt underst...

© 2001 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/
Generated by doxygen 1.9.1