15 #include <QScriptEngine>
37 return createIndex(row, column, wrapper->
child(row));
44 return createIndex(row, column, child);
53 if (!item || !item->displayParent()) {
56 auto parent = item->displayParent();
57 if (!
parent->displayParent()) {
71 if (!
index.isValid() || !
index.internalPointer()) {
75 if (Qt::DisplayRole != role && Qt::DecorationRole != role && Qt::ToolTipRole != role) {
80 if (Qt::DecorationRole == role) {
83 if (Qt::ToolTipRole == role) {
84 return wrapper->tooltip();
86 return wrapper->displayName();
102 auto flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
103 if (
index.isValid() &&
index.internalPointer()) {
105 if (wrapper->canDrag()) {
106 flags |= Qt::ItemIsDragEnabled;
113 QMimeData *
data =
nullptr;
114 for (
auto index : indexes) {
115 if (
index.isValid() &&
index.internalPointer()) {
117 if (wrapper->canDrag()) {
119 data =
new QMimeData();
130 if (action != Qt::CopyAction) {
143 if (action != Qt::CopyAction) {
158 emit dataChanged(QModelIndex(), QModelIndex());
162 auto idx = createIndex(
parent->childIndex(asset), 0, asset);
165 emit dataChanged(idx, idx);
168 auto left = createIndex(0, 0, asset->
child(0));
169 auto right = createIndex(count, 0, asset->
child(count));
170 emit dataChanged(left, right);
175 beginInsertRows(idx, extra, extra);
183 beginRemoveRows(idx, extra, extra);
191 emit layoutAboutToBeChanged();
195 emit layoutChanged();
216 auto index = sourceModel()->index(sourceRow, 0, sourceParent);
217 auto wrapper = qobject_cast<AssetWrapper *>(
static_cast<QObject *
>(index.internalPointer()));
224 return cache->second;
229 auto possibleUse = wrapper->uses(
myAsset, hint);
236 int count = sourceModel()->rowCount(index);
237 for (
int c = 0; c < count && !uses; c++) {
246 QVariant ret = QSortFilterProxyModel::data(index, role);
247 if (role == Qt::DisplayRole) {
248 auto sourceIndex = mapToSource(index);
249 auto w = qobject_cast<AssetWrapper *>(
static_cast<QObject *
>(sourceIndex.internalPointer()));
252 return ret.toString() + QString(
" (") + QString::fromLocal8Bit(hint->second.c_str()) +
")";
259 : QSortFilterProxyModel(parent), myEngine(engine) {
260 setSourceModel(model);
273 auto index = sourceModel()->index(sourceRow, 0, sourceParent);
274 auto wrapper = qobject_cast<AssetWrapper *>(
static_cast<QObject *
>(index.internalPointer()));
281 return cache->second;
286 int count = sourceModel()->rowCount(index);
287 for (
int c = 0; c < count && !accept; c++) {
296 QScriptValue engineValue =
myEngine->newQObject(item);
297 myEngine->globalObject().setProperty(
"item", engineValue);
302 if (
myEngine->hasUncaughtException()) {