src/hbwidgets/widgets/hbdatetimepicker_p.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
--- a/src/hbwidgets/widgets/hbdatetimepicker_p.cpp	Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbwidgets/widgets/hbdatetimepicker_p.cpp	Fri Sep 17 08:32:10 2010 +0300
@@ -186,7 +186,7 @@
                     newDisplay |= AmPmSection;
                     if (i + 1 < format.size()
                         && format.at(i+1) == (cap ? QLatin1Char('P') : QLatin1Char('p'))) {
-                            ++i;
+                        ++i;
                     }
                     index = i + 1;
                 }
@@ -196,7 +196,7 @@
                     const int repeat = countRepeat(format, i, 4);
                     if (repeat >= 2) {
                         const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits,
-                            i - add, repeat == 4 ? 4 : 2 };
+                                                 i - add, repeat == 4 ? 4 : 2 };
                         newSectionNodes.append(sn);
                         appendSeparator(&newSeparators, format, index, i - index, lastQuote);
                         i += sn.count - 1;
@@ -278,7 +278,7 @@
         return mDisplayFormat.size() - sectionPos(sectionIndex) - mSeparators.last().size();
     } else {
         return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex)
-            - mSeparators.at(sectionIndex + 1).size();
+                - mSeparators.at(sectionIndex + 1).size();
     }
 }
 
@@ -304,7 +304,7 @@
 
 
 HbDateTimePickerPrivate::HbDateTimePickerPrivate()
-:HbWidgetPrivate()
+    :HbWidgetPrivate()
     ,mDayPicker(0)
     ,mMonthPicker(0)
     ,mYearPicker(0)
@@ -329,6 +329,7 @@
     ,mDateTimeMode(QVariant::Date) //default is date mode
     ,mLayout(0)         
     //,mFormat() //set the format again in init()
+    ,mFormatEventType(-1)
     //,mDisplaySecions() //is blank by default
     ,mParser()
     ,mYearFormat()
@@ -339,10 +340,10 @@
     ,mSecondFormat() 
     ,mIs24HourFormat(false)
     ,mIsTwoDigitYearFormat(false)
+    ,mContent(0)
+    ,mIntervals()
     ,mBackground(0)
     ,mFrame(0)
