QDateTime{Parser,EditPrivate}: clean up initialization

Initialize members by assigning them where declared, where possible,
rather than duplicating initializations in constructors.

Change-Id: I35c398581ad649210aaec979ea7c6c2fc2cb0bca
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Edward Welbourne 2021-06-01 18:26:10 +02:00
parent a15a3fef0b
commit 5dff645db0
3 changed files with 12 additions and 25 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@ -83,8 +83,7 @@ public:
DateTimeEdit
};
QDateTimeParser(QMetaType::Type t, Context ctx, const QCalendar &cal = QCalendar())
: currentSectionIndex(-1), cachedDay(-1), parserType(t),
fixday(false), context(ctx), calendar(cal)
: parserType(t), context(ctx), calendar(cal)
{
defaultLocale = QLocale::system();
first.type = FirstSection;
@ -270,7 +269,7 @@ protected: // for the benefit of QDateTimeEditPrivate
virtual int cursorPosition() const { return -1; }
virtual QLocale locale() const { return defaultLocale; }
mutable int currentSectionIndex;
mutable int currentSectionIndex = int(NoSectionIndex);
Sections display;
/*
This stores the most recently selected day.
@ -285,7 +284,7 @@ protected: // for the benefit of QDateTimeEditPrivate
This is good for when users have selected their desired day and are scrolling up or down in the month or year section
and do not want smaller months (or non-leap years) to alter the day that they chose.
*/
mutable int cachedDay;
mutable int cachedDay = -1;
mutable QString m_text;
QList<SectionNode> sectionNodes;
SectionNode first, last, none, popup;
@ -293,7 +292,7 @@ protected: // for the benefit of QDateTimeEditPrivate
QString displayFormat;
QLocale defaultLocale;
QMetaType::Type parserType;
bool fixday;
bool fixday = false;
Context context;
QCalendar calendar;
};

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@ -1737,26 +1737,14 @@ QDateEdit::~QDateEdit()
QDateTimeEditPrivate::QDateTimeEditPrivate()
: QDateTimeParser(QMetaType::QDateTime, QDateTimeParser::DateTimeEdit, QCalendar())
{
hasHadFocus = false;
formatExplicitlySet = false;
cacheGuard = false;
fixday = true;
type = QMetaType::QDateTime;
sections = { };
cachedDay = -1;
currentSectionIndex = FirstSectionIndex;
first.pos = 0;
calendarPopup = false;
minimum = QDATETIMEEDIT_COMPAT_DATE_MIN.startOfDay();
maximum = QDATETIMEEDIT_DATE_MAX.endOfDay();
arrowState = QStyle::State_None;
monthCalendar = nullptr;
readLocaleSettings();
#ifdef QT_KEYPAD_NAVIGATION
focusOnButton = false;
#endif
}
QDateTime QDateTimeEditPrivate::convertTimeSpec(const QDateTime &datetime)

View File

@ -140,17 +140,17 @@ public:
void initCalendarPopup(QCalendarWidget *cw = nullptr);
void positionCalendarPopup();
QDateTimeEdit::Sections sections;
mutable bool cacheGuard;
QDateTimeEdit::Sections sections = {};
mutable bool cacheGuard = false;
QString defaultDateFormat, defaultTimeFormat, defaultDateTimeFormat, unreversedFormat;
mutable QVariant conflictGuard;
bool hasHadFocus, formatExplicitlySet, calendarPopup;
QStyle::StateFlag arrowState;
QCalendarPopup *monthCalendar;
bool hasHadFocus = false, formatExplicitlySet = false, calendarPopup = false;
QStyle::StateFlag arrowState = QStyle::State_None;
QCalendarPopup *monthCalendar = nullptr;
#ifdef QT_KEYPAD_NAVIGATION
bool focusOnButton;
bool focusOnButton = false;
#endif
Qt::TimeSpec spec = Qt::LocalTime;