00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __DB_LIST_MANAGER_H
00021 #define __DB_LIST_MANAGER_H
00022
00023 #include "dbList.h"
00024 #include "sql.h"
00025
00026 #include "../DataClasses/DataClass.h"
00027 #include "../DataClasses/Institute.h"
00028 #include "../DataClasses/Programme.h"
00029 #include "../DataClasses/Module.h"
00030 #include "../DataClasses/Faculty.h"
00031 #include "../DataClasses/Department.h"
00032 #include "../DataClasses/Staff.h"
00033 #include "../DataClasses/Room.h"
00034 #include "../DataClasses/ModLecAlloc.h"
00035 #include "../DataClasses/TimeSlot.h"
00036
00037 #include "../ModelClasses/RootModel.h"
00038 #include "../ItemClasses/RootItem.h"
00039
00040 class RootModel;
00041
00053 class dbListManager
00054 {
00055 public:
00063 enum registeredLists
00064 {regInstitute = 1
00065 ,regProgramme = 2
00066 ,regModule = 4
00067 ,regFaculty = 8
00068 ,regDepartment = 16
00069 ,regStaff = 32
00070 ,regRoom = 64
00071 ,regMLAlloc = 128
00072 ,regTimeSlot = 256
00073 };
00074
00086 class registeredModels
00087 {
00088 public:
00089 RootModel * pModel;
00090 QList<dbList *> listOfLists;
00091 registeredModels(RootModel * model){pModel = model;}
00092 void registerList(dbList * list){listOfLists.append(list);}
00093 bool listIsMember(dbList * list){return listOfLists.contains(list);}
00094 void dump();
00095 };
00096
00097 private:
00098 static dbListManager * _instance;
00099 private:
00100 sql* dbConn;
00101 dbList * pInstituteList;
00102 dbList * pProgrammeList;
00103 dbList * pModuleList;
00104 dbList * pFacultyList;
00105 dbList * pDepartmentList;
00106 dbList * pStaffList;
00107 dbList * pRoomList;
00108 dbList * pMLAllocList;
00109 dbList * pTimeSlotList;
00110
00117 QList<registeredModels *> pRegisteredModels;
00118 private:
00120 dbListManager();
00122 dbListManager(dbListManager & clone);
00123 public:
00124 static dbListManager * Instance();
00125 public:
00126
00128 void registerModel(RootModel * model, int lists);
00129
00130
00131 inline dbList * InstituteList(){return pInstituteList;}
00132 inline dbList * ProgrammeList(){return pProgrammeList;}
00133 inline dbList * ModuleList(){return pModuleList;}
00134 inline dbList * FacultyList(){return pFacultyList;}
00135 inline dbList * DepartmentList(){return pDepartmentList;}
00136 inline dbList * StaffList(){return pStaffList;}
00137 inline dbList * RoomList(){return pRoomList;}
00138 inline dbList * MLAllocList(){return pMLAllocList;}
00139 inline dbList * TimeSlotList(){return pTimeSlotList;}
00140
00143 QList<Institute * > * getInstituteList()
00144 {return List<Institute *>(pInstituteList->list());}
00147 QList<Programme * > * getProgrammeList()
00148 {return List<Programme *>(pProgrammeList->list());}
00154 QList<Programme * > * getProgrammeList(Institute * inst)
00155 {if (inst == 0) return getProgrammeList();
00156 else return List<Programme *>(pProgrammeList->allChildren(inst));}
00161 QList<Module * > * getModuleList()
00162 {return List<Module *>(pModuleList->list());}
00168 QList<Module * > * getModuleList(Programme * prog)
00169 {return List<Module *>(pModuleList->allChildren(prog));}
00174 QList<Faculty * > * getFacultyList()
00175 {return List<Faculty *>(pFacultyList->list());}
00181 QList<Faculty * > * getFacultyList(Institute * inst)
00182 {if (inst == 0) return getFacultyList();
00183 else return List<Faculty *>(pFacultyList->allChildren(inst));}
00188 QList<Department * > * getDepartmentList()
00189 {return List<Department*>(pDepartmentList->list());}
00195 QList<Department * > * getDepartmentList(Faculty * faculty)
00196 {if (faculty == 0) return getDepartmentList();
00197 else return List<Department*>(pDepartmentList->allChildren(faculty));}
00203 QList<Department * > * getDepartmentList(Institute * inst)
00204 {if (inst == 0) return getDepartmentList();
00205 else return List<Department*>(pDepartmentList->allChildren(inst,true));}
00210 QList<Staff * > * getStaffList()
00211 {return List<Staff*>(pStaffList->list());}
00217 QList<Staff * > * getStaffList(Department * dept)
00218 {if (dept == 0) return getStaffList();
00219 else return List<Staff*>(pStaffList->allChildren(dept,true));}
00225 QList<Staff * > * getStaffList(Institute * inst)
00226 {if (inst == 0) return getStaffList();
00227 else return List<Staff*>(pStaffList->allChildren(inst,true));}
00232 QList<Room * > * getRoomList()
00233 {return List<Room *>(pRoomList->list());}
00239 QList<Room * > * getRoomList(Institute * inst)
00240 {return List<Room *>(pRoomList->allChildren(inst));}
00245 QList<ModLecAlloc * > * getMLAllocList()
00246 {return List<ModLecAlloc*>(pMLAllocList->list());}
00252 QList<ModLecAlloc * > * getMLAllocList(Programme * prog)
00253 {return List<ModLecAlloc*>(pMLAllocList->allChildren(prog));}
00259 QList<ModLecAlloc * > * getMLAllocList(Institute * inst)
00260 {return List<ModLecAlloc*>(pMLAllocList->allChildren(inst, true));}
00261
00266 QList<TimeSlot * > * getTimeSlotList()
00267 {return List<TimeSlot *>(pTimeSlotList->list());}
00273 QList<TimeSlot * > * getTimeSlotList(Institute * inst)
00274 {return List<TimeSlot *>(pTimeSlotList->allChildren(inst));}
00275
00276
00283 Institute * getInstituteFromID(int id) {return getObjFromID<Institute *>(pInstituteList,id);}
00290 Programme * getProgrammeFromID(int id) {return getObjFromID<Programme *>(pProgrammeList,id);}
00297 Module * getModuleFromID(int id) {return getObjFromID<Module *>(pModuleList,id);}
00304 Faculty * getFacultyFromID(int id) {return getObjFromID<Faculty *>(pFacultyList,id);}
00311 Department * getDepartmentFromID(int id) {return getObjFromID<Department *>(pDepartmentList,id);}
00318 Staff * getStaffFromID(int id) {return getObjFromID<Staff *>(pStaffList,id);}
00325 Room * getRoomFromID(int id) {return getObjFromID<Room *>(pRoomList,id);}
00332 ModLecAlloc * getMLAllocFromID(int id) {return getObjFromID<ModLecAlloc *>(pMLAllocList,id);}
00339
00340 Institute * getInstFromName(QString &InstName){return getObjFromName(getInstituteList(),InstName);}
00350 Programme * getProgFromName(Institute * instObj, QString &ProgName){return getObjFromName(getProgrammeList(instObj),ProgName);}
00360 Department * getDeptFromName(Institute * instObj, QString &deptName){return getObjFromName(getDepartmentList(instObj),deptName);}
00361
00362
00371 void insert(RootItem * item, dbList * list, QModelIndex & index, CompareDC lessThan);
00381 void update(RootItem * item, dbList * list, CompareRI compare);
00391 void remove(RootItem * item, dbList * list, bool cascade=true);
00392
00393
00398 void dump(bool details = false);
00399
00400 private:
00401
00405 void newInstitute ();
00410 void newProgramme (Institute * parent);
00415 void newModule (Programme * parent);
00420 void newFaculty (Institute * parent);
00425 void newDepartment (Faculty * parent);
00430 void newStaff (Department * parent);
00435 void newRoom (Institute * parent);
00439 void newAlloc ();
00443 void newTimeSlot ();
00444
00452 void updateRMInsert(dbList * list, RootItem * item, QModelIndex & index, int posn);
00459 void updateRMUpdate(dbList * list, DataClass * dcObj, CompareRI compare);
00465 void updateRMDelete(dbList * list, DataClass * dcObj);
00471 void removeAllChilden(DataClass * dcObj);
00478 void removeChild(DataClass * dcObj, dbList * list);
00488 template<typename T>
00489 QList<T> * List(QList<DataClass*> * list);
00496 template<typename T>
00497 T getObjFromID(dbList* pList, int id);
00504 template<typename T>
00505 T getObjFromName(QList<T>* list, QString &name);
00506 };
00507
00508 template<typename T>
00509 QList<T> * dbListManager::List(QList<DataClass*> * list)
00510 {
00511 QList<T> * theList = new QList<T>();
00512 for (int i = 0; i < list->size(); i++)
00513 {
00514 theList->append(static_cast<T>(list->at(i)));
00515 }
00516 return theList;
00517 }
00518
00519 template<typename T>
00520 T dbListManager::getObjFromID(dbList* pList, int id)
00521 {
00522 for (int i=0; i<pList->size(); i++)
00523 {
00524 if (pList->at(i)->getID() == id)
00525 return static_cast<T>(pList->at(i));
00526 }
00527 return 0;
00528 }
00529
00530 template<typename T>
00531 T dbListManager::getObjFromName(QList<T>* list, QString &name)
00532 {
00533 T instObj = 0;
00534 for (int i = 0; i<list->size(); i++)
00535 {
00536 if (list->at(i)->getName().compare(name)==0)
00537 {
00538 instObj = list->at(i);
00539 break;
00540 }
00541 }
00542 return instObj;
00543 }
00544
00545 #endif