Qt 4.8
Classes | Public Types | Public Functions | Public Variables | List of all members
QDateTimeParser Class Reference

#include <qdatetime_p.h>

Inheritance diagram for QDateTimeParser:
QDateTimeEditPrivate

Classes

struct  SectionNode
 
struct  StateNode
 

Public Types

enum  {
  Neither = -1, AM = 0, PM = 1, PossibleAM = 2,
  PossiblePM = 3, PossibleBoth = 4
}
 
enum  AmPm { AmText, PmText }
 
enum  Case { UpperCase, LowerCase }
 
enum  Context { FromString, DateTimeEdit }
 
enum  FieldInfoFlag { Numeric = 0x01, FixedWidth = 0x02, AllowPartial = 0x04, Fraction = 0x08 }
 
enum  Section {
  NoSection = 0x00000, AmPmSection = 0x00001, MSecSection = 0x00002, SecondSection = 0x00004,
  MinuteSection = 0x00008, Hour12Section = 0x00010, Hour24Section = 0x00020, TimeSectionMask = (AmPmSection|MSecSection|SecondSection|MinuteSection|Hour12Section|Hour24Section),
  Internal = 0x10000, DaySection = 0x00100, MonthSection = 0x00200, YearSection = 0x00400,
  YearSection2Digits = 0x00800, DayOfWeekSection = 0x01000, DateSectionMask = (DaySection|MonthSection|YearSection|YearSection2Digits|DayOfWeekSection), FirstSection = 0x02000|Internal,
  LastSection = 0x04000|Internal, CalendarPopupSection = 0x08000|Internal, NoSectionIndex = -1, FirstSectionIndex = -2,
  LastSectionIndex = -3, CalendarPopupIndex = -4
}
 
enum  State { Invalid, Intermediate, Acceptable }
 

Public Functions

int absoluteMax (int index, const QDateTime &value=QDateTime()) const
 \ More...
 
int absoluteMin (int index) const
 
virtual int cursorPosition () const
 
virtual QString displayText () const
 
FieldInfo fieldInfo (int index) const
 
int findAmPm (QString &str1, int index, int *used=0) const
 
int findDay (const QString &str1, int intDaystart, int sectionIndex, QString *dayName=0, int *used=0) const
 
int findMonth (const QString &str1, int monthstart, int sectionIndex, QString *monthName=0, int *used=0) const
 
bool fromString (const QString &text, QDate *date, QTime *time) const
 
virtual QString getAmPmText (AmPm ap, Case cs) const
 
int getDigit (const QDateTime &dt, int index) const
 Gets the digit from a datetime. More...
 
virtual QDateTime getMaximum () const
 
virtual QDateTime getMinimum () const
 
virtual QLocale locale () const
 
int maxChange (int s) const
 Max number of units that can be changed by this section. More...
 
StateNode parse (QString &input, int &cursorPosition, const QDateTime &currentValue, bool fixup) const
 
bool parseFormat (const QString &format)
 
int parseSection (const QDateTime &currentValue, int sectionIndex, QString &txt, int &cursorPosition, int index, QDateTimeParser::State &state, int *used=0) const
 
bool potentialValue (const QString &str, int min, int max, int index, const QDateTime &currentValue, int insert) const
 
 QDateTimeParser (QVariant::Type t, Context ctx)
 
QString sectionFormat (int index) const
 
QString sectionFormat (Section s, int count) const
 
int sectionMaxSize (int index) const
 
int sectionMaxSize (Section s, int count) const
 
QString sectionName (int s) const
 For debugging. More...
 
const SectionNodesectionNode (int index) const
 Returns the sectionNode for the Section s. More...
 
int sectionPos (int index) const
 Returns the starting position for section s. More...
 
int sectionPos (const SectionNode &sn) const
 
int sectionSize (int index) const
 Returns the size of section s. More...
 
QString sectionText (int sectionIndex) const
 
QString sectionText (const QString &text, int sectionIndex, int index) const
 Returns the text of section s. More...
 
Section sectionType (int index) const
 
bool setDigit (QDateTime &t, int index, int newval) const
 Sets a digit in a datetime. More...
 
bool skipToNextSection (int section, const QDateTime &current, const QString &sectionText) const
 
QString stateName (int s) const
 For debugging. More...
 
virtual ~QDateTimeParser ()
 

Public Variables

int cachedDay
 
Context context
 
int currentSectionIndex
 
QLocale defaultLocale
 
Sections display
 
QString displayFormat
 
SectionNode first
 
bool fixday
 
SectionNode last
 
SectionNode none
 
QVariant::Type parserType
 
SectionNode popup
 
QVector< SectionNodesectionNodes
 
QStringList separators
 
Qt::TimeSpec spec
 
QString text
 

Detailed Description

Definition at line 112 of file qdatetime_p.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
Neither 
AM 
PM 
PossibleAM 
PossiblePM 
PossibleBoth 

Definition at line 135 of file qdatetime_p.h.

◆ AmPm

Enumerator
AmText 
PmText 

Definition at line 191 of file qdatetime_p.h.

◆ Case

Enumerator
UpperCase 
LowerCase 

Definition at line 196 of file qdatetime_p.h.

◆ Context

Enumerator
FromString 
DateTimeEdit 

Definition at line 115 of file qdatetime_p.h.

◆ FieldInfoFlag

Enumerator
Numeric 
FixedWidth 
AllowPartial 
Fraction 

Definition at line 242 of file qdatetime_p.h.

◆ Section

Enumerator
NoSection 
AmPmSection 
MSecSection 
SecondSection 
MinuteSection 
Hour12Section 
Hour24Section 
TimeSectionMask 
Internal 
DaySection 
MonthSection 
YearSection 
YearSection2Digits 
DayOfWeekSection 
DateSectionMask 
FirstSection 
LastSection 
CalendarPopupSection 
NoSectionIndex 
FirstSectionIndex 
LastSectionIndex 
CalendarPopupIndex 

Definition at line 144 of file qdatetime_p.h.

144  {
145  NoSection = 0x00000,
146  AmPmSection = 0x00001,
147  MSecSection = 0x00002,
148  SecondSection = 0x00004,
149  MinuteSection = 0x00008,
150  Hour12Section = 0x00010,
151  Hour24Section = 0x00020,
153  Internal = 0x10000,
154  DaySection = 0x00100,
155  MonthSection = 0x00200,
156  YearSection = 0x00400,
157  YearSection2Digits = 0x00800,
158  DayOfWeekSection = 0x01000,
160  FirstSection = 0x02000|Internal,
161  LastSection = 0x04000|Internal,
162  CalendarPopupSection = 0x08000|Internal,
163 
164  NoSectionIndex = -1,
165  FirstSectionIndex = -2,
166  LastSectionIndex = -3,
167  CalendarPopupIndex = -4
168  }; // duplicated from qdatetimeedit.h

◆ State

Enumerator
Invalid 
Intermediate 
Acceptable 

Definition at line 177 of file qdatetime_p.h.

177  { // duplicated from QValidator
178  Invalid,
179  Intermediate,
180  Acceptable
181  };

Constructors and Destructors

◆ QDateTimeParser()

QDateTimeParser::QDateTimeParser ( QVariant::Type  t,
Context  ctx 
)
inline

Definition at line 119 of file qdatetime_p.h.

120  : currentSectionIndex(-1), display(0), cachedDay(-1), parserType(t),
121  fixday(false), spec(Qt::LocalTime), context(ctx)
122  {
125  first.pos = -1;
126  first.count = -1;
128  last.pos = -1;
129  last.count = -1;
130  none.type = NoSection;
131  none.pos = -1;
132  none.count = -1;
133  }
SectionNode first
Definition: qdatetime_p.h:264
SectionNode last
Definition: qdatetime_p.h:264
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition: qlocale.cpp:1917
QVariant::Type parserType
Definition: qdatetime_p.h:268
Qt::TimeSpec spec
Definition: qdatetime_p.h:272
Sections display
Definition: qdatetime_p.h:260
#define ctx
Definition: qgl.cpp:6094
SectionNode none
Definition: qdatetime_p.h:264
QLocale defaultLocale
Definition: qdatetime_p.h:267

◆ ~QDateTimeParser()

virtual QDateTimeParser::~QDateTimeParser ( )
inlinevirtual

Definition at line 134 of file qdatetime_p.h.

134 {}

Functions

◆ absoluteMax()

int QDateTimeParser::absoluteMax ( int  s,
const QDateTime cur = QDateTime() 
) const

\

Returns the absolute maximum for a section

Definition at line 4590 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::stepBy().

4591 {
4592  const SectionNode &sn = sectionNode(s);
4593  switch (sn.type) {
4594  case Hour24Section:
4595  case Hour12Section: return 23; // this is special-cased in
4596  // parseSection. We want it to be
4597  // 23 for the stepBy case.
4598  case MinuteSection:
4599  case SecondSection: return 59;
4600  case MSecSection: return 999;
4601  case YearSection2Digits:
4602  case YearSection: return 9999; // sectionMaxSize will prevent
4603  // people from typing in a larger
4604  // number in count == 2 sections.
4605  // stepBy() will work on real years anyway
4606  case MonthSection: return 12;
4607  case DaySection:
4608  case DayOfWeekSection: return cur.isValid() ? cur.date().daysInMonth() : 31;
4609  case AmPmSection: return 1;
4610  default: break;
4611  }
4612  qWarning("QDateTimeParser::absoluteMax() Internal error (%s)",
4613  qPrintable(sectionName(sn.type)));
4614  return -1;
4615 }
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
int daysInMonth() const
Returns the number of days in the month (28 to 31) for this date.
Definition: qdatetime.cpp:431
#define qPrintable(string)
Definition: qglobal.h:1750

◆ absoluteMin()

int QDateTimeParser::absoluteMin ( int  s) const
Warning
This function is not part of the public interface.

Returns the absolute minimum for a section

Definition at line 4623 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::stepBy().

4624 {
4625  const SectionNode &sn = sectionNode(s);
4626  switch (sn.type) {
4627  case Hour24Section:
4628  case Hour12Section:
4629  case MinuteSection:
4630  case SecondSection:
4631  case MSecSection:
4632  case YearSection2Digits:
4633  case YearSection: return 0;
4634  case MonthSection:
4635  case DaySection:
4636  case DayOfWeekSection: return 1;
4637  case AmPmSection: return 0;
4638  default: break;
4639  }
4640  qWarning("QDateTimeParser::absoluteMin() Internal error (%s, %0x)",
4641  qPrintable(sectionName(sn.type)), sn.type);
4642  return -1;
4643 }
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
#define qPrintable(string)
Definition: qglobal.h:1750

