Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdatetimeedit_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDATETIMEEDIT_P_H
5#define QDATETIMEEDIT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include <QtCore/qcalendar.h>
20#include <QtCore/qdatetime.h>
21#include <QtCore/qtimezone.h>
22#include "QtWidgets/qcalendarwidget.h"
23#include "QtWidgets/qspinbox.h"
24#include "QtWidgets/qtoolbutton.h"
25#include "QtWidgets/qmenu.h"
26#include "QtWidgets/qdatetimeedit.h"
27#include "private/qabstractspinbox_p.h"
28#include "private/qdatetimeparser_p.h"
29
30#include <QtCore/qpointer.h>
31
32QT_BEGIN_NAMESPACE
33
34class QCalendarPopup;
35class Q_AUTOTEST_EXPORT QDateTimeEditPrivate : public QAbstractSpinBoxPrivate, public QDateTimeParser
36{
37 Q_DECLARE_PUBLIC(QDateTimeEdit)
38public:
39 QDateTimeEditPrivate(const QTimeZone &zone = QTimeZone::LocalTime);
40
41 void init(const QVariant &var);
42 void readLocaleSettings();
43
44 QDateTime validateAndInterpret(QString &input, int &, QValidator::State &state,
45 bool fixup = false) const;
46 void clearSection(int index);
47
48 // Override QAbstractSpinBoxPrivate:
49 void emitSignals(EmitPolicy ep, const QVariant &old) override;
50 QString textFromValue(const QVariant &f) const override;
51 QVariant valueFromText(const QString &f) const override;
52 void editorCursorPositionChanged(int oldpos, int newpos) override;
53 void interpret(EmitPolicy ep) override;
54 void clearCache() const override;
55 QStyle::SubControl newHoverControl(const QPoint &pos) override;
56 void updateEditFieldGeometry() override;
57 QVariant getZeroVariant() const override;
58 void setRange(const QVariant &min, const QVariant &max) override;
59 void updateEdit() override;
60
61 // Override QDateTimeParser:
62 QString displayText() const override { return edit->text(); }
63 QDateTime getMinimum(const QTimeZone &zone) const override;
64 QDateTime getMaximum(const QTimeZone &zone) const override;
65 QLocale locale() const override { return q_func()->locale(); }
66 int cursorPosition() const override { return edit ? edit->cursorPosition() : -1; }
67
68 int absoluteIndex(QDateTimeEdit::Section s, int index) const;
69 int absoluteIndex(SectionNode s) const;
70 QDateTime stepBy(int index, int steps, bool test = false) const;
71 int sectionAt(int pos) const;
72 int closestSection(int index, bool forward) const;
73 int nextPrevSection(int index, bool forward) const;
74 void setSelected(int index, bool forward = false);
75
76 void updateCache(const QVariant &val, const QString &str) const;
77
78 QDateTime convertTimeZone(const QDateTime &datetime);
79 void updateTimeZone();
80 QString valueToText(const QVariant &var) const { return textFromValue(var); }
81 QDateTime dateTimeValue(QDate date, QTime time) const;
82
83 void _q_resetButton();
84 void updateArrow(QStyle::StateFlag state);
85 bool calendarPopupEnabled() const;
86 void syncCalendarWidget();
87
88 bool isSeparatorKey(const QKeyEvent *k) const;
89
90 static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s);
91 static QDateTimeEdit::Section convertToPublic(QDateTimeParser::Section s);
92
93 void initCalendarPopup(QCalendarWidget *cw = nullptr);
94 void positionCalendarPopup();
95
96 QDateTimeEdit::Sections sections = {};
97 mutable bool cacheGuard = false;
98
99 QString defaultDateFormat, defaultTimeFormat, defaultDateTimeFormat, unreversedFormat;
100 mutable QVariant conflictGuard;
101 bool hasHadFocus = false, formatExplicitlySet = false, calendarPopup = false;
102 QStyle::StateFlag arrowState = QStyle::State_None;
103 QCalendarPopup *monthCalendar = nullptr;
104
105#ifdef QT_KEYPAD_NAVIGATION
106 bool focusOnButton = false;
107#endif
108
109 QTimeZone timeZone;
110};
111
112
114{
116public:
117 explicit QCalendarPopup(QWidget *parent = nullptr, QCalendarWidget *cw = nullptr,
119 QDate selectedDate() { return verifyCalendarInstance()->selectedDate(); }
120 void setDate(QDate date);
121 void setDateRange(QDate min, QDate max);
122 void setFirstDayOfWeek(Qt::DayOfWeek dow) { verifyCalendarInstance()->setFirstDayOfWeek(dow); }
123 QCalendarWidget *calendarWidget() const { return const_cast<QCalendarPopup*>(this)->verifyCalendarInstance(); }
124 void setCalendarWidget(QCalendarWidget *cw);
127 void newDateSelected(QDate newDate);
128 void hidingCalendar(QDate oldDate);
130
131private Q_SLOTS:
132 void dateSelected(QDate date);
133 void dateSelectionChanged();
134
135protected:
136 void hideEvent(QHideEvent *) override;
137 void mousePressEvent(QMouseEvent *e) override;
138 void mouseReleaseEvent(QMouseEvent *) override;
139 bool event(QEvent *e) override;
140
141private:
142 QCalendarWidget *verifyCalendarInstance();
143
144 QPointer<QCalendarWidget> calendar;
145 QDate oldDate;
146 bool dateChanged;
147 QCalendar calendarSystem;
148};
149
150QT_END_NAMESPACE
151
152#endif // QDATETIMEEDIT_P_H
void mousePressEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void mouseReleaseEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void hidingCalendar(QDate oldDate)
void setCalendarWidget(QCalendarWidget *cw)
void setDate(QDate date)
void hideEvent(QHideEvent *) override
This event handler can be reimplemented in a subclass to receive widget hide events.
void setDateRange(QDate min, QDate max)
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void newDateSelected(QDate newDate)
void resetButton()
void setFirstDayOfWeek(Qt::DayOfWeek dow)
QCalendarWidget * calendarWidget() const