Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QDateTimeParser Class Reference

#include <qdatetimeparser_p.h>

+ Inheritance diagram for QDateTimeParser:
+ Collaboration diagram for QDateTimeParser:

Classes

struct  SectionNode
 
struct  StateNode
 

Public Types

enum  Context { FromString , DateTimeEdit }
 
enum  Section {
  NoSection = 0x00000 , AmPmSection = 0x00001 , MSecSection = 0x00002 , SecondSection = 0x00004 ,
  MinuteSection = 0x00008 , Hour12Section = 0x00010 , Hour24Section = 0x00020 , TimeZoneSection = 0x00040 ,
  HourSectionMask = (Hour12Section | Hour24Section) , TimeSectionMask , DaySection = 0x00100 , MonthSection = 0x00200 ,
  YearSection = 0x00400 , YearSection2Digits = 0x00800 , YearSectionMask = YearSection | YearSection2Digits , DayOfWeekSectionShort = 0x01000 ,
  DayOfWeekSectionLong = 0x02000 , DayOfWeekSectionMask = DayOfWeekSectionShort | DayOfWeekSectionLong , DaySectionMask = DaySection | DayOfWeekSectionMask , DateSectionMask = DaySectionMask | MonthSection | YearSectionMask ,
  Internal = 0x10000 , FirstSection = 0x20000 | Internal , LastSection = 0x40000 | Internal , CalendarPopupSection = 0x80000 | Internal ,
  NoSectionIndex = -1 , FirstSectionIndex = -2 , LastSectionIndex = -3 , CalendarPopupIndex = -4
}
 
enum  State { Invalid , Intermediate , Acceptable }
 
enum  AmPm { AmText , PmText }
 
enum  FieldInfoFlag { Numeric = 0x01 , FixedWidth = 0x02 , AllowPartial = 0x04 , Fraction = 0x08 }
 

Public Member Functions

 QDateTimeParser (QMetaType::Type t, Context ctx, const QCalendar &cal=QCalendar())
 
virtual ~QDateTimeParser ()
 
StateNode parse (const QString &input, int position, const QDateTime &defaultValue, bool fixup) const
 
bool fromString (const QString &text, QDate *date, QTime *time) const
 
bool fromString (const QString &text, QDateTime *datetime) const
 
bool parseFormat (QStringView format)
 
FieldInfo fieldInfo (int index) const
 
void setDefaultLocale (const QLocale &loc)
 
virtual QString displayText () const
 
void setCalendar (const QCalendar &calendar)
 Sets cal as the calendar to use.
 

Protected Member Functions

int sectionSize (int index) const
 
int sectionMaxSize (int index) const
 
int sectionPos (int index) const
 
int sectionPos (const SectionNode &sn) const
 
const SectionNodesectionNode (int index) const
 
Section sectionType (int index) const
 
QString sectionText (int sectionIndex) const
 
int getDigit (const QDateTime &dt, int index) const
 
bool setDigit (QDateTime &t, int index, int newval) const
 
int absoluteMax (int index, const QDateTime &value=QDateTime()) const
 
int absoluteMin (int index) const
 
bool skipToNextSection (int section, const QDateTime &current, QStringView sectionText) const
 
bool skipToNextSection (int section, const QDateTime &current, const QString &sectionText) const
 
QString stateName (State s) const
 
virtual QDateTime getMinimum () const
 
virtual QDateTime getMaximum () const
 
virtual int cursorPosition () const
 
virtual QLocale locale () const
 

Protected Attributes

int currentSectionIndex = int(NoSectionIndex)
 
Sections display
 
int cachedDay = -1
 
QString m_text
 
QList< SectionNodesectionNodes
 
SectionNode first
 
SectionNode last
 
SectionNode none
 
SectionNode popup
 
QStringList separators
 
QString displayFormat
 
QLocale defaultLocale
 
QMetaType::Type parserType
 
bool fixday = false
 
Context context
 
QCalendar calendar
 

Friends

class QDTPUnitTestParser
 

Detailed Description

Definition at line 42 of file qdatetimeparser_p.h.

Member Enumeration Documentation

◆ AmPm

Enumerator
AmText 
PmText 

Definition at line 132 of file qdatetimeparser_p.h.

◆ Context

Enumerator
FromString 
DateTimeEdit 

Definition at line 45 of file qdatetimeparser_p.h.

◆ FieldInfoFlag

Enumerator
Numeric 
FixedWidth 
AllowPartial 
Fraction 

Definition at line 143 of file qdatetimeparser_p.h.

