-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilelistmodel.cpp
102 lines (84 loc) · 2.2 KB
/
filelistmodel.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
95
96
97
98
99
100
101
102
#include "filelistmodel.h"
FileListModel::FileListModel(QObject* parent,
const FileList* list) : QAbstractTableModel(parent)
, m_parent(parent)
, m_list(list)
{
}
int FileListModel::rowCount(const QModelIndex &parent) const
{
(void)parent;
int rows = m_list->count();
return rows;
}
int FileListModel::columnCount(const QModelIndex &parent) const
{
(void)parent;
return 2;
}
QVariant FileListModel::data(const QModelIndex &index, int role) const
{
int rowidx = index.row();
int columnidx = index.column();
if (role == Qt::DisplayRole && rowidx < m_list->count()) {
switch (columnidx) {
case 0:
return m_list->at(rowidx).getNameOld();
case 1:
return m_list->at(rowidx).getNameNew();
default:
break;
}
}
return QVariant();
}
QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Orientation::Horizontal) return QVariant();
switch (role) {
case Qt::DisplayRole:
switch (section) {
case 0:
return QString("alter Name");
case 1:
return QString("neuer Name");
default:
return QString("%1").arg(section);
}
break;
default:
break;
}
return QVariant();
}
void FileListModel::beginInsertFiles(int numberOfFiles)
{
beginInsertRows(QModelIndex(), m_list->count(), m_list->count() + numberOfFiles - 1);
}
void FileListModel::endInsertFiles()
{
endInsertRows();
}
void FileListModel::beginRemoveFiles()
{
beginRemoveRows(QModelIndex(), 0, m_list->count() - 1);
}
void FileListModel::endRemoveFiles()
{
endRemoveRows();
}
void FileListModel::fileListChanged()
{
QModelIndex topleft = createIndex(0, 0);
int rows = m_list->count();
QModelIndex bottomright = createIndex(rows-1, 2-1);
emit dataChanged(topleft, bottomright);
}
QString FileListModel::folder() const
{
return m_folder;
}
void FileListModel::setFolder(const QString &folder)
{
m_folder = folder;
}