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

RoomModel.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 "RoomModel.h"
00021 
00022 RoomModel::RoomModel(dbListManager * dataLists, QObject *parent)
00023         : RootModel(parent)
00024 {
00025         QList<QVariant> rootData;
00026         Institute * rootObj;
00027         rootObj = new Institute (0,tr("Institute Name"), tr("Abbreviation"));
00028         rootItem = new InstItem(rootObj);
00029         setupInstData(*dataLists,rootItem);
00030 }
00031 
00032 
00033 /******************************************************************************
00034  * Inherited from RootModel
00035  ******************************************************************************/
00036 int RoomModel::columnCount(const QModelIndex &) const
00037 {
00038         return 3;
00039 }
00040 
00041 QVariant RoomModel::headerData(int section, Qt::Orientation orientation,
00042                                                                                  int role) const
00043 {
00044         if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
00045                 switch (section)
00046                 {
00047                         case 0:
00048                                 return tr("Name");
00049                         case 1:
00050                                 return tr("Code");
00051                         case 2:
00052                                 return tr("Capacity");
00053                         default:
00054                                 return "";
00055                 }
00056         return QVariant();
00057 }
00058 
00059 /******************************************************************************
00060  * Private Methods
00061  ******************************************************************************/
00062 void RoomModel::setupInstData(dbListManager &dataLists, RootItem * parent)
00063 {
00064         Institute * instObj;
00065         InstItem   * iiObj;
00066         QList<Institute * > * instList = dataLists.getInstituteList();
00067         
00068         for (int iCnt = 0; iCnt < instList->size(); ++iCnt)
00069         {
00070                 instObj = instList->at(iCnt);
00071                 iiObj = new InstItem(instObj, parent);
00072                 parent->insertChild(iiObj);
00073                 setupRoomData(dataLists, iiObj);
00074         } // end loop for each institute
00075 }
00076 
00077 void RoomModel::setupRoomData(dbListManager &dataLists, InstItem * parent)
00078 {
00079         Room * roomObj;
00080         RoomItem   * riObj;
00081         QList<Room * > * roomList;
00082         
00083         roomList = dataLists.getRoomList(parent->getItemData());
00084         for (int rCnt = 0; rCnt < roomList->size(); ++rCnt)
00085         {
00086                 roomObj = roomList->at(rCnt);
00087                 riObj = new RoomItem(roomObj, parent);
00088                 parent->insertChild(riObj);
00089         } // end loop for each room
00090 }

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