00001 #include "projectassigner.h" 00002 00003 #include <controldata.h> 00004 #include <models/taskmodel.h> 00005 #include <models/projectmodel.h> 00006 00007 #include <domain/taskmanagerdata.h> 00008 00009 #include <tools/functions.h> 00010 #include <tools/stringexception.h> 00011 00012 using namespace control; 00013 00014 00015 ControllerInterface::ActionType ProjectAssigner::actionType() const 00016 { 00017 return AssignAction; 00018 } 00019 00020 ControllerInterface::DataType ProjectAssigner::dataType() const 00021 { 00022 return ProjectData; 00023 } 00024 00025 QString ProjectAssigner::description() const 00026 { 00027 return "Assign task to project"; 00028 } 00029 00030 bool ProjectAssigner::userIsValid() const 00031 { 00032 return userHasLoggedIn() && !userIsAdmin(); 00033 } 00034 00035 void ProjectAssigner::execute() 00036 { 00037 TaskModel tasks(data); 00038 data::SelectionData selectedTasks = ui->getSelection("Select a task", &tasks); 00039 00040 if (!selectedTasks.processData) 00041 return; 00042 00043 if (selectedTasks.selection.isEmpty()) 00044 { 00045 ui->showWarning("No task selected."); 00046 return; 00047 } 00048 00049 Q_ASSERT(selectedTasks.selection.count() == 1); 00050 00051 const domain::Task* task = 00052 tasks.taskForIndex(selectedTasks.selection.first()); 00053 00054 ProjectModel projects(data); 00055 data::SelectionData selectedProjects = ui->getSelection("Select a project", 00056 &projects); 00057 00058 if (!selectedProjects.processData) 00059 return; 00060 00061 if (selectedProjects.selection.isEmpty()) 00062 { 00063 ui->showWarning("No project selected."); 00064 return; 00065 } 00066 00067 Q_ASSERT(selectedProjects.selection.count() == 1); 00068 00069 const domain::Project* project = 00070 projects.projectForIndex(selectedProjects.selection.first()); 00071 00072 domain::Task* nonConstTask = data->task(task); 00073 domain::Project* nonConstProject = data->project(project); 00074 00075 try 00076 { 00077 nonConstTask->setProject(nonConstProject); 00078 } 00079 catch (tools::StringException& e) 00080 { 00081 ui->showError(e.message()); 00082 } 00083 } 00084 00085 QString ProjectAssigner::name() const 00086 { 00087 return "ProjectAssigner"; 00088 } 00089 00090 Q_EXPORT_PLUGIN2(controller_projectassigner, ProjectAssigner)