diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-15 19:17:03 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-15 20:08:30 +0530 |
| commit | 387cf24e389854ecc97f6236fdd6acbc2486dd52 (patch) | |
| tree | a51b51de0064fb10685d2da85d11748c4a32ce73 /src/completion/TabsModel.cpp | |
| parent | 05ae8976a8e1ab5411058de244c4e2fcc87ec369 (diff) | |
| download | null-browser-387cf24e389854ecc97f6236fdd6acbc2486dd52.tar.gz null-browser-387cf24e389854ecc97f6236fdd6acbc2486dd52.zip | |
Replaced QCompleter with custom implementation
Diffstat (limited to '')
| -rw-r--r-- | src/completion/TabsModel.cpp | 47 |
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 +} |
