1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

LocationCompleter: Remove all originalText handling

Instead move the original text (original text from locationbar)
directly into model item.
This commit is contained in:
David Rosca 2018-03-16 20:45:31 +01:00
parent 6d26d67db4
commit 49c028740e
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
6 changed files with 29 additions and 42 deletions

View File

@ -99,25 +99,29 @@ void LocationCompleter::complete(const QString &string)
m_oldSuggestions.clear();
}
// Add search/visit item
if (!trimmedStr.isEmpty()) {
// Add/update search/visit item
QTimer::singleShot(0, this, [=]() {
const QModelIndex index = s_model->index(0, 0);
if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
s_model->setData(index, trimmedStr, Qt::DisplayRole);
s_model->setData(index, trimmedStr, LocationCompleterModel::UrlRole);
s_model->setData(index, m_locationBar->text(), LocationCompleterModel::SearchStringRole);
} else {
QStandardItem *item = new QStandardItem();
item->setText(trimmedStr);
item->setData(trimmedStr, LocationCompleterModel::UrlRole);
item->setData(trimmedStr, LocationCompleterModel::SearchStringRole);
item->setData(m_locationBar->text(), LocationCompleterModel::SearchStringRole);
item->setData(true, LocationCompleterModel::VisitSearchItemRole);
s_model->setCompletions({item});
addSuggestions(m_oldSuggestions);
}
showPopup();
if (!s_view->currentIndex().isValid()) {
m_ignoreCurrentChanged = true;
s_view->setCurrentIndex(s_model->index(0, 0));
m_ignoreCurrentChanged = false;
}
}
m_originalText = m_locationBar->text();
s_view->setOriginalText(m_originalText);
});
}
void LocationCompleter::showMostVisited()
@ -149,6 +153,8 @@ void LocationCompleter::refreshJobFinished()
if (qzSettings->useInlineCompletion) {
emit showDomainCompletion(job->domainCompletion());
}
s_model->setData(s_model->index(0, 0), m_locationBar->text(), LocationCompleterModel::SearchStringRole);
}
job->deleteLater();
@ -211,14 +217,16 @@ void LocationCompleter::currentChanged(const QModelIndex &index)
bool completeDomain = index.data(LocationCompleterModel::VisitSearchItemRole).toBool();
const QString originalText = s_model->index(0, 0).data(LocationCompleterModel::SearchStringRole).toString();
// Domain completion was dismissed
if (completeDomain && completion == m_originalText) {
if (completeDomain && completion == originalText) {
completeDomain = false;
}
if (completion.isEmpty()) {
completeDomain = true;
completion = m_originalText;
completion = originalText;
}
emit showCompletion(completion, completeDomain);
@ -272,7 +280,7 @@ void LocationCompleter::indexShiftActivated(const QModelIndex &index)
// Load request
if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
loadRequest(LoadRequest(QUrl(m_originalText)));
loadRequest(LoadRequest(index.data(LocationCompleterModel::SearchStringRole).toUrl()));
} else {
loadRequest(createLoadRequest(index));
}
@ -314,7 +322,7 @@ LoadRequest LocationCompleter::createLoadRequest(const QModelIndex &index)
const QString text = index.data(LocationCompleterModel::TitleRole).toString();
request = mApp->searchEnginesManager()->searchResult(LocationBar::searchEngine(), text);
} else if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
const auto action = LocationBar::loadAction(m_originalText);
const auto action = LocationBar::loadAction(index.data(LocationCompleterModel::SearchStringRole).toString());
switch (action.type) {
case LocationBar::LoadAction::Url:
case LocationBar::LoadAction::Search:
@ -413,11 +421,6 @@ void LocationCompleter::showPopup()
void LocationCompleter::adjustPopupSize()
{
if (s_view->currentIndex().row() == 0) {
m_originalText = m_locationBar->text();
s_view->setOriginalText(m_originalText);
}
s_view->adjustSize();
s_view->show();
}

View File

@ -79,7 +79,6 @@ private:
BrowserWindow* m_window;
LocationBar* m_locationBar;
qint64 m_lastRefreshTimestamp;
QString m_originalText;
bool m_popupClosed;
bool m_ignoreCurrentChanged = false;
OpenSearchEngine* m_openSearchEngine = nullptr;

View File

@ -84,7 +84,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
BookmarkItem *bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
if (isVisitSearchItem) {
loadAction = LocationBar::loadAction(m_originalText);
loadAction = LocationBar::loadAction(index.data(LocationCompleterModel::SearchStringRole).toString());
isWebSearch = loadAction.type == LocationBar::LoadAction::Search;
if (!m_forceVisitItem) {
bookmark = loadAction.bookmark;
@ -132,7 +132,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
if (bookmark) {
title = bookmark->title();
} else {
title = m_originalText.trimmed();
title = index.data(LocationCompleterModel::SearchStringRole).toString();
searchText.clear();
}
}
@ -232,11 +232,6 @@ void LocationCompleterDelegate::setForceVisitItem(bool enable)
m_forceVisitItem = enable;
}
void LocationCompleterDelegate::setOriginalText(const QString &originalText)
{
m_originalText = originalText;
}
static bool sizeBiggerThan(const QString &s1, const QString &s2)
{
return s1.size() > s2.size();

View File

@ -31,7 +31,6 @@ public:
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setForceVisitItem(bool enable);
void setOriginalText(const QString &originalText);
private:
int viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect,
@ -41,7 +40,6 @@ private:
mutable int m_rowHeight;
mutable int m_padding;
bool m_forceVisitItem = false;
QString m_originalText;
};
#endif // LOCATIONCOMPLETERDELEGATE_H

View File

@ -114,12 +114,6 @@ QItemSelectionModel *LocationCompleterView::selectionModel() const
return m_view->selectionModel();
}
void LocationCompleterView::setOriginalText(const QString &originalText)
{
m_originalText = originalText;
m_delegate->setOriginalText(originalText);
}
void LocationCompleterView::adjustSize()
{
const int maxItemsCount = 12;
@ -395,7 +389,8 @@ void LocationCompleterView::setupSearchEngines()
button->setAutoRaise(true);
button->setIconSize(QSize(16, 16));
connect(button, &ToolButton::clicked, this, [=]() {
emit loadRequested(mApp->searchEnginesManager()->searchResult(engine, m_originalText));
const QString text = model()->index(0, 0).data(LocationCompleterModel::SearchStringRole).toString();
emit loadRequested(mApp->searchEnginesManager()->searchResult(engine, text));
});
m_searchEnginesLayout->addWidget(button);
}

View File

@ -42,8 +42,6 @@ public:
QModelIndex currentIndex() const;
void setCurrentIndex(const QModelIndex &index);
void setOriginalText(const QString &originalText);
void adjustSize();
bool eventFilter(QObject* object, QEvent* event);
@ -68,7 +66,6 @@ private:
QListView *m_view;
LocationCompleterDelegate *m_delegate;
QHBoxLayout *m_searchEnginesLayout;
QString m_originalText;
int m_resizeHeight = -1;
QTimer *m_resizeTimer = nullptr;
bool m_forceResize = true;