00001 #ifndef TASKSTATES_H 00002 #define TASKSTATES_H 00003 00004 #include <tools/global.h> 00005 00006 class QString; 00007 00008 template<typename T> 00009 class QList; 00010 00011 namespace domain 00012 { 00013 00014 class Reservation; 00015 class StateChangeData; 00016 class Task; 00017 class Project; 00018 class Resource; 00019 00028 class DOMAIN_EXPORT TaskState 00029 { 00030 friend class Task; 00031 00032 public: 00033 00034 enum SettableState 00035 { 00036 Failed, 00037 Unfinished, 00038 Successful 00039 }; 00040 00041 virtual QString name() const = 0; 00042 00047 static QList<TaskState::SettableState> allStates(); 00048 00054 static TaskState* stateForEnum(TaskState::SettableState state); 00055 00061 static QString nameForEnum(TaskState::SettableState state ); 00062 00063 protected: 00064 00065 TaskState(); 00066 TaskState(const TaskState& other); 00067 TaskState& operator=(const TaskState& other); 00068 00075 static void setTaskState(Task* task, TaskState* state); 00076 00084 static void setTaskField(Task* task, const QString& id, const QVariant& value); 00085 00092 static void addTaskReservation(Task* task, Reservation* reservation); 00093 00100 static void setTaskProject(Task* task, Project* project); 00101 00108 static void addTaskSubTask(Task* task, Task* subTask); 00109 00110 private: 00111 00115 virtual SettableState settableState() const = 0; 00116 00122 virtual void updateTask(Task* task); 00123 00133 virtual void setField(Task* task, const QString& id, const QVariant& value); 00134 00143 virtual void addReservation(Task* task, Reservation* reservation); 00144 00153 virtual void setProject(Task* task, Project* project); 00154 00163 virtual void addSubTask(Task* task, Task* subTask); 00164 }; 00165 00169 class TaskSuccessful : public TaskState 00170 { 00171 public: 00172 00173 QString name() const; 00174 00175 static TaskState* instance(); 00176 00177 private: 00178 00179 TaskSuccessful(); 00180 SettableState settableState() const; 00181 void updateTask(Task* task); 00182 00183 void setProject(Task* task, Project* project); 00184 void setField(Task* task, const QString& id, const QVariant& value); 00185 void addReservation(Task* task, Reservation* reservation); 00186 }; 00187 00188 00192 class TaskFailed : public TaskState 00193 { 00194 public: 00195 00196 QString name() const; 00197 00198 static TaskState* instance(); 00199 00200 private: 00201 00202 TaskFailed(); 00203 SettableState settableState() const; 00204 00205 void setProject(Task* task, Project* project); 00206 void setField(Task* task, const QString& id, const QVariant& value); 00207 void addReservation(Task* task, Reservation* reservation); 00208 }; 00209 00210 00214 class TaskUnfinished : public TaskState 00215 { 00216 public: 00217 00218 QString name() const; 00219 00220 static TaskState* instance(); 00221 00222 protected: 00223 00224 TaskUnfinished(); 00225 00226 private: 00227 00228 SettableState settableState() const; 00229 void updateTask(Task* task); 00230 bool shouldBeFailed(Task* task); 00231 bool isAvailable(const Task* task); 00232 00233 void setField(Task* task, const QString& id, const QVariant& value); 00234 void addReservation(Task* task, Reservation* reservation); 00235 void setProject(Task* task, Project* project); 00236 void addSubTask(Task* task, Task* subTask); 00237 }; 00238 00242 class TaskAvailable : public TaskUnfinished 00243 { 00244 public: 00245 00246 QString name() const; 00247 00248 static TaskState* instance(); 00249 00250 private: 00251 00252 TaskAvailable(); 00253 }; 00254 00258 class TaskUnavailable : public TaskUnfinished 00259 { 00260 public: 00261 00262 QString name() const; 00263 00264 static TaskState* instance(); 00265 00266 private: 00267 00268 TaskUnavailable(); 00269 }; 00270 00277 class TaskDeleting : public TaskState 00278 { 00279 public: 00280 00281 QString name() const; 00282 00283 static TaskState* instance(); 00284 00285 private: 00286 00287 TaskDeleting(); 00288 void setField(Task* task, const QString& id, const QVariant& value); 00289 void addReservation(Task* task, Reservation* reservation); 00290 void setProject(Task* task, Project* project); 00291 void addSubTask(Task* task, Task* subTask); 00292 SettableState settableState() const; 00293 }; 00294 00295 } 00296 00297 #endif