-    ,mContent(0)
-    ,mIntervals()
     ,mHighlight(0)
 {
     mMinimumDate = HBDATETIMEPICKER_DATETIME_MIN;
@@ -372,21 +373,16 @@
 
     mDateTimeMode = dateTimeMode;
     mIntervals[QDateTimeEdit::MinuteSection]=1;
-
+    mFormatEventType = QEvent::registerEventType(QEvent::User+1);
     //read the format from locale
     QString newFormat = localeDateTimeFormat(dateTimeMode);
-
-    //parse the format and set the sections in order
-    if(isFormatValid(newFormat)) {
-        mFormat=newFormat;
-        processDisplaySections();
+    if(isFormatValid(newFormat)){
+        mFormat = newFormat;
+        postFormatEvent();
     }
-
+    
     //create primitives
     createPrimitives();
-
-    //recreate and rearrange depending on the format
-    rearrangeTumbleViews();
 }
 
 /*!
@@ -419,50 +415,50 @@
 */
 void HbDateTimePickerPrivate::processDisplaySections()
 {
-        for(int i=0;i<mParser.mSectionNodes.count();++i) {
-            switch(mParser.mSectionNodes[i].type) {
-                case HbDateTimeParser::DaySection:
-                case HbDateTimeParser::DayOfWeekSection:
-                    mDayFormat = QString(mParser.mSectionNodes[i].count,'d');
-                    break;
+    for(int i=0;i<mParser.mSectionNodes.count();++i) {
+        switch(mParser.mSectionNodes[i].type) {
+        case HbDateTimeParser::DaySection:
+        case HbDateTimeParser::DayOfWeekSection:
+            mDayFormat = QString(mParser.mSectionNodes[i].count,'d');
+            break;
 
-                case HbDateTimeParser::MonthSection:
-                    mMonthFormat = QString(mParser.mSectionNodes[i].count,'M');
-                    break;
+        case HbDateTimeParser::MonthSection:
+            mMonthFormat = QString(mParser.mSectionNodes[i].count,'M');
+            break;
 
-                case HbDateTimeParser::YearSection:
-                    mIsTwoDigitYearFormat = false;
-                    mYearFormat = QString(mParser.mSectionNodes[i].count,'y');
-                    break;
+        case HbDateTimeParser::YearSection:
+            mIsTwoDigitYearFormat = false;
+            mYearFormat = QString(mParser.mSectionNodes[i].count,'y');
+            break;
 
-                case HbDateTimeParser::YearSection2Digits:
-                    mIsTwoDigitYearFormat = true;
-                    mYearFormat = QString(mParser.mSectionNodes[i].count,'y');
-                    break;
+        case HbDateTimeParser::YearSection2Digits:
+            mIsTwoDigitYearFormat = true;
+            mYearFormat = QString(mParser.mSectionNodes[i].count,'y');
+            break;
 
-                case HbDateTimeParser::SecondSection:
-                    mSecondFormat = QString(mParser.mSectionNodes[i].count,'s');
-                    break;
+        case HbDateTimeParser::SecondSection:
+            mSecondFormat = QString(mParser.mSectionNodes[i].count,'s');
+            break;
 
-                case HbDateTimeParser::MinuteSection:
-                    mMinuteFormat = QString(mParser.mSectionNodes[i].count,'m');
-                    break;
+        case HbDateTimeParser::MinuteSection:
+            mMinuteFormat = QString(mParser.mSectionNodes[i].count,'m');
+            break;
 
-                case HbDateTimeParser::Hour12Section:
-                    mIs24HourFormat = false;
-                    mHourFormat = QString(mParser.mSectionNodes[i].count,'h');
-                    break;
+        case HbDateTimeParser::Hour12Section:
+            mIs24HourFormat = false;
+            mHourFormat = QString(mParser.mSectionNodes[i].count,'h');
+            break;
 
-                case HbDateTimeParser::Hour24Section:
-                    mIs24HourFormat = true;
-                    mHourFormat = QString(mParser.mSectionNodes[i].count,'h');
-                    break;
+        case HbDateTimeParser::Hour24Section:
+            mIs24HourFormat = true;
+            mHourFormat = QString(mParser.mSectionNodes[i].count,'h');
+            break;
 
-                default:
-                    break;
-                    /*case HbDateTimeParser::DayOfWeekSection: not supported */
-            }
+        default:
+            break;
+            /*case HbDateTimeParser::DayOfWeekSection: not supported */
         }
+    }
 }
 
 /*
@@ -475,34 +471,34 @@
     Q_Q(HbDateTimePicker);
 
     if(!(mParser.mDisplaySections & (HbDateTimeParser::YearSection|
-                     HbDateTimeParser::YearSection2Digits))) {
-      deleteAndNull(mYearPicker);
-      mYearModel = 0;
+                                     HbDateTimeParser::YearSection2Digits))) {
+        deleteAndNull(mYearPicker);
+        mYearModel = 0;
     }
     if(!(mParser.mDisplaySections & HbDateTimeParser::MonthSection)) {
-      deleteAndNull(mMonthPicker);
-      mMonthModel = 0;
+        deleteAndNull(mMonthPicker);
+        mMonthModel = 0;
     }
     if(!(mParser.mDisplaySections & HbDateTimeParser::DaySection)) {
-      deleteAndNull(mDayPicker);
-      mDayModel = 0;
+        deleteAndNull(mDayPicker);
+        mDayModel = 0;
     }
     if(!(mParser.mDisplaySections & (HbDateTimeParser::Hour12Section|
-                     HbDateTimeParser::Hour24Section))) {
-      deleteAndNull(mHourPicker);
-      mHourModel = 0;
+                                     HbDateTimeParser::Hour24Section))) {
+        deleteAndNull(mHourPicker);
+        mHourModel = 0;
     }
     if(!(mParser.mDisplaySections & HbDateTimeParser::MinuteSection)) {
-      deleteAndNull(mMinutePicker);
-      mMinuteModel = 0;
+        deleteAndNull(mMinutePicker);
+        mMinuteModel = 0;
     }
     if(!(mParser.mDisplaySections & HbDateTimeParser::SecondSection)) {
-      deleteAndNull(mSecondPicker);
-      mSecondModel = 0;
+        deleteAndNull(mSecondPicker);
+        mSecondModel = 0;
     }
     if(!(mParser.mDisplaySections & HbDateTimeParser::AmPmSection)) {
-      deleteAndNull(mAmPmPicker);
-      mAmPmModel = 0;
+        deleteAndNull(mAmPmPicker);
+        mAmPmModel = 0;
     }
 
     mYearOffset = -1;
@@ -513,87 +509,87 @@
     mSecondOffset = -1;
 
     while(mLayout->count()) {
-      mLayout->removeAt(0);
+        mLayout->removeAt(0);
     }
 
     QPointer<VIEWER> lastAdded;
 
     for(int i=0;i<mParser.mSectionNodes.count();i++) {
         switch(mParser.mSectionNodes[i].type) {
-            case HbDateTimeParser::AmPmSection:
-                if(!mAmPmPicker) {
-                    mAmPmPicker = new VIEWER(q);
-                    mAmPmModel = static_cast<QStringListModel*>(mAmPmPicker->model());
-                }
-                mLayout->addItem(mAmPmPicker);
-                lastAdded = mAmPmPicker;
-                break;
+        case HbDateTimeParser::AmPmSection:
+            if(!mAmPmPicker) {
+                mAmPmPicker = new VIEWER(q);
+                mAmPmModel = static_cast<QStringListModel*>(mAmPmPicker->model());
+            }
+            mLayout->addItem(mAmPmPicker);
+            lastAdded = mAmPmPicker;
+            break;
 
             case HbDateTimeParser::DaySection:
             case HbDateTimeParser::DayOfWeekSection:
-                if(!mDayPicker) {
-                    mDayPicker = new VIEWER(q);
-                    mDayModel = static_cast<QStringListModel*>(mDayPicker->model());
-                    mDayPicker->setLoopingEnabled(true);
-                }
-                mLayout->addItem(mDayPicker);
-                lastAdded = mDayPicker;
-                break;
+            if(!mDayPicker) {
+                mDayPicker = new VIEWER(q);
+                mDayModel = static_cast<QStringListModel*>(mDayPicker->model());
+                mDayPicker->setLoopingEnabled(true);
+            }
+            mLayout->addItem(mDayPicker);
+            lastAdded = mDayPicker;
+            break;
 
             case HbDateTimeParser::MonthSection:
-                if(!mMonthPicker) {
-                    mMonthPicker = new VIEWER(q);
-                    mMonthModel = static_cast<QStringListModel*>(mMonthPicker->model());
-                    mMonthPicker->setLoopingEnabled(true);
-                }
-                mLayout->addItem(mMonthPicker);
-                lastAdded = mMonthPicker;
-                break;
+            if(!mMonthPicker) {
+                mMonthPicker = new VIEWER(q);
+                mMonthModel = static_cast<QStringListModel*>(mMonthPicker->model());
+                mMonthPicker->setLoopingEnabled(true);
+            }
+            mLayout->addItem(mMonthPicker);
+            lastAdded = mMonthPicker;
+            break;
 
             case HbDateTimeParser::YearSection:
             case HbDateTimeParser::YearSection2Digits:
-                if(!mYearPicker) {
-                    mYearPicker = new VIEWER(q);
-                    mYearModel = static_cast<QStringListModel*>(mYearPicker->model());
-                    mYearPicker->setLoopingEnabled(true);
-                }
-                mLayout->addItem(mYearPicker);
-                lastAdded = mYearPicker;
-                break;
+            if(!mYearPicker) {
+                mYearPicker = new VIEWER(q);
+                mYearModel = static_cast<QStringListModel*>(mYearPicker->model());
+                mYearPicker->setLoopingEnabled(true);
+            }
+            mLayout->addItem(mYearPicker);
+            lastAdded = mYearPicker;
+            break;
 
             case HbDateTimeParser::SecondSection:
-                if(!mSecondPicker) {
-                    mSecondPicker = new VIEWER(q);
-                    mSecondModel = static_cast<QStringListModel*>(mSecondPicker->model());
-                    mSecondPicker->setLoopingEnabled(true);
-                }
-                mLayout->addItem(mSecondPicker);
-                lastAdded = mSecondPicker;
-                break;
+            if(!mSecondPicker) {
+                mSecondPicker = new VIEWER(q);
+                mSecondModel = static_cast<QStringListModel*>(mSecondPicker->model());
+                mSecondPicker->setLoopingEnabled(true);
+            }
+            mLayout->addItem(mSecondPicker);
+            lastAdded = mSecondPicker;
+            break;
 
             case HbDateTimeParser::MinuteSection:
-                if(!mMinutePicker) {
-                    mMinutePicker = new VIEWER(q);
-                    mMinuteModel = static_cast<QStringListModel*>(mMinutePicker->model());
-                    mMinutePicker->setLoopingEnabled(true);
-                }
-                mLayout->addItem(mMinutePicker);
-                lastAdded = mMinutePicker;
-                break;
+            if(!mMinutePicker) {
+                mMinutePicker = new VIEWER(q);
+                mMinuteModel = static_cast<QStringListModel*>(mMinutePicker->model());
+                mMinutePicker->setLoopingEnabled(true);
+            }
+            mLayout->addItem(mMinutePicker);
+            lastAdded = mMinutePicker;
+            break;
 
             case HbDateTimeParser::Hour12Section:
             case HbDateTimeParser::Hour24Section:
-                if(!mHourPicker) {
-                    mHourPicker = new VIEWER(q);
-                    mHourModel = static_cast<QStringListModel*>(mHourPicker->model());
-                    mHourPicker->setLoopingEnabled(true);
-                }
-                mLayout->addItem(mHourPicker);
-                lastAdded = mHourPicker;
-                break;
+            if(!mHourPicker) {
+                mHourPicker = new VIEWER(q);
+                mHourModel = static_cast<QStringListModel*>(mHourPicker->model());
+                mHourPicker->setLoopingEnabled(true);
+            }
+            mLayout->addItem(mHourPicker);
+            lastAdded = mHourPicker;
+            break;
 
             default:
-                break;
+            break;
         }
         
         if(lastAdded){
@@ -773,7 +769,7 @@
 
 
 void HbDateTimePickerPrivate::setDateTimeRange(const QDateTime &startdt,
-        const QDateTime &enddt)
+                                               const QDateTime &enddt)
 {
     Q_Q(HbDateTimePicker);
     QDateTime start(startdt);
@@ -892,7 +888,7 @@
                 index = newDateTime.time().minute()-mMinuteOffset;
             }
 #ifdef HBDATETIMEPICKER_DEBUG
-    qDebug() << "setMinuteRange:selecting= " << index;
+            qDebug() << "setMinuteRange:selecting= " << index;
 #endif
             mMinutePicker->setSelected(index);
         }
@@ -952,8 +948,8 @@
 
 
     resizeModel(mYearModel, mYearOffset, 
-        mYearOffset+mYearModel->rowCount()-1, start, 
-        end, &HbDateTimePickerPrivate::localeYear);
+                mYearOffset+mYearModel->rowCount()-1, start,
+                end, &HbDateTimePickerPrivate::localeYear);
 
     mYearOffset = start;
 
@@ -979,9 +975,9 @@
         newIndex = end-start;
     }
     resizeModel(mMonthModel,
-            mMonthOffset,mMonthOffset+mMonthModel->rowCount()-1,
-            start,end,
-            &HbDateTimePickerPrivate::localeMonth);
+                mMonthOffset,mMonthOffset+mMonthModel->rowCount()-1,
+                start,end,
+                &HbDateTimePickerPrivate::localeMonth);
     mMonthOffset = start;
 
     mMonthPicker->setSelected(newIndex);
@@ -1016,9 +1012,9 @@
     }
 
     resizeModel(mDayModel,
-            mDayOffset,mDayOffset+mDayModel->rowCount()-1,
-            start,end,
-            &HbDateTimePickerPrivate::localeDay);
+                mDayOffset,mDayOffset+mDayModel->rowCount()-1,
+                start,end,
+                &HbDateTimePickerPrivate::localeDay);
     mDayOffset = start;
 
     mDayPicker->setSelected(newIndex);
@@ -1054,9 +1050,9 @@
     }
 
     resizeModel(mHourModel,
-            mHourOffset,mHourOffset+mHourModel->rowCount()-1,
-            start,end,
-            &HbDateTimePickerPrivate::localeHour);
+                mHourOffset,mHourOffset+mHourModel->rowCount()-1,
+                start,end,
+                &HbDateTimePickerPrivate::localeHour);
     mHourOffset = start;
 
     mHourPicker->setSelected(newIndex);
@@ -1091,17 +1087,17 @@
     }
 
     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.
     int index = 0;
 
     for(int i=start;i<newIndex;i+=mIntervals[QDateTimeEdit::MinuteSection]) {
-      index++;
+        index++;
     }
 #ifdef HBDATETIMEPICKER_DEBUG
     qDebug() << "initMinute:selecting= " << index;
@@ -1139,9 +1135,9 @@
     }
 
     resizeModel(mSecondModel,
-            mSecondOffset,mSecondOffset+mSecondModel->rowCount()-1,
-            start,end,
-            &HbDateTimePickerPrivate::localeSecond);
+                mSecondOffset,mSecondOffset+mSecondModel->rowCount()-1,
+                start,end,
+                &HbDateTimePickerPrivate::localeSecond);
     mSecondOffset = start;
 
     mSecondPicker->setSelected(newIndex);
@@ -1230,9 +1226,9 @@
    model classes with one interface/virtual function specialization.
 */
 void HbDateTimePickerPrivate::resizeModel(QStringListModel *model,
-            int oldStart, int oldEnd,
-            int newStart, int newEnd,
-            QString (HbDateTimePickerPrivate::*localeFunc)(int), int interval)
+                                          int oldStart, int oldEnd,
+                                          int newStart, int newEnd,
+                                          QString (HbDateTimePickerPrivate::*localeFunc)(int), int interval)
 {
     class ConnectionRemover {
     public:
@@ -1247,98 +1243,21 @@
     }Obj(this);
 
 #ifdef HBDATETIMEPICKER_DEBUG
-            qDebug() << "resizeModel: oldStart=" << oldStart
-                     << " oldEnd=" << oldEnd << " newStart=" 
-                     << newStart << " newEnd=" << newEnd
-                     << " interval=" << interval;
-#endif
-        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;
-#endif
-            if(b1 && b2 && (oldinterval == interval) && (newStart == oldStart)) {
-                if(newEnd>oldEnd) {
-                    int rowCount=model->rowCount();
-#ifdef HBDATETIMEPICKER_DEBUG
-                    qDebug() << "resizeModel:sameinserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
-#endif
-                    model->insertRows(rowCount,(newEnd-oldEnd)/interval);
-                    for(int i=0;i<((newEnd-oldEnd)/interval);++i) {
-                        QModelIndex index=model->index(i+rowCount,0);
-                        if(index.isValid()) {
-                            model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd));
-#ifdef HBDATETIMEPICKER_DEBUG
-                            qDebug() << "resizeModel:samesetData(" << ((i+1)*interval)+oldEnd << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
-#endif
-                        }
-                    }
-                }
-                if(oldEnd>newEnd) {
-                    //if the start offset is preset more items can fit at end
-                    int stay=((newEnd-newStart)/interval)+1;
-                    int count=model->rowCount()-stay;
-#ifdef HBDATETIMEPICKER_DEBUG
-                    qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
-                             << " data=" << model->index((model->rowCount()-count),0).data().toString();
+    qDebug() << "resizeModel: oldStart=" << oldStart
+            << " oldEnd=" << oldEnd << " newStart="
+            << newStart << " newEnd=" << newEnd
+            << " interval=" << interval;
 #endif
-                    model->removeRows((model->rowCount()-count),count);
-                }
-                return;//optimizing inserts when interval is set
-            } else {
-            if(b1 && b2) {      
-            model->removeRows(0,model->rowCount());
-                    oldStart = oldEnd = 0;
-            }
-            }
-
-        if((model->rowCount() == 0) && (newEnd-newStart>=0)) {
+    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:default addition inserting(0," << (newEnd-newStart+1)/interval << ")";
-#endif
-
-            model->insertRows(0,((newEnd-newStart)/interval)+1);
-            for(int i=0;i<=((newEnd-newStart)/interval);++i) {
-                QString text=(this->*localeFunc)((i*interval)+newStart);
-#ifdef HB_TEXT_MEASUREMENT_UTILITY
-                if ( localeFunc == &HbDateTimePickerPrivate::localeMonth &&
-                        HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
-                    text.append(QChar(LOC_TEST_START));
-                    text.append("qtl_datetimepicker_popup_month_sec");
-                    text.append(QChar(LOC_TEST_END));
-                }
+    qDebug() << "resizeModel:sameoldInterval=" << oldinterval;
 #endif
-                QModelIndex index=model->index(i,0);
-                if(index.isValid()) {
-                    model->setData(index,text);
-#ifdef HBDATETIMEPICKER_DEBUG
-                    qDebug() << "resizeModel:setData(" << i << "," << text << ")";
-#endif
-                }
-            }
-            return;
-        }
-
-        if(newStart<oldStart) {
-#ifdef HBDATETIMEPICKER_DEBUG
-            qDebug() << "resizeModel:inserting(0," << (oldStart-newStart)/interval << ")";
-#endif
-            model->insertRows(0,(oldStart-newStart)/interval);
-            for(int i=0;i<((oldStart-newStart)/interval);++i) {
-                QModelIndex index=model->index(i,0);
-                if(index.isValid()) {
-                    model->setData(index,(this->*localeFunc)((i*interval)+newStart));
-#ifdef HBDATETIMEPICKER_DEBUG
-                    qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i*interval)+newStart) << ")";
-#endif
-                }
-            }
-        }
-
+    if(b1 && b2 && (oldinterval == interval) && (newStart == oldStart)) {
         if(newEnd>oldEnd) {
             int rowCount=model->rowCount();
 #ifdef HBDATETIMEPICKER_DEBUG
-            qDebug() << "resizeModel:inserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
+            qDebug() << "resizeModel:sameinserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
 #endif
             model->insertRows(rowCount,(newEnd-oldEnd)/interval);
             for(int i=0;i<((newEnd-oldEnd)/interval);++i) {
@@ -1346,51 +1265,125 @@
                 if(index.isValid()) {
                     model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd));
 #ifdef HBDATETIMEPICKER_DEBUG
-                    qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
+                    qDebug() << "resizeModel:samesetData(" << ((i+1)*interval)+oldEnd << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
 #endif
                 }
             }
         }
