24 #include "kdganttdatetimegrid_p.h" 28 #include <QApplication> 32 #include <QStyleOptionHeader> 64 qreal DateTimeGrid::Private::dateTimeToChartX(
const QDateTime& dt )
const 66 assert( startDateTime.isValid() );
67 qreal result = startDateTime.date().daysTo(dt.date())*24.*60.*60.;
68 result += startDateTime.time().msecsTo(dt.time())/1000.;
69 result *= dayWidth/( 24.*60.*60. );
74 QDateTime DateTimeGrid::Private::chartXtoDateTime( qreal x )
const 76 assert( startDateTime.isValid() );
77 int days =
static_cast<int>( x/dayWidth );
78 qreal secs = x*( 24.*60.*60. )/dayWidth;
79 QDateTime dt = startDateTime;
80 QDateTime result = dt.addDays( days )
81 .addSecs( static_cast<int>(secs-(days*24.*60.*60.) ) )
82 .addMSecs( qRound( ( secs-static_cast<int>( secs ) )*1000. ) );
116 const QString& templ, Qt::Alignment alignment )
117 : _d( new Private( range, format, templ, alignment ) )
122 : _d( new Private( range, format, QString::fromLatin1(
"%1" ), alignment ) )
138 if (
this == &other )
157 QString result =
d->format;
159 const QString shortWeekNumber = QString::number( datetime.date().weekNumber()) + QLatin1String(
"/")
160 + QString::number( datetime.date().year());
161 const QString longWeekNumber = ( shortWeekNumber.length() == 1 ? QString::fromLatin1(
"0" ) : QString() ) + shortWeekNumber;
162 result.replace( QString::fromLatin1(
"ww" ), longWeekNumber );
163 result.replace( QString::fromLatin1(
"w" ), shortWeekNumber );
164 result = datetime.toLocalTime().toString( result );
170 return d->templ.arg(
format( datetime ) );
190 QDateTime result = datetime;
194 result = result.addSecs( 60 );
198 result.setTime( QTime( result.time().hour(), result.time().minute() ) );
199 result = result.addSecs( 60 );
203 result.setTime( QTime( result.time().hour(), 0 ) );
204 result = result.addSecs( 60 * 60 );
208 result.setTime( QTime( 0, 0 ) );
209 result = result.addDays( 1 );
213 result.setTime( QTime( 0, 0 ) );
216 const int weekNumber = result.date().weekNumber();
217 while ( weekNumber == result.date().weekNumber() )
218 result = result.addDays( 1 );
223 result.setTime( QTime( 0, 0 ) );
225 result.setDate( QDate( result.date().year(), result.date().month(), 1 ).addMonths( 1 ) );
229 result.setTime( QTime( 0, 0 ) );
231 result.setDate( QDate( result.date().year(), 1, 1 ).addYears( 1 ) );
235 assert( result != datetime );
245 QDateTime result = datetime;
252 result.setTime( QTime( result.time().hour(), result.time().minute() ) );
256 result.setTime( QTime( result.time().hour(), 0 ) );
260 result.setTime( QTime( 0, 0 ) );
264 result.setTime( QTime( 0, 0 ) );
267 const int weekNumber = result.date().weekNumber();
268 while ( weekNumber == result.date().addDays( -1 ).weekNumber() )
269 result = result.addDays( -1 );
274 result.setTime( QTime( 0, 0 ) );
276 result.setDate( QDate( result.date().year(), result.date().month(), 1 ) );
280 result.setTime( QTime( 0, 0 ) );
282 result.setDate( QDate( result.date().year(), 1, 1 ) );
302 return d->startDateTime;
312 d->startDateTime = dt;
329 return d->dateTimeToChartX( dt );
336 return d->chartXtoDateTime( x );
462 d->freeDaysBrush = brush;
470 return d->freeDaysBrush;
476 return d->rowSeparators;
481 d->rowSeparators = enable;
490 d->noInformationBrush = brush;
498 return d->noInformationBrush;
507 if ( ! value.canConvert( QVariant::DateTime ) ||
508 ( value.type() == QVariant::String && value.toString().isEmpty() ) )
512 return d->dateTimeToChartX( value.toDateTime() );
521 return d->chartXtoDateTime( x );
530 if ( !idx.isValid() )
return Span();
531 assert( idx.model()==
model() );
534 if ( sv.canConvert( QVariant::DateTime ) &&
535 ev.canConvert( QVariant::DateTime ) &&
536 !(sv.type() == QVariant::String && sv.toString().isEmpty()) &&
537 !(ev.type() == QVariant::String && ev.toString().isEmpty())
539 QDateTime st = sv.toDateTime();
540 QDateTime et = ev.toDateTime();
541 if ( et.isValid() && st.isValid() ) {
542 qreal sx =
d->dateTimeToChartX( st );
543 qreal ex =
d->dateTimeToChartX( et )-sx;
545 return Span( sx, ex);
549 if ( sv.canConvert( QVariant::DateTime ) && !(sv.type() == QVariant::String && sv.toString().isEmpty()) ) {
550 QDateTime st = sv.toDateTime();
551 if ( st.isValid() ) {
552 qreal sx =
d->dateTimeToChartX( st );
553 return Span( sx, 0 );
560 static void debug_print_idx(
const QModelIndex& idx )
562 if ( !idx.isValid() ) {
563 qDebug() <<
"[Invalid]";
567 QDateTime et = idx.data(
EndTimeRole ).toDateTime();
568 qDebug() << idx <<
"["<<st<<et<<
"]";
590 if ( !idx.isValid() )
return false;
591 assert( idx.model()==
model() );
593 QDateTime st =
d->chartXtoDateTime(span.
start());
594 QDateTime et =
d->chartXtoDateTime(span.
start()+span.
length());
596 Q_FOREACH(
const Constraint& c, constraints ) {
601 if ( tmpst<et )
return false;
605 if ( tmpet>st )
return false;
613 Qt::PenStyle DateTimeGrid::Private::gridLinePenStyle( QDateTime dt, Private::HeaderType headerType )
const 615 switch ( headerType ) {
616 case Private::HeaderHour:
618 if ( dt.time().hour() == 0 )
619 return Qt::SolidLine;
621 case Private::HeaderDay:
623 if ( dt.date().dayOfWeek() ==
weekStart )
624 return Qt::SolidLine;
626 case Private::HeaderWeek:
628 if ( dt.date().day() == 1 )
629 return Qt::SolidLine;
631 if ( dt.date().dayOfWeek() ==
weekStart )
634 case Private::HeaderMonth:
636 if ( dt.date().dayOfYear() == 1 )
637 return Qt::SolidLine;
639 if ( dt.date().day() == 1 )
651 QDateTime DateTimeGrid::Private::adjustDateTimeForHeader( QDateTime dt, Private::HeaderType headerType )
const 654 dt.setTime( QTime( 0, 0, 0, 0 ) );
656 switch ( headerType ) {
657 case Private::HeaderWeek:
659 while ( dt.date().dayOfWeek() !=
weekStart )
660 dt = dt.addDays( -1 );
662 case Private::HeaderMonth:
664 dt = dt.addDays( 1 - dt.date().day() );
666 case Private::HeaderYear:
668 dt = dt.addDays( 1 - dt.date().dayOfYear() );
678 void DateTimeGrid::Private::paintVerticalLines( QPainter* painter,
679 const QRectF& sceneRect,
680 const QRectF& exposedRect,
682 Private::HeaderType headerType )
684 QDateTime dt = chartXtoDateTime( exposedRect.left() );
685 dt = adjustDateTimeForHeader( dt, headerType );
687 int offsetSeconds = 0;
690 if ( headerType == Private::HeaderHour )
691 offsetSeconds = 60*60;
695 for ( qreal x = dateTimeToChartX( dt ); x < exposedRect.right();
696 dt = dt.addSecs( offsetSeconds ), dt = dt.addDays( offsetDays ), x = dateTimeToChartX( dt ) ) {
700 QPen pen = painter->pen();
701 pen.setBrush( QApplication::palette().dark() );
702 pen.setStyle( gridLinePenStyle( dt, headerType ) );
703 painter->setPen( pen );
704 if (
freeDays.contains( static_cast<Qt::DayOfWeek>( dt.date().dayOfWeek() ) ) ) {
706 painter->setBrush( widget?widget->palette().midlight()
707 :QApplication::palette().midlight() );
711 painter->fillRect( QRectF( x, exposedRect.top(),
dayWidth, exposedRect.height() ), painter->brush() );
713 painter->drawLine( QPointF( x, sceneRect.top() ), QPointF( x, sceneRect.bottom() ) );
718 void DateTimeGrid::Private::paintVerticalUserDefinedLines( QPainter* painter,
719 const QRectF& sceneRect,
720 const QRectF& exposedRect,
725 QDateTime dt = chartXtoDateTime( exposedRect.left() );
727 QPen pen = painter->pen();
728 pen.setBrush( QApplication::palette().dark() );
729 pen.setStyle( Qt::DashLine );
730 painter->setPen( pen );
731 for ( qreal x = dateTimeToChartX( dt ); x < exposedRect.right();
733 if (
freeDays.contains( static_cast<Qt::DayOfWeek>( dt.date().dayOfWeek() ) ) ) {
734 QBrush oldBrush = painter->brush();
736 painter->setBrush( widget?widget->palette().midlight()
737 :QApplication::palette().midlight() );
741 painter->fillRect( QRectF( x, exposedRect.top(),
dayWidth, exposedRect.height() ), painter->brush() );
742 painter->setBrush( oldBrush );
748 painter->drawLine( QPointF( x, sceneRect.top() ), QPointF( x, sceneRect.bottom() ) );
757 return Private::HeaderHour;
759 return Private::HeaderDay;
761 return Private::HeaderWeek;
763 return Private::HeaderMonth;
769 return Private::HeaderDay;
773 const QRectF& sceneRect,
774 const QRectF& exposedRect,
784 d->paintVerticalLines( painter, sceneRect, exposedRect, widget,
d->headerTypeForScale(
scale() ) );
787 const qreal tabw = QApplication::fontMetrics().width( QLatin1String(
"XXXXX" ) );
789 if ( dayw > 24*60*60*tabw ) {
791 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect, &
d->minute_lower, widget );
792 }
else if ( dayw > 24*60*tabw ) {
793 d->paintVerticalLines( painter, sceneRect, exposedRect, widget, Private::HeaderHour );
794 }
else if ( dayw > 24*tabw ) {
795 d->paintVerticalLines( painter, sceneRect, exposedRect, widget, Private::HeaderDay );
796 }
else if ( dayw > tabw ) {
797 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect, &
d->week_lower, widget );
798 }
else if ( 4*dayw > tabw ) {
799 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect, &
d->month_lower, widget );
801 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect, &
d->year_lower, widget );
806 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect,
d->lower, widget );
809 if ( rowController ) {
811 QPen pen = painter->pen();
812 pen.setBrush( QApplication::palette().dark() );
813 pen.setStyle( Qt::DashLine );
814 painter->setPen( pen );
815 QModelIndex idx = rowController->
indexAt( qRound( exposedRect.top() ) );
818 while ( y < exposedRect.bottom() && idx.isValid() ) {
821 if (
d->rowSeparators ) {
822 painter->drawLine( QPointF( sceneRect.left(), y ),
823 QPointF( sceneRect.right(), y ) );
825 if ( !idx.data(
ItemTypeRole ).isValid() &&
d->noInformationBrush.style() != Qt::NoBrush ) {
826 painter->fillRect( QRectF( exposedRect.left(), s.
start(), exposedRect.width(), s.
length() ),
d->noInformationBrush );
835 int DateTimeGrid::Private::tabHeight(
const QString& txt,
QWidget* widget )
const 837 QStyleOptionHeader opt;
838 if ( widget ) opt.initFrom( widget );
841 if ( widget ) style = widget->style();
842 else style = QApplication::style();
843 QSize s = style->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), widget);
849 const qreal tabw = QApplication::fontMetrics().width( QLatin1String(
"XXXXX" ) );
851 if ( dayw > 24*60*60*tabw ) {
852 *lower = &minute_lower;
853 *upper = &minute_upper;
854 }
else if ( dayw > 24*60*tabw ) {
855 *lower = &hour_lower;
856 *upper = &hour_upper;
857 }
else if ( dayw > 24*tabw ) {
860 }
else if ( dayw > tabw ) {
861 *lower = &week_lower;
862 *upper = &week_upper;
863 }
else if ( 4*dayw > tabw ) {
864 *lower = &month_lower;
865 *upper = &month_upper;
867 *lower = &year_lower;
868 *upper = &year_upper;
874 qreal offset,
QWidget* widget )
877 QPainterPath clipPath;
878 clipPath.addRect( headerRect );
879 painter->setClipPath( clipPath, Qt::IntersectClip );
897 d->getAutomaticFormatters( &lower, &upper );
900 const qreal upperRatio = upperHeight/( lowerHeight+upperHeight );
902 const QRectF upperHeaderRect( headerRect.x(), headerRect.top(), headerRect.width()-1, headerRect.height() * upperRatio );
903 const QRectF lowerHeaderRect( headerRect.x(), upperHeaderRect.bottom()+1, headerRect.width()-1, headerRect.height()-upperHeaderRect.height()-1 );
911 const qreal lowerHeight =
d->tabHeight(
d->lower->text(
startDateTime() ) );
912 const qreal upperHeight =
d->tabHeight(
d->upper->text(
startDateTime() ) );
913 const qreal upperRatio = upperHeight/( lowerHeight+upperHeight );
915 const QRectF upperHeaderRect( headerRect.x(), headerRect.top(), headerRect.width()-1, headerRect.height() * upperRatio );
916 const QRectF lowerHeaderRect( headerRect.x(), upperHeaderRect.bottom()+1, headerRect.width()-1, headerRect.height()-upperHeaderRect.height()-1 );
927 const QRectF& headerRect,
const QRectF& exposedRect,
931 const QStyle*
const style = widget ? widget->style() : QApplication::style();
933 QDateTime dt = formatter->
currentRangeBegin(
d->chartXtoDateTime( offset + exposedRect.left() ));
934 qreal x =
d->dateTimeToChartX( dt );
936 while ( x < exposedRect.right() + offset ) {
938 const qreal nextx =
d->dateTimeToChartX( next );
940 QStyleOptionHeader opt;
941 if ( widget ) opt.init( widget );
942 opt.rect = QRectF( x - offset+1, headerRect.top(), qMax<qreal>( 1., nextx-x-1 ), headerRect.height() ).toAlignedRect();
943 opt.textAlignment = formatter->
alignment();
944 opt.text = formatter->
text( dt );
945 style->drawControl( QStyle::CE_Header, &opt, painter, widget );
952 void DateTimeGrid::Private::paintHeader( QPainter* painter,
953 const QRectF& headerRect,
const QRectF& exposedRect,
955 Private::HeaderType headerType,
956 DateTextFormatter *formatter )
958 QStyle* style = widget?widget->style():QApplication::style();
960 const qreal left = exposedRect.left() + offset;
961 const qreal right = exposedRect.right() + offset;
964 QDateTime dt = chartXtoDateTime( left );
965 dt = adjustDateTimeForHeader( dt, headerType );
967 int offsetSeconds = 0;
969 int offsetMonths = 0;
971 switch ( headerType ) {
972 case Private::HeaderHour:
973 offsetSeconds = 60*60;
975 case Private::HeaderDay:
978 case Private::HeaderWeek:
981 case Private::HeaderMonth:
984 case Private::HeaderYear:
993 for ( qreal x = dateTimeToChartX( dt ); x < right;
994 dt = dt.addSecs( offsetSeconds ), dt = dt.addDays( offsetDays ), dt = dt.addMonths( offsetMonths ),
995 x = dateTimeToChartX( dt ) ) {
996 QStyleOptionHeader opt;
997 if ( widget ) opt.init( widget );
998 opt.rect = formatter->textRect( x, offset,
dayWidth, headerRect, dt );
999 opt.text = formatter->format( dt );
1000 opt.textAlignment = Qt::AlignCenter;
1001 style->drawControl(QStyle::CE_Header, &opt, painter, widget);
1009 const QRectF& headerRect,
const QRectF& exposedRect,
1010 qreal offset,
QWidget* widget )
1012 class HourFormatter :
public Private::DateTextFormatter {
1014 virtual ~HourFormatter() {}
1016 QString format(
const QDateTime& dt ) {
1017 return dt.time().toString( QString::fromLatin1(
"hh" ) );
1019 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt ) {
1022 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset + 1.0, headerRect.height() / 2.0 ),
1023 QSizeF( dayWidth / 24.0, headerRect.height() / 2.0 ) ).toAlignedRect();
1026 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1027 Private::HeaderHour,
new HourFormatter );
1029 class DayFormatter :
public Private::DateTextFormatter {
1031 virtual ~DayFormatter() {}
1032 QString format(
const QDateTime& dt ) {
1033 return dt.date().toString();
1035 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt ) {
1038 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, 0.0 ),
1039 QSizeF( dayWidth, headerRect.height() / 2.0 ) ).toRect();
1042 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1043 Private::HeaderDay,
new DayFormatter );
1050 qreal offset,
QWidget* widget )
1052 class DayFormatter :
public Private::DateTextFormatter {
1054 virtual ~DayFormatter() {}
1056 QString format(
const QDateTime& dt ) {
1057 return dt.toString( QString::fromLatin1(
"ddd" ) ).left( 1 );
1059 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt ) {
1062 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset + 1.0, headerRect.height() / 2.0 ),
1063 QSizeF( dayWidth, headerRect.height() / 2.0 ) ).toAlignedRect();
1066 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1067 Private::HeaderDay,
new DayFormatter );
1069 class WeekFormatter :
public Private::DateTextFormatter {
1071 virtual ~WeekFormatter() {}
1072 QString format(
const QDateTime& dt ) {
1073 return QString::number(dt.date().weekNumber()) + QLatin1String(
"/") + QString::number(dt.date().year());
1075 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt ) {
1078 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, 0.0 ),
1079 QSizeF( dayWidth * 7, headerRect.height() / 2.0 ) ).toRect();
1082 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1083 Private::HeaderWeek,
new WeekFormatter );
1090 qreal offset,
QWidget* widget )
1092 class WeekFormatter :
public Private::DateTextFormatter {
1094 virtual ~WeekFormatter() {}
1096 QString format(
const QDateTime& dt ) {
1097 return QString::number( dt.date().weekNumber() );
1099 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt ) {
1102 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, headerRect.height() / 2.0 ),
1103 QSizeF( dayWidth * 7, headerRect.height() / 2.0 ) ).toRect();
1106 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1107 Private::HeaderWeek,
new WeekFormatter );
1109 class MonthFormatter :
public Private::DateTextFormatter {
1111 virtual ~MonthFormatter() {}
1113 QString format(
const QDateTime& dt ) {
1114 return QLocale().monthName(dt.date().month(), QLocale::LongFormat) + QLatin1String(
"/") + QString::number(dt.date().year());
1116 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt ) {
1117 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, 0.0 ),
1118 QSizeF( dayWidth * dt.date().daysInMonth(), headerRect.height() / 2.0 ) ).toRect();
1121 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1122 Private::HeaderMonth,
new MonthFormatter );
1129 qreal offset,
QWidget* widget )
1131 class MonthFormatter :
public Private::DateTextFormatter {
1133 virtual ~MonthFormatter() {}
1135 QString format(
const QDateTime& dt ) {
1136 return QLocale().monthName(dt.date().month(), QLocale::ShortFormat) + QLatin1String(
"/") + QString::number(dt.date().year());
1138 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt ) {
1139 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, headerRect.height() / 2.0 ),
1140 QSizeF( dayWidth * dt.date().daysInMonth(), headerRect.height() / 2.0 ) ).toRect();
1143 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1144 Private::HeaderMonth,
new MonthFormatter );
1146 class YearFormatter :
public Private::DateTextFormatter {
1148 virtual ~YearFormatter() {}
1150 QString format(
const QDateTime& dt ) {
1151 return QString::number( dt.date().year() );
1153 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt ) {
1154 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, 0.0 ),
1155 QSizeF( dayWidth * dt.date().daysInYear(), headerRect.height() / 2.0 ) ).toRect();
1158 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1159 Private::HeaderYear,
new YearFormatter );
1184 qreal topLeft =
d->dateTimeToChartX(from);
1185 qreal topRight =
d->dateTimeToChartX(to);
1187 return QRectF(topLeft, rect.top(), topRight - topLeft, rect.height());
1197 start =
d->chartXtoDateTime(rect.left());
1198 end =
d->chartXtoDateTime(rect.right());
1200 return qMakePair(start, end);
1208 QDate date =
d->chartXtoDateTime(rect.left()).date();
1211 int startx = rect.left();
1212 int endx = rect.right();
1220 QDate nextDate =
d->chartXtoDateTime(startx+1).date();
1221 if (date != nextDate)
1224 dayRect = dayRect.adjusted(1, 0, 0, 0);
1233 for (
int i=startx; i<endx; i+=offset)
1235 date =
d->chartXtoDateTime(i+1).date();
1237 QRectF dayRect(i, rect.top(),
dayWidth(), rect.height());
1238 dayRect = dayRect.adjusted(1, 0, 0, 0);
1251 QDate date =
d->chartXtoDateTime(rect.left()).date();
1254 int startx = rect.left();
1255 int endx = rect.right();
1263 QDate nextDate =
d->chartXtoDateTime(startx+1).date();
1264 if (date != nextDate)
1267 dayRect = dayRect.adjusted(1, 0, 0, 0);
1276 for (
int i=startx; i<endx; i+=offset)
1278 date =
d->chartXtoDateTime(i+1).date();
1280 QRectF dayRect(i, rect.top(),
dayWidth(), rect.height());
1281 dayRect = dayRect.adjusted(1, 0, 0, 0);
1291 #ifndef KDAB_NO_UNIT_TESTS 1293 #include <QStandardItemModel> 1296 static std::ostream&
operator<<( std::ostream& os,
const QDateTime& dt )
1299 os << dt.toString().toLatin1().constData();
1301 os << dt.toString().toStdString();
1307 QStandardItemModel
model( 3, 2 );
1309 QDateTime dt = QDateTime::currentDateTime();
1311 QDateTime startdt = dt.addDays( -10 );
1315 model.setData( model.index( 0, 0 ), dt.addDays( 17 ),
EndTimeRole );
1317 model.setData( model.index( 2, 0 ), dt.addDays( 18 ),
StartTimeRole );
1318 model.setData( model.index( 2, 0 ), dt.addDays( 19 ),
EndTimeRole );
1330 QDateTime s1 = model.data( model.index( 0, 0 ),
StartTimeRole ).toDateTime();
1331 QDateTime e1 = model.data( model.index( 0, 0 ),
EndTimeRole ).toDateTime();
1332 QDateTime s2 = model.data( model.index( 1, 0 ),
StartTimeRole ).toDateTime();
1333 QDateTime e2 = model.data( model.index( 1, 0 ),
EndTimeRole ).toDateTime();
1347 s.
setEnd( s.end()+100000. );
1358 QDate currentDate = QDate::currentDate();
1359 QDateTime dt( QDate(currentDate.year(), 1, 1), QTime( 0, 0, 0, 0 ) );
1360 assert( dt.isValid() );
1361 qreal result = startDateTime.date().daysTo(dt.date())*24.*60.*60.;
1362 result += startDateTime.time().msecsTo(dt.time())/1000.;
1363 result *= dayWidth/( 24.*60.*60. );
1365 int days =
static_cast<int>( result/
dayWidth );
1366 qreal secs = result*( 24.*60.*60. )/dayWidth;
1368 QDateTime result2 = dt2.addDays( days ).addSecs( static_cast<int>(secs-(days*24.*60.*60.) ) ).addMSecs( qRound( ( secs-static_cast<int>( secs ) )*1000. ) );
1376 #include "moc_kdganttdatetimegrid.cpp" void setNoInformationBrush(const QBrush &brush)
DateTimeScaleFormatter * userDefinedUpperScale() const
KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, DateTimeGrid,"test")
QDateTime mapToDateTime(qreal x) const
void setUserDefinedLowerScale(DateTimeScaleFormatter *lower)
Abstract baseclass for grids. A grid is used to convert between QModelIndex'es and gantt chart values...
virtual void paintUserDefinedHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, const DateTimeScaleFormatter *formatter, QWidget *widget=0)
virtual QModelIndex indexBelow(const QModelIndex &idx) const =0
qreal mapFromDateTime(const QDateTime &dt) const
Span mapToChart(const QModelIndex &idx) const
void paintHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, QWidget *widget=0)
A class used to represent a dependency.
virtual Span rowGeometry(const QModelIndex &idx) const =0
QPair< QDateTime, QDateTime > dateTimeRange(const QRectF &rect) const
Return a date-range represented by the rectangle.
QDebug operator<<(QDebug dbg, KDGantt::DateTimeScaleFormatter::Range range)
virtual void paintMonthScaleHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, QWidget *widget=0)
QRectF computeRect(const QDateTime &from, const QDateTime &to, const QRectF &rect) const
Return the rectangle that represents the date-range.
bool mapFromChart(const Span &span, const QModelIndex &idx, const QList< Constraint > &constraints=QList< Constraint >()) const
virtual void paintWeekScaleHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, QWidget *widget=0)
void setUserDefinedUpperScale(DateTimeScaleFormatter *upper)
void drawForeground(QPainter *paint, const QRectF &rect)
virtual void drawDayBackground(QPainter *painter, const QRectF &rect, const QDate &date)
virtual QModelIndex indexAt(int height) const =0
A class representing a start point and a length.
virtual QModelIndex indexAbove(const QModelIndex &idx) const =0
bool isSatisfiedConstraint(const Constraint &c) const
virtual void setModel(QAbstractItemModel *model)
QAbstractItemModel * model() const
virtual void drawDayForeground(QPainter *painter, const QRectF &rect, const QDate &date)
void setWeekStart(Qt::DayOfWeek)
void setStartDateTime(const QDateTime &dt)
DateTimeScaleFormatter * userDefinedLowerScale() const
void setFreeDaysBrush(const QBrush brush)
void paintGrid(QPainter *painter, const QRectF &sceneRect, const QRectF &exposedRect, AbstractRowController *rowController=0, QWidget *widget=0)
virtual void paintDayScaleHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, QWidget *widget=0)
void setFreeDays(const QSet< Qt::DayOfWeek > &fd)
bool rowSeparators() const
QBrush freeDaysBrush() const
QModelIndex endIndex() const
void drawBackground(QPainter *paint, const QRectF &rect)
virtual void paintHourScaleHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, QWidget *widget=0)
QDateTime startDateTime() const
QSet< Qt::DayOfWeek > freeDays() const
Qt::DayOfWeek weekStart() const
Abstract baseclass for row controllers. A row controller is used by the GraphicsView to nagivate the ...
QModelIndex startIndex() const
void setRowSeparators(bool enable)
#define assertEqual(x, y)
QBrush noInformationBrush() const