⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qextdatetimevalidator.cpp

📁 Linux/Windows 环境下的跨平台开发程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        startIndex=i;
        if (FormatString[i]=='%') {
            
            CurToken->Type=TYPE_SPECIFIER;

            /*parse specifier string - up to and including first alphabetic or % character*/
            CompleteToken=FALSE;
            while (!CompleteToken) {
                CurToken->SpecString.append(FormatString[i]);

                /*end of token is a letter, whitespace, end of format string, or start of a new 
                  token (% character)*/
                if (isalpha(FormatString[i]) || isspace(FormatString[i]) || !FormatString[i] || 
                    (FormatString[i]=='%' && i!=startIndex)) {
                    CompleteToken=TRUE;

                    /*if 2 % signs in a row, this code prevents the parser from 
                      "eating" the second one*/
                    if (FormatString[i]=='%' && i!=startIndex) {
                        CurToken->SpecString.truncate(CurToken->SpecString.length()-1);
                        i--;
                    }

                    /*validate specifier - if not recognized, treat as a literal*/
                    switch(FormatString[i]) {
                        case 'a':
                        case 'A':
                            CurToken->FType=FIELD_AMPM;
                            CurToken->MinSize=2;
                            CurToken->MaxSize=2;
                            CurToken->IsFixedSize=TRUE;
                            break;

                        case 'n':
                            CurToken->FType=FIELD_MINUTE;
                            CurToken->MinSize=2;
                            CurToken->MaxSize=2;
                            CurToken->IsFixedSize=TRUE;
                            break;

                        case 's':
                            CurToken->FType=FIELD_SECOND;
                            CurToken->MinSize=2;
                            CurToken->MaxSize=2;
                            CurToken->IsFixedSize=TRUE;
                            break;

                        case 'y':
                            CurToken->FType=FIELD_YEAR_2;
                            CurToken->MinSize=2;
                            CurToken->MaxSize=2;
                            CurToken->IsFixedSize=TRUE;
                            break;

                        case 'Y':
                            CurToken->FType=FIELD_YEAR_4;
                            CurToken->MinSize=4;
                            CurToken->MaxSize=4;
                            CurToken->IsFixedSize=TRUE;
                            break;

                        case 'd':
                            CurToken->FType=FIELD_DAY;
                            if (((const char*)(CurToken->SpecString))[1]=='0') {
                                CurToken->MinSize=2;
                                CurToken->MaxSize=2;
                                CurToken->IsFixedSize=TRUE;
                            }
                            else {
                                CurToken->MinSize=1;
                                CurToken->MaxSize=2;
                                CurToken->IsFixedSize=FALSE;
                            }
                            break;

                        case 'H':
                            CurToken->FType=FIELD_HOUR_24;
                            if (((const char*)(CurToken->SpecString))[1]=='0') {
                                CurToken->MinSize=2;
                                CurToken->MaxSize=2;
                                CurToken->IsFixedSize=TRUE;
                            }
                            else {
                                CurToken->MinSize=1;
                                CurToken->MaxSize=2;
                                CurToken->IsFixedSize=FALSE;
                            }
                            break;

                        case 'h':
                            CurToken->FType=FIELD_HOUR_12;
                            if (((const char*)(CurToken->SpecString))[1]=='0') {
                                CurToken->MinSize=2;
                                CurToken->MaxSize=2;
                                CurToken->IsFixedSize=TRUE;
                            }
                            else {
                                CurToken->MinSize=1;
                                CurToken->MaxSize=2;
                                CurToken->IsFixedSize=FALSE;
                            }
                            break;

                        case 'M':
                            CurToken->FType=FIELD_MONTH;
                            if (((const char*)(CurToken->SpecString))[1]=='0') {
                                CurToken->MinSize=2;
                                CurToken->MaxSize=2;
                                CurToken->IsFixedSize=TRUE;
                            }
                            else {
                                CurToken->MinSize=1;
                                CurToken->MaxSize=2;
                                CurToken->IsFixedSize=FALSE;
                            }
                            break;

                        case 'm':
                            CurToken->FType=FIELD_MONTH_STRING;
                            CurToken->MinSize=MinMonthString;
                            CurToken->MaxSize=MaxMonthString;
                            CurToken->IsFixedSize=FALSE;
                            break;

                        case 'w':
                            CurToken->FType=FIELD_DAY_STRING;
                            CurToken->MinSize=MinDayString;
                            CurToken->MaxSize=MaxDayString;
                            CurToken->IsFixedSize=FALSE;
                            break;

                        default:
                            CurToken->Type=TYPE_LITERAL;
                            CurToken->FType=FIELD_LITERAL;
                            CurToken->IsFixedSize=TRUE;
                            CurToken->MinSize=CurToken->SpecString.length();
                            CurToken->MaxSize=CurToken->SpecString.length();
                            break;
                    }
                }
                for (; j<i; j++) {
                    if (isdigit(FormatString[j])) {
                        CurToken->IsFixedSize=TRUE;
                        
                        /*0 character in a format specifier indicates right-justification in the 
                        case of strings, or leading 0's in the case of numerics*/
                        CurToken->MinSize=CurToken->MaxSize;
                        if (FormatString[j]=='0') {
                            CurToken->IsRightJustified=TRUE;
                        }
                        else {
                            CurToken->TruncateLength*=10;
                            CurToken->TruncateLength+=FormatString[j]-'0';
                        }
                    }
                }
                i++;
            }
            if (CurToken->TruncateLength) {
                CurToken->MinSize=CurToken->TruncateLength;
                CurToken->MaxSize=CurToken->TruncateLength;
            }
        }
        else {
            CurToken->Type=TYPE_LITERAL;
            CurToken->FType=FIELD_LITERAL;
            CurToken->IsFixedSize=TRUE;

            /*parse literal string - everything up to next % character*/
            while (FormatString[i] && FormatString[i]!='%') {
                CurToken->SpecString.append(FormatString[i]);
                i++;
            }
            CurToken->MinSize=CurToken->SpecString.length();
            CurToken->MaxSize=CurToken->SpecString.length();
        }

        //Append new token to end of list
        temp=DisplayFormat;
        while (temp && temp->Next) {
            temp=temp->Next;
        }
        if (CurToken!=DisplayFormat) {
            temp->Next=CurToken;
        }
    }
}

