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

ModuleModel.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 "ProgItem.h"
00023 #include "ModuItem.h"
00024 
00025 #include "ModuleModel.h"
00026 
00027 ModuleModel::ModuleModel(dbListManager * dataLists, Programme* prog, bool evenSem, QObject *parent)
00028         : RootModel(parent)
00029 {
00030         QList<QVariant> rootData;
00031         Module * rootObj;
00032         rootObj = new Module (0,0,tr("Module Name"), tr("Nomenclature"), 0, 0, 0);
00033         rootItem = new ProgItem(prog);
00034         setupModData(*dataLists,prog,rootItem, evenSem);
00035 }
00036 
00037 
00038 /******************************************************************************
00039  * Inherited from RootModel
00040  ******************************************************************************/
00041 int ModuleModel::columnCount(const QModelIndex &) const
00042 {
00043         return 3;
00044 }
00045 
00046 
00047 QVariant ModuleModel::headerData(int section, Qt::Orientation orientation,
00048                                                                                  int role) const
00049 {
00050         if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
00051                 switch (section)
00052                 {
00053                         case 0:
00054                                 return tr("Code");
00055                         case 1:
00056                                 return tr("Hours");
00057                         case 2:
00058                                 return tr("Name");
00059                         default:
00060                                 return "";
00061                 }
00062         return QVariant();
00063 }
00064 
00065 /******************************************************************************
00066  * Private Methods
00067  ******************************************************************************/
00068 void ModuleModel::setupData(dbListManager&, RootItem * )
00069 {
00070 }
00071 
00072 void ModuleModel::setupModData(dbListManager &dataLists, Programme * prog, RootItem * parent, bool evenSem)
00073 {
00074         Module * modObj;
00075         ModuleItem   * miObj;
00076         QList<Module * > * modList;
00077         
00078         modList = dataLists.getModuleList(prog);
00079         for (int Cnt = 0; Cnt < modList->size(); ++Cnt)
00080         {
00081                 modObj = modList->at(Cnt);
00082                 if (evenSem && modObj->isEvenSem())
00083                 {
00084                         miObj = new ModuleItem(modObj, parent);
00085                         miObj->setColumnOrder(4
00086                                              ,ModuleItem::COL_NOMENCLATURE
00087                                              ,ModuleItem::COL_HOURS
00088                                              ,ModuleItem::COL_NAME
00089                                              ,ModuleItem::COL_WEEKS);
00090                         parent->insertChild(miObj);
00091                 }
00092                 if (!evenSem && modObj->isOddSem())
00093                 {
00094                         miObj = new ModuleItem(modObj, parent);
00095                         miObj->setColumnOrder(4
00096                                              ,ModuleItem::COL_NOMENCLATURE
00097                                              ,ModuleItem::COL_HOURS
00098                                              ,ModuleItem::COL_NAME
00099                                              ,ModuleItem::COL_WEEKS);
00100                         parent->insertChild(miObj);
00101                 }
00102         } // end loop for each module
00103 }

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