1 /****************************************************************************
2 ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved.
4 ** This file is part of the KD Gantt library.
6 ** This file may be used under the terms of the GNU General Public
7 ** License versions 2.0 or 3.0 as published by the Free Software
8 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
9 ** included in the packaging of this file. Alternatively you may (at
10 ** your option) use any later version of the GNU General Public
11 ** License if such license has been publicly approved by
12 ** Klarälvdalens Datakonsult AB (or its successors, if any).
14 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
15 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
16 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
17 ** not expressly granted herein.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **********************************************************************/
23 #include "kdganttglobal.h"
25 using namespace KDGantt
;
27 /*!\enum KDGantt::ItemDataRole
29 * The values of this enum are used for the special data roles
33 /*!\enum KDGantt::ItemDataRole KDGantt::KDGanttRoleBase
34 * The base value used for the KDGantt role enum values.
35 * The actual roles have values base+1, base+2, ...
38 /*!\enum KDGantt::ItemDataRole KDGantt::StartTimeRole
39 * Start time (or other start value) for a gantt item.
42 /*!\enum KDGantt::ItemDataRole KDGantt::EndTimeRole
43 * End time (or other end value) for a gantt item.
46 /*!\enum KDGantt::ItemDataRole KDGantt::TaskCompletionRole
47 * Task completetion percentage used by Task items. Should be an
48 * integer og a double between 0 and 100.
51 /*!\enum KDGantt::ItemDataRole KDGantt::ItemTypeRole
52 * The item type. \see KDGantt::ItemType.
55 /*!\enum KDGantt::ItemType
57 * The values of this enum are used to represent the different
58 * types of gantt items that KDGantt understands. The itemtype
59 * is served through the KDGantt::ItemTypeRole role
62 /*!\class KDGantt::Span kdganttglobal.h KDGanttGlobal
64 * \brief A class representing a start point and a length */
70 DateTimeSpan::DateTimeSpan()
74 DateTimeSpan::DateTimeSpan( const QDateTime
& start
, const QDateTime
& end
)
75 : m_start( start
), m_end( end
)
79 DateTimeSpan::DateTimeSpan( const DateTimeSpan
& other
)
84 DateTimeSpan::~DateTimeSpan()
88 DateTimeSpan
& DateTimeSpan::operator=( const DateTimeSpan
& other
)
90 if ( this != &other
) {
91 m_start
= other
.m_start
;
97 bool DateTimeSpan::isValid() const
99 return m_start
.isValid() && m_end
.isValid();
102 bool DateTimeSpan::equals( const DateTimeSpan
& other
) const
104 return m_start
==other
.m_start
&& m_end
==other
.m_end
;
107 #ifndef QT_NO_DEBUG_STREAM
109 QDebug
operator<<( QDebug dbg
, KDGantt::ItemDataRole r
)
112 case KDGantt::StartTimeRole
: dbg
<< "KDGantt::StartTimeRole"; break;
113 case KDGantt::EndTimeRole
: dbg
<< "KDGantt::EndTimeRole"; break;
114 case KDGantt::TaskCompletionRole
: dbg
<< "KDGantt::TaskCompletionRole"; break;
115 case KDGantt::ItemTypeRole
: dbg
<< "KDGantt::ItemTypeRole"; break;
116 case KDGantt::LegendRole
: dbg
<< "KDGantt::LegendRole"; break;
117 default: dbg
<< static_cast<Qt::ItemDataRole
>(r
);
122 QDebug
operator<<( QDebug dbg
, const KDGantt::Span
& s
)
124 dbg
<< "KDGantt::Span[ start="<<s
.start()<<" length="<<s
.length()<<"]";
127 QDebug
operator<<( QDebug dbg
, const KDGantt::DateTimeSpan
& s
)
129 dbg
<< "KDGantt::DateTimeSpan[ start="<<s
.start()<<" end="<<s
.end()<<"]";
133 #endif /* QT_NO_DEBUG_STREAM */
135 #ifndef KDAB_NO_UNIT_TESTS
136 #include "unittest/test.h"
139 std::ostream
& operator<<( std::ostream
& os
, const Span
& span
)
141 os
<< "Span[ start="<<span
.start()<<", length="<<span
.length()<<"]";
144 std::ostream
& operator<<( std::ostream
& os
, const DateTimeSpan
& span
)
146 os
<< "DateTimeSpan[ start="<<span
.start().toString().toStdString()
147 << ", end="<<span
.end().toString().toStdString() << "]";
152 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt
, Span
, "test" ) {
154 assertFalse( s1
.isValid() );
158 Span
s2( s1
.start(), s1
.length() );
159 assertEqual( s1
, s2
);
162 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt
, DateTimeSpan
, "test" ) {
164 assertFalse( s1
.isValid() );
165 QDateTime dt
= QDateTime::currentDateTime();
167 assertTrue( dt
.isValid() );
168 s1
.setEnd( dt
.addDays( 1 ) );
170 DateTimeSpan
s2( dt
, dt
.addDays( 1 ) );
172 assertEqual( s1
, s2
);
176 assertNotEqual( s1
, s3
);
178 #endif /* KDAB_NO_UNIT_TESTS */