-        if(newStart>oldStart) {
+        if(oldEnd>newEnd) {
+            //if the start offset is preset more items can fit at end
+            int stay=((newEnd-newStart)/interval)+1;
+            int count=model->rowCount()-stay;
+#ifdef HBDATETIMEPICKER_DEBUG
+            qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
+                    << " data=" << model->index((model->rowCount()-count),0).data().toString();
+#endif
+            model->removeRows((model->rowCount()-count),count);
+        }
+        return;//optimizing inserts when interval is set
+    } else {
+        if(b1 && b2) {
+            model->removeRows(0,model->rowCount());
+            oldStart = oldEnd = 0;
+        }
+    }
+
+    if((model->rowCount() == 0) && (newEnd-newStart>=0)) {
 #ifdef HBDATETIMEPICKER_DEBUG
-            qDebug() << "resizeModel:removing(0," << (newStart-oldStart)/interval << ")"
-                             << " data=" << model->index((newStart-oldStart)/interval,0).data().toString();
+        qDebug() << "resizeModel:default addition inserting(0," << (newEnd-newStart+1)/interval << ")";
 #endif
-            model->removeRows(0,(newStart-oldStart)/interval);
+
+        model->insertRows(0,((newEnd-newStart)/interval)+1);
+        for(int i=0;i<=((newEnd-newStart)/interval);++i) {
+            QString text=(this->*localeFunc)((i*interval)+newStart);
+#ifdef HB_TEXT_MEASUREMENT_UTILITY
+            if ( localeFunc == &HbDateTimePickerPrivate::localeMonth &&
+                 HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement ) ) {
+                text.append(QChar(LOC_TEST_START));
+                text.append("qtl_datetimepicker_popup_month_sec");
+                text.append(QChar(LOC_TEST_END));
+            }
+#endif
+            QModelIndex index=model->index(i,0);
+            if(index.isValid()) {
+                model->setData(index,text);
+#ifdef HBDATETIMEPICKER_DEBUG
+                qDebug() << "resizeModel:setData(" << i << "," << text << ")";
+#endif
+            }
         }
