Changeset View
Changeset View
Standalone View
Standalone View
src/runnercontext.cpp
Show First 20 Lines • Show All 389 Lines • ▼ Show 20 Line(s) | |||||
390 | bool RunnerContext::addMatches(const QList<QueryMatch> &matches) | 390 | bool RunnerContext::addMatches(const QList<QueryMatch> &matches) | ||
391 | { | 391 | { | ||
392 | if (matches.isEmpty() || !isValid()) { | 392 | if (matches.isEmpty() || !isValid()) { | ||
393 | //Bail out if the query is empty or the qptr is dirty | 393 | //Bail out if the query is empty or the qptr is dirty | ||
394 | return false; | 394 | return false; | ||
395 | } | 395 | } | ||
396 | 396 | | |||
397 | LOCK_FOR_WRITE(d) | 397 | LOCK_FOR_WRITE(d) | ||
398 | foreach (QueryMatch match, matches) { | 398 | for (QueryMatch match : matches) { | ||
399 | // Give previously launched matches a slight boost in relevance | 399 | // Give previously launched matches a slight boost in relevance | ||
400 | // The boost smoothly saturates to 0.5; | 400 | // The boost smoothly saturates to 0.5; | ||
401 | if (int count = d->launchCounts.value(match.id())) { | 401 | if (int count = d->launchCounts.value(match.id())) { | ||
402 | match.setRelevance(match.relevance() + 0.5 * (1-exp(-count*0.3))); | 402 | match.setRelevance(match.relevance() + 0.5 * (1-exp(-count*0.3))); | ||
403 | } | 403 | } | ||
404 | 404 | | |||
405 | d->matches.append(match); | 405 | d->matches.append(match); | ||
406 | #ifndef NDEBUG | 406 | #ifndef NDEBUG | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 448 | { | |||
449 | if (!isValid()) { | 449 | if (!isValid()) { | ||
450 | return false; | 450 | return false; | ||
451 | } | 451 | } | ||
452 | 452 | | |||
453 | QStringList presentMatchIdList; | 453 | QStringList presentMatchIdList; | ||
454 | QList<const QueryMatch*> presentMatchList; | 454 | QList<const QueryMatch*> presentMatchList; | ||
455 | 455 | | |||
456 | LOCK_FOR_READ(d) | 456 | LOCK_FOR_READ(d) | ||
457 | foreach(const QString &matchId, matchIdList) { | 457 | for (const QString &matchId : matchIdList) { | ||
458 | const QueryMatch* match = d->matchesById.value(matchId, nullptr); | 458 | const QueryMatch* match = d->matchesById.value(matchId, nullptr); | ||
459 | if (match) { | 459 | if (match) { | ||
460 | presentMatchList << match; | 460 | presentMatchList << match; | ||
461 | presentMatchIdList << matchId; | 461 | presentMatchIdList << matchId; | ||
462 | } | 462 | } | ||
463 | } | 463 | } | ||
464 | UNLOCK(d) | 464 | UNLOCK(d) | ||
465 | 465 | | |||
466 | if (presentMatchIdList.isEmpty()) { | 466 | if (presentMatchIdList.isEmpty()) { | ||
467 | return false; | 467 | return false; | ||
468 | } | 468 | } | ||
469 | 469 | | |||
470 | LOCK_FOR_WRITE(d) | 470 | LOCK_FOR_WRITE(d) | ||
471 | foreach(const QueryMatch *match, presentMatchList) { | 471 | for (const QueryMatch *match : qAsConst(presentMatchList)) { | ||
472 | d->matches.removeAll(*match); | 472 | d->matches.removeAll(*match); | ||
473 | } | 473 | } | ||
474 | foreach(const QString &matchId, presentMatchIdList) { | 474 | for (const QString &matchId : qAsConst(presentMatchIdList)) { | ||
475 | d->matchesById.remove(matchId); | 475 | d->matchesById.remove(matchId); | ||
476 | } | 476 | } | ||
477 | UNLOCK(d) | 477 | UNLOCK(d) | ||
478 | 478 | | |||
479 | emit d->q->matchesChanged(); | 479 | emit d->q->matchesChanged(); | ||
480 | 480 | | |||
481 | return true; | 481 | return true; | ||
482 | } | 482 | } | ||
Show All 22 Lines | |||||
505 | { | 505 | { | ||
506 | if (!isValid()) { | 506 | if (!isValid()) { | ||
507 | return false; | 507 | return false; | ||
508 | } | 508 | } | ||
509 | 509 | | |||
510 | QList<QueryMatch> presentMatchList; | 510 | QList<QueryMatch> presentMatchList; | ||
511 | 511 | | |||
512 | LOCK_FOR_READ(d) | 512 | LOCK_FOR_READ(d) | ||
513 | foreach(const QueryMatch &match, d->matches) { | 513 | for(const QueryMatch &match : qAsConst(d->matches)) { | ||
514 | if (match.runner() == runner) { | 514 | if (match.runner() == runner) { | ||
515 | presentMatchList << match; | 515 | presentMatchList << match; | ||
516 | } | 516 | } | ||
517 | } | 517 | } | ||
518 | UNLOCK(d) | 518 | UNLOCK(d) | ||
519 | 519 | | |||
520 | if (presentMatchList.isEmpty()) { | 520 | if (presentMatchList.isEmpty()) { | ||
521 | return false; | 521 | return false; | ||
522 | } | 522 | } | ||
523 | 523 | | |||
524 | LOCK_FOR_WRITE(d) | 524 | LOCK_FOR_WRITE(d) | ||
525 | foreach (const QueryMatch &match, presentMatchList) { | 525 | for (const QueryMatch &match : qAsConst(presentMatchList)) { | ||
526 | d->matchesById.remove(match.id()); | 526 | d->matchesById.remove(match.id()); | ||
527 | d->matches.removeAll(match); | 527 | d->matches.removeAll(match); | ||
528 | } | 528 | } | ||
529 | UNLOCK(d) | 529 | UNLOCK(d) | ||
530 | 530 | | |||
531 | emit d->q->matchesChanged(); | 531 | emit d->q->matchesChanged(); | ||
532 | return true; | 532 | return true; | ||
533 | } | 533 | } | ||
Show All 29 Lines | 562 | { | |||
563 | return d->singleRunnerQueryMode; | 563 | return d->singleRunnerQueryMode; | ||
564 | } | 564 | } | ||
565 | 565 | | |||
566 | void RunnerContext::restore(const KConfigGroup &config) | 566 | void RunnerContext::restore(const KConfigGroup &config) | ||
567 | { | 567 | { | ||
568 | const QStringList cfgList = config.readEntry("LaunchCounts", QStringList()); | 568 | const QStringList cfgList = config.readEntry("LaunchCounts", QStringList()); | ||
569 | 569 | | |||
570 | const QRegExp r(QStringLiteral("(\\d*) (.*)")); | 570 | const QRegExp r(QStringLiteral("(\\d*) (.*)")); | ||
571 | foreach (const QString& entry, cfgList) { | 571 | for (const QString& entry : cfgList) { | ||
572 | r.indexIn(entry); | 572 | r.indexIn(entry); | ||
573 | int count = r.cap(1).toInt(); | 573 | int count = r.cap(1).toInt(); | ||
574 | QString id = r.cap(2); | 574 | QString id = r.cap(2); | ||
575 | d->launchCounts[id] = count; | 575 | d->launchCounts[id] = count; | ||
576 | } | 576 | } | ||
577 | } | 577 | } | ||
578 | 578 | | |||
579 | void RunnerContext::save(KConfigGroup &config) | 579 | void RunnerContext::save(KConfigGroup &config) | ||
Show All 23 Lines |