display exact matching result on the top of the suggestions list #LINQT-2433

This commit is contained in:
Gaelle Braud 2026-02-26 11:40:13 +01:00
parent 272e986e99
commit f42b529adb
3 changed files with 10 additions and 0 deletions

View file

@ -193,6 +193,10 @@ void MagicSearchList::setSearch(const QString &search) {
}
}
QString MagicSearchList::getSearch() const {
return mSearchFilter;
}
int MagicSearchList::getSourceFlags() const {
return mSourceFlags;
}

View file

@ -43,6 +43,7 @@ public:
void setSelf(const QSharedPointer<MagicSearchList> &me);
void connectContact(FriendCore *data);
void setSearch(const QString &search);
QString getSearch() const;
void setResults(const QList<QSharedPointer<FriendCore>> &contacts);
void add(QSharedPointer<FriendCore> contact);

View file

@ -129,6 +129,7 @@ void MagicSearchProxy::setSearchText(const QString &search) {
if (mSearchText != search) {
mSearchText = search;
mList->setSearch(mSearchText);
emit searchTextChanged();
}
}
@ -233,6 +234,8 @@ bool MagicSearchProxy::SortFilterList::filterAcceptsRow(int sourceRow, const QMo
bool MagicSearchProxy::SortFilterList::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const {
auto l = getItemAtSource<MagicSearchList, FriendCore>(sourceLeft.row());
auto r = getItemAtSource<MagicSearchList, FriendCore>(sourceRight.row());
auto list = dynamic_cast<MagicSearchList *>(sourceModel());
QString filter = list ? list->getSearch() : QString();
if (l && r) {
bool lIsStored = l->getIsStored() || l->isLdap() || l->isCardDAV();
@ -241,6 +244,8 @@ bool MagicSearchProxy::SortFilterList::lessThan(const QModelIndex &sourceLeft, c
else if (!lIsStored && rIsStored) return false;
auto lName = l->getFullName().toLower();
auto rName = r->getFullName().toLower();
if (lName == filter) return true;
else if (rName == filter) return false;
return lName < rName;
}
return true;