Qt 4.8
Classes | Public Functions | Private Functions | Properties | List of all members
QCalendarDateValidator Class Reference

Classes

struct  SectionToken
 

Public Functions

QDate currentDate () const
 
QString currentText () const
 
void handleKeyEvent (QKeyEvent *keyEvent)
 
 QCalendarDateValidator ()
 
void setFormat (const QString &format)
 
void setInitialDate (const QDate &date)
 
void setLocale (const QLocale &locale)
 
 ~QCalendarDateValidator ()
 

Private Functions

void applyToDate ()
 
void clear ()
 
int countRepeat (const QString &str, int index) const
 
void toNextToken ()
 
void toPreviousToken ()
 

Properties

QDate m_currentDate
 
SectionTokenm_currentToken
 
QCalendarDateSectionValidatorm_dayValidator
 
QDate m_initialDate
 
QCalendarDateSectionValidator::Section m_lastSectionMove
 
QCalendarDateSectionValidatorm_monthValidator
 
QStringList m_separators
 
QList< SectionToken * > m_tokens
 
QCalendarDateSectionValidatorm_yearValidator
 

Detailed Description

Definition at line 455 of file qcalendarwidget.cpp.

Constructors and Destructors

◆ QCalendarDateValidator()

QCalendarDateValidator::QCalendarDateValidator ( )

Definition at line 498 of file qcalendarwidget.cpp.

Referenced by QCalendarTextNavigator::createDateLabel().

500 {
505 }
SectionToken * m_currentToken
QCalendarDateSectionValidator * m_yearValidator
static QDate currentDate()
Returns the current date, as reported by the system clock.
Definition: qdatetime.cpp:3115
QCalendarDateSectionValidator * m_monthValidator
QCalendarDateSectionValidator::Section m_lastSectionMove
QCalendarDateSectionValidator * m_dayValidator

◆ ~QCalendarDateValidator()

QCalendarDateValidator::~QCalendarDateValidator ( )

Definition at line 514 of file qcalendarwidget.cpp.

515 {
516  delete m_yearValidator;
517  delete m_monthValidator;
518  delete m_dayValidator;
519  clear();
520 }
QCalendarDateSectionValidator * m_yearValidator
QCalendarDateSectionValidator * m_monthValidator
QCalendarDateSectionValidator * m_dayValidator

Functions

◆ applyToDate()

void QCalendarDateValidator::applyToDate ( )
private

Definition at line 621 of file qcalendarwidget.cpp.

Referenced by handleKeyEvent().

622 {
626 }
QCalendarDateSectionValidator * m_yearValidator
QCalendarDateSectionValidator * m_monthValidator
QCalendarDateSectionValidator * m_dayValidator
virtual QDate applyToDate(const QDate &date) const =0

◆ clear()

void QCalendarDateValidator::clear ( )
private

Definition at line 562 of file qcalendarwidget.cpp.

Referenced by setFormat(), and ~QCalendarDateValidator().

563 {
564  QListIterator<SectionToken *> it(m_tokens);
565  while (it.hasNext())
566  delete it.next();
567 
568  m_tokens.clear();
570 
571  m_currentToken = 0;
572 }
SectionToken * m_currentToken
#define it(className, varName)
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< SectionToken * > m_tokens

◆ countRepeat()

int QCalendarDateValidator::countRepeat ( const QString str,
int  index 
) const
private

Definition at line 523 of file qcalendarwidget.cpp.

Referenced by setFormat().

524 {
525  Q_ASSERT(index >= 0 && index < str.size());
526  int count = 1;
527  const QChar ch = str.at(index);
528  while (index + count < str.size() && str.at(index + count) == ch)
529  ++count;
530  return count;
531 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
quint16 index

◆ currentDate()

QDate QCalendarDateValidator::currentDate ( ) const
inline

Definition at line 463 of file qcalendarwidget.cpp.

463 { return m_currentDate; }

◆ currentText()

QString QCalendarDateValidator::currentText ( ) const

Definition at line 543 of file qcalendarwidget.cpp.

544 {
545  QString str;
547  QListIterator<SectionToken *> itTok(m_tokens);
548  while (itSep.hasNext()) {
549  str += itSep.next();
550  if (itTok.hasNext()) {
551  SectionToken *token = itTok.next();
552  QCalendarDateSectionValidator *validator = token->validator;
553  if (m_currentToken == token)
554  str += validator->text();
555  else
556  str += validator->text(m_currentDate, token->repeat);
557  }
558  }
559  return str;
560 }
SectionToken * m_currentToken
The QString class provides a Unicode character string.
Definition: qstring.h:83
QList< SectionToken * > m_tokens
virtual QString text() const =0
QListIterator< QString > QStringListIterator
Definition: qstringlist.h:61

◆ handleKeyEvent()

void QCalendarDateValidator::handleKeyEvent ( QKeyEvent keyEvent)

Definition at line 650 of file qcalendarwidget.cpp.

651 {
652  if (!m_currentToken)
653  return;
654 
655  int key = keyEvent->key();
657  if (key == Qt::Key_Back || key == Qt::Key_Backspace)
658  toPreviousToken();
659  }
660  if (key == Qt::Key_Right)
661  toNextToken();
662  else if (key == Qt::Key_Left)
663  toPreviousToken();
664 
666 
667  applyToDate();
669  toNextToken();
671  toPreviousToken();
672 }
SectionToken * m_currentToken
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
QCalendarDateSectionValidator * validator
virtual Section handleKey(int key)=0
QCalendarDateSectionValidator::Section m_lastSectionMove
int key