+        return;
+    }
 
-        if(oldEnd>newEnd) {
-//#ifdef HBDATETIMEPICKER_DEBUG
-//            qDebug() << "resizeModel:removing(" <<model->rowCount()-((oldEnd-newEnd)/interval)<<"," << (oldEnd-newEnd)/interval << ")";
-//#endif
-//            model->removeRows((model->rowCount()-((oldEnd-newEnd)/interval)),(oldEnd-newEnd)/interval);
-                    //if the start offset is preset more items can fit at end
-                    int stay=((newEnd-newStart)/interval)+1;
-                    int count=model->rowCount()-stay;
+    if(newStart<oldStart) {
+#ifdef HBDATETIMEPICKER_DEBUG
+        qDebug() << "resizeModel:inserting(0," << (oldStart-newStart)/interval << ")";
+#endif
+        model->insertRows(0,(oldStart-newStart)/interval);
+        for(int i=0;i<((oldStart-newStart)/interval);++i) {
+            QModelIndex index=model->index(i,0);
+            if(index.isValid()) {
+                model->setData(index,(this->*localeFunc)((i*interval)+newStart));
+#ifdef HBDATETIMEPICKER_DEBUG
+                qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i*interval)+newStart) << ")";
+#endif
+            }
+        }
+    }
+
+    if(newEnd>oldEnd) {
+        int rowCount=model->rowCount();
+#ifdef HBDATETIMEPICKER_DEBUG
+        qDebug() << "resizeModel:inserting(" << rowCount << "," <<(newEnd-oldEnd)/interval << ")";
+#endif
+        model->insertRows(rowCount,(newEnd-oldEnd)/interval);
+        for(int i=0;i<((newEnd-oldEnd)/interval);++i) {
+            QModelIndex index=model->index(i+rowCount,0);
+            if(index.isValid()) {
+                model->setData(index,(this->*localeFunc)(((i+1)*interval)+oldEnd));
 #ifdef HBDATETIMEPICKER_DEBUG
-                    qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
-                             << " data=" << model->index((model->rowCount()-count),0).data().toString();
+                qDebug() << "resizeModel:setData(" << i << "," << (this->*localeFunc)((i+1)*interval+oldEnd) << ")";
+#endif
+            }
+        }
+    }
+    if(newStart>oldStart) {
+#ifdef HBDATETIMEPICKER_DEBUG
+        qDebug() << "resizeModel:removing(0," << (newStart-oldStart)/interval << ")"
+                << " data=" << model->index((newStart-oldStart)/interval,0).data().toString();
 #endif
-                    model->removeRows((model->rowCount()-count),count);
-        }
+        model->removeRows(0,(newStart-oldStart)/interval);
+    }
+
+    if(oldEnd>newEnd) {
+        //#ifdef HBDATETIMEPICKER_DEBUG
+        //            qDebug() << "resizeModel:removing(" <<model->rowCount()-((oldEnd-newEnd)/interval)<<"," << (oldEnd-newEnd)/interval << ")";
+        //#endif
+        //            model->removeRows((model->rowCount()-((oldEnd-newEnd)/interval)),(oldEnd-newEnd)/interval);
+        //if the start offset is preset more items can fit at end
+        int stay=((newEnd-newStart)/interval)+1;
+        int count=model->rowCount()-stay;
+#ifdef HBDATETIMEPICKER_DEBUG
+        qDebug() << "resizeModel:removing(" <<model->rowCount()-count << "," << count << ")"
+                << " data=" << model->index((model->rowCount()-count),0).data().toString();
+#endif
+        model->removeRows((model->rowCount()-count),count);
+    }
 }  
 
 
 void HbDateTimePickerPrivate::createPrimitives()
