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
11using namespace KGantt;
12
13
14DateTimeSpan::DateTimeSpan()
15{
16}
17
18DateTimeSpan::DateTimeSpan( const QDateTime& start, const QDateTime& end )
19 : m_start( start ), m_end( end )
20{
21}
22
23DateTimeSpan::DateTimeSpan( const DateTimeSpan& other )
24{
25 *this = other;
26}
27
28DateTimeSpan::~DateTimeSpan()
29{
30}
31
32DateTimeSpan& 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
41bool DateTimeSpan::isValid() const
42{
43 return m_start.isValid() && m_end.isValid();
44}
45
46bool 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
66QDebug operator<<( QDebug dbg, KGantt::ItemType t)
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
80QDebug operator<<( QDebug dbg, const KGantt::Span& s )
81{
82 dbg << "KGantt::Span[ start="<<s.start()<<" length="<<s.length()<<"]";
83 return dbg;
84}
85QDebug 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
97static std::ostream& operator<<( std::ostream& os, const Span& span )
98{
99 os << "Span[ start="<<span.start()<<", length="<<span.length()<<"]";
100 return os;
101}
102
103static 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
117KDAB_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
127KDAB_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 */
A class representing a start point and a length.
Q_SCRIPTABLE Q_NOREPLY void start()
Contains KGantt macros.
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
Global namespace.
@ ItemTypeRole
The item type.
@ StartTimeRole
Start time (or other start value) for a gantt item.
@ TaskCompletionRole
Task completion percentage used by Task items. Should be an integer og a qreal between 0 and 100.
@ LegendRole
The Legend text.
@ EndTimeRole
End time (or other end value) for a gantt item.
const QList< QKeySequence > & end()
const char * constData() const const
QDateTime addDays(qint64 ndays) const const
QDateTime currentDateTime()
bool isValid() const const
QString toString(QStringView format, QCalendar cal) const const
QByteArray toLatin1() const const
std::string toStdString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.