◆ setFormat()

void QCalendarDateValidator::setFormat ( const QString format)

Definition at line 574 of file qcalendarwidget.cpp.

575 {
576  clear();
577 
578  int pos = 0;
579  const QLatin1Char quote('\'');
580  bool quoting = false;
581  QString separator;
582  while (pos < format.size()) {
583  QString mid = format.mid(pos);
584  int offset = 1;
585 
586  if (mid.startsWith(quote)) {
587  quoting = !quoting;
588  } else {
589  const QChar nextChar = format.at(pos);
590  if (quoting) {
591  separator += nextChar;
592  } else {
593  SectionToken *token = 0;
594  if (nextChar == QLatin1Char('d')) {
595  offset = qMin(4, countRepeat(format, pos));
596  token = new SectionToken(m_dayValidator, offset);
597  } else if (nextChar == QLatin1Char('M')) {
598  offset = qMin(4, countRepeat(format, pos));
599  token = new SectionToken(m_monthValidator, offset);
600  } else if (nextChar == QLatin1Char('y')) {
601  offset = qMin(4, countRepeat(format, pos));
602  token = new SectionToken(m_yearValidator, offset);
603  } else {
604  separator += nextChar;
605  }
606  if (token) {
607  m_tokens.append(token);
608  m_separators.append(separator);
609  separator = QString();
610  if (!m_currentToken)
611  m_currentToken = token;
612 
613  }
614  }
615  }
616  pos += offset;
617  }
618  m_separators += separator;
619 }
SectionToken * m_currentToken
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
int countRepeat(const QString &str, int index) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QCalendarDateSectionValidator * m_yearValidator
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
QCalendarDateSectionValidator * m_monthValidator
QList< SectionToken * > m_tokens
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QCalendarDateSectionValidator * m_dayValidator
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ setInitialDate()

void QCalendarDateValidator::setInitialDate ( const QDate date)

Definition at line 533 of file qcalendarwidget.cpp.

534 {
535  m_yearValidator->setDate(date);
536  m_monthValidator->setDate(date);
537  m_dayValidator->setDate(date);
538  m_initialDate = date;
539  m_currentDate = date;
541 }
QCalendarDateSectionValidator * m_yearValidator
QCalendarDateSectionValidator * m_monthValidator
virtual void setDate(const QDate &date)=0
QCalendarDateSectionValidator::Section m_lastSectionMove
QCalendarDateSectionValidator * m_dayValidator

◆ setLocale()

void QCalendarDateValidator::setLocale ( const QLocale locale)

Definition at line 507 of file qcalendarwidget.cpp.

508 {
509  m_yearValidator->m_locale = locale;
510  m_monthValidator->m_locale = locale;
511  m_dayValidator->m_locale = locale;
512 }
QCalendarDateSectionValidator * m_yearValidator
QCalendarDateSectionValidator * m_monthValidator
QCalendarDateSectionValidator * m_dayValidator

◆ toNextToken()

void QCalendarDateValidator::toNextToken ( )
private

Definition at line 628 of file qcalendarwidget.cpp.

Referenced by handleKeyEvent().

629 {
630  const int idx = m_tokens.indexOf(m_currentToken);
631  if (idx == -1)
632  return;
633  if (idx + 1 >= m_tokens.count())
634  m_currentToken = m_tokens.first();
635  else
636  m_currentToken = m_tokens.at(idx + 1);
637 }
SectionToken * m_currentToken
QList< SectionToken * > m_tokens

◆ toPreviousToken()

void QCalendarDateValidator::toPreviousToken ( )
private

Definition at line 639 of file qcalendarwidget.cpp.

Referenced by handleKeyEvent().

640 {
641  const int idx = m_tokens.indexOf(m_currentToken);
642  if (idx == -1)
643  return;
644  if (idx - 1 < 0)
645  m_currentToken = m_tokens.last();
646  else
647  m_currentToken = m_tokens.at(idx - 1);
648 }
SectionToken * m_currentToken
QList< SectionToken * > m_tokens

Properties

◆ m_currentDate

QDate QCalendarDateValidator::m_currentDate
private

◆ m_currentToken

SectionToken* QCalendarDateValidator::m_currentToken
private

◆ m_dayValidator

QCalendarDateSectionValidator* QCalendarDateValidator::m_dayValidator
private

◆ m_initialDate

QDate QCalendarDateValidator::m_initialDate
private

Definition at line 492 of file qcalendarwidget.cpp.

Referenced by QCalendarDateValidator(), and setInitialDate().

◆ m_lastSectionMove

QCalendarDateSectionValidator::Section QCalendarDateValidator::m_lastSectionMove
private

Definition at line 495 of file qcalendarwidget.cpp.

Referenced by handleKeyEvent(), and setInitialDate().

◆ m_monthValidator

QCalendarDateSectionValidator* QCalendarDateValidator::m_monthValidator
private

◆ m_separators

QStringList QCalendarDateValidator::m_separators
private

Definition at line 484 of file qcalendarwidget.cpp.

Referenced by clear(), currentText(), and setFormat().

◆ m_tokens

QList<SectionToken *> QCalendarDateValidator::m_tokens
private

Definition at line 485 of file qcalendarwidget.cpp.

Referenced by clear(), currentText(), setFormat(), toNextToken(), and toPreviousToken().

◆ m_yearValidator

QCalendarDateSectionValidator* QCalendarDateValidator::m_yearValidator
private

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