◆ cursorPosition()

virtual int QDateTimeParser::cursorPosition ( ) const
inlinevirtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 254 of file qdatetime_p.h.

254 { return -1; }

◆ displayText()

virtual QString QDateTimeParser::displayText ( ) const
inlinevirtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 255 of file qdatetime_p.h.

255 { return text; }

◆ fieldInfo()

QDateTimeParser::FieldInfo QDateTimeParser::fieldInfo ( int  index) const

Definition at line 5868 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::interpret(), and QDateTimeEditPrivate::isSeparatorKey().

5869 {
5870  FieldInfo ret = 0;
5871  const SectionNode &sn = sectionNode(index);
5872  const Section s = sn.type;
5873  switch (s) {
5874  case MSecSection:
5875  ret |= Fraction;
5876  // fallthrough
5877  case SecondSection:
5878  case MinuteSection:
5879  case Hour24Section:
5880  case Hour12Section:
5881  case YearSection:
5882  case YearSection2Digits:
5883  ret |= Numeric;
5884  if (s != YearSection) {
5885  ret |= AllowPartial;
5886  }
5887  if (sn.count != 1) {
5888  ret |= FixedWidth;
5889  }
5890  break;
5891  case MonthSection:
5892  case DaySection:
5893  switch (sn.count) {
5894  case 2:
5895  ret |= FixedWidth;
5896  // fallthrough
5897  case 1:
5898  ret |= (Numeric|AllowPartial);
5899  break;
5900  }
5901  break;
5902  case DayOfWeekSection:
5903  if (sn.count == 3)
5904  ret |= FixedWidth;
5905  break;
5906  case AmPmSection:
5907  ret |= FixedWidth;
5908  break;
5909  default:
5910  qWarning("QDateTimeParser::fieldInfo Internal error 2 (%d %s %d)",
5911  index, qPrintable(sectionName(sn.type)), sn.count);
5912  break;
5913  }
5914  return ret;
5915 }
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
quint16 index
#define qPrintable(string)
Definition: qglobal.h:1750

◆ findAmPm()

int QDateTimeParser::findAmPm ( QString str,
int  index,
int *  used = 0 
) const
Warning
This function is not part of the public interface.

returns 0 if str == QDateTimeEdit::tr("AM") 1 if str == QDateTimeEdit::tr("PM") 2 if str can become QDateTimeEdit::tr("AM") 3 if str can become QDateTimeEdit::tr("PM") 4 if str can become QDateTimeEdit::tr("PM") and can become QDateTimeEdit::tr("AM") -1 can't become anything sensible

Definition at line 5759 of file qdatetime.cpp.

5760 {
5761  const SectionNode &s = sectionNode(index);
5762  if (s.type != AmPmSection) {
5763  qWarning("QDateTimeParser::findAmPm Internal error");
5764  return -1;
5765  }
5766  if (used)
5767  *used = str.size();
5768  if (str.trimmed().isEmpty()) {
5769  return PossibleBoth;
5770  }
5771  const QLatin1Char space(' ');
5772  int size = sectionMaxSize(index);
5773 
5774  enum {
5775  amindex = 0,
5776  pmindex = 1
5777  };
5778  QString ampm[2];
5779  ampm[amindex] = getAmPmText(AmText, s.count == 1 ? UpperCase : LowerCase);
5780  ampm[pmindex] = getAmPmText(PmText, s.count == 1 ? UpperCase : LowerCase);
5781  for (int i=0; i<2; ++i)
5782  ampm[i].truncate(size);
5783 
5784  QDTPDEBUG << "findAmPm" << str << ampm[0] << ampm[1];
5785 
5786  if (str.indexOf(ampm[amindex], 0, Qt::CaseInsensitive) == 0) {
5787  str = ampm[amindex];
5788  return AM;
5789  } else if (str.indexOf(ampm[pmindex], 0, Qt::CaseInsensitive) == 0) {
5790  str = ampm[pmindex];
5791  return PM;
5792  } else if (context == FromString || (str.count(space) == 0 && str.size() >= size)) {
5793  return Neither;
5794  }
5795  size = qMin(size, str.size());
5796 
5797  bool broken[2] = {false, false};
5798  for (int i=0; i<size; ++i) {
5799  if (str.at(i) != space) {
5800  for (int j=0; j<2; ++j) {
5801  if (!broken[j]) {
5802  int index = ampm[j].indexOf(str.at(i));
5803  QDTPDEBUG << "looking for" << str.at(i)
5804  << "in" << ampm[j] << "and got" << index;
5805  if (index == -1) {
5806  if (str.at(i).category() == QChar::Letter_Uppercase) {
5807  index = ampm[j].indexOf(str.at(i).toLower());
5808  QDTPDEBUG << "trying with" << str.at(i).toLower()
5809  << "in" << ampm[j] << "and got" << index;
5810  } else if (str.at(i).category() == QChar::Letter_Lowercase) {
5811  index = ampm[j].indexOf(str.at(i).toUpper());
5812  QDTPDEBUG << "trying with" << str.at(i).toUpper()
5813  << "in" << ampm[j] << "and got" << index;
5814  }
5815  if (index == -1) {
5816  broken[j] = true;
5817  if (broken[amindex] && broken[pmindex]) {
5818  QDTPDEBUG << str << "didn't make it";
5819  return Neither;
5820  }
5821  continue;
5822  } else {
5823  str[i] = ampm[j].at(index); // fix case
5824  }
5825  }
5826  ampm[j].remove(index, 1);
5827  }
5828  }
5829  }
5830  }
5831  if (!broken[pmindex] && !broken[amindex])
5832  return PossibleBoth;
5833  return (!broken[amindex] ? PossibleAM : PossiblePM);
5834 }
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
virtual QString getAmPmText(AmPm ap, Case cs) const
Definition: qdatetime.cpp:6122
int sectionMaxSize(int index) const
Definition: qdatetime.cpp:5033
The QString class provides a Unicode character string.
Definition: qstring.h:83
Category category() const
Returns the character&#39;s category.
Definition: qchar.cpp:853
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1287
int count() const
Definition: qstring.h:103
#define QDTPDEBUG
Definition: qdatetime.cpp:68
quint16 index
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1239
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ findDay()

int QDateTimeParser::findDay ( const QString str1,
int  intDaystart,
int  sectionIndex,
QString dayName = 0,
int *  used = 0 
) const

Definition at line 5688 of file qdatetime.cpp.

5689 {
5690  int bestMatch = -1;
5691  int bestCount = 0;
5692  if (!str1.isEmpty()) {
5693  const SectionNode &sn = sectionNode(sectionIndex);
5694  if (!(sn.type & (DaySection|DayOfWeekSection))) {
5695  qWarning("QDateTimeParser::findDay Internal error");
5696  return -1;
5697  }
5698  const QLocale l = locale();
5699  for (int day=startDay; day<=7; ++day) {
5700  const QString str2 = l.dayName(day, sn.count == 4 ? QLocale::LongFormat : QLocale::ShortFormat);
5701 
5702  if (str1.startsWith(str2.toLower())) {
5703  if (used)
5704  *used = str2.size();
5705  if (usedDay) {
5706  *usedDay = str2;
5707  }
5708  return day;
5709  }
5710  if (context == FromString)
5711  continue;
5712 
5713  const int limit = qMin(str1.size(), str2.size());
5714  bool found = true;
5715  for (int i=0; i<limit; ++i) {
5716  if (str1.at(i) != str2.at(i) && !str1.at(i).isSpace()) {
5717  if (i > bestCount) {
5718  bestCount = i;
5719  bestMatch = day;
5720  }
5721  found = false;
5722  break;
5723  }
5724 
5725  }
5726  if (found) {
5727  if (used)
5728  *used = limit;
5729  if (usedDay)
5730  *usedDay = str2;
5731 
5732  return day;
5733  }
5734  }
5735  if (usedDay && bestMatch != -1) {
5736  *usedDay = l.dayName(bestMatch, sn.count == 4 ? QLocale::LongFormat : QLocale::ShortFormat);
5737  }
5738  }
5739  if (used)
5740  *used = bestCount;
5741 
5742  return bestMatch;
5743 }
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
virtual QLocale locale() const
Definition: qdatetime_p.h:257
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QFactoryLoader * l
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

◆ findMonth()

int QDateTimeParser::findMonth ( const QString str1,
int  startMonth,
int  sectionIndex,
QString usedMonth = 0,
int *  used = 0 
) const
Warning
This function is not part of the public interface. finds the first possible monthname that str1 can match. Starting from index; str should already by lowered

Definition at line 5625 of file qdatetime.cpp.

5627 {
5628  int bestMatch = -1;
5629  int bestCount = 0;
5630  if (!str1.isEmpty()) {
5631  const SectionNode &sn = sectionNode(sectionIndex);
5632  if (sn.type != MonthSection) {
5633  qWarning("QDateTimeParser::findMonth Internal error");
5634  return -1;
5635  }
5636 
5638  QLocale l = locale();
5639 
5640  for (int month=startMonth; month<=12; ++month) {
5641  QString str2 = l.monthName(month, type).toLower();
5642 
5643  if (str1.startsWith(str2)) {
5644  if (used) {
5645  QDTPDEBUG << "used is set to" << str2.size();
5646  *used = str2.size();
5647  }
5648  if (usedMonth)
5649  *usedMonth = l.monthName(month, type);
5650 
5651  return month;
5652  }
5653  if (context == FromString)
5654  continue;
5655 
5656  const int limit = qMin(str1.size(), str2.size());
5657 
5658  QDTPDEBUG << "limit is" << limit << str1 << str2;
5659  bool equal = true;
5660  for (int i=0; i<limit; ++i) {
5661  if (str1.at(i) != str2.at(i)) {
5662  equal = false;
5663  if (i > bestCount) {
5664  bestCount = i;
5665  bestMatch = month;
5666  }
5667  break;
5668  }
5669  }
5670  if (equal) {
5671  if (used)
5672  *used = limit;
5673  if (usedMonth)
5674  *usedMonth = l.monthName(month, type);
5675  return month;
5676  }
5677  }
5678  if (usedMonth && bestMatch != -1)
5679  *usedMonth = l.monthName(bestMatch, type);
5680  }
5681  if (used) {
5682  QDTPDEBUG << "used is set to" << bestCount;
5683  *used = bestCount;
5684  }
5685  return bestMatch;
5686 }
int type
Definition: qmetatype.cpp:239
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
virtual QLocale locale() const
Definition: qdatetime_p.h:257
QString monthName(int, FormatType format=LongFormat) const
Returns the localized name of month, in the format specified by type.
Definition: qlocale.cpp:2007
FormatType
Definition: qlocale.h:659
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
#define QDTPDEBUG
Definition: qdatetime.cpp:68
QFactoryLoader * l
static bool equal(const QChar *a, int l, const char *b)
Definition: qurl.cpp:3270

