-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidationClassBoxesListModel.cpp
59 lines (52 loc) · 1.7 KB
/
ValidationClassBoxesListModel.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
#include "ValidationClassBoxesListModel.h"
#include "Utils.h"
#include <QPixmap>
#include <QFileInfo>
ValidationClassBoxesListModel::ValidationClassBoxesListModel(QObject *parent, QList<ClassBoxes>* classBoxes)
: QAbstractListModel{parent}
, classBoxesListPtr{classBoxes}
{
}
int ValidationClassBoxesListModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent)
return classBoxesListPtr->count();
}
QVariant ValidationClassBoxesListModel::data(const QModelIndex &index, int role) const
{
if ((index.row() < 0) || (index.row() > classBoxesListPtr->count()))
{
return QVariant();
}
switch(role)
{
case Qt::DisplayRole:
return QFileInfo(classBoxesListPtr->at(index.row()).filePath).fileName();
case Qt::DecorationRole:
return classBoxesListPtr->at(index.row()).pixMap;
case Qt::UserRole + 1:
return reinterpret_cast<quint64>(&classBoxesListPtr->at(index.row()));
default:
return {};
}
}
bool ValidationClassBoxesListModel::insertRows(int row, int count, const QModelIndex &parent)
{
beginInsertRows(parent, row, row + count - 1);
while(count--)
{
auto intAsPtrToClassObject = reinterpret_cast<ClassBoxes*>(parent.model()->data(parent, Qt::UserRole + 1).toLongLong());
classBoxesListPtr->insert(classBoxesListPtr->count(), *intAsPtrToClassObject);
}
endInsertRows();
return true;
}
bool ValidationClassBoxesListModel::removeRows(int row, int count, const QModelIndex &parent)
{
beginRemoveRows(parent, row, row + count - 1);
for(auto current = row + count - 1; current >= row; --current)
{
classBoxesListPtr->removeAt(current);
}
endRemoveRows();
return true;
}