00001 #include "project.h" 00002 00003 #include "task.h" 00004 00005 #include <tools/invaliddataexception.h> 00006 00007 #include <QList> 00008 #include <QDebug> 00009 00010 namespace domain 00011 { 00012 00013 struct ProjectPrivate 00014 { 00015 QString description; 00016 QList<Task*> tasks; 00017 }; 00018 00019 Project::Project(const QString& description) : d(new ProjectPrivate) 00020 { 00021 setDescription(description); 00022 } 00023 00024 Project::~Project() 00025 { 00026 deleteDependentData(); 00027 00028 delete d; 00029 } 00030 00031 const QString& Project::description() const 00032 { 00033 return d->description; 00034 } 00035 00036 QList< const domain::Task* > Project::tasks() const 00037 { 00038 QList<const Task*> ret; 00039 00040 Q_FOREACH (Task* task, d->tasks) 00041 ret << task; 00042 00043 return ret; 00044 } 00045 00046 void Project::setDescription(const QString& description) 00047 { 00048 if (description.isEmpty()) 00049 throw tools::InvalidDataException("An empty description is not allowed"); 00050 00051 d->description = description; 00052 emit dataChanged(); 00053 } 00054 00055 void Project::addTask(Task* task) 00056 { 00057 d->tasks << task; 00058 emit dataChanged(); 00059 } 00060 00061 void Project::removeTask(Task* task) 00062 { 00063 Q_ASSERT(task->project() == this); 00064 00065 d->tasks.removeAll(task); 00066 emit dataChanged(); 00067 } 00068 00069 QList<StorableData*> Project::dependentData() const 00070 { 00071 QList<StorableData*> ret; 00072 00073 Q_FOREACH (Task* task, d->tasks) 00074 ret << task; 00075 00076 return ret; 00077 } 00078 00079 } 00080 00081