◆ fromString()

bool QDateTimeParser::fromString ( const QString text,
QDate date,
QTime time 
) const

Definition at line 6084 of file qdatetime.cpp.

Referenced by QDate::fromString(), QTime::fromString(), QDateTime::fromString(), QLocale::toDate(), QLocale::toDateTime(), and QLocale::toTime().

6085 {
6086  QDateTime val(QDate(1900, 1, 1), QDATETIMEEDIT_TIME_MIN);
6087  QString text = t;
6088  int copy = -1;
6089  const StateNode tmp = parse(text, copy, val, false);
6090  if (tmp.state != Acceptable || tmp.conflicts) {
6091  return false;
6092  }
6093  if (time) {
6094  const QTime t = tmp.value.time();
6095  if (!t.isValid()) {
6096  return false;
6097  }
6098  *time = t;
6099  }
6100 
6101  if (date) {
6102  const QDate d = tmp.value.date();
6103  if (!d.isValid()) {
6104  return false;
6105  }
6106  *date = d;
6107  }
6108  return true;
6109 }
double d
Definition: qnumeric_p.h:62
StateNode parse(QString &input, int &cursorPosition, const QDateTime &currentValue, bool fixup) const
Definition: qdatetime.cpp:5271
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
The QDate class provides date functions.
Definition: qdatetime.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define QDATETIMEEDIT_TIME_MIN
Definition: qdatetime_p.h:67
The QTime class provides clock time functions.
Definition: qdatetime.h:148
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
bool isValid() const
Returns true if the time is valid; otherwise returns false.
Definition: qdatetime.cpp:1566

◆ getAmPmText()

QString QDateTimeParser::getAmPmText ( AmPm  ap,
Case  cs 
) const
virtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 6122 of file qdatetime.cpp.

