void ADT::search (Node* node, const ADTPoint& targetPoint, int& index) { if (node != NULL) { /*if (targetPoint.idx == 231) { cout << "alibaba" << endl; //exit(-2); }*/ // check whether the point is inside the element if (!node->isEmpty && node->p->idx!=-1 && doCubesOverlap (node, targetPoint) && compareFunction (node, targetPoint) ) { if (searchForNIntersections) { ++nIntersections; ids.push_back (node->p->idx); addresses.push_back (node); searchChildren (node, targetPoint); if (!searchStack.empty()) { Node* last = searchStack.back(); searchStack.back() = NULL; searchStack.pop_back(); search (last, targetPoint, index); } } else { fill (searchStack.begin(), searchStack.end(), nullptr); searchStack.clear(); index = node->p->idx; addresses.push_back (node); if (node != root) { node = NULL; } } } else { searchChildren (node, targetPoint); if (!searchStack.empty()) { Node* last = searchStack.back(); searchStack.back() = NULL; searchStack.pop_back(); search (last, targetPoint, index); } } } }
bool mainWin::searchChildren(QString srch, QTreeWidget *TW, QTreeWidgetItem *CI, bool &started, QTreeWidgetItem *SI){ //This is a recursive function for searching all the children of a particular item // TW - TreeWidget pointer // CI - Current TreeWidget Item (to search the children of) // SI - Start Item (Try to start searching right after this item - optional) // bool started - Start Item found and search has been started (optional input/output) //qDebug() << "Search Children of:" << CI->text(0) << srch << started; //Check for the start position int start = -1; if(SI == 0 || SI == CI){ //No search item to start at start = 0; started = true; }else if( !started){ QTreeWidgetItem *PI = SI; while( (start == -1) && (PI!=0) ){ start = CI->indexOfChild(PI); PI = PI->parent(); //look up one more layer to make sure it is not a child of one of these items } }else{ start = 0; } //start with the first child //Now quit if the start item is not found here if(start == -1){ started = false; return false; } //Now start searching bool found = false; for(int i=start; (i<CI->childCount()) && !found ; i++){ if(started){ //Check this item if(CI->child(i)->text(0).contains(srch, Qt::CaseInsensitive)){ TW->setCurrentItem(CI->child(i)); TW->scrollToItem(CI->child(i)); found=true; break; } }else if( SI == CI->child(i) ){ started = true; //but don't look at this item, continue on to the next one (or children) } if(found){ break; } else if(CI->child(i)->childCount() > 0){ //recursively search this items children found = searchChildren(srch, TW, CI->child(i), started, SI); } } return found; }
bool mainWin::performSearch(QString pkgSearch, QTreeWidget *TW, QTreeWidgetItem *SI){ //Start Iterating over the tree bool found=false; bool started = false; //if(SI==0){ started = true; } for(int p=0; (p<TW->topLevelItemCount()) && !found; p++){ //Check the actual item itself QTreeWidgetItem *CI = TW->topLevelItem(p); if(started && CI->text(0).contains(pkgSearch, Qt::CaseInsensitive)){ TW->setCurrentItem(CI); TW->scrollToItem(CI); found=true; }else{ found = searchChildren(pkgSearch, TW, CI, started, SI); } } return found; }
/// Constructor for AMControlState. /// Sets the name to the AMControl's objectName() function output. /// Calls searchChildren() on the control, which is called recursively. AMControlState::AMControlState(AMControl *ctrl, QObject *parent) : QObject(parent) { name_ = ctrl->objectName(); searchChildren(ctrl); }