Logo Search packages:      
Sourcecode: qtodo version File versions  Download package

void QTodoDateEdit::fix (  )  [protected, virtual]

Attempts to fix any invalid date entries.

The rules applied are as follows:

If the year has four digits it is left unchanged. If the year has two digits, the year will be changed to four digits in the range current year - 70 to current year + 29. If the year has three digits in the range 100..999, the current millennium, i.e. 2000, will be added giving a year in the range 2100..2999. If the day or month is 0 then it will be set to 1 or the minimum valid day in the range.

Definition at line 1822 of file qtodo_datetimeedit.cpp.

References maxValue, minValue, outOfRange(), setYear(), and valueChanged().

Referenced by event(), and setFocusSection().

{
      bool changed = FALSE;
      int currentYear = QDate::currentDate().year();
      int year = d->y;
      if ( year < 100 )
      {
            int currentCentury = currentYear / 100;
            year += currentCentury * 100;
            if ( currentYear > year )
            {
                  if ( currentYear > year + 70 )
                        year += 100;
            }
            else
            {
                  if ( year >= currentYear + 30 )
                        year -= 100;
            }
            changed = TRUE;
      }
      else if ( year < 1000 )
      {
            int currentMillennium = currentYear / 10;
            year += currentMillennium * 10;
            changed = TRUE;
      }
      else if (d->d == 0)
      {
            d->d = 1;
            changed = TRUE;
      }
      else if (d->m == 0)
      {
            d->m = 1;
            changed = TRUE;
      }
      if ( outOfRange( year, d->m, d->d ) )
      {
            if ( minValue().isValid() && date() < minValue() )
            {
                  d->d =  minValue().day();
                  d->dayCache = d->d;
                  d->m = minValue().month();
                  d->y = minValue().year();
            }
            if ( date() > maxValue() )
            {
                  d->d =  maxValue().day();
                  d->dayCache = d->d;
                  d->m = maxValue().month();
                  d->y = maxValue().year();
            }
            changed = TRUE;
      }
      else if ( changed )
            setYear( year );
      if ( changed )
      {
            emit valueChanged( date() );
            d->changed = FALSE;
      }
}


Generated by  Doxygen 1.6.0   Back to index