Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Fine-Tuned Zim Search #1189

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7b7c949
Introduce suggestiolistmodel.{h, cpp}
ShaopengLin Aug 19, 2024
1f1743b
Move SearchBarLineEdit urlList to SuggestionListModel
ShaopengLin Sep 1, 2024
8611a1c
Enter Library::getZimIcon()
ShaopengLin Sep 1, 2024
6cbc9e8
Add Suggestion Icon Decoration Role
ShaopengLin Sep 1, 2024
c029da2
Refactor SuggestionListWorker
ShaopengLin Sep 1, 2024
d5de7c6
Introduce SuggestionListModel::lastIndex
ShaopengLin Sep 17, 2024
0aac03f
Introduce Endless Suggestions
ShaopengLin Sep 17, 2024
84e29ec
Endless Suggestion Key press compatible
ShaopengLin Sep 17, 2024
2aca115
Endless Suggestion Page_Down Compatible
ShaopengLin Sep 17, 2024
1894d41
Correctly handle Endless w/Fulltext
ShaopengLin Sep 17, 2024
d0a1680
Fetch Only When More Suggesion Exist
ShaopengLin Sep 18, 2024
76bae0d
Make First Row Visible on Suggestion Popup
ShaopengLin Sep 17, 2024
a7d7304
Introduce Kiwix Search Header
ShaopengLin Sep 17, 2024
d713173
Replace m_completer.popup() with m_suggestionView
ShaopengLin Sep 17, 2024
b3d9424
Enter KiwixApp::getSearchBar()
ShaopengLin Sep 17, 2024
ff7117b
BugFix openCompletion Connected Multiple Times
ShaopengLin Sep 28, 2024
ce36366
Make SearchBar Margin Consistent
ShaopengLin Sep 28, 2024
b9f4f94
Align Search Suggestion with Line Edit
ShaopengLin Sep 28, 2024
02e042a
Fix Suggestion Flickering when Typing
ShaopengLin Sep 28, 2024
dac8d04
Proper Size for Suggestion View
ShaopengLin Sep 28, 2024
fcebdd0
Proper Suggestion Icon&Text Spacing
ShaopengLin Sep 28, 2024
64b30c3
Proper Hover Style to Suggestion Items
ShaopengLin Sep 28, 2024
b19ea81
Proper Elide for Suggestion List Text
ShaopengLin Sep 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void SearchBarLineEdit::hideSuggestions()
void SearchBarLineEdit::clearSuggestions()
{
m_suggestionModel.resetSuggestions();
m_urlList.clear();
m_suggestionModel.resetUrlList();
}

void SearchBarLineEdit::on_currentTitleChanged(const QString& title)
Expand Down Expand Up @@ -169,9 +169,9 @@ void SearchBarLineEdit::updateCompletion()
if (token != m_token) {
return;
}
m_urlList = urlList;
m_suggestionModel.resetUrlList(urlList);
if (m_returnPressed) {
openCompletion(suggestions.first(), 0);
openCompletion(m_suggestionModel.index(0));
return;
}
m_suggestionModel.resetSuggestions(suggestions);
ShaopengLin marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -183,20 +183,17 @@ void SearchBarLineEdit::updateCompletion()

void SearchBarLineEdit::openCompletion(const QModelIndex &index)
{
if (m_urlList.size() != 0) {
openCompletion(index.data().toString(), index.row());
}
}

void SearchBarLineEdit::openCompletion(const QString& text, int index)
{
QUrl url;
if (this->text().compare(text, Qt::CaseInsensitive) == 0) {
url = m_urlList.at(index);
} else {
url = m_urlList.last();
if (m_suggestionModel.rowCount() != 0)
{
QUrl url;
auto editText = index.data().toString();
if (this->text().compare(editText, Qt::CaseInsensitive) == 0) {
url = index.data(Qt::UserRole).toUrl();
} else {
url = m_suggestionModel.index(m_suggestionModel.rowCount() - 1).data(Qt::UserRole).toUrl();
}
QTimer::singleShot(0, [=](){KiwixApp::instance()->openUrl(url, false);});
}
QTimer::singleShot(0, [=](){KiwixApp::instance()->openUrl(url, false);});
}

SearchBar::SearchBar(QWidget *parent) :
Expand Down
2 changes: 0 additions & 2 deletions src/searchbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public slots:
private:
SuggestionListModel m_suggestionModel;
QCompleter m_completer;
QVector<QUrl> m_urlList;
QString m_title;
QString m_searchbarInput;
bool m_returnPressed = false;
Expand All @@ -49,7 +48,6 @@ public slots:
private slots:
void updateCompletion();
void openCompletion(const QModelIndex& index);
void openCompletion(const QString& text, int index);
};


Expand Down
16 changes: 15 additions & 1 deletion src/suggestionlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ int SuggestionListModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);

return m_suggestions.size();
/* From SearchBarLineEdit::updateCompletion, urlList can be set before
the display texts of the suggestions.
*/
ShaopengLin marked this conversation as resolved.
Show resolved Hide resolved
return m_urlList.size();
}

QVariant SuggestionListModel::data(const QModelIndex &index, int role) const
Expand All @@ -26,6 +29,10 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const
if (row < m_suggestions.size())
ShaopengLin marked this conversation as resolved.
Show resolved Hide resolved
return m_suggestions.at(row);
break;
case Qt::UserRole:
if (row < m_urlList.size())
return m_urlList.at(row);
break;
}
return QVariant();
}
Expand All @@ -38,3 +45,10 @@ void SuggestionListModel::resetSuggestions(const QStringList &suggestions)
m_suggestions.append(suggestion);
endResetModel();
}

void SuggestionListModel::resetUrlList(const QVector<QUrl> &urlList)
{
beginResetModel();
m_urlList = urlList;
endResetModel();
}
3 changes: 3 additions & 0 deletions src/suggestionlistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SUGGESTIONLISTMODEL_H

#include <QAbstractListModel>
#include <QUrl>

class SuggestionListModel : public QAbstractListModel
{
Expand All @@ -15,9 +16,11 @@ class SuggestionListModel : public QAbstractListModel
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

void resetSuggestions(const QStringList& suggestions = QStringList{});
void resetUrlList(const QVector<QUrl>& urlList = QVector<QUrl>{});

private:
QStringList m_suggestions;
QVector<QUrl> m_urlList;
ShaopengLin marked this conversation as resolved.
Show resolved Hide resolved
};

#endif // SUGGESTIONLISTMODEL_H