本文整理汇总了C++中Match::rank方法的典型用法代码示例。如果您正苦于以下问题:C++ Match::rank方法的具体用法?C++ Match::rank怎么用?C++ Match::rank使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Match
的用法示例。
在下文中一共展示了Match::rank方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: queryChanged
void DocumentCatalog::queryChanged()
{
int newStatus = 0;
if(query() == "")
{
// reset query
dir = QDir::home();
currentPath = "";
queryMatched = 0;
refreshFolders();
} else {
if(query().length() >= minQueryLen())
{
QString path = query().lower().remove(0, queryMatched);
int index;
while((index = path.find('/')) != -1) {
QString folderQuery = path.left(index);
QString guess = QString::null;
for(QStringList::Iterator it = folders.begin(); it != folders.end(); ++it) {
QString folderName = *it;
if(folderName.lower().startsWith(folderQuery) && (guess.isNull() || folderName.length() < guess.length()))
guess = folderName;
}
if(guess == QString::null) {
path = QString::null;
break;
}
if(!dir.cd(guess)) {
path = QString::null;
break;
}
refreshFolders();
queryMatched += folderQuery.length() + 1;
currentPath += guess + "/";
path = path.remove(0, index+1);
}
Match newBestMatch;
if(path.isNull()) {
files.clear();
} else {
if(!filesListed) {
refreshFiles();
}
if(!path.isEmpty()) {
if(currentDirDoc != 0) {
files.removeRef(currentDirDoc);
currentDirDoc = 0;
}
QPtrListIterator<Document> it(files);
Document *document;
while((document = it.current()) != 0) {
++it;
if(document->name().lower().startsWith(path)) {
int rank = 100*query().length()/document->text().length();
if(newBestMatch.isNull() || rank > newBestMatch.rank())
newBestMatch = Match(document, rank, currentPath.length() + path.length());
} else {
files.removeRef(document);
}
}
}
}
if(currentDirDoc != 0 && path.isEmpty())
newBestMatch = Match(currentDirDoc, 100, currentPath.length());
newStatus |= S_Active;
if(files.count() > 0)
{
newStatus |= S_HasResults;
if(files.count() > 1 || files.at(0)->className() == "Directory")
newStatus |= S_Multiple;
} else
newStatus |= S_NoResults;
setBestMatch(newBestMatch);
} else {
setBestMatch(Match());
}
}
setStatus(newStatus);
}
示例2: setQuery
void Katapult::setQuery(QString _query)
{
int allStatus=0;
bestMatch = Match();
this->_query = _query;
if(display != 0)
display->setQuery(_query);
if(_query == "")
{
QDictIterator<KatapultCatalog> it(catalogs);
KatapultCatalog *catalog;
while((catalog = it.current()) != 0)
{
++it;
catalog->setQuery("");
}
display->setItem(0);
display->setAction(0);
display->setStatus(0);
display->setSelected(0);
action = 0;
} else if(catalogs.count() == 0) {
allStatus = S_Active | S_NoResults;
display->setStatus(allStatus);
} else {
QDictIterator<KatapultCatalog> it(catalogs);
KatapultCatalog *catalog;
int status;
while((catalog = it.current()) != 0)
{
++it;
catalog->setQuery(_query);
status = catalog->status();
if(status & S_HasResults)
{
if(allStatus & S_HasResults)
allStatus |= S_Multiple;
Match match = catalog->bestMatch();
if(!match.isNull())
{
if(bestMatch.isNull() || bestMatch.rank() < match.rank())
bestMatch = match;
}
}
allStatus |= status;
}
if(bestMatch.isNull() || bestMatch.rank() == 0)
bestMatch = Match();
if(!bestMatch.isNull()) {
QPtrList<KatapultAction> itemActions = ActionRegistry::self()->actionsForItem(bestMatch.item());
action = itemActions.at(0);
}
if(display != 0)
{
display->setItem(bestMatch.item());
if(bestMatch.isNull()) {
display->setAction(0);
display->setSelected(0);
} else {
display->setAction(action);
display->setSelected(bestMatch.matched());
}
display->setStatus(allStatus);
}
if(!executing && settings->isAutoExecute() && allStatus & S_HasResults && !(allStatus & S_Multiple))
execute();
}
if(display != 0)
{
if(!(allStatus & S_HasResults) && allStatus & S_Active) {
// no results
switch(settings->noResultsAction()) {
case KatapultSettings::NR_HideDisplay:
hideTimer->start(settings->noResultsDelay(), TRUE);
break;
case KatapultSettings::NR_ClearQuery:
clearTimer->start(settings->noResultsDelay(), TRUE);
break;
default:
break;
}
}
display->update();
}
}