KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
kdganttglobal.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 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 
27 /* Older Qt don't have this macro, so define it... */
28 #ifndef QT_VERSION_CHECK
29 # define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
30 #endif
31 
32 /* Version check */
33 #if QT_VERSION < QT_VERSION_CHECK(4,3,0)
34 # error "The minimum required version of Qt for KD Gantt is 4.3.0"
35 #endif
36 
83 {
84 }
85 
86 DateTimeSpan::DateTimeSpan( const QDateTime& start, const QDateTime& end )
87  : m_start( start ), m_end( end )
88 {
89 }
90 
92 {
93  *this = other;
94 }
95 
97 {
98 }
99 
101 {
102  if ( this != &other ) {
103  m_start = other.m_start;
104  m_end = other.m_end;
105  }
106  return *this;
107 }
108 
110 {
111  return m_start.isValid() && m_end.isValid();
112 }
113 
114 bool DateTimeSpan::equals( const DateTimeSpan& other ) const
115 {
116  return m_start==other.m_start && m_end==other.m_end;
117 }
118 
119 #ifndef QT_NO_DEBUG_STREAM
120 
121 QDebug operator<<( QDebug dbg, KDGantt::ItemDataRole r)
122 {
123  switch (r) {
124  case KDGantt::StartTimeRole: dbg << "KDGantt::StartTimeRole"; break;
125  case KDGantt::EndTimeRole: dbg << "KDGantt::EndTimeRole"; break;
126  case KDGantt::TaskCompletionRole: dbg << "KDGantt::TaskCompletionRole"; break;
127  case KDGantt::ItemTypeRole: dbg << "KDGantt::ItemTypeRole"; break;
128  case KDGantt::LegendRole: dbg << "KDGantt::LegendRole"; break;
129  default: dbg << static_cast<Qt::ItemDataRole>(r);
130  }
131  return dbg;
132 }
133 
134 QDebug operator<<( QDebug dbg, KDGantt::ItemType t)
135 {
136  switch ( t ) {
137  case KDGantt::TypeNone: dbg << "KDGantt::TypeNone"; break;
138  case KDGantt::TypeEvent: dbg << "KDGantt::TypeEvent"; break;
139  case KDGantt::TypeTask: dbg << "KDGantt::TypeTask"; break;
140  case KDGantt::TypeSummary: dbg << "KDGantt::TypeSummary"; break;
141  case KDGantt::TypeMulti: dbg << "KDGantt::TypeMulti"; break;
142  case KDGantt::TypeUser: dbg << "KDGantt::TypeUser"; break;
143  default: dbg << static_cast<int>(t);
144  }
145  return dbg;
146 }
147 
148 QDebug operator<<( QDebug dbg, const KDGantt::Span& s )
149 {
150  dbg << "KDGantt::Span[ start="<<s.start()<<" length="<<s.length()<<"]";
151  return dbg;
152 }
153 QDebug operator<<( QDebug dbg, const KDGantt::DateTimeSpan& s )
154 {
155  dbg << "KDGantt::DateTimeSpan[ start="<<s.start()<<" end="<<s.end()<<"]";
156  return dbg;
157 }
158 
159 #endif /* QT_NO_DEBUG_STREAM */
160 
161 #ifndef KDAB_NO_UNIT_TESTS
162 
163 #include <ostream>
164 
165 static std::ostream& operator<<( std::ostream& os, const Span& span )
166 {
167  os << "Span[ start="<<span.start()<<", length="<<span.length()<<"]";
168  return os;
169 }
170 
171 static std::ostream& operator<<( std::ostream& os, const DateTimeSpan& span )
172 {
173 #ifdef QT_NO_STL
174  os << "DateTimeSpan[ start="<<span.start().toString().toLatin1().constData()
175  << ", end="<<span.end().toString().toLatin1().constData() << "]";
176 #else
177  os << "DateTimeSpan[ start="<<span.start().toString().toStdString()
178  << ", end="<<span.end().toString().toStdString() << "]";
179 #endif
180  return os;
181 }
182 
183 #include "unittest/test.h"
184 
185 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, Span, "test" ) {
186  Span s1;
187  assertFalse( s1.isValid() );
188  s1.setStart( 10. );
189  s1.setLength( 2. );
190 
191  Span s2( s1.start(), s1.length() );
192  assertEqual( s1, s2 );
193 }
194 
196  DateTimeSpan s1;
197  assertFalse( s1.isValid() );
198  QDateTime dt = QDateTime::currentDateTime();
199  s1.setStart( dt );
200  assertTrue( dt.isValid() );
201  s1.setEnd( dt.addDays( 1 ) );
202 
203  DateTimeSpan s2( dt, dt.addDays( 1 ) );
204 
205  assertEqual( s1, s2 );
206 
207  DateTimeSpan s3;
208 
209  assertNotEqual( s1, s3 );
210 }
211 #endif /* KDAB_NO_UNIT_TESTS */

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/