How can I test if an item is anchored? - qml

What is the proper way to test if an item has been anchored? For example, take the left side, I have tried:
property bool isAnchored: parent.anchors.left != undefined
But that does not seem to work? I also tried:
property bool isAnchored: !!parent.anchors.left
which also does not seem to work, I also tried:
property bool isAnchored: parent.anchors.left ? true : false
Any other ideas? There has to be a way to check if an item is anchored but I can not find it?

Unfortunately I don't see any way to do it using the provided/exposed properties. The only thing that determines a valid anchor is the Anchors flag type which is defined in the QQuickAnchorLine::anchorLine member, but that's not exposed to QML anywhere (eg. anchors.left.anchorLine is always undefined). Or in the public C++ API for that matter. The actual QQuickAnchorLines attached to each object are always valid/non-null, as you've discovered.
I think you will need to implement your own flags in whatever routine(s) which set or remove the anchors in your code (I assume that has to be determined somewhere). That is, whenever an anchor changes, set a custom property value. There are also the anchor change signals (leftChanged() etc.) which could be connected to.
Alternatively, you could re-implement your own attached Anchors object in C++ and track whatever properties you want (basically same as the above suggestion but centralized in a C++ class). Here is a good example (I think, not my code) of defining your own anchors lines using a custom attached object. With something like this it would be pretty easy to track/query what is anchored to what.

Related

"Convert property getter to initializer" - but they aren't the same thing, are they?

I'm using IntelliJ with a mixed Java/Kotlin project. In one of my Kotlin files, I have this property:
override val value: String
get() {
return webElement.getAttribute("value")
}
IntelliJ's light bulb offers to "Convert property getter to initializer", which changes the code to this:
override val value: String = webElement.getAttribute("value")
To me, it seems like this isn't a simple refactoring, but a significant code change. What I think is happening is:
In the first version, the value property is retrieved when I call value.
In the changed version, the value property is set immediately when the class instance is constructed, and then never changes for that class instance.
But maybe this is more like C# expression-bodied members, which use a lambda arrow => instead of braces and return but otherwise work exactly the same way.
So...which is it? When will the second version of the code initialize?
You are correct regarding these statements:
In the first version, the value property is retrieved when I call value.
In the changed version, the value property is set immediately when the class instance is constructed, and then never changes for that class instance.
IntelliJ's light bulb offers to "Convert property getter to initializer" because it is just an option available. Light bulb only highlights the actions you can do with a selected piece of code.
IntelliJ does not try to tell you that "property initializer" and "property getter" are equal. What it tells you is that you can convert one to the other if you wish to.
I agree that it is confusing, especially considering this quote from IntelliJ Idea documentation:
As soon as the IDE finds a way to alter your code, it displays a yellow bulb icon in the editor next to the current line. By clicking this icon, you can view intention actions available for this unit of code. Intention actions cover a wide range of situations from warnings to optimization suggestions. You can view the full list of intentions and customize them in the Settings/Preferences dialog ⌘,.
Having this in mind it could appear that your code is either can be optimized or has a warning.
The answer
When will the second version of the code initialize?
... immediately when the class instance is constructed.
You are correct.

QPickPointEvent when mouse cursor do something above points in Python Qt 3D?

I have a QEntity with a mesh which is set as a primitive type (Points). Beside that I also initialized QObjectPicker and connect four basic signals to functions (clicked, moved, pressed, and released). When I run application and do some mouse events, none of these events is QPickPointEvent. Only QPickEvents occur. Is it possible in Python to trigger a QPickPointEvent?
I also set pick method to PointPicking.
You need to enable point picking using the pick method on the QPickSettings property of the instance of QRenderSettings.
In that case, the QPickEvent will actually be an instance of QPointPickEvent. I'm not sure how you "downcast" that in python though.
But if you entity is indeed using point primitives, then the coordinates of the picked point and the point itself should be the same. The only information you would be missing is the index of the point in it's parent list of primitives.

What 'expression:' property in QML Item

I've inherited a collection of mostly undocumented QML code. I'm new to QML, and I'm struggling to understand this code. In particular, the construct
expression: "connected == false"
occurs frequently in various items, but I can't find any documentation on what this property does. It does not seem to be defined anywhere in the existing code collection, so I'm assuming it's part of QML, but I'm having no luck turning it up anywhere.
It looks as though all items using this construct are backed by C++ classes. However, "expression" is not defined as a QPROPERTY anywhere in the C++ code.
Nope, there's no such property in QML. You'll have to look into the QML file for the type that it's used in, or the C++ if it's declared there.

Identifying objects in IBM RFT

While executing my script in RFT, my script got failed due to the slight position change of a button. (This button's position slightly changes according to the option selected for previous combo box due to the label appearing near the button)
As there are 2 positions for this button in window, one of my script fails while other passes.
Please suggest how to identify this same object in 2 different places in RFT?
If you're alright with not using pre-mapped values and instead work with objects directly in code (which I've personally found to be extremely useful... it's allowed me to do great and wondrous things with RFT :), the following ought to work fine:
private void clickObject(String uniqueIdentifier) {
// Find object
RootTestObject root = RootTestObject.getRootTestObject();
TestObject[] matchingObjs = root.find(atProperty(".id", uniqueIdentifier));
if (matchingObjs.length > 0) {
// Click the object
((GuiTestObject) matchingObjs[0]).click();
}
// Clean-up
unregister(matchingObjs);
}
Feel free to replace ".id" with whatever property is best suited for the situation... since I work primarily with a web application, the ".id" property has worked splendidly for me.
Because the method finds the object anew each time, it'll grab the object's position wherever it's at at the time the method's called. The clean-up will also prevent any weird, horrible, and otherwise unfortunate UnregisteredObjectExceptions from cropping up.
Without looking at your pages I cannot be sure, but I think the buttons are actually two different buttons. Maybe they are generated by javascript, or they are just un-hidden after the option you select in the combobox.
If they are two different buttons (record them both and look at the recognition properties) you can either replace some properties with a regular expression or check wich button is visible/exists and then click it:
if (btn_button1.exists()) {
btn_button1.click();
} else if (btn_button2.exists()) {
btn_button1.click();
}
Here's a more complete tutorial on Object Recognition.
You can increase the tolerance of Rational Performance Tester AssureScript in the properties tab or you could set the description but hide the value. You can also make a custom code that updates the object map to prepare for this change in a java IF structure

How to make my own property attribute in objective-c?

I was thinking how could I make my own property attribute, for example:
#property(retain,nonatomic,'myAttribute') int numberOfWheels
#property('unique',nonatomic) NSString productCode
but when I try to get a help from Xcode pressing command button or option button nothing happens
I was looking in this page and many others but no one ask how to make your own attribute, most of then just asking about how to use property attributes or difference between them
I dont know if its possible to make a new attribute, but if its true, could someone help me
The only way to do this is to modify the compiler directly to add this functionality. I have no idea where you'd begin to do that, except to point you to http://llvm.org and say "good luck".