KDGantt::DateTimeScaleFormatter Class Reference

#include <kdganttdatetimegrid.h>

List of all members.


Detailed Description

This class formats dates and times used in DateTimeGrid follawing a given format.

The format follows the format of QDateTime::toString(), with one addition: "w" is replaced with the week number of the date as number without a leading zero (1-53) "ww" is replaced with the week number of the date as number with a leading zero (01-53)

For example:

  // formatter to print the complete date over the current week
  // This leads to the first day of the week being printed
  DateTimeScaleFormatter formatter = DateTimeScaleFormatter( DateTimeScaleFormatter::Week, "yyyy-MM-dd" );

Optionally, you can set an user defined text alignment flag. The default value is Qt::AlignCenter.

See also:
DateTimeScaleFormatter::DateTimeScaleFormatter
This class even controls the range of the grid sections.
See also:
KDGanttDateTimeScaleFormatter::Range

Definition at line 34 of file kdganttdatetimegrid.h.


Public Types

enum  Range {
  Second,
  Minute,
  Hour,
  Day,
  Week,
  Month,
  Year
}

Public Member Functions

Qt::Alignment alignment () const
virtual QDateTime currentRangeBegin (const QDateTime &datetime) const
 DateTimeScaleFormatter (const DateTimeScaleFormatter &other)
 DateTimeScaleFormatter (Range range, const QString &formatString, const QString &templ, Qt::Alignment alignment=Qt::AlignCenter)
 DateTimeScaleFormatter (Range range, const QString &formatString, Qt::Alignment alignment=Qt::AlignCenter)
QString format (const QDateTime &datetime) const
QString format () const
virtual QDateTime nextRangeBegin (const QDateTime &datetime) const
DateTimeScaleFormatteroperator= (const DateTimeScaleFormatter &other)
Range range () const
virtual QString text (const QDateTime &datetime) const
virtual ~DateTimeScaleFormatter ()

Member Enumeration Documentation

enum KDGantt::DateTimeScaleFormatter::Range

Enumerator:
Second 
Minute 
Hour 
Day 
Week 
Month 
Year 

Definition at line 38 of file kdganttdatetimegrid.h.

00039         {
00040             Second,
00041             Minute,
00042             Hour,
00043             Day,
00044             Week,
00045             Month,
00046             Year
00047         };


Constructor & Destructor Documentation

DateTimeScaleFormatter::DateTimeScaleFormatter ( Range  range,
const QString &  formatString,
Qt::Alignment  alignment = Qt::AlignCenter 
)

Definition at line 124 of file kdganttdatetimegrid.cpp.

00125     : _d( new Private( range, format, QString::fromLatin1( "%1" ), alignment ) )
00126 {
00127 }

DateTimeScaleFormatter::DateTimeScaleFormatter ( Range  range,
const QString &  format,
const QString &  templ,
Qt::Alignment  alignment = Qt::AlignCenter 
)

Creates a DateTimeScaleFormatter using range and format. The text on the header is aligned following alignment.

Definition at line 118 of file kdganttdatetimegrid.cpp.

00120     : _d( new Private( range, format, templ, alignment ) )
00121 {
00122 }

DateTimeScaleFormatter::DateTimeScaleFormatter ( const DateTimeScaleFormatter other  ) 

Definition at line 129 of file kdganttdatetimegrid.cpp.

00130     : _d( new Private( other.range(), other.format(), other.d->templ, other.alignment() ) )
00131 {
00132 }

DateTimeScaleFormatter::~DateTimeScaleFormatter (  )  [virtual]

Definition at line 134 of file kdganttdatetimegrid.cpp.

00135 {
00136     delete _d;
00137 }


Member Function Documentation

Qt::Alignment DateTimeScaleFormatter::alignment (  )  const

Definition at line 179 of file kdganttdatetimegrid.cpp.

References d.

Referenced by operator=(), and KDGantt::DateTimeGrid::paintUserDefinedHeader().

00180 {
00181     return d->alignment;
00182 }

QDateTime DateTimeScaleFormatter::currentRangeBegin ( const QDateTime &  datetime  )  const [virtual]

Returns:
the QDateTime being the begin of the range containing datetime
See also:
nextRangeBegin

Definition at line 242 of file kdganttdatetimegrid.cpp.

References d, Day, Hour, Minute, Month, Second, Week, and Year.

Referenced by KDGantt::DateTimeGrid::paintUserDefinedHeader().

00243 {
00244     QDateTime result = datetime;
00245     switch( d->range )
00246     {
00247     case Second:
00248         break; // nothing
00249     case Minute:
00250         // set it to the begin of the current minute
00251         result.setTime( QTime( result.time().hour(), result.time().minute() ) );
00252         break;
00253     case Hour:
00254         // set it to the begin of the current hour
00255         result.setTime( QTime( result.time().hour(), 0 ) );
00256         break;
00257     case Day:
00258         // set it to midnight the current day
00259         result.setTime( QTime( 0, 0 ) );
00260         break;
00261     case Week:
00262         // set it to midnight
00263         result.setTime( QTime( 0, 0 ) );
00264         // iterate day-wise, as long weekNumber is the same
00265         {
00266             const int weekNumber = result.date().weekNumber();
00267             while( weekNumber == result.date().addDays( -1 ).weekNumber() )
00268                 result = result.addDays( -1 );
00269         }
00270         break;
00271     case Month:
00272         // set it to midnight
00273         result.setTime( QTime( 0, 0 ) );
00274         // set it to the first of the current month
00275         result.setDate( QDate( result.date().year(), result.date().month(), 1 ) );
00276         break;
00277     case Year:
00278         // set it to midnight
00279         result.setTime( QTime( 0, 0 ) );
00280         // set it to the first of the current year
00281         result.setDate( QDate( result.date().year(), 1, 1 ) );
00282         break;
00283     }
00284     return result;
00285 }

