notes/notesui/notesmodel/src/notesmodel.cpp
changeset 75 7ac58b2aae6f
parent 57 bb2d3e476f29
child 83 5aadd1120515
equal deleted inserted replaced
72:27feeedec790 75:7ac58b2aae6f
   208 		// Get the status of the to-do.
   208 		// Get the status of the to-do.
   209 		AgendaEntry::Status entryStatus = (AgendaEntry::Status) foundIndex.data(
   209 		AgendaEntry::Status entryStatus = (AgendaEntry::Status) foundIndex.data(
   210 				NotesNamespace::StatusRole).value<int>();
   210 				NotesNamespace::StatusRole).value<int>();
   211 
   211 
   212 		if (entry.status() == entryStatus) {
   212 		if (entry.status() == entryStatus) {
   213 			if (AgendaEntry::TodoNeedsAction == entryStatus) {
   213 			if (AgendaEntry::TodoCompleted != entryStatus) {
   214 				// Make sure that the old model index is removed.
   214 				// Make sure that the old model index is removed.
   215 				mSourceModel->removeRow(foundIndex.row());
   215 				mSourceModel->removeRow(foundIndex.row());
   216 				mInCompTodoCount--;
   216 				mInCompTodoCount--;
   217 
   217 
   218 				// Now insert the to-do.
   218 				// Now insert the to-do.
   219 				insertInCompTodoToModel(foundIndex, id);
   219 				insertInCompTodoToModel(foundIndex, id);
   220 
   220 
   221 			} else if (AgendaEntry::TodoCompleted == entryStatus) {
   221 			} else {
   222 				// Make sure that the old model index is removed.
   222 				// Make sure that the old model index is removed.
   223 				mSourceModel->removeRow(foundIndex.row());
   223 				mSourceModel->removeRow(foundIndex.row());
   224 				mCompTodoCount--;
   224 				mCompTodoCount--;
   225 
   225 
   226 				// Now insert the completed to-do.
   226 				// Now insert the completed to-do.
   227 				insertCompTodoToModel(foundIndex, id);
   227 				insertCompTodoToModel(foundIndex, id);
   228 
   228 
   229 			}
   229 			}
   230 		} else {
   230 		} else {
   231 			if (AgendaEntry::TodoNeedsAction == entryStatus) {
   231 			if (AgendaEntry::TodoCompleted != entryStatus) {
   232 				// Here the to-do was marked completed. Hence we need to remove
   232 				// Here the to-do was marked completed. Hence we need to remove
   233 				// the incompleted to-do and insert a completed to-do.
   233 				// the incompleted to-do and insert a completed to-do.
   234 				mSourceModel->removeRow(foundIndex.row());
   234 				mSourceModel->removeRow(foundIndex.row());
   235 				mInCompTodoCount--;
   235 				mInCompTodoCount--;
   236 
   236 
   237 				// Now insert the completed to-do.
   237 				// Now insert the completed to-do.
   238 				insertCompTodoToModel(foundIndex, id);
   238 				insertCompTodoToModel(foundIndex, id);
   239 
   239 
   240 			} else if (AgendaEntry::TodoCompleted == entryStatus) {
   240 			} else {
   241 				// Here the to-do was marked incompleted. Hence we need to
   241 				// Here the to-do was marked incompleted. Hence we need to
   242 				// remove the completed to-do and insert an incompleted to-do.
   242 				// remove the completed to-do and insert an incompleted to-do.
   243 				mSourceModel->removeRow(foundIndex.row());
   243 				mSourceModel->removeRow(foundIndex.row());
   244 				mCompTodoCount--;
   244 				mCompTodoCount--;
   245 
   245 
   290 		// All new notes are inserted at the top of the list by default.
   290 		// All new notes are inserted at the top of the list by default.
   291 		// Create a new model index at the 0th position.
   291 		// Create a new model index at the 0th position.
   292 		notify = insertNoteToModel(indexToNotify, id);
   292 		notify = insertNoteToModel(indexToNotify, id);
   293 
   293 
   294 	} else if (AgendaEntry::TypeTodo == entry.type()) {
   294 	} else if (AgendaEntry::TypeTodo == entry.type()) {
   295 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   295 		if (AgendaEntry::TodoCompleted != entry.status()) {
   296 			// Try to insert the to-do at its appropriate position.
   296 			// Try to insert the to-do at its appropriate position.
   297 			notify = insertInCompTodoToModel(indexToNotify, id);
   297 			notify = insertInCompTodoToModel(indexToNotify, id);
   298 
   298 
   299 		} else if (AgendaEntry::TodoCompleted == entry.status()) {
   299 		} else {
   300 			// Try to insert the to-do at its appropriate position.
   300 			// Try to insert the to-do at its appropriate position.
   301 			insertCompTodoToModel(indexToNotify, id);
   301 			insertCompTodoToModel(indexToNotify, id);
   302 		}
   302 		}
   303 	}
   303 	}
   304 
   304 
   338 			if (entryType == AgendaEntry::TypeNote) {
   338 			if (entryType == AgendaEntry::TypeNote) {
   339 				mNotesCount--;
   339 				mNotesCount--;
   340 			} else if (entryType == AgendaEntry::TypeTodo) {
   340 			} else if (entryType == AgendaEntry::TypeTodo) {
   341 				if (entryStatus == AgendaEntry::TodoCompleted) {
   341 				if (entryStatus == AgendaEntry::TodoCompleted) {
   342 					mCompTodoCount--;
   342 					mCompTodoCount--;
   343 				} else if (entryStatus == AgendaEntry::TodoNeedsAction) {
   343 				} else {
   344 					mInCompTodoCount--;
   344 					mInCompTodoCount--;
   345 				}
   345 				}
   346 			}
   346 			}
   347 			break;
   347 			break;
   348 		}
   348 		}
   434 			// If empty set unnamed text
   434 			// If empty set unnamed text
   435 			stringList<<hbTrId("txt_notes_dblist_unnamed");
   435 			stringList<<hbTrId("txt_notes_dblist_unnamed");
   436 		} else {
   436 		} else {
   437 			stringList << entry.summary();
   437 			stringList << entry.summary();
   438 		}
   438 		}
   439 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   439 		if (AgendaEntry::TodoCompleted != entry.status()) {
   440 			// Read due date from agenda entry
   440 			// Read due date from agenda entry
   441 			QString displayText;
   441 			QString displayText;
   442 			QString timeText(hbTrId("txt_notes_dblist_val_due_on_1"));
   442 			QString timeText(hbTrId("txt_notes_dblist_val_due_on_1"));
   443 			QString dueDateText =
   443 			QString dueDateText =
   444 					entry.startTime().toString(dateFormatString());
   444 					entry.startTime().toString(dateFormatString());
   593 
   593 
   594 		// Read the to-do details.
   594 		// Read the to-do details.
   595 		AgendaEntry entry = agendaEntryList[idIter];
   595 		AgendaEntry entry = agendaEntryList[idIter];
   596 
   596 
   597 		if (AgendaEntry::TypeTodo != entry.type()) {
   597 		if (AgendaEntry::TypeTodo != entry.type()) {
       
   598 			// delete the inserted row in the model
       
   599 			mSourceModel->removeRow(modelIter);
       
   600 			// decrement the iterator
       
   601 			modelIter--;
   598 			continue;
   602 			continue;
   599 		}
   603 		}
   600 
   604 
   601 		if (AgendaEntry::TodoNeedsAction != entry.status()) {
   605 		if (AgendaEntry::TodoCompleted == entry.status()) {
       
   606 			// delete the inserted row in the model
       
   607 			mSourceModel->removeRow(modelIter);
       
   608 			// decrement the iterator
       
   609 			modelIter--;
   602 			continue;
   610 			continue;
   603 		}
   611 		}
   604 
   612 
   605 		// Create a model index.
   613 		// Create a model index.
   606 		QModelIndex mdlIndex = mSourceModel->index(modelIter, 0);
   614 		QModelIndex mdlIndex = mSourceModel->index(modelIter, 0);
   622 			stringList<<hbTrId("txt_notes_dblist_unnamed");
   630 			stringList<<hbTrId("txt_notes_dblist_unnamed");
   623 		} else {
   631 		} else {
   624 			stringList << entry.summary();
   632 			stringList << entry.summary();
   625 		}
   633 		}
   626 
   634 
   627 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   635 		if (AgendaEntry::TodoCompleted != entry.status()) {
   628 			// Read due date from agenda entry
   636 			// Read due date from agenda entry
   629 			QString displayText;
   637 			QString displayText;
   630 			QString timeText(hbTrId("txt_notes_dblist_val_due_on_1"));
   638 			QString timeText(hbTrId("txt_notes_dblist_val_due_on_1"));
   631 			QString dueDateText =
   639 			QString dueDateText =
   632 					entry.startTime().toString(dateFormatString());
   640 					entry.startTime().toString(dateFormatString());
   895 				// If empty set unnamed text
   903 				// If empty set unnamed text
   896 				stringList<<hbTrId("txt_notes_dblist_unnamed");
   904 				stringList<<hbTrId("txt_notes_dblist_unnamed");
   897 			} else {
   905 			} else {
   898 				stringList << entry.summary();
   906 				stringList << entry.summary();
   899 			}
   907 			}
   900 			if (AgendaEntry::TodoNeedsAction == entry.status()) {
   908 			if (AgendaEntry::TodoCompleted != entry.status()) {
   901 				// Read due date from agenda entry
   909 				// Read due date from agenda entry
   902 				QString displayText;
   910 				QString displayText;
   903 				QString timeText(hbTrId("txt_notes_dblist_val_due_on_1"));
   911 				QString timeText(hbTrId("txt_notes_dblist_val_due_on_1"));
   904 				QString dueDateText =
   912 				QString dueDateText =
   905 						entry.startTime().toString(dateFormatString());
   913 						entry.startTime().toString(dateFormatString());