00001 #ifndef TASKTYPE_H 00002 #define TASKTYPE_H 00003 00004 #include "type.h" 00005 00006 namespace domain 00007 { 00008 00009 struct TaskTypePrivate; 00010 class UserType; 00011 class ResourceType; 00012 class TaskManagerData; 00013 class Task; 00014 00026 struct DOMAIN_EXPORT Field 00027 { 00033 enum Nature 00034 { 00039 Numerical, 00040 00044 Textual 00045 }; 00046 00050 Nature nature; 00051 00057 QString id; 00058 00062 QString name; 00063 00070 bool isValid(const QVariant& value) const; 00071 00078 bool isNull() const; 00079 00086 bool isValid() const; 00087 }; 00088 00100 struct DOMAIN_EXPORT Requirement 00101 { 00105 Type* type; 00106 00111 unsigned min; 00112 00117 unsigned max; 00118 00119 Requirement(Type* type); 00120 00124 virtual bool isFulfilled(const Task* task) const = 0; 00125 00133 virtual bool canBeSuccessful(const Task* task) const = 0; 00134 }; 00135 00141 class DOMAIN_EXPORT UserRequirement : public Requirement 00142 { 00143 friend class TaskTypePrivate; 00144 00145 public: 00146 00147 bool isFulfilled(const domain::Task* task) const; 00148 bool canBeSuccessful(const domain::Task* task) const; 00149 00150 private: 00151 00152 UserRequirement(UserType* userType); 00153 ~UserRequirement(); 00154 }; 00155 00161 class DOMAIN_EXPORT ResourceRequirement : public Requirement 00162 { 00163 friend class TaskTypePrivate; 00164 00165 public: 00166 00167 bool isFulfilled(const domain::Task* task) const; 00168 bool canBeSuccessful(const domain::Task* task) const; 00169 00170 private: 00171 00172 ResourceRequirement(ResourceType* reType); 00173 ~ResourceRequirement(); 00174 }; 00175 00188 class DOMAIN_EXPORT TaskType : public Type 00189 { 00190 Q_OBJECT 00191 friend class TaskManagerData; 00192 friend class TaskTypePrivate; 00193 00194 public: 00195 00201 const QList<Field>& fields() const; 00202 00209 Field fieldById(const QString& id) const; 00210 00215 Requirement* requirementByType(Type* type) const; 00216 00222 const QList<Requirement*>& requirements() const; 00223 00229 QList<Requirement*> userRequirements() const; 00230 00236 QList<Requirement*> resourceRequirements() const; 00237 00244 bool requirementsAreFulfilled(const Task* task) const; 00245 00252 bool canBeSuccessful(const Task* task) const; 00253 00260 const QList<UserType*>& potentialOwners() const; 00261 00268 bool userCanCreate(UserType* userType) const; 00269 00280 void addField(const Field& field); 00281 00287 ResourceRequirement* addRequirement(ResourceType* type, unsigned min, unsigned max); 00288 00294 UserRequirement* addRequirement(UserType* type, unsigned min, unsigned max); 00295 00302 void addPotentialOwner(UserType* owner); 00303 00304 Q_SIGNALS: 00305 00309 void dataChanged(); 00310 00311 private: 00312 00316 TaskType(const QString& id, const QString& name); 00317 ~TaskType(); 00318 00319 TaskTypePrivate* d; 00320 }; 00321 00322 } 00323 00324 #endif