Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QCalendarYearValidator Class Reference
Inheritance diagram for QCalendarYearValidator:
QCalendarDateSectionValidator

Public Functions

virtual QDate applyToDate (const QDate &date) const
 
virtual Section handleKey (int key)
 
 QCalendarYearValidator ()
 
virtual void setDate (const QDate &date)
 
virtual QString text () const
 
virtual QString text (const QDate &date, int repeat) const
 
- Public Functions inherited from QCalendarDateSectionValidator
 QCalendarDateSectionValidator ()
 
virtual ~QCalendarDateSectionValidator ()
 

Private Functions

int pow10 (int n)
 

Properties

int m_oldYear
 
int m_pos
 
int m_year
 

Additional Inherited Members

- Public Types inherited from QCalendarDateSectionValidator
enum  Section { NextSection, ThisSection, PrevSection }
 
- Public Variables inherited from QCalendarDateSectionValidator
QLocale m_locale
 
- Protected Functions inherited from QCalendarDateSectionValidator
QString highlightString (const QString &str, int pos) const
 

Detailed Description

Definition at line 342 of file qcalendarwidget.cpp.

Constructors and Destructors

◆ QCalendarYearValidator()

QCalendarYearValidator::QCalendarYearValidator ( )

Functions

◆ applyToDate()

QDate QCalendarYearValidator::applyToDate ( const QDate date) const
virtual

Implements QCalendarDateSectionValidator.

Definition at line 410 of file qcalendarwidget.cpp.

411 {
412  int year = m_year;
413  if (year < 1)
414  year = 1;
415  QDate newDate(year, date.month(), 1);
416  int day = date.day();
417  if (day > newDate.daysInMonth())
418  day = newDate.daysInMonth();
419  return QDate(year, date.month(), day);
420 }
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
The QDate class provides date functions.
Definition: qdatetime.h:55

◆ handleKey()

QCalendarDateSectionValidator::Section QCalendarYearValidator::handleKey ( int  key)
virtual

Implements QCalendarDateSectionValidator.

Definition at line 372 of file qcalendarwidget.cpp.

373 {
374  if (key == Qt::Key_Right || key == Qt::Key_Left) {
375  m_pos = 0;
377  } else if (key == Qt::Key_Up) {
378  m_pos = 0;
379  ++m_year;
381  } else if (key == Qt::Key_Down) {
382  m_pos = 0;
383  --m_year;
385  } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
386  --m_pos;
387  if (m_pos < 0)
388  m_pos = 3;
389 
390  int pow = pow10(m_pos);
391  m_year = m_oldYear / pow * pow + m_year % (pow * 10) / 10;
392 
393  if (m_pos == 0)
396  }
397  if (key < Qt::Key_0 || key > Qt::Key_9)
399  int pressedKey = key - Qt::Key_0;
400  int pow = pow10(m_pos);
401  m_year = m_year / (pow * 10) * (pow * 10) + m_year % pow * 10 + pressedKey;
402  ++m_pos;
403  if (m_pos > 3) {
404  m_pos = 0;
406  }
408 }
int key

◆ pow10()

int QCalendarYearValidator::pow10 ( int  n)
private

Definition at line 364 of file qcalendarwidget.cpp.

Referenced by handleKey().

365 {
366  int power = 1;
367  for (int i = 0; i < n; i++)
368  power *= 10;
369  return power;
370 }

◆ setDate()

void QCalendarYearValidator::setDate ( const QDate date)
virtual

Implements QCalendarDateSectionValidator.

Definition at line 422 of file qcalendarwidget.cpp.

423 {
424  m_year = m_oldYear = date.year();
425  m_pos = 0;
426 }
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353

◆ text() [1/2]

QString QCalendarYearValidator::text ( ) const
virtual

Implements QCalendarDateSectionValidator.

Definition at line 428 of file qcalendarwidget.cpp.

429 {
430  QString str;
431  int pow = 10;
432  for (int i = 0; i < 3; i++) {
433  if (m_year / pow == 0)
434  str += QLatin1Char('0');
435  pow *= 10;
436  }
437  str += QString::number(m_year);
438  return highlightString(str, m_pos);
439 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QString highlightString(const QString &str, int pos) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ text() [2/2]

QString QCalendarYearValidator::text ( const QDate date,
int  repeat 
) const
virtual

Implements QCalendarDateSectionValidator.

Definition at line 441 of file qcalendarwidget.cpp.

442 {
443  if (repeat < 4) {
444  QString str;
445  int year = date.year() % 100;
446  if (year / 10 == 0)
447  str = QLatin1Char('0');
448  return str + QString::number(year);
449  }
450  return QString::number(date.year());
451 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QString class provides a Unicode character string.
Definition: qstring.h:83
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ m_oldYear

int QCalendarYearValidator::m_oldYear
private

Definition at line 356 of file qcalendarwidget.cpp.

Referenced by handleKey(), and setDate().

◆ m_pos

int QCalendarYearValidator::m_pos
private

Definition at line 354 of file qcalendarwidget.cpp.

Referenced by handleKey(), setDate(), and text().

◆ m_year

int QCalendarYearValidator::m_year
private

Definition at line 355 of file qcalendarwidget.cpp.

Referenced by applyToDate(), handleKey(), setDate(), and text().


The documentation for this class was generated from the following file: