aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-02-07 21:54:05 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-02-07 21:54:05 +0100
commitba757f8a1e528fdf9744094f97d1a652072771f8 (patch)
tree191faaf2f0f907af8df15cd139a45a3f27b7be0d /src
parentRewrote bookmark manager to use QTreeWidget over QTreeView (diff)
downloadsmolbote-ba757f8a1e528fdf9744094f97d1a652072771f8.tar.xz
Fixed address bar auto-complete
Diffstat (limited to 'src')
-rw-r--r--src/addressbar/completer.cpp7
-rw-r--r--src/addressbar/completer.h3
-rw-r--r--src/addressbar/urllineedit.cpp11
-rw-r--r--src/addressbar/urllineedit.h7
-rw-r--r--src/mainwindow/mainwindow.cpp2
5 files changed, 13 insertions, 17 deletions
diff --git a/src/addressbar/completer.cpp b/src/addressbar/completer.cpp
index 4c95bce..5d64dd7 100644
--- a/src/addressbar/completer.cpp
+++ b/src/addressbar/completer.cpp
@@ -15,15 +15,16 @@ Completer::Completer(QWidget *parent)
setWindowFlags(Qt::ToolTip);
}
-bool Completer::updateItems(const QModelIndexList &list)
+bool Completer::updateItems(const QList<QTreeWidgetItem *> &list)
{
if(list.isEmpty())
return false;
// list is not empty
QStringList l;
- for(const QModelIndex &idx : list) {
- l.append(idx.data(Qt::EditRole).toString());
+ for(QTreeWidgetItem *item : list) {
+ if(!item->text(1).isEmpty())
+ l.append(item->text(1));
}
auto *model = new QStringListModel(l, this);
diff --git a/src/addressbar/completer.h b/src/addressbar/completer.h
index adf5d8e..ce19f07 100644
--- a/src/addressbar/completer.h
+++ b/src/addressbar/completer.h
@@ -11,6 +11,7 @@
#include <QListView>
#include <QStringListModel>
+#include <QTreeWidgetItem>
class Completer : public QListView
{
@@ -20,7 +21,7 @@ class Completer : public QListView
public:
explicit Completer(QWidget *parent = nullptr);
- bool updateItems(const QModelIndexList &list);
+ bool updateItems(const QList<QTreeWidgetItem*> &list);
bool keyPressed(QKeyEvent *event);
diff --git a/src/addressbar/urllineedit.cpp b/src/addressbar/urllineedit.cpp
index 5b8e6c6..21effb4 100644
--- a/src/addressbar/urllineedit.cpp
+++ b/src/addressbar/urllineedit.cpp
@@ -11,6 +11,7 @@
#include <QMenu>
#include <QTimer>
#include <QWidgetAction>
+#include <lib/bookmarks/bookmarksview.h>
UrlLineEdit::UrlLineEdit(QWidget *parent)
: QLineEdit(parent)
@@ -61,7 +62,7 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
});
}
-void UrlLineEdit::setCompleterModel(QAbstractItemModel *model)
+void UrlLineEdit::setCompleterModel(BookmarksView *model)
{
Q_CHECK_PTR(model);
m_bookmarksModel = model;
@@ -93,19 +94,13 @@ void UrlLineEdit::setUrl(const QUrl &url)
setText(urlText);
}
-void UrlLineEdit::showSslError(const QString &message)
-{
- m_sslLabel->setText(message);
- m_sslAction->trigger();
-}
-
void UrlLineEdit::updateCompleter(const QString &text)
{
if(m_bookmarksModel == nullptr) {
return;
}
- const QModelIndexList res = m_bookmarksModel->match(QModelIndex(), Qt::EditRole, text, 7);
+ const QList<QTreeWidgetItem*> res = m_bookmarksModel->findItems(text, Qt::MatchContains | Qt::MatchRecursive, 1);
if(!m_listView->updateItems(res)) {
m_listView->hide();
diff --git a/src/addressbar/urllineedit.h b/src/addressbar/urllineedit.h
index 4e62128..4c5ce82 100644
--- a/src/addressbar/urllineedit.h
+++ b/src/addressbar/urllineedit.h
@@ -15,7 +15,7 @@
#include <src/webengine/webview.h>
#include "completer.h"
-class QAbstractItemModel;
+class BookmarksView;
class QMenu;
class QLabel;
class UrlLineEdit : public QLineEdit
@@ -24,7 +24,7 @@ class UrlLineEdit : public QLineEdit
public:
explicit UrlLineEdit(QWidget *parent = nullptr);
- void setCompleterModel(QAbstractItemModel *model);
+ void setCompleterModel(BookmarksView *model);
signals:
void addressEntered(const QUrl &url);
@@ -33,7 +33,6 @@ signals:
public slots:
void connectWebView(WebView *view);
void setUrl(const QUrl &url);
- void showSslError(const QString &message);
void updateCompleter(const QString &text);
@@ -56,7 +55,7 @@ private:
QLabel *m_sslLabel;
// completer
- QAbstractItemModel *m_bookmarksModel = nullptr;
+ BookmarksView *m_bookmarksModel = nullptr;
Completer *m_listView;
QMetaObject::Connection urlChangedConnection;
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 00c716f..5ee0a78 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -217,7 +217,7 @@ void MainWindow::setBookmarksWidget(std::shared_ptr<BookmarksWidget> &widget)
{
Q_ASSERT(widget);
m_bookmarksWidget = widget;
- //m_addressBar->setCompleterModel(m_bookmarksWidget->model());
+ m_addressBar->setCompleterModel(m_bookmarksWidget->model());
connect(menuBar->bookmarksAction(), &QAction::triggered, this, [this]() {
addTabbedDock(Qt::RightDockWidgetArea, m_bookmarksWidget.get());
});