aboutsummaryrefslogtreecommitdiff
path: root/src/lib/navigation
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/navigation')
-rw-r--r--src/lib/navigation/navigation.qbs2
-rw-r--r--src/lib/navigation/urlcompleter.cpp26
-rw-r--r--src/lib/navigation/urlcompleter.h25
-rw-r--r--src/lib/navigation/urllineedit.cpp5
-rw-r--r--src/lib/navigation/urllineedit.h4
5 files changed, 57 insertions, 5 deletions
diff --git a/src/lib/navigation/navigation.qbs b/src/lib/navigation/navigation.qbs
index a58f86d..7719fbc 100644
--- a/src/lib/navigation/navigation.qbs
+++ b/src/lib/navigation/navigation.qbs
@@ -17,6 +17,8 @@ Project {
files: [
"navigationbutton.cpp",
"navigationbutton.h",
+ "urlcompleter.cpp",
+ "urlcompleter.h",
"urllineedit.cpp",
"urllineedit.h",
]
diff --git a/src/lib/navigation/urlcompleter.cpp b/src/lib/navigation/urlcompleter.cpp
new file mode 100644
index 0000000..bbde297
--- /dev/null
+++ b/src/lib/navigation/urlcompleter.cpp
@@ -0,0 +1,26 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "urlcompleter.h"
+
+UrlCompleter::UrlCompleter(QAbstractItemModel *model, QObject *parent) :
+ QCompleter(model, parent)
+{
+ setCompletionMode(QCompleter::PopupCompletion);
+ setFilterMode(Qt::MatchContains);
+}
+
+QStringList UrlCompleter::splitPath(const QString &path) const
+{
+ return path.split('.');
+}
+
+QString UrlCompleter::pathFromIndex(const QModelIndex &index) const
+{
+ return model()->data(index, completionRole()).toString();
+}
diff --git a/src/lib/navigation/urlcompleter.h b/src/lib/navigation/urlcompleter.h
new file mode 100644
index 0000000..f2c52ff
--- /dev/null
+++ b/src/lib/navigation/urlcompleter.h
@@ -0,0 +1,25 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef URLCOMPLETER_H
+#define URLCOMPLETER_H
+
+#include <QCompleter>
+
+class UrlCompleter : public QCompleter
+{
+ Q_OBJECT
+public:
+ explicit UrlCompleter(QAbstractItemModel *model, QObject *parent = nullptr);
+
+protected:
+ QStringList splitPath(const QString &path) const override;
+ QString pathFromIndex(const QModelIndex &index) const override;
+};
+
+#endif // URLCOMPLETER_H
diff --git a/src/lib/navigation/urllineedit.cpp b/src/lib/navigation/urllineedit.cpp
index c9f11c6..4dc6b39 100644
--- a/src/lib/navigation/urllineedit.cpp
+++ b/src/lib/navigation/urllineedit.cpp
@@ -83,11 +83,8 @@ QAction *UrlLineEdit::pageAction()
void UrlLineEdit::setCompleterModel(QAbstractItemModel *model)
{
Q_CHECK_PTR(model);
- QCompleter *m_completer = new QCompleter(this);
- m_completer->setCompletionMode(QCompleter::PopupCompletion);
- m_completer->setModel(model);
+ m_completer = new UrlCompleter(model, this);
m_completer->setCompletionColumn(1);
-
this->setCompleter(m_completer);
}
diff --git a/src/lib/navigation/urllineedit.h b/src/lib/navigation/urllineedit.h
index 9dd73ab..46366a7 100644
--- a/src/lib/navigation/urllineedit.h
+++ b/src/lib/navigation/urllineedit.h
@@ -13,6 +13,8 @@
#include <QTextLayout>
#include <QAction>
+#include "urlcompleter.h"
+
class QAbstractItemModel;
class QMenu;
class QLabel;
@@ -51,7 +53,7 @@ private:
QMenu *m_sslMenu;
QLabel *m_sslLabel;
- QCompleter *m_completer;
+ UrlCompleter *m_completer;
};
#endif // URLLINEEDIT_H