Added filter for QT autogenerated functions and integrated it to Developers menu

This commit is contained in:
luiscuenca 2017-12-21 16:26:06 -07:00
parent 54297e00a8
commit 38bfddf786
3 changed files with 215 additions and 167 deletions

View file

@ -18,10 +18,7 @@ Item {
width: parent.width width: parent.width
height: parent.height height: parent.height
property var hideQtMethods: true
property bool keyboardEnabled: false
property bool keyboardRaised: false
property bool punctuationMode: false
property var maxUpdateValues: 20 property var maxUpdateValues: 20
property var maxReloadValues: 200 property var maxReloadValues: 200
@ -31,7 +28,7 @@ Item {
property var evaluatingIdx: -1 property var evaluatingIdx: -1
property Component scrollSlider property Component scrollSlider
property Component keyboard property Component keyboard
Rectangle { Rectangle {
color: "white" color: "white"
width: parent.width width: parent.width
@ -375,9 +372,6 @@ Item {
} }
} }
} }
} }
HifiControls.GlyphButton { HifiControls.GlyphButton {
@ -417,6 +411,30 @@ Item {
} }
} }
HifiControls.CheckBox {
id: hideQt
boxSize: 25
boxRadius: 3
checked: true
anchors.left: clipboard.right
anchors.leftMargin: 8
anchors.verticalCenter: clipboard.verticalCenter
anchors.margins: 2
onClicked: {
hideQtMethods = checked;
addListElements();
}
}
HifiControls.Label {
id: hideLabel
anchors.left: hideQt.right
anchors.verticalCenter: clipboard.verticalCenter
anchors.margins: 2
font.pixelSize: 15
text: "Hide Qt Methods"
}
HifiControls.Keyboard { HifiControls.Keyboard {
id: keyboard; id: keyboard;
raised: false; raised: false;
@ -425,7 +443,7 @@ Item {
left: parent.left; left: parent.left;
right: parent.right; right: parent.right;
} }
// "\ue02b"
Keys.onPressed: { Keys.onPressed: {
console.log(event.nativeScanCode); console.log(event.nativeScanCode);
if (event.key == Qt.Key_Left) { if (event.key == Qt.Key_Left) {
@ -433,8 +451,6 @@ Item {
} }
} }
} }
function addNewMember() { function addNewMember() {
apiMembers.push({member: searchBar.text, type: "user", value: valueBar.text, hasValue: true}); apiMembers.push({member: searchBar.text, type: "user", value: valueBar.text, hasValue: true});
@ -595,7 +611,17 @@ Item {
'apiType': filteredArray[i].type, 'apiType': filteredArray[i].type,
'apiValue': filteredArray[i].value}; 'apiValue': filteredArray[i].value};
memberModel.append(data); if (hideQtMethods) {
var chain = data.apiMember.split(".");
var method = chain[chain.length-1];
if (method != "destroyed" &&
method != "objectName" &&
method != "objectNameChanged") {
memberModel.append(data);
}
} else {
memberModel.append(data);
}
} }
computeMembersWithValues(); computeMembersWithValues();

View file

@ -757,6 +757,14 @@ Menu::Menu() {
// Developer > Stats // Developer > Stats
addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::Stats); addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::Stats);
// Developer > API Debugger
action = addActionToQMenuAndActionHash(developerMenu, "API Debugger");
connect(action, &QAction::triggered, [] {
auto scriptEngines = DependencyManager::get<ScriptEngines>();
QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "developer/utilities/tools/currentAPI.js");
scriptEngines->loadScript(defaultScriptsLoc.toString());
});
#if 0 /// -------------- REMOVED FOR NOW -------------- #if 0 /// -------------- REMOVED FOR NOW --------------
addDisabledActionAndSeparator(navigateMenu, "History"); addDisabledActionAndSeparator(navigateMenu, "History");

View file

