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

RootItem.h

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 #ifndef __ROOT_ITEM_H
00021 #define __ROOT_ITEM_H
00022 
00023 #include <QList>
00024 #include <QVariant>
00025 #include <QColor>
00026 
00027 #include "GUIPref.h"
00028 #include "DataClass.h"
00029 
00030 class RootItem;
00031 
00032 typedef bool (*CompareRI)(const RootItem*, const RootItem*);
00033 
00034 class RootItem : virtual public QObject
00035 {
00036         Q_OBJECT
00037         
00038         public: // Data Types
00039                 // When adding a new class also modify getClassName() in RootItem.cpp
00040                 enum ObjClass {ABSTRACT_ITEM
00041                                                   ,INST_ITEM
00042                                                   ,PROG_ITEM
00043                                                   ,MODULE_ITEM
00044                                                   ,FACULTY_ITEM
00045                                                   ,DEPT_ITEM
00046                                                   ,STAFF_ITEM
00047                                                   ,ROOM_ITEM
00048                                                   ,ML_ALLOC_ITEM
00049                                                   ,TIME_SLOT_ITEM
00050                                                   ,DAILY_TIME_SLOT_ITEM
00051                                                   };
00052         public: // Constants
00053                 static const int UNKNOWN;
00054                 
00055         protected: // Properties
00056                 QList<RootItem*> childItems;
00057                 RootItem *parentItem;
00058                 DataClass * itemData;
00059                 int RTTI;
00060                 int col_count;
00061                 QVector<int> col_order;
00062                 QVector<QColor> txtColour;
00063                 QVector<QColor> backgroundColour;
00064         public: // Methods
00065         // Constructors
00066                 RootItem(RootItem *parent = 0, int cc =0);
00067                 RootItem(RootItem & ii);
00068         
00069         // Get Methods
00070                 // Abstract Methods
00071                 virtual QString getDescription()const=0;
00072                 virtual QVariant data(int column) const =0;
00073                 virtual DataClass * getItemData()const =0;
00074                 // inline virtual Methods
00075                 inline virtual int getParentID() {return UNKNOWN;}
00076                 inline int columnCount() const {return col_count;}
00077                 // inline Methods
00078                 inline int getID() const {return itemData->getID();}
00079                 inline RootItem *parent(){return parentItem;}
00080                 inline int childCount() const {return childItems.count();}
00081                 inline RootItem *child(int row) const {return dynamic_cast<RootItem *>(childItems.value(row));}
00082                 // Methods
00083                 QString getClassName();
00084                 int row() const;
00085                 RootItem * findItem(DataClass * dc);
00086                 int findChildPos(int id);
00087         
00088         // Set Methods
00089                 // Abstract Methods
00090                 virtual bool setData(int column, const QVariant & value) =0;
00091                 // inline  Methods
00092                 inline void setParent(RootItem* pi){parentItem = pi;}
00093                 inline void clearAllChildren(){childItems.clear();}
00094                 inline void setColumnCount(int cc) {col_count = cc;}
00095                 // Methods
00096                 void setColumnOrder(int count, ...);
00097                 void setTextColour(int count, ...);
00098                 void setBGColour(int count, ...);
00099                 void insertChild(RootItem *child);
00100                 void appendChild(RootItem *item);
00101                 void deleteChild(RootItem *child);
00102                 static bool riCompareCI(const RootItem *p1, const RootItem * p2);
00103                 static bool riCompareCS(const RootItem *p1, const RootItem * p2);
00104                 void sort(CompareRI compare) {qSort(childItems.begin(), childItems.end(), compare);}
00105         
00106         // Data display
00107                 // inline virtual Methods
00108                 inline virtual QColor textColour(int ){return txtColour[row()%2];}
00109                 inline virtual QColor bgColour(int )  {return backgroundColour[row()%2];}
00110         // database manipulation
00111                 // Abstract Methods
00112                 virtual void dbSave()=0;
00113                 virtual void dbDelete()=0;
00114         
00115         // diagnostic
00116                 // inline Methods
00117                 inline int rtti(){return RTTI;}
00118                 RootItem * clone();
00119                 // Methods
00120                 void dump();
00121 };
00122 
00123 #endif

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