-
Notifications
You must be signed in to change notification settings - Fork 1
/
pagemodel.cpp
95 lines (72 loc) · 1.56 KB
/
pagemodel.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
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <QDebug>
#include "pagemodel.hpp"
using namespace SMSDB;
Page::Page(const QString &contents) :
m_contents(contents)
{
}
Page::~Page()
{
}
QString Page::Contents() const
{
return m_contents;
}
void Page::SetContents(const QString &contents)
{
m_contents = contents;
}
PageModel::PageModel(QObject *parent) :
QAbstractListModel(parent)
{
}
PageModel::~PageModel()
{
}
void PageModel::clear()
{
m_pages.clear();
}
QVariantMap PageModel::get(int index)
{
QVariantMap element;
if (index >= this->m_pages.size() || index < 0)
return element;
Page *item = m_pages.at(index);
element["contents"] = item->Contents();
return element;
}
void PageModel::remove(int index)
{
m_pages.removeAt(index);
}
void PageModel::set(int index, QVariantMap dict)
{
Page *item = m_pages.at(index);
item->SetContents(dict["contents"].toString());
}
void PageModel::AddPage(Page *page)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_pages << page;
endInsertRows();
}
int PageModel::rowCount(const QModelIndex &parent) const
{
(void)parent;
return m_pages.count();
}
QVariant PageModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_pages.count())
return QVariant();
const Page *page = m_pages[index.row()];
if (role == ContentsRole)
return page->Contents();
return QVariant();
}
QHash<int, QByteArray> PageModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[ContentsRole] = "contents";
return roles;
}