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
2121 #include <NetworkLogging.h>
2222 #include <OffscreenUi.h>
2323
24−void 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−
3724 AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() {
3825 _proxyModel.setSourceModel(&_assetMappingModel);
3926 _proxyModel.setSortRole(Qt::DisplayRole);
@@ -154,7 +141,7 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) { · 114 unmodified lines
154141 auto map = callback.engine()->newObject();
155142
156143 for (auto& kv : mappings ) {
157− map.setProperty(kv.first, kv.second);
144+ map.setProperty(kv.first, kv.second.hash);
158145 }
159146
160147 if (callback.isCallable()) {
@@ -184,6 +171,10 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new · 23 unmodified lines
184171 request->start();
185172 }
186173
174+AssetMappingModel::AssetMappingModel() {
175+ setupHeaders();
176+}
177+
187178 bool AssetMappingModel::isKnownFolder(QString path) const {
188179 if (!path.endsWith("/")) {
189180 return false;
@@ -228,17 +219,19 @@ void AssetMappingModel::refresh() { · 38 unmodified lines
228219 if (it == _pathToItemMap.end()) {
229220 auto item = new QStandardItem(parts[i]);
230221 bool isFolder = i < length - 1;
222+ auto statusString = isFolder ? "--" : bakingStatusToString(mapping.second.status);
231223 item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole);
232224 item->setData(isFolder, Qt::UserRole + 1);
233225 item->setData(parts[i], Qt::UserRole + 2);
234226 item->setData("atp:" + fullPath, Qt::UserRole + 3);
235227 item->setData(fullPath, Qt::UserRole + 4);
228+ item->setData(statusString, Qt::UserRole + 5);
229+
236230 if (lastItem) {
237− lastItem->setChild(lastItem->rowCount(), 0, item);
231+ lastItem->appendRow(item);
238232 } else {
239233 appendRow(item);
240234 }
241−
242235 lastItem = item;
243236 _pathToItemMap[fullPath] = lastItem;
244237 } else {
@@ -300,3 +293,25 @@ void AssetMappingModel::refresh() { · 55 unmodified lines
300293
301294 request->start();
302295 }
296+
297+void 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+
311+void 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+}