6123 {
6124  if (ap == AmText) {
6125  return (cs == UpperCase ? QLatin1String("AM") : QLatin1String("am"));
6126  } else {
6127  return (cs == UpperCase ? QLatin1String("PM") : QLatin1String("pm"));
6128  }
6129 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ getDigit()

int QDateTimeParser::getDigit ( const QDateTime t,
int  index 
) const

Gets the digit from a datetime.

Warning
This function is not part of the public interface. E.g.

QDateTime var(QDate(2004, 02, 02)); int digit = getDigit(var, Year); digit = 2004

Definition at line 4469 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::stepBy().

4470 {
4471  if (index < 0 || index >= sectionNodes.size()) {
4472 #ifndef QT_NO_DATESTRING
4473  qWarning("QDateTimeParser::getDigit() Internal error (%s %d)",
4474  qPrintable(t.toString()), index);
4475 #else
4476  qWarning("QDateTimeParser::getDigit() Internal error (%d)", index);
4477 #endif
4478  return -1;
4479  }
4480  const SectionNode &node = sectionNodes.at(index);
4481  switch (node.type) {
4482  case Hour24Section: case Hour12Section: return t.time().hour();
4483  case MinuteSection: return t.time().minute();
4484  case SecondSection: return t.time().second();
4485  case MSecSection: return t.time().msec();
4486  case YearSection2Digits:
4487  case YearSection: return t.date().year();
4488  case MonthSection: return t.date().month();
4489  case DaySection: return t.date().day();
4490  case DayOfWeekSection: return t.date().day();
4491  case AmPmSection: return t.time().hour() > 11 ? 1 : 0;
4492 
4493  default: break;
4494  }
4495 
4496 #ifndef QT_NO_DATESTRING
4497  qWarning("QDateTimeParser::getDigit() Internal error 2 (%s %d)",
4498  qPrintable(t.toString()), index);
4499 #else
4500  qWarning("QDateTimeParser::getDigit() Internal error 2 (%d)", index);
4501 #endif
4502  return -1;
4503 }
QVector< SectionNode > sectionNodes
Definition: qdatetime_p.h:263
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
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
Q_CORE_EXPORT void qWarning(const char *,...)
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
quint16 index
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
#define qPrintable(string)
Definition: qglobal.h:1750
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578

◆ getMaximum()

QDateTime QDateTimeParser::getMaximum ( ) const
virtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 6117 of file qdatetime.cpp.

6118 {
6120 }
#define QDATETIMEEDIT_DATE_MAX
Definition: qdatetime_p.h:71
#define QDATETIMEEDIT_TIME_MAX
Definition: qdatetime_p.h:68
Qt::TimeSpec spec
Definition: qdatetime_p.h:272
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216

◆ getMinimum()

QDateTime QDateTimeParser::getMinimum ( ) const
virtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 6112 of file qdatetime.cpp.

6113 {
6115 }
#define QDATETIMEEDIT_TIME_MIN
Definition: qdatetime_p.h:67
#define QDATETIMEEDIT_DATE_MIN
Definition: qdatetime_p.h:69
Qt::TimeSpec spec
Definition: qdatetime_p.h:272
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216

◆ locale()

virtual QLocale QDateTimeParser::locale ( ) const
inlinevirtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 257 of file qdatetime_p.h.

257 { return defaultLocale; }
QLocale defaultLocale
Definition: qdatetime_p.h:267

◆ maxChange()

int QDateTimeParser::maxChange ( int  index) const

Max number of units that can be changed by this section.

Warning
This function is not part of the public interface.

Definition at line 5844 of file qdatetime.cpp.

Referenced by parse().

5845 {
5846  const SectionNode &sn = sectionNode(index);
5847  switch (sn.type) {
5848  // Time. unit is msec
5849  case MSecSection: return 999;
5850  case SecondSection: return 59 * 1000;
5851  case MinuteSection: return 59 * 60 * 1000;
5852  case Hour24Section: case Hour12Section: return 59 * 60 * 60 * 1000;
5853 
5854  // Date. unit is day
5855  case DayOfWeekSection: return 7;
5856  case DaySection: return 30;
5857  case MonthSection: return 365 - 31;
5858  case YearSection: return 9999 * 365;
5859  case YearSection2Digits: return 100 * 365;
5860  default:
5861  qWarning("QDateTimeParser::maxChange() Internal error (%s)",
5863  }
5864 
5865  return -1;
5866 }
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
Section sectionType(int index) const
Definition: qdatetime.cpp:4674
quint16 index
#define qPrintable(string)
Definition: qglobal.h:1750

◆ parse()

QDateTimeParser::StateNode QDateTimeParser::parse ( QString input,
int &  cursorPosition,
const QDateTime currentValue,
bool  fixup 
) const
Warning
This function is not part of the public interface.

Definition at line 5271 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::validateAndInterpret().

5273 {
5274  const QDateTime minimum = getMinimum();
5275  const QDateTime maximum = getMaximum();
5276 
5277  State state = Acceptable;
5278 
5279  QDateTime newCurrentValue;
5280  int pos = 0;
5281  bool conflicts = false;
5282  const int sectionNodesCount = sectionNodes.size();
5283 
5284  QDTPDEBUG << "parse" << input;
5285  {
5286  int year, month, day, hour12, hour, minute, second, msec, ampm, dayofweek, year2digits;
5287  getDateFromJulianDay(currentValue.date().toJulianDay(), &year, &month, &day);
5288  year2digits = year % 100;
5289  hour = currentValue.time().hour();
5290  hour12 = -1;
5291  minute = currentValue.time().minute();
5292  second = currentValue.time().second();
5293  msec = currentValue.time().msec();
5294  dayofweek = currentValue.date().dayOfWeek();
5295 
5296  ampm = -1;
5297  Sections isSet = NoSection;
5298  int num;
5299  State tmpstate;
5300 
5301  for (int index=0; state != Invalid && index<sectionNodesCount; ++index) {
5302  if (QStringRef(&input, pos, separators.at(index).size()) != separators.at(index)) {
5303  QDTPDEBUG << "invalid because" << input.mid(pos, separators.at(index).size())
5304  << "!=" << separators.at(index)
5305  << index << pos << currentSectionIndex;
5306  state = Invalid;
5307  goto end;
5308  }
5309  pos += separators.at(index).size();
5310  sectionNodes[index].pos = pos;
5311  int *current = 0;
5312  const SectionNode sn = sectionNodes.at(index);
5313  int used;
5314 
5315  num = parseSection(currentValue, index, input, cursorPosition, pos, tmpstate, &used);
5316  QDTPDEBUG << "sectionValue" << sectionName(sectionType(index)) << input
5317  << "pos" << pos << "used" << used << stateName(tmpstate);
5318  if (fixup && tmpstate == Intermediate && used < sn.count) {
5319  const FieldInfo fi = fieldInfo(index);
5320  if ((fi & (Numeric|FixedWidth)) == (Numeric|FixedWidth)) {
5321  const QString newText = QString::fromLatin1("%1").arg(num, sn.count, 10, QLatin1Char('0'));
5322  input.replace(pos, used, newText);
5323  used = sn.count;
5324  }
5325  }
5326  pos += qMax(0, used);
5327 
5328  state = qMin<State>(state, tmpstate);
5329  if (state == Intermediate && context == FromString) {
5330  state = Invalid;
5331  break;
5332  }
5333 
5334  QDTPDEBUG << index << sectionName(sectionType(index)) << "is set to"
5335  << pos << "state is" << stateName(state);
5336 
5337 
5338  if (state != Invalid) {
5339  switch (sn.type) {
5340  case Hour24Section: current = &hour; break;
5341  case Hour12Section: current = &hour12; break;
5342  case MinuteSection: current = &minute; break;
5343  case SecondSection: current = &second; break;
5344  case MSecSection: current = &msec; break;
5345  case YearSection: current = &year; break;
5346  case YearSection2Digits: current = &year2digits; break;
5347  case MonthSection: current = &month; break;
5348  case DayOfWeekSection: current = &dayofweek; break;
5349  case DaySection: current = &day; num = qMax<int>(1, num); break;
5350  case AmPmSection: current = &ampm; break;
5351  default:
5352  qWarning("QDateTimeParser::parse Internal error (%s)",
5353  qPrintable(sectionName(sn.type)));
5354  break;
5355  }
5356  if (!current) {
5357  qWarning("QDateTimeParser::parse Internal error 2");
5358  return StateNode();
5359  }
5360  if (isSet & sn.type && *current != num) {
5361  QDTPDEBUG << "CONFLICT " << sectionName(sn.type) << *current << num;
5362  conflicts = true;
5363  if (index != currentSectionIndex || num == -1) {
5364  continue;
5365  }
5366  }
5367  if (num != -1)
5368  *current = num;
5369  isSet |= sn.type;
5370  }
5371  }
5372 
5373  if (state != Invalid && QStringRef(&input, pos, input.size() - pos) != separators.last()) {
5374  QDTPDEBUG << "invalid because" << input.mid(pos)
5375  << "!=" << separators.last() << pos;
5376  state = Invalid;
5377  }
5378 
5379  if (state != Invalid) {
5380  if (parserType != QVariant::Time) {
5381  if (year % 100 != year2digits) {
5382  switch (isSet & (YearSection2Digits|YearSection)) {
5383  case YearSection2Digits:
5384  year = (year / 100) * 100;
5385  year += year2digits;
5386  break;
5388  conflicts = true;
5389  const SectionNode &sn = sectionNode(currentSectionIndex);
5390  if (sn.type == YearSection2Digits) {
5391  year = (year / 100) * 100;
5392  year += year2digits;
5393  }
5394  break; }
5395  default:
5396  break;
5397  }
5398  }
5399 
5400  const QDate date(year, month, day);
5401  const int diff = dayofweek - date.dayOfWeek();
5402  if (diff != 0 && state == Acceptable && isSet & DayOfWeekSection) {
5403  conflicts = isSet & DaySection;
5404  const SectionNode &sn = sectionNode(currentSectionIndex);
5405  if (sn.type == DayOfWeekSection || currentSectionIndex == -1) {
5406  // dayofweek should be preferred
5407  day += diff;
5408  if (day <= 0) {
5409  day += 7;
5410  } else if (day > date.daysInMonth()) {
5411  day -= 7;
5412  }
5413  QDTPDEBUG << year << month << day << dayofweek
5414  << diff << QDate(year, month, day).dayOfWeek();
5415  }
5416  }
5417  bool needfixday = false;
5418  if (sectionType(currentSectionIndex) & (DaySection|DayOfWeekSection)) {
5419  cachedDay = day;
5420  } else if (cachedDay > day) {
5421  day = cachedDay;
5422  needfixday = true;
5423  }
5424 
5425  if (!QDate::isValid(year, month, day)) {
5426  if (day < 32) {
5427  cachedDay = day;
5428  }
5429  if (day > 28 && QDate::isValid(year, month, 1)) {
5430  needfixday = true;
5431  }
5432  }
5433  if (needfixday) {
5434  if (context == FromString) {
5435  state = Invalid;
5436  goto end;
5437  }
5438  if (state == Acceptable && fixday) {
5439  day = qMin<int>(day, QDate(year, month, 1).daysInMonth());
5440 
5441  const QLocale loc = locale();
5442  for (int i=0; i<sectionNodesCount; ++i) {
5443  if (sectionType(i) & (DaySection|DayOfWeekSection)) {
5444  input.replace(sectionPos(i), sectionSize(i), loc.toString(day));
5445  }
5446  }
5447  } else {
5448  state = qMin(Intermediate, state);
5449  }
5450  }
5451  }
5452 
5453  if (parserType != QVariant::Date) {
5454  if (isSet & Hour12Section) {
5455  const bool hasHour = isSet & Hour24Section;
5456  if (ampm == -1) {
5457  if (hasHour) {
5458  ampm = (hour < 12 ? 0 : 1);
5459  } else {
5460  ampm = 0; // no way to tell if this is am or pm so I assume am
5461  }
5462  }
5463  hour12 = (ampm == 0 ? hour12 % 12 : (hour12 % 12) + 12);
5464  if (!hasHour) {
5465  hour = hour12;
5466  } else if (hour != hour12) {
5467  conflicts = true;
5468  }
5469  } else if (ampm != -1) {
5470  if (!(isSet & (Hour24Section))) {
5471  hour = (12 * ampm); // special case. Only ap section
5472  } else if ((ampm == 0) != (hour < 12)) {
5473  conflicts = true;
5474  }
5475  }
5476 
5477  }
5478 
5479  newCurrentValue = QDateTime(QDate(year, month, day), QTime(hour, minute, second, msec), spec);
5480  QDTPDEBUG << year << month << day << hour << minute << second << msec;
5481  }
5482  QDTPDEBUGN("'%s' => '%s'(%s)", input.toLatin1().constData(),
5483  newCurrentValue.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")).toLatin1().constData(),
5484  stateName(state).toLatin1().constData());
5485  }
5486 end:
5487  if (newCurrentValue.isValid()) {
5488  if (context != FromString && state != Invalid && newCurrentValue < minimum) {
5489  const QLatin1Char space(' ');
5490  if (newCurrentValue >= minimum)
5491  qWarning("QDateTimeParser::parse Internal error 3 (%s %s)",
5492  qPrintable(newCurrentValue.toString()), qPrintable(minimum.toString()));
5493 
5494  bool done = false;
5495  state = Invalid;
5496  for (int i=0; i<sectionNodesCount && !done; ++i) {
5497  const SectionNode &sn = sectionNodes.at(i);
5498  QString t = sectionText(input, i, sn.pos).toLower();
5499  if ((t.size() < sectionMaxSize(i) && (((int)fieldInfo(i) & (FixedWidth|Numeric)) != Numeric))
5500  || t.contains(space)) {
5501  switch (sn.type) {
5502  case AmPmSection:
5503  switch (findAmPm(t, i)) {
5504  case AM:
5505  case PM:
5506  state = Acceptable;
5507  done = true;
5508  break;
5509  case Neither:
5510  state = Invalid;
5511  done = true;
5512  break;
5513  case PossibleAM:
5514  case PossiblePM:
5515  case PossibleBoth: {
5516  const QDateTime copy(newCurrentValue.addSecs(12 * 60 * 60));
5517  if (copy >= minimum && copy <= maximum) {
5518  state = Intermediate;
5519  done = true;
5520  }
5521  break; }
5522  }
5523  case MonthSection:
5524  if (sn.count >= 3) {
5525  int tmp = newCurrentValue.date().month();
5526  // I know the first possible month makes the date too early
5527  while ((tmp = findMonth(t, tmp + 1, i)) != -1) {
5528  const QDateTime copy(newCurrentValue.addMonths(tmp - newCurrentValue.date().month()));
5529  if (copy >= minimum && copy <= maximum)
5530  break; // break out of while
5531  }
5532  if (tmp == -1) {
5533  break;
5534  }
5535  state = Intermediate;
5536  done = true;
5537  break;
5538  }
5539  // fallthrough
5540  default: {
5541  int toMin;
5542  int toMax;
5543 
5544  if (sn.type & TimeSectionMask) {
5545  if (newCurrentValue.daysTo(minimum) != 0) {
5546  break;
5547  }
5548  toMin = newCurrentValue.time().msecsTo(minimum.time());
5549  if (newCurrentValue.daysTo(maximum) > 0) {
5550  toMax = -1; // can't get to max
5551  } else {
5552  toMax = newCurrentValue.time().msecsTo(maximum.time());
5553  }
5554  } else {
5555  toMin = newCurrentValue.daysTo(minimum);
5556  toMax = newCurrentValue.daysTo(maximum);
5557  }
5558  const int maxChange = QDateTimeParser::maxChange(i);
5559  if (toMin > maxChange) {
5560  QDTPDEBUG << "invalid because toMin > maxChange" << toMin
5561  << maxChange << t << newCurrentValue << minimum;
5562  state = Invalid;
5563  done = true;
5564  break;
5565  } else if (toMax > maxChange) {
5566  toMax = -1; // can't get to max
5567  }
5568 
5569  const int min = getDigit(minimum, i);
5570  if (min == -1) {
5571  qWarning("QDateTimeParser::parse Internal error 4 (%s)",
5572  qPrintable(sectionName(sn.type)));
5573  state = Invalid;
5574  done = true;
5575  break;
5576  }
5577 
5578  int max = toMax != -1 ? getDigit(maximum, i) : absoluteMax(i, newCurrentValue);
5579  int pos = cursorPosition - sn.pos;
5580  if (pos < 0 || pos >= t.size())
5581  pos = -1;
5582  if (!potentialValue(t.simplified(), min, max, i, newCurrentValue, pos)) {
5583  QDTPDEBUG << "invalid because potentialValue(" << t.simplified() << min << max
5584  << sectionName(sn.type) << "returned" << toMax << toMin << pos;
5585  state = Invalid;
5586  done = true;
5587  break;
5588  }
5589  state = Intermediate;
5590  done = true;
5591  break; }
5592  }
5593  }
5594  }
5595  } else {
5596  if (context == FromString) {
5597  // optimization
5598  Q_ASSERT(getMaximum().date().toJulianDay() == 4642999);
5599  if (newCurrentValue.date().toJulianDay() > 4642999)
5600  state = Invalid;
5601  } else {
5602  if (newCurrentValue > getMaximum())
5603  state = Invalid;
5604  }
5605 
5606  QDTPDEBUG << "not checking intermediate because newCurrentValue is" << newCurrentValue << getMinimum() << getMaximum();
5607  }
5608  }
5609  StateNode node;
5610  node.input = input;
5611  node.state = state;
5612  node.conflicts = conflicts;
5613  node.value = newCurrentValue.toTimeSpec(spec);
5614  text = input;
5615  return node;
5616 }
QDateTime addSecs(int secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
Definition: qdatetime.cpp:2869
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
int dayOfWeek() const
Returns the weekday (1 = Monday to 7 = Sunday) for this date.
Definition: qdatetime.cpp:408
int daysTo(const QDateTime &) const
Returns the number of days from this datetime to the other datetime.
Definition: qdatetime.cpp:2894
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int findAmPm(QString &str1, int index, int *used=0) const
Definition: qdatetime.cpp:5759
virtual QLocale locale() const
Definition: qdatetime_p.h:257
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
int msecsTo(const QTime &) const
Returns the number of milliseconds from this time to t.
Definition: qdatetime.cpp:1832
QVector< SectionNode > sectionNodes
Definition: qdatetime_p.h:263
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
int absoluteMax(int index, const QDateTime &value=QDateTime()) const
\
Definition: qdatetime.cpp:4590
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static void getDateFromJulianDay(uint julianDay, int *year, int *month, int *day)
Definition: qdatetime.cpp:133
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
virtual QDateTime getMaximum() const
Definition: qdatetime.cpp:6117
int sectionMaxSize(int index) const
Definition: qdatetime.cpp:5033
The QString class provides a Unicode character string.
Definition: qstring.h:83
int maxChange(int s) const
Max number of units that can be changed by this section.
Definition: qdatetime.cpp:5844
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define QDTPDEBUGN
Definition: qdatetime.cpp:69
The QTime class provides clock time functions.
Definition: qdatetime.h:148
QVariant::Type parserType
Definition: qdatetime_p.h:268
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
int sectionSize(int index) const
Returns the size of section s.
Definition: qdatetime.cpp:4943
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual QDateTime getMinimum() const
Definition: qdatetime.cpp:6112
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
unsigned int uint
Definition: qglobal.h:996
static Bigint * diff(Bigint *a, Bigint *b)
QString stateName(int s) const
For debugging.
Definition: qdatetime.cpp:6073
QDateTime addMonths(int months) const
Returns a QDateTime object containing a datetime nmonths months later than the datetime of this objec...
Definition: qdatetime.cpp:2796
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int getDigit(const QDateTime &dt, int index) const
Gets the digit from a datetime.
Definition: qdatetime.cpp:4469
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
The State element defines configurations of objects and properties.
int parseSection(const QDateTime &currentValue, int sectionIndex, QString &txt, int &cursorPosition, int index, QDateTimeParser::State &state, int *used=0) const
Definition: qdatetime.cpp:5088
QStringList separators
Definition: qdatetime_p.h:265
int count() const
Definition: qstring.h:103
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
virtual int cursorPosition() const
Definition: qdatetime_p.h:254
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
int toJulianDay() const
Converts the date to a Julian day.
Definition: qdatetime.h:134
int findMonth(const QString &str1, int monthstart, int sectionIndex, QString *monthName=0, int *used=0) const
Definition: qdatetime.cpp:5625
int daysInMonth() const
Returns the number of days in the month (28 to 31) for this date.
Definition: qdatetime.cpp:431
Qt::TimeSpec spec
Definition: qdatetime_p.h:272
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
Section sectionType(int index) const
Definition: qdatetime.cpp:4674
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
#define QDTPDEBUG
Definition: qdatetime.cpp:68
bool potentialValue(const QString &str, int min, int max, int index, const QDateTime &currentValue, int insert) const
Definition: qdatetime.cpp:5964
quint16 index
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
QDateTime toTimeSpec(Qt::TimeSpec spec) const
Returns a copy of this datetime configured to use the given time specification.
Definition: qdatetime.cpp:2969
QString sectionText(int sectionIndex) const
Definition: qdatetime.cpp:5064
FieldInfo fieldInfo(int index) const
Definition: qdatetime.cpp:5868
static const KeyPair *const end
#define qPrintable(string)
Definition: qglobal.h:1750
int sectionPos(int index) const
Returns the starting position for section s.
Definition: qdatetime.cpp:4689
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578

◆ parseFormat()

bool QDateTimeParser::parseFormat ( const QString format)

Definition at line 4769 of file qdatetime.cpp.

Referenced by QDate::fromString(), QTime::fromString(), QDateTime::fromString(), QLocale::toDate(), QLocale::toDateTime(), and QLocale::toTime().

4770 {
4771  const QLatin1Char quote('\'');
4772  const QLatin1Char slash('\\');
4773  const QLatin1Char zero('0');
4774  if (newFormat == displayFormat && !newFormat.isEmpty()) {
4775  return true;
4776  }
4777 
4778  QDTPDEBUGN("parseFormat: %s", newFormat.toLatin1().constData());
4779 
4780  QVector<SectionNode> newSectionNodes;
4781  Sections newDisplay = 0;
4782  QStringList newSeparators;
4783  int i, index = 0;
4784  int add = 0;
4785  QChar status(zero);
4786  const int max = newFormat.size();
4787  int lastQuote = -1;
4788  for (i = 0; i<max; ++i) {
4789  if (newFormat.at(i) == quote) {
4790  lastQuote = i;
4791  ++add;
4792  if (status != quote) {
4793  status = quote;
4794  } else if (newFormat.at(i - 1) != slash) {
4795  status = zero;
4796  }
4797  } else if (status != quote) {
4798  const char sect = newFormat.at(i).toLatin1();
4799  switch (sect) {
4800  case 'H':
4801  case 'h':
4802  if (parserType != QVariant::Date) {
4803  const Section hour = (sect == 'h') ? Hour12Section : Hour24Section;
4804  const SectionNode sn = { hour, i - add, countRepeat(newFormat, i, 2) };
4805  newSectionNodes.append(sn);
4806  appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
4807  i += sn.count - 1;
4808  index = i + 1;
4809  newDisplay |= hour;
4810  }
4811  break;
4812  case 'm':
4813  if (parserType != QVariant::Date) {
4814  const SectionNode sn = { MinuteSection, i - add, countRepeat(newFormat, i, 2) };
4815  newSectionNodes.append(sn);
4816  appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
4817  i += sn.count - 1;
4818  index = i + 1;
4819  newDisplay |= MinuteSection;
4820  }
4821  break;
4822  case 's':
4823  if (parserType != QVariant::Date) {
4824  const SectionNode sn = { SecondSection, i - add, countRepeat(newFormat, i, 2) };
4825  newSectionNodes.append(sn);
4826  appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
4827  i += sn.count - 1;
4828  index = i + 1;
4829  newDisplay |= SecondSection;
4830  }
4831  break;
4832 
4833  case 'z':
4834  if (parserType != QVariant::Date) {
4835  const SectionNode sn = { MSecSection, i - add, countRepeat(newFormat, i, 3) < 3 ? 1 : 3 };
4836  newSectionNodes.append(sn);
4837  appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
4838  i += sn.count - 1;
4839  index = i + 1;
4840  newDisplay |= MSecSection;
4841  }
4842  break;
4843  case 'A':
4844  case 'a':
4845  if (parserType != QVariant::Date) {
4846  const bool cap = (sect == 'A');
4847  const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0) };
4848  newSectionNodes.append(sn);
4849  appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
4850  newDisplay |= AmPmSection;
4851  if (i + 1 < newFormat.size()
4852  && newFormat.at(i+1) == (cap ? QLatin1Char('P') : QLatin1Char('p'))) {
4853  ++i;
4854  }
4855  index = i + 1;
4856  }
4857  break;
4858  case 'y':
4859  if (parserType != QVariant::Time) {
4860  const int repeat = countRepeat(newFormat, i, 4);
4861  if (repeat >= 2) {
4862  const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits,
4863  i - add, repeat == 4 ? 4 : 2 };
4864  newSectionNodes.append(sn);
4865  appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
4866  i += sn.count - 1;
4867  index = i + 1;
4868  newDisplay |= sn.type;
4869  }
4870  }
4871  break;
4872  case 'M':
4873  if (parserType != QVariant::Time) {
4874  const SectionNode sn = { MonthSection, i - add, countRepeat(newFormat, i, 4) };
4875  newSectionNodes.append(sn);
4876  newSeparators.append(unquote(newFormat.mid(index, i - index)));
4877  i += sn.count - 1;
4878  index = i + 1;
4879  newDisplay |= MonthSection;
4880  }
4881  break;
4882  case 'd':
4883  if (parserType != QVariant::Time) {
4884  const int repeat = countRepeat(newFormat, i, 4);
4885  const SectionNode sn = { repeat >= 3 ? DayOfWeekSection : DaySection, i - add, repeat };
4886  newSectionNodes.append(sn);
4887  appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
4888  i += sn.count - 1;
4889  index = i + 1;
4890  newDisplay |= sn.type;
4891  }
4892  break;
4893 
4894  default:
4895  break;
4896  }
4897  }
4898  }
4899  if (newSectionNodes.isEmpty() && context == DateTimeEdit) {
4900  return false;
4901  }
4902 
4903  if ((newDisplay & (AmPmSection|Hour12Section)) == Hour12Section) {
4904  const int max = newSectionNodes.size();
4905  for (int i=0; i<max; ++i) {
4906  SectionNode &node = newSectionNodes[i];
4907  if (node.type == Hour12Section)
4908  node.type = Hour24Section;
4909  }
4910  }
4911 
4912  if (index < newFormat.size()) {
4913  appendSeparator(&newSeparators, newFormat, index, index - max, lastQuote);
4914  } else {
4915  newSeparators.append(QString());
4916  }
4917 
4918  displayFormat = newFormat;
4919  separators = newSeparators;
4920  sectionNodes = newSectionNodes;
4921  display = newDisplay;
4922  last.pos = -1;
4923 
4924 // for (int i=0; i<sectionNodes.size(); ++i) {
4925 // QDTPDEBUG << sectionName(sectionNodes.at(i).type) << sectionNodes.at(i).count;
4926 // }
4927 
4928  QDTPDEBUG << newFormat << displayFormat;
4929  QDTPDEBUGN("separators:\n'%s'", separators.join(QLatin1String("\n")).toLatin1().constData());
4930 
4931  return true;
4932 }
static void appendSeparator(QStringList *list, const QString &string, int from, int size, int lastQuote)
Definition: qdatetime.cpp:4760
#define add(aName)
QVector< SectionNode > sectionNodes
Definition: qdatetime_p.h:263
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
SectionNode last
Definition: qdatetime_p.h:264
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QDTPDEBUGN
Definition: qdatetime.cpp:69
QVariant::Type parserType
Definition: qdatetime_p.h:268
static int countRepeat(const QString &str, int index, int maxCount)
Parses the format newFormat.
Definition: qdatetime.cpp:4749
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QStringList separators
Definition: qdatetime_p.h:265
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static QString unquote(const QString &str)
Definition: qdatetime.cpp:4715
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
Sections display
Definition: qdatetime_p.h:260
#define QDTPDEBUG
Definition: qdatetime.cpp:68
static const int zero
quint16 index
QString displayFormat
Definition: qdatetime_p.h:266
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ parseSection()

