This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
forked from pinkierton/harkach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoardModel.cpp
81 lines (69 loc) · 2.29 KB
/
BoardModel.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "BoardModel.h"
#include <QDebug>
BoardModel::BoardModel(QObject *parent) : QAbstractListModel(parent)
{
}
BoardModel::~BoardModel() {
qDeleteAll(mBoards);
mBoards.clear();
}
QHash<int, QByteArray> BoardModel::roleNames() const {
return {
{ IdRole, "board_id" },
{ NameRole, "name" },
{ CategoryRole, "category" },
{ DefaultNameRole, "default_name" },
{ BumpLimitRole, "bump_limit" },
{ PagesRole, "pages" },
{ EnableLikesRole, "enable_likes" },
{ EnablePostingRole, "enable_posting" },
{ EnableThreadTagsRole, "enable_thread_tags"},
{ SageRole, "sage" },
{ TripcodesRole, "tripcodes" }
};
}
int BoardModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent)
return mBoards.count();
}
QVariant BoardModel::data(const QModelIndex &index, int role) const {
if (index.row() < 0 || index.row() >= rowCount())
return QVariant();
using BoardPtr = Board*;
const BoardPtr &board = mBoards.at(index.row());
if (role == IdRole)
return board->id();
else if (role == NameRole)
return board->name();
else if (role == CategoryRole)
return board->category();
else if (role == DefaultNameRole)
return board->defaultName();
else if (role == BumpLimitRole)
return board->bumpLimit();
else if (role == PagesRole)
return board->pages();
else if (role == EnableLikesRole)
return board->enableLikes();
else if (role == EnablePostingRole)
return board->enablePosting();
else if (role == EnableThreadTagsRole)
return board->enableThreadTags();
else if (role == SageRole)
return board->sage();
else if (role == TripcodesRole)
return board->tripcodes();
return QVariant();
}
void BoardModel::setBoards(QList<Board *> &&boards) {
if (!mBoards.empty()) {
qDeleteAll(mBoards);
mBoards.clear();
}
mBoards = boards;
beginInsertRows(QModelIndex(), 0, 0+rowCount()-1);
endInsertRows();
}
const QList<Board *> &BoardModel::getBoards() const noexcept {
return mBoards;
}