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

Public Functions

virtual QDate applyToDate (const QDate &date) const
 
virtual Section handleKey (int key)
 
 QCalendarDayValidator ()
 
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 ()
 

Properties

int m_day
 
int m_oldDay
 
int m_pos
 

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 109 of file qcalendarwidget.cpp.

Constructors and Destructors

◆ QCalendarDayValidator()

QCalendarDayValidator::QCalendarDayValidator ( )

Functions

◆ applyToDate()

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

Implements QCalendarDateSectionValidator.

Definition at line 179 of file qcalendarwidget.cpp.

180 {
181  int day = m_day;
182  if (day < 1)
183  day = 1;
184  else if (day > 31)
185  day = 31;
186  if (day > date.daysInMonth())
187  day = date.daysInMonth();
188  return QDate(date.year(), date.month(), day);
189 }
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
The QDate class provides date functions.
Definition: qdatetime.h:55
int daysInMonth() const
Returns the number of days in the month (28 to 31) for this date.
Definition: qdatetime.cpp:431
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353

◆ handleKey()

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

Implements QCalendarDateSectionValidator.

Definition at line 130 of file qcalendarwidget.cpp.

131 {
132  if (key == Qt::Key_Right || key == Qt::Key_Left) {
133  m_pos = 0;
135  } else if (key == Qt::Key_Up) {
136  m_pos = 0;
137  ++m_day;
138  if (m_day > 31)
139  m_day = 1;
141  } else if (key == Qt::Key_Down) {
142  m_pos = 0;
143  --m_day;
144  if (m_day < 1)
145  m_day = 31;
147  } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
148  --m_pos;
149  if (m_pos < 0)
150  m_pos = 1;
151 
152  if (m_pos == 0)
153  m_day = m_oldDay;
154  else
155  m_day = m_day / 10;
156  //m_day = m_oldDay / 10 * 10 + m_day / 10;
157 
158  if (m_pos == 0)
161  }
162  if (key < Qt::Key_0 || key > Qt::Key_9)
164  int pressedKey = key - Qt::Key_0;
165  if (m_pos == 0)
166  m_day = pressedKey;
167  else
168  m_day = m_day % 10 * 10 + pressedKey;
169  if (m_day > 31)
170  m_day = 31;
171  ++m_pos;
172  if (m_pos > 1) {
173  m_pos = 0;
175  }
177 }
int key

◆ setDate()

void QCalendarDayValidator::setDate ( const QDate date)
virtual

Implements QCalendarDateSectionValidator.

Definition at line 191 of file qcalendarwidget.cpp.

192 {
193  m_day = m_oldDay = date.day();
194  m_pos = 0;
195 }
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395

◆ text() [1/2]

QString QCalendarDayValidator::text ( ) const
virtual

Implements QCalendarDateSectionValidator.

Definition at line 197 of file qcalendarwidget.cpp.

198 {
199  QString str;
200  if (m_day / 10 == 0)
201  str += QLatin1Char('0');
202  str += QString::number(m_day);
203  return highlightString(str, m_pos);
204 }
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 QCalendarDayValidator::text ( const QDate date,
int  repeat 
) const
virtual

Implements QCalendarDateSectionValidator.

Definition at line 206 of file qcalendarwidget.cpp.

207 {
208  if (repeat <= 1) {
209  return QString::number(date.day());
210  } else if (repeat == 2) {
211  QString str;
212  if (date.day() / 10 == 0)
213  str += QLatin1Char('0');
214  return str + QString::number(date.day());
215  } else if (repeat == 3) {
217  } else if (repeat >= 4) {
219  }
220  return QString();
221 }
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
int dayOfWeek() const
Returns the weekday (1 = Monday to 7 = Sunday) for this date.
Definition: qdatetime.cpp:408
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString dayName(int, FormatType format=LongFormat) const
Returns the localized name of the day (where 1 represents Monday, 2 represents Tuesday and so on)...
Definition: qlocale.cpp:2106
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ m_day

int QCalendarDayValidator::m_day
private

Definition at line 121 of file qcalendarwidget.cpp.

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

◆ m_oldDay

int QCalendarDayValidator::m_oldDay
private

Definition at line 122 of file qcalendarwidget.cpp.

Referenced by handleKey(), and setDate().

◆ m_pos

int QCalendarDayValidator::m_pos
private

Definition at line 120 of file qcalendarwidget.cpp.

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


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