Changeset f3f036a


Ignore:
Timestamp:
08/19/13 09:54:10 (17 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3, releng/10.1
Children:
2e7bf77
Parents:
1a09105
Message:

Clean up the new search functionality in pc-pkgmanager. It is now recursive and fast (so no worries about changing the depth of the tree's) The only caveat is that it will not return a top-level item as a search result at the moment.
Also setup the search button to be actively enabled/disabled

Location:
src-qt4/pc-pkgmanager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/pc-pkgmanager/mainWin.cpp

    r5fd031d rf3f036a  
    3030  lastError=""; 
    3131  wDir = ch; 
    32  
     32         
    3333  //Grab the username 
    3434  //username = QString::fromLocal8Bit(getenv("LOGNAME")); 
     
    117117  //Make sure the tree widget is not empty 
    118118  if(TW->topLevelItemCount() < 2){ return; } 
    119   //iterate through the tree widget, starting at the current selection 
     119  //Get the currently selected item 
    120120  QTreeWidgetItem *CI = TW->currentItem(); 
    121121  bool found=false; bool atTop=false; 
    122   if(CI == 0){ CI = TW->topLevelItem(0); atTop=true; } 
    123   //Get the starting index (parent and child) 
    124   QTreeWidgetItem *PI = CI->parent(); 
    125   int startParent=0; int startChild=0; 
    126   if(PI == 0){ startParent = TW->indexOfTopLevelItem(CI); } //startchild == 0 
    127   else{ startParent = TW->indexOfTopLevelItem(PI); startChild = PI->indexOfChild(CI) +1; } 
    128   //Now iterate over the tree, only looking at the actual packages (not categories) 
    129   found = performSearch(pkgSearch, TW, startParent, startChild); 
     122  if(CI == 0){ atTop=true; } 
     123  //Now search the tree, starting at that item 
     124  found = performSearch(pkgSearch, TW, CI); 
    130125  if(!found && !atTop){ 
    131126    //Ask whether to restart the search at the top  
    132127    if(QMessageBox::Yes == QMessageBox::question(this,tr("No Search Results"),tr("Do you want to continue the search from the top?"),QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ){ 
    133128      //Restart the search from the top 
    134       found = performSearch(pkgSearch, TW, 0, 0); 
     129      found = performSearch(pkgSearch, TW, 0); 
    135130    } 
    136131  } 
     
    141136} 
    142137 
    143 bool mainWin::performSearch(QString pkgSearch, QTreeWidget *TW, int startParent, int startChild){ 
    144   //Iterate over the Tree  
     138bool mainWin::performSearch(QString pkgSearch, QTreeWidget *TW, QTreeWidgetItem *SI){ 
     139  //Start Iterating over the tree 
    145140  bool found=false; 
    146   for(int p=startParent; p<TW->topLevelItemCount(); p++){ 
    147     for(int c=startChild; c<TW->topLevelItem(p)->childCount(); c++){ 
    148       QTreeWidgetItem *CI = TW->topLevelItem(p)->child(c); 
    149       if(CI->text(0).contains(pkgSearch, Qt::CaseInsensitive)){ 
    150         TW->setCurrentItem(CI); 
    151         TW->scrollToItem(CI); 
     141  bool started = false; 
     142 
     143  for(int p=0; (p<TW->topLevelItemCount()) && !found; p++){ 
     144    found = searchChildren(pkgSearch, TW, TW->topLevelItem(p), started, SI); 
     145  } 
     146  return found; 
     147} 
     148 
     149bool mainWin::searchChildren(QString srch, QTreeWidget *TW, QTreeWidgetItem *CI, bool &started, QTreeWidgetItem *SI){ 
     150  //This is a recursive function for searching all the children of a particular item 
     151  // TW - TreeWidget pointer 
     152  // CI - Current TreeWidget Item (to search the children of) 
     153  // SI - Start Item (Try to start searching right after this item - optional) 
     154  // bool started - Start Item found and search has been started (optional input/output) 
     155         
     156  //qDebug() << "Search Children of:" << CI->text(0) << srch << started; 
     157  //Check for the start position 
     158  int start = -1; 
     159  if(SI == 0){ 
     160    //No search item to start at 
     161    start = 0; 
     162    started = true; 
     163  }else if( !started){ 
     164    QTreeWidgetItem *PI = SI; 
     165      while( (start == -1) && (PI!=0) ){ 
     166        start = CI->indexOfChild(PI); 
     167        PI = PI->parent(); //look up one more layer to make sure it is not a child of one of these items 
     168      } 
     169  }else{ start = 0; } //start with the first child 
     170  //Now quit if the start item is not found here 
     171  if(start == -1){ started = false; return false; } 
     172   
     173  //Now start searching 
     174  bool found = false; 
     175  for(int i=start; (i<CI->childCount()) && !found ; i++){ 
     176    if(started){ 
     177      //Check this item  
     178      if(CI->child(i)->text(0).contains(srch, Qt::CaseInsensitive)){ 
     179        TW->setCurrentItem(CI->child(i)); 
     180        TW->scrollToItem(CI->child(i)); 
    152181        found=true; 
    153182        break; 
    154183      } 
     184    }else if( SI == CI->child(i) || SI == CI ){ 
     185      started = true; //but don't look at this item, continue on to the next one (or children) 
    155186    } 
    156     startChild=0; //reset this for the next top level item 
    157187    if(found){ break; } 
     188    else if(CI->child(i)->childCount() > 0){ 
     189      //recursively search this items children 
     190      found = searchChildren(srch, TW, CI->child(i), started, SI);  
     191    } 
    158192  } 
    159193  return found; 
     
    511545  qDebug() << "Starting metaWidget..."; 
    512546  groupInfo->setVisible(false); 
     547  //Make sure the search box is disabled at startup 
     548  tool_search->setEnabled(false); 
    513549 
    514550  // Running in basic mode 
     
    601637  connect(treeNGPkgs, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotEnableApply())); 
    602638  connect(treeNGPkgs, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(slotNGItemChanged())); 
    603  
     639  //Enable the search option 
     640  tool_search->setEnabled(true); 
    604641  // Now we can look for updates safely 
    605642  slotRescanPkgsClicked(); 
     
    908945 
    909946  connect(treeMetaPkgs, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotDeskPkgsChanged(QTreeWidgetItem *, int))); 
    910  
     947  //Enable the search option 
     948  tool_search->setEnabled(true); 
    911949  // Now we can look for updates safely 
    912950  slotRescanPkgsClicked(); 
  • src-qt4/pc-pkgmanager/mainWin.h

    r5fd031d rf3f036a  
    8282 
    8383    //Search Iteration 
    84     bool performSearch(QString pkgSearch, QTreeWidget *TW, int startParent, int startChild); 
     84    bool performSearch(QString pkgSearch, QTreeWidget *TW, QTreeWidgetItem *SI = 0); 
     85    bool searchChildren(QString srch, QTreeWidget *TW, QTreeWidgetItem *CI, bool &started, QTreeWidgetItem *SI); 
    8586 
    8687    // Updates 
Note: See TracChangeset for help on using the changeset viewer.