Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

StaffModel.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Graeme Foster                                   *
00003  *   email    foster.graeme@gmail.com                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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  * Inherited from RootModel
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  * Private Methods
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         } // end loop for each institute
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         } // end loop for each faculty
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         } // end loop for each department
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         } // end loop for each staff
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         } // end loop for each staff
00168 }

Generated on Thu Apr 6 16:27:17 2006 for time-table by  doxygen 1.4.4