/** * \brief Find the index of the entry with the matching task id */ int TaskMainWindow::indexForTask(int taskid) { for (int i = 0; i < ui->tasklistWidget->count(); i++) { QListWidgetItem *lwi = ui->tasklistWidget->item(i); TaskItem *ti = (TaskItem *)ui->tasklistWidget->itemWidget(lwi); if (ti->id() == taskid) { return i; } } return -1; }
/** * \brief Remove a task from the tasklist * * This method deletes task list entries. It is called from the timer tick * method and the taskRealUpdate slot. */ void TaskMainWindow::remove(int taskid) { // find the item in the list that matches the id for (int i = 0; i < ui->tasklistWidget->count(); i++) { QListWidgetItem *lwi = ui->tasklistWidget->item(i); TaskItem *ti = (TaskItem *)ui->tasklistWidget->itemWidget(lwi); if (ti->id() == taskid) { QListWidgetItem *lwi = ui->tasklistWidget->takeItem(i); delete lwi; return; } } }
/** * \brief Retrieve a list of selected task ids * * This method scans the task list and constructs a list of tasks that * are selected. */ std::list<long> TaskMainWindow::selectedTaskids() { debug(LOG_DEBUG, DEBUG_LOG, 0, "retrieve a list of selected items"); std::list<long> taskids; for (int i = 0; i < ui->tasklistWidget->count(); i++) { QListWidgetItem *item = ui->tasklistWidget->item(i); if (item->isSelected()) { TaskItem *ti = (TaskItem *)ui->tasklistWidget->itemWidget(item); taskids.push_back(ti->id()); } } debug(LOG_DEBUG, DEBUG_LOG, 0, "%d selected task ids", taskids.size()); return taskids; }