Re: [SailfishDevel] Dynamically populate a ContextMenu
Hi, simply assign id to one of the static items, e.g. firstStatic, and then use firstStatic.parent instead of menu._contentColumn as parent for the dynamic items -- this way you do not rely on implementation details: menu: ContextMenu { id: menu MenuItem { id: firstStatic; text: Static 1 } MenuItem { text: Static 2 } } Component.onCompleted: { console.debug(Populating menu) for (var i=0; i 4 ; i++){ var newMenuItem = menuItemComp.createObject(firstStatic.parent, {text : Dynamic + i}) } } Event better consider using Repeater and provide the list of dynamic items as item model[1] (assiging a number as a model gives exactly the same result as in your original example): ApplicationWindow { initialPage: Page { ComboBox { width: parent.width label: Menu menu: ContextMenu { id: menu MenuItem { text: Static 1 } MenuItem { text: Static 2 } Repeater { model: 4 MenuItem { text: Dynamic + index } } } } } } BR, Martin [1] https://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-repeater.html#model-prop On Saturday, November 23, 2013 04:06:40 PM christopher.l...@thurweb.ch wrote: Hi Andrey Zitat von Andrey Kozhevnikov coderusin...@gmail.com: you may need to make childs of menu._contentColumn, not just menu. I thought that the underscore stuff are private internal properties / functions that we mere mortals should not be using 8-) (Not that that would necessarily stop me). Chris ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Please check ContextMenu and ComboBox code. _contentColumn property used in a proper way. QML is not C++ where you not allowed to reimplement headers to use private and protected functions outside. QML is hack-for-fun. On 24.11.2013 00:03, christopher.l...@thurweb.ch wrote: We should not have to make that choice. using an underscore property is the pragmatic solution, but I would be interested to hear what the Jolla developers have to say on this issue. Zitat von Andrey Kozhevnikov coderusin...@gmail.com: You should use it if you want real dynamically created components. Or reimplement ContextMenu item. What would you prefer? ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu: use of _underscore properties
Andrey I beg to differ. You can hack in any language, just as you can apply clean coding conventions. QML is no different here, it is just a little less rigorous in enforcing some conventions. Just like any code, QML code will need maintaining, updating etc, so I prefer to clean code and follow the conventions where they make sense. http://harmattan-dev.nokia.com/docs/library/html/qt4/qml-coding-conventions.html clearly states that double underscore are private, not for external use. So it's hands off double underscores, but this raises the moot point: what about single underscores like _contentColumn? By a strict reading of the conventions they are not private, so what does a single underscore imply? Chris Zitat von Andrey Kozhevnikov coderusin...@gmail.com: Please check ContextMenu and ComboBox code. _contentColumn property used in a proper way. QML is not C++ where you not allowed to reimplement headers to use private and protected functions outside. QML is hack-for-fun. On 24.11.2013 00:03, christopher.l...@thurweb.ch wrote: We should not have to make that choice. using an underscore property is the pragmatic solution, but I would be interested to hear what the Jolla developers have to say on this issue. Zitat von Andrey Kozhevnikov coderusin...@gmail.com: You should use it if you want real dynamically created components. Or reimplement ContextMenu item. What would you prefer? ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu: use of _underscore properties
'protected' ? ;-) I mean when a 'derived' component creted, altering/extending original vehaviour, they canbe used. But just guessing... Zoltán christopher.l...@thurweb.ch írta ekkor: 2013.11.24. 10:26 Andrey I beg to differ. You can hack in any language, just as you can apply clean coding conventions. QML is no different here, it is just a little less rigorous in enforcing some conventions. Just like any code, QML code will need maintaining, updating etc, so I prefer to clean code and follow the conventions where they make sense. http://harmattan-dev.nokia.com/docs/library/html/qt4/qml-coding-conventions.html clearly states that double underscore are private, not for external use. So it's hands off double underscores, but this raises the moot point: what about single underscores like _contentColumn? By a strict reading of the conventions they are not private, so what does a single underscore imply? Chris Zitat von Andrey Kozhevnikov coderusin...@gmail.com: Please check ContextMenu and ComboBox code. _contentColumn property used in a proper way. QML is not C++ where you not allowed to reimplement headers to use private and protected functions outside. QML is hack-for-fun. On 24.11.2013 00:03, coderusin...@gmail.com wrote: We should not have to make that choice. using an underscore property is the pragmatic solution, but I would be interested to hear what the Jolla developers have to say on this issue. Zitat von Andrey Kozhevnikov coderusin...@gmail.com: You should use it if you want real dynamically created components. Or reimplement ContextMenu item. What would you prefer? ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu: use of _underscore properties
Hi Andrey If the _underscore is, as we suspect an indication of internal only, the next question is what is internal? Internal could mean to the component itself. However it could mean internal to Silica. Under this definition a call from Combobox to ContextMenu could be regarded as internal. Given that there will be a degree of coupling between components in the same library this is not unreasonable. Either way, your and my code are clearly external. That implies that if we call anything internal / undocumented we do so at our own risk. I am sure that all the Jolla guys are ultra busy right now (boxing phones?), but it would be great to have an official take some time .. Chris Zitat von Andrey Kozhevnikov coderusin...@gmail.com: ComboBox can use private properties of ContextMenu, but i can't? really? :D ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Hi Antoine I think I had similar problems some months ago. If I remember correctly, I had to explicitly resize the menu height after adding items to it. I will see if I can find the old code, and have a dig around in it ... Chris Zitat von Tigre-Bleu de...@tigre-bleu.net: Hi, I try to dynamically populate a ContextMenu but either I ran into a bug in the Silica Component or there is something I'm doing wrong. Here is an example of simplified code showing the problem: ComboBox { width: parent.width label: Menu menu: ContextMenu { id: menu MenuItem { text: Static 1 } MenuItem { text: Static 2 } } Component { id: menuItemComp MenuItem {} } Component.onCompleted: { console.debug(Populating menu) for (var i=0; i 4 ; i++){ var newMenuItem = menuItemComp.createObject(menu, {text : Dynamic + i}) } } } And in attachment is the result in the emulator. We see that Static entries are correctly displayed, but dynamic ones are all superposed. What is wrong? Thanks, Antoine ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Hi Antoine I had a quick play around, and a peak back in my old code. Just changing the menu height does not change anything. I also tried a version of your code with just dynamic menuItems. The menu did not drop, it just flashes. The problem I was fighting with some months ago (and did my best to try and forget for a while as it was such a nightmare) was slightly different. I had a set of ListViews, loaded from an SQLite DB, the delegates of which expanded to show a contextMenu with static menuItems. The problem was getting the ListViews to resize (and shift the other contextMenus on the page) as the contextMenu opened and closed. Sorry not much help yet ... Chris Zitat von christopher.l...@thurweb.ch: Hi Antoine I think I had similar problems some months ago. If I remember correctly, I had to explicitly resize the menu height after adding items to it. I will see if I can find the old code, and have a dig around in it ... Chris Zitat von Tigre-Bleu de...@tigre-bleu.net: Hi, I try to dynamically populate a ContextMenu but either I ran into a bug in the Silica Component or there is something I'm doing wrong. Here is an example of simplified code showing the problem: ComboBox { width: parent.width label: Menu menu: ContextMenu { id: menu MenuItem { text: Static 1 } MenuItem { text: Static 2 } } Component { id: menuItemComp MenuItem {} } Component.onCompleted: { console.debug(Populating menu) for (var i=0; i 4 ; i++){ var newMenuItem = menuItemComp.createObject(menu, {text : Dynamic + i}) } } } And in attachment is the result in the emulator. We see that Static entries are correctly displayed, but dynamic ones are all superposed. What is wrong? Thanks, Antoine ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
you may need to make childs of menu._contentColumn, not just menu. On 23.11.2013 19:47, Tigre-Bleu wrote: Hi, I try to dynamically populate a ContextMenu but either I ran into a bug in the Silica Component or there is something I'm doing wrong. Here is an example of simplified code showing the problem: ComboBox { width: parent.width label: Menu menu: ContextMenu { id: menu MenuItem { text: Static 1 } MenuItem { text: Static 2 } } Component { id: menuItemComp MenuItem {} } Component.onCompleted: { console.debug(Populating menu) for (var i=0; i 4 ; i++){ var newMenuItem = menuItemComp.createObject(menu, {text : Dynamic + i}) } } } And in attachment is the result in the emulator. We see that Static entries are correctly displayed, but dynamic ones are all superposed. What is wrong? Thanks, Antoine ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Hi Antoine One useful technique for finding out what the Silica components are doing (and how you may need to modify your code, or to prove a bug), is to create a private clone of the problem component in your project. In your case it is ContextMenu, which on my development host lives in /Users/christopherlamb/SailfishOSAlpha5/mersdk/targets/SailfishOS-i486-x86/usr/lib/qt5/qml/Sailfish/Silica/ContextMenu.qml Copy that file into your project as AntContextMenu.qml, and in your code use AntContextMenu rather than ContextMenu. You will also need to clone the private folder + contents to your project (without renaming). Once you have done that, you can then add console.log statements in AntContextMenu.qml in appropriate places, make what if .. changes, and generally play around in the guts of the Silica code. You can easily swap back and forth between your debug / hack version and the standard. Of course this should only temporary while your are figuring out what is wrong. Once you have a solution you should revert to the standard component. Chris Zitat von Tigre-Bleu de...@tigre-bleu.net: Hi, I try to dynamically populate a ContextMenu but either I ran into a bug in the Silica Component or there is something I'm doing wrong. Here is an example of simplified code showing the problem: ComboBox { width: parent.width label: Menu menu: ContextMenu { id: menu MenuItem { text: Static 1 } MenuItem { text: Static 2 } } Component { id: menuItemComp MenuItem {} } Component.onCompleted: { console.debug(Populating menu) for (var i=0; i 4 ; i++){ var newMenuItem = menuItemComp.createObject(menu, {text : Dynamic + i}) } } } And in attachment is the result in the emulator. We see that Static entries are correctly displayed, but dynamic ones are all superposed. What is wrong? Thanks, Antoine ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Hi Andrey Zitat von Andrey Kozhevnikov coderusin...@gmail.com: you may need to make childs of menu._contentColumn, not just menu. I thought that the underscore stuff are private internal properties / functions that we mere mortals should not be using 8-) (Not that that would necessarily stop me). Chris ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
You should use it if you want real dynamically created components. Or reimplement ContextMenu item. What would you prefer? On 23.11.2013 21:06, christopher.l...@thurweb.ch wrote: Hi Andrey Zitat von Andrey Kozhevnikov coderusin...@gmail.com: you may need to make childs of menu._contentColumn, not just menu. I thought that the underscore stuff are private internal properties / functions that we mere mortals should not be using 8-) (Not that that would necessarily stop me). Chris ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Hi Andrey, I wonder why those properties are not documented in the list of all members of ContextMenu: https://sailfishos.org/sailfish-silica/qml-sailfishsilica-contextmenu-members.html Anyway, using menu._contentColumn solved my problem. Thanks for the help. Antoine - Mail original - De: Andrey Kozhevnikov coderusin...@gmail.com À: christopher lamb christopher.l...@thurweb.ch, Sailfish OS Developers devel@lists.sailfishos.org Envoyé: Samedi 23 Novembre 2013 16:08:30 Objet: Re: [SailfishDevel] Dynamically populate a ContextMenu You should use it if you want real dynamically created components. Or reimplement ContextMenu item. What would you prefer? On 23.11.2013 21:06, christopher.l...@thurweb.ch wrote: Hi Andrey Zitat von Andrey Kozhevnikov coderusin...@gmail.com: you may need to make childs of menu._contentColumn, not just menu. I thought that the underscore stuff are private internal properties / functions that we mere mortals should not be using 8-) (Not that that would necessarily stop me). Chris ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Just dont use dynamic childs if you dont want, but let it to others ;) On 24.11.2013 00:03, christopher.l...@thurweb.ch wrote: We should not have to make that choice. using an underscore property is the pragmatic solution, but I would be interested to hear what the Jolla developers have to say on this issue. Zitat von Andrey Kozhevnikov coderusin...@gmail.com: You should use it if you want real dynamically created components. Or reimplement ContextMenu item. What would you prefer? ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Agree with Cristopher. This is a workaround, but it should be fixed so that no manual tweaking is needed. Just as in c++ - private is private. -- Marcin 2013/11/23 Andrey Kozhevnikov coderusin...@gmail.com Just dont use dynamic childs if you dont want, but let it to others ;) On 24.11.2013 00:03, christopher.l...@thurweb.ch wrote: We should not have to make that choice. using an underscore property is the pragmatic solution, but I would be interested to hear what the Jolla developers have to say on this issue. Zitat von Andrey Kozhevnikov coderusin...@gmail.com: You should use it if you want real dynamically created components. Or reimplement ContextMenu item. What would you prefer? ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Sent from my BlackBerry 10 smartphone. From: Andrey KozhevnikovSent: Saturday, November 23, 2013 10:14To: christopher.l...@thurweb.chReply To: Sailfish OS DevelopersCc: Sailfish OS DevelopersSubject: Re: [SailfishDevel] Dynamically populate a ContextMenuJust dont use dynamic childs if you dont want, but let it to others ;)On 24.11.2013 00:03, christopher.l...@thurweb.ch wrote: We should not have to make that choice. using an underscore property is the pragmatic solution, but I would be interested to hear what the Jolla developers have to say on this issue. Zitat von "Andrey Kozhevnikov" coderusin...@gmail.com: You should use it if you want "real" dynamically created components. Or reimplement ContextMenu item. What would you prefer?___SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list
Re: [SailfishDevel] Dynamically populate a ContextMenu
Sorry for the blank emails that were accidentally sent out... I guess that is why BB10 is not my main phone... On Saturday, November 23, 2013 12:15 PM, sonyfe...@ovi.com sonyfe...@ovi.com wrote: Sent from my BlackBerry 10 smartphone. From: Andrey Kozhevnikov Sent: Saturday, November 23, 2013 10:14 To: christopher.l...@thurweb.ch Reply To: Sailfish OS Developers Cc: Sailfish OS Developers Subject: Re: [SailfishDevel] Dynamically populate a ContextMenu Just dont use dynamic childs if you dont want, but let it to others ;) On 24.11.2013 00:03, christopher.l...@thurweb.ch wrote: We should not have to make that choice. using an underscore property is the pragmatic solution, but I would be interested to hear what the Jolla developers have to say on this issue. Zitat von Andrey Kozhevnikov coderusin...@gmail.com: You should use it if you want real dynamically created components. Or reimplement ContextMenu item. What would you prefer? ___ SailfishOS.org Devel mailing list ___ SailfishOS.org Devel mailing list___ SailfishOS.org Devel mailing list