aboutsummaryrefslogtreecommitdiff
path: root/src/completion/UrlModel.cpp
blob: 7671fc3529b01d5995aa2f0bc3dba5a192e0e8df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
}