summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcalendarwidget.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-09-14 02:04:31 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-11-04 14:14:50 +0000
commita926f675be220ca6020039ac3640991b63a0fae7 (patch)
treeb4324abd8ff1eb84a525e114fa19055cbb2c0711 /src/widgets/widgets/qcalendarwidget.cpp
parent9a07ab9234ccb4ed0d6aa3a64b4b2c888635dae5 (diff)
QCalendarWidget: replace a QVector by std::vector
This allows to drop the default ctor and isNull() method of SectionToken again, and reduces text size on optimized AMD64 / GCC builds by a further 456 bytes. Change-Id: I7109c9a138dcc27c478c0827d6216a043f592992 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Diffstat (limited to 'src/widgets/widgets/qcalendarwidget.cpp')
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index 9857cce92a..5e6db46a63 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -53,6 +53,8 @@
#include <qbasictimer.h>
#include <qstylepainter.h>
+#include <vector>
+
QT_BEGIN_NAMESPACE
enum {
@@ -424,14 +426,11 @@ QString QCalendarYearValidator::text(const QDate &date, int repeat) const
///////////////////////////////////
struct SectionToken {
- Q_DECL_CONSTEXPR SectionToken() : validator(Q_NULLPTR), repeat(0) {}
Q_DECL_CONSTEXPR SectionToken(QCalendarDateSectionValidator *v, int rep)
: validator(v), repeat(rep) {}
QCalendarDateSectionValidator *validator;
int repeat;
-
- Q_DECL_CONSTEXPR bool isNull() const { return !validator; }
};
} // unnamed namespace
Q_DECLARE_TYPEINFO(SectionToken, Q_PRIMITIVE_TYPE);
@@ -460,7 +459,7 @@ private:
void clear();
QStringList m_separators;
- QVector<SectionToken> m_tokens;
+ std::vector<SectionToken> m_tokens;
QCalendarYearValidator m_yearValidator;
QCalendarMonthValidator m_monthValidator;
QCalendarDayValidator m_dayValidator;
@@ -518,11 +517,11 @@ QString QCalendarDateValidator::currentText() const
{
QString str;
const int numSeps = m_separators.size();
- const int numTokens = m_tokens.size();
+ const int numTokens = int(m_tokens.size());
for (int i = 0; i < numSeps; ++i) {
str += m_separators.at(i);
if (i < numTokens) {
- const SectionToken &token = m_tokens.at(i);
+ const SectionToken &token = m_tokens[i];
if (i == m_currentToken)
str += token.validator->text();
else
@@ -560,25 +559,25 @@ void QCalendarDateValidator::setFormat(const QString &format)
separator += nextChar;
quoting = false;
} else {
- SectionToken token;
+ QCalendarDateSectionValidator *validator = 0;
if (nextChar == QLatin1Char('d')) {
offset = qMin(4, countRepeat(format, pos));
- token = SectionToken(&m_dayValidator, offset);
+ validator = &m_dayValidator;
} else if (nextChar == QLatin1Char('M')) {
offset = qMin(4, countRepeat(format, pos));
- token = SectionToken(&m_monthValidator, offset);
+ validator = &m_monthValidator;
} else if (nextChar == QLatin1Char('y')) {
offset = qMin(4, countRepeat(format, pos));
- token = SectionToken(&m_yearValidator, offset);
+ validator = &m_yearValidator;
} else {
separator += nextChar;
}
- if (!token.isNull()) {
- m_tokens.append(token);
+ if (validator) {
+ m_tokens.push_back(SectionToken(validator, offset));
m_separators.append(separator);
separator = QString();
if (m_currentToken < 0)
- m_currentToken = m_tokens.size() - 1;
+ m_currentToken = int(m_tokens.size()) - 1;
}
}
@@ -626,7 +625,7 @@ void QCalendarDateValidator::handleKeyEvent(QKeyEvent *keyEvent)
else if (key == Qt::Key_Left)
toPreviousToken();
- m_lastSectionMove = m_tokens.at(m_currentToken).validator->handleKey(key);
+ m_lastSectionMove = m_tokens[m_currentToken].validator->handleKey(key);
applyToDate();
if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection)