-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexporttexturestablemodel.cpp
More file actions
116 lines (94 loc) · 2.99 KB
/
exporttexturestablemodel.cpp
File metadata and controls
116 lines (94 loc) · 2.99 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "exporttexturestablemodel.h"
#include "project.h"
ExportTexturesTableModel::ExportTexturesTableModel(QObject *parent)
: QAbstractTableModel(parent)
{
QVectorIterator<Mesh*> meshes = Project::activeProject()->meshes();
while (meshes.hasNext()) {
Mesh* mesh = meshes.next();
_writeList.append(false);
_meshList.append(mesh);
}
}
QVariant ExportTexturesTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
QVariant headers[] = {
QVariant("Bake?"),
QVariant("Mesh Name"),
QVariant("Path")
};
return headers[section];
}
return QVariant("");
}
int ExportTexturesTableModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return _writeList.count();
}
int ExportTexturesTableModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return 3;
}
QVariant ExportTexturesTableModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::CheckStateRole && index.column() == 0) {
if (_writeList[index.row()])
return Qt::Checked;
else
return Qt::Unchecked;
}
if (role == Qt::DisplayRole || role == Qt::EditRole) {
if (index.column() == 1) {
return _meshList[index.row()]->meshName();
} else if (index.column() == 2) {
return _meshList[index.row()]->texturePath();
}
}
return QVariant();
}
bool ExportTexturesTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
return false;
if (role == Qt::CheckStateRole && index.column() == 0) {
_writeList[index.row()] = value.toBool();
emit dataChanged(index, index);
return true;
} else if (index.column() == 2) {
_meshList[index.row()]->setTexturePath(value.toString());
emit dataChanged(index, index);
return true;
}
return false;
}
Qt::ItemFlags ExportTexturesTableModel::flags(const QModelIndex &index) const
{
if (!index.isValid()) {
return QAbstractTableModel::flags(index) | Qt::ItemIsEnabled;
}
if (index.column() == 0) {
return QAbstractTableModel::flags(index) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
} else if (index.column() == 1) {
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsEnabled;
} else if (index.column() == 2) {
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsEnabled;;
}
return QAbstractTableModel::flags(index) | Qt::ItemIsEnabled;
}
bool ExportTexturesTableModel::exportTexture(const int meshIndex)
{
return _writeList[meshIndex];
}
Mesh* ExportTexturesTableModel::mesh(const int meshIndex)
{
return _meshList[meshIndex];
}