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

InstModel.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 "InstModel.h"
00021 
00022 InstModel::InstModel(dbListManager &dataLists, QObject *parent)
00023         : RootModel(parent)
00024 {
00025         Institute * rootObj;
00026         rootObj = new Institute (0,tr("Institute Name"), tr("Abbreviation"));
00027         rootItem = new InstItem(rootObj);
00028         setupInstData(dataLists,rootItem);
00029 }
00030 
00031 /******************************************************************************
00032  * Inherited from QAbstractItemModel
00033  ******************************************************************************/
00034 QVariant InstModel::headerData(int section, Qt::Orientation orientation,
00035                                                                                  int role) const
00036 {
00037         if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
00038                 switch (section)
00039                 {
00040                         case 0:
00041                                 return tr("Name");
00042                         case 1:
00043                                 return tr("Abbrev");
00044                         case 2:
00045                                 return tr("Duration");
00046                         case 3:
00047                                 return tr("WeeklyPeriods");
00048                         default:
00049                                 return "";
00050                 }
00051         return QVariant();
00052 }
00053 
00054 /******************************************************************************
00055  * Private Methods
00056  ******************************************************************************/
00057 void InstModel::setupInstData(dbListManager &dataLists, RootItem * parent)
00058 {
00059         Institute * instObj;
00060         InstItem   * iiObj;
00061         QList<Institute * > * instList = dataLists.getInstituteList();
00062         
00063         for (int iCnt = 0; iCnt < instList->size(); ++iCnt)
00064         {
00065                 instObj = instList->at(iCnt);
00066                 iiObj = new InstItem(instObj, parent);
00067                 parent->insertChild(iiObj);
00068                 setupProgData(dataLists, iiObj);
00069         } // end loop for each institute
00070 }
00071 
00072 void InstModel::setupProgData(dbListManager &dataLists, InstItem * parent)
00073 {
00074         Programme * progObj;
00075         ProgItem   * piObj;
00076         QList<Programme * > * selectedProgList;
00077         
00078         selectedProgList = dataLists.getProgrammeList(parent->getItemData());
00079         for (int pCnt = 0; pCnt < selectedProgList->size(); ++pCnt)
00080         {
00081                 progObj = selectedProgList->at(pCnt);
00082                 piObj = new ProgItem(progObj, parent,2);
00083                 parent->insertChild(piObj);
00084                 setupModuleData(dataLists, piObj);
00085         } // end loop for each programme
00086 }
00087 
00088 void InstModel::setupModuleData(dbListManager &dataLists, ProgItem * parent)
00089 {
00090         Module    * moduleObj;
00091         ModuleItem * miObj;
00092         QList<Module * >    * selectedModuleList;
00093 
00094         selectedModuleList = dataLists.getModuleList(parent->getItemData());
00095         for (int mCnt = 0; mCnt < selectedModuleList->size(); ++mCnt)
00096         {
00097                 moduleObj = selectedModuleList->at(mCnt);
00098                 miObj = new ModuleItem(moduleObj, parent);
00099                 parent->insertChild(miObj);
00100         } // end loop for each module
00101 }

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