Better Filter on Path (Text, Type and Property)#107
Better Filter on Path (Text, Type and Property)#10753845714nF wants to merge 5 commits intofaaxm:masterfrom
Conversation
477aa6b to
d918a14
Compare
|
close and re-open to trigger fresh build |
Using # in front of a Type and using "" to looking for a text.
f80008f to
4d4cc45
Compare
|
@faaxm I think you need to poke gh again :) |
4d4cc45 to
a40e0b7
Compare
a40e0b7 to
3f095d1
Compare
|
@faaxm sorry, my clangformat does run very selectively apparently, please recheck again :) |
faaxm
left a comment
There was a problem hiding this comment.
I like the general idea, and had a few comments regarding some details.
One thing I noticed is that the functions for parsing the item name/path component in the QtScene and the ones for searching items have become rather long and a bit less obvious, so I am wondering if it would make sense to refactor this a bit.
However, I am also wondering how this best fits with opening Spix up towards other UI Frameworks. Moving the path parsing into the ItemPath object might be a solution as all Scenes could then use the same logic... Maybe with ItemPath having a list of ItemPathComponents, rather than plain strings
Having a common path with filtering support however begs the question if there is any sensible syntax that makes sense for all ui frameworks...
So... basically just thinking out loud here as I am not quite sure about this myself yet... Would be interested in your thoughts and might play around with some ideas myself during the next week. Still wanted to provide some initial feedback though :)
| if (pathss.peek() == '\"') { | ||
| getline(pathss, component, '\"'); | ||
| getline(pathss, component, '\"'); | ||
| component = '\"' + component + '\"'; | ||
| m_components.push_back(std::move(component)); | ||
| } | ||
|
|
||
| if (pathss.peek() == '(') { | ||
| getline(pathss, component, '('); | ||
| getline(pathss, component, ')'); | ||
| component = '(' + component + ')'; | ||
| m_components.push_back(std::move(component)); | ||
| } |
There was a problem hiding this comment.
Is the purpose of handling components that start with " or ( separately to make sure that intermittent '/' are kept as part of the component? Because if that is the only reason and I am not missing anything, I think it would make sense to combine that with a fix to issue #45 and to have a more generic '' way of escaping a '/'.
Otherwise it feels a bit like part of the logic for parsing special path components is distributed among the ItemPath class and the QtScene implementation.
Also, a path "/foo/"bar"(baz)/x" would now be the same as "/foo/"bar"/(baz)/x" which is a bit confusing. Probably would also make sense to extend the unit test for the ItemPath to cover those extra cases...
I know this is an old PR, so I wouldn't mind joining in the effort and fixing this myself. Just let me know if I missed anything when looking at this ;-)
| size_t found = itemName.find("\""); | ||
| auto searchText = itemName.substr(found + 1, itemName.length() - 2); |
There was a problem hiding this comment.
| size_t found = itemName.find("\""); | |
| auto searchText = itemName.substr(found + 1, itemName.length() - 2); | |
| auto searchText = itemName.substr(1, itemName.length() - 2); |
should be good enough since we already know the " is the first character.
| size_t found = itemName.find("#"); | ||
| auto type = QString::fromStdString(itemName.substr(found + 1)); |
There was a problem hiding this comment.
| size_t found = itemName.find("#"); | |
| auto type = QString::fromStdString(itemName.substr(found + 1)); | |
| auto type = QString::fromStdString(itemName.substr(1)); |
(as above)
| } | ||
| } | ||
|
|
||
| if (GetObjectName(child) == name) { |
There was a problem hiding this comment.
isn't this obsolete now that the name is compared in the if (name.has_value()) clause above?
| if (auto item = FindChildItem(child, name, {}, {}, type)) { | ||
| return item; | ||
| } |
There was a problem hiding this comment.
I'm wondering if a depth-first search is still the right approach when searching for something by type. With object names, it is more safe to assume that they are somewhat unique, but if I search for a Text in a root-view, I would probably assume to get the first text in that root view, and not the Text object that is a child of a child of the first Rectangle in that root view...
| QString getNameForObject(QObject* object) | ||
| { | ||
| QString name = "#" + spix::qt::TypeByObject(object); | ||
|
|
||
| return name; | ||
| } |
There was a problem hiding this comment.
I think this function is not used anywhere. Is it a leftover from debugging?
| QString getNameForObject(QObject* object) | ||
| { | ||
| QString name; | ||
| if (spix::qt::PropertValueByObject(object, QString::fromStdString("text")) != "") { | ||
| name = "\"" + spix::qt::PropertValueByObject(object, QString::fromStdString("text")) + "\""; | ||
| } else if (spix::qt::PropertValueByObject(object, QString::fromStdString("source")) != "") { | ||
| name = "(source=" + spix::qt::PropertValueByObject(object, QString::fromStdString("source")) + ")"; | ||
| } else if (spix::qt::GetObjectName(object) != "") { | ||
| name = spix::qt::GetObjectName(object); | ||
| } else { | ||
| name = "#" + spix::qt::TypeByObject(object); | ||
| } | ||
|
|
||
| return name; | ||
| } |
There was a problem hiding this comment.
I think this function is not used anywhere. Is it a leftover from debugging?
| size_t foundBracketSign = itemName.find('('); | ||
| auto searchText = itemName.substr(foundBracketSign + 1, itemName.length() - 2); |
There was a problem hiding this comment.
| size_t foundBracketSign = itemName.find('('); | |
| auto searchText = itemName.substr(foundBracketSign + 1, itemName.length() - 2); | |
| auto searchText = itemName.substr(1, itemName.length() - 2); |
| if (propertyValue.has_value() && propertyName.has_value()) { | ||
| if (auto item = FindChildItem(child, name, propertyName.value(), propertyValue.value(), {})) { | ||
| return item; | ||
| } | ||
| } else if (type.has_value()) { | ||
| if (auto item = FindChildItem(child, name, {}, {}, type)) { | ||
| return item; | ||
| } | ||
| } else { | ||
| if (auto item = FindChildItem(child, name)) { | ||
| return item; | ||
| } | ||
| } |
There was a problem hiding this comment.
I think this could just be a single
| if (propertyValue.has_value() && propertyName.has_value()) { | |
| if (auto item = FindChildItem(child, name, propertyName.value(), propertyValue.value(), {})) { | |
| return item; | |
| } | |
| } else if (type.has_value()) { | |
| if (auto item = FindChildItem(child, name, {}, {}, type)) { | |
| return item; | |
| } | |
| } else { | |
| if (auto item = FindChildItem(child, name)) { | |
| return item; | |
| } | |
| } | |
| if (auto item = FindChildItem(child, name, propertyName, propertyValue, type)) { | |
| return item; | |
| } |
Where the optionals are just passed along, leaving the has_value() check to the FindChildItem call.
| } | ||
|
|
||
| QObject* FindChildItem(QObject* object, const QString& name) | ||
| QString PropertValueByObject(QObject* object, QString propertyName) |
There was a problem hiding this comment.
typo
| QString PropertValueByObject(QObject* object, QString propertyName) | |
| QString PropertyValueByObject(QObject* object, QString propertyName) |
|
Hi @53845714nF and @chsterz ! Your PR made me review how items were searched previously and how paths were managed in general. Once I started restructuring things, this ended up being a bigger change, but with the new system in place, adding new selectors was quite straight forward. I cherry-picked some of your changes into a new branch with the new path system. Hope you don't mind. I will leave those PRs open during the next week, so if you want to have a look or propose changes (in case I missed something that was important for your particular use case), let me know and we can discuss how to best merge your changes. The PR with the general changes of how paths work: #136 |
|
Hello, I think this is a good way to go. I can no longer answer all the questions ad hoc about what I did a year ago. |
I added the option in Path to use
#for finding types of a Qml Object.Finding Text with
"yout text". And a filter for looking at Properties(source=qrc:/menu/back.png).Example in Python:
This can then be used in all spix functions.
For the Property Filter, I use
()so select them. They also must have a=to look what is the Value and what is the Property.It is very cool when you use this on a back arrow Button.