SImplifying Page.js, and adding a REsourceInspector

This commit is contained in:
Sam Gateau 2019-09-24 18:10:57 -07:00
parent 2a78fc7b38
commit 0d9cd69d94
5 changed files with 100 additions and 30 deletions

View file

@ -320,11 +320,11 @@ void ResourceCache::refreshAll() {
QVariantList ResourceCache::getResourceList() { QVariantList ResourceCache::getResourceList() {
QVariantList list; QVariantList list;
if (QThread::currentThread() != thread()) { /*if (QThread::currentThread() != thread()) {
// NOTE: invokeMethod does not allow a const QObject* // NOTE: invokeMethod does not allow a const QObject*
BLOCKING_INVOKE_METHOD(this, "getResourceList", BLOCKING_INVOKE_METHOD(this, "getResourceList",
Q_RETURN_ARG(QVariantList, list)); Q_RETURN_ARG(QVariantList, list));
} else { } else {*/
QList<QUrl> resources; QList<QUrl> resources;
{ {
QReadLocker locker(&_resourcesLock); QReadLocker locker(&_resourcesLock);
@ -334,7 +334,7 @@ QVariantList ResourceCache::getResourceList() {
for (auto& resource : resources) { for (auto& resource : resources) {
list << resource; list << resource;
} }
} /* }*/
return list; return list;
} }

View file

@ -5,25 +5,20 @@ function openView() {
//window.closed.connect(function() { Script.stop(); }); //window.closed.connect(function() { Script.stop(); });
var pages = new Pages(); var pages = new Pages();
function fromQml(message) { function fromQml(message) {
console.log(JSON.stringify(message)) console.log(JSON.stringify(message))
if (message.method == "inspectResource") {
pages.open("openResourceInspector")
pages.sendTo("openResourceInspector", message)
return;
}
if (pages.open(message.method)) { if (pages.open(message.method)) {
return; return;
} }
} }
var cashWindow
function openCashWindow(window) { function openCashWindow(window) {
if (cashWindow !== undefined) {
activeWindow.fromQml.disconnect(fromQml);
}
if (window !== undefined) {
window.fromQml.connect(fromQml);
}
cashWindow = window;
var onMousePressEvent = function (e) { var onMousePressEvent = function (e) {
}; };
Controller.mousePressEvent.connect(onMousePressEvent); Controller.mousePressEvent.connect(onMousePressEvent);
@ -38,23 +33,21 @@ function openView() {
} }
function closeCashWindow() { function closeCashWindow() {
if (cashWindow !== undefined) {
activeWindow.fromQml.disconnect(fromQml);
}
cashWindow = {};
Controller.mousePressEvent.disconnect(onMousePressEvent); Controller.mousePressEvent.disconnect(onMousePressEvent);
Controller.mouseReleaseEvent.disconnect(onMouseReleaseEvent); Controller.mouseReleaseEvent.disconnect(onMouseReleaseEvent);
Controller.mouseMoveEvent.disconnect(onMouseMoveEvent); Controller.mouseMoveEvent.disconnect(onMouseMoveEvent);
pages.clear(); pages.clear();
} }
pages.addPage('Cash', 'Cash', "../cash.qml", 300, 500, openCashWindow, closeCashWindow); pages.addPage('Cash', 'Cash', "../cash.qml", 300, 500, fromQml, openCashWindow, closeCashWindow);
pages.addPage('openModelCacheInspector', 'Model Cache Inspector', "./ModelCacheInspector.qml", 300, 500); pages.addPage('openModelCacheInspector', 'Model Cache Inspector', "./ModelCacheInspector.qml", 300, 500, fromQml);
pages.addPage('openMaterialCacheInspector', 'Material Cache Inspector', "./MaterialCacheInspector.qml", 300, 500); pages.addPage('openMaterialCacheInspector', 'Material Cache Inspector', "./MaterialCacheInspector.qml", 300, 500, fromQml);
pages.addPage('openTextureCacheInspector', 'Texture Cache Inspector', "./TextureCacheInspector.qml", 300, 500); pages.addPage('openTextureCacheInspector', 'Texture Cache Inspector', "./TextureCacheInspector.qml", 300, 500, fromQml);
pages.addPage('openAnimationCacheInspector', 'Animation Cache Inspector', "./AnimationCacheInspector.qml", 300, 500); pages.addPage('openAnimationCacheInspector', 'Animation Cache Inspector', "./AnimationCacheInspector.qml", 300, 500);
pages.addPage('openSoundCacheInspector', 'Sound Cache Inspector', "./SoundCacheInspector.qml", 300, 500); pages.addPage('openSoundCacheInspector', 'Sound Cache Inspector', "./SoundCacheInspector.qml", 300, 500);
pages.addPage('openResourceInspector', 'Resource Inspector', "./ResourceInspector.qml", 300, 500);
pages.open('Cash'); pages.open('Cash');

View file

@ -10,11 +10,12 @@
"use strict"; "use strict";
(function() { (function() {
function Page(title, qmlurl, width, height, onViewCreated, onViewClosed) { function Page(title, qmlurl, width, height, onFromQml, onViewCreated, onViewClosed) {
this.title = title; this.title = title;
this.qml = qmlurl; this.qml = qmlurl;
this.width = width; this.width = width;
this.height = height; this.height = height;
this.onFromQml = onFromQml;
this.onViewCreated = onViewCreated; this.onViewCreated = onViewCreated;
this.onViewClosed = onViewClosed; this.onViewClosed = onViewClosed;
@ -30,6 +31,9 @@ Page.prototype.killView = function () {
//this.window.closed.disconnect(function () { //this.window.closed.disconnect(function () {
// this.killView(); // this.killView();
//}); //});
if (this.onFromQml) {
this.window.fromQml.disconnect(this.onFromQml)
}
this.window.close(); this.window.close();
this.window = false; this.window = false;
} }
@ -45,6 +49,9 @@ Page.prototype.createView = function () {
size: {x: this.width, y: this.height} size: {x: this.width, y: this.height}
}); });
this.onViewCreated(this.window); this.onViewCreated(this.window);
if (this.onFromQml) {
this.window.fromQml.connect(this.onFromQml)
}
this.window.closed.connect(function () { this.window.closed.connect(function () {
that.killView(); that.killView();
that.onViewClosed(); that.onViewClosed();
@ -57,7 +64,7 @@ Pages = function () {
this._pages = {}; this._pages = {};
}; };
Pages.prototype.addPage = function (command, title, qmlurl, width, height, onViewCreated, onViewClosed) { Pages.prototype.addPage = function (command, title, qmlurl, width, height, onFromQml, onViewCreated, onViewClosed) {
if (onViewCreated === undefined) { if (onViewCreated === undefined) {
// Workaround for bad linter // Workaround for bad linter
onViewCreated = function(window) {}; onViewCreated = function(window) {};
@ -66,7 +73,7 @@ Pages.prototype.addPage = function (command, title, qmlurl, width, height, onVie
// Workaround for bad linter // Workaround for bad linter
onViewClosed = function() {}; onViewClosed = function() {};
} }
this._pages[command] = new Page(title, qmlurl, width, height, onViewCreated, onViewClosed); this._pages[command] = new Page(title, qmlurl, width, height, onFromQml, onViewCreated, onViewClosed);
}; };
Pages.prototype.open = function (command) { Pages.prototype.open = function (command) {
@ -87,4 +94,12 @@ Pages.prototype.clear = function () {
this._pages = {}; this._pages = {};
}; };
Pages.prototype.sendTo = function (command, message) {
if (!this._pages[command]) {
print("Pages: unknown command = " + command);
return;
}
this._pages[command].window.sendToQml(message);
};
}()); }());

View file

@ -30,6 +30,10 @@ Item {
} }
} }
function requestResourceDetails(resourceURL) {
sendToScript({method: "inspectResource", params: {url: resourceURL, semantic: cacheResourceName}});
}
Component.onCompleted: { Component.onCompleted: {
resetItemListFromCache(); resetItemListFromCache();
} }
@ -66,7 +70,7 @@ Item {
function pullFreshValues() { function pullFreshValues() {
if (needFreshList) { if (needFreshList) {
console.log("Updating " + cacheResourceName + "cache list") //console.log("Updating " + cacheResourceName + "cache list")
updateItemList(fetchItemsList()) updateItemList(fetchItemsList())
needFreshList = false needFreshList = false
} }
@ -234,12 +238,12 @@ Item {
height: item.height height: item.height
onPressed: {held = true} onPressed: {held = true}
onReleased: {held = false} onReleased: {held = false}
onDoubleClicked: { requestResourceDetails(model.url) }
Rectangle { Rectangle {
id: item id: item
width: parent.width width: parent.width
height: global.slimHeight height: global.slimHeight
color: dragArea.held ? global.colorBackHighlight : (model.identifier % 2 ? global.colorBackShadow : global.colorBack) color: dragArea.held ? global.colorBackHighlight : (index % 2 ? global.colorBackShadow : global.colorBack)
Row { Row {
id: itemRow id: itemRow
anchors.verticalCenter : parent.verticalCenter anchors.verticalCenter : parent.verticalCenter
@ -324,7 +328,7 @@ Item {
] ]
function refreshFilter() { function refreshFilter() {
console.log("refreshFilter! token = " + textFilter + " field = " + filterField) //console.log("refreshFilter! token = " + textFilter + " field = " + filterField)
acceptItem = acceptItemArray[(textFilter.length != 0) * + (1 + filterField)] acceptItem = acceptItemArray[(textFilter.length != 0) * + (1 + filterField)]
} }

View file

@ -0,0 +1,58 @@
//
// ResourceInspector.qml
//
// Created by Sam Gateau on 2019-09-24
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import QtQml.Models 2.12
import "../../lib/prop" as Prop
Item {
id: root;
Prop.Global { id: global }
anchors.fill: parent.fill
property var cache: {}
property string cacheResourceName: ""
function fromScript(message) {
switch (message.method) {
case "inspectResource":
inspectResource(message.params.url, message.params.semantic)
break;
}
}
function inspectResource(url, semantic) {
console.log("inspectResource :" + url + " as " + semantic)
info.text = "url: " + url + "\nsemantic: " + semantic + "\n";
if (semantic == "Texture") {
var res = TextureCache.prefetch(url, 0)
info.text += JSON.stringify(res);
} else if (semantic == "Model") {
var res = ModelCache.prefetch(url)
info.text += JSON.stringify(res);
}
}
TextEdit {
id: info
anchors.fill: parent
text: "Click an object to get material JSON"
width: root.width
font.pointSize: 10
color: "#FFFFFF"
readOnly: true
selectByMouse: true
wrapMode: Text.WordWrap
}
}