125 const SectionNode sn = { hour, i - add, countRepeat(format, i, 2) }; |
119 const SectionNode sn = { hour, i - add, countRepeat(format, i, 2) }; |
126 newSectionNodes.append(sn); |
120 newSectionNodes.append(sn); |
127 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
121 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
128 i += sn.count - 1; |
122 i += sn.count - 1; |
129 index = i + 1; |
123 index = i + 1; |
|
124 if(newDisplay & hour) { |
|
125 return false; // error in format |
|
126 } |
130 newDisplay |= hour; |
127 newDisplay |= hour; |
131 } |
128 } |
132 break; |
129 break; |
133 case 'm': |
130 case 'm': |
134 { |
131 { |
135 const SectionNode sn = { MinuteSection, i - add, countRepeat(format, i, 2) }; |
132 const SectionNode sn = { MinuteSection, i - add, countRepeat(format, i, 2) }; |
136 newSectionNodes.append(sn); |
133 newSectionNodes.append(sn); |
137 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
134 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
138 i += sn.count - 1; |
135 i += sn.count - 1; |
139 index = i + 1; |
136 index = i + 1; |
|
137 if(newDisplay & MinuteSection) { |
|
138 return false; // error in format |
|
139 } |
140 newDisplay |= MinuteSection; |
140 newDisplay |= MinuteSection; |
141 } |
141 } |
142 break; |
142 break; |
143 case 's': |
143 case 's': |
144 { |
144 { |
145 const SectionNode sn = { SecondSection, i - add, countRepeat(format, i, 2) }; |
145 const SectionNode sn = { SecondSection, i - add, countRepeat(format, i, 2) }; |
146 newSectionNodes.append(sn); |
146 newSectionNodes.append(sn); |
147 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
147 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
148 i += sn.count - 1; |
148 i += sn.count - 1; |
149 index = i + 1; |
149 index = i + 1; |
|
150 if(newDisplay & SecondSection) { |
|
151 return false; // error in format |
|
152 } |
150 newDisplay |= SecondSection; |
153 newDisplay |= SecondSection; |
151 } |
154 } |
152 break; |
155 break; |
153 |
156 |
154 case 'z': |
157 case 'z': |
156 const SectionNode sn = { MSecSection, i - add, countRepeat(format, i, 3) < 3 ? 1 : 3 }; |
159 const SectionNode sn = { MSecSection, i - add, countRepeat(format, i, 3) < 3 ? 1 : 3 }; |
157 newSectionNodes.append(sn); |
160 newSectionNodes.append(sn); |
158 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
161 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
159 i += sn.count - 1; |
162 i += sn.count - 1; |
160 index = i + 1; |
163 index = i + 1; |
|
164 if(newDisplay & MSecSection) { |
|
165 return false; // error in format |
|
166 } |
161 newDisplay |= MSecSection; |
167 newDisplay |= MSecSection; |
162 } |
168 } |
163 break; |
169 break; |
164 case 'A': |
170 case 'A': |
165 case 'a': |
171 case 'a': |
166 { |
172 { |
167 const bool cap = (sect == 'A'); |
173 const bool cap = (sect == 'A'); |
168 const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0) }; |
174 const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0) }; |
169 newSectionNodes.append(sn); |
175 newSectionNodes.append(sn); |
170 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
176 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
|
177 if(newDisplay & AmPmSection) { |
|
178 return false; // error in format |
|
179 } |
171 newDisplay |= AmPmSection; |
180 newDisplay |= AmPmSection; |
172 if (i + 1 < format.size() |
181 if (i + 1 < format.size() |
173 && format.at(i+1) == (cap ? QLatin1Char('P') : QLatin1Char('p'))) { |
182 && format.at(i+1) == (cap ? QLatin1Char('P') : QLatin1Char('p'))) { |
174 ++i; |
183 ++i; |
175 } |
184 } |
176 index = i + 1; |
185 index = i + 1; |
177 } |
186 } |
178 break; |
187 break; |
179 case 'y': |
188 case 'y': |
180 { |
189 { |
181 const int repeat = countRepeat(format, i, 4); |
190 const int repeat = countRepeat(format, i, 4); |
182 if (repeat >= 2) { |
191 if (repeat >= 2) { |
183 const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits, |
192 const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits, |
184 i - add, repeat == 4 ? 4 : 2 }; |
193 i - add, repeat == 4 ? 4 : 2 }; |
185 newSectionNodes.append(sn); |
194 newSectionNodes.append(sn); |
186 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
195 appendSeparator(&newSeparators, format, index, i - index, lastQuote); |
187 i += sn.count - 1; |
196 i += sn.count - 1; |
188 index = i + 1; |
197 index = i + 1; |
|
198 if(newDisplay & sn.type) { |
|
199 return false; //error in format |
|
200 } |
189 newDisplay |= sn.type; |
201 newDisplay |= sn.type; |
190 } |
202 } |
191 } |
203 } |
192 break; |
204 break; |
193 case 'M': |
205 case 'M': |
380 bool HbDateTimePickerPrivate::isFormatValid(const QString &newDisplayFormat) |
429 bool HbDateTimePickerPrivate::isFormatValid(const QString &newDisplayFormat) |
381 { |
430 { |
382 if(newDisplayFormat == mFormat) { |
431 if(newDisplayFormat == mFormat) { |
383 return false; |
432 return false; |
384 } |
433 } |
385 return true; |
434 |
|
435 return mParser.parseFormat(newDisplayFormat); |
386 } |
436 } |
387 |
437 |
388 /* |
438 /* |
389 this will reset the display sections and re add them in order |
439 this will reset the display sections and re add them in order |
390 mentioned in the display format passed. this also sets the mIs24HourFormat var. |
440 mentioned in the display format passed. this also sets the mIs24HourFormat var. |
391 */ |
441 */ |
392 void HbDateTimePickerPrivate::parseDisplayFormat(const QString &format) |
442 void HbDateTimePickerPrivate::processDisplaySections() |
393 { |
443 { |
394 if(mParser.parseFormat(format)) { |
444 for(int i=0;i<mParser.mSectionNodes.count();++i) { |
395 for(int i=0;i<mParser.mSectionNodes.count();++i) { |
445 switch(mParser.mSectionNodes[i].type) { |
396 switch(mParser.mSectionNodes[i].type) { |
446 case HbDateTimeParser::DaySection: |
397 case HbDateTimeParser::DaySection: |
447 case HbDateTimeParser::DayOfWeekSection: |
398 case HbDateTimeParser::DayOfWeekSection: |
448 mDayFormat = QString(mParser.mSectionNodes[i].count,'d'); |
399 mDayFormat = QString(mParser.mSectionNodes[i].count,'d'); |
449 break; |
400 break; |
450 |
401 |
451 case HbDateTimeParser::MonthSection: |
402 case HbDateTimeParser::MonthSection: |
452 mMonthFormat = QString(mParser.mSectionNodes[i].count,'M'); |
403 mMonthFormat = QString(mParser.mSectionNodes[i].count,'M'); |
453 break; |
404 break; |
454 |
405 |
455 case HbDateTimeParser::YearSection: |
406 case HbDateTimeParser::YearSection: |
456 mIsTwoDigitYearFormat = false; |
407 mIsTwoDigitYearFormat = false; |
457 mYearFormat = QString(mParser.mSectionNodes[i].count,'y'); |
408 mYearFormat = QString(mParser.mSectionNodes[i].count,'y'); |
458 break; |
409 break; |
459 |
410 |
460 case HbDateTimeParser::YearSection2Digits: |
411 case HbDateTimeParser::YearSection2Digits: |
461 mIsTwoDigitYearFormat = true; |
412 mIsTwoDigitYearFormat = true; |
462 mYearFormat = QString(mParser.mSectionNodes[i].count,'y'); |
413 mYearFormat = QString(mParser.mSectionNodes[i].count,'y'); |
463 break; |
414 break; |
464 |
415 |
465 case HbDateTimeParser::SecondSection: |
416 case HbDateTimeParser::SecondSection: |
466 mSecondFormat = QString(mParser.mSectionNodes[i].count,'s'); |
417 mSecondFormat = QString(mParser.mSectionNodes[i].count,'s'); |
467 break; |
418 break; |
468 |
419 |
469 case HbDateTimeParser::MinuteSection: |
420 case HbDateTimeParser::MinuteSection: |
470 mMinuteFormat = QString(mParser.mSectionNodes[i].count,'m'); |
421 mMinuteFormat = QString(mParser.mSectionNodes[i].count,'m'); |
471 break; |
422 break; |
472 |
423 |
473 case HbDateTimeParser::Hour12Section: |
424 case HbDateTimeParser::Hour12Section: |
474 mIs24HourFormat = false; |
425 mIs24HourFormat = false; |
475 mHourFormat = QString(mParser.mSectionNodes[i].count,'h'); |
426 mHourFormat = QString(mParser.mSectionNodes[i].count,'h'); |
476 break; |
427 break; |
477 |
428 |
478 case HbDateTimeParser::Hour24Section: |
429 case HbDateTimeParser::Hour24Section: |
479 mIs24HourFormat = true; |
430 mIs24HourFormat = true; |
480 mHourFormat = QString(mParser.mSectionNodes[i].count,'h'); |
431 mHourFormat = QString(mParser.mSectionNodes[i].count,'h'); |
481 break; |
432 break; |
482 |
433 |
483 default: |
434 default: |
484 break; |
435 break; |
485 /*case HbDateTimeParser::DayOfWeekSection: not supported */ |
436 /*case HbDateTimeParser::DayOfWeekSection: not supported */ |
|
437 } |
|
438 } |
486 } |
439 } |
487 } |
440 } |
488 } |
441 |
489 |
442 /* |
490 /* |
445 it creates the ones which are required and makes the connections. |
493 it creates the ones which are required and makes the connections. |
446 */ |
494 */ |
447 void HbDateTimePickerPrivate::rearrangeTumbleViews() |
495 void HbDateTimePickerPrivate::rearrangeTumbleViews() |
448 { |
496 { |
449 Q_Q(HbDateTimePicker); |
497 Q_Q(HbDateTimePicker); |
450 |
|
451 if(!(mParser.mDisplaySections & (HbDateTimeParser::YearSection| |
498 if(!(mParser.mDisplaySections & (HbDateTimeParser::YearSection| |
452 HbDateTimeParser::YearSection2Digits))) { |
499 HbDateTimeParser::YearSection2Digits))) { |
453 deleteAndNull(mYearPicker); |
500 deleteAndNull(mYearPicker); |
|
501 delete mLabelYear; |
454 mYearModel = 0; |
502 mYearModel = 0; |
455 } |
503 } |
456 if(!(mParser.mDisplaySections & HbDateTimeParser::MonthSection)) { |
504 if(!(mParser.mDisplaySections & HbDateTimeParser::MonthSection)) { |
457 deleteAndNull(mMonthPicker); |
505 deleteAndNull(mMonthPicker); |
458 mMonthModel = 0; |
506 delete mLabelMonth; |
|
507 mMonthModel = 0; |
459 } |
508 } |
460 if(!(mParser.mDisplaySections & HbDateTimeParser::DaySection)) { |
509 if(!(mParser.mDisplaySections & HbDateTimeParser::DaySection)) { |
461 deleteAndNull(mDayPicker); |
510 deleteAndNull(mDayPicker); |
462 mDayModel = 0; |
511 delete mLabelDay; |
|
512 mDayModel = 0; |
463 } |
513 } |
464 if(!(mParser.mDisplaySections & (HbDateTimeParser::Hour12Section| |
514 if(!(mParser.mDisplaySections & (HbDateTimeParser::Hour12Section| |
465 HbDateTimeParser::Hour24Section))) { |
515 HbDateTimeParser::Hour24Section))) { |
466 deleteAndNull(mHourPicker); |
516 deleteAndNull(mHourPicker); |
|
517 delete mLabelHour; |
467 mHourModel = 0; |
518 mHourModel = 0; |
468 } |
519 } |
469 if(!(mParser.mDisplaySections & HbDateTimeParser::MinuteSection)) { |
520 if(!(mParser.mDisplaySections & HbDateTimeParser::MinuteSection)) { |
470 deleteAndNull(mMinutePicker); |
521 deleteAndNull(mMinutePicker); |
471 mMinuteModel = 0; |
522 delete mLabelMinute; |
|
523 mMinuteModel = 0; |
472 } |
524 } |
473 if(!(mParser.mDisplaySections & HbDateTimeParser::SecondSection)) { |
525 if(!(mParser.mDisplaySections & HbDateTimeParser::SecondSection)) { |
474 deleteAndNull(mSecondPicker); |
526 deleteAndNull(mSecondPicker); |
475 mSecondModel = 0; |
527 delete mLabelSecond; |
|
528 mSecondModel = 0; |
476 } |
529 } |
477 if(!(mParser.mDisplaySections & HbDateTimeParser::AmPmSection)) { |
530 if(!(mParser.mDisplaySections & HbDateTimeParser::AmPmSection)) { |
478 deleteAndNull(mAmPmPicker); |
531 deleteAndNull(mAmPmPicker); |
479 mAmPmModel = 0; |
532 mAmPmModel = 0; |
480 } |
533 } |
481 |
534 |
482 mYearOffset = -1; |
535 mYearOffset = -1; |
483 mMonthOffset = -1; |
536 mMonthOffset = -1; |
484 mDayOffset = -1; |
537 mDayOffset = -1; |
485 mHourOffset = -1; |
538 mHourOffset = -1; |
486 mMinuteOffset = -1; |
539 mMinuteOffset = -1; |
487 mSecondOffset = -1; |
540 mSecondOffset = -1; |
488 |
541 |
489 while(mLayout->count()) { |
542 while(mLayout->count()) { |
490 mLayout->removeAt(0); |
543 mLayout->removeAt(0); |
491 } |
544 } |
492 |
|
493 QPointer<VIEWER> lastAdded; |
|
494 |
545 |
495 for(int i=0;i<mParser.mSectionNodes.count();i++) { |
546 for(int i=0;i<mParser.mSectionNodes.count();i++) { |
496 switch(mParser.mSectionNodes[i].type) { |
547 switch(mParser.mSectionNodes[i].type) { |
497 case HbDateTimeParser::AmPmSection: |
548 case HbDateTimeParser::AmPmSection: |
498 if(!mAmPmPicker) { |
549 if(!mAmPmPicker) { |
499 mAmPmPicker = new VIEWER(q); |
550 mAmPmPicker = new VIEWER(q); |
500 mAmPmModel = static_cast<QStringListModel*>(mAmPmPicker->model()); |
551 mAmPmModel = static_cast<QStringListModel*>(mAmPmPicker->model()); |
501 } |
552 } |
502 mLayout->addItem(mAmPmPicker); |
553 |
503 lastAdded = mAmPmPicker; |
554 mLayout->addItem(mAmPmPicker, 1, i); |
504 break; |
555 mLastAdded = mAmPmPicker; |
|
556 break; |
505 |
557 |
506 case HbDateTimeParser::DaySection: |
558 case HbDateTimeParser::DaySection: |
507 case HbDateTimeParser::DayOfWeekSection: |
559 case HbDateTimeParser::DayOfWeekSection: |
508 if(!mDayPicker) { |
560 if(!mDayPicker) { |
509 mDayPicker = new VIEWER(q); |
561 mDayPicker = new VIEWER(q); |
510 mDayModel = static_cast<QStringListModel*>(mDayPicker->model()); |
562 mDayModel = static_cast<QStringListModel*>(mDayPicker->model()); |
511 mDayPicker->setLoopingEnabled(true); |
563 mDayPicker->setLoopingEnabled(true); |
|
564 } |
|
565 |
|
566 if(mLabelDay.isNull()){ |
|
567 mLabelDay = new HbDatePickerViewLabel("Day", q);//TODO:Text should come from common.ts |
512 } |
568 } |
513 mLayout->addItem(mDayPicker); |
569 |
514 lastAdded = mDayPicker; |
570 mLayout->addItem(mLabelDay, 0, i); |
515 break; |
571 mLayout->addItem(mDayPicker, 1, i); |
|
572 mLastAdded = mDayPicker; |
|
573 break; |
516 |
574 |
517 case HbDateTimeParser::MonthSection: |
575 case HbDateTimeParser::MonthSection: |
518 if(!mMonthPicker) { |
576 if(!mMonthPicker) { |
519 mMonthPicker = new VIEWER(q); |
577 mMonthPicker = new VIEWER(q); |
520 mMonthModel = static_cast<QStringListModel*>(mMonthPicker->model()); |
578 mMonthModel = static_cast<QStringListModel*>(mMonthPicker->model()); |
521 mMonthPicker->setLoopingEnabled(true); |
579 mMonthPicker->setLoopingEnabled(true); |
|
580 } |
|
581 |
|
582 if(mLabelMonth.isNull()){ |
|
583 mLabelMonth = new HbDatePickerViewLabel("Month", q);//TODO:Text should come from common.ts |
522 } |
584 } |
523 mLayout->addItem(mMonthPicker); |
585 |
524 lastAdded = mMonthPicker; |
586 mLastAdded = mMonthPicker; |
525 break; |
587 mLayout->addItem(mLabelMonth, 0, i); |
|
588 mLayout->addItem(mMonthPicker, 1, i); |
|
589 break; |
526 |
590 |
527 case HbDateTimeParser::YearSection: |
591 case HbDateTimeParser::YearSection: |
528 case HbDateTimeParser::YearSection2Digits: |
592 case HbDateTimeParser::YearSection2Digits: |
529 if(!mYearPicker) { |
593 if(!mYearPicker) { |
530 mYearPicker = new VIEWER(q); |
594 mYearPicker = new VIEWER(q); |
531 mYearModel = static_cast<QStringListModel*>(mYearPicker->model()); |
595 mYearModel = static_cast<QStringListModel*>(mYearPicker->model()); |
532 mYearPicker->setLoopingEnabled(true); |
596 mYearPicker->setLoopingEnabled(true); |
|
597 } |
|
598 |
|
599 if(mLabelYear.isNull()){ |
|
600 mLabelYear = new HbDatePickerViewLabel("Year", q);//TODO:Text should come from common.ts |
533 } |
601 } |
534 mLayout->addItem(mYearPicker); |
602 |
535 lastAdded = mYearPicker; |
603 mLayout->addItem(mLabelYear, 0, i); |
536 break; |
604 mLayout->addItem(mYearPicker, 1, i); |
|
605 mLastAdded = mYearPicker; |
|
606 break; |
537 |
607 |
538 case HbDateTimeParser::SecondSection: |
608 case HbDateTimeParser::SecondSection: |
539 if(!mSecondPicker) { |
609 if(!mSecondPicker) { |
540 mSecondPicker = new VIEWER(q); |
610 mSecondPicker = new VIEWER(q); |
541 mSecondModel = static_cast<QStringListModel*>(mSecondPicker->model()); |
611 mSecondModel = static_cast<QStringListModel*>(mSecondPicker->model()); |
542 mSecondPicker->setLoopingEnabled(true); |
612 mSecondPicker->setLoopingEnabled(true); |
|
613 } |
|
614 |
|
615 if(mLabelSecond.isNull()){ |
|
616 mLabelSecond = new HbDatePickerViewLabel("Seconds", q);//TODO:Text should come from common.ts |
543 } |
617 } |
544 mLayout->addItem(mSecondPicker); |
618 |
545 lastAdded = mSecondPicker; |
619 mLayout->addItem(mLabelSecond, 0, i); |
546 break; |
620 mLayout->addItem(mSecondPicker, 1, i); |
|
621 mLastAdded = mSecondPicker; |
|
622 break; |
547 |
623 |
548 case HbDateTimeParser::MinuteSection: |
624 case HbDateTimeParser::MinuteSection: |
549 if(!mMinutePicker) { |
625 if(!mMinutePicker) { |
550 mMinutePicker = new VIEWER(q); |
626 mMinutePicker = new VIEWER(q); |
551 mMinuteModel = static_cast<QStringListModel*>(mMinutePicker->model()); |
627 mMinuteModel = static_cast<QStringListModel*>(mMinutePicker->model()); |
552 mMinutePicker->setLoopingEnabled(true); |
628 mMinutePicker->setLoopingEnabled(true); |
|
629 } |
|
630 if(mLabelMinute.isNull()){ |
|
631 mLabelMinute = new HbDatePickerViewLabel("Minute", q);//TODO:Text should come from common.ts |
553 } |
632 } |
554 mLayout->addItem(mMinutePicker); |
633 mLayout->addItem(mLabelMinute, 0, i); |
555 lastAdded = mMinutePicker; |
634 mLayout->addItem(mMinutePicker, 1, i); |
556 break; |
635 mLastAdded = mMinutePicker; |
|
636 break; |
557 |
637 |
558 case HbDateTimeParser::Hour12Section: |
638 case HbDateTimeParser::Hour12Section: |
559 case HbDateTimeParser::Hour24Section: |
639 case HbDateTimeParser::Hour24Section: |
560 if(!mHourPicker) { |
640 if(!mHourPicker) { |
561 mHourPicker = new VIEWER(q); |
641 mHourPicker = new VIEWER(q); |
562 mHourModel = static_cast<QStringListModel*>(mHourPicker->model()); |
642 mHourModel = static_cast<QStringListModel*>(mHourPicker->model()); |
563 mHourPicker->setLoopingEnabled(true); |
643 mHourPicker->setLoopingEnabled(true); |
|
644 } |
|
645 |
|
646 if(mLabelHour.isNull()){ |
|
647 mLabelHour = new HbDatePickerViewLabel("Hour", q);//TODO:Text should come from common.ts |
564 } |
648 } |
565 mLayout->addItem(mHourPicker); |
649 |
566 lastAdded = mHourPicker; |
650 mLayout->addItem(mLabelHour, 0, i); |
567 break; |
651 mLayout->addItem(mHourPicker, 1, i); |
|
652 mLastAdded = mHourPicker; |
|
653 |
|
654 break; |
568 |
655 |
569 default: |
656 default: |
570 break; |
657 break; |
571 } |
658 } |
572 |
659 |
573 if(lastAdded){ |
660 if(mLastAdded){ |
574 lastAdded->primitive("highlight")->hide(); |
661 mLastAdded->primitive("highlight")->hide(); |
575 lastAdded->primitive("separator")->show(); |
662 mLastAdded->primitive("separator")->show(); |
|
663 mLastAdded->primitive("background")->hide(); |
|
664 mLastAdded->primitive("frame")->hide(); |
576 } |
665 } |
577 |
666 |
578 } |
667 } |
579 |
668 |
580 //For the last added tumble view, hide the separator. |
669 //For the last added tumble view, hide the separator. |
581 if(lastAdded){ |
670 if(mLastAdded){ |
582 lastAdded->primitive("separator")->hide(); |
671 mLastAdded->primitive("separator")->hide(); |
583 } |
672 } |
584 |
673 |
585 setRanges(); |
674 setRanges(); |
586 makeConnections(); |
675 makeConnections(); |
587 syncVisualDate(); |
676 syncVisualDate(); |
1219 } |
1308 } |
1220 HbDateTimePickerPrivate *priv; |
1309 HbDateTimePickerPrivate *priv; |
1221 }Obj(this); |
1310 }Obj(this); |
1222 |
1311 |
1223 #ifdef HBDATETIMEPICKER_DEBUG |
1312 #ifdef HBDATETIMEPICKER_DEBUG |
1224 qDebug() << "resizeModel: oldStart=" << oldStart |
1313 qDebug() << "resizeModel: oldStart=" << oldStart |
1225 << " oldEnd=" << oldEnd << " newStart=" |
1314 << " oldEnd=" << oldEnd << " newStart=" |
1226 << newStart << " newEnd=" << newEnd |
1315 << newStart << " newEnd=" << newEnd |
1227 << " interval=" << interval; |
1316 << " interval=" << interval; |
1228 #endif |
1317 #endif |
1229 bool b1=false,b2=false; |
1318 bool b1=false,b2=false; |
1230 int oldinterval=model->rowCount()>1 ? (model->index(1,0).data().toInt(&b1)-model->index(0,0).data().toInt(&b2)):0; |
1319 int oldinterval=model->rowCount()>1 ? (model->index(1,0).data().toInt(&b1)-model->index(0,0).data().toInt(&b2)):0; |
1231 #ifdef HBDATETIMEPICKER_DEBUG |
1320 #ifdef HBDATETIMEPICKER_DEBUG |
1232 qDebug() << "resizeModel:sameoldInterval=" << oldinterval; |
1321 qDebug() << "resizeModel:sameoldInterval=" << oldinterval; |
1233 #endif |
1322 #endif |
1234 if(b1 && b2 && (oldinterval == interval) && (newStart == oldStart)) { |
1323 if(b1 && b2 && (oldinterval == interval) && (newStart == oldStart)) { |
1235 if(newEnd>oldEnd) { |
|
1236 int rowCount=model->rowCount(); |
|
1237 #ifdef HBDATETIMEPICKER_DEBUG |
|
1238 qDebug() << "resizeModel:sameinserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")"; |
|
1239 #endif |
|
1240 model->insertRows(rowCount,(newEnd-oldEnd)/interval); |
|
1241 for(int i=0;i<((newEnd-oldEnd)/interval);++i) { |
|
1242 QModelIndex index=model->index(i+rowCount,0); |
|
1243 if(index.isValid()) { |
|
1244 model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd)); |
|
1245 #ifdef HBDATETIMEPICKER_DEBUG |
|
1246 qDebug() << "resizeModel:samesetData(" << ((i+1)*interval)+oldEnd << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")"; |
|
1247 #endif |
|
1248 } |
|
1249 } |
|
1250 } |
|
1251 if(oldEnd>newEnd) { |
|
1252 //if the start offset is preset more items can fit at end |
|
1253 int stay=((newEnd-newStart)/interval)+1; |
|
1254 int count=model->rowCount()-stay; |
|
1255 #ifdef HBDATETIMEPICKER_DEBUG |
|
1256 qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")" |
|
1257 << " data=" << model->index((model->rowCount()-count),0).data().toString(); |
|
1258 #endif |
|
1259 model->removeRows((model->rowCount()-count),count); |
|
1260 } |
|
1261 return;//optimizing inserts when interval is set |
|
1262 } else { |
|
1263 if(b1 && b2) { |
|
1264 model->removeRows(0,model->rowCount()); |
|
1265 oldStart = oldEnd = 0; |
|
1266 } |
|
1267 } |
|
1268 |
|
1269 if((model->rowCount() == 0) && (newEnd-newStart>=0)) { |
|
1270 #ifdef HBDATETIMEPICKER_DEBUG |
|
1271 qDebug() << "resizeModel:default addition inserting(0," << (newEnd-newStart+1)/interval << ")"; |
|
1272 #endif |
|
1273 |
|
1274 model->insertRows(0,((newEnd-newStart)/interval)+1); |
|
1275 for(int i=0;i<=((newEnd-newStart)/interval);++i) { |
|
1276 QString text=(this->*localeFunc)((i*interval)+newStart); |
|
1277 #ifdef HB_TEXT_MEASUREMENT_UTILITY |
|
1278 if ( localeFunc == &HbDateTimePickerPrivate::localeMonth && |
|
1279 HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) { |
|
1280 text.append(QChar(LOC_TEST_START)); |
|
1281 text.append("qtl_datetimepicker_popup_month_sec"); |
|
1282 text.append(QChar(LOC_TEST_END)); |
|
1283 } |
|
1284 #endif |
|
1285 QModelIndex index=model->index(i,0); |
|
1286 if(index.isValid()) { |
|
1287 model->setData(index,text); |
|
1288 #ifdef HBDATETIMEPICKER_DEBUG |
|
1289 qDebug() << "resizeModel:setData(" << i << "," << text << ")"; |
|
1290 #endif |
|
1291 } |
|
1292 } |
|
1293 return; |
|
1294 } |
|
1295 |
|
1296 if(newStart<oldStart) { |
|
1297 #ifdef HBDATETIMEPICKER_DEBUG |
|
1298 qDebug() << "resizeModel:inserting(0," << (oldStart-newStart)/interval << ")"; |
|
1299 #endif |
|
1300 model->insertRows(0,(oldStart-newStart)/interval); |
|
1301 for(int i=0;i<((oldStart-newStart)/interval);++i) { |
|
1302 QModelIndex index=model->index(i,0); |
|
1303 if(index.isValid()) { |
|
1304 model->setData(index,(this->*localeFunc)((i*interval)+newStart)); |
|
1305 #ifdef HBDATETIMEPICKER_DEBUG |
|
1306 qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i*interval)+newStart) << ")"; |
|
1307 #endif |
|
1308 } |
|
1309 } |
|
1310 } |
|
1311 |
|
1312 if(newEnd>oldEnd) { |
1324 if(newEnd>oldEnd) { |
1313 int rowCount=model->rowCount(); |
1325 int rowCount=model->rowCount(); |
1314 #ifdef HBDATETIMEPICKER_DEBUG |
1326 #ifdef HBDATETIMEPICKER_DEBUG |
1315 qDebug() << "resizeModel:inserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")"; |
1327 qDebug() << "resizeModel:sameinserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")"; |
1316 #endif |
1328 #endif |
1317 model->insertRows(rowCount,(newEnd-oldEnd)/interval); |
1329 model->insertRows(rowCount,(newEnd-oldEnd)/interval); |
1318 for(int i=0;i<((newEnd-oldEnd)/interval);++i) { |
1330 for(int i=0;i<((newEnd-oldEnd)/interval);++i) { |
1319 QModelIndex index=model->index(i+rowCount,0); |
1331 QModelIndex index=model->index(i+rowCount,0); |
1320 if(index.isValid()) { |
1332 if(index.isValid()) { |
1321 model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd)); |
1333 model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd)); |
1322 #ifdef HBDATETIMEPICKER_DEBUG |
1334 #ifdef HBDATETIMEPICKER_DEBUG |
1323 qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")"; |
1335 qDebug() << "resizeModel:samesetData(" << ((i+1)*interval)+oldEnd << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")"; |
1324 #endif |
1336 #endif |
1325 } |
1337 } |
1326 } |
1338 } |
1327 } |
1339 } |
1328 if(newStart>oldStart) { |
|
1329 #ifdef HBDATETIMEPICKER_DEBUG |
|
1330 qDebug() << "resizeModel:removing(0," << (newStart-oldStart)/interval << ")" |
|
1331 << " data=" << model->index((newStart-oldStart)/interval,0).data().toString(); |
|
1332 #endif |
|
1333 model->removeRows(0,(newStart-oldStart)/interval); |
|
1334 } |
|
1335 |
|
1336 if(oldEnd>newEnd) { |
1340 if(oldEnd>newEnd) { |
1337 //#ifdef HBDATETIMEPICKER_DEBUG |
1341 //if the start offset is preset more items can fit at end |
1338 // qDebug() << "resizeModel:removing(" <<model->rowCount()-((oldEnd-newEnd)/interval)<<"," << (oldEnd-newEnd)/interval << ")"; |
1342 int stay=((newEnd-newStart)/interval)+1; |
1339 //#endif |
1343 int count=model->rowCount()-stay; |
1340 // model->removeRows((model->rowCount()-((oldEnd-newEnd)/interval)),(oldEnd-newEnd)/interval); |
1344 #ifdef HBDATETIMEPICKER_DEBUG |
1341 //if the start offset is preset more items can fit at end |
1345 qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")" |
1342 int stay=((newEnd-newStart)/interval)+1; |
1346 << " data=" << model->index((model->rowCount()-count),0).data().toString(); |
1343 int count=model->rowCount()-stay; |
1347 #endif |
1344 #ifdef HBDATETIMEPICKER_DEBUG |
1348 model->removeRows((model->rowCount()-count),count); |
1345 qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")" |
1349 } |
1346 << " data=" << model->index((model->rowCount()-count),0).data().toString(); |
1350 return;//optimizing inserts when interval is set |
1347 #endif |
1351 } else { |
1348 model->removeRows((model->rowCount()-count),count); |
1352 if(b1 && b2) { |
1349 } |
1353 model->removeRows(0,model->rowCount()); |
|
1354 oldStart = oldEnd = 0; |
|
1355 } |
|
1356 } |
|
1357 |
|
1358 if((model->rowCount() == 0) && (newEnd-newStart>=0)) { |
|
1359 #ifdef HBDATETIMEPICKER_DEBUG |
|
1360 qDebug() << "resizeModel:default addition inserting(0," << (newEnd-newStart+1)/interval << ")"; |
|
1361 #endif |
|
1362 |
|
1363 model->insertRows(0,((newEnd-newStart)/interval)+1); |
|
1364 for(int i=0;i<=((newEnd-newStart)/interval);++i) { |
|
1365 QString text=(this->*localeFunc)((i*interval)+newStart); |
|
1366 #ifdef HB_TEXT_MEASUREMENT_UTILITY |
|
1367 if ( localeFunc == &HbDateTimePickerPrivate::localeMonth && |
|
1368 HbTextMeasurementUtility::instance()->locTestMode() ) { |
|
1369 text.append(QChar(LOC_TEST_START)); |
|
1370 text.append("qtl_datetimepicker_popup_month_sec"); |
|
1371 text.append(QChar(LOC_TEST_END)); |
|
1372 } |
|
1373 #endif |
|
1374 QModelIndex index=model->index(i,0); |
|
1375 if(index.isValid()) { |
|
1376 model->setData(index,text); |
|
1377 #ifdef HBDATETIMEPICKER_DEBUG |
|
1378 qDebug() << "resizeModel:setData(" << i << "," << text << ")"; |
|
1379 #endif |
|
1380 } |
|
1381 } |
|
1382 return; |
|
1383 } |
|
1384 |
|
1385 if(newStart<oldStart) { |
|
1386 #ifdef HBDATETIMEPICKER_DEBUG |
|
1387 qDebug() << "resizeModel:inserting(0," << (oldStart-newStart)/interval << ")"; |
|
1388 #endif |
|
1389 model->insertRows(0,(oldStart-newStart)/interval); |
|
1390 for(int i=0;i<((oldStart-newStart)/interval);++i) { |
|
1391 QModelIndex index=model->index(i,0); |
|
1392 if(index.isValid()) { |
|
1393 model->setData(index,(this->*localeFunc)((i*interval)+newStart)); |
|
1394 #ifdef HBDATETIMEPICKER_DEBUG |
|
1395 qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i*interval)+newStart) << ")"; |
|
1396 #endif |
|
1397 } |
|
1398 } |
|
1399 } |
|
1400 |
|
1401 if(newEnd>oldEnd) { |
|
1402 int rowCount=model->rowCount(); |
|
1403 #ifdef HBDATETIMEPICKER_DEBUG |
|
1404 qDebug() << "resizeModel:inserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")"; |
|
1405 #endif |
|
1406 model->insertRows(rowCount,(newEnd-oldEnd)/interval); |
|
1407 for(int i=0;i<((newEnd-oldEnd)/interval);++i) { |
|
1408 QModelIndex index=model->index(i+rowCount,0); |
|
1409 if(index.isValid()) { |
|
1410 model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd)); |
|
1411 #ifdef HBDATETIMEPICKER_DEBUG |
|
1412 qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")"; |
|
1413 #endif |
|
1414 } |
|
1415 } |
|
1416 } |
|
1417 if(newStart>oldStart) { |
|
1418 #ifdef HBDATETIMEPICKER_DEBUG |
|
1419 qDebug() << "resizeModel:removing(0," << (newStart-oldStart)/interval << ")" |
|
1420 << " data=" << model->index((newStart-oldStart)/interval,0).data().toString(); |
|
1421 #endif |
|
1422 model->removeRows(0,(newStart-oldStart)/interval); |
|
1423 } |
|
1424 |
|
1425 if(oldEnd>newEnd) { |
|
1426 //#ifdef HBDATETIMEPICKER_DEBUG |
|
1427 // qDebug() << "resizeModel:removing(" <<model->rowCount()-((oldEnd-newEnd)/interval)<<"," << (oldEnd-newEnd)/interval << ")"; |
|
1428 //#endif |
|
1429 // model->removeRows((model->rowCount()-((oldEnd-newEnd)/interval)),(oldEnd-newEnd)/interval); |
|
1430 //if the start offset is preset more items can fit at end |
|
1431 int stay=((newEnd-newStart)/interval)+1; |
|
1432 int count=model->rowCount()-stay; |
|
1433 #ifdef HBDATETIMEPICKER_DEBUG |
|
1434 qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")" |
|
1435 << " data=" << model->index((model->rowCount()-count),0).data().toString(); |
|
1436 #endif |
|
1437 model->removeRows((model->rowCount()-count),count); |
|
1438 } |
1350 } |
1439 } |
1351 |
1440 |
1352 |
1441 |
1353 void HbDateTimePickerPrivate::createPrimitives() |
1442 void HbDateTimePickerPrivate::createPrimitives() |
1354 { |
1443 { |
1355 Q_Q(HbDateTimePicker); |
1444 Q_Q(HbDateTimePicker); |
1356 if(!mBackground) { |
1445 if (!mBackground) { |
1357 mBackground = q->style()->createPrimitive(HbStyle::P_DateTimePicker_background,q); |
1446 mBackground = q->style()->createPrimitive(HbStyle::PT_FrameItem,"background",q); |
1358 q->style()->setItemName(mBackground,"background"); |
1447 } |
1359 } |
1448 |
1360 if(!mFrame) { |
1449 if(!mFrame) { |
1361 mFrame = q->style()->createPrimitive(HbStyle::P_DateTimePicker_frame,q); |
1450 mFrame = q->style()->createPrimitive(HbStyle::PT_FrameItem,"frame",q); |
1362 q->style()->setItemName(mFrame,"frame"); |
1451 } |
1363 } |
1452 |
1364 |
1453 if(!mHighlight) { |
1365 if(!mHighlight){ |
1454 mHighlight = q->style()->createPrimitive(HbStyle::PT_FrameItem,"highlight",q); |
1366 mHighlight = q->style()->createPrimitive(HbStyle::P_TumbleView_highlight,q); |
|
1367 q->style()->setItemName(mHighlight,"highlight"); |
|
1368 } |
1455 } |
1369 } |
1456 } |
1370 |
1457 |
1371 void HbDateTimePickerPrivate::_q_dayChanged(int index) |
1458 void HbDateTimePickerPrivate::_q_dayChanged(int index) |
1372 { |
1459 { |