int QDateTimeParser::parseSection ( const QDateTime currentValue,
int  sectionIndex,
QString txt,
int &  cursorPosition,
int  index,
QDateTimeParser::State state,
int *  used = 0 
) const
Warning
This function is not part of the public interface.:skipToNextSection

Parses the part of text that corresponds to s and returns the value of that field. Sets *stateptr to the right state if stateptr != 0.

Definition at line 5088 of file qdatetime.cpp.

5091 {
5092  state = Invalid;
5093  int num = 0;
5094  const SectionNode &sn = sectionNode(sectionIndex);
5095  if ((sn.type & Internal) == Internal) {
5096  qWarning("QDateTimeParser::parseSection Internal error (%s %d)",
5097  qPrintable(sectionName(sn.type)), sectionIndex);
5098  return -1;
5099  }
5100 
5101  const int sectionmaxsize = sectionMaxSize(sectionIndex);
5102  QString sectiontext = text.mid(index, sectionmaxsize);
5103  int sectiontextSize = sectiontext.size();
5104 
5105  QDTPDEBUG << "sectionValue for" << sectionName(sn.type)
5106  << "with text" << text << "and st" << sectiontext
5107  << text.mid(index, sectionmaxsize)
5108  << index;
5109 
5110  int used = 0;
5111  switch (sn.type) {
5112  case AmPmSection: {
5113  const int ampm = findAmPm(sectiontext, sectionIndex, &used);
5114  switch (ampm) {
5115  case AM: // sectiontext == AM
5116  case PM: // sectiontext == PM
5117  num = ampm;
5118  state = Acceptable;
5119  break;
5120  case PossibleAM: // sectiontext => AM
5121  case PossiblePM: // sectiontext => PM
5122  num = ampm - 2;
5123  state = Intermediate;
5124  break;
5125  case PossibleBoth: // sectiontext => AM|PM
5126  num = 0;
5127  state = Intermediate;
5128  break;
5129  case Neither:
5130  state = Invalid;
5131  QDTPDEBUG << "invalid because findAmPm(" << sectiontext << ") returned -1";
5132  break;
5133  default:
5134  QDTPDEBUGN("This should never happen (findAmPm returned %d)", ampm);
5135  break;
5136  }
5137  if (state != Invalid) {
5138  QString str = text;
5139  text.replace(index, used, sectiontext.left(used));
5140  }
5141  break; }
5142  case MonthSection:
5143  case DayOfWeekSection:
5144  if (sn.count >= 3) {
5145  if (sn.type == MonthSection) {
5146  int min = 1;
5147  const QDate minDate = getMinimum().date();
5148  if (currentValue.date().year() == minDate.year()) {
5149  min = minDate.month();
5150  }
5151  num = findMonth(sectiontext.toLower(), min, sectionIndex, &sectiontext, &used);
5152  } else {
5153  num = findDay(sectiontext.toLower(), 1, sectionIndex, &sectiontext, &used);
5154  }
5155 
5156  if (num != -1) {
5157  state = (used == sectiontext.size() ? Acceptable : Intermediate);
5158  QString str = text;
5159  text.replace(index, used, sectiontext.left(used));
5160  } else {
5161  state = Intermediate;
5162  }
5163  break; }
5164  // fall through
5165  case DaySection:
5166  case YearSection:
5167  case YearSection2Digits:
5168  case Hour12Section:
5169  case Hour24Section:
5170  case MinuteSection:
5171  case SecondSection:
5172  case MSecSection: {
5173  if (sectiontextSize == 0) {
5174  num = 0;
5175  used = 0;
5176  state = Intermediate;
5177  } else {
5178  const int absMax = absoluteMax(sectionIndex);
5179  QLocale loc;
5180  bool ok = true;
5181  int last = -1;
5182  used = -1;
5183 
5184  QString digitsStr(sectiontext);
5185  for (int i = 0; i < sectiontextSize; ++i) {
5186  if (digitsStr.at(i).isSpace()) {
5187  sectiontextSize = i;
5188  break;
5189  }
5190  }
5191 
5192  const int max = qMin(sectionmaxsize, sectiontextSize);
5193  for (int digits = max; digits >= 1; --digits) {
5194  digitsStr.truncate(digits);
5195  int tmp = (int)loc.toUInt(digitsStr, &ok, 10);
5196  if (ok && sn.type == Hour12Section) {
5197  if (tmp > 12) {
5198  tmp = -1;
5199  ok = false;
5200  } else if (tmp == 12) {
5201  tmp = 0;
5202  }
5203  }
5204  if (ok && tmp <= absMax) {
5205  QDTPDEBUG << sectiontext.left(digits) << tmp << digits;
5206  last = tmp;
5207  used = digits;
5208  break;
5209  }
5210  }
5211 
5212  if (last == -1) {
5213  QChar first(sectiontext.at(0));
5214  if (separators.at(sectionIndex + 1).startsWith(first)) {
5215  used = 0;
5216  state = Intermediate;
5217  } else {
5218  state = Invalid;
5219  QDTPDEBUG << "invalid because" << sectiontext << "can't become a uint" << last << ok;
5220  }
5221  } else {
5222  num += last;
5223  const FieldInfo fi = fieldInfo(sectionIndex);
5224  const bool done = (used == sectionmaxsize);
5225  if (!done && fi & Fraction) { // typing 2 in a zzz field should be .200, not .002
5226  for (int i=used; i<sectionmaxsize; ++i) {
5227  num *= 10;
5228  }
5229  }
5230  const int absMin = absoluteMin(sectionIndex);
5231  if (num < absMin) {
5232  state = done ? Invalid : Intermediate;
5233  if (done)
5234  QDTPDEBUG << "invalid because" << num << "is less than absoluteMin" << absMin;
5235  } else if (num > absMax) {
5236  state = Intermediate;
5237  } else if (!done && (fi & (FixedWidth|Numeric)) == (FixedWidth|Numeric)) {
5238  if (skipToNextSection(sectionIndex, currentValue, digitsStr)) {
5239  state = Acceptable;
5240  const int missingZeroes = sectionmaxsize - digitsStr.size();
5241  text.insert(index, QString().fill(QLatin1Char('0'), missingZeroes));
5242  used = sectionmaxsize;
5243  cursorPosition += missingZeroes;
5244  } else {
5245  state = Intermediate;;
5246  }
5247  } else {
5248  state = Acceptable;
5249  }
5250  }
5251  }
5252  break; }
5253  default:
5254  qWarning("QDateTimeParser::parseSection Internal error (%s %d)",
5255  qPrintable(sectionName(sn.type)), sectionIndex);
5256  return -1;
5257  }
5258 
5259  if (usedptr)
5260  *usedptr = used;
5261 
5262  return (state != Invalid ? num : -1);
5263 }
SectionNode first
Definition: qdatetime_p.h:264
int absoluteMin(int index) const
Definition: qdatetime.cpp:4623
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int findAmPm(QString &str1, int index, int *used=0) const
Definition: qdatetime.cpp:5759
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
uint toUInt(const QString &s, bool *ok=0, int base=0) const
Returns the unsigned int represented by the localized string s, using base base.
Definition: qlocale.cpp:1161
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
int absoluteMax(int index, const QDateTime &value=QDateTime()) const
\
Definition: qdatetime.cpp:4590
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
The QDate class provides date functions.
Definition: qdatetime.h:55
int sectionMaxSize(int index) const
Definition: qdatetime.cpp:5033
The QString class provides a Unicode character string.
Definition: qstring.h:83
SectionNode last
Definition: qdatetime_p.h:264
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
#define QDTPDEBUGN
Definition: qdatetime.cpp:69
bool skipToNextSection(int section, const QDateTime &current, const QString &sectionText) const
Definition: qdatetime.cpp:6001
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual QDateTime getMinimum() const
Definition: qdatetime.cpp:6112
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
int findDay(const QString &str1, int intDaystart, int sectionIndex, QString *dayName=0, int *used=0) const
Definition: qdatetime.cpp:5688
Q_CORE_EXPORT void qWarning(const char *,...)
QStringList separators
Definition: qdatetime_p.h:265
virtual int cursorPosition() const
Definition: qdatetime_p.h:254
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
int findMonth(const QString &str1, int monthstart, int sectionIndex, QString *monthName=0, int *used=0) const
Definition: qdatetime.cpp:5625
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
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
#define QDTPDEBUG
Definition: qdatetime.cpp:68
quint16 index
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
FieldInfo fieldInfo(int index) const
Definition: qdatetime.cpp:5868
#define qPrintable(string)
Definition: qglobal.h:1750
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ potentialValue()

