UNPKG

react-qml

Version:
89 lines (72 loc) 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getObjectType = getObjectType; exports.isAnimation = isAnimation; exports.isPlatformObject = isPlatformObject; exports.isWindow = isWindow; exports.isPlatformDialog = isPlatformDialog; exports.isQuickItem = isQuickItem; exports.findChildIndex = findChildIndex; exports.findModelChildIndex = findModelChildIndex; function getObjectType(obj) { if (!Qt.isQtObject(obj)) { return ''; } // debug name is in the form of QObjectType(memory_address); // we need to remove the memory address part var debugName = obj.toString(); return debugName.replace(/\(.+\)/, ''); } function isAnimation(obj) { var isQtObject = Qt.isQtObject(obj); var objType = getObjectType(obj); var isAnimationType = objType === 'QQuickColorAnimation' || objType === 'QQuickNumberAnimation' || objType === 'QQuickPropertyAnimation' || objType === 'QQuickVector3dAnimation' || objType === 'QQuickRotationAnimation' || objType === 'QQuickAnchorAnimation' || objType === 'QQuickParentAnimation ' || objType === 'QQuickSmoothedAnimation' || objType === 'QQuickSpringAnimation'; return isQtObject && isAnimationType; } function isPlatformObject(obj) { var isQtObject = Qt.isQtObject(obj); var objType = getObjectType(obj); var isPlatformType = objType.indexOf('QQuickPlatform') === 0; return isQtObject && isPlatformType; } function isWindow(obj) { var isQtObject = Qt.isQtObject(obj); var objType = getObjectType(obj); var isWindowType = objType === 'QQuickWindow' || objType === 'QQuickApplicationWindow' || objType === 'QQuickWindowQmlImpl'; return isQtObject && isWindowType; } function isPlatformDialog(obj) { var isQtObject = Qt.isQtObject(obj); var objType = getObjectType(obj); var isPlatformDialogType = objType === 'QQuickPlatformDialog' || objType === 'QQuickPlatformFileDialog' || objType === 'QQuickPlatformColorDialog' || objType === 'QQuickPlatformFolderDialog' || objType === 'QQuickPlatformFontDialog'; return isQtObject && isPlatformDialogType; } // TODO: revise this later function isQuickItem(obj) { var isQtObject = Qt.isQtObject(obj); var hasChildAtMethod = typeof obj.childAt === 'function'; var hasParentProp = obj.hasOwnProperty('parent'); var hasDataProp = obj.hasOwnProperty('data'); return isQtObject && hasChildAtMethod && hasParentProp && hasDataProp; } function findChildIndex(parentData, child) { if (!parentData) { return -1; } for (var index = 0; index < parentData.length; index++) { var element = parentData[index]; if (element === child) { return index; } } return -1; } function findModelChildIndex(model, child) { for (var index = 0; index < model.count; index++) { var element = model.get(index); if (element === child) { return index; } } return -1; }