--- a/src/hbwidgets/widgets/hbdatetimepicker_p.cpp Wed Aug 18 10:05:37 2010 +0300
+++ b/src/hbwidgets/widgets/hbdatetimepicker_p.cpp Thu Sep 02 20:44:51 2010 +0300
@@ -127,6 +127,9 @@
appendSeparator(&newSeparators, format, index, i - index, lastQuote);
i += sn.count - 1;
index = i + 1;
+ if(newDisplay & hour) {
+ return false; // error in format
+ }
newDisplay |= hour;
}
break;
@@ -137,6 +140,9 @@
appendSeparator(&newSeparators, format, index, i - index, lastQuote);
i += sn.count - 1;
index = i + 1;
+ if(newDisplay & MinuteSection) {
+ return false; // error in format
+ }
newDisplay |= MinuteSection;
}
break;
@@ -147,6 +153,9 @@
appendSeparator(&newSeparators, format, index, i - index, lastQuote);
i += sn.count - 1;
index = i + 1;
+ if(newDisplay & SecondSection) {
+ return false; // error in format
+ }
newDisplay |= SecondSection;
}
break;
@@ -158,6 +167,9 @@
appendSeparator(&newSeparators, format, index, i - index, lastQuote);
i += sn.count - 1;
index = i + 1;
+ if(newDisplay & MSecSection) {
+ return false; // error in format
+ }
newDisplay |= MSecSection;
}
break;
@@ -168,6 +180,9 @@
const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0) };
newSectionNodes.append(sn);
appendSeparator(&newSeparators, format, index, i - index, lastQuote);
+ if(newDisplay & AmPmSection) {
+ return false; // error in format
+ }
newDisplay |= AmPmSection;
if (i + 1 < format.size()
&& format.at(i+1) == (cap ? QLatin1Char('P') : QLatin1Char('p'))) {
@@ -186,6 +201,9 @@
appendSeparator(&newSeparators, format, index, i - index, lastQuote);
i += sn.count - 1;
index = i + 1;
+ if(newDisplay & sn.type) {
+ return false; //error in format
+ }
newDisplay |= sn.type;
}
}
@@ -197,6 +215,9 @@
newSeparators.append(unquote(format.mid(index, i - index)));
i += sn.count - 1;
index = i + 1;
+ if(newDisplay & MonthSection) {
+ return false; // error in format
+ }
newDisplay |= MonthSection;
}
break;
@@ -208,6 +229,9 @@
appendSeparator(&newSeparators, format, index, i - index, lastQuote);
i += sn.count - 1;
index = i + 1;
+ if(newDisplay & (DayOfWeekSection | DaySection)) {
+ return false; // error in format, dd and ddd not yet supported in same format
+ }
newDisplay |= sn.type;
}
break;
@@ -350,10 +374,13 @@
mIntervals[QDateTimeEdit::MinuteSection]=1;
//read the format from locale
- mFormat = localeDateTimeFormat(dateTimeMode);
+ QString newFormat = localeDateTimeFormat(dateTimeMode);
//parse the format and set the sections in order
- parseDisplayFormat(mFormat);
+ if(isFormatValid(newFormat)) {
+ mFormat=newFormat;
+ processDisplaySections();
+ }
//create primitives
createPrimitives();
@@ -382,16 +409,16 @@
if(newDisplayFormat == mFormat) {
return false;
}
- return true;
+
+ return mParser.parseFormat(newDisplayFormat);
}
/*
this will reset the display sections and re add them in order
mentioned in the display format passed. this also sets the mIs24HourFormat var.
*/
-void HbDateTimePickerPrivate::parseDisplayFormat(const QString &format)
+void HbDateTimePickerPrivate::processDisplaySections()
{
- if(mParser.parseFormat(format)) {
for(int i=0;i<mParser.mSectionNodes.count();++i) {
switch(mParser.mSectionNodes[i].type) {
case HbDateTimeParser::DaySection:
@@ -436,7 +463,6 @@
/*case HbDateTimeParser::DayOfWeekSection: not supported */
}
}
- }
}
/*
@@ -449,7 +475,7 @@
Q_Q(HbDateTimePicker);
if(!(mParser.mDisplaySections & (HbDateTimeParser::YearSection|
- HbDateTimeParser::YearSection2Digits))) {
+ HbDateTimeParser::YearSection2Digits))) {
deleteAndNull(mYearPicker);
mYearModel = 0;
}
@@ -462,7 +488,7 @@
mDayModel = 0;
}
if(!(mParser.mDisplaySections & (HbDateTimeParser::Hour12Section|
- HbDateTimeParser::Hour24Section))) {
+ HbDateTimeParser::Hour24Section))) {
deleteAndNull(mHourPicker);
mHourModel = 0;
}
@@ -1065,10 +1091,10 @@
}
resizeModel(mMinuteModel,
- mMinuteOffset,mMinuteModel->index(mMinuteModel->rowCount() - 1).data().toInt(),
- start,end,
- &HbDateTimePickerPrivate::localeMinute,
- mIntervals[QDateTimeEdit::MinuteSection]);
+ mMinuteOffset,mMinuteModel->index(mMinuteModel->rowCount() - 1).data().toInt(),
+ start,end,
+ &HbDateTimePickerPrivate::localeMinute,
+ mIntervals[QDateTimeEdit::MinuteSection]);
mMinuteOffset = start;
//Select the nearest value when the range is set.
@@ -1226,7 +1252,7 @@
<< newStart << " newEnd=" << newEnd
<< " interval=" << interval;
#endif
- bool b1=false,b2=false;
+ bool b1=false,b2=false;
int oldinterval=model->rowCount()>1 ? (model->index(1,0).data().toInt(&b1)-model->index(0,0).data().toInt(&b2)):0;
#ifdef HBDATETIMEPICKER_DEBUG
qDebug() << "resizeModel:sameoldInterval=" << oldinterval;
@@ -1260,10 +1286,10 @@
}
return;//optimizing inserts when interval is set
} else {
- if(b1 && b2) {
- model->removeRows(0,model->rowCount());
+ if(b1 && b2) {
+ model->removeRows(0,model->rowCount());
oldStart = oldEnd = 0;
- }
+ }
}
if((model->rowCount() == 0) && (newEnd-newStart>=0)) {
@@ -1627,7 +1653,7 @@
qDebug() << "_q_minutesChanged:" << index;
qDebug() << mLocale.toInt(mMinuteModel->index(mMinuteOffset+index,0).data().toString(),bOk, 10);
#endif
- QTime newTime(mDateTime.time().hour(),mLocale.toInt(mMinuteModel->index(index,0).data().toString(),bOk, 10),mDateTime.time().second());
+ QTime newTime(mDateTime.time().hour(),mLocale.toInt(mMinuteModel->index(index,0).data().toString(),bOk, 10),mDateTime.time().second());
if(newTime.isValid()) {
mDateTime.setTime(newTime);
}