bool QDateTimeParser::potentialValue ( const QString str,
int  min,
int  max,
int  index,
const QDateTime currentValue,
int  insert 
) const
Warning
This function is not part of the public interface. Returns true if str can be modified to represent a number that is within min and max.

Definition at line 5964 of file qdatetime.cpp.

5966 {
5967  if (str.isEmpty()) {
5968  return true;
5969  }
5970  const int size = sectionMaxSize(index);
5971  int val = (int)locale().toUInt(str);
5972  const SectionNode &sn = sectionNode(index);
5973  if (sn.type == YearSection2Digits) {
5974  val += currentValue.date().year() - (currentValue.date().year() % 100);
5975  }
5976  if (val >= min && val <= max && str.size() == size) {
5977  return true;
5978  } else if (val > max) {
5979  return false;
5980  } else if (str.size() == size && val < min) {
5981  return false;
5982  }
5983 
5984  const int len = size - str.size();
5985  for (int i=0; i<len; ++i) {
5986  for (int j=0; j<10; ++j) {
5987  if (potentialValue(str + QLatin1Char('0' + j), min, max, index, currentValue, insert)) {
5988  return true;
5989  } else if (insert >= 0) {
5990  QString tmp = str;
5991  tmp.insert(insert, QLatin1Char('0' + j));
5992  if (potentialValue(tmp, min, max, index, currentValue, insert))
5993  return true;
5994  }
5995  }
5996  }
5997 
5998  return false;
5999 }
virtual QLocale locale() const
Definition: qdatetime_p.h:257
uint toUInt(const QString &s, bool *ok=0, int base=0) const
Returns the unsigned int represented by the localized string s, using base base.
Definition: qlocale.cpp:1161
int sectionMaxSize(int index) const
Definition: qdatetime.cpp:5033
The QString class provides a Unicode character string.
Definition: qstring.h:83
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
bool potentialValue(const QString &str, int min, int max, int index, const QDateTime &currentValue, int insert) const
Definition: qdatetime.cpp:5964
quint16 index
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ sectionFormat() [1/2]

