aboutsummaryrefslogtreecommitdiff
path: root/src/completion/TabsModel.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-15 19:17:03 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-15 20:08:30 +0530
commit387cf24e389854ecc97f6236fdd6acbc2486dd52 (patch)
treea51b51de0064fb10685d2da85d11748c4a32ce73 /src/completion/TabsModel.cpp
parent05ae8976a8e1ab5411058de244c4e2fcc87ec369 (diff)
downloadnull-browser-387cf24e389854ecc97f6236fdd6acbc2486dd52.tar.gz
null-browser-387cf24e389854ecc97f6236fdd6acbc2486dd52.zip
Replaced QCompleter with custom implementation
Diffstat (limited to '')
-rw-r--r--src/completion/TabsModel.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/completion/TabsModel.cpp b/src/completion/TabsModel.cpp
new file mode 100644
index 0000000..37eb1dd
--- /dev/null
+++ b/src/completion/TabsModel.cpp
@@ -0,0 +1,47 @@
+#include <QAbstractListModel>
+#include <QWidget>
+#include <QtCore>
+
+#include "completion/TabsModel.hpp"
+
+TabsModel::TabsModel(QObject *parent) : QAbstractListModel(parent) {
+ items = {
+ {.url = "https://ediblemonad.dev", .title = "EdibleMonad website"},
+ {.url = "https://lite.duckduckgo.com", .title = "DDG lite"},
+ {.url = "https://github.com/trending", .title = "Github trending"},
+ };
+}
+
+QVariant TabsModel::data(const QModelIndex &index, int role) const {
+ if (!index.isValid() || index.row() >= items.size())
+ return QVariant();
+
+ const Buffer &item = items.at(index.row());
+
+ if (role == Qt::DisplayRole)
+ return index.row();
+ else if (role == Qt::UserRole)
+ return item.title;
+ else if (role == Qt::AccessibleDescriptionRole)
+ return item.url + item.title;
+
+ return QVariant();
+}
+
+QHash<int, QByteArray> TabsModel::roleNames() const {
+ QHash<int, QByteArray> roles;
+ roles[Qt::DisplayRole] = "url";
+ roles[Qt::UserRole] = "title";
+ roles[Qt::AccessibleDescriptionRole] = "full";
+ return roles;
+}
+
+int TabsModel::rowCount(const QModelIndex &parent) const {
+ Q_UNUSED(parent);
+ return items.size();
+}
+
+int TabsModel::columnCount(const QModelIndex &parent) const {
+ Q_UNUSED(parent);
+ return 2; // url + title
+}