-{
+{    
     Q_Q(HbDateTimePicker);
-    if(!mBackground) {
-        mBackground = HbStylePrivate::createPrimitive(HbStylePrivate::P_DateTimePicker_background,q);
-        HbStyle::setItemName(mBackground,"background");
+    if (!mBackground) {
+        mBackground = q->style()->createPrimitive(HbStyle::PT_FrameItem,"background",q);
     }
     if(!mFrame) {
-        mFrame = HbStylePrivate::createPrimitive(HbStylePrivate::P_DateTimePicker_frame,q);
-        HbStyle::setItemName(mFrame,"frame");
+        mFrame = q->style()->createPrimitive(HbStyle::PT_FrameItem,"frame",q);
     }
 
-    if(!mHighlight){
-        mHighlight = HbStylePrivate::createPrimitive(HbStylePrivate::P_TumbleView_highlight,q);
-        HbStyle::setItemName(mHighlight,"highlight");
+    if(!mHighlight) {
+        mHighlight = q->style()->createPrimitive(HbStyle::PT_FrameItem,"highlight",q);
     }
 }
 
@@ -1472,7 +1465,7 @@
 
         //set if dayrange changed
         if((start != mDayOffset)
-                ||(end !=mDayOffset+mDayModel->rowCount()-1)) {
+            ||(end !=mDayOffset+mDayModel->rowCount()-1)) {
             setDayRange(start,end);
         }
     }
@@ -1529,7 +1522,7 @@
 
         //set if range changed
         if((start != mMonthOffset)
-                || (end != mMonthModel->rowCount()-1)) {
+            || (end != mMonthModel->rowCount()-1)) {
             setMonthRange(start,end);
         }
 
@@ -1552,7 +1545,7 @@
 
         //set if dayrange changed
         if((start != mDayOffset)
-                ||(end !=mDayOffset+mDayModel->rowCount()-1)) {
+            ||(end !=mDayOffset+mDayModel->rowCount()-1)) {
             setDayRange(start,end);
         }
     }
@@ -1600,7 +1593,7 @@
 
         //set if range changed
         if((start != mMinuteOffset)
-                || (end != start+mMinuteModel->rowCount()-1)) {
+            || (end != start+mMinuteModel->rowCount()-1)) {
             setMinuteRange(start,end);
         }
 
@@ -1623,7 +1616,7 @@
 
         //set if seconds range changed
         if((start != mSecondOffset)
-                ||(end !=mSecondOffset+mSecondModel->rowCount()-1)) {
+            ||(end !=mSecondOffset+mSecondModel->rowCount()-1)) {
             setSecondRange(start,end);
         }
     }
@@ -1683,7 +1676,7 @@
 
         //set if seconds range changed
         if((start != mSecondOffset)
-                ||(end !=mSecondOffset+mSecondModel->rowCount()-1)) {
+            ||(end !=mSecondOffset+mSecondModel->rowCount()-1)) {
             setSecondRange(start,end);
         }
     }
@@ -1749,3 +1742,20 @@
         } 
     }
 }
+void HbDateTimePickerPrivate::processFormatEvent()
+{
+    QDateTime tempDate=mDateTime;
+    processDisplaySections();
+    //recreate and rearrange depending on the format
+    rearrangeTumbleViews();
+    setDateTime(tempDate);
+    emitDateTimeChange();
+}
+void HbDateTimePickerPrivate::postFormatEvent()
+{
+    Q_Q(HbDateTimePicker);
+    
+    QCoreApplication::removePostedEvents(q,QEvent::Type(mFormatEventType));
+
+    QCoreApplication::postEvent(q,new QEvent(QEvent::Type(mFormatEventType)));
+}