00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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:
00039
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:
00053 static const int UNKNOWN;
00054
00055 protected:
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:
00065
00066 RootItem(RootItem *parent = 0, int cc =0);
00067 RootItem(RootItem & ii);
00068
00069
00070
00071 virtual QString getDescription()const=0;
00072 virtual QVariant data(int column) const =0;
00073 virtual DataClass * getItemData()const =0;
00074
00075 inline virtual int getParentID() {return UNKNOWN;}
00076 inline int columnCount() const {return col_count;}
00077
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
00083 QString getClassName();
00084 int row() const;
00085 RootItem * findItem(DataClass * dc);
00086 int findChildPos(int id);
00087
00088
00089
00090 virtual bool setData(int column, const QVariant & value) =0;
00091
00092 inline void setParent(RootItem* pi){parentItem = pi;}
00093 inline void clearAllChildren(){childItems.clear();}
00094 inline void setColumnCount(int cc) {col_count = cc;}
00095
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
00107
00108 inline virtual QColor textColour(int ){return txtColour[row()%2];}
00109 inline virtual QColor bgColour(int ) {return backgroundColour[row()%2];}
00110
00111
00112 virtual void dbSave()=0;
00113 virtual void dbDelete()=0;
00114
00115
00116
00117 inline int rtti(){return RTTI;}
00118 RootItem * clone();
00119
00120 void dump();
00121 };
00122
00123 #endif