Commit 0f853bb4 authored by Daniel Teske's avatar Daniel Teske

TaskModel: Sort task by id

Makes it easier to later find the task again, and does actually not
change the order in the normal case

Change-Id: I2f36f2e7a6ab52c06e35be22820438a809ecb012
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent bc193874
......@@ -114,14 +114,21 @@ QList<Task> TaskModel::tasks(const Core::Id &categoryId) const
return taskList;
}
bool sortById(const Task &task, unsigned int id)
{
return task.taskId < id;
}
void TaskModel::addTask(const Task &task)
{
Q_ASSERT(m_categories.keys().contains(task.category));
CategoryData &data = m_categories[task.category];
CategoryData &global = m_categories[Core::Id()];
beginInsertRows(QModelIndex(), m_tasks.count(), m_tasks.count());
m_tasks.append(task);
QList<Task>::iterator it = qLowerBound(m_tasks.begin(), m_tasks.end(),task.taskId, sortById);
int i = it - m_tasks.begin();
beginInsertRows(QModelIndex(), i, i);
m_tasks.insert(it, task);
data.addTask(task);
global.addTask(task);
endInsertRows();
......
......@@ -116,7 +116,7 @@ private:
};
QHash<Core::Id,CategoryData> m_categories; // category id to data
QList<Task> m_tasks; // all tasks (in order of insertion)
QList<Task> m_tasks; // all tasks (in order of id)
QHash<QString,bool> m_fileNotFound;
int m_maxSizeOfFileName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment