00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <QtGui>
00021
00022 #include "Institute.h"
00023 #include "InstItem.h"
00024 #include "ProgItem.h"
00025
00026 #include "StaffModel.h"
00027
00028 StaffModel::StaffModel(dbListManager * dataLists
00029 ,DataClass::ClassName cn
00030 ,RootItem * root
00031 ,QObject *parent
00032 )
00033 : RootModel(parent)
00034 {
00035 QList<QVariant> rootData;
00036 Institute * rootObj;
00037 if (root == 0)
00038 {
00039 rootObj = new Institute (0,tr("First Name"), tr("Last Name"));
00040 rootItem = new InstItem(rootObj);
00041 }
00042 else
00043 rootItem = root;
00044 setupData(*dataLists,cn,root);
00045 }
00046
00047
00048
00049
00050
00051 int StaffModel::columnCount(const QModelIndex &) const
00052 {
00053 return 2;
00054 }
00055
00056
00057 QVariant StaffModel::headerData(int section, Qt::Orientation orientation,
00058 int role) const
00059 {
00060 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
00061 switch (section)
00062 {
00063 case 0:
00064 return tr("First Name");
00065 case 1:
00066 return tr("Last Name");
00067 default:
00068 return "";
00069 }
00070 return QVariant();
00071 }
00072
00073
00074
00075
00076
00077 void StaffModel::setupData(dbListManager &dataLists
00078 ,DataClass::ClassName cn
00079 ,RootItem * parent
00080 )
00081 {
00082 if (parent == 0)
00083 setupInstData(dataLists, rootItem);
00084 else if (parent->rtti() == DataClass::INSTITUTE_CLASS)
00085 {
00086 if (cn == DataClass::INSTITUTE_CLASS)
00087 setupFacultyData(dataLists, static_cast<InstItem*>(parent));
00088 else if (cn == DataClass::DEPARTMENT_CLASS)
00089 setupInstStaffData(dataLists, static_cast<InstItem*>(parent));
00090 }
00091 else if (parent->rtti() == DataClass::FACULTY_CLASS)
00092 setupDeptData(dataLists, static_cast<FacItem*>(parent));
00093 else if (parent->rtti() == DataClass::DEPARTMENT_CLASS)
00094 setupStaffData(dataLists, static_cast<DeptItem*>(parent));
00095 }
00096
00097 void StaffModel::setupInstData(dbListManager &dataLists, RootItem * parent)
00098 {
00099 Institute * instObj;
00100 InstItem * iiObj;
00101 QList<Institute * > * instList = dataLists.getInstituteList();
00102
00103 for (int iCnt = 0; iCnt < instList->size(); ++iCnt)
00104 {
00105 instObj = instList->at(iCnt);
00106 iiObj = new InstItem(instObj, parent);
00107 parent->insertChild(iiObj);
00108 setupFacultyData(dataLists, iiObj);
00109 }
00110 }
00111
00112 void StaffModel::setupFacultyData(dbListManager &dataLists, InstItem * parent)
00113 {
00114 Faculty * facultyObj;
00115 FacItem * fiObj;
00116 QList<Faculty * > * facultyList = dataLists.getFacultyList(parent->getItemData());
00117
00118 for (int fCnt = 0; fCnt < facultyList->size(); ++fCnt)
00119 {
00120 facultyObj = facultyList->at(fCnt);
00121 fiObj = new FacItem(facultyObj, parent);
00122 parent->insertChild(fiObj);
00123 setupDeptData(dataLists, fiObj);
00124 }
00125 }
00126
00127 void StaffModel::setupDeptData(dbListManager &dataLists, FacItem * parent)
00128 {
00129 Department * deptObj;
00130 DeptItem * diObj;
00131 QList<Department * > * deptList = dataLists.getDepartmentList(parent->getItemData());
00132
00133 for (int dCnt = 0; dCnt < deptList->size(); ++dCnt)
00134 {
00135 deptObj = deptList->at(dCnt);
00136 diObj = new DeptItem(deptObj, parent);
00137 parent->insertChild(diObj);
00138 setupStaffData(dataLists, diObj);
00139 }
00140 }
00141
00142 void StaffModel::setupStaffData(dbListManager &dataLists, DeptItem * parent)
00143 {
00144 Staff * staffObj;
00145 StaffItem * siObj;
00146 QList<Staff * > * staffList = dataLists.getStaffList(parent->getItemData());
00147
00148 for (int dCnt = 0; dCnt < staffList->size(); ++dCnt)
00149 {
00150 staffObj = staffList->at(dCnt);
00151 siObj = new StaffItem(staffObj, parent);
00152 parent->insertChild(siObj);
00153 }
00154 }
00155
00156 void StaffModel::setupInstStaffData(dbListManager &dataLists, InstItem * parent)
00157 {
00158 Staff * staffObj;
00159 StaffItem * siObj;
00160 QList<Staff * > * staffList = dataLists.getStaffList(parent->getItemData());
00161
00162 for (int dCnt = 0; dCnt < staffList->size(); ++dCnt)
00163 {
00164 staffObj = staffList->at(dCnt);
00165 siObj = new StaffItem(staffObj, parent);
00166 parent->insertChild(siObj);
00167 }
00168 }