QString QDateTimeParser::sectionFormat ( int  index) const
Warning
This function is not part of the public interface. Get a number that str can become which is between min and max or -1 if this is not possible.

Definition at line 5923 of file qdatetime.cpp.

5924 {
5925  const SectionNode &sn = sectionNode(index);
5926  return sectionFormat(sn.type, sn.count);
5927 }
QString sectionFormat(int index) const
Definition: qdatetime.cpp:5923
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
quint16 index

◆ sectionFormat() [2/2]

QString QDateTimeParser::sectionFormat ( Section  s,
int  count 
) const

Definition at line 5929 of file qdatetime.cpp.

5930 {
5931  QChar fillChar;
5932  switch (s) {
5933  case AmPmSection: return count == 1 ? QLatin1String("AP") : QLatin1String("ap");
5934  case MSecSection: fillChar = QLatin1Char('z'); break;
5935  case SecondSection: fillChar = QLatin1Char('s'); break;
5936  case MinuteSection: fillChar = QLatin1Char('m'); break;
5937  case Hour24Section: fillChar = QLatin1Char('H'); break;
5938  case Hour12Section: fillChar = QLatin1Char('h'); break;
5939  case DayOfWeekSection:
5940  case DaySection: fillChar = QLatin1Char('d'); break;
5941  case MonthSection: fillChar = QLatin1Char('M'); break;
5942  case YearSection2Digits:
5943  case YearSection: fillChar = QLatin1Char('y'); break;
5944  default:
5945  qWarning("QDateTimeParser::sectionFormat Internal error (%s)",
5946  qPrintable(sectionName(s)));
5947  return QString();
5948  }
5949  if (fillChar.isNull()) {
5950  qWarning("QDateTimeParser::sectionFormat Internal error 2");
5951  return QString();
5952  }
5953 
5954  QString str;
5955  str.fill(fillChar, count);
5956  return str;
5957 }
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString & fill(QChar c, int size=-1)
Sets every character in the string to character ch.
Definition: qstring.cpp:4641
#define qPrintable(string)
Definition: qglobal.h:1750
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ sectionMaxSize() [1/2]

int QDateTimeParser::sectionMaxSize ( int  index) const

Definition at line 5033 of file qdatetime.cpp.

5034 {
5035  const SectionNode &sn = sectionNode(index);
5036  return sectionMaxSize(sn.type, sn.count);
5037 }
int sectionMaxSize(int index) const
Definition: qdatetime.cpp:5033
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
quint16 index

◆ sectionMaxSize() [2/2]

int QDateTimeParser::sectionMaxSize ( Section  s,
int  count 
) const

Definition at line 4961 of file qdatetime.cpp.

4962 {
4963 #ifndef QT_NO_TEXTDATE
4964  int mcount = 12;
4965 #endif
4966 
4967  switch (s) {
4968  case FirstSection:
4969  case NoSection:
4970  case LastSection: return 0;
4971 
4972  case AmPmSection: {
4973  const int lowerMax = qMin(getAmPmText(AmText, LowerCase).size(),
4974  getAmPmText(PmText, LowerCase).size());
4975  const int upperMax = qMin(getAmPmText(AmText, UpperCase).size(),
4976  getAmPmText(PmText, UpperCase).size());
4977  return qMin(4, qMin(lowerMax, upperMax));
4978  }
4979 
4980  case Hour24Section:
4981  case Hour12Section:
4982  case MinuteSection:
4983  case SecondSection:
4984  case DaySection: return 2;
4985  case DayOfWeekSection:
4986 #ifdef QT_NO_TEXTDATE
4987  return 2;
4988 #else
4989  mcount = 7;
4990  // fall through
4991 #endif
4992  case MonthSection:
4993  if (count <= 2)
4994  return 2;
4995 
4996 #ifdef QT_NO_TEXTDATE
4997  return 2;
4998 #else
4999  {
5000  int ret = 0;
5001  const QLocale l = locale();
5002  for (int i=1; i<=mcount; ++i) {
5003  const QString str = (s == MonthSection
5004  ? l.monthName(i, count == 4 ? QLocale::LongFormat : QLocale::ShortFormat)
5005  : l.dayName(i, count == 4 ? QLocale::LongFormat : QLocale::ShortFormat));
5006  ret = qMax(str.size(), ret);
5007  }
5008  return ret;
5009  }
5010 #endif
5011  case MSecSection: return 3;
5012  case YearSection: return 4;
5013  case YearSection2Digits: return 2;
5014 
5015  case CalendarPopupSection:
5016  case Internal:
5017  case TimeSectionMask:
5018  case DateSectionMask:
5019  qWarning("QDateTimeParser::sectionMaxSize: Invalid section %s",
5020  sectionName(s).toLatin1().constData());
5021 
5022  case NoSectionIndex:
5023  case FirstSectionIndex:
5024  case LastSectionIndex:
5025  case CalendarPopupIndex:
5026  // these cases can't happen
5027  break;
5028  }
5029  return -1;
5030 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual QLocale locale() const
Definition: qdatetime_p.h:257
QString monthName(int, FormatType format=LongFormat) const
Returns the localized name of month, in the format specified by type.
Definition: qlocale.cpp:2007
virtual QString getAmPmText(AmPm ap, Case cs) const
Definition: qdatetime.cpp:6122
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
Q_CORE_EXPORT void qWarning(const char *,...)
QFactoryLoader * l
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

◆ sectionName()

QString QDateTimeParser::sectionName ( int  s) const

For debugging.

Warning
This function is not part of the public interface. Returns the name of the section s.

Definition at line 6044 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::_q_editorCursorPositionChanged().

6045 {
6046  switch (s) {
6047  case QDateTimeParser::AmPmSection: return QLatin1String("AmPmSection");
6048  case QDateTimeParser::DaySection: return QLatin1String("DaySection");
6049  case QDateTimeParser::DayOfWeekSection: return QLatin1String("DayOfWeekSection");
6050  case QDateTimeParser::Hour24Section: return QLatin1String("Hour24Section");
6051  case QDateTimeParser::Hour12Section: return QLatin1String("Hour12Section");
6052  case QDateTimeParser::MSecSection: return QLatin1String("MSecSection");
6053  case QDateTimeParser::MinuteSection: return QLatin1String("MinuteSection");
6054  case QDateTimeParser::MonthSection: return QLatin1String("MonthSection");
6055  case QDateTimeParser::SecondSection: return QLatin1String("SecondSection");
6056  case QDateTimeParser::YearSection: return QLatin1String("YearSection");
6057  case QDateTimeParser::YearSection2Digits: return QLatin1String("YearSection2Digits");
6058  case QDateTimeParser::NoSection: return QLatin1String("NoSection");
6059  case QDateTimeParser::FirstSection: return QLatin1String("FirstSection");
6060  case QDateTimeParser::LastSection: return QLatin1String("LastSection");
6061  default: return QLatin1String("Unknown section ") + QString::number(s);
6062  }
6063 }
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
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ sectionNode()

const QDateTimeParser::SectionNode & QDateTimeParser::sectionNode ( int  sectionIndex) const

Returns the sectionNode for the Section s.

Warning
This function is not part of the public interface.

Definition at line 4654 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::setSelected(), and QDateTimeEditPrivate::stepBy().

4655 {
4656  if (sectionIndex < 0) {
4657  switch (sectionIndex) {
4658  case FirstSectionIndex:
4659  return first;
4660  case LastSectionIndex:
4661  return last;
4662  case NoSectionIndex:
4663  return none;
4664  }
4665  } else if (sectionIndex < sectionNodes.size()) {
4666  return sectionNodes.at(sectionIndex);
4667  }
4668 
4669  qWarning("QDateTimeParser::sectionNode() Internal error (%d)",
4670  sectionIndex);
4671  return none;
4672 }
SectionNode first
Definition: qdatetime_p.h:264
QVector< SectionNode > sectionNodes
Definition: qdatetime_p.h:263
SectionNode last
Definition: qdatetime_p.h:264
Q_CORE_EXPORT void qWarning(const char *,...)
SectionNode none
Definition: qdatetime_p.h:264

◆ sectionPos() [1/2]

int QDateTimeParser::sectionPos ( int  sectionIndex) const

Returns the starting position for section s.

Warning
This function is not part of the public interface.

Definition at line 4689 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::_q_editorCursorPositionChanged(), QDateTimeEditPrivate::clearSection(), QDateTimeEditPrivate::closestSection(), QDateTimeEditPrivate::sectionAt(), QDateTimeEditPrivate::setSelected(), and QDateTimeEditPrivate::updateEdit().

4690 {
4691  return sectionPos(sectionNode(sectionIndex));
4692 }
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
int sectionPos(int index) const
Returns the starting position for section s.
Definition: qdatetime.cpp:4689

◆ sectionPos() [2/2]

int QDateTimeParser::sectionPos ( const SectionNode sn) const

Definition at line 4694 of file qdatetime.cpp.

4695 {
4696  switch (sn.type) {
4697  case FirstSection: return 0;
4698  case LastSection: return displayText().size() - 1;
4699  default: break;
4700  }
4701  if (sn.pos == -1) {
4702  qWarning("QDateTimeParser::sectionPos Internal error (%s)", qPrintable(sectionName(sn.type)));
4703  return -1;
4704  }
4705  return sn.pos;
4706 }
virtual QString displayText() const
Definition: qdatetime_p.h:255
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
Q_CORE_EXPORT void qWarning(const char *,...)
#define qPrintable(string)
Definition: qglobal.h:1750

◆ sectionSize()

int QDateTimeParser::sectionSize ( int  sectionIndex) const

Returns the size of section s.

Warning
This function is not part of the public interface.

Definition at line 4943 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::_q_editorCursorPositionChanged(), QDateTimeEditPrivate::clearSection(), QDateTimeEditPrivate::closestSection(), QDateTimeEditPrivate::sectionAt(), and QDateTimeEditPrivate::setSelected().

4944 {
4945  if (sectionIndex < 0)
4946  return 0;
4947 
4948  if (sectionIndex >= sectionNodes.size()) {
4949  qWarning("QDateTimeParser::sectionSize Internal error (%d)", sectionIndex);
4950  return -1;
4951  }
4952  if (sectionIndex == sectionNodes.size() - 1) {
4953  return displayText().size() - sectionPos(sectionIndex) - separators.last().size();
4954  } else {
4955  return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex)
4956  - separators.at(sectionIndex + 1).size();
4957  }
4958 }
virtual QString displayText() const
Definition: qdatetime_p.h:255
QVector< SectionNode > sectionNodes
Definition: qdatetime_p.h:263
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
QStringList separators
Definition: qdatetime_p.h:265
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
int sectionPos(int index) const
Returns the starting position for section s.
Definition: qdatetime.cpp:4689

