forked from nomic-ai/gpt4all
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localdocsmodel.cpp
53 lines (45 loc) · 1.34 KB
/
localdocsmodel.cpp
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
49
50
51
52
53
#include "localdocsmodel.h"
LocalDocsModel::LocalDocsModel(QObject *parent)
: QAbstractListModel(parent)
{
}
int LocalDocsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_collectionList.size();
}
QVariant LocalDocsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_collectionList.size())
return QVariant();
const CollectionItem item = m_collectionList.at(index.row());
switch (role) {
case CollectionRole:
return item.collection;
case FolderPathRole:
return item.folder_path;
case InstalledRole:
return item.installed;
}
return QVariant();
}
QHash<int, QByteArray> LocalDocsModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[CollectionRole] = "collection";
roles[FolderPathRole] = "folder_path";
roles[InstalledRole] = "installed";
return roles;
}
void LocalDocsModel::addCollectionItem(const CollectionItem &item)
{
beginInsertRows(QModelIndex(), m_collectionList.size(), m_collectionList.size());
m_collectionList.append(item);
endInsertRows();
}
void LocalDocsModel::handleCollectionListUpdated(const QList<CollectionItem> &collectionList)
{
beginResetModel();
m_collectionList = collectionList;
endResetModel();
}