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

📄 qdatetimeedit.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        return false;    const int newSection = d->nextPrevSection(d->currentSectionIndex, next);    switch (d->sectionType(newSection)) {    case QDateTimeParser::NoSection:    case QDateTimeParser::FirstSection:    case QDateTimeParser::LastSection:        break;    default:        return false;    }    return QAbstractSpinBox::focusNextPrevChild(next);}/*!  \reimp*/void QDateTimeEdit::stepBy(int steps){    Q_D(QDateTimeEdit);    d->setValue(d->stepBy(d->currentSectionIndex, steps, false), EmitIfChanged);    d->updateCache(d->value, d->displayText());    d->setSelected(d->currentSectionIndex);}/*!  This virtual function is used by the date time edit whenever it  needs to display \a dateTime.  If you reimplement this, you may also need to reimplement  valueFromText() and validate().  \sa dateTimeFromText(), validate()*/QString QDateTimeEdit::textFromDateTime(const QDateTime &dateTime) const{    Q_D(const QDateTimeEdit);    return dateTime.toString(d->reversedFormat.isEmpty() ? d->displayFormat : d->reversedFormat);}/*!  Returns an appropriate datetime for the given \a text.  This virtual function is used by the datetime edit whenever it  needs to interpret text entered by the user as a value.  \sa textFromDateTime(), validate()*/QDateTime QDateTimeEdit::dateTimeFromText(const QString &text) const{    Q_D(const QDateTimeEdit);    QString copy = text;    int pos = d->edit->cursorPosition();    QValidator::State state = QValidator::Acceptable;    return d->validateAndInterpret(copy, pos, state).toDateTime();}/*!  \reimp*/QValidator::State QDateTimeEdit::validate(QString &text, int &pos) const{    Q_D(const QDateTimeEdit);    QValidator::State state;    d->validateAndInterpret(text, pos, state);    return state;}/*!  \reimp*/void QDateTimeEdit::fixup(QString &input) const{    Q_D(const QDateTimeEdit);    QValidator::State state;    int copy = d->edit->cursorPosition();    d->validateAndInterpret(input, copy, state, true);}/*!  \reimp*/QDateTimeEdit::StepEnabled QDateTimeEdit::stepEnabled() const{    Q_D(const QDateTimeEdit);    if (d->readOnly)        return StepEnabled(0);    if (d->specialValue()) {        if (d->minimum == d->maximum)            return StepEnabled(0);        return d->wrapping            ? StepEnabled(StepDownEnabled|StepUpEnabled)            : StepEnabled(StepUpEnabled);    }    switch (d->sectionType(d->currentSectionIndex)) {    case QDateTimeParser::NoSection:    case QDateTimeParser::FirstSection:    case QDateTimeParser::LastSection: return 0;    default: break;    }    if (!style()->styleHint(QStyle::SH_SpinControls_DisableOnBounds)        || d->wrapping)        return StepEnabled(StepUpEnabled | StepDownEnabled);    QAbstractSpinBox::StepEnabled ret = 0;    QVariant v = d->stepBy(d->currentSectionIndex, 1, true);    if (v != d->value) {        ret |= QAbstractSpinBox::StepUpEnabled;    }    v = d->stepBy(d->currentSectionIndex, -1, true);    if (v != d->value) {        ret |= QAbstractSpinBox::StepDownEnabled;    }    return ret;}/*!  \class QTimeEdit  \brief The QTimeEdit class provides a widget for editing times based on  the QDateTimeEdit widget.  \ingroup basic  \mainclass  Many of the properties and functions provided by QTimeEdit are implemented in  QDateTimeEdit. The following properties are most relevant to users of this  class:  \list  \o \l{QDateTimeEdit::time}{time} holds the date displayed by the widget.  \o \l{QDateTimeEdit::minimumTime}{minimumTime} defines the minimum (earliest) time     that can be set by the user.  \o \l{QDateTimeEdit::maximumTime}{maximumTime} defines the maximum (latest) time     that can be set by the user.  \o \l{QDateTimeEdit::displayFormat}{displayFormat} contains a string that is used     to format the time displayed in the widget.  \endlist  \table 100%  \row \o \inlineimage windowsxp-timeedit.png Screenshot of a Windows XP style time editing widget       \o A time editing widget shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}.  \row \o \inlineimage macintosh-timeedit.png Screenshot of a Macintosh style time editing widget       \o A time editing widget shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}.  \row \o \inlineimage plastique-timeedit.png Screenshot of a Plastique style time editing widget       \o A time editing widget shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}.  \endtable  \sa QDateEdit, QDateTimeEdit*//*!  Constructs an empty time editor with a \a parent.*/QTimeEdit::QTimeEdit(QWidget *parent)    : QDateTimeEdit(QTIME_MIN, parent){}/*!  Constructs an empty time editor with a \a parent. The time is set  to \a time.*/QTimeEdit::QTimeEdit(const QTime &time, QWidget *parent)    : QDateTimeEdit(time, parent){}/*!  \class QDateEdit  \brief The QDateEdit class provides a widget for editing dates based on  the QDateTimeEdit widget.  \ingroup basic  \mainclass  Many of the properties and functions provided by QDateEdit are implemented in  QDateTimeEdit. The following properties are most relevant to users of this  class:  \list  \o \l{QDateTimeEdit::date}{date} holds the date displayed by the widget.  \o \l{QDateTimeEdit::minimumDate}{minimumDate} defines the minimum (earliest)     date that can be set by the user.  \o \l{QDateTimeEdit::maximumDate}{maximumDate} defines the maximum (latest) date     that can be set by the user.  \o \l{QDateTimeEdit::displayFormat}{displayFormat} contains a string that is used     to format the date displayed in the widget.  \endlist  \table 100%  \row \o \inlineimage windowsxp-dateedit.png Screenshot of a Windows XP style date editing widget       \o A date editing widget shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}.  \row \o \inlineimage macintosh-dateedit.png Screenshot of a Macintosh style date editing widget       \o A date editing widget shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}.  \row \o \inlineimage plastique-dateedit.png Screenshot of a Plastique style date editing widget       \o A date editing widget shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}.  \endtable  \sa QTimeEdit, QDateTimeEdit*//*!  Constructs an empty date editor with a \a parent.*/QDateEdit::QDateEdit(QWidget *parent)    : QDateTimeEdit(QDATE_INITIAL, parent){}/*!  Constructs an empty date editor with a \a parent. The date is set  to \a date.*/QDateEdit::QDateEdit(const QDate &date, QWidget *parent)    : QDateTimeEdit(date, parent){}// --- QDateTimeEditPrivate ---/*!  \internal  Constructs a QDateTimeEditPrivate object*/QDateTimeEditPrivate::QDateTimeEditPrivate()    : QDateTimeParser(QVariant::DateTime){    cacheGuard = false;    fixday = true;    allowEmpty = false;    type = QVariant::DateTime;    sections = 0;    cachedDay = -1;    currentSectionIndex = FirstSectionIndex;    if (currentSectionIndex >= sectionNodes.size())        qFatal("%d currentSectionIndex >= sectionNodes.size()) %d %d", __LINE__,               currentSectionIndex, sectionNodes.size());    layoutDirection = QApplication::layoutDirection();    first.type = FirstSection;    last.type = LastSection;    none.type = NoSection;    first.pos = 0;    last.pos = -1;    none.pos = -1;    sections = 0;    readLocaleSettings();}void QDateTimeEditPrivate::updateEdit(){    const QString newText = specialValue() ? specialValueText : textFromValue(value);    if (newText == displayText())        return;    int selsize = edit->selectedText().size();    const bool sb = edit->blockSignals(true);    edit->setText(newText);    if (!specialValue()) {        int cursor = sectionPos(currentSectionIndex);        QDTEDEBUG << "cursor is " << cursor << currentSectionIndex;        cursor = qBound(0, cursor, displayText().size());        QDTEDEBUG << cursor;        if (selsize > 0) {            edit->setSelection(cursor, selsize);            QDTEDEBUG << cursor << selsize;        } else {            edit->setCursorPosition(cursor);            QDTEDEBUG << cursor;        }    }    edit->blockSignals(sb);}/*!  \internal  Selects the section \a s. If \a forward is false selects backwards.*/void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward){    if (specialValue()) {        edit->selectAll();    } else {        const SectionNode &node = sectionNode(sectionIndex);        if (node.type == NoSection || node.type == LastSection || node.type == FirstSection)            return;        updateCache(value, displayText());        const int size = sectionSize(sectionIndex);        if (forward) {            edit->setSelection(sectionPos(node), size);        } else {            edit->setSelection(sectionPos(node) + size, -size);        }    }}/*!  \internal  Returns the section at index \a index or NoSection if there are no sections there.*/int QDateTimeEditPrivate::sectionAt(int pos) const{    if (pos < separators.first().size()) {        return (pos == 0 ? FirstSectionIndex : NoSectionIndex);    } else if (displayText().size() - pos < separators.last().size() + 1) {        if (separators.last().size() == 0) {            return sectionNodes.count() - 1;        }        return (pos == displayText().size() ? LastSectionIndex : NoSectionIndex);    }    updateCache(value, displayText());    for (int i=0; i<sectionNodes.size(); ++i) {        const int tmp = sectionPos(i);        if (pos < tmp + sectionSize(i)) {            return (pos < tmp ? -1 : i);        }    }    return -1;}/*!  \internal  Returns the closest section of index \a index. Searches forward  for a section if \a forward is true. Otherwise searches backwards.*/int QDateTimeEditPrivate::closestSection(int pos, bool forward) const{    Q_ASSERT(pos >= 0);    if (pos < separators.first().size()) {        return forward ? 0 : FirstSectionIndex;    } else if (displayText().size() - pos < separators.last().size() + 1) {        return forward ? LastSectionIndex : sectionNodes.size() - 1;    }    updateCache(value, displayText());    for (int i=0; i<sectionNodes.size(); ++i) {        const int tmp = sectionPos(sectionNodes.at(i));        if (pos < tmp + sectionSize(i)) {            if (pos < tmp && !forward) {                return i-1;            }            return i;        } else if (i == sectionNodes.size() - 1 && pos > tmp) {            return i;        }    }    qWarning("closestSection return NoSection. This should not happen");    return NoSectionIndex;}/*!  \internal  Returns a copy of the section that is before or after \a current, depending on \a forward.*/int QDateTimeEditPrivate::nextPrevSection(int current, bool forward) const{    if (QApplication::isRightToLeft())        forward = !forward;    switch (current) {    case FirstSectionIndex: return forward ? 0 : FirstSectionIndex;    case LastSectionIndex: return (forward ? LastSectionIndex : sectionNodes.size() - 1);    case NoSectionIndex: return FirstSectionIndex;    default: break;    }    Q_ASSERT(current >= 0 && current < sectionNodes.size());    current += (forward ? 1 : -1);    if (current >= sectionNodes.size()) {        return LastSectionIndex;    } else if (current < 0) {        return FirstSectionIndex;    }    return current;}/*!  \internal  Clears the text of section \a s.*/void QDateTimeEditPrivate::clearSection(int index){

⌨️ 快捷键说明

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