src/hbwidgets/widgets/hbdatetimepicker_p.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    34 #include <QStringListModel>
    34 #include <QStringListModel>
    35 #include <QGraphicsLinearLayout>
    35 #include <QGraphicsLinearLayout>
    36 #include <QModelIndex>
    36 #include <QModelIndex>
    37 #include <QDate>
    37 #include <QDate>
    38 #include <QLocale>
    38 #include <QLocale>
       
    39 #include <QPointer>
       
    40 
       
    41 //#define HBDATETIMEPICKER_DEBUG
       
    42 #ifdef HBDATETIMEPICKER_DEBUG
    39 #include <QDebug>
    43 #include <QDebug>
    40 #include <QStringListModel>
    44 #endif
    41 #include <QPointer>
       
    42 
       
    43 #define HBDATETIMEPICKER_DEBUG
       
    44 
    45 
    45 //////////HbDateTimeParser - Implementaion may change in future.//////////////
    46 //////////HbDateTimeParser - Implementaion may change in future.//////////////
    46 
    47 
    47 static inline int countRepeat(const QString &str, int index, int maxCount)
    48 static inline int countRepeat(const QString &str, int index, int maxCount)
    48 {
    49 {
   344     mLayout->setContentsMargins(0,0,0,0);
   345     mLayout->setContentsMargins(0,0,0,0);
   345     mContent->setLayout(mLayout);
   346     mContent->setLayout(mLayout);
   346     q->style()->setItemName(mContent,"content");
   347     q->style()->setItemName(mContent,"content");
   347 
   348 
   348     mDateTimeMode = dateTimeMode;
   349     mDateTimeMode = dateTimeMode;
       
   350     mIntervals[QDateTimeEdit::MinuteSection]=1;
   349 
   351 
   350     //read the format from locale
   352     //read the format from locale
   351     mFormat = localeDateTimeFormat(dateTimeMode);
   353     mFormat = localeDateTimeFormat(dateTimeMode);
   352 
   354 
   353     //parse the format and set the sections in order
   355     //parse the format and set the sections in order
   444 */
   446 */
   445 void HbDateTimePickerPrivate::rearrangeTumbleViews()
   447 void HbDateTimePickerPrivate::rearrangeTumbleViews()
   446 {                  
   448 {                  
   447     Q_Q(HbDateTimePicker);
   449     Q_Q(HbDateTimePicker);
   448 
   450 
   449     deleteAndNull(mYearPicker);
   451     if(!(mParser.mDisplaySections & (HbDateTimeParser::YearSection|
   450     deleteAndNull(mMonthPicker);
   452 				     HbDateTimeParser::YearSection2Digits))) {
   451     deleteAndNull(mDayPicker);
   453       deleteAndNull(mYearPicker);
   452     deleteAndNull(mHourPicker);
   454       mYearModel = 0;
   453     deleteAndNull(mMinutePicker);
   455     }
   454     deleteAndNull(mSecondPicker);
   456     if(!(mParser.mDisplaySections & HbDateTimeParser::MonthSection)) {
   455     deleteAndNull(mAmPmPicker);
   457       deleteAndNull(mMonthPicker);
   456 
   458       mMonthModel = 0;
   457     deleteAndNull(mYearModel);
   459     }
   458     deleteAndNull(mDayModel);
   460     if(!(mParser.mDisplaySections & HbDateTimeParser::DaySection)) {
   459     deleteAndNull(mMonthModel);
   461       deleteAndNull(mDayPicker);
   460     deleteAndNull(mHourModel);
   462       mDayModel = 0;
   461     deleteAndNull(mMinuteModel);
   463     }
   462     deleteAndNull(mSecondModel);
   464     if(!(mParser.mDisplaySections & (HbDateTimeParser::Hour12Section|
   463     deleteAndNull(mAmPmModel);
   465 				     HbDateTimeParser::Hour24Section))) {
       
   466       deleteAndNull(mHourPicker);
       
   467       mHourModel = 0;
       
   468     }
       
   469     if(!(mParser.mDisplaySections & HbDateTimeParser::MinuteSection)) {
       
   470       deleteAndNull(mMinutePicker);
       
   471       mMinuteModel = 0;
       
   472     }
       
   473     if(!(mParser.mDisplaySections & HbDateTimeParser::SecondSection)) {
       
   474       deleteAndNull(mSecondPicker);
       
   475       mSecondModel = 0;
       
   476     }
       
   477     if(!(mParser.mDisplaySections & HbDateTimeParser::AmPmSection)) {
       
   478       deleteAndNull(mAmPmPicker);
       
   479       mAmPmModel = 0;
       
   480     }
   464 
   481 
   465     mYearOffset = -1;
   482     mYearOffset = -1;
   466     mMonthOffset = -1;
   483     mMonthOffset = -1;
   467     mDayOffset = -1;
   484     mDayOffset = -1;
   468     mHourOffset = -1;
   485     mHourOffset = -1;
   469     mMinuteOffset = -1;
   486     mMinuteOffset = -1;
   470     mSecondOffset = -1;
   487     mSecondOffset = -1;
   471 
   488 
   472     QPointer<HbTumbleView> lastAdded;
   489     while(mLayout->count()) {
       
   490       mLayout->removeAt(0);
       
   491     }
       
   492 
       
   493     QPointer<VIEWER> lastAdded;
   473 
   494 
   474     for(int i=0;i<mParser.mSectionNodes.count();i++) {
   495     for(int i=0;i<mParser.mSectionNodes.count();i++) {
   475         switch(mParser.mSectionNodes[i].type) {
   496         switch(mParser.mSectionNodes[i].type) {
   476             case HbDateTimeParser::AmPmSection:
   497             case HbDateTimeParser::AmPmSection:
   477                 mAmPmPicker = new HbTumbleView(q);
   498                 if(!mAmPmPicker) {
   478                 mAmPmModel = new QStringListModel(q);
   499                     mAmPmPicker = new VIEWER(q);
   479                 mAmPmPicker->setModel(mAmPmModel);
   500                     mAmPmModel = static_cast<QStringListModel*>(mAmPmPicker->model());
   480                 mAmPmPicker->setLoopingEnabled(true);
   501                 }
   481                 mLayout->addItem(mAmPmPicker);
   502                 mLayout->addItem(mAmPmPicker);
   482                 mAmPmPicker->primitive("highlight")->hide();
       
   483                 mAmPmPicker->primitive("separator")->show();
       
   484                 lastAdded = mAmPmPicker;
   503                 lastAdded = mAmPmPicker;
   485                 break;
   504                 break;
   486 
   505 
   487             case HbDateTimeParser::DaySection:
   506             case HbDateTimeParser::DaySection:
   488             case HbDateTimeParser::DayOfWeekSection:
   507             case HbDateTimeParser::DayOfWeekSection:
   489                 mDayPicker = new HbTumbleView(q);
   508                 if(!mDayPicker) {
   490                 mDayModel = new QStringListModel(q);
   509                     mDayPicker = new VIEWER(q);
   491                 mDayPicker->setModel(mDayModel);
   510                     mDayModel = static_cast<QStringListModel*>(mDayPicker->model());
   492                 mDayPicker->setLoopingEnabled(true);
   511                     mDayPicker->setLoopingEnabled(true);
       
   512                 }
   493                 mLayout->addItem(mDayPicker);
   513                 mLayout->addItem(mDayPicker);
   494                 mDayPicker->primitive("separator")->show();
       
   495                 lastAdded = mDayPicker;
   514                 lastAdded = mDayPicker;
   496                 break;
   515                 break;
   497 
   516 
   498             case HbDateTimeParser::MonthSection:
   517             case HbDateTimeParser::MonthSection:
   499                 mMonthPicker = new HbTumbleView(q);
   518                 if(!mMonthPicker) {
   500                 mMonthModel = new QStringListModel(q);
   519                     mMonthPicker = new VIEWER(q);
   501                 mMonthPicker->setModel(mMonthModel);
   520                     mMonthModel = static_cast<QStringListModel*>(mMonthPicker->model());
   502                 mMonthPicker->setLoopingEnabled(true);
   521                     mMonthPicker->setLoopingEnabled(true);
       
   522                 }
   503                 mLayout->addItem(mMonthPicker);
   523                 mLayout->addItem(mMonthPicker);
   504                 mMonthPicker->primitive("separator")->show();
       
   505                 lastAdded = mMonthPicker;
   524                 lastAdded = mMonthPicker;
   506                 break;
   525                 break;
   507 
   526 
   508             case HbDateTimeParser::YearSection:
   527             case HbDateTimeParser::YearSection:
   509             case HbDateTimeParser::YearSection2Digits:
   528             case HbDateTimeParser::YearSection2Digits:
   510                 mYearPicker = new HbTumbleView(q);
   529                 if(!mYearPicker) {
   511                 mYearModel = new QStringListModel(q);
   530                     mYearPicker = new VIEWER(q);
   512                 mYearPicker->setModel(mYearModel);
   531                     mYearModel = static_cast<QStringListModel*>(mYearPicker->model());
   513                 mYearPicker->setLoopingEnabled(true);
   532                     mYearPicker->setLoopingEnabled(true);
       
   533                 }
   514                 mLayout->addItem(mYearPicker);
   534                 mLayout->addItem(mYearPicker);
   515                 mYearPicker->primitive("separator")->show();
       
   516                 lastAdded = mYearPicker;
   535                 lastAdded = mYearPicker;
   517                 break;
   536                 break;
   518 
   537 
   519             case HbDateTimeParser::SecondSection:
   538             case HbDateTimeParser::SecondSection:
   520                 mSecondPicker = new HbTumbleView(q);
   539                 if(!mSecondPicker) {
   521                 mSecondModel = new QStringListModel(q);
   540                     mSecondPicker = new VIEWER(q);
   522                 mSecondPicker->setModel(mSecondModel);
   541                     mSecondModel = static_cast<QStringListModel*>(mSecondPicker->model());
   523                 mSecondPicker->setLoopingEnabled(true);
   542                     mSecondPicker->setLoopingEnabled(true);
       
   543                 }
   524                 mLayout->addItem(mSecondPicker);
   544                 mLayout->addItem(mSecondPicker);
   525                 mSecondPicker->primitive("separator")->show();
       
   526                 lastAdded = mSecondPicker;
   545                 lastAdded = mSecondPicker;
   527                 break;
   546                 break;
   528 
   547 
   529             case HbDateTimeParser::MinuteSection:
   548             case HbDateTimeParser::MinuteSection:
   530                 mMinutePicker = new HbTumbleView(q);
   549                 if(!mMinutePicker) {
   531                 mMinuteModel = new QStringListModel(q);
   550                     mMinutePicker = new VIEWER(q);
   532                 mMinutePicker->setModel(mMinuteModel);
   551                     mMinuteModel = static_cast<QStringListModel*>(mMinutePicker->model());
   533                 mMinutePicker->setLoopingEnabled(true);
   552                     mMinutePicker->setLoopingEnabled(true);
       
   553                 }
   534                 mLayout->addItem(mMinutePicker);
   554                 mLayout->addItem(mMinutePicker);
   535                 mMinutePicker->primitive("separator")->show();
       
   536                 lastAdded = mMinutePicker;
   555                 lastAdded = mMinutePicker;
   537                 break;
   556                 break;
   538 
   557 
   539             case HbDateTimeParser::Hour12Section:
   558             case HbDateTimeParser::Hour12Section:
   540             case HbDateTimeParser::Hour24Section:
   559             case HbDateTimeParser::Hour24Section:
   541                 mHourPicker = new HbTumbleView(q);
   560                 if(!mHourPicker) {
   542                 mHourModel = new QStringListModel(q);
   561                     mHourPicker = new VIEWER(q);
   543                 mHourPicker->setModel(mHourModel);
   562                     mHourModel = static_cast<QStringListModel*>(mHourPicker->model());
   544                 mHourPicker->setLoopingEnabled(true);
   563                     mHourPicker->setLoopingEnabled(true);
       
   564                 }
   545                 mLayout->addItem(mHourPicker);
   565                 mLayout->addItem(mHourPicker);
   546                 mHourPicker->primitive("separator")->show();
       
   547                 lastAdded = mHourPicker;
   566                 lastAdded = mHourPicker;
   548                 break;
   567                 break;
   549 
   568 
   550             default:
   569             default:
   551                 break;
   570                 break;
   630 }
   649 }
   631 
   650 
   632 
   651 
   633 void HbDateTimePickerPrivate::setRanges() 
   652 void HbDateTimePickerPrivate::setRanges() 
   634 {
   653 {
       
   654     //clear all data before inserting
       
   655     if(mYearModel) mYearModel->removeRows(0,mYearModel->rowCount());    
       
   656     //insert data
   635     if(mIsTwoDigitYearFormat) {
   657     if(mIsTwoDigitYearFormat) {
   636         mYearOffset = mMinimumDate.date().year()%100;
   658         mYearOffset = mMinimumDate.date().year()%100;
   637         setYearRange(mMinimumDate.date().year()%100,mMaximumDate.date().year()%100); 
   659         setYearRange(mMinimumDate.date().year()%100,mMaximumDate.date().year()%100); 
   638     } else {
   660     } else {
   639         mYearOffset = mMinimumDate.date().year();
   661         mYearOffset = mMinimumDate.date().year();
   640         setYearRange(mMinimumDate.date().year(),mMaximumDate.date().year()); 
   662         setYearRange(mMinimumDate.date().year(),mMaximumDate.date().year()); 
   641     }
   663     }
   642 
   664 
       
   665     if(mMonthModel) mMonthModel->removeRows(0,mMonthModel->rowCount());
   643     mMonthOffset = 1;
   666     mMonthOffset = 1;
   644     setMonthRange(1,12);//default all months
   667     setMonthRange(1,12);//default all months
   645 
   668 
       
   669     if(mDayModel) mDayModel->removeRows(0,mDayModel->rowCount());
   646     mDayOffset = 1;
   670     mDayOffset = 1;
   647     setDayRange(1,31);//default all days
   671     setDayRange(1,31);//default all days
   648 
   672 
       
   673     if(mHourModel) mHourModel->removeRows(0,mHourModel->rowCount());
   649     mHourOffset = 0;
   674     mHourOffset = 0;
   650     setHourRange(0,23);
   675     setHourRange(0,23);
   651 
   676 
       
   677     if(mMinuteModel) mMinuteModel->removeRows(0,mMinuteModel->rowCount());
   652     mMinuteOffset = 0;
   678     mMinuteOffset = 0;
   653     setMinuteRange(0,59);
   679     setMinuteRange(0,59);
   654 
   680 
       
   681     if(mSecondModel) mSecondModel->removeRows(0,mSecondModel->rowCount());
   655     mSecondOffset = 0;
   682     mSecondOffset = 0;
   656     setSecondRange(0,59);
   683     setSecondRange(0,59);
   657 
   684 
       
   685     if(mAmPmModel) mAmPmModel->removeRows(0,mAmPmModel->rowCount());
   658     setAmPm();
   686     setAmPm();
   659 }
   687 }
   660 
   688 
   661 void HbDateTimePickerPrivate::syncVisualDate()
   689 void HbDateTimePickerPrivate::syncVisualDate()
   662 {
   690 {
   835                 }
   863                 }
   836             }
   864             }
   837             else{
   865             else{
   838                 index = newDateTime.time().minute()-mMinuteOffset;
   866                 index = newDateTime.time().minute()-mMinuteOffset;
   839             }
   867             }
       
   868 #ifdef HBDATETIMEPICKER_DEBUG
       
   869     qDebug() << "setMinuteRange:selecting= " << index;
       
   870 #endif
   840             mMinutePicker->setSelected(index);
   871             mMinutePicker->setSelected(index);
   841         }
   872         }
   842 
   873 
   843         if(mSecondPicker) {
   874         if(mSecondPicker) {
   844 #ifdef HBDATETIMEPICKER_DEBUG
   875 #ifdef HBDATETIMEPICKER_DEBUG
  1018     if(!mMinutePicker) {
  1049     if(!mMinutePicker) {
  1019         return;
  1050         return;
  1020     }
  1051     }
  1021 #ifdef HBDATETIMEPICKER_DEBUG
  1052 #ifdef HBDATETIMEPICKER_DEBUG
  1022     qDebug() << "setMinuteRange: " << start << " ," << end;
  1053     qDebug() << "setMinuteRange: " << start << " ," << end;
       
  1054     qDebug() << "setMinuteRange:interval=" << mIntervals[QDateTimeEdit::MinuteSection];
  1023 #endif
  1055 #endif
  1024     //calculate the index it should be after resize
  1056     //calculate the index it should be after resize
  1025     //the currentIndex gets reset after the resize and gets set to 0
  1057     //the currentIndex gets reset after the resize and gets set to 0
  1026     //to work around that issue this is added
  1058     //to work around that issue this is added
  1027     int newIndex = mMinutePicker->selected()-(start-mMinuteOffset);
  1059     int newIndex = mMinuteModel->index(mMinutePicker->selected(),0).data().toInt();
  1028     if(newIndex < 0) {
  1060     if(newIndex < 0) {
  1029         newIndex = 0;
  1061         newIndex = 0;
  1030     }
  1062     }
  1031     if(newIndex > (end-start)) {
  1063     if(newIndex > (end-start)) {
  1032         newIndex = end-start;
  1064         newIndex = end-start;
  1033     }
  1065     }
  1034 
  1066 
  1035     //Store the value before resizing the model.
  1067     resizeModel(mMinuteModel, 
  1036     int value = mMinuteModel->index(mMinutePicker->selected()).data().toInt();
  1068 		mMinuteOffset,mMinuteModel->index(mMinuteModel->rowCount() - 1).data().toInt(),
  1037 
  1069 		start,end,
  1038     if(mIntervals[QDateTimeEdit::MinuteSection] > 1){ 
  1070 		&HbDateTimePickerPrivate::localeMinute, 
  1039         if((mIntervals[QDateTimeEdit::MinuteSection] <= mMinimumDate.time().minute()) &&
  1071 		mIntervals[QDateTimeEdit::MinuteSection]);
  1040             !isMinimumHour()){
       
  1041                 int i = 0;
       
  1042                 for(i = start; i > 0; i -= mIntervals[QDateTimeEdit::MinuteSection]){
       
  1043 
       
  1044                 }
       
  1045 
       
  1046                 start = i;
       
  1047         }
       
  1048         else{
       
  1049             start = mMinimumDate.time().minute();
       
  1050         }
       
  1051     }
       
  1052 
       
  1053     resizeModel(mMinuteModel, mMinuteOffset,mMinuteModel->index(mMinuteModel->rowCount() - 1).data().toInt()/*mMinuteOffset+mMinuteModel->mMinuteModel->rowCount()-1*/,
       
  1054         start,end,
       
  1055         &HbDateTimePickerPrivate::localeMinute, mIntervals[QDateTimeEdit::MinuteSection]);
       
  1056     mMinuteOffset = start;
  1072     mMinuteOffset = start;
  1057 
  1073 
  1058     //Select the nearest value when the range is set.
  1074     //Select the nearest value when the range is set.
  1059     int index = newIndex;
  1075     int index = 0;
  1060     if(mIntervals[QDateTimeEdit::MinuteSection] > 1){
  1076 
  1061         for(int i = 0; i < mMinuteModel->rowCount(); i++){
  1077     for(int i=start;i<newIndex;i+=mIntervals[QDateTimeEdit::MinuteSection]) {
  1062 
  1078       index++;
  1063             if(mMinuteModel->index(i,0).data().toInt() <= value){
  1079     }
  1064                 index = i;
  1080 #ifdef HBDATETIMEPICKER_DEBUG
  1065             }
  1081     qDebug() << "initMinute:selecting= " << index;
  1066             else{
  1082 #endif
  1067                 break;
       
  1068             }
       
  1069         }
       
  1070     }
       
  1071     mMinutePicker->setSelected(index);
  1083     mMinutePicker->setSelected(index);
  1072 
  1084 
  1073     mDateTime.setTime(QTime(mDateTime.time().hour(), localeMinute(mMinuteModel->index(index,0).data().toInt()).toInt(), mDateTime.time().second()));
  1085     mDateTime.setTime(QTime(mDateTime.time().hour(), localeMinute(mMinuteModel->index(index,0).data().toInt()).toInt(), mDateTime.time().second()));
  1074 
  1086 
  1075     //check if minute is valid
  1087     //check if minute is valid
  1152     if(mIs24HourFormat) {
  1164     if(mIs24HourFormat) {
  1153         return mLocale.toString(QTime(hour,0,0),mHourFormat);
  1165         return mLocale.toString(QTime(hour,0,0),mHourFormat);
  1154     } 
  1166     } 
  1155 
  1167 
  1156     QString hourStr=mLocale.toString(QTime(hour,0,0),QString("%1:%2").arg(mHourFormat).arg("ap"));
  1168     QString hourStr=mLocale.toString(QTime(hour,0,0),QString("%1:%2").arg(mHourFormat).arg("ap"));
  1157     QStringList hourAm=hourStr.split(":");
  1169     QStringList hourAm=hourStr.split(':');
  1158     if(hourAm.count() > 1) {
  1170     if(hourAm.count() > 1) {
  1159         return hourAm.at(0);
  1171         return hourAm.at(0);
  1160     }
  1172     }
  1161     return QString("Format Err");
  1173     return QString("Format Err");
  1162 }
  1174 }
  1187 
  1199 
  1188 /* there are seven different models for seven pickers. insertion and removal
  1200 /* there are seven different models for seven pickers. insertion and removal
  1189    to each of the models to resize them its the same logic. but to populate the
  1201    to each of the models to resize them its the same logic. but to populate the
  1190    data need the appropriate locale and format converted data. which is passed
  1202    data need the appropriate locale and format converted data. which is passed
  1191    as a function pointer instead of creating seven different QStringListModel derived
  1203    as a function pointer instead of creating seven different QStringListModel derived
  1192    model classes with one interface/virtual fuction specialization.
  1204    model classes with one interface/virtual function specialization.
  1193 */
  1205 */
  1194 void HbDateTimePickerPrivate::resizeModel(QStringListModel *model,
  1206 void HbDateTimePickerPrivate::resizeModel(QStringListModel *model,
  1195             int oldStart, int oldEnd,
  1207             int oldStart, int oldEnd,
  1196             int newStart, int newEnd,
  1208             int newStart, int newEnd,
  1197             QString (HbDateTimePickerPrivate::*localeFunc)(int), int interval)
  1209             QString (HbDateTimePickerPrivate::*localeFunc)(int), int interval)
  1198 {
  1210 {
  1199     if((model->rowCount() == 0) && (newEnd-newStart>=0)) {
  1211     class ConnectionRemover {
  1200         //initialize condition
  1212     public:
  1201         int previous = newStart;
  1213         ConnectionRemover(HbDateTimePickerPrivate *priv){
  1202         for(int i=0;i<=newEnd-newStart;i++) {
  1214             this->priv = priv;
  1203             QString text;
  1215             priv->removeConnections();
  1204 
  1216         }
  1205             if(interval > 1){
  1217         ~ConnectionRemover() {
  1206 
  1218             priv->makeConnections();
  1207                 if(previous <= newEnd){
  1219         }
  1208                     model->insertRow(i);
  1220         HbDateTimePickerPrivate *priv;
  1209                     text = (this->*localeFunc)(previous);
  1221     }Obj(this);
  1210                 }
  1222 
  1211                 else{
  1223 #ifdef HBDATETIMEPICKER_DEBUG
  1212                     break;
  1224             qDebug() << "resizeModel: oldStart=" << oldStart
  1213                 }
  1225                      << " oldEnd=" << oldEnd << " newStart=" 
  1214 
  1226                      << newStart << " newEnd=" << newEnd
  1215                 previous += interval;
  1227                      << " interval=" << interval;
       
  1228 #endif
       
  1229 	    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; 
       
  1231 #ifdef HBDATETIMEPICKER_DEBUG
       
  1232             qDebug() << "resizeModel:sameoldInterval=" << oldinterval;
       
  1233 #endif
       
  1234             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 	        }
  1216             }
  1267             }
  1217             else{
  1268 
  1218                 model->insertRow(i);
  1269         if((model->rowCount() == 0) && (newEnd-newStart>=0)) {
  1219                 text = (this->*localeFunc)(i+newStart);
  1270 #ifdef HBDATETIMEPICKER_DEBUG
  1220             }
  1271             qDebug() << "resizeModel:default addition inserting(0," << (newEnd-newStart+1)/interval << ")";
  1221 
  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);
  1222 #ifdef HB_TEXT_MEASUREMENT_UTILITY
  1277 #ifdef HB_TEXT_MEASUREMENT_UTILITY
  1223             if ( localeFunc == &HbDateTimePickerPrivate::localeMonth &&
  1278                 if ( localeFunc == &HbDateTimePickerPrivate::localeMonth &&
  1224                 HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
  1279                         HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
  1225                     text.append(QChar(LOC_TEST_START));
  1280                     text.append(QChar(LOC_TEST_START));
  1226                     text.append("qtl_datetimepicker_popup_month_sec");
  1281                     text.append("qtl_datetimepicker_popup_month_sec");
  1227                     text.append(QChar(LOC_TEST_END));
  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                 }
  1228             }
  1292             }
  1229 #endif
  1293             return;
  1230             QModelIndex index=model->index(i,0);
  1294         }
  1231             if(index.isValid()) {
  1295 
  1232                 model->setData(index,text);//TODO:add a readable typedef
  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                 }
  1233             }
  1309             }
  1234 
  1310         }
  1235         }
  1311 
  1236         return;
  1312         if(newEnd>oldEnd) {
  1237     }
  1313             int rowCount=model->rowCount();
  1238 
  1314 #ifdef HBDATETIMEPICKER_DEBUG
  1239     if(newStart < oldStart) {
  1315             qDebug() << "resizeModel:inserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
  1240         int previous = newStart;
  1316 #endif
  1241 
  1317             model->insertRows(rowCount,(newEnd-oldEnd)/interval);
  1242         for(int i=0;i<oldStart-newStart;++i) {
  1318             for(int i=0;i<((newEnd-oldEnd)/interval);++i) {
  1243             QString text;
  1319                 QModelIndex index=model->index(i+rowCount,0);
  1244 
  1320                 if(index.isValid()) {
  1245             if(interval > 1){
  1321                     model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd));
  1246 
  1322 #ifdef HBDATETIMEPICKER_DEBUG
  1247                 if(previous < oldStart){
  1323                     qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
  1248                     model->insertRow(i);
  1324 #endif
  1249                     text = (this->*localeFunc)(previous);
  1325                 }
  1250                 }
       
  1251                 else{
       
  1252                     break;
       
  1253                 }
       
  1254 
       
  1255                 previous += interval;
       
  1256             }
  1326             }
  1257             else{
  1327         }
  1258                 model->insertRow(i);
  1328         if(newStart>oldStart) {
  1259                 text = (this->*localeFunc)(i+newStart);
  1329 #ifdef HBDATETIMEPICKER_DEBUG
  1260             }
  1330             qDebug() << "resizeModel:removing(0," << (newStart-oldStart)/interval << ")"
  1261 
  1331                              << " data=" << model->index((newStart-oldStart)/interval,0).data().toString();
  1262             QModelIndex index=model->index(i,0);
  1332 #endif
  1263             if(index.isValid()) {
  1333             model->removeRows(0,(newStart-oldStart)/interval);
  1264                 model->setData(index,text);
  1334         }
  1265             }
  1335 
  1266         }
  1336         if(oldEnd>newEnd) {
  1267     }
  1337 //#ifdef HBDATETIMEPICKER_DEBUG
  1268     if(newEnd > oldEnd) {
  1338 //            qDebug() << "resizeModel:removing(" <<model->rowCount()-((oldEnd-newEnd)/interval)<<"," << (oldEnd-newEnd)/interval << ")";
  1269 
  1339 //#endif
  1270         int rowCount = model->rowCount(); 
  1340 //            model->removeRows((model->rowCount()-((oldEnd-newEnd)/interval)),(oldEnd-newEnd)/interval);
  1271         int previous = oldEnd+interval;
  1341                     //if the start offset is preset more items can fit at end
  1272         for(int i=0;i<newEnd-oldEnd;++i) {
  1342                     int stay=((newEnd-newStart)/interval)+1;
  1273             QString text;
  1343                     int count=model->rowCount()-stay;
  1274 
  1344 #ifdef HBDATETIMEPICKER_DEBUG
  1275             if(interval > 1){
  1345                     qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
  1276 
  1346                              << " data=" << model->index((model->rowCount()-count),0).data().toString();
  1277                 if(previous <= newEnd){
  1347 #endif
  1278                     model->insertRows(rowCount+i,1);
  1348                     model->removeRows((model->rowCount()-count),count);
  1279                     text = (this->*localeFunc)(previous);
  1349         }
  1280                 }
  1350 }  
  1281                 else{
  1351 
  1282                     break;
       
  1283                 }
       
  1284 
       
  1285                 previous += interval;
       
  1286             }
       
  1287             else{
       
  1288                 model->insertRows(rowCount+i,1);
       
  1289                 text = (this->*localeFunc)(oldEnd+i+1);
       
  1290             }
       
  1291 
       
  1292             QModelIndex index=model->index(rowCount+i,0);
       
  1293             if(index.isValid()) {
       
  1294                 model->setData(index,text);
       
  1295             }
       
  1296         }
       
  1297     }
       
  1298 
       
  1299     if(newStart > oldStart) {
       
  1300         if(interval > 1){
       
  1301             for(int i = oldStart; i < newStart; i += interval){
       
  1302                 model->removeRows(0, 1);
       
  1303             }
       
  1304         }
       
  1305         else{
       
  1306             model->removeRows(0,newStart-oldStart);
       
  1307         }
       
  1308     }
       
  1309 
       
  1310     if(oldEnd > newEnd) {
       
  1311         if(interval > 1){
       
  1312             for(int i = oldEnd; i > newEnd; i -= interval){
       
  1313                 model->removeRows(model->rowCount()-1, 1);
       
  1314             }
       
  1315         }
       
  1316         else{
       
  1317             model->removeRows((model->rowCount()-(oldEnd-newEnd)),oldEnd-newEnd);
       
  1318         }
       
  1319     }
       
  1320 
       
  1321     if(interval > 1){
       
  1322         //Check if there's any mismatch between actual rows in the model and the supposed rows.
       
  1323         int previous = newStart;
       
  1324         int actualRowCount = 0;
       
  1325         for(actualRowCount=0;actualRowCount<=newEnd-newStart;actualRowCount++) {
       
  1326             if(previous <= newEnd){
       
  1327             }
       
  1328             else{
       
  1329                 break;
       
  1330             }
       
  1331 
       
  1332             previous += interval;
       
  1333         }
       
  1334 
       
  1335         if(actualRowCount > model->rowCount()){
       
  1336             model->insertRows(model->rowCount(), actualRowCount - model->rowCount());
       
  1337         }
       
  1338         else if( actualRowCount < model->rowCount()){
       
  1339             model->removeRows(model->rowCount()-1, model->rowCount() - actualRowCount);
       
  1340         }
       
  1341 
       
  1342         //Populate the data in the model.
       
  1343         previous = newStart;
       
  1344         for(int i = 0; i < model->rowCount(); i++)
       
  1345         {
       
  1346             if(previous <= newEnd){
       
  1347                 model->setData(model->index(i), (this->*localeFunc)(previous));
       
  1348             }
       
  1349             else{
       
  1350                 break;
       
  1351             }
       
  1352             previous += interval;
       
  1353         }
       
  1354     }
       
  1355 }
       
  1356 
  1352 
  1357 void HbDateTimePickerPrivate::createPrimitives()
  1353 void HbDateTimePickerPrivate::createPrimitives()
  1358 {
  1354 {
  1359     Q_Q(HbDateTimePicker);
  1355     Q_Q(HbDateTimePicker);
  1360     if(!mBackground) {
  1356     if(!mBackground) {
  1458     emitDateChange();
  1454     emitDateChange();
  1459 }
  1455 }
  1460 
  1456 
  1461 void HbDateTimePickerPrivate::_q_yearChanged(int index)
  1457 void HbDateTimePickerPrivate::_q_yearChanged(int index)
  1462 {
  1458 {
       
  1459 #ifdef HBDATETIMEPICKER_DEBUG
  1463     qDebug() << "_q_yearChanged:" << index;
  1460     qDebug() << "_q_yearChanged:" << index;
       
  1461 #endif
  1464     //Q_Q(HbDateTimePicker);
  1462     //Q_Q(HbDateTimePicker);
  1465     QDate newDate(mDateTime.date());
  1463     QDate newDate(mDateTime.date());
  1466     if(mIsTwoDigitYearFormat) {
  1464     if(mIsTwoDigitYearFormat) {
  1467         newDate = newDate.addYears(index+mYearOffset-(newDate.year()%100));
  1465         newDate = newDate.addYears(index+mYearOffset-(newDate.year()%100));
  1468     }
  1466     }
  1557     //check if minute range changed
  1555     //check if minute range changed
  1558     int start=0,end=0;
  1556     int start=0,end=0;
  1559     if(mMinutePicker) {
  1557     if(mMinutePicker) {
  1560         start=mMinuteOffset;
  1558         start=mMinuteOffset;
  1561         end=start+mMinuteModel->rowCount()-1;
  1559         end=start+mMinuteModel->rowCount()-1;
  1562         if(isMinimumHour())  {
  1560         if(isMinimumHour() )  {
  1563             start = mMinimumDate.time().minute();
  1561             start = mMinimumDate.time().minute();
  1564         } else {
  1562         } else {               
  1565             start = 0;
  1563             if(mIntervals[QDateTimeEdit::MinuteSection]!=1 && (mIntervals[QDateTimeEdit::MinuteSection]>0)) {
       
  1564                 start = mMinimumDate.time().minute()%mIntervals[QDateTimeEdit::MinuteSection];
       
  1565             } else {
       
  1566                 start = 0;
       
  1567             }
  1566         }
  1568         }
  1567         if(isMaximumHour()) {
  1569         if(isMaximumHour()) {
  1568             end = mMaximumDate.time().minute();
  1570             end = mMaximumDate.time().minute();
  1569         } else {
  1571         } else {
  1570             end = 59;
  1572             end = 59;