X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..14cd6d834ab531525a51c6a6992583b3e9143e02:/BlockLibraryTree.cpp diff --git a/BlockLibraryTree.cpp b/BlockLibraryTree.cpp index 33980f9..2c9b365 100644 --- a/BlockLibraryTree.cpp +++ b/BlockLibraryTree.cpp @@ -1,8 +1,6 @@ #include "BlockLibraryTree.h" -BlockLibraryTree::BlockLibraryTree() { - tabCategories = NULL; - tabIdParent = NULL; +BlockLibraryTree::BlockLibraryTree() { nbCategories = 0; } @@ -14,8 +12,7 @@ void BlockLibraryTree::clear() { for(int i=0;iblocks.clear(); } } - +/* void BlockLibraryTree::addItem(QXmlAttributes &attributes) { nbCategories++; @@ -51,15 +48,22 @@ void BlockLibraryTree::addItem(QXmlAttributes &attributes) tabCategories[id] = cat; tabIdParent[id] = idParent; } - -bool BlockLibraryTree::initChildParent() -{ +*/ +bool BlockLibraryTree::initChildParent() { // initializing parent/childs + bool ok; for(int i=0;i= nbCategories) return false; - tabCategories[i]->setParent(tabCategories[tabIdParent[i]]); - tabCategories[tabIdParent[i]]->addChild(tabCategories[i]); + if (tabIdParent[i] >= 0) { + ok = false; + foreach (BlockCategory* cat, tabCategories) { + if (cat->getId() == tabIdParent[i]) { + tabCategories[i]->setParent(cat); + cat->addChild(tabCategories[i]); + ok = true; + break; + } + } + if (!ok) return false; } } return true; @@ -79,20 +83,15 @@ void BlockLibraryTree::load(QDomElement &elt) throw(Exception) { if (elt.tagName() != "categories") throw(Exception(CONFIGFILE_CORRUPTED)); - QString nbStr = elt.attribute("nb","none"); bool ok; - int nb = nbStr.toInt(&ok); QDomNodeList list = elt.elementsByTagName("category"); nbCategories = list.size(); - if (nb != nbCategories) throw(Exception(CONFIGFILE_CORRUPTED)); QString name; int id; QString idStr; int idParent; QString idParentStr; - tabCategories = new BlockCategory* [nbCategories]; - tabIdParent = new int[nbCategories]; BlockCategory* cat = NULL; // creating all BlockCategory objects @@ -103,35 +102,31 @@ void BlockLibraryTree::load(QDomElement &elt) throw(Exception) { idStr = e.attribute("id","none"); idParentStr = e.attribute("parent","none"); id = idStr.toInt(&ok); - if ((!ok) || (id < 0) || (id >= nbCategories)) throw(Exception(CONFIGFILE_CORRUPTED)); + if ((!ok) || (id < 0) || (id >= 100)) throw(Exception(CONFIGFILE_CORRUPTED)); idParent = idParentStr.toInt(&ok); - if ((!ok)|| (idParent < -1) || (idParent >= nbCategories)) throw(Exception(CONFIGFILE_CORRUPTED)); + if ((!ok)|| (idParent < -1) || (idParent >= 100)) throw(Exception(CONFIGFILE_CORRUPTED)); cat = new BlockCategory(name,id); - tabCategories[id] = cat; - tabIdParent[id] = idParent; + tabCategories.append(cat); + tabIdParent.append(idParent); } + cat = new BlockCategory("hidden",100); + tabCategories.append(cat); + tabIdParent.append(0); ok = initChildParent(); - delete [] tabIdParent; + if (!ok) throw(Exception(CONFIGFILE_CORRUPTED)); } BlockCategory* BlockLibraryTree::searchCategory(int id) { - if (tabCategories != NULL) { - if ((id>=0) && (id < nbCategories)) { - return tabCategories[id]; - } + foreach(BlockCategory* cat, tabCategories) { + if (cat->getId() == id) return cat; } - return NULL; } BlockCategory *BlockLibraryTree::getRoot() { - if (tabCategories != NULL) { - if (nbCategories > 0) { - return tabCategories[0]; - } - } - return NULL; + + return searchCategory(0); }