◆ Section

Enumerator
NoSection 
AmPmSection 
MSecSection 
SecondSection 
MinuteSection 
Hour12Section 
Hour24Section 
TimeZoneSection 
HourSectionMask 
TimeSectionMask 
DaySection 
MonthSection 
YearSection 
YearSection2Digits 
YearSectionMask 
DayOfWeekSectionShort 
DayOfWeekSectionLong 
DayOfWeekSectionMask 
DaySectionMask 
DateSectionMask 
Internal 
FirstSection 
LastSection 
CalendarPopupSection 
NoSectionIndex 
FirstSectionIndex 
LastSectionIndex 
CalendarPopupIndex 

Definition at line 68 of file qdatetimeparser_p.h.

◆ State

Enumerator
Invalid 
Intermediate 
Acceptable 

Definition at line 116 of file qdatetimeparser_p.h.

Constructor & Destructor Documentation

◆ QDateTimeParser()

QDateTimeParser::QDateTimeParser ( QMetaType::Type  t,
Context  ctx,
const QCalendar cal = QCalendar() 
)
inline

Definition at line 49 of file qdatetimeparser_p.h.

References QLocale::system().

+ Here is the call graph for this function:

◆ ~QDateTimeParser()

QDateTimeParser::~QDateTimeParser ( )
virtual

Definition at line 35 of file qdatetimeparser.cpp.

Member Function Documentation

◆ absoluteMax()

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

Returns the absolute maximum for a section

Definition at line 223 of file qdatetimeparser.cpp.

References AmPmSection, calendar, QDateTime::date(), DayOfWeekSectionLong, DayOfWeekSectionShort, DaySection, QDate::daysInMonth(), Hour12Section, Hour24Section, QDateTime::isValid(), QCalendar::maximumDaysInMonth(), QCalendar::maximumMonthsInYear(), QTimeZone::MaxUtcOffsetSecs, MinuteSection, MonthSection, MSecSection, QDateTimeParser::SectionNode::name(), qUtf16Printable, qWarning, SecondSection, sectionNode(), TimeZoneSection, QDateTimeParser::SectionNode::type, YearSection, and YearSection2Digits.

Referenced by parse(), setDigit(), skipToNextSection(), and QDateTimeEditPrivate::stepBy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ absoluteMin()

int QDateTimeParser::absoluteMin ( int  s) const
protected

Returns the absolute minimum for a section

Definition at line 267 of file qdatetimeparser.cpp.

References AmPmSection, DayOfWeekSectionLong, DayOfWeekSectionShort, DaySection, Hour12Section, Hour24Section, QTimeZone::MinUtcOffsetSecs, MinuteSection, MonthSection, MSecSection, QDateTimeParser::SectionNode::name(), qUtf16Printable, qWarning, SecondSection, sectionNode(), TimeZoneSection, QDateTimeParser::SectionNode::type, YearSection, and YearSection2Digits.

Referenced by setDigit(), skipToNextSection(), and QDateTimeEditPrivate::stepBy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cursorPosition()

virtual int QDateTimeParser::cursorPosition ( ) const
inlineprotectedvirtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 233 of file qdatetimeparser_p.h.

Referenced by skipToNextSection().

+ Here is the caller graph for this function:

◆ displayText()

virtual QString QDateTimeParser::displayText ( ) const
inlinevirtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 154 of file qdatetimeparser_p.h.

Referenced by sectionPos(), sectionSize(), and sectionText().

+ Here is the caller graph for this function:

◆ fieldInfo()

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

Definition at line 1958 of file qdatetimeparser.cpp.

References AllowPartial, AmPmSection, AmText, QDateTimeParser::SectionNode::count, DayOfWeekSectionLong, DayOfWeekSectionShort, DaySection, FixedWidth, Fraction, Hour12Section, Hour24Section, MinuteSection, MonthSection, MSecSection, QDateTimeParser::SectionNode::name(), Numeric, PmText, Q_FALLTHROUGH, qUtf16Printable, qWarning, ret, SecondSection, sectionNode(), QString::size(), TimeZoneSection, QDateTimeParser::SectionNode::type, YearSection, and YearSection2Digits.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromString() [1/2]

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

Definition at line 2161 of file qdatetimeparser.cpp.

References Acceptable, QDateTimeParser::StateNode::conflicts, d, date, QDateTime::date(), parse(), Q_ASSERT, QDateTimeParser::StateNode::state, time, QDateTime::time(), QTimeZone::UTC, and QDateTimeParser::StateNode::value.

