From cfb820762d1e670d2b3ff17cd112f41926691213 Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Wed, 22 Aug 2018 00:42:01 +0300 Subject: [PATCH] bulk adjusting to coding guidelines --- interface/resources/qml/hifi/AvatarApp.qml | 54 +++++++------- .../qml/hifi/avatarapp/AdjustWearables.qml | 50 ++++++------- .../qml/hifi/avatarapp/AvatarsModel.qml | 74 ++++++++++--------- .../hifi/avatarapp/CreateFavoriteDialog.qml | 8 +- .../qml/hifi/avatarapp/DialogButtons.qml | 2 +- .../qml/hifi/avatarapp/MessageBox.qml | 6 +- .../qml/hifi/avatarapp/MessageBoxes.qml | 27 ++++--- .../resources/qml/hifi/avatarapp/Settings.qml | 6 +- .../qml/hifi/avatarapp/TransparencyMask.qml | 2 +- 9 files changed, 123 insertions(+), 106 deletions(-) diff --git a/interface/resources/qml/hifi/AvatarApp.qml b/interface/resources/qml/hifi/AvatarApp.qml index 217525498d..d8eae311d8 100644 --- a/interface/resources/qml/hifi/AvatarApp.qml +++ b/interface/resources/qml/hifi/AvatarApp.qml @@ -57,7 +57,7 @@ Rectangle { try { var marketResponse = JSON.parse(xmlhttp.responseText.trim()) - if(marketResponse.status === 'success') { + if (marketResponse.status === 'success') { avatar.modelName = marketResponse.data.title; } } @@ -72,14 +72,14 @@ Rectangle { function getAvatarModelName() { - if(currentAvatar === null) { + if (currentAvatar === null) { return ''; } - if(currentAvatar.modelName !== undefined) { + if (currentAvatar.modelName !== undefined) { return currentAvatar.modelName; } else { var marketId = allAvatars.extractMarketId(currentAvatar.avatarUrl); - if(marketId !== '') { + if (marketId !== '') { fetchAvatarModelName(marketId, currentAvatar); } } @@ -103,51 +103,51 @@ Rectangle { property url externalAvatarThumbnailUrl: '../../images/avatarapp/guy-in-circle.svg' function fromScript(message) { - if(message.method === 'initialize') { + if (message.method === 'initialize') { jointNames = message.data.jointNames; emitSendToScript({'method' : getAvatarsMethod}); - } else if(message.method === 'wearableUpdated') { + } else if (message.method === 'wearableUpdated') { adjustWearables.refreshWearable(message.entityID, message.wearableIndex, message.properties, message.updateUI); - } else if(message.method === 'wearablesUpdated') { + } else if (message.method === 'wearablesUpdated') { var wearablesModel = currentAvatar.wearables; wearablesModel.clear(); message.wearables.forEach(function(wearable) { wearablesModel.append(wearable); }); adjustWearables.refresh(currentAvatar); - } else if(message.method === 'scaleChanged') { + } else if (message.method === 'scaleChanged') { currentAvatar.avatarScale = message.value; updateCurrentAvatarInBookmarks(currentAvatar); - } else if(message.method === 'externalAvatarApplied') { + } else if (message.method === 'externalAvatarApplied') { currentAvatar.avatarUrl = message.avatarURL; currentAvatar.thumbnailUrl = allAvatars.makeThumbnailUrl(message.avatarURL); currentAvatar.entry.avatarUrl = currentAvatar.avatarUrl; currentAvatar.modelName = undefined; updateCurrentAvatarInBookmarks(currentAvatar); - } else if(message.method === 'settingChanged') { + } else if (message.method === 'settingChanged') { currentAvatarSettings[message.name] = message.value; - } else if(message.method === 'changeSettings') { + } else if (message.method === 'changeSettings') { currentAvatarSettings = message.settings; - } else if(message.method === 'bookmarkLoaded') { + } else if (message.method === 'bookmarkLoaded') { setCurrentAvatar(message.data.currentAvatar, message.data.name); var avatarIndex = allAvatars.findAvatarIndex(currentAvatar.name); allAvatars.move(avatarIndex, 0, 1); view.setPage(0); - } else if(message.method === 'bookmarkAdded') { + } else if (message.method === 'bookmarkAdded') { var avatar = allAvatars.findAvatar(message.bookmarkName); - if(avatar !== undefined) { + if (avatar !== undefined) { var avatarObject = allAvatars.makeAvatarObject(message.bookmark, message.bookmarkName); for(var prop in avatarObject) { avatar[prop] = avatarObject[prop]; } - if(currentAvatar.name === message.bookmarkName) { + if (currentAvatar.name === message.bookmarkName) { currentAvatar = currentAvatarModel.makeAvatarEntry(avatarObject); } } else { allAvatars.addAvatarEntry(message.bookmark, message.bookmarkName); } updateCurrentAvatarInBookmarks(currentAvatar); - } else if(message.method === 'bookmarkDeleted') { + } else if (message.method === 'bookmarkDeleted') { pageOfAvatars.isUpdating = true; var index = pageOfAvatars.findAvatarIndex(message.name); @@ -159,15 +159,16 @@ Rectangle { var itemsOnPage = pageOfAvatars.count; var newItemIndex = view.currentPage * view.itemsPerPage + itemsOnPage; - if(newItemIndex <= (allAvatars.count - 1)) { + if (newItemIndex <= (allAvatars.count - 1)) { pageOfAvatars.append(allAvatars.get(newItemIndex)); } else { - if(!pageOfAvatars.hasGetAvatars()) + if (!pageOfAvatars.hasGetAvatars()) { pageOfAvatars.appendGetAvatars(); + } } pageOfAvatars.isUpdating = false; - } else if(message.method === getAvatarsMethod) { + } else if (message.method === getAvatarsMethod) { var getAvatarsData = message.data; allAvatars.populate(getAvatarsData.bookmarks); setCurrentAvatar(getAvatarsData.currentAvatar, ''); @@ -175,16 +176,16 @@ Rectangle { currentAvatarSettings = getAvatarsData.currentAvatarSettings; updateCurrentAvatarInBookmarks(currentAvatar); - } else if(message.method === 'updateAvatarInBookmarks') { + } else if (message.method === 'updateAvatarInBookmarks') { updateCurrentAvatarInBookmarks(currentAvatar); - } else if(message.method === 'selectAvatarEntity') { + } else if (message.method === 'selectAvatarEntity') { adjustWearables.selectWearableByID(message.entityID); } } function updateCurrentAvatarInBookmarks(avatar) { var bookmarkAvatarIndex = allAvatars.findAvatarIndexByValue(avatar); - if(bookmarkAvatarIndex === -1) { + if (bookmarkAvatarIndex === -1) { avatar.name = ''; view.setPage(0); } else { @@ -597,8 +598,9 @@ Rectangle { pageOfAvatars.append(avatarItem); } - if(pageOfAvatars.count !== itemsPerPage) + if (pageOfAvatars.count !== itemsPerPage) { pageOfAvatars.appendGetAvatars(); + } currentPage = pageIndex; pageOfAvatars.isUpdating = false; @@ -619,7 +621,7 @@ Rectangle { } function removeGetAvatars() { - if(hasGetAvatars()) { + if (hasGetAvatars()) { remove(count - 1) } } @@ -687,13 +689,13 @@ Rectangle { hoverEnabled: enabled onClicked: { - if(isInManageState) { + if (isInManageState) { var currentItem = delegateRoot.GridView.view.model.get(index); popup.showDeleteFavorite(currentItem.name, function() { view.deleteAvatar(currentItem); }); } else { - if(delegateRoot.GridView.view.currentIndex !== index) { + if (delegateRoot.GridView.view.currentIndex !== index) { var currentItem = delegateRoot.GridView.view.model.get(index); popup.showLoadFavorite(currentItem.name, function() { view.selectAvatar(currentItem); diff --git a/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml b/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml index bec037fdf2..e80dab60c2 100644 --- a/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml +++ b/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml @@ -43,10 +43,10 @@ Rectangle { wearablesCombobox.model.clear(); wearablesCombobox.currentIndex = -1; - for(var i = 0; i < avatar.wearables.count; ++i) { + for (var i = 0; i < avatar.wearables.count; ++i) { var wearable = avatar.wearables.get(i).properties; - for(var j = (wearable.modelURL.length - 1); j >= 0; --j) { - if(wearable.modelURL[j] === '/') { + for (var j = (wearable.modelURL.length - 1); j >= 0; --j) { + if (wearable.modelURL[j] === '/') { wearable.text = wearable.modelURL.substring(j + 1); break; } @@ -54,34 +54,34 @@ Rectangle { wearablesCombobox.model.append(wearable); } - if(wearablesCombobox.model.count !== 0) { + if (wearablesCombobox.model.count !== 0) { wearablesCombobox.currentIndex = 0; } } function refreshWearable(wearableID, wearableIndex, properties, updateUI) { - if(wearableIndex === -1) { + if (wearableIndex === -1) { wearableIndex = wearablesCombobox.model.findIndexById(wearableID); } var wearable = wearablesCombobox.model.get(wearableIndex); - if(!wearable) { + if (!wearable) { return; } var wearableModelItemProperties = wearablesModel.get(wearableIndex).properties; - for(var prop in properties) { + for (var prop in properties) { wearable[prop] = properties[prop]; wearableModelItemProperties[prop] = wearable[prop]; - if(updateUI) { - if(prop === 'localPosition') { + if (updateUI) { + if (prop === 'localPosition') { positionVector.set(wearable[prop]); - } else if(prop === 'localRotationAngles') { + } else if (prop === 'localRotationAngles') { rotationVector.set(wearable[prop]); - } else if(prop === 'dimensions') { + } else if (prop === 'dimensions') { scalespinner.set(wearable[prop].x / wearable.naturalDimensions.x); } } @@ -95,9 +95,9 @@ Rectangle { } function selectWearableByID(entityID) { - for(var i = 0; i < wearablesCombobox.model.count; ++i) { + for (var i = 0; i < wearablesCombobox.model.count; ++i) { var wearable = wearablesCombobox.model.get(i); - if(wearable.id === entityID) { + if (wearable.id === entityID) { wearablesCombobox.currentIndex = i; break; } @@ -220,9 +220,9 @@ Rectangle { model: ListModel { function findIndexById(id) { - for(var i = 0; i < count; ++i) { + for (var i = 0; i < count; ++i) { var wearable = get(i); - if(wearable.id === id) { + if (wearable.id === id) { return i; } } @@ -245,7 +245,7 @@ Rectangle { jointsCombobox.set(joint); isSoft.set(soft); - if(currentWearable) { + if (currentWearable) { wearableSelected(currentWearable.id); } } @@ -298,7 +298,7 @@ Rectangle { } onCurrentIndexChanged: { - if(notify) notifyJointChanged(); + if (notify) notifyJointChanged(); } } } @@ -352,9 +352,9 @@ Rectangle { property bool notify: false; - onXvalueChanged: if(notify) notifyPositionChanged(); - onYvalueChanged: if(notify) notifyPositionChanged(); - onZvalueChanged: if(notify) notifyPositionChanged(); + onXvalueChanged: if (notify) notifyPositionChanged(); + onYvalueChanged: if (notify) notifyPositionChanged(); + onZvalueChanged: if (notify) notifyPositionChanged(); decimals: 2 realFrom: -10 @@ -412,9 +412,9 @@ Rectangle { property bool notify: false; - onXvalueChanged: if(notify) notifyRotationChanged(); - onYvalueChanged: if(notify) notifyRotationChanged(); - onZvalueChanged: if(notify) notifyRotationChanged(); + onXvalueChanged: if (notify) notifyRotationChanged(); + onYvalueChanged: if (notify) notifyRotationChanged(); + onZvalueChanged: if (notify) notifyRotationChanged(); decimals: 0 realFrom: -180 @@ -453,7 +453,7 @@ Rectangle { property bool notify: false; - onCheckedChanged: if(notify) notifyIsSoftChanged(); + onCheckedChanged: if (notify) notifyIsSoftChanged(); } Column { @@ -482,7 +482,7 @@ Rectangle { colorScheme: hifi.colorSchemes.light property bool notify: false; - onRealValueChanged: if(notify) notifyScaleChanged(); + onRealValueChanged: if (notify) notifyScaleChanged(); function set(value) { notify = false; diff --git a/interface/resources/qml/hifi/avatarapp/AvatarsModel.qml b/interface/resources/qml/hifi/avatarapp/AvatarsModel.qml index f9a231ec48..bfd66f1a30 100644 --- a/interface/resources/qml/hifi/avatarapp/AvatarsModel.qml +++ b/interface/resources/qml/hifi/avatarapp/AvatarsModel.qml @@ -24,8 +24,9 @@ ListModel { function makeThumbnailUrl(avatarUrl) { var marketId = extractMarketId(avatarUrl); - if(marketId === '') + if (marketId === '') { return ''; + } var avatarThumbnailUrl = "https://hifi-metaverse.s3-us-west-1.amazonaws.com/marketplace/previews/%marketId%/large/hifi-mp-%marketId%.jpg" .split('%marketId%').join(marketId); @@ -57,7 +58,7 @@ ListModel { function populate(bookmarks) { clear(); - for(var avatarName in bookmarks) { + for (var avatarName in bookmarks) { var avatar = bookmarks[avatarName]; var avatarEntry = makeAvatarObject(avatar, avatarName); @@ -66,19 +67,19 @@ ListModel { } function arraysAreEqual(a1, a2, comparer) { - if(Array.isArray(a1) && Array.isArray(a2)) { - if(a1.length !== a2.length) { + if (Array.isArray(a1) && Array.isArray(a2)) { + if (a1.length !== a2.length) { return false; } - for(var i = 0; i < a1.length; ++i) { - if(!comparer(a1[i], a2[i])) { + for (var i = 0; i < a1.length; ++i) { + if (!comparer(a1[i], a2[i])) { return false; } } - } else if(Array.isArray(a1)) { + } else if (Array.isArray(a1)) { return a1.length === 0; - } else if(Array.isArray(a2)) { + } else if (Array.isArray(a2)) { return a2.length === 0; } @@ -86,26 +87,26 @@ ListModel { } function modelsAreEqual(m1, m2, comparer) { - if(m1.count !== m2.count) { + if (m1.count !== m2.count) { return false; } - for(var i = 0; i < m1.count; ++i) { + for (var i = 0; i < m1.count; ++i) { var e1 = m1.get(i); var allDifferent = true; // it turns out order of wearables can randomly change so make position-independent comparison here - for(var j = 0; j < m2.count; ++j) { + for (var j = 0; j < m2.count; ++j) { var e2 = m2.get(j); - if(comparer(e1, e2)) { + if (comparer(e1, e2)) { allDifferent = false; break; } } - if(allDifferent) { + if (allDifferent) { return false; } } @@ -114,18 +115,20 @@ ListModel { } function compareNumericObjects(o1, o2) { - if(o1 === undefined && o2 !== undefined) + if (o1 === undefined && o2 !== undefined) { return false; - if(o1 !== undefined && o2 === undefined) + } + if (o1 !== undefined && o2 === undefined) { return false; + } - for(var prop in o1) { - if(o1.hasOwnProperty(prop) && o2.hasOwnProperty(prop)) { + for (var prop in o1) { + if (o1.hasOwnProperty(prop) && o2.hasOwnProperty(prop)) { var v1 = o1[prop]; var v2 = o2[prop]; - if(v1 !== v2 && Math.round(v1 * 500) != Math.round(v2 * 500)) { + if (v1 !== v2 && Math.round(v1 * 500) != Math.round(v2 * 500)) { return false; } } @@ -135,7 +138,7 @@ ListModel { } function compareObjects(o1, o2, props, arrayProp) { - for(var i = 0; i < props.length; ++i) { + for (var i = 0; i < props.length; ++i) { var prop = props[i]; var propertyName = prop.propertyName; var comparer = prop.comparer; @@ -143,12 +146,12 @@ ListModel { var o1Value = arrayProp ? o1[arrayProp][propertyName] : o1[propertyName]; var o2Value = arrayProp ? o2[arrayProp][propertyName] : o2[propertyName]; - if(comparer) { - if(comparer(o1Value, o2Value) === false) { + if (comparer) { + if (comparer(o1Value, o2Value) === false) { return false; } } else { - if(JSON.stringify(o1Value) !== JSON.stringify(o2Value)) { + if (JSON.stringify(o1Value) !== JSON.stringify(o2Value)) { return false; } } @@ -174,21 +177,23 @@ ListModel { var index = -1; // 2DO: find better way of determining selected avatar in bookmarks - for(var i = 0; i < allAvatars.count; ++i) { + for (var i = 0; i < allAvatars.count; ++i) { var thesame = true; var bookmarkedAvatar = allAvatars.get(i); - if(bookmarkedAvatar.avatarUrl !== avatar.avatarUrl) - continue; - - if(bookmarkedAvatar.avatarScale !== avatar.avatarScale) - continue; - - if(!modelsAreEqual(bookmarkedAvatar.wearables, avatar.wearables, compareWearables)) { + if (bookmarkedAvatar.avatarUrl !== avatar.avatarUrl) { continue; } - if(thesame) { + if (bookmarkedAvatar.avatarScale !== avatar.avatarScale) { + continue; + } + + if (!modelsAreEqual(bookmarkedAvatar.wearables, avatar.wearables, compareWearables)) { + continue; + } + + if (thesame) { index = i; break; } @@ -198,8 +203,8 @@ ListModel { } function findAvatarIndex(avatarName) { - for(var i = 0; i < count; ++i) { - if(get(i).name === avatarName) { + for (var i = 0; i < count; ++i) { + if (get(i).name === avatarName) { return i; } } @@ -208,8 +213,9 @@ ListModel { function findAvatar(avatarName) { var avatarIndex = findAvatarIndex(avatarName); - if(avatarIndex === -1) + if (avatarIndex === -1) { return undefined; + } return get(avatarIndex); } diff --git a/interface/resources/qml/hifi/avatarapp/CreateFavoriteDialog.qml b/interface/resources/qml/hifi/avatarapp/CreateFavoriteDialog.qml index ab995e79e8..1387c0791a 100644 --- a/interface/resources/qml/hifi/avatarapp/CreateFavoriteDialog.qml +++ b/interface/resources/qml/hifi/avatarapp/CreateFavoriteDialog.qml @@ -125,9 +125,9 @@ Rectangle { size: 15 color: 'red' visible: { - for(var i = 0; i < avatars.count; ++i) { + for (var i = 0; i < avatars.count; ++i) { var avatarName = avatars.get(i).name; - if(avatarName === favoriteName.text) { + if (avatarName === favoriteName.text) { return true; } } @@ -165,7 +165,7 @@ Rectangle { } onYesClicked: function() { - if(onSaveClicked) { + if (onSaveClicked) { onSaveClicked(); } else { root.close(); @@ -173,7 +173,7 @@ Rectangle { } onNoClicked: function() { - if(onCancelClicked) { + if (onCancelClicked) { onCancelClicked(); } else { root.close(); diff --git a/interface/resources/qml/hifi/avatarapp/DialogButtons.qml b/interface/resources/qml/hifi/avatarapp/DialogButtons.qml index 46c17bb4dc..d6eb0139ed 100644 --- a/interface/resources/qml/hifi/avatarapp/DialogButtons.qml +++ b/interface/resources/qml/hifi/avatarapp/DialogButtons.qml @@ -33,7 +33,7 @@ Row { onClicked: { console.debug('whitebutton.clicked', onNoClicked); - if(onNoClicked) { + if (onNoClicked) { onNoClicked(); } } diff --git a/interface/resources/qml/hifi/avatarapp/MessageBox.qml b/interface/resources/qml/hifi/avatarapp/MessageBox.qml index e4aa0847c5..f111303214 100644 --- a/interface/resources/qml/hifi/avatarapp/MessageBox.qml +++ b/interface/resources/qml/hifi/avatarapp/MessageBox.qml @@ -128,7 +128,7 @@ Rectangle { wrapMode: Text.WordWrap; onLinkActivated: { - if(onLinkClicked) + if (onLinkClicked) onLinkClicked(link); } } @@ -166,7 +166,7 @@ Rectangle { noText: root.button1text onYesClicked: function() { - if(onButton2Clicked) { + if (onButton2Clicked) { onButton2Clicked(); } else { root.close(); @@ -174,7 +174,7 @@ Rectangle { } onNoClicked: function() { - if(onButton1Clicked) { + if (onButton1Clicked) { onButton1Clicked(); } else { root.close(); diff --git a/interface/resources/qml/hifi/avatarapp/MessageBoxes.qml b/interface/resources/qml/hifi/avatarapp/MessageBoxes.qml index f78c973bd6..b7782c697d 100644 --- a/interface/resources/qml/hifi/avatarapp/MessageBoxes.qml +++ b/interface/resources/qml/hifi/avatarapp/MessageBoxes.qml @@ -18,15 +18,17 @@ MessageBox { popup.button2text = 'CONFIRM'; popup.onButton2Clicked = function() { - if(callback) + if (callback) { callback(); + } popup.close(); } popup.onLinkClicked = function(link) { - if(linkCallback) + if (linkCallback) { linkCallback(link); + } } popup.open(); @@ -43,8 +45,9 @@ MessageBox { popup.inputText.placeholderText = 'Enter Wearable URL'; popup.onButton2Clicked = function() { - if(callback) + if (callback) { callback(popup.inputText.text); + } popup.close(); } @@ -68,15 +71,17 @@ MessageBox { popup.onButton2Clicked = function() { popup.close(); - if(callback) + if (callback) { callback(); + } } popup.onLinkClicked = function(link) { popup.close(); - if(linkCallback) + if (linkCallback) { linkCallback(link); + } } popup.open(); @@ -92,8 +97,9 @@ MessageBox { popup.onButton2Clicked = function() { popup.close(); - if(callback) + if (callback) { callback(); + } } popup.open(); } @@ -107,8 +113,9 @@ MessageBox { popup.onButton2Clicked = function() { popup.close(); - if(callback) + if (callback) { callback(); + } } popup.open(); } @@ -129,15 +136,17 @@ MessageBox { popup.onButton2Clicked = function() { popup.close(); - if(callback) + if (callback) { callback(); + } } popup.onLinkClicked = function(link) { popup.close(); - if(linkCallback) + if (linkCallback) { linkCallback(link); + } } popup.open(); diff --git a/interface/resources/qml/hifi/avatarapp/Settings.qml b/interface/resources/qml/hifi/avatarapp/Settings.qml index e1b55866c2..71bfbb084d 100644 --- a/interface/resources/qml/hifi/avatarapp/Settings.qml +++ b/interface/resources/qml/hifi/avatarapp/Settings.qml @@ -33,13 +33,13 @@ Rectangle { scaleSlider.value = Math.round(avatarScale * 10); scaleSlider.notify = true;; - if(settings.dominantHand === 'left') { + if (settings.dominantHand === 'left') { leftHandRadioButton.checked = true; } else { rightHandRadioButton.checked = true; } - if(settings.collisionsEnabled) { + if (settings.collisionsEnabled) { collisionsEnabledRadiobutton.checked = true; } else { collisionsDisabledRadioButton.checked = true; @@ -113,7 +113,7 @@ Rectangle { onValueChanged: { console.debug('value changed: ', value); - if(notify) { + if (notify) { console.debug('notifying.. '); root.scaleChanged(value / 10); } diff --git a/interface/resources/qml/hifi/avatarapp/TransparencyMask.qml b/interface/resources/qml/hifi/avatarapp/TransparencyMask.qml index 4884d1e1ad..6c50a6093a 100644 --- a/interface/resources/qml/hifi/avatarapp/TransparencyMask.qml +++ b/interface/resources/qml/hifi/avatarapp/TransparencyMask.qml @@ -32,7 +32,7 @@ Item { highp vec4 maskColor = texture2D(mask, vec2(qt_TexCoord0.x, qt_TexCoord0.y)); highp vec4 sourceColor = texture2D(source, vec2(qt_TexCoord0.x, qt_TexCoord0.y)); - if(maskColor.a > 0.0) + if (maskColor.a > 0.0) gl_FragColor = sourceColor; else gl_FragColor = maskColor;