calendarui/caleneditor/src/caleneditorrepeatfield.cpp
changeset 50 579cc610882e
parent 49 5de72ea7a065
child 58 ef813d54df51
equal deleted inserted replaced
49:5de72ea7a065 50:579cc610882e
    31 
    31 
    32 // User Included
    32 // User Included
    33 #include "caleneditorrepeatfield.h"
    33 #include "caleneditorrepeatfield.h"
    34 #include "caleneditorcustomitem.h"
    34 #include "caleneditorcustomitem.h"
    35 
    35 
       
    36 // Constants
       
    37 const int userRole = Qt::UserRole + 100;
       
    38 
    36 /*!
    39 /*!
    37 	\class CalenEditorRepeatField
    40 	\class CalenEditorRepeatField
    38  */
    41  */
    39 /*!
    42 /*!
    40 	Constructor.
    43 	Constructor.
    69 
    72 
    70 		// Create the repeat choices
    73 		// Create the repeat choices
    71 		QStringList repeatChoices;
    74 		QStringList repeatChoices;
    72 		repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once")
    75 		repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once")
    73 		        << hbTrId("txt_calendar_setlabel_repeat_val_daily")
    76 		        << hbTrId("txt_calendar_setlabel_repeat_val_daily")
    74 		        // TODO : add text ID for workdays
    77 		        << hbTrId("txt_calendar_setlabel_repeat_val_workdays")
    75 		        << hbTrId("Workdays")
       
    76 		        << hbTrId("txt_calendar_setlabel_repeat_val_weekly")
    78 		        << hbTrId("txt_calendar_setlabel_repeat_val_weekly")
    77 		        << hbTrId("txt_calendar_setlabel_repeat_val_fortnightly")
    79 		        << hbTrId("txt_calendar_setlabel_repeat_val_fortnightly")
    78 		        << hbTrId("txt_calendar_setlabel_repeat_val_monthly")
    80 		        << hbTrId("txt_calendar_setlabel_repeat_val_monthly")
    79 		        << hbTrId("txt_calendar_setlabel_repeat_val_yearly");
    81 		        << hbTrId("txt_calendar_setlabel_repeat_val_yearly");
    80 
    82 
   124 			= qobject_cast<HbComboBox *> (item->dataItemContentWidget());
   126 			= qobject_cast<HbComboBox *> (item->dataItemContentWidget());
   125 
   127 
   126 	// Set the user roles for the combobox items so that we depend on these
   128 	// Set the user roles for the combobox items so that we depend on these
   127 	// roles to identify the correct repeat type when repeat choices are 
   129 	// roles to identify the correct repeat type when repeat choices are 
   128 	// dynamically removed or added
   130 	// dynamically removed or added
   129 	mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, Qt::UserRole+100);
   131 	mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, userRole);
   130 	mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, Qt::UserRole+100);
   132 	mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, userRole);
   131 	mRepeatComboBox->setItemData(RepeatWorkdays, 
   133 	mRepeatComboBox->setItemData(RepeatWorkdays, 
   132 								 RepeatWorkdays, Qt::UserRole+100);
   134 								 RepeatWorkdays, userRole);
   133 	mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly, Qt::UserRole+100);
   135 	mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly, userRole);
   134 	mRepeatComboBox->setItemData(RepeatBiWeekly, 
   136 	mRepeatComboBox->setItemData(RepeatBiWeekly, 
   135 								 RepeatBiWeekly, Qt::UserRole+100);
   137 								 RepeatBiWeekly, userRole);
   136 	mRepeatComboBox->setItemData(RepeatMonthly, 
   138 	mRepeatComboBox->setItemData(RepeatMonthly, 
   137 								 RepeatMonthly, Qt::UserRole+100);
   139 								 RepeatMonthly, userRole);
   138 	mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, Qt::UserRole+100);
   140 	mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, userRole);
   139 	
   141 	
   140 	if (mCalenEditor->editedEntry()->isRepeating()) {
   142 	if (mCalenEditor->editedEntry()->isRepeating()) {
   141 		switch (mCalenEditor->editedEntry()->repeatRule().type()) {
   143 		switch (mCalenEditor->editedEntry()->repeatRule().type()) {
   142 			case AgendaRepeatRule::DailyRule: {
   144 			case AgendaRepeatRule::DailyRule: {
   143 				mRepeatComboBox->setCurrentIndex(1);
   145 				mRepeatComboBox->setCurrentIndex(1);
   195 {
   197 {
   196 	mIsBiWeekly = false;
   198 	mIsBiWeekly = false;
   197 	mIsWorkdays = false;
   199 	mIsWorkdays = false;
   198 
   200 
   199 	HbExtendedLocale locale = HbExtendedLocale::system();
   201 	HbExtendedLocale locale = HbExtendedLocale::system();
   200 	// Get the user role w ehave set for this index
   202 	// Get the user role we have set for this index
   201 	QVariant userRole = mRepeatComboBox->itemData(index, Qt::UserRole + 100);
   203 	QVariant role = mRepeatComboBox->itemData(index, userRole);
   202 	int value = userRole.toInt();
   204 	int value = role.toInt();
   203 	switch (value) {
   205 	switch (value) {
   204 		case 1: {
   206 		case 1: {
   205 			if (!mRepeatUntilItemAdded) {
   207 			if (!mRepeatUntilItemAdded) {
   206 				insertRepeatUntilItem();
   208 				insertRepeatUntilItem();
   207 			}
   209 			}
   294 				mCustomRepeatUntilItem = NULL;
   296 				mCustomRepeatUntilItem = NULL;
   295 			}
   297 			}
   296 		}
   298 		}
   297 		break;
   299 		break;
   298 	}
   300 	}
   299 	mCalenEditor->addDiscardAction();
   301 	if(!mCalenEditor->isNewEntry()) {
       
   302 		mCalenEditor->addDiscardAction();
       
   303 	}
   300 	mCalenEditor->updateReminderChoices();
   304 	mCalenEditor->updateReminderChoices();
   301 }
   305 }
   302 
   306 
   303 /*!
   307 /*!
   304 	 Returns model index of the repeat item
   308 	 Returns model index of the repeat item
   444 	int previousCount = mRepeatComboBox->count();
   448 	int previousCount = mRepeatComboBox->count();
   445 	mRepeatComboBox->clear();
   449 	mRepeatComboBox->clear();
   446 	QStringList repeatChoices;
   450 	QStringList repeatChoices;
   447 	repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once")
   451 	repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once")
   448 			<< hbTrId("txt_calendar_setlabel_repeat_val_daily")
   452 			<< hbTrId("txt_calendar_setlabel_repeat_val_daily")
   449 			// TODO : add text ID for workdays
   453 			<< hbTrId("txt_calendar_setlabel_repeat_val_workdays")
   450 			<< hbTrId("Workdays")
       
   451 			<< hbTrId("txt_calendar_setlabel_repeat_val_weekly")
   454 			<< hbTrId("txt_calendar_setlabel_repeat_val_weekly")
   452 			<< hbTrId("txt_calendar_setlabel_repeat_val_fortnightly")
   455 			<< hbTrId("txt_calendar_setlabel_repeat_val_fortnightly")
   453 			<< hbTrId("txt_calendar_setlabel_repeat_val_monthly")
   456 			<< hbTrId("txt_calendar_setlabel_repeat_val_monthly")
   454 			<< hbTrId("txt_calendar_setlabel_repeat_val_yearly");
   457 			<< hbTrId("txt_calendar_setlabel_repeat_val_yearly");
   455 	mRepeatComboBox->addItems(repeatChoices);
   458 	mRepeatComboBox->addItems(repeatChoices);
   456 	// Set the user roles for the combobox items so that we depend on these
   459 	// Set the user roles for the combobox items so that we depend on these
   457 	// roles to identify the correct repeat type when repeat choices are 
   460 	// roles to identify the correct repeat type when repeat choices are 
   458 	// dynamically removed or added
   461 	// dynamically removed or added
   459 	mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, Qt::UserRole + 100);
   462 	mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, userRole);
   460 	mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, 
   463 	mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, 
   461 								 Qt::UserRole + 100);
   464 	                             userRole);
   462 	mRepeatComboBox->setItemData(RepeatWorkdays, 
   465 	mRepeatComboBox->setItemData(RepeatWorkdays, 
   463 								 RepeatWorkdays, Qt::UserRole+100);
   466 								 RepeatWorkdays, userRole);
   464 	mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly,
   467 	mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly,
   465 								 Qt::UserRole + 100);
   468 	                             userRole);
   466 	mRepeatComboBox->setItemData(RepeatBiWeekly, RepeatBiWeekly,
   469 	mRepeatComboBox->setItemData(RepeatBiWeekly, RepeatBiWeekly,
   467 								 Qt::UserRole + 100);
   470 	                             userRole);
   468 	mRepeatComboBox->setItemData(RepeatMonthly, RepeatMonthly,
   471 	mRepeatComboBox->setItemData(RepeatMonthly, RepeatMonthly,
   469 								 Qt::UserRole + 100);
   472 	                             userRole);
   470 	mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, 
   473 	mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, 
   471 								 Qt::UserRole + 100);
   474 	                             userRole);
   472 
   475 
   473 	int totalCount = mRepeatComboBox->count();
   476 	int totalCount = mRepeatComboBox->count();
   474 
   477 
   475 	if (previousCount < totalCount && choice > 0) {
   478 	if (previousCount < totalCount && choice > 0) {
   476 		choice += (totalCount - previousCount);
   479 		choice += (totalCount - previousCount);