+ Here is the call graph for this function:

◆ fromString() [2/2]

bool QDateTimeParser::fromString ( const QString text,
QDateTime datetime 
) const

Definition at line 2187 of file qdatetimeparser.cpp.

References Acceptable, QDateTimeParser::StateNode::conflicts, QDateTime::isValid(), parse(), QDate::startOfDay(), QDateTimeParser::StateNode::state, and QDateTimeParser::StateNode::value.

+ Here is the call graph for this function:

◆ getDigit()

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

Gets the digit from a datetime. E.g.

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

Definition at line 48 of file qdatetimeparser.cpp.

References AmPmSection, calendar, QCalendar::dayOfWeek(), DayOfWeekSectionLong, DayOfWeekSectionShort, DaySection, Hour12Section, Hour24Section, MinuteSection, MonthSection, MSecSection, qUtf16Printable, qWarning, SecondSection, sectionNodes, TimeZoneSection, QDateTimeParser::SectionNode::type, YearSection, and YearSection2Digits.

Referenced by parse(), skipToNextSection(), and QDateTimeEditPrivate::stepBy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMaximum()

QDateTime QDateTimeParser::getMaximum ( ) const
protectedvirtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 2207 of file qdatetimeparser.cpp.

References QDATETIMEEDIT_DATE_MAX.

Referenced by QDateTimeEditPrivate::getMaximum(), parse(), and skipToNextSection().

+ Here is the caller graph for this function:

◆ getMinimum()

QDateTime QDateTimeParser::getMinimum ( ) const
protectedvirtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 2196 of file qdatetimeparser.cpp.

References QDATETIMEEDIT_DATE_MIN.

Referenced by QDateTimeEditPrivate::getMinimum(), parse(), and skipToNextSection().

+ Here is the caller graph for this function:

◆ locale()

virtual QLocale QDateTimeParser::locale ( ) const
inlineprotectedvirtual

Reimplemented in QDateTimeEditPrivate.

Definition at line 234 of file qdatetimeparser_p.h.

◆ parse()

QDateTimeParser::StateNode QDateTimeParser::parse ( const QString input,
int  position,
const QDateTime defaultValue,
bool  fixup 
) const

◆ parseFormat()

◆ sectionMaxSize()

int QDateTimeParser::sectionMaxSize ( int  index) const
protected

Definition at line 724 of file qdatetimeparser.cpp.

References QDateTimeParser::SectionNode::count, sectionNode(), and QDateTimeParser::SectionNode::type.

+ Here is the call graph for this function:

◆ sectionNode()

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

Returns the sectionNode for the Section s.

Definition at line 300 of file qdatetimeparser.cpp.

References first, FirstSectionIndex, last, LastSectionIndex, none, NoSectionIndex, qWarning, and sectionNodes.

Referenced by QDateTimeEditPrivate::_q_editorCursorPositionChanged(), absoluteMax(), absoluteMin(), fieldInfo(), sectionMaxSize(), sectionPos(), sectionText(), sectionType(), QDateTimeEditPrivate::setSelected(), skipToNextSection(), and QDateTimeEditPrivate::stepBy().

+ Here is the caller graph for this function:

◆ sectionPos() [1/2]

int QDateTimeParser::sectionPos ( const SectionNode sn) const
protected

Definition at line 337 of file qdatetimeparser.cpp.

References displayText(), FirstSection, LastSection, QDateTimeParser::SectionNode::name(), QDateTimeParser::SectionNode::pos, qUtf16Printable, qWarning, QString::size(), and QDateTimeParser::SectionNode::type.

+ Here is the call graph for this function:

◆ sectionPos() [2/2]

int QDateTimeParser::sectionPos ( int  sectionIndex) const
protected

Returns the starting position for section s.

Definition at line 332 of file qdatetimeparser.cpp.

References sectionNode(), and sectionPos().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sectionSize()

int QDateTimeParser::sectionSize ( int  sectionIndex) const
protected

Returns the size of section s.

Definition at line 605 of file qdatetimeparser.cpp.

References begin(), context, DateTimeEdit, displayText(), m_text, qWarning, sectionNodes, sectionPos(), separators, and QString::size().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sectionText()

QString QDateTimeParser::sectionText ( int  sectionIndex) const
protected

Definition at line 752 of file qdatetimeparser.cpp.

References displayText(), QDateTimeParser::SectionNode::pos, and sectionNode().

+ Here is the call graph for this function:

◆ sectionType()

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

Definition at line 320 of file qdatetimeparser.cpp.

