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

Public Functions

virtual QDate applyToDate (const QDate &date) const
 
virtual Section handleKey (int key)
 
 QCalendarMonthValidator ()
 
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_month
 
int m_oldMonth
 
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 225 of file qcalendarwidget.cpp.

Constructors and Destructors

◆ QCalendarMonthValidator()

QCalendarMonthValidator::QCalendarMonthValidator ( )

Functions

◆ applyToDate()

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

Implements QCalendarDateSectionValidator.

Definition at line 295 of file qcalendarwidget.cpp.

296 {
297  int month = m_month;
298  if (month < 1)
299  month = 1;
300  else if (month > 12)
301  month = 12;
302  QDate newDate(date.year(), m_month, 1);
303  int day = date.day();
304  if (day > newDate.daysInMonth())
305  day = newDate.daysInMonth();
306  return QDate(date.year(), month, day);
307 }
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
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353

◆ handleKey()

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

Implements QCalendarDateSectionValidator.

Definition at line 246 of file qcalendarwidget.cpp.

247 {
248  if (key == Qt::Key_Right || key == Qt::Key_Left) {
249  m_pos = 0;
251  } else if (key == Qt::Key_Up) {
252  m_pos = 0;
253  ++m_month;
254  if (m_month > 12)
255  m_month = 1;
257  } else if (key == Qt::Key_Down) {
258  m_pos = 0;
259  --m_month;
260  if (m_month < 1)
261  m_month = 12;
263  } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
264  --m_pos;
265  if (m_pos < 0)
266  m_pos = 1;
267 
268  if (m_pos == 0)
270  else
271  m_month = m_month / 10;
272  //m_month = m_oldMonth / 10 * 10 + m_month / 10;
273 
274  if (m_pos == 0)
277  }
278  if (key < Qt::Key_0 || key > Qt::Key_9)
280  int pressedKey = key - Qt::Key_0;
281  if (m_pos == 0)
282  m_month = pressedKey;
283  else
284  m_month = m_month % 10 * 10 + pressedKey;
285  if (m_month > 12)
286  m_month = 12;
287  ++m_pos;
288  if (m_pos > 1) {
289  m_pos = 0;
291  }
293 }
int key

◆ setDate()

void QCalendarMonthValidator::setDate ( const QDate date)
virtual

Implements QCalendarDateSectionValidator.

Definition at line 309 of file qcalendarwidget.cpp.

310 {
311  m_month = m_oldMonth = date.month();
312  m_pos = 0;
313 }
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382

◆ text() [1/2]

QString QCalendarMonthValidator::text ( ) const
virtual

Implements QCalendarDateSectionValidator.

Definition at line 315 of file qcalendarwidget.cpp.

316 {
317  QString str;
318  if (m_month / 10 == 0)
319  str += QLatin1Char('0');
320  str += QString::number(m_month);
321  return highlightString(str, m_pos);
322 }
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 QCalendarMonthValidator::text ( const QDate date,
int  repeat 
) const
virtual

Implements QCalendarDateSectionValidator.

Definition at line 324 of file qcalendarwidget.cpp.

325 {
326  if (repeat <= 1) {
327  return QString::number(date.month());
328  } else if (repeat == 2) {
329  QString str;
330  if (date.month() / 10 == 0)
331  str += QLatin1Char('0');
332  return str + QString::number(date.month());
333  } else if (repeat == 3) {
335  } else /*if (repeat >= 4)*/ {
337  }
338 }
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 month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString standaloneMonthName(int, FormatType format=LongFormat) const
Returns the localized name of month that is used as a standalone text, in the format specified by typ...
Definition: qlocale.cpp:2056
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ m_month

int QCalendarMonthValidator::m_month
private

Definition at line 237 of file qcalendarwidget.cpp.

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

◆ m_oldMonth

int QCalendarMonthValidator::m_oldMonth
private

Definition at line 238 of file qcalendarwidget.cpp.

Referenced by handleKey(), and setDate().

◆ m_pos

int QCalendarMonthValidator::m_pos
private

Definition at line 236 of file qcalendarwidget.cpp.

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


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