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

RootItem.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 
00021 #include "RootItem.h"
00022 
00023 #include "InstItem.h"
00024 #include "FacItem.h"
00025 #include "DeptItem.h"
00026 #include "StaffItem.h"
00027 #include "ProgItem.h"
00028 #include "ModuItem.h"
00029 #include "RoomItem.h"
00030 #include "MLAllocItem.h"
00031 #include "TimeSlotItem.h"
00032 
00033 const int RootItem::UNKNOWN = -1;
00034 
00035 bool RootItem::riCompareCI(const RootItem *p1, const RootItem * p2)
00036 {
00037         return p1->getDescription().toLower() < p2->getDescription().toLower();
00038 }
00039 
00040 bool RootItem::riCompareCS(const RootItem *p1, const RootItem * p2)
00041 {
00042         return p1->getDescription() < p2->getDescription();
00043 }
00044 
00045 
00046 RootItem::RootItem(RootItem* parent, int cc)
00047 {
00048         RTTI = ABSTRACT_ITEM;
00049         itemData = 0;
00050         col_count = cc;
00051         parentItem = parent;
00052         setTextColour(2
00053                      ,GUIPref::Instance()->getColour(GUIPref::CT_DEFAULT_TEXT,0)
00054                      ,GUIPref::Instance()->getColour(GUIPref::CT_DEFAULT_TEXT,0));
00055         setBGColour(2
00056                    ,GUIPref::Instance()->getColour(GUIPref::CT_DEFAULT_BG,0)
00057                    ,GUIPref::Instance()->getColour(GUIPref::CT_DEFAULT_BG,1));
00058 }
00059 RootItem::RootItem(RootItem & ri)
00060 {
00061         RTTI       = ri.RTTI;
00062         itemData   = ri.itemData;
00063         col_count  = ri.col_count;
00064         parentItem = ri.parentItem;
00065 }
00066 // Get Methods
00067 QString RootItem::getClassName()
00068 {
00069         switch (RTTI)
00070         {
00071                 case ABSTRACT_ITEM:
00072                         return "RootItem";
00073                 case INST_ITEM:
00074                         return "InstItem";
00075                 case PROG_ITEM:
00076                         return "ProgItem";
00077                 case MODULE_ITEM:
00078                         return "ModuleItem";
00079                 case FACULTY_ITEM:
00080                         return "FacItem";
00081                 case DEPT_ITEM:
00082                         return "DeptItem";
00083                 case STAFF_ITEM:
00084                         return "StaffItem";
00085                 case ROOM_ITEM:
00086                         return "RoomItem";
00087                 case ML_ALLOC_ITEM:
00088                         return "MLAllocItem";
00089         }       // end of switch on RTTI
00090         return QString();
00091 }
00092 
00093 int RootItem::row() const
00094 {
00095         if (parentItem)
00096                 return parentItem->childItems.indexOf(const_cast<RootItem*>(this));
00097         return 0;
00098 }
00099 
00100 RootItem * RootItem::findItem(DataClass * dc)
00101 {
00102         if (itemData == dc)
00103                 return this;
00104         for (int i = 0; i < childItems.size(); ++i)
00105         {
00106                 RootItem * item = childItems.at(i)->findItem(dc);
00107                 if (item != 0)
00108                         return item;
00109         }
00110         return 0;
00111 }
00112 
00113 int RootItem::findChildPos(int id)
00114 {
00115         for (int i = 0; i < childItems.size(); ++i)
00116         {
00117                 if (childItems.at(i)->getID() == id)
00118                         return i;
00119         }
00120         return RootItem::UNKNOWN;
00121 }
00122 
00123 // Set Methods
00124 void RootItem::setColumnOrder(int count, ...)
00125 {
00126         col_order.resize(count);
00127         setColumnCount(count);
00128         int i = 0;
00129         va_list ap;
00130         va_start(ap,count); /* point to first element after count*/
00131         while(count > i)
00132         {
00133                 col_order[i]=va_arg(ap, int);
00134                 i++;
00135         }
00136         va_end(ap);
00137 }
00138 
00139 void RootItem::setTextColour(int count, ...)
00140 {
00141         txtColour.resize(count);
00142         int i = 0;
00143         va_list ap;
00144         va_start(ap,count); /* point to first element after count*/
00145         while(count > i)
00146         {
00147                 txtColour[i]=(QColor)(* va_arg(ap, QColor *));
00148                 i++;
00149         }
00150         va_end(ap);
00151 }
00152 
00153 void RootItem::setBGColour(int count, ...)
00154 {
00155         backgroundColour.resize(count);
00156         int i = 0;
00157         va_list ap;
00158         va_start(ap,count); /* point to first element after count*/
00159         while(count > i)
00160         {
00161                 backgroundColour[i]=(QColor)(* va_arg(ap, QColor *));
00162                 i++;
00163         }
00164         va_end(ap);
00165 }
00166 
00167 void RootItem::insertChild(RootItem *item)
00168 {
00169         int i = 0;
00170         while (i < childItems.size())
00171         {
00172                 if (childItems[i]->data(0).toString() > item->data(0).toString())
00173                         break;
00174                 i++;
00175         }
00176         childItems.insert(i,item);
00177 }
00178 
00179 void RootItem::appendChild(RootItem *item)
00180 {
00181         childItems.insert(childItems.size(),item);
00182 }
00183 
00184 void RootItem::deleteChild(RootItem *child)
00185 {
00186         if (child != 0)
00187         {
00188                 int pos = findChildPos(child->getID());
00189                 if (pos != RootItem::UNKNOWN)
00190                 {
00191                         childItems.takeAt(pos);
00192                 }
00193         }
00194 }
00195 
00196 RootItem * RootItem::clone()
00197 {
00198         switch (RTTI)
00199         {
00200                 case ABSTRACT_ITEM:
00201                         return 0;
00202                 case INST_ITEM:
00203                         return new InstItem(*static_cast<InstItem *>(this));
00204                 case PROG_ITEM:
00205                         return new ProgItem(*static_cast<ProgItem *>(this));
00206                 case MODULE_ITEM:
00207                         return new ModuleItem(*static_cast<ModuleItem*>(this));
00208                 case FACULTY_ITEM:
00209                         return new FacItem(*static_cast<FacItem*>(this));
00210                 case DEPT_ITEM:
00211                         return new DeptItem(*static_cast<DeptItem*>(this));
00212                 case STAFF_ITEM:
00213                         return new StaffItem(*static_cast<StaffItem*>(this));
00214                 case ROOM_ITEM:
00215                         return new RoomItem(*static_cast<RoomItem*>(this));
00216                 case ML_ALLOC_ITEM:
00217                         return new MLAllocItem(*static_cast<MLAllocItem*>(this));
00218         }       // end of switch on RTTI
00219         return 0;
00220 }
00221 
00222 void RootItem::dump()
00223 {
00224         std::cout << "Start of RootItem dump\n";
00225         for (int i = 0; i<childItems.size(); i++)
00226                 std::cout << i << ": " << childItems.at(i)->getDescription().toStdString() << " Child Count" << childItems.at(i)->childCount() << std::endl;
00227         std::cout << "End of RootItem dump\n\n";
00228 }

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