References sectionNode(), and QDateTimeParser::SectionNode::type.

Referenced by parseFormat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCalendar()

void QDateTimeParser::setCalendar ( const QCalendar cal)

Sets cal as the calendar to use.

The default is Gregorian.

Definition at line 2246 of file qdatetimeparser.cpp.

References calendar.

◆ setDefaultLocale()

void QDateTimeParser::setDefaultLocale ( const QLocale loc)
inline

Definition at line 153 of file qdatetimeparser_p.h.

◆ setDigit()

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

Sets a digit in a datetime. 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 118 of file qdatetimeparser.cpp.

References absoluteMax(), absoluteMin(), AmPmSection, cachedDay, calendar, date, QCalendar::dateFromParts(), QDate::day(), QCalendar::dayOfWeek(), dayOfWeekDiff(), DayOfWeekSectionLong, DayOfWeekSectionShort, DaySection, DaySectionMask, QCalendar::daysInMonth(), QTimeZone::fromSecondsAheadOfUtc(), QTime::hour(), Hour12Section, Hour24Section, QDate::isValid(), QTime::isValid(), QTime::minute(), MinuteSection, QDate::month(), MonthSection, QTime::msec(), MSecSection, QDateTimeParser::SectionNode::name(), QCalendar::partsFromDate(), preferDayOfWeek(), Q_ASSERT, qUtf16Printable, qWarning, QTime::second(), SecondSection, sectionNodes, time, TimeZoneSection, QDateTimeParser::SectionNode::type, WeekDay(), QDate::year(), YearSection, and YearSection2Digits.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipToNextSection() [1/2]

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

Definition at line 225 of file qdatetimeparser_p.h.

◆ skipToNextSection() [2/2]

bool QDateTimeParser::skipToNextSection ( int  index,
const QDateTime current,
QStringView  text 
) const
protected

Definition at line 2085 of file qdatetimeparser.cpp.

References absoluteMax(), absoluteMin(), cursorPosition(), getDigit(), getMaximum(), getMinimum(), Qt::OffsetFromUTC, pos, QDateTimeParser::SectionNode::pos, Q_ASSERT, sectionNode(), setDigit(), QString::size(), text, QDateTime::timeSpec(), TimeZoneSection, and QDateTimeParser::SectionNode::type.

+ Here is the call graph for this function:

◆ stateName()

QString QDateTimeParser::stateName ( State  s) const
protected

For debugging. Returns the name of the state s.

Definition at line 2150 of file qdatetimeparser.cpp.

References Acceptable, Intermediate, Invalid, and QString::number().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QDTPUnitTestParser

friend class QDTPUnitTestParser
friend

Definition at line 207 of file qdatetimeparser_p.h.

Member Data Documentation

◆ cachedDay

int QDateTimeParser::cachedDay = -1
mutableprotected

◆ calendar

◆ context

Context QDateTimeParser::context
protected

Definition at line 260 of file qdatetimeparser_p.h.

Referenced by parse(), parseFormat(), and sectionSize().

◆ currentSectionIndex

◆ defaultLocale

QLocale QDateTimeParser::defaultLocale
protected

Definition at line 257 of file qdatetimeparser_p.h.

◆ display

Sections QDateTimeParser::display
protected

Definition at line 237 of file qdatetimeparser_p.h.

◆ displayFormat

QString QDateTimeParser::displayFormat
protected

Definition at line 256 of file qdatetimeparser_p.h.

Referenced by parseFormat().

◆ first

SectionNode QDateTimeParser::first
protected

Definition at line 254 of file qdatetimeparser_p.h.

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

◆ fixday

bool QDateTimeParser::fixday = false
protected

Definition at line 259 of file qdatetimeparser_p.h.

Referenced by QDateTimeEditPrivate::QDateTimeEditPrivate().

◆ last

SectionNode QDateTimeParser::last
protected

Definition at line 254 of file qdatetimeparser_p.h.

Referenced by parseFormat(), and sectionNode().

◆ m_text

QString QDateTimeParser::m_text
mutableprotected

◆ none

SectionNode QDateTimeParser::none
protected

Definition at line 254 of file qdatetimeparser_p.h.

Referenced by sectionNode().

◆ parserType

QMetaType::Type QDateTimeParser::parserType
protected

Definition at line 258 of file qdatetimeparser_p.h.

Referenced by parseFormat().

◆ popup

SectionNode QDateTimeParser::popup
protected

Definition at line 254 of file qdatetimeparser_p.h.

◆ sectionNodes

◆ separators


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