History

Setup script model status

Atlante45 committed 9 years ago

Commit 28c9aa01 parent 859ec576 files · +45 −20Browse files

Showing the changes to interface/src/scripting/AssetMappingsScriptingInterface.cpp (1 of 6 files). Show all

Unified · Split

interface/src/scripting/AssetMappingsScriptingInterface.cpp+31−16
@@ -21,19 +21,6 @@ · 20 unmodified lines
21#include <NetworkLogging.h>21#include <NetworkLogging.h>
22#include <OffscreenUi.h>22#include <OffscreenUi.h>
23 23
24void AssetMappingModel::clear() {
25 // make sure we are on the same thread before we touch the hash
26 if (thread() != QThread::currentThread()) {
27 QMetaObject::invokeMethod(this, "clear");
28 return;
29 }
30
31 qDebug() << "Clearing loaded asset mappings for Asset Browser";
32
33 _pathToItemMap.clear();
34 QStandardItemModel::clear();
35}
36
37AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() {24AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() {
38 _proxyModel.setSourceModel(&_assetMappingModel);25 _proxyModel.setSourceModel(&_assetMappingModel);
39 _proxyModel.setSortRole(Qt::DisplayRole);26 _proxyModel.setSortRole(Qt::DisplayRole);
@@ -154,7 +141,7 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) { · 114 unmodified lines
154 auto map = callback.engine()->newObject();141 auto map = callback.engine()->newObject();
155 142
156 for (auto& kv : mappings ) {143 for (auto& kv : mappings ) {
157 map.setProperty(kv.first, kv.second);144 map.setProperty(kv.first, kv.second.hash);
158 }145 }
159 146
160 if (callback.isCallable()) {147 if (callback.isCallable()) {
@@ -184,6 +171,10 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new · 23 unmodified lines
184 request->start();171 request->start();
185}172}
186 173
174AssetMappingModel::AssetMappingModel() {
175 setupHeaders();
176}
177
187bool AssetMappingModel::isKnownFolder(QString path) const {178bool AssetMappingModel::isKnownFolder(QString path) const {
188 if (!path.endsWith("/")) {179 if (!path.endsWith("/")) {
189 return false;180 return false;
@@ -228,17 +219,19 @@ void AssetMappingModel::refresh() { · 38 unmodified lines
228 if (it == _pathToItemMap.end()) {219 if (it == _pathToItemMap.end()) {
229 auto item = new QStandardItem(parts[i]);220 auto item = new QStandardItem(parts[i]);
230 bool isFolder = i < length - 1;221 bool isFolder = i < length - 1;
222 auto statusString = isFolder ? "--" : bakingStatusToString(mapping.second.status);
231 item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole);223 item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole);
232 item->setData(isFolder, Qt::UserRole + 1);224 item->setData(isFolder, Qt::UserRole + 1);
233 item->setData(parts[i], Qt::UserRole + 2);225 item->setData(parts[i], Qt::UserRole + 2);
234 item->setData("atp:" + fullPath, Qt::UserRole + 3);226 item->setData("atp:" + fullPath, Qt::UserRole + 3);
235 item->setData(fullPath, Qt::UserRole + 4);227 item->setData(fullPath, Qt::UserRole + 4);
228 item->setData(statusString, Qt::UserRole + 5);
229
236 if (lastItem) {230 if (lastItem) {
237 lastItem->setChild(lastItem->rowCount(), 0, item);231 lastItem->appendRow(item);
238 } else {232 } else {
239 appendRow(item);233 appendRow(item);
240 }234 }
241
242 lastItem = item;235 lastItem = item;
243 _pathToItemMap[fullPath] = lastItem;236 _pathToItemMap[fullPath] = lastItem;
244 } else {237 } else {
@@ -300,3 +293,25 @@ void AssetMappingModel::refresh() { · 55 unmodified lines
300 293
301 request->start();294 request->start();
302}295}
296
297void AssetMappingModel::clear() {
298 // make sure we are on the same thread before we touch the hash
299 if (thread() != QThread::currentThread()) {
300 QMetaObject::invokeMethod(this, "clear");
301 return;
302 }
303
304 qDebug() << "Clearing loaded asset mappings for Asset Browser";
305
306 _pathToItemMap.clear();
307 QStandardItemModel::clear();
308 setupHeaders(); // restore headers
309}
310
311void AssetMappingModel::setupHeaders() {
312 setHorizontalHeaderLabels(QStringList() << "Name" << "Use Baked?");
313 QHash<int, QByteArray> roleNames;
314 roleNames[Qt::DisplayRole] = "name";
315 roleNames[Qt::UserRole + 5] = "baked";
316 setItemRoleNames(roleNames);
317}