/*!
\fn void QextDateTimeValidator::setFormat(const QString& format) 
Sets the date and time display format for the QextDateTimeSpinBox widget.
*/
void QextDateTimeValidator::setFormat(const QString& format) {
    Format=format;
    findStringLimits();
    parseFormat();
}

/*!
\fn void QextDateTimeValidator::setMaxDayStringSize(unsigned int newSize)
Sets the maximum length of the full name of a day of the week.
*/
void QextDateTimeValidator::setMaxDayStringSize(unsigned int newSize) {
    MaxDayString=newSize;
}

/*!
\fn void QextDateTimeValidator::setMaxMonthStringSize(unsigned int newSize)
Sets the maximum length of the full name of a month of the year.
*/
void QextDateTimeValidator::setMaxMonthStringSize(unsigned int newSize) {
    MaxMonthString=newSize;
}

/*!
\fn void QextDateTimeValidator::setMinDayStringSize(unsigned int newSize)
Sets the minimum length of the full name of a day of the week.
*/
void QextDateTimeValidator::setMinDayStringSize(unsigned int newSize) {
    MinDayString=newSize;
}

/*!
\fn void QextDateTimeValidator::setMinMonthStringSize(unsigned int newSize)
Sets the minimum length of the full name of a month of the year.
*/
void QextDateTimeValidator::setMinMonthStringSize(unsigned int newSize) {
    MinMonthString=newSize;
}

/*!
\fn QValidator::State QextDateTimeValidator::validate(QString& input, int&) const
validates a string entered into a time spin box
*/
QValidator::State QextDateTimeValidator::validate(QString&, int&) const {
    return QValidator::Acceptable;
}

/*!
\fn QString QextDateTimeValidator::longMonthName(int month) const
returns the month name for the month specified.  By default, longMonthName(1) will return 
"January", etc.
*/
QString QextDateTimeValidator::longMonthName(int month) const {
    return monthNames[month-1];
}

/*!
\fn QString QextDateTimeValidator::longDayName(int dayNum) const
returns the day name for the day of the week specified.  By default longDayName(1) will return 
"Monday", etc.  Note that this is different from the American week which starts with Sunday.  This
is to maintain consistency with the QT 3.0 function QDate::longDayName().
*/
QString QextDateTimeValidator::longDayName(int dayNum) const {
    return dayNames[dayNum-1];    
}

/*!
\fn void QextDateTimeValidator::setLongMonthNames(const QStringList& names)
Sets the names of the months.  The QStringList reference passed in is assumed to have at least 12
QStrings in it; any after the first 12 will be ignored.
*/
void QextDateTimeValidator::setLongMonthNames(const QStringList& names) {
    QStringList::ConstIterator i=names.begin();
    int j;
    for (j=0; j<12; j++) {
        monthNames[j]=*i;
        i++;
    }
}

/*!
void QextDateTimeValidator::setLongDayNames(const QStringList& names)
Sets the names of days of the week.  Note that Monday is assumed to map to the first element, and 
Sunday to the last.  This is for consistency with the behavior of QDate.  The QStringList passed 
in is assumed to have at least 7 elements.  Any elements beyond the first 7 are ignored.
*/
void QextDateTimeValidator::setLongDayNames(const QStringList& names) {
    QStringList::ConstIterator i=names.begin();
    int j;
    for (j=0; j<7; j++) {
        dayNames[j]=*i;
        i++;
    }
}

/*!
\fn void QextDateTimeSpinBox::setStrings(const QStringList* days, const QStringList* months)
Sets the strings used to represent the daysof the week and the months of the year.  By 
default these strings are English.
*/
void QextDateTimeValidator::setStrings(const QStringList& days, const QStringList& months) {
    setLongMonthNames(months);
    setLongDayNames(days);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -