Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 "qdebug.h"
31#include <QtCore/qpointer.h>
32
34
35class QCalendarPopup;
37{
38 Q_DECLARE_PUBLIC(QDateTimeEdit)
39public:
41
42 void init(const QVariant &var);
43 void readLocaleSettings();
44
45 QDateTime validateAndInterpret(QString &input, int &, QValidator::State &state,
46 bool fixup = false) const;
47 void clearSection(int index);
48
49 // Override QAbstractSpinBoxPrivate:
50 void emitSignals(EmitPolicy ep, const QVariant &old) override;
51 QString textFromValue(const QVariant &f) const override;
52 QVariant valueFromText(const QString &f) const override;
53 void editorCursorPositionChanged(int oldpos, int newpos) override;
54 void interpret(EmitPolicy ep) override;
55 void clearCache() const override;
57 void updateEditFieldGeometry() override;
58 QVariant getZeroVariant() const override;
59 void setRange(const QVariant &min, const QVariant &max) override;
60 void updateEdit() override;
61
62 // Override QDateTimeParser:
63 QString displayText() const override { return edit->text(); }
64 QDateTime getMinimum() const override;
65 QDateTime getMaximum() const override;
66 QLocale locale() const override { return q_func()->locale(); }
67 int cursorPosition() const override { return edit ? edit->cursorPosition() : -1; }
68
69 int absoluteIndex(QDateTimeEdit::Section s, int index) const;
70 int absoluteIndex(SectionNode s) const;
71 QDateTime stepBy(int index, int steps, bool test = false) const;
72 int sectionAt(int pos) const;
73 int closestSection(int index, bool forward) const;
74 int nextPrevSection(int index, bool forward) const;
75 void setSelected(int index, bool forward = false);
76
77 void updateCache(const QVariant &val, const QString &str) const;
78
79 QDateTime convertTimeZone(const QDateTime &datetime);
80 void updateTimeZone();
81 QString valueToText(const QVariant &var) const { return textFromValue(var); }
82 QDateTime dateTimeValue(QDate date, QTime time) const;
83
84 void _q_resetButton();
85 void updateArrow(QStyle::StateFlag state);
86 bool calendarPopupEnabled() const;
87 void syncCalendarWidget();
88
89 bool isSeparatorKey(const QKeyEvent *k) const;
90
91 static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s);
93
94 void initCalendarPopup(QCalendarWidget *cw = nullptr);
95 void positionCalendarPopup();
96
97 QDateTimeEdit::Sections sections = {};
98 mutable bool cacheGuard = false;
99
100 QString defaultDateFormat, defaultTimeFormat, defaultDateTimeFormat, unreversedFormat;
102 bool hasHadFocus = false, formatExplicitlySet = false, calendarPopup = false;
104 QCalendarPopup *monthCalendar = nullptr;
105
106#ifdef QT_KEYPAD_NAVIGATION
107 bool focusOnButton = false;
108#endif
109
111};
112
113
115{
117public:
118 explicit QCalendarPopup(QWidget *parent = nullptr, QCalendarWidget *cw = nullptr,
119 QCalendar ca = QCalendar());
120 QDate selectedDate() { return verifyCalendarInstance()->selectedDate(); }
121 void setDate(QDate date);
122 void setDateRange(QDate min, QDate max);
123 void setFirstDayOfWeek(Qt::DayOfWeek dow) { verifyCalendarInstance()->setFirstDayOfWeek(dow); }
124 QCalendarWidget *calendarWidget() const { return const_cast<QCalendarPopup*>(this)->verifyCalendarInstance(); }
128 void newDateSelected(QDate newDate);
129 void hidingCalendar(QDate oldDate);
131
132private Q_SLOTS:
133 void dateSelected(QDate date);
134 void dateSelectionChanged();
135
136protected:
137 void hideEvent(QHideEvent *) override;
138 void mousePressEvent(QMouseEvent *e) override;
139 void mouseReleaseEvent(QMouseEvent *) override;
140 bool event(QEvent *e) override;
141
142private:
143 QCalendarWidget *verifyCalendarInstance();
144
145 QPointer<QCalendarWidget> calendar;
146 QDate oldDate;
147 bool dateChanged;
148 QCalendar calendarSystem;
149};
150
152
153#endif // QDATETIMEEDIT_P_H
virtual QVariant valueFromText(const QString &input) const
virtual void emitSignals(EmitPolicy ep, const QVariant &old)
virtual QStyle::SubControl newHoverControl(const QPoint &pos)
virtual QVariant getZeroVariant() const
virtual void editorCursorPositionChanged(int oldpos, int newpos)
virtual void setRange(const QVariant &min, const QVariant &max)
virtual void interpret(EmitPolicy ep)
virtual void updateEditFieldGeometry()
virtual QString textFromValue(const QVariant &n) const
virtual void clearCache() const
void activated(QDate date)
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)
void newDateSelected(QDate newDate)
QCalendarPopup(QWidget *parent=nullptr, QCalendarWidget *cw=nullptr, QCalendar ca=QCalendar())
void resetButton()
void setFirstDayOfWeek(Qt::DayOfWeek dow)
QCalendarWidget * calendarWidget() const
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date...
QDate selectedDate
the currently selected date.
void setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek)
The QCalendar class describes calendar systems.
Definition qcalendar.h:53
QLocale locale() const override
QString valueToText(const QVariant &var) const
int cursorPosition() const override
QString displayText() const override
The QDateTimeEdit class provides a widget for editing dates and times.
Section
\value NoSection \value AmPmSection \value MSecSection \value SecondSection \value MinuteSection \val...
virtual QDateTime getMaximum() const
virtual QDateTime getMinimum() const
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore \reentrant
Definition qdatetime.h:29
\inmodule QtCore
Definition qcoreevent.h:45
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
The QKeyEvent class describes a key event.
Definition qevent.h:424
int cursorPosition
The current cursor position for this line edit.
Definition qlineedit.h:37
QString text
The line edit's text.
Definition qlineedit.h:32
\inmodule QtGui
Definition qevent.h:196
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore\reentrant
Definition qpoint.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
StateFlag
This enum describes flags that are used when drawing primitive elements.
Definition qstyle.h:65
@ State_None
Definition qstyle.h:66
SubControl
This enum describes the available sub controls.
Definition qstyle.h:347
\inmodule QtCore
Definition qtimezone.h:26
\inmodule QtCore \reentrant
Definition qdatetime.h:215
State
This enum type defines the states in which a validated string can exist.
Definition qvalidator.h:30
\inmodule QtCore
Definition qvariant.h:65
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QString str
[2]
QDate date
[1]
else opt state
[0]
Combined button and popup list for selecting options.
DayOfWeek
GLuint index
[2]
GLfloat GLfloat f
struct _cl_event * event
GLdouble s
[6]
Definition qopenglext.h:235
GLuint GLfloat * val
GLenum GLenum GLenum input
static const struct TessellationWindingOrderTab cw[]
#define Q_AUTOTEST_EXPORT
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
spinBox stepBy(1)