#include "kdganttdatetimegrid.h"
#include "kdganttdatetimegrid_p.h"
#include "kdganttabstractrowcontroller.h"
#include <QApplication>
#include <QDateTime>
#include <QPainter>
#include <QStyle>
#include <QStyleOptionHeader>
#include <QWidget>
#include <QDebug>
#include <cassert>
#include <QStandardItemModel>
#include "unittest/test.h"
#include "moc_kdganttdatetimegrid.cpp"
Go to the source code of this file.
Defines | |
#define | d d_func() |
Functions | |
KDAB_SCOPED_UNITTEST_SIMPLE (KDGantt, DateTimeGrid,"test") | |
std::ostream & | operator<< (std::ostream &os, const QDateTime &dt) |
QDebug | operator<< (QDebug dbg, KDGantt::DateTimeScaleFormatter::Range range) |
#define d d_func() |
Definition at line 89 of file kdganttdatetimegrid.cpp.
KDAB_SCOPED_UNITTEST_SIMPLE | ( | KDGantt | , | |
DateTimeGrid | , | |||
"test" | ||||
) |
Definition at line 1088 of file kdganttdatetimegrid.cpp.
References assertEqual, assertFalse, assertTrue, KDGantt::DateTimeGrid::dayWidth(), KDGantt::EndTimeRole, KDGantt::AbstractGrid::isSatisfiedConstraint(), KDGantt::Span::length(), KDGantt::DateTimeGrid::mapFromChart(), KDGantt::DateTimeGrid::mapFromDateTime(), KDGantt::DateTimeGrid::mapToChart(), KDGantt::DateTimeGrid::mapToDateTime(), KDGantt::AbstractGrid::model(), KDGantt::Span::setEnd(), KDGantt::AbstractGrid::setModel(), KDGantt::DateTimeGrid::setStartDateTime(), KDGantt::Span::start(), KDGantt::DateTimeGrid::startDateTime(), and KDGantt::StartTimeRole.
01088 { 01089 QStandardItemModel model( 3, 2 ); 01090 DateTimeGrid grid; 01091 QDateTime dt = QDateTime::currentDateTime(); 01092 grid.setModel( &model ); 01093 QDateTime startdt = dt.addDays( -10 ); 01094 grid.setStartDateTime( startdt ); 01095 01096 model.setData( model.index( 0, 0 ), dt, StartTimeRole ); 01097 model.setData( model.index( 0, 0 ), dt.addDays( 17 ), EndTimeRole ); 01098 01099 model.setData( model.index( 2, 0 ), dt.addDays( 18 ), StartTimeRole ); 01100 model.setData( model.index( 2, 0 ), dt.addDays( 19 ), EndTimeRole ); 01101 01102 Span s = grid.mapToChart( model.index( 0, 0 ) ); 01103 //qDebug() << "span="<<s; 01104 01105 assertTrue( s.start()>0 ); 01106 assertTrue( s.length()>0 ); 01107 01108 assertTrue( startdt == grid.mapToDateTime( grid.mapFromDateTime( startdt ) ) ); 01109 01110 grid.mapFromChart( s, model.index( 1, 0 ) ); 01111 01112 QDateTime s1 = model.data( model.index( 0, 0 ), StartTimeRole ).toDateTime(); 01113 QDateTime e1 = model.data( model.index( 0, 0 ), EndTimeRole ).toDateTime(); 01114 QDateTime s2 = model.data( model.index( 1, 0 ), StartTimeRole ).toDateTime(); 01115 QDateTime e2 = model.data( model.index( 1, 0 ), EndTimeRole ).toDateTime(); 01116 01117 assertTrue( s1.isValid() ); 01118 assertTrue( e1.isValid() ); 01119 assertTrue( s2.isValid() ); 01120 assertTrue( e2.isValid() ); 01121 01122 assertEqual( s1, s2 ); 01123 assertEqual( e1, e2 ); 01124 01125 assertTrue( grid.isSatisfiedConstraint( Constraint( model.index( 0, 0 ), model.index( 2, 0 ) ) ) ); 01126 assertFalse( grid.isSatisfiedConstraint( Constraint( model.index( 2, 0 ), model.index( 0, 0 ) ) ) ); 01127 01128 s = grid.mapToChart( model.index( 0, 0 ) ); 01129 s.setEnd( s.end()+100000. ); 01130 bool rc = grid.mapFromChart( s, model.index( 0, 0 ) ); 01131 assertTrue( rc ); 01132 assertEqual( s1, model.data( model.index( 0, 0 ), StartTimeRole ).toDateTime() ); 01133 Span newspan = grid.mapToChart( model.index( 0, 0 ) ); 01134 assertEqual( newspan.start(), s.start() ); 01135 assertEqual( newspan.length(), s.length() ); 01136 01137 { 01138 QDateTime startDateTime = QDateTime::currentDateTime(); 01139 qreal dayWidth = 100; 01140 QDate currentDate = QDate::currentDate(); 01141 QDateTime dt( QDate(currentDate.year(), 1, 1), QTime( 0, 0, 0, 0 ) ); 01142 assert( dt.isValid() ); 01143 qreal result = startDateTime.date().daysTo(dt.date())*24.*60.*60.; 01144 result += startDateTime.time().msecsTo(dt.time())/1000.; 01145 result *= dayWidth/( 24.*60.*60. ); 01146 01147 int days = static_cast<int>( result/dayWidth ); 01148 qreal secs = result*( 24.*60.*60. )/dayWidth; 01149 QDateTime dt2 = startDateTime; 01150 QDateTime result2 = dt2.addDays( days ).addSecs( static_cast<int>(secs-(days*24.*60.*60.) ) ).addMSecs( qRound( ( secs-static_cast<int>( secs ) )*1000. ) ); 01151 01152 assertEqual( dt, result2 ); 01153 } 01154 }
std::ostream& @13::operator<< | ( | std::ostream & | os, | |
const QDateTime & | dt | |||
) | [static] |
Definition at line 1077 of file kdganttdatetimegrid.cpp.
01078 { 01079 #ifdef QT_NO_STL 01080 os << dt.toString().toLatin1().constData(); 01081 #else 01082 os << dt.toString().toStdString(); 01083 #endif 01084 return os; 01085 }
QDebug operator<< | ( | QDebug | dbg, | |
KDGantt::DateTimeScaleFormatter::Range | range | |||
) |
Definition at line 42 of file kdganttdatetimegrid.cpp.
References KDGantt::DateTimeScaleFormatter::Day, KDGantt::DateTimeScaleFormatter::Hour, KDGantt::DateTimeScaleFormatter::Minute, KDGantt::DateTimeScaleFormatter::Month, KDGantt::DateTimeScaleFormatter::Second, KDGantt::DateTimeScaleFormatter::Week, and KDGantt::DateTimeScaleFormatter::Year.
00043 { 00044 switch( range ) { 00045 case KDGantt::DateTimeScaleFormatter::Second: dbg << "KDGantt::DateTimeScaleFormatter::Second"; break; 00046 case KDGantt::DateTimeScaleFormatter::Minute: dbg << "KDGantt::DateTimeScaleFormatter::Minute"; break; 00047 case KDGantt::DateTimeScaleFormatter::Hour: dbg << "KDGantt::DateTimeScaleFormatter::Hour"; break; 00048 case KDGantt::DateTimeScaleFormatter::Day: dbg << "KDGantt::DateTimeScaleFormatter::Day"; break; 00049 case KDGantt::DateTimeScaleFormatter::Week: dbg << "KDGantt::DateTimeScaleFormatter::Week"; break; 00050 case KDGantt::DateTimeScaleFormatter::Month: dbg << "KDGantt::DateTimeScaleFormatter::Month"; break; 00051 case KDGantt::DateTimeScaleFormatter::Year: dbg << "KDGantt::DateTimeScaleFormatter::Year"; break; 00052 } 00053 return dbg; 00054 }