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// Qt-Security score:significant reason:default
4
5#ifndef QDATETIMEEDIT_P_H
6#define QDATETIMEEDIT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
20#include <QtCore/qcalendar.h>
21#include <QtCore/qdatetime.h>
22#include <QtCore/qtimezone.h>
23#include "QtWidgets/qcalendarwidget.h"
24#include "QtWidgets/qspinbox.h"
25#include "QtWidgets/qtoolbutton.h"
26#include "QtWidgets/qmenu.h"
27#include "QtWidgets/qdatetimeedit.h"
28#include "private/qabstractspinbox_p.h"
29#include "private/qdatetimeparser_p.h"
30
31#include <QtCore/qpointer.h>
32
33QT_BEGIN_NAMESPACE
34
35class QCalendarPopup;
36class Q_AUTOTEST_EXPORT QDateTimeEditPrivate : public QAbstractSpinBoxPrivate, public QDateTimeParser
37{
38 Q_DECLARE_PUBLIC(QDateTimeEdit)
39public:
40 QDateTimeEditPrivate(const QTimeZone &zone = QTimeZone::LocalTime);
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;
56 QStyle::SubControl newHoverControl(const QPoint &pos) 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 QTimeZone &zone) const override;
65 QDateTime getMaximum(const QTimeZone &zone) 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);
92 static QDateTimeEdit::Section convertToPublic(QDateTimeParser::Section 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;
101 mutable QVariant conflictGuard;
102 bool hasHadFocus = false, formatExplicitlySet = false, calendarPopup = false;
103 QStyle::StateFlag arrowState = QStyle::State_None;
104 QCalendarPopup *monthCalendar = nullptr;
105
106#ifdef QT_KEYPAD_NAVIGATION
107 bool focusOnButton = false;
108#endif
109
110 QTimeZone timeZone;
111};
112
113
115{
117public:
118 explicit QCalendarPopup(QWidget *parent = nullptr, QCalendarWidget *cw = nullptr,
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(); }
125 void setCalendarWidget(QCalendarWidget *cw);
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
151QT_END_NAMESPACE
152
153#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