◆ sectionText() [1/2]

QString QDateTimeParser::sectionText ( int  sectionIndex) const

Definition at line 5064 of file qdatetime.cpp.

5065 {
5066  const SectionNode &sn = sectionNode(sectionIndex);
5067  switch (sn.type) {
5068  case NoSectionIndex:
5069  case FirstSectionIndex:
5070  case LastSectionIndex:
5071  return QString();
5072  default: break;
5073  }
5074 
5075  return displayText().mid(sn.pos, sectionSize(sectionIndex));
5076 }
virtual QString displayText() const
Definition: qdatetime_p.h:255
The QString class provides a Unicode character string.
Definition: qstring.h:83
int sectionSize(int index) const
Returns the size of section s.
Definition: qdatetime.cpp:4943
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
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

◆ sectionText() [2/2]

QString QDateTimeParser::sectionText ( const QString text,
int  sectionIndex,
int  index 
) const

Returns the text of section s.

Warning
This function is not part of the public interface.

This function operates on the arg text rather than edit->text().

Definition at line 5050 of file qdatetime.cpp.

5051 {
5052  const SectionNode &sn = sectionNode(sectionIndex);
5053  switch (sn.type) {
5054  case NoSectionIndex:
5055  case FirstSectionIndex:
5056  case LastSectionIndex:
5057  return QString();
5058  default: break;
5059  }
5060 
5061  return text.mid(index, sectionSize(sectionIndex));
5062 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
int sectionSize(int index) const
Returns the size of section s.
Definition: qdatetime.cpp:4943
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
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
quint16 index

◆ sectionType()

QDateTimeParser::Section QDateTimeParser::sectionType ( int  index) const

Definition at line 4674 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::_q_editorCursorPositionChanged().

4675 {
4676  return sectionNode(sectionIndex).type;
4677 }
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654

◆ setDigit()

bool QDateTimeParser::setDigit ( QDateTime v,
int  index,
int  newVal 
) const

Sets a digit in a datetime.

Warning
This function is not part of the public interface. E.g.

QDateTime var(QDate(2004, 02, 02)); int digit = getDigit(var, Year); digit = 2004 setDigit(&var, Year, 2005); digit = getDigit(var, Year); digit = 2005

Definition at line 4520 of file qdatetime.cpp.

Referenced by QDateTimeEditPrivate::stepBy().

4521 {
4522  if (index < 0 || index >= sectionNodes.size()) {
4523 #ifndef QT_NO_DATESTRING
4524  qWarning("QDateTimeParser::setDigit() Internal error (%s %d %d)",
4525  qPrintable(v.toString()), index, newVal);
4526 #else
4527  qWarning("QDateTimeParser::setDigit() Internal error (%d %d)", index, newVal);
4528 #endif
4529  return false;
4530  }
4531  const SectionNode &node = sectionNodes.at(index);
4532 
4533  int year, month, day, hour, minute, second, msec;
4534  year = v.date().year();
4535  month = v.date().month();
4536  day = v.date().day();
4537  hour = v.time().hour();
4538  minute = v.time().minute();
4539  second = v.time().second();
4540  msec = v.time().msec();
4541 
4542  switch (node.type) {
4543  case Hour24Section: case Hour12Section: hour = newVal; break;
4544  case MinuteSection: minute = newVal; break;
4545  case SecondSection: second = newVal; break;
4546  case MSecSection: msec = newVal; break;
4547  case YearSection2Digits:
4548  case YearSection: year = newVal; break;
4549  case MonthSection: month = newVal; break;
4550  case DaySection:
4551  case DayOfWeekSection:
4552  if (newVal > 31) {
4553  // have to keep legacy behavior. setting the
4554  // date to 32 should return false. Setting it
4555  // to 31 for february should return true
4556  return false;
4557  }
4558  day = newVal;
4559  break;
4560  case AmPmSection: hour = (newVal == 0 ? hour % 12 : (hour % 12) + 12); break;
4561  default:
4562  qWarning("QDateTimeParser::setDigit() Internal error (%s)",
4563  qPrintable(sectionName(node.type)));
4564  break;
4565  }
4566 
4567  if (!(node.type & (DaySection|DayOfWeekSection))) {
4568  if (day < cachedDay)
4569  day = cachedDay;
4570  const int max = QDate(year, month, 1).daysInMonth();
4571  if (day > max) {
4572  day = max;
4573  }
4574  }
4575  if (QDate::isValid(year, month, day) && QTime::isValid(hour, minute, second, msec)) {
4576  v = QDateTime(QDate(year, month, day), QTime(hour, minute, second, msec), spec);
4577  return true;
4578  }
4579  return false;
4580 }
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
QVector< SectionNode > sectionNodes
Definition: qdatetime_p.h:263
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
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
The QTime class provides clock time functions.
Definition: qdatetime.h:148
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
Q_CORE_EXPORT void qWarning(const char *,...)
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
int daysInMonth() const
Returns the number of days in the month (28 to 31) for this date.
Definition: qdatetime.cpp:431
Qt::TimeSpec spec
Definition: qdatetime_p.h:272
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
quint16 index
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
#define qPrintable(string)
Definition: qglobal.h:1750
bool isValid() const
Returns true if the time is valid; otherwise returns false.
Definition: qdatetime.cpp:1566
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578

◆ skipToNextSection()

bool QDateTimeParser::skipToNextSection ( int  section,
const QDateTime current,
const QString sectionText 
) const

Definition at line 6001 of file qdatetime.cpp.

6002 {
6003  Q_ASSERT(current >= getMinimum() && current <= getMaximum());
6004 
6005  const SectionNode &node = sectionNode(index);
6007 
6008  const QDateTime maximum = getMaximum();
6009  const QDateTime minimum = getMinimum();
6010  QDateTime tmp = current;
6011  int min = absoluteMin(index);
6012  setDigit(tmp, index, min);
6013  if (tmp < minimum) {
6014  min = getDigit(minimum, index);
6015  }
6016 
6017  int max = absoluteMax(index, current);
6018  setDigit(tmp, index, max);
6019  if (tmp > maximum) {
6020  max = getDigit(maximum, index);
6021  }
6022  int pos = cursorPosition() - node.pos;
6023  if (pos < 0 || pos >= text.size())
6024  pos = -1;
6025 
6026  const bool potential = potentialValue(text, min, max, index, current, pos);
6027  return !potential;
6028 
6029  /* If the value potentially can become another valid entry we
6030  * don't want to skip to the next. E.g. In a M field (month
6031  * without leading 0 if you type 1 we don't want to autoskip but
6032  * if you type 3 we do
6033  */
6034 }
int absoluteMin(int index) const
Definition: qdatetime.cpp:4623
int absoluteMax(int index, const QDateTime &value=QDateTime()) const
\
Definition: qdatetime.cpp:4590
virtual QDateTime getMaximum() const
Definition: qdatetime.cpp:6117
int sectionMaxSize(int index) const
Definition: qdatetime.cpp:5033
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
virtual QDateTime getMinimum() const
Definition: qdatetime.cpp:6112
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
int getDigit(const QDateTime &dt, int index) const
Gets the digit from a datetime.
Definition: qdatetime.cpp:4469
virtual int cursorPosition() const
Definition: qdatetime_p.h:254
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
bool setDigit(QDateTime &t, int index, int newval) const
Sets a digit in a datetime.
Definition: qdatetime.cpp:4520
bool potentialValue(const QString &str, int min, int max, int index, const QDateTime &currentValue, int insert) const
Definition: qdatetime.cpp:5964
quint16 index

◆ stateName()

QString QDateTimeParser::stateName ( int  s) const

For debugging.

Warning
This function is not part of the public interface. Returns the name of the state s.

Definition at line 6073 of file qdatetime.cpp.

6074 {
6075  switch (s) {
6076  case Invalid: return QLatin1String("Invalid");
6077  case Intermediate: return QLatin1String("Intermediate");
6078  case Acceptable: return QLatin1String("Acceptable");
6079  default: return QLatin1String("Unknown state ") + QString::number(s);
6080  }
6081 }
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
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

Properties

◆ cachedDay

int QDateTimeParser::cachedDay
mutable

◆ context

Context QDateTimeParser::context

Definition at line 273 of file qdatetime_p.h.

◆ currentSectionIndex

int QDateTimeParser::currentSectionIndex
mutable

◆ defaultLocale

QLocale QDateTimeParser::defaultLocale

Definition at line 267 of file qdatetime_p.h.

Referenced by QLocale::toDate(), QLocale::toDateTime(), and QLocale::toTime().

◆ display

Sections QDateTimeParser::display

Definition at line 260 of file qdatetime_p.h.

◆ displayFormat

QString QDateTimeParser::displayFormat

Definition at line 266 of file qdatetime_p.h.

◆ first

SectionNode QDateTimeParser::first

Definition at line 264 of file qdatetime_p.h.

Referenced by QDateTimeEditPrivate::QDateTimeEditPrivate().

◆ fixday

bool QDateTimeParser::fixday

Definition at line 270 of file qdatetime_p.h.

Referenced by QDateTimeEditPrivate::QDateTimeEditPrivate().

◆ last

SectionNode QDateTimeParser::last

Definition at line 264 of file qdatetime_p.h.

Referenced by QDateTimeEditPrivate::QDateTimeEditPrivate().

◆ none

SectionNode QDateTimeParser::none

Definition at line 264 of file qdatetime_p.h.

Referenced by QDateTimeEditPrivate::QDateTimeEditPrivate().

◆ parserType

QVariant::Type QDateTimeParser::parserType

Definition at line 268 of file qdatetime_p.h.

◆ popup

SectionNode QDateTimeParser::popup

Definition at line 264 of file qdatetime_p.h.

◆ sectionNodes

QVector<SectionNode> QDateTimeParser::sectionNodes

◆ separators

QStringList QDateTimeParser::separators

◆ spec

Qt::TimeSpec QDateTimeParser::spec

◆ text

QString QDateTimeParser::text
mutable

Definition at line 262 of file qdatetime_p.h.


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