10#define D(i, j) d[(i)*n + (j)]
13 qsizetype m = s.size() + 1;
14 qsizetype n = t.size() + 1;
15 int *d =
new int[m * n];
18 for (i = 0; i < m; ++i)
20 for (j = 0; j < n; ++j)
22 for (i = 1; i < m; ++i) {
23 for (j = 1; j < n; ++j) {
24 if (s[i - 1] == t[j - 1]) {
25 D(i, j) =
D(i - 1, j - 1);
28 int y =
D(i - 1, j - 1);
30 D(i, j) = 1 + qMin(qMin(x, y), z);
34 result =
D(m - 1, n - 1);
45 int deltaBest = 10000;
49 for (
const auto &candidate : candidates) {
50 if (candidate[0] == actual[0]) {
51 int delta = editDistance(actual, candidate);
52 if (delta < deltaBest) {
56 }
else if (delta == deltaBest) {
62 if (numBest == 1 && deltaBest <= 2 && actual.size() + best.size() >= 5)
69
70
71
72
74 const QSet<QString> &excludeSet)
76 QString best = nearestName(str, commandSet);
77 if (best.isEmpty() || excludeSet.contains(best))
QString suggestName(const QString &str, const QSet< QString > &commandSet, const QSet< QString > &excludeSet)
Returns a suggestion for the closest match to str in the given commandSet.
QT_BEGIN_NAMESPACE int editDistance(const QString &s, const QString &t)
QString nearestName(const QString &actual, const QSet< QString > &candidates)
Combined button and popup list for selecting options.