@ -1,167 +1,181 @@
//
// currentAPI.js
// examples
//
// Created by Clément Brisset on 5/30/14.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function(){ (function(){
var array = []; var array = [];
var mainKeys = Object.keys(this); var mainKeys = Object.keys(this);
var qml = Script.resourcesPath() + '/qml/CurrentAPI.qml'; var qml = Script.resourcesPath() + '/qml/CurrentAPI.qml';
var needsUpdate = false; var needsUpdate = false;
var updateTime = 20; var updateTime = 20;
var updateData = []; var updateData = [];
var deltaTime = 0; var deltaTime = 0;
var maxUpdatingMethods = 20; var maxUpdatingMethods = 20;
var scriptPath = ""; var scriptPath = "";
if (ScriptDiscoveryService.debugScriptUrl != "") { if (ScriptDiscoveryService.debugScriptUrl != "") {
Script.include(ScriptDiscoveryService.debugScriptUrl); Script.include(ScriptDiscoveryService.debugScriptUrl);
} }
var window = new OverlayWindow({ var window = new OverlayWindow({
title: 'API methods', title: 'API Debugger',
source: qml, source: qml,
width: 1200, width: 1200,
height: 500 height: 500
}); });
window.closed.connect(function () { window.closed.connect(function () {
Script.stop(); Script.stop();
}); });
function addMainKeys(){ function addMainKeys(){
var keys = Object.keys(this); var keys = Object.keys(this);
for (var i = 0; i < keys.length; i++) { for (var i = 0; i < keys.length; i++) {
array.push({member:keys[i] , type: "class"}); array.push({member:keys[i] , type: "class"});
} }
} }
function memberHasValue(member, type) { function memberHasValue(member, type) {
if (type === "function()") { if (type === "function()") {
if (member.indexOf(".has") < 0 && member.indexOf(".is") < 0) { if (member.indexOf(".has") < 0 && member.indexOf(".is") < 0 && member.indexOf(".get") < 0) {
return false; return false;
} }
if (member.indexOf("indow") < 0) { if (member.indexOf("indow") < 0) {
return true; return true;
} }
} else if (type === "boolean" || type === "string" || type === "number" || type === "user") { } else if (type === "boolean" || type === "string" || type === "number" || type === "user") {
return true; return true;
} }
return false; return false;
} }
function listKeys(string, object) { function listKeys(string, object) {
if (string === "listKeys" || string === "array" || string === "buffer" || string === "i") { if (string === "listKeys" || string === "array" || string === "buffer" || string === "i") {
return; return;
} }
if (typeof(object) !== "object" || object === null) { if (typeof(object) !== "object" || object === null) {
var type = typeof(object); var type = typeof(object);
if (type === "function") { if (type === "function") {
chain = string.split("("); chain = string.split("(");
if (chain.length > 1) { if (chain.length > 1) {
string = chain[0]; string = chain[0];
type = "function(" + chain[1]; type = "function(" + chain[1];
} } else {
} type = "function()";
var value = ""; }
var hasValue = false; }
if (memberHasValue(string, type)){ var value = "";
var evalstring = type === "function()" ? string+"()" : string; var hasValue = false;
try{ if (memberHasValue(string, type)){
value = "" + eval(evalstring); var evalstring = type === "function()" ? string+"()" : string;
hasValue = true; try{
} catch(e) { value = "" + eval(evalstring);
value = "Error evaluating"; hasValue = true;
} } catch(e) {
} value = "Error evaluating";
array.push({member:string , type: type, value: value, hasValue: hasValue}); }
return; }
} array.push({member:string , type: type, value: value, hasValue: hasValue});
return;
var keys = Object.keys(object); }
for (var i = 0; i < keys.length; ++i) {
if (string === "") { var keys = Object.keys(object);
listKeys(keys[i], object[keys[i]]); for (var i = 0; i < keys.length; ++i) {
} else if (keys[i] !== "parent") { if (string === "") {
listKeys(string + "." + keys[i], object[keys[i]]); listKeys(keys[i], object[keys[i]]);
} } else if (keys[i] !== "parent") {
} listKeys(string + "." + keys[i], object[keys[i]]);
} }
}
}
function findMethods(addon, object, addkeys) { function findMethods(addon, object, addkeys) {
array = []; array = [];
var string = addkeys ? "" : addon+"."; var string = addkeys ? "" : addon+".";
listKeys(string, object); listKeys(string, object);
if (addkeys) { if (addkeys) {
addMainKeys(); addMainKeys();
} }
array.sort(function(a, b){ array.sort(function(a, b){
if(a.member < b.member) return -1; if(a.member < b.member) return -1;
if(a.member > b.member) return 1; if(a.member > b.member) return 1;
return 0; return 0;
}); });
}; };
findMethods("", this, true); findMethods("", this, true);
window.sendToQml({type:"methods", data:array}); window.sendToQml({type:"methods", data:array});
window.fromQml.connect(function(message){ window.fromQml.connect(function(message){
if (message.type == "refreshValues") { if (message.type == "refreshValues") {
updateData = message.data; updateData = message.data;
updateValues(); updateValues();
} else if (message.type == "startRefreshValues") { } else if (message.type == "startRefreshValues") {
updateData = message.data; updateData = message.data;
if (updateData.length > maxUpdatingMethods) { if (updateData.length > maxUpdatingMethods) {
updateData = message.data; updateData = message.data;
updateValues(); updateValues();
} else { } else {
needsUpdate = true; needsUpdate = true;
deltaTime = updateTime; deltaTime = updateTime;
} }
} else if (message.type == "stopRefreshValues") { } else if (message.type == "stopRefreshValues") {
needsUpdate = false; needsUpdate = false;
deltaTime = 0; deltaTime = 0;
} else if (message.type == "evaluateMember") { } else if (message.type == "evaluateMember") {
var value = "" var value = ""
try { try {
value = "" + eval(message.data.member); value = "" + eval(message.data.member);
} catch(e) { } catch(e) {
value = "Error evaluating" value = "Error evaluating"
} }
window.sendToQml({type:"evaluateMember", data:{value:value, index:message.data.index}}); window.sendToQml({type:"evaluateMember", data:{value:value, index:message.data.index}});
} else if (message.type == "selectScript") { } else if (message.type == "selectScript") {
scriptPath = Window.browse("Select script to debug", "*.js", "JS files(*.js)"); scriptPath = Window.browse("Select script to debug", "*.js", "JS files(*.js)");
if (scriptPath) { if (scriptPath) {
ScriptDiscoveryService.stopScript(Paths.defaultScripts + "/developer/utilities/tools/currentAPI.js", true); ScriptDiscoveryService.stopScript(Paths.defaultScripts + "/developer/utilities/tools/currentAPI.js", true);
} }
} }
}); });
function updateValues() { function updateValues() {
for (var i = 0; i < updateData.length; i++) { for (var i = 0; i < updateData.length; i++) {
try { try {
updateData[i].value = "" + eval(updateData[i].member); updateData[i].value = "" + eval(updateData[i].member);
} catch(e) { } catch(e) {
updateData[i].value = "Error evaluating" updateData[i].value = "Error evaluating"
} }
} }
window.sendToQml({type: "refreshValues", data: updateData}); window.sendToQml({type: "refreshValues", data: updateData});
} }
Script.update.connect(function(){ Script.update.connect(function(){
deltaTime++; deltaTime++;
if (deltaTime > updateTime) { if (deltaTime > updateTime) {
deltaTime = 0; deltaTime = 0;
if (needsUpdate) { if (needsUpdate) {
updateValues(); updateValues();
} }
} }
}); });
Script.scriptEnding.connect(function(){ Script.scriptEnding.connect(function(){
if (!scriptPath || scriptPath.length == 0) { if (!scriptPath || scriptPath.length == 0) {
ScriptDiscoveryService.debugScriptUrl = ""; ScriptDiscoveryService.debugScriptUrl = "";
} else { } else {
ScriptDiscoveryService.debugScriptUrl = scriptPath; ScriptDiscoveryService.debugScriptUrl = scriptPath;
} }
console.log("done running"); console.log("done running");
window.close(); window.close();
}); });
}()); }());