Ignore:
Timestamp:
Aug 16, 2013 2:23:52 PM (11 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2
Children:
db5e0d0
Parents:
cb8f638
Message:

Add search functionality to pc-pkgmanager. Still need to setup the keyboard shortcuts (ctrl-F, enter)

File:
1 edited

Legend:

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

    raac79d5c r5fd031d  
    4040  connect(action_Basic, SIGNAL( triggered(bool) ), this, SLOT( slotViewChanged() ) ); 
    4141  connect(action_Advanced, SIGNAL( triggered(bool) ), this, SLOT( slotViewChanged() ) ); 
     42  connect(tool_search, SIGNAL( clicked() ), this, SLOT( slotSearchPackages() ) ); 
    4243 
    4344  // Setup the action group 
     
    105106  } 
    106107 
     108} 
     109 
     110void mainWin::slotSearchPackages(){ 
     111  QString pkgSearch = line_search->text(); 
     112  if(pkgSearch.isEmpty()){ return; } 
     113  qDebug() << "Search for package:" <<pkgSearch; 
     114  //Get the pointer to the proper treewidget 
     115  QTreeWidget *TW = treeNGPkgs; 
     116  if( stackedPkgView->currentIndex() == 0 ){ TW = treeMetaPkgs; } 
     117  //Make sure the tree widget is not empty 
     118  if(TW->topLevelItemCount() < 2){ return; } 
     119  //iterate through the tree widget, starting at the current selection 
     120  QTreeWidgetItem *CI = TW->currentItem(); 
     121  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); 
     130  if(!found && !atTop){ 
     131    //Ask whether to restart the search at the top  
     132    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) ){ 
     133      //Restart the search from the top 
     134      found = performSearch(pkgSearch, TW, 0, 0); 
     135    } 
     136  } 
     137  if(!found){ 
     138    QMessageBox::information(this, tr("No Search Results"), tr("No packages could be found with that search term. Please adjust it and try again.") ); 
     139  } 
     140  qDebug() << " - Search Finished"; 
     141} 
     142 
     143bool mainWin::performSearch(QString pkgSearch, QTreeWidget *TW, int startParent, int startChild){ 
     144  //Iterate over the Tree  
     145  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); 
     152        found=true; 
     153        break; 
     154      } 
     155    } 
     156    startChild=0; //reset this for the next top level item 
     157    if(found){ break; } 
     158  } 
     159  return found; 
    107160} 
    108161 
     
    673726        catItem->addChild(pkgItem); 
    674727   } 
    675  
    676728} 
    677729 
     
    900952    addTreeItems(metaPkgList.at(z).at(0));     
    901953  } 
     954 
    902955} 
    903956 
Note: See TracChangeset for help on using the changeset viewer.