24 #include "kdganttdatetimegrid_p.h" 28 #include <QApplication> 32 #include <QStyleOptionHeader> 37 #include <QPainterPath> 65 qreal DateTimeGrid::Private::dateTimeToChartX(
const QDateTime& dt )
const 67 assert( startDateTime.isValid() );
68 qreal result = startDateTime.date().daysTo(dt.date())*24.*60.*60.;
69 result += startDateTime.time().msecsTo(dt.time())/1000.;
70 result *= dayWidth/( 24.*60.*60. );
75 QDateTime DateTimeGrid::Private::chartXtoDateTime( qreal x )
const 77 assert( startDateTime.isValid() );
78 int days =
static_cast<int>( x/dayWidth );
79 qreal secs = x*( 24.*60.*60. )/dayWidth;
80 QDateTime dt = startDateTime;
81 QDateTime result = dt.addDays( days )
82 .addSecs( static_cast<int>(secs-(days*24.*60.*60.) ) )
83 .addMSecs( qRound( ( secs-static_cast<int>( secs ) )*1000. ) );
117 const QString& templ, Qt::Alignment alignment )
118 : _d( new Private( range, format, templ, alignment ) )
123 : _d( new Private( range, format, QString::fromLatin1(
"%1" ), alignment ) )
139 if (
this == &other )
158 QString result =
d->format;
160 const QString shortWeekNumber = QString::number( datetime.date().weekNumber()) + QLatin1String(
"/")
161 + QString::number( datetime.date().year());
162 const QString longWeekNumber = ( shortWeekNumber.length() == 1 ? QString::fromLatin1(
"0" ) : QString() ) + shortWeekNumber;
163 result.replace( QString::fromLatin1(
"ww" ), longWeekNumber );
164 result.replace( QString::fromLatin1(
"w" ), shortWeekNumber );
165 result = datetime.toLocalTime().toString( result );
171 return d->templ.arg(
format( datetime ) );
191 QDateTime result = datetime;
195 result = result.addSecs( 60 );
199 result.setTime( QTime( result.time().hour(), result.time().minute() ) );
200 result = result.addSecs( 60 );
204 result.setTime( QTime( result.time().hour(), 0 ) );
205 result = result.addSecs( 60 * 60 );
209 result.setTime( QTime( 0, 0 ) );
210 result = result.addDays( 1 );
214 result.setTime( QTime( 0, 0 ) );
217 const int weekNumber = result.date().weekNumber();
218 while ( weekNumber == result.date().weekNumber() )
219 result = result.addDays( 1 );
224 result.setTime( QTime( 0, 0 ) );
226 result.setDate( QDate( result.date().year(), result.date().month(), 1 ).addMonths( 1 ) );
230 result.setTime( QTime( 0, 0 ) );
232 result.setDate( QDate( result.date().year(), 1, 1 ).addYears( 1 ) );
236 assert( result != datetime );
246 QDateTime result = datetime;
253 result.setTime( QTime( result.time().hour(), result.time().minute() ) );
257 result.setTime( QTime( result.time().hour(), 0 ) );
261 result.setTime( QTime( 0, 0 ) );
265 result.setTime( QTime( 0, 0 ) );
268 const int weekNumber = result.date().weekNumber();
269 while ( weekNumber == result.date().addDays( -1 ).weekNumber() )
270 result = result.addDays( -1 );
275 result.setTime( QTime( 0, 0 ) );
277 result.setDate( QDate( result.date().year(), result.date().month(), 1 ) );
281 result.setTime( QTime( 0, 0 ) );
283 result.setDate( QDate( result.date().year(), 1, 1 ) );
303 return d->startDateTime;
313 d->startDateTime = dt;
330 return d->dateTimeToChartX( dt );
337 return d->chartXtoDateTime( x );
463 d->freeDaysBrush = brush;
471 return d->freeDaysBrush;
477 return d->rowSeparators;
482 d->rowSeparators = enable;
491 d->noInformationBrush = brush;
499 return d->noInformationBrush;
508 if ( ! value.canConvert( QVariant::DateTime ) ||
509 ( value.type() == QVariant::String && value.toString().isEmpty() ) )
513 return d->dateTimeToChartX( value.toDateTime() );
522 return d->chartXtoDateTime( x );
531 if ( !idx.isValid() )
return Span();
532 assert( idx.model()==
model() );
535 if ( sv.canConvert( QVariant::DateTime ) &&
536 ev.canConvert( QVariant::DateTime ) &&
537 !(sv.type() == QVariant::String && sv.toString().isEmpty()) &&
538 !(ev.type() == QVariant::String && ev.toString().isEmpty())
540 QDateTime st = sv.toDateTime();
541 QDateTime et = ev.toDateTime();
542 if ( et.isValid() && st.isValid() ) {
543 qreal sx =
d->dateTimeToChartX( st );
544 qreal ex =
d->dateTimeToChartX( et )-sx;
546 return Span( sx, ex);
550 if ( sv.canConvert( QVariant::DateTime ) && !(sv.type() == QVariant::String && sv.toString().isEmpty()) ) {
551 QDateTime st = sv.toDateTime();
552 if ( st.isValid() ) {
553 qreal sx =
d->dateTimeToChartX( st );
554 return Span( sx, 0 );
561 static void debug_print_idx(
const QModelIndex& idx )
563 if ( !idx.isValid() ) {
564 qDebug() <<
"[Invalid]";
568 QDateTime et = idx.data(
EndTimeRole ).toDateTime();
569 qDebug() << idx <<
"["<<st<<et<<
"]";
591 if ( !idx.isValid() )
return false;
592 assert( idx.model()==
model() );
594 QDateTime st =
d->chartXtoDateTime(span.
start());
595 QDateTime et =
d->chartXtoDateTime(span.
start()+span.
length());
597 Q_FOREACH(
const Constraint& c, constraints ) {
602 if ( tmpst<et )
return false;
606 if ( tmpet>st )
return false;
614 Qt::PenStyle DateTimeGrid::Private::gridLinePenStyle( QDateTime dt, Private::HeaderType headerType )
const 616 switch ( headerType ) {
617 case Private::HeaderHour:
619 if ( dt.time().hour() == 0 )
620 return Qt::SolidLine;
622 case Private::HeaderDay:
624 if ( dt.date().dayOfWeek() ==
weekStart )
625 return Qt::SolidLine;
627 case Private::HeaderWeek:
629 if ( dt.date().day() == 1 )
630 return Qt::SolidLine;
632 if ( dt.date().dayOfWeek() ==
weekStart )
635 case Private::HeaderMonth:
637 if ( dt.date().dayOfYear() == 1 )
638 return Qt::SolidLine;
640 if ( dt.date().day() == 1 )
652 QDateTime DateTimeGrid::Private::adjustDateTimeForHeader( QDateTime dt, Private::HeaderType headerType )
const 655 dt.setTime( QTime( 0, 0, 0, 0 ) );
657 switch ( headerType ) {
658 case Private::HeaderWeek:
660 while ( dt.date().dayOfWeek() !=
weekStart )
661 dt = dt.addDays( -1 );
663 case Private::HeaderMonth:
665 dt = dt.addDays( 1 - dt.date().day() );
667 case Private::HeaderYear:
669 dt = dt.addDays( 1 - dt.date().dayOfYear() );
679 void DateTimeGrid::Private::paintVerticalLines( QPainter* painter,
680 const QRectF& sceneRect,
681 const QRectF& exposedRect,
683 Private::HeaderType headerType )
685 QDateTime dt = chartXtoDateTime( exposedRect.left() );
686 dt = adjustDateTimeForHeader( dt, headerType );
688 int offsetSeconds = 0;
691 if ( headerType == Private::HeaderHour )
692 offsetSeconds = 60*60;
696 for ( qreal x = dateTimeToChartX( dt ); x < exposedRect.right();
697 dt = dt.addSecs( offsetSeconds ), dt = dt.addDays( offsetDays ), x = dateTimeToChartX( dt ) ) {
701 QPen pen = painter->pen();
702 pen.setBrush( QApplication::palette().dark() );
703 pen.setStyle( gridLinePenStyle( dt, headerType ) );
704 painter->setPen( pen );
705 if (
freeDays.contains( static_cast<Qt::DayOfWeek>( dt.date().dayOfWeek() ) ) ) {
707 painter->setBrush( widget?widget->palette().midlight()
708 :QApplication::palette().midlight() );
712 painter->fillRect( QRectF( x, exposedRect.top(),
dayWidth, exposedRect.height() ), painter->brush() );
714 painter->drawLine( QPointF( x, sceneRect.top() ), QPointF( x, sceneRect.bottom() ) );
719 void DateTimeGrid::Private::paintVerticalUserDefinedLines( QPainter* painter,
720 const QRectF& sceneRect,
721 const QRectF& exposedRect,
726 QDateTime dt = chartXtoDateTime( exposedRect.left() );
728 QPen pen = painter->pen();
729 pen.setBrush( QApplication::palette().dark() );
730 pen.setStyle( Qt::DashLine );
731 painter->setPen( pen );
732 for ( qreal x = dateTimeToChartX( dt ); x < exposedRect.right();
734 if (
freeDays.contains( static_cast<Qt::DayOfWeek>( dt.date().dayOfWeek() ) ) ) {
735 QBrush oldBrush = painter->brush();
737 painter->setBrush( widget?widget->palette().midlight()
738 :QApplication::palette().midlight() );
742 painter->fillRect( QRectF( x, exposedRect.top(),
dayWidth, exposedRect.height() ), painter->brush() );
743 painter->setBrush( oldBrush );
749 painter->drawLine( QPointF( x, sceneRect.top() ), QPointF( x, sceneRect.bottom() ) );
758 return Private::HeaderHour;
760 return Private::HeaderDay;
762 return Private::HeaderWeek;
764 return Private::HeaderMonth;
770 return Private::HeaderDay;
774 const QRectF& sceneRect,
775 const QRectF& exposedRect,
785 d->paintVerticalLines( painter, sceneRect, exposedRect, widget,
d->headerTypeForScale(
scale() ) );
788 const qreal tabw = QApplication::fontMetrics().width( QLatin1String(
"XXXXX" ) );
790 if ( dayw > 24*60*60*tabw ) {
792 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect, &
d->minute_lower, widget );
793 }
else if ( dayw > 24*60*tabw ) {
794 d->paintVerticalLines( painter, sceneRect, exposedRect, widget, Private::HeaderHour );
795 }
else if ( dayw > 24*tabw ) {
796 d->paintVerticalLines( painter, sceneRect, exposedRect, widget, Private::HeaderDay );
797 }
else if ( dayw > tabw ) {
798 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect, &
d->week_lower, widget );
799 }
else if ( 4*dayw > tabw ) {
800 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect, &
d->month_lower, widget );
802 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect, &
d->year_lower, widget );
807 d->paintVerticalUserDefinedLines( painter, sceneRect, exposedRect,
d->lower, widget );
810 if ( rowController ) {
812 QPen pen = painter->pen();
813 pen.setBrush( QApplication::palette().dark() );
814 pen.setStyle( Qt::DashLine );
815 painter->setPen( pen );
816 QModelIndex idx = rowController->
indexAt( qRound( exposedRect.top() ) );
819 while ( y < exposedRect.bottom() && idx.isValid() ) {
822 if (
d->rowSeparators ) {
823 painter->drawLine( QPointF( sceneRect.left(), y ),
824 QPointF( sceneRect.right(), y ) );
826 if ( !idx.data(
ItemTypeRole ).isValid() &&
d->noInformationBrush.style() != Qt::NoBrush ) {
827 painter->fillRect( QRectF( exposedRect.left(), s.
start(), exposedRect.width(), s.
length() ),
d->noInformationBrush );
836 int DateTimeGrid::Private::tabHeight(
const QString& txt,
QWidget* widget )
const 838 QStyleOptionHeader opt;
839 if ( widget ) opt.initFrom( widget );
842 if ( widget ) style = widget->style();
843 else style = QApplication::style();
844 QSize s = style->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), widget);
850 const qreal tabw = QApplication::fontMetrics().width( QLatin1String(
"XXXXX" ) );
852 if ( dayw > 24*60*60*tabw ) {
853 *lower = &minute_lower;
854 *upper = &minute_upper;
855 }
else if ( dayw > 24*60*tabw ) {
856 *lower = &hour_lower;
857 *upper = &hour_upper;
858 }
else if ( dayw > 24*tabw ) {
861 }
else if ( dayw > tabw ) {
862 *lower = &week_lower;
863 *upper = &week_upper;
864 }
else if ( 4*dayw > tabw ) {
865 *lower = &month_lower;
866 *upper = &month_upper;
868 *lower = &year_lower;
869 *upper = &year_upper;
875 qreal offset,
QWidget* widget )
878 QPainterPath clipPath;
879 clipPath.addRect( headerRect );
880 painter->setClipPath( clipPath, Qt::IntersectClip );
898 d->getAutomaticFormatters( &lower, &upper );
901 const qreal upperRatio = upperHeight/( lowerHeight+upperHeight );
903 const QRectF upperHeaderRect( headerRect.x(), headerRect.top(), headerRect.width()-1, headerRect.height() * upperRatio );
904 const QRectF lowerHeaderRect( headerRect.x(), upperHeaderRect.bottom()+1, headerRect.width()-1, headerRect.height()-upperHeaderRect.height()-1 );
912 const qreal lowerHeight =
d->tabHeight(
d->lower->text(
startDateTime() ) );
913 const qreal upperHeight =
d->tabHeight(
d->upper->text(
startDateTime() ) );
914 const qreal upperRatio = upperHeight/( lowerHeight+upperHeight );
916 const QRectF upperHeaderRect( headerRect.x(), headerRect.top(), headerRect.width()-1, headerRect.height() * upperRatio );
917 const QRectF lowerHeaderRect( headerRect.x(), upperHeaderRect.bottom()+1, headerRect.width()-1, headerRect.height()-upperHeaderRect.height()-1 );
928 const QRectF& headerRect,
const QRectF& exposedRect,
932 const QStyle*
const style = widget ? widget->style() : QApplication::style();
934 QDateTime dt = formatter->
currentRangeBegin(
d->chartXtoDateTime( offset + exposedRect.left() ));
935 qreal x =
d->dateTimeToChartX( dt );
937 while ( x < exposedRect.right() + offset ) {
939 const qreal nextx =
d->dateTimeToChartX( next );
941 QStyleOptionHeader opt;
942 if ( widget ) opt.init( widget );
943 opt.rect = QRectF( x - offset+1, headerRect.top(), qMax<qreal>( 1., nextx-x-1 ), headerRect.height() ).toAlignedRect();
944 opt.textAlignment = formatter->
alignment();
945 opt.text = formatter->
text( dt );
946 style->drawControl( QStyle::CE_Header, &opt, painter, widget );
953 void DateTimeGrid::Private::paintHeader( QPainter* painter,
954 const QRectF& headerRect,
const QRectF& exposedRect,
956 Private::HeaderType headerType,
957 DateTextFormatter *formatter )
959 QStyle* style = widget?widget->style():QApplication::style();
961 const qreal left = exposedRect.left() + offset;
962 const qreal right = exposedRect.right() + offset;
965 QDateTime dt = chartXtoDateTime( left );
966 dt = adjustDateTimeForHeader( dt, headerType );
968 int offsetSeconds = 0;
970 int offsetMonths = 0;
972 switch ( headerType ) {
973 case Private::HeaderHour:
974 offsetSeconds = 60*60;
976 case Private::HeaderDay:
979 case Private::HeaderWeek:
982 case Private::HeaderMonth:
985 case Private::HeaderYear:
994 for ( qreal x = dateTimeToChartX( dt ); x < right;
995 dt = dt.addSecs( offsetSeconds ), dt = dt.addDays( offsetDays ), dt = dt.addMonths( offsetMonths ),
996 x = dateTimeToChartX( dt ) ) {
997 QStyleOptionHeader opt;
998 if ( widget ) opt.init( widget );
999 opt.rect = formatter->textRect( x, offset,
dayWidth, headerRect, dt );
1000 opt.text = formatter->format( dt );
1001 opt.textAlignment = Qt::AlignCenter;
1002 style->drawControl(QStyle::CE_Header, &opt, painter, widget);
1010 const QRectF& headerRect,
const QRectF& exposedRect,
1011 qreal offset,
QWidget* widget )
1013 class HourFormatter :
public Private::DateTextFormatter {
1015 ~HourFormatter()
override {}
1017 QString format(
const QDateTime& dt )
override {
1018 return dt.time().toString( QString::fromLatin1(
"hh" ) );
1020 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt )
override {
1023 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset + 1.0, headerRect.height() / 2.0 ),
1024 QSizeF( dayWidth / 24.0, headerRect.height() / 2.0 ) ).toAlignedRect();
1027 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1028 Private::HeaderHour,
new HourFormatter );
1030 class DayFormatter :
public Private::DateTextFormatter {
1032 ~DayFormatter()
override {}
1033 QString format(
const QDateTime& dt )
override {
1034 return dt.date().toString();
1036 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt )
override {
1039 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, 0.0 ),
1040 QSizeF( dayWidth, headerRect.height() / 2.0 ) ).toRect();
1043 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1044 Private::HeaderDay,
new DayFormatter );
1051 qreal offset,
QWidget* widget )
1053 class DayFormatter :
public Private::DateTextFormatter {
1055 ~DayFormatter()
override {}
1057 QString format(
const QDateTime& dt )
override {
1058 return dt.toString( QString::fromLatin1(
"ddd" ) ).left( 1 );
1060 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt )
override {
1063 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset + 1.0, headerRect.height() / 2.0 ),
1064 QSizeF( dayWidth, headerRect.height() / 2.0 ) ).toAlignedRect();
1067 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1068 Private::HeaderDay,
new DayFormatter );
1070 class WeekFormatter :
public Private::DateTextFormatter {
1072 ~WeekFormatter()
override {}
1073 QString format(
const QDateTime& dt )
override {
1074 return QString::number(dt.date().weekNumber()) + QLatin1String(
"/") + QString::number(dt.date().year());
1076 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt )
override {
1079 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, 0.0 ),
1080 QSizeF( dayWidth * 7, headerRect.height() / 2.0 ) ).toRect();
1083 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1084 Private::HeaderWeek,
new WeekFormatter );
1091 qreal offset,
QWidget* widget )
1093 class WeekFormatter :
public Private::DateTextFormatter {
1095 ~WeekFormatter()
override {}
1097 QString format(
const QDateTime& dt )
override {
1098 return QString::number( dt.date().weekNumber() );
1100 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt )
override {
1103 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, headerRect.height() / 2.0 ),
1104 QSizeF( dayWidth * 7, headerRect.height() / 2.0 ) ).toRect();
1107 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1108 Private::HeaderWeek,
new WeekFormatter );
1110 class MonthFormatter :
public Private::DateTextFormatter {
1112 ~MonthFormatter()
override {}
1114 QString format(
const QDateTime& dt )
override {
1115 return QLocale().monthName(dt.date().month(), QLocale::LongFormat) + QLatin1String(
"/") + QString::number(dt.date().year());
1117 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt )
override {
1118 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, 0.0 ),
1119 QSizeF( dayWidth * dt.date().daysInMonth(), headerRect.height() / 2.0 ) ).toRect();
1122 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1123 Private::HeaderMonth,
new MonthFormatter );
1130 qreal offset,
QWidget* widget )
1132 class MonthFormatter :
public Private::DateTextFormatter {
1134 ~MonthFormatter()
override {}
1136 QString format(
const QDateTime& dt )
override {
1137 return QLocale().monthName(dt.date().month(), QLocale::ShortFormat) + QLatin1String(
"/") + QString::number(dt.date().year());
1139 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt )
override {
1140 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, headerRect.height() / 2.0 ),
1141 QSizeF( dayWidth * dt.date().daysInMonth(), headerRect.height() / 2.0 ) ).toRect();
1144 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1145 Private::HeaderMonth,
new MonthFormatter );
1147 class YearFormatter :
public Private::DateTextFormatter {
1149 ~YearFormatter()
override {}
1151 QString format(
const QDateTime& dt )
override {
1152 return QString::number( dt.date().year() );
1154 QRect textRect( qreal x, qreal offset, qreal
dayWidth,
const QRectF& headerRect,
const QDateTime& dt )
override {
1155 return QRectF( QPointF( x, headerRect.top() ) + QPointF( -offset, 0.0 ),
1156 QSizeF( dayWidth * dt.date().daysInYear(), headerRect.height() / 2.0 ) ).toRect();
1159 d->paintHeader( painter, headerRect, exposedRect, offset, widget,
1160 Private::HeaderYear,
new YearFormatter );
1185 qreal topLeft =
d->dateTimeToChartX(from);
1186 qreal topRight =
d->dateTimeToChartX(to);
1188 return QRectF(topLeft, rect.top(), topRight - topLeft, rect.height());
1198 start =
d->chartXtoDateTime(rect.left());
1199 end =
d->chartXtoDateTime(rect.right());
1201 return qMakePair(start, end);
1209 QDate date =
d->chartXtoDateTime(rect.left()).date();
1212 int startx = rect.left();
1213 int endx = rect.right();
1221 QDate nextDate =
d->chartXtoDateTime(startx+1).date();
1222 if (date != nextDate)
1225 dayRect = dayRect.adjusted(1, 0, 0, 0);
1234 for (
int i=startx; i<endx; i+=offset)
1236 date =
d->chartXtoDateTime(i+1).date();
1238 QRectF dayRect(i, rect.top(),
dayWidth(), rect.height());
1239 dayRect = dayRect.adjusted(1, 0, 0, 0);
1252 QDate date =
d->chartXtoDateTime(rect.left()).date();
1255 int startx = rect.left();
1256 int endx = rect.right();
1264 QDate nextDate =
d->chartXtoDateTime(startx+1).date();
1265 if (date != nextDate)
1268 dayRect = dayRect.adjusted(1, 0, 0, 0);
1277 for (
int i=startx; i<endx; i+=offset)
1279 date =
d->chartXtoDateTime(i+1).date();
1281 QRectF dayRect(i, rect.top(),
dayWidth(), rect.height());
1282 dayRect = dayRect.adjusted(1, 0, 0, 0);
1292 #ifndef KDAB_NO_UNIT_TESTS 1294 #include <QStandardItemModel> 1297 static std::ostream&
operator<<( std::ostream& os,
const QDateTime& dt )
1300 os << dt.toString().toLatin1().constData();
1302 os << dt.toString().toStdString();
1308 QStandardItemModel
model( 3, 2 );
1310 QDateTime dt = QDateTime::currentDateTime();
1312 QDateTime startdt = dt.addDays( -10 );
1316 model.setData( model.index( 0, 0 ), dt.addDays( 17 ),
EndTimeRole );
1318 model.setData( model.index( 2, 0 ), dt.addDays( 18 ),
StartTimeRole );
1319 model.setData( model.index( 2, 0 ), dt.addDays( 19 ),
EndTimeRole );
1331 QDateTime s1 = model.data( model.index( 0, 0 ),
StartTimeRole ).toDateTime();
1332 QDateTime e1 = model.data( model.index( 0, 0 ),
EndTimeRole ).toDateTime();
1333 QDateTime s2 = model.data( model.index( 1, 0 ),
StartTimeRole ).toDateTime();
1334 QDateTime e2 = model.data( model.index( 1, 0 ),
EndTimeRole ).toDateTime();
1348 s.
setEnd( s.end()+100000. );
1359 QDate currentDate = QDate::currentDate();
1360 QDateTime dt( QDate(currentDate.year(), 1, 1), QTime( 0, 0, 0, 0 ) );
1361 assert( dt.isValid() );
1362 qreal result = startDateTime.date().daysTo(dt.date())*24.*60.*60.;
1363 result += startDateTime.time().msecsTo(dt.time())/1000.;
1364 result *= dayWidth/( 24.*60.*60. );
1366 int days =
static_cast<int>( result/
dayWidth );
1367 qreal secs = result*( 24.*60.*60. )/dayWidth;
1369 QDateTime result2 = dt2.addDays( days ).addSecs( static_cast<int>(secs-(days*24.*60.*60.) ) ).addMSecs( qRound( ( secs-static_cast<int>( secs ) )*1000. ) );
1377 #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
void paintGrid(QPainter *painter, const QRectF &sceneRect, const QRectF &exposedRect, AbstractRowController *rowController=0, QWidget *widget=0) override
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)
void drawForeground(QPainter *paint, const QRectF &rect) override
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 override
virtual void paintWeekScaleHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, QWidget *widget=0)
void setUserDefinedUpperScale(DateTimeScaleFormatter *upper)
void drawBackground(QPainter *paint, const QRectF &rect) override
virtual void drawDayBackground(QPainter *painter, const QRectF &rect, const QDate &date)
void paintHeader(QPainter *painter, const QRectF &headerRect, const QRectF &exposedRect, qreal offset, QWidget *widget=0) override
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)
Span mapToChart(const QModelIndex &idx) const override
DateTimeScaleFormatter * userDefinedLowerScale() const
void setFreeDaysBrush(const QBrush brush)
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
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