QString DateTimeScaleFormatter::format ( const QDateTime &  datetime  )  const

Returns:
The datetime as string respecting the format.

Definition at line 155 of file kdganttdatetimegrid.cpp.

References d.

00156 {
00157     QString result = d->format;
00158     // additional feature: Weeknumber
00159     const QString shortWeekNumber = QString::number( datetime.date().weekNumber() );
00160     const QString longWeekNumber = ( shortWeekNumber.length() == 1 ? QString::fromLatin1( "0" ) : QString() ) + shortWeekNumber;
00161     result.replace( QString::fromLatin1( "ww" ), longWeekNumber );
00162     result.replace( QString::fromLatin1( "w" ), shortWeekNumber );
00163     result = datetime.toLocalTime().toString( result );
00164     return result;
00165 }

QString DateTimeScaleFormatter::format (  )  const

Returns:
The format being used for formatting dates and times.

Definition at line 148 of file kdganttdatetimegrid.cpp.

References d.

Referenced by operator=(), and text().

00149 {
00150     return d->format;
00151 }

QDateTime DateTimeScaleFormatter::nextRangeBegin ( const QDateTime &  datetime  )  const [virtual]

Returns:
the QDateTime being the begin of the range after the one containing datetime
See also:
currentRangeBegin

Definition at line 187 of file kdganttdatetimegrid.cpp.

References d, Day, Hour, Minute, Month, Second, Week, and Year.

Referenced by KDGantt::DateTimeGrid::paintUserDefinedHeader().

00188 {
00189     QDateTime result = datetime;
00190     switch( d->range )
00191     {
00192     case Second:
00193         result = result.addSecs( 60 );
00194         break;
00195     case Minute:
00196         // set it to the begin of the next minute
00197         result.setTime( QTime( result.time().hour(), result.time().minute() ) );
00198         result = result.addSecs( 60 );
00199         break;
00200     case Hour:
00201         // set it to the begin of the next hour
00202         result.setTime( QTime( result.time().hour(), 0 ) );
00203         result = result.addSecs( 60 * 60 );
00204         break;
00205     case Day:
00206         // set it to midnight the next day
00207         result.setTime( QTime( 0, 0 ) );
00208         result = result.addDays( 1 );
00209         break;
00210     case Week:
00211         // set it to midnight
00212         result.setTime( QTime( 0, 0 ) );
00213         // iterate day-wise, until weekNumber changes
00214         {
00215             const int weekNumber = result.date().weekNumber();
00216             while( weekNumber == result.date().weekNumber() )
00217                 result = result.addDays( 1 );
00218         }
00219         break;
00220     case Month:
00221         // set it to midnight
00222         result.setTime( QTime( 0, 0 ) );
00223         // set it to the first of the next month
00224         result.setDate( QDate( result.date().year(), result.date().month(), 1 ).addMonths( 1 ) );
00225         break;
00226     case Year:
00227         // set it to midnight
00228         result.setTime( QTime( 0, 0 ) );
00229         // set it to the first of the next year
00230         result.setDate( QDate( result.date().year(), 1, 1 ).addYears( 1 ) );
00231         break;
00232     }
00233     //result = result.toLocalTime();
00234     assert(  result != datetime );
00235     //qDebug() << "DateTimeScaleFormatter::nextRangeBegin("<<datetime<<")="<<d->range<<result;
00236     return result;
00237 }

DateTimeScaleFormatter & DateTimeScaleFormatter::operator= ( const DateTimeScaleFormatter other  ) 

Definition at line 139 of file kdganttdatetimegrid.cpp.

References alignment(), format(), StockDiagram::Private::Private(), and range().

00140 {
00141     delete _d;
00142     _d = new Private( other.range(), other.format(), other.d->templ, other.alignment() );
00143     return *this;
00144 }

DateTimeScaleFormatter::Range DateTimeScaleFormatter::range (  )  const

Returns:
The range of each item on a DateTimeGrid header.
See also:
DateTimeScaleFormatter::Range

Definition at line 174 of file kdganttdatetimegrid.cpp.

References d.

Referenced by operator=().

00175 {
00176     return d->range;
00177 }

QString DateTimeScaleFormatter::text ( const QDateTime &  datetime  )  const [virtual]

Definition at line 167 of file kdganttdatetimegrid.cpp.

References d, and format().

Referenced by KDGantt::DateTimeGrid::paintHeader(), and KDGantt::DateTimeGrid::paintUserDefinedHeader().

00168 {
00169     return d->templ.arg( format( datetime ) );
00170 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 4 23:27:05 2010 for KD Chart 2 by  doxygen 1.5.4