Get all parents of all children in Rust Vec - vector

I have a Vec<(String, String)> where first String is child and second String is parent.
How can I make a HashMap<String, Vec<String>> where key is child and value is array of parents?
Example:
Child
Parent
""
"Child1"
"Child1"
"Parent1"
"Parent1"
"Parent2"
"Child2"
"Parent3"
"Parent3"
"Parent2"
"Parent2"
""
""
"Child2"
Expected result:
Child
Parents
"Child1"
["Parent1", "Parent2"]
"Child2"
["Parent3", "Parent2"]

Related

QML Question about Calling Nested Variables

So I want to call a variable from an object within an object several levels down. The only way I've figured out how to do it successfully is as follows:
//object doing the calling
Text {
text: lv1.lv1Out
}
//object containing the variable I want
Rectangle {
id: lv1
property var lv1Out: lv2Out
Rectangle {
id: lv2
property var lv2Out: variableIWant
Rectangle {
id: lv3
property var variableIWant: 1
}
}
}
Basically I have to define variables at every level, and define the variable I want all the way out of the containing object tree. Is there a more elegant way of doing this? Calling the following doesn't work for me:
Text {
text: lv1.lv2.lv3.variableIWant;
}
Calling a.b.c for nested definitions will not work because children object are contained in parent object but not as variable/property. For this type of inspection you need to use attribute children[i] - in your case children of children and loop over children.
But in your case it is is unnecessary. You have children object named by id so can can do:
Text {
text: lv3.variableIWant;
}

Is there a way to distinguish internally defined children from externally defined ones in QML?

I have defined a MyElement element (in the MyElement.qml file) as the following:
Rectangle {
Item {
}
Component.onCompleted: {
console.warn(children.length)
}
}
Let's call the Item element defined within MyElement the internal child. Now, I'm using the MyElement element in the following way:
MyElement {
Item {
}
}
Here another one Item element is used as a child of MyElement. Let's call this Item element the external child. To understand my question below one should clearly understand the difference between internal and external children.
The output for the presented code will be 2, i.e. both Item elements are calculated as children.
In the future I want to iterate in the block Component.onCompleted only over external children, not over internal (external children go after internal). But for this I have to know a children index from which I have to start (in the given example this index is 1). Is there a way to get this index or, in other words, the number of internal children? Thanks.
There is no internal mechanism in Qt to distinguish internal children from those which are defined outside of the own QML definition.
My workaround is as follow
//MyElement.qml
Rectangle {
id: root
readonly property Item last_item: lastone
Item {
id: someitem
}
Item {
id: lastone
}
Component.onCompleted: {
var external_started = false;
for(var i = 0 ; i < root.children.length ; ++i)
{
if(external_started)
console.log(root.children[i].toString(), 'is external');
else if(root.children[i]===last_item)
external_started = true;
}
}
}
and
MyElement {
Item {
objectName: 'I am external'
}
}
It's a dirty hack but it works.
I'm saving a reference to the last item in a readonly property called last_item and that will distinguish my last item in qml definition.
Other items which are added outside of the qml file, will be placed after this item in the children list.

CSS of a parent table of a Div with ID =? that is the table above said div id but not direct parent

CSS of a parent table of a Div with ID =? that is the table above said div id but not direct parent
Any ideas...
I have tried [id*="reserveEmail"] {

QML SplitView: How this control handle their children items into internal item?

I looking into source code of SplitView (%QT_SOURCE_PATH%\qml\QtQuick\Controls\SplitView.qml) and noticed that it used 3 Items to maipulate splitters and items:
Item {
id: contents
visible: false
anchors.fill: parent
}
Item {
id: splitterItems
anchors.fill: parent
}
Item {
id: splitterHandles
anchors.fill: parent
}
According to code, new items is placing into item splitterItems by the function addItem_impl(item). The fuction addItem_impl(item) are called from function init() that pass every child item from Item with id contents. But I wonder how all the children from root item were placed into contents Item?
Via a default property:
default property alias __contents: contents.data
From the documentation:
An object definition can have a single default property. A default property is the property to which a value is assigned if an object is declared within another object's definition without declaring it as a value for a particular property.
[...]
You will notice that child objects can be added to any Item-based type without explicitly adding them to the children property. This is because the default property of Item is its data property, and any items added to this list for an Item are automatically added to its list of children.
Default properties can be useful for reassigning the children of an item. See the TabWidget Example, which uses a default property to automatically reassign children of the TabWidget as children of an inner ListView. See also Extending QML.

PyQt: Qtreeview how to implement a different header for child and parent?

I would like to implement a simple qtreeview which has a different header for parent and children, depending on which one is selected. For example :
parent1 parentAttr1 ParentAttr2 ...
child1 childAttr1 childAttr2 ...
child2 childAttr1 childAttr2 ...
parent2 parentAttr1 ParentAttr2 ...
then if I select a parent row, I will see a parent header and conversely with the child row.
Can anyone give me a simple working example ?

Resources