00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "dbList.h"
00022
00023 dbList::dbList()
00024 {
00025 pdcList = new QList<DataClass * >();
00026 }
00027
00028 dbList::dbList(QList<DataClass * > * p_dcList)
00029 {
00030 pdcList = p_dcList;
00031 }
00032
00033
00034 QList<DataClass * > * dbList::list()
00035 {
00036 return pdcList;
00037 }
00038
00039 QList<DataClass * > * dbList::allChildren(DataClass * parent, bool deep)
00040 {
00041 if (deep)
00042 return allChildrenDeep(parent);
00043
00044 QList<DataClass * > * pChildren = new QList<DataClass * >();
00045 for (int i = 0; i<size(); i++)
00046 if (pdcList->at(i)->getParent() == parent)
00047 pChildren->append(pdcList->at(i));
00048 return pChildren;
00049 }
00050
00051 QList<DataClass * > * dbList::allChildrenDeep(DataClass * parent)
00052 {
00053 QList<DataClass * > * pChildren = new QList<DataClass * >();
00054 DataClass * obj, * objParent;
00055 for (int i = 0; i<size(); i++)
00056 {
00057 obj = pdcList->at(i);
00058 objParent = obj->getParent();
00059 while (objParent != 0)
00060 {
00061 if (objParent == parent)
00062 {
00063 pChildren->append(obj);
00064 break;
00065 }
00066 objParent = objParent->getParent();
00067 }
00068 }
00069 return pChildren;
00070 }
00071
00072
00073 DataClass * dbList::remove(int posn)
00074 {
00075 if (posn < 0 || posn >= pdcList->size())
00076 return 0;
00077 else
00078 {
00079 DataClass * dc = pdcList->at(posn);
00080 pdcList->removeAt(posn);
00081 return dc;
00082 }
00083 }
00084
00085
00086 DataClass * dbList::at(int posn)
00087 {
00088 if (posn < 0 || posn >= pdcList->size())
00089 return 0;
00090 else
00091 {
00092 return pdcList->at(posn);
00093 }
00094 }
00095
00096 void dbList::dump()
00097 {
00098 std::cout << " DataClass: ";
00099 if (pdcList->size() == 0)
00100 std::cout << "List is empty" << "\n";
00101 else
00102 std::cout << pdcList->at(0)->rtti() << "\n";
00103 for (int i = 0; i<pdcList->size(); i++)
00104 std::cout << pdcList->at(i)->getDescription().toStdString() << "\n";
00105 }