aboutsummaryrefslogtreecommitdiff
path: root/src/completion/UrlModel.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-11 11:31:14 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-11 11:44:31 +0530
commit12d0ce37db7323e8efd56d6a698a98abcb8d680b (patch)
treeec2102d40326a332b2ecb976869585f81cba8574 /src/completion/UrlModel.cpp
parent971854bfefad4c644ac3d5f5d6003f24d551bf1d (diff)
downloadnull-browser-12d0ce37db7323e8efd56d6a698a98abcb8d680b.tar.gz
null-browser-12d0ce37db7323e8efd56d6a698a98abcb8d680b.zip
Add command+url adapter and switching
Diffstat (limited to '')
-rw-r--r--src/completion/UrlModel.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/completion/UrlModel.cpp b/src/completion/UrlModel.cpp
new file mode 100644
index 0000000..7671fc3
--- /dev/null
+++ b/src/completion/UrlModel.cpp
@@ -0,0 +1,48 @@
+#include <QAbstractListModel>
+#include <QWidget>
+#include <QtCore>
+
+#include "completion/UrlModel.hpp"
+
+UrlModel::UrlModel(QObject *parent) : QAbstractListModel(parent) {
+ items = {
+ {.url = "https://google.com", .description = "Google"},
+ {.url = "https://duckduckgo.com", .description = "DuckDuckGo"},
+ {.url = "https://ediblemonad.dev", .description = "EdibleMonad website"},
+ {.url = "https://lite.duckduckgo.com", .description = "DDG lite"},
+ {.url = "https://github.com/trending", .description = "Github trending"},
+ };
+}
+
+QVariant UrlModel::data(const QModelIndex &index, int role) const {
+ if (!index.isValid() || index.row() >= items.size())
+ return QVariant();
+
+ const Url &item = items.at(index.row());
+
+ if (role == Qt::DisplayRole)
+ return item.url;
+ else if (role == Qt::ToolTipRole)
+ return item.description;
+ else if (role == Qt::UserRole)
+ return item.description;
+
+ return QVariant();
+}
+
+QHash<int, QByteArray> UrlModel::roleNames() const {
+ QHash<int, QByteArray> roles;
+ roles[Qt::DisplayRole] = "url";
+ roles[Qt::UserRole] = "description";
+ return roles;
+}
+
+int UrlModel::rowCount(const QModelIndex &parent) const {
+ Q_UNUSED(parent);
+ return items.size();
+}
+
+int UrlModel::columnCount(const QModelIndex &parent) const {
+ Q_UNUSED(parent);
+ return 2; // name + description
+}