diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-09-14 00:00:42 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-02-02 22:23:17 +0000 |
commit | a9066ecf646134009494f68a0365d4549d999c66 (patch) | |
tree | 03c2ab17126c29eac145db5226ad228fb2146b3f /src | |
parent | 3e14bb04b7c052aabb3c5ae0d6a2dd8916f6e543 (diff) |
QCalendarWidget: avoid three dynamic allocations
The three validators in QCalendarDateValidator were heap-allocated,
but the pointers were never reseated.
Allocate by-value instead.
Text size savings are minimal.
Change-Id: I99401e29cfc8371656a17fba4affd5c6ffd6ad53
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/widgets/qcalendarwidget.cpp | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 09fc6fa10f..2f9c87ad7e 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -463,9 +463,9 @@ private: QStringList m_separators; QList<SectionToken *> m_tokens; - QCalendarDateSectionValidator *m_yearValidator; - QCalendarDateSectionValidator *m_monthValidator; - QCalendarDateSectionValidator *m_dayValidator; + QCalendarYearValidator m_yearValidator; + QCalendarMonthValidator m_monthValidator; + QCalendarDayValidator m_dayValidator; SectionToken *m_currentToken; @@ -481,23 +481,17 @@ QCalendarDateValidator::QCalendarDateValidator() m_currentDate(m_initialDate), m_lastSectionMove(QCalendarDateSectionValidator::ThisSection) { - m_yearValidator = new QCalendarYearValidator(); - m_monthValidator = new QCalendarMonthValidator(); - m_dayValidator = new QCalendarDayValidator(); } void QCalendarDateValidator::setLocale(const QLocale &locale) { - m_yearValidator->m_locale = locale; - m_monthValidator->m_locale = locale; - m_dayValidator->m_locale = locale; + m_yearValidator.m_locale = locale; + m_monthValidator.m_locale = locale; + m_dayValidator.m_locale = locale; } QCalendarDateValidator::~QCalendarDateValidator() { - delete m_yearValidator; - delete m_monthValidator; - delete m_dayValidator; clear(); } @@ -514,9 +508,9 @@ int QCalendarDateValidator::countRepeat(const QString &str, int index) const void QCalendarDateValidator::setInitialDate(const QDate &date) { - m_yearValidator->setDate(date); - m_monthValidator->setDate(date); - m_dayValidator->setDate(date); + m_yearValidator.setDate(date); + m_monthValidator.setDate(date); + m_dayValidator.setDate(date); m_initialDate = date; m_currentDate = date; m_lastSectionMove = QCalendarDateSectionValidator::ThisSection; @@ -576,13 +570,13 @@ void QCalendarDateValidator::setFormat(const QString &format) SectionToken *token = 0; if (nextChar == QLatin1Char('d')) { offset = qMin(4, countRepeat(format, pos)); - token = new SectionToken(m_dayValidator, offset); + token = new SectionToken(&m_dayValidator, offset); } else if (nextChar == QLatin1Char('M')) { offset = qMin(4, countRepeat(format, pos)); - token = new SectionToken(m_monthValidator, offset); + token = new SectionToken(&m_monthValidator, offset); } else if (nextChar == QLatin1Char('y')) { offset = qMin(4, countRepeat(format, pos)); - token = new SectionToken(m_yearValidator, offset); + token = new SectionToken(&m_yearValidator, offset); } else { separator += nextChar; } @@ -603,9 +597,9 @@ void QCalendarDateValidator::setFormat(const QString &format) void QCalendarDateValidator::applyToDate() { - m_currentDate = m_yearValidator->applyToDate(m_currentDate); - m_currentDate = m_monthValidator->applyToDate(m_currentDate); - m_currentDate = m_dayValidator->applyToDate(m_currentDate); + m_currentDate = m_yearValidator.applyToDate(m_currentDate); + m_currentDate = m_monthValidator.applyToDate(m_currentDate); + m_currentDate = m_dayValidator.applyToDate(m_currentDate); } void QCalendarDateValidator::toNextToken() |