15 #include <QScriptEngine>
37 return createIndex(row, column, wrapper->
child(row));
44 return createIndex(row, column, child);
53 if (!
item || !
item->displayParent()) {
57 if (!
parent->displayParent()) {
71 if ((Qt::DisplayRole != role && Qt::DecorationRole != role) || !
index.isValid() || !
index.internalPointer()) {
76 if (Qt::DecorationRole == role) {
79 return wrapper->displayName();
95 auto flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
96 if (
index.isValid() &&
index.internalPointer()) {
98 if (wrapper->canDrag()) {
99 flags |= Qt::ItemIsDragEnabled;
106 QMimeData *
data =
nullptr;
107 for (
auto index : indexes) {
108 if (
index.isValid() &&
index.internalPointer()) {
110 if (wrapper->canDrag()) {
112 data =
new QMimeData();
123 if (
action != Qt::CopyAction) {
136 if (
action != Qt::CopyAction) {
151 emit dataChanged(QModelIndex(), QModelIndex());
155 auto idx = createIndex(
parent->childIndex(asset), 0, asset);
158 emit dataChanged(idx, idx);
161 auto left = createIndex(0, 0, asset->
child(0));
163 emit dataChanged(left, right);
168 beginInsertRows(idx, extra, extra);
176 beginRemoveRows(idx, extra, extra);
184 emit layoutAboutToBeChanged();
188 emit layoutChanged();
209 auto index = sourceModel()->index(sourceRow, 0, sourceParent);
210 auto wrapper = qobject_cast<AssetWrapper *>(
static_cast<QObject *
>(
index.internalPointer()));
217 return cache->second;
222 auto possibleUse = wrapper->uses(
myAsset, hint);
230 for (
int c = 0;
c <
count && !uses;
c++) {
240 if (role == Qt::DisplayRole) {
241 auto sourceIndex = mapToSource(
index);
242 auto w = qobject_cast<AssetWrapper *>(
static_cast<QObject *
>(sourceIndex.internalPointer()));
245 return ret.toString() + QString(
" (") + QString::fromLocal8Bit(hint->second.c_str()) +
")";
252 : QSortFilterProxyModel(parent), myEngine(engine) {
253 setSourceModel(model);
266 auto index = sourceModel()->index(sourceRow, 0, sourceParent);
267 auto wrapper = qobject_cast<AssetWrapper *>(
static_cast<QObject *
>(
index.internalPointer()));
274 return cache->second;
290 myEngine->globalObject().setProperty(
"item", engineValue);
295 if (
myEngine->hasUncaughtException()) {