forked from abranson/rockpool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshotmodel.cpp
71 lines (61 loc) · 1.47 KB
/
screenshotmodel.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
#include "screenshotmodel.h"
#include <QDebug>
ScreenshotModel::ScreenshotModel(QObject *parent):
QAbstractListModel(parent)
{
}
int ScreenshotModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_files.count();
}
QVariant ScreenshotModel::data(const QModelIndex &index, int role) const
{
switch (role) {
case RoleFileName:
return m_files.at(index.row());
}
return QVariant();
}
QHash<int, QByteArray> ScreenshotModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles.insert(RoleFileName, "filename");
return roles;
}
QString ScreenshotModel::get(int index) const
{
if (index >= 0 && index < m_files.count()) {
return m_files.at(index);
}
return QString();
}
QString ScreenshotModel::latestScreenshot() const
{
return get(0);
}
void ScreenshotModel::clear()
{
beginResetModel();
m_files.clear();
endResetModel();
}
void ScreenshotModel::insert(const QString &filename)
{
qDebug() << "should insert filename" << filename;
if (!m_files.contains(filename)) {
beginInsertRows(QModelIndex(), 0, 0);
m_files.prepend(filename);
endInsertRows();
emit latestScreenshotChanged();
}
}
void ScreenshotModel::remove(const QString &filename)
{
if (m_files.contains(filename)) {
int idx = m_files.indexOf(filename);
beginRemoveRows(QModelIndex(), idx, idx);
m_files.removeOne